You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
modeling_phi3 errors with AttributeError: 'DynamicCache' object has no attribute 'get_max_length' #36071
The get_max_length() has been deprecated for several releases and is removed in the last v4.48. It should be cache.get_max_cache_shape().
Since the source of error is the remote code stored on hub, you need to open an issue in model repo and ask authors to fix that. Also you can downgrade transformers version a a workaround
Reacted by Saibo-creator, Brendan, Cheng Jiang, Sun Haoyang and Zhe Gao
I need to upgrade to v4.49 to use GRPO, so downgrading the transformers version isn't an option. Since the issue is with the HF hub's modeling_phi3.py, is there an easy way to get it to use the transformers' modeling_phi3.py instead (where it looks like the issue is fixed)? My current workaround is to download the transformers version and modify it to use absolute imports instead of relative imports.
Unfortunately the same workaround doesn't seem to exist for phi3_v. @zucchini-nlp Are you aware of any limitations that would prevent a HF-maintained version of this model as well? I'd normally open a PR on HF, but the project hasn't been updated in 7 months.
@kylesayrs yeah, we didn't ship Phi3-Vision to transformers and it is supported only by hub code. You can still run it by cloning the repo and changing the problematic line. Not sure if authors are actively updating the model code
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.
I'm not sure why this is only coming up with phi-3 so far
Updating the line 1292 of modeling_phi3.py from max_cache_length = past_key_values.get_max_length() to max_cache_length = past_key_values.get_max_cache_shape() seems to be fixing the issue.
Reacted by Maëlic Neau, Hirunima Jayasekara, hunter2009pf and SenvenJ
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.
I tried pip install transformers==4.47.0 and restarted the kernel, but it did not fix the error for me, but adding use_cache=False to my Pipeline args did fix it.
Setting use_cache=False in the generation_args fixes the issue for me. It slows everything down, however.
hey did, you find the workaround for this issue, i am running in same problem and currently doing same in generation_args to fix but latency is my concern
Activity
zucchini-nlp commentedon Feb 7, 2025
Hey @doctorpangloss !
The
get_max_length()has been deprecated for several releases and is removed in the last v4.48. It should becache.get_max_cache_shape().Since the source of error is the remote code stored on hub, you need to open an issue in model repo and ask authors to fix that. Also you can downgrade transformers version a a workaround
jillianmclements commentedon Feb 8, 2025
I need to upgrade to v4.49 to use GRPO, so downgrading the transformers version isn't an option. Since the issue is with the HF hub's modeling_phi3.py, is there an easy way to get it to use the transformers' modeling_phi3.py instead (where it looks like the issue is fixed)? My current workaround is to download the transformers version and modify it to use absolute imports instead of relative imports.
zucchini-nlp commentedon Feb 9, 2025
@doctorpangloss you can set
trust_remote_code=Falseif you are using one of the supported checkpoints. Check out #32365 (comment)kylesayrs commentedon Feb 12, 2025
Unfortunately the same workaround doesn't seem to exist for phi3_v. @zucchini-nlp Are you aware of any limitations that would prevent a HF-maintained version of this model as well? I'd normally open a PR on HF, but the project hasn't been updated in 7 months.
zucchini-nlp commentedon Feb 12, 2025
@kylesayrs yeah, we didn't ship Phi3-Vision to transformers and it is supported only by hub code. You can still run it by cloning the repo and changing the problematic line. Not sure if authors are actively updating the model code
alothomas commentedon Feb 13, 2025
Hey I have the same error, with Phi2 backbone, did you manage to fix it ?
ArthurZucker commentedon Feb 13, 2025
@kylesayrs limitation is just time 🤣 happy to have it in transformers
github-actions commentedon Mar 10, 2025
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.
Rocketknight1 commentedon Mar 10, 2025
We currently have a user PR to add Phi-3.5-vision to the main library, which should resolve this: #36036
jranaraki commentedon Mar 13, 2025
Updating the line 1292 of
modeling_phi3.pyfrommax_cache_length = past_key_values.get_max_length()tomax_cache_length = past_key_values.get_max_cache_shape()seems to be fixing the issue.[Bugfix] Disable generation of deepseek models with transformers>=4.48 (
kevalmorabia97 commentedon Mar 20, 2025
Submitted a fix to Phi-3.5-Vision-Instruct huggingface repo: https://huggingface.co/microsoft/Phi-3.5-vision-instruct/discussions/38
github-actions commentedon Apr 14, 2025
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.
Efim27 commentedon Jun 7, 2025
Just use:
pip install transformers==4.47.0
leonmayer commentedon Jun 17, 2025
Setting
use_cache=Falsein thegeneration_argsfixes the issue for me. It slows everything down, however.chipwilson commentedon Jul 23, 2025
I tried
pip install transformers==4.47.0and restarted the kernel, but it did not fix the error for me, but addinguse_cache=Falseto my Pipeline args did fix it.Fix DynamicCache compatibility for transformers 4.49+
KanishkNoir commentedon Dec 17, 2025
hey did, you find the workaround for this issue, i am running in same problem and currently doing same in generation_args to fix but latency is my concern