Value of Module.state_dict()

I tried to run the following code and the output confused me.
Code is:

class test_model(nn.Module):
    def __init__(self):
        super(test_model, self).__init__()
        self.fc = nn.Linear(10, 20)
    def forward(self, x):
        x = self.fc(x)
        return x

def model_sum(params):
    # return sum of parameters of a model
    temp = 0
    for value in params.values():
        temp += value.sum().item()
    return temp

model = test_model()
params = model.state_dict()
print(model_sum(params))

new_params = OrderedDict()
for key in params.keys():
    new_params[key] = params[key] + 1.0
model.load_state_dict(new_params)

print(model_sum(params))

And the output is

-0.15531682968139648
219.84470748901367

which means params is like a pointer to the state_dict of model. I am curious about why the output is like this?

I’m not sure I understand your concern completely.
Since you are loading the newly created state_dict (with the addition of 1), I would assume model_sum to return a higher number.

Thank you for prompt reply.
Yes, model_sum returns a higher number.
My question is why params, which is the OrderedDict of model parameters, also changes when the model parameters change, even without assigning the new model.state_dict() to it.

params = model.state_dict() is inplace operation, which means params is always to same as model.state_dict()