mlopezantequera commited on
Commit
06feb1a
·
verified ·
1 Parent(s): ac032b9

Update modeling_molmo to work with transformers 4.56.2

Browse files

Avoid errors like this:
```
[rank0]: past_length = past_key_values[0][0].size(-2)
[rank0]: AttributeError: 'NoneType' object has no attribute 'size'
```

Files changed (1) hide show
  1. modeling_molmo.py +5 -0
modeling_molmo.py CHANGED
@@ -2226,6 +2226,11 @@ class MolmoForCausalLM(PreTrainedModel):
2226
  def prepare_inputs_for_generation(
2227
  self, input_ids: torch.LongTensor, past_key_values: Optional[List[Tuple]] = None, **kwargs
2228
  ):
 
 
 
 
 
2229
  if past_key_values:
2230
  # This is because we want the model to only process the last generated token.
2231
  input_ids = input_ids[:, -1:]
 
2226
  def prepare_inputs_for_generation(
2227
  self, input_ids: torch.LongTensor, past_key_values: Optional[List[Tuple]] = None, **kwargs
2228
  ):
2229
+ has_past_key_values = past_key_values is not None and any (x != (None, None) for x in past_key_values)
2230
+ if not has_past_key_values:
2231
+ # Override a list of (None, None) tuples with a single None value as expected by the rest of the code
2232
+ past_key_values = None
2233
+
2234
  if past_key_values:
2235
  # This is because we want the model to only process the last generated token.
2236
  input_ids = input_ids[:, -1:]