self.layer_weights is not a tensor but a Parameter 48 that is registered as an attribute of your module. That’s why when you assign it a tensor it throws an error. Instead, try
self.layer_weights = nn.Parameter(F.softmax(self.layer_weights,dim=0))