amanrangapur syhuggingface commited on
Commit
ac032b9
·
verified ·
1 Parent(s): 1721478

Update modeling_molmo.py for compatibility (#43)

Browse files

- Update modeling_molmo.py for compatibility with transformers v4.50.3 (2fa83bdcb6a845da16ca81cffdbe506027777306)


Co-authored-by: Seungyeon Jwa <[email protected]>

Files changed (1) hide show
  1. modeling_molmo.py +5 -1
modeling_molmo.py CHANGED
@@ -2272,7 +2272,11 @@ class MolmoForCausalLM(PreTrainedModel):
2272
  del model_kwargs["images"]
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
 
2272
  del model_kwargs["images"]
2273
  del model_kwargs["image_masks"]
2274
  del model_kwargs["image_input_idx"]
2275
+ try:
2276
+ cache_name, cache = super()._extract_past_from_model_output(outputs)
2277
+ except AttributeError:
2278
+ past_key_values = outputs.past_key_values if "past_key_values" in outputs else None
2279
+ cache_name, cache = "past_key_values", past_key_values
2280
  model_kwargs[cache_name] = cache
2281
  model_kwargs["cache_position"] = model_kwargs["cache_position"][-1:] + num_new_tokens
2282
  return model_kwargs