Skip to content

Instantly share code, notes, and snippets.

@napoler
Created September 29, 2021 08:56
Show Gist options
  • Save napoler/082bc2c4f7bb1f6772b6f73b0630ac16 to your computer and use it in GitHub Desktop.
Save napoler/082bc2c4f7bb1f6772b6f73b0630ac16 to your computer and use it in GitHub Desktop.
Created with Copy to Gist
model = Model()
# 这里是一般情况,共享层往往不止一层,所以做一个for循环
for para in model.linear1.parameters():
 para.requires_grad = False
# 假如真的只有一层也可以这样操作:
# model.linear1.weight.requires_grad = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment