Concatenate a tensor with a padding tensor of the given value.
(
tensor: torch.Tensor,
padding_length: int,
value: int | float,
)
| 497 | |
| 498 | |
| 499 | def _cat_with_padding( |
| 500 | tensor: torch.Tensor, |
| 501 | padding_length: int, |
| 502 | value: int | float, |
| 503 | ) -> torch.Tensor: |
| 504 | """Concatenate a tensor with a padding tensor of the given value.""" |
| 505 | return torch.cat( |
| 506 | [ |
| 507 | tensor, |
| 508 | torch.full( |
| 509 | (1, padding_length), |
| 510 | value, |
| 511 | dtype=tensor.dtype, |
| 512 | device=tensor.device, |
| 513 | ), |
| 514 | ], |
| 515 | dim=1, |
| 516 | ) |
| 517 | |
| 518 | |
| 519 | def _pad_inputs_for_attention_alignment(model_inputs, pad_token_id, alignment: int = 8): |
no outgoing calls
no test coverage detected