Update modeling_molmo.py for compatibility
Browse filesMake code compatible with transformers >= 4.50.3.
Update code to align with recent changes in the Transformers library (calling _extract_past_from_model_output() raises an error).
Same PR from `allenai/Molmo-7B-D-0924`
https://huggingface.co/allenai/Molmo-7B-D-0924/discussions/43
- modeling_molmo.py +5 -0
modeling_molmo.py
CHANGED
|
@@ -2273,6 +2273,11 @@ class MolmoForCausalLM(PreTrainedModel):
|
|
| 2273 |
del model_kwargs["image_masks"]
|
| 2274 |
del model_kwargs["image_input_idx"]
|
| 2275 |
cache_name, cache = super()._extract_past_from_model_output(outputs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2276 |
model_kwargs[cache_name] = cache
|
| 2277 |
model_kwargs["cache_position"] = model_kwargs["cache_position"][-1:] + num_new_tokens
|
| 2278 |
return model_kwargs
|
|
|
|
| 2273 |
del model_kwargs["image_masks"]
|
| 2274 |
del model_kwargs["image_input_idx"]
|
| 2275 |
cache_name, cache = super()._extract_past_from_model_output(outputs)
|
| 2276 |
+
try:
|
| 2277 |
+
cache_name, cache = super()._extract_past_from_model_output(outputs)
|
| 2278 |
+
except AttributeError:
|
| 2279 |
+
past_key_values = outputs.past_key_values if "past_key_values" in outputs else None
|
| 2280 |
+
cache_name, cache = "past_key_values", past_key_values
|
| 2281 |
model_kwargs[cache_name] = cache
|
| 2282 |
model_kwargs["cache_position"] = model_kwargs["cache_position"][-1:] + num_new_tokens
|
| 2283 |
return model_kwargs
|