This is old, but I was able to work around this issue by accessing module attributes using  __dict__ instead of setattr:
some_nn_module.__dict__['weight'] = myFunction(x)

This requires using self.named_modules() instead of self.named_parameters(), but doesn’t require writing any custom modules or changing existing ones.