Fix compatibility with transformers >= 4.45#220
Open
Mr-Neutr0n wants to merge 1 commit intozai-org:mainfrom
Open
Fix compatibility with transformers >= 4.45#220Mr-Neutr0n wants to merge 1 commit intozai-org:mainfrom
Mr-Neutr0n wants to merge 1 commit intozai-org:mainfrom
Conversation
Add transformers_compat.py module that patches CogVLM2 model for compatibility with transformers 4.45+ where _extract_past_from_model_output was removed from GenerationMixin. The patch replaces _update_model_kwargs_for_generation with a version that directly accesses outputs.past_key_values instead of calling the removed method. Changes: - Add basic_demo/transformers_compat.py with patch_model_for_transformers_compat() - Update cli_demo.py to apply the patch after model loading - Update web_demo.py to apply the patch after model loading The patch is automatically skipped if running on older transformers versions that still have _extract_past_from_model_output. Fixes zai-org#218
Author
|
following up — this fixes compatibility with transformers >= 4.45 where some internal APIs changed. lmk if you'd want a different approach |
Author
|
Friendly bump! Let me know if there's anything I should update or improve to help move this forward. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AttributeError: 'CogVLMForCausalLM' object has no attribute '_extract_past_from_model_output'when using transformers >= 4.45Problem
In transformers 4.45+, the
_extract_past_from_model_outputmethod was removed fromGenerationMixin. The model'smodeling_cogvlm.py(on HuggingFace Hub) calls this method in_update_model_kwargs_for_generation, causing the error:This breaks
model.generate()when using the model with streaming or any generation that updates model kwargs.Solution
Since the
modeling_cogvlm.pyis hosted on HuggingFace Hub rather than in this repo, we add a runtime compatibility patch in the demo scripts:New
transformers_compat.pymodule: Containspatch_model_for_transformers_compat()that replaces_update_model_kwargs_for_generationwith a version that directly accessesoutputs.past_key_valuesUpdated demo scripts:
cli_demo.pyandweb_demo.pynow call the patch after model loadingThe patch is backward compatible:
Usage
For users with custom scripts, they can apply the patch:
Long-term fix
The proper fix would be to update
modeling_cogvlm.pyon HuggingFace Hub to use:instead of:
Test plan
cli_demo.pywith transformers >= 4.45web_demo.pywith transformers >= 4.45Fixes #218