config = ChatGLMConfig.from_pretrained(args.model_dir) config.pre_seq_len = args.pre_seq_len config.prefix_projection = args.prefix_projection model = ChatGLMForConditionalGeneration.from_pretrained(args.model_dir, config=config) for name, param in model.named_parameters[](https://zhida.zhihu.com/search?content_id=226105873&content_type=Article&match_order=2&q=named_parameters&zd_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ6aGlkYV9zZXJ2ZXIiLCJleHAiOjE3OTExMzkxNDEsInEiOiJuYW1lZF9wYXJhbWV0ZXJzIiwiemhpZGFfc291cmNlIjoiZW50aXR5IiwiY29udGVudF9pZCI6MjI2MTA1ODczLCJjb250ZW50X3R5cGUiOiJBcnRpY2xlIiwibWF0Y2hfb3JkZXIiOjIsInpkX3Rva2VuIjpudWxsfQ.Ug45pcpNHAVxfI15ktBqqmAxHpZ3hxB3Y8RA3r5d5iE&zhida_source=entity)(): if not any(nd in name for nd in ["prefix_encoder"]): param.requires_grad = False