Premium problem82. A Module With One Learnable Scalar

Medium Locked

Write a module holding exactly one learnable scalar parameter named scale, initialised to init, whose forward pass returns scale * x.

Return the tuple (parameter_names, output) where parameter_names is the list of names from named_parameters(). A correct answer has ["scale"] there -- wrapping the scalar in nn.Parameter is what puts it in parameters() and therefore what lets an optimiser ever update it.

Input

x = tensor([1., 2., 3.])
init = 2.0

Output

(['scale'], tensor([2., 4., 6.]))

Premium problem

This one's part of Premium. Unlock the full PyTorch track plus every other premium problem on the site.

Implement solve(...)