This function is used to re-order the `past_key_values` cache if [`~PretrainedModel.beam_search`] or [`~PretrainedModel.beam_sample`] is called. This is required to match `past_key_values` with the correct beam_idx at every generation step.
(
past_key_values: Tuple[Tuple[torch.Tensor]], beam_idx: torch.Tensor
)
| 720 | |
| 721 | @staticmethod |
| 722 | def _reorder_cache( |
| 723 | past_key_values: Tuple[Tuple[torch.Tensor]], beam_idx: torch.Tensor |
| 724 | ) -> Tuple[Tuple[torch.Tensor]]: |
| 725 | """ |
| 726 | This function is used to re-order the `past_key_values` cache if [`~PretrainedModel.beam_search`] or |
| 727 | [`~PretrainedModel.beam_sample`] is called. This is required to match `past_key_values` with the correct |
| 728 | beam_idx at every generation step. |
| 729 | """ |
| 730 | return tuple( |
| 731 | tuple(past_state.index_select(0, beam_idx.to(past_state.device)) for past_state in layer_past) |
| 732 | for layer_past in past_key_values |
| 733 | ) |
| 734 | |
| 735 | def quantize(self, wbits, groupsize): |
| 736 | from .quantization import quantize_with_gptq |
nothing calls this directly
no outgoing calls
no test coverage detected