Make canine model exportable by removing unncessary complicated logic (#37124)

This commit is contained in:
Tugsbayasgalan Manlaibaatar 2025-04-01 07:31:12 -04:00 committed by GitHub
parent 60b75d99b6
commit c0bd8048a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1056,7 +1056,7 @@ class CanineModel(CaninePreTrainedModel):
return molecule_attention_mask
def _repeat_molecules(self, molecules: torch.Tensor, char_seq_length: torch.Tensor) -> torch.Tensor:
def _repeat_molecules(self, molecules: torch.Tensor, char_seq_length: int) -> torch.Tensor:
"""Repeats molecules to make them the same length as the char sequence."""
rate = self.config.downsampling_rate
@ -1070,7 +1070,7 @@ class CanineModel(CaninePreTrainedModel):
# n elements (n < `downsampling_rate`), i.e. the remainder of floor
# division. We do this by repeating the last molecule a few extra times.
last_molecule = molecules[:, -1:, :]
remainder_length = torch.fmod(torch.tensor(char_seq_length), torch.tensor(rate)).item()
remainder_length = char_seq_length % rate
remainder_repeated = torch.repeat_interleave(
last_molecule,
# +1 molecule to compensate for truncation.