fix recursion error

This commit is contained in:
hiyouga 2023-10-22 16:28:37 +08:00
parent 7b4acf7265
commit b79ca8781e
1 changed files with 2 additions and 2 deletions

View File

@ -54,7 +54,7 @@ def prepare_model_for_training(
input_embed: torch.nn.Embedding = model.get_input_embeddings()
def noisy_forward(self: torch.nn.Embedding, x: torch.Tensor) -> torch.Tensor:
embeddings = input_embed.forward(x)
embeddings = torch.nn.Embedding.forward(self, x)
if self.training:
dims = self.num_embeddings * self.embedding_dim
mag_norm = finetuning_args.neft_alpha / (dims ** 0.5)
@ -79,7 +79,7 @@ def prepare_model_for_training(
input_dtype = output_layer.weight.dtype
def forward_in_fp32(self, x: torch.Tensor) -> torch.Tensor:
return output_layer.forward(x.to(input_dtype)).to(torch.float32)
return torch.nn.Linear.forward(self, x.to(input_dtype)).to(torch.float32)
output_layer.forward = MethodType(forward_in_fp32, output_layer)