When initializing a nn.Module class, which tensors would count as parameters? Would…
- User
When initializing a nn.Module class, which tensors would count as parameters? Would tensors that I create using, say, nn.Linear() or nn.Sequential automatically be parameters? When do I have to use nn.Parameter()?
Assistant
In PyTorch, when you use modules like
nn.Linear()ornn.Sequential(), the learnable parameters (weights) are automatically created as parameters of those modules. You don't need to explicitly usenn.Parameter()for those modules.However, if you create your own tensors or modules and want them to be learnable parameters, you need to use
nn.Parameter(). This is useful when you need to define custom layers or tensors that should be considered as learnable parameters in your neural network.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.