Make qwen3's set_embed_and_head idempotent (#26798)
This commit is contained in:
@@ -674,8 +674,10 @@ class Qwen3ForCausalLM(nn.Module):
|
|||||||
return self.model.embed_tokens.weight, self.lm_head.weight
|
return self.model.embed_tokens.weight, self.lm_head.weight
|
||||||
|
|
||||||
def set_embed_and_head(self, embed, head):
|
def set_embed_and_head(self, embed, head):
|
||||||
del self.model.embed_tokens.weight
|
if hasattr(self.model.embed_tokens, "weight"):
|
||||||
del self.lm_head.weight
|
del self.model.embed_tokens.weight
|
||||||
|
if hasattr(self.lm_head, "weight"):
|
||||||
|
del self.lm_head.weight
|
||||||
self.model.embed_tokens.weight = embed
|
self.model.embed_tokens.weight = embed
|
||||||
self.lm_head.weight = head
|
self.lm_head.weight = head
|
||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
|
|||||||
Reference in New Issue
Block a user