(
self,
input_ids: torch.LongTensor = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[List[torch.FloatTensor]] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
use_cache: Optional[bool] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
cache_position: Optional[torch.LongTensor] = None,
offload_model: Optional[bool] = False,
)
| 54 | |
| 55 | |
| 56 | def forward( |
| 57 | self, |
| 58 | input_ids: torch.LongTensor = None, |
| 59 | attention_mask: Optional[torch.Tensor] = None, |
| 60 | position_ids: Optional[torch.LongTensor] = None, |
| 61 | past_key_values: Optional[List[torch.FloatTensor]] = None, |
| 62 | inputs_embeds: Optional[torch.FloatTensor] = None, |
| 63 | use_cache: Optional[bool] = None, |
| 64 | output_attentions: Optional[bool] = None, |
| 65 | output_hidden_states: Optional[bool] = None, |
| 66 | return_dict: Optional[bool] = None, |
| 67 | cache_position: Optional[torch.LongTensor] = None, |
| 68 | offload_model: Optional[bool] = False, |
| 69 | ) -> Union[Tuple, BaseModelOutputWithPast]: |
| 70 | output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions |
| 71 | output_hidden_states = ( |
| 72 | output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states |
| 73 | ) |
| 74 | use_cache = use_cache if use_cache is not None else self.config.use_cache |
| 75 | |
| 76 | return_dict = return_dict if return_dict is not None else self.config.use_return_dict |
| 77 | |
| 78 | if (input_ids is None) ^ (inputs_embeds is not None): |
| 79 | raise ValueError("You must specify exactly one of input_ids or inputs_embeds") |
| 80 | |
| 81 | if self.gradient_checkpointing and self.training: |
| 82 | if use_cache: |
| 83 | logger.warning_once( |
| 84 | "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..." |
| 85 | ) |
| 86 | use_cache = False |
| 87 | |
| 88 | # kept for BC (non `Cache` `past_key_values` inputs) |
| 89 | return_legacy_cache = False |
| 90 | if use_cache and not isinstance(past_key_values, Cache): |
| 91 | return_legacy_cache = True |
| 92 | if past_key_values is None: |
| 93 | past_key_values = DynamicCache() |
| 94 | else: |
| 95 | past_key_values = DynamicCache.from_legacy_cache(past_key_values) |
| 96 | logger.warning_once( |
| 97 | "We detected that you are passing `past_key_values` as a tuple of tuples. This is deprecated and " |
| 98 | "will be removed in v4.47. Please convert your cache or use an appropriate `Cache` class " |
| 99 | "(https://huggingface.co/docs/transformers/kv_cache#legacy-cache-format)" |
| 100 | ) |
| 101 | |
| 102 | # if inputs_embeds is None: |
| 103 | # inputs_embeds = self.embed_tokens(input_ids) |
| 104 | |
| 105 | # if cache_position is None: |
| 106 | # past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0 |
| 107 | # cache_position = torch.arange( |
| 108 | # past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device |
| 109 | # ) |
| 110 | # if position_ids is None: |
| 111 | # position_ids = cache_position.unsqueeze(0) |
| 112 | |
| 113 | if attention_mask is not None and attention_mask.dim() == 3: |
nothing calls this directly
no test coverage detected