You can wrap the computation for the model you don’t want to update inside torch.no_grad() then no grad will be accumulated for those parameters inside enclosed inside .no_grad:
x = torch.tensor([3.])  # input
w = torch.tensor([1.]).requires_grad_(True)  # params of model0
b = torch.tensor([0.]).requires_grad_(True)  # params of model1

# now skip updating model0
with torch.no_grad():
  y = x * w
y = y + b

# update params
y.backward()
optim.step()  # this will only `model1` since `model0.grad = None` as it's like it has never being passed to optim object

# print some grads
print(w.grad) = None
print(b.grad) = # a tensor