Trainable parameter

How can I integrate a trainable parameter ranging from 2 to 10 using Torch? This parameter doesn’t directly participate in the output operations, but its updates need to be maintained during training.

Autograd won’t calculate gradients for parameters which weren’t used as they do not have any influence on the output. You can manually assign a .grad attribute but I don’t know how you would calculate it.