You have to create the init function and apply it to the model:
def weights_init(m):
    if isinstance(m, nn.Conv2d):
        nn.init.xavier_uniform(m.weight.data)
        nn.init.xavier_uniform(m.bias.data)
    

model = MyModel()
model.apply(weights_init)