Your code seems to work on my machine using 1.0.0.dev20181125.
However, the error is most likely thrown due to a wrong if condition.
If you call apply on your model, the function you are providing will be applied recursively on all children as well as the model itself.
Even though your code works for me, I would recommend to write the checks as:
if isinstance(m, nn.Conv2d):
    ...
# or
if type(m) == nn.Conv2d:
    ...