Skip to content
ml-recall

#load-state-dict

1 question from PyTorch

Timed test

1 question · 1 min · score and explanations at the end

Take a test
Q 1 / 1Score 0 / 0

Question 1: Single choice

hardAI-checkedPyTorch

A trained model was saved with torch.save(old.state_dict(), "mlp.params"). Its class is:

class MLP(nn.Module):
    def __init__(self, num_outputs=10):
        super().__init__()
        self.hidden = nn.Linear(20, 256)
        self.output = nn.Linear(256, num_outputs)

    def forward(self, X):
        return self.output(torch.relu(self.hidden(X)))

You build new = MLP(num_outputs=5) and load sd = torch.load("mlp.params"). Which call copies the trained hidden layer into new and leaves the new 5-class output layer at its random initialization?

Choose one option