Update modeling_molmo.py for compatibility

#43

A slight modification from #41

Make 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 error).

syhuggingface changed pull request title from Update modeling_molmo.py for compatibility with transformers v4.50.3 to Update modeling_molmo.py for compatibility
amanrangapur changed pull request status to merged

Thanks for the contribution.

@amanrangapur can you please this apply this change to allenai/MolmoE-1B-0924 as well? It has the exact same issue in the same spot, so should be a quick patch.

Hey @HTahboub , thanks, I've updated the code.

@amanrangapur hi! seems like allenai/Molmo-7B-O-0924 requires the same fix..

in the Molmo-7B-O version, the original line of code appears just before the try-except block:

    cache_name, cache = super()._extract_past_from_model_output(outputs)
    try:
        cache_name, cache = super()._extract_past_from_model_output(outputs)
    except AttributeError:
        past_key_values = outputs.past_key_values if "past_key_values" in outputs else None
        cache_name, cache = "past_key_values", past_key_values

Sign up or log in to comment