Premium problem86. Copy Weights With state_dict

Easy Locked

Build two Linear(4, 2) layers with different seeds -- seed_source then seed_target -- so they start with different weights. Copy all learned state from the source into the target using the state-dictionary API.

Return the tuple (source_output, target_output) for the same input x, under torch.no_grad(). After a correct copy the two are identical.

Input

x =
tensor([[1., 1., 1., 1.],
        [1., 1., 1., 1.]])
seed_source = 0
seed_target = 1

Output

(tensor([[-0.5594,  0.4603],
        [-0.5594,  0.4603]]), tensor([[-0.5594,  0.4603],
        [-0.5594,  0.4603]]))

Premium problem

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

Implement solve(...)