Compatible with transformers 5.0 at TurboMind side#4304
Compatible with transformers 5.0 at TurboMind side#4304lvhan028 wants to merge 1 commit intoInternLM:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to make lmdeploy compatible with transformers 5.0 at the TurboMind side. Transformers 5.0 introduced a breaking change where rope-related parameters (including rope_theta and rope_scaling) are now aggregated into a single rope_parameters dictionary in the model configuration.
Changes:
- Removed unused utility functions from
lmdeploy/vl/model/utils.pyincluding weight loading helpers and import hacks - Added support for the new
rope_parametersstructure in transformers 5.0 for LlamaModel while maintaining backward compatibility with older versions - Added similar rope_parameters support for DeepSeek2Model
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lmdeploy/vl/model/utils.py | Cleaned up by removing unused functions: load_weight_ckpt, get_used_weight_files, load_model_from_weight_files, add_sys_path, and hack_import_with |
| lmdeploy/turbomind/deploy/source_model/llama.py | Added conditional logic to check for rope_parameters (transformers 5.0) and extract rope_theta and rope_scaling from it, with fallback to the old structure for backward compatibility |
| lmdeploy/turbomind/deploy/source_model/deepseek2.py | Added similar conditional logic to handle rope_parameters for DeepSeek2 models |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if 'rope_parameters' in model_arg: | ||
| # transformers v5.0.0 aggregates all rope-related parameters into 'rope_parameters' | ||
| rope_scaling = model_arg['rope_parameters'] | ||
| rope_theta = rope_scaling.get('rope_theta', 10000.0) |
There was a problem hiding this comment.
The rope_theta value retrieved from rope_parameters is not explicitly converted to float, unlike line 140 which uses float(model_arg.get('rope_theta', 10000.0)). For consistency and to ensure type safety, this should be: rope_theta = float(rope_scaling.get('rope_theta', 10000.0)).
| rope_theta = rope_scaling.get('rope_theta', 10000.0) | |
| rope_theta = float(rope_scaling.get('rope_theta', 10000.0)) |
RunningLeon
left a comment
There was a problem hiding this comment.
v5 broke for vl model
lmdeploy/lmdeploy/vl/model/utils.py", line 12, in <module>
from transformers.utils import (SAFE_WEIGHTS_INDEX_NAME, SAFE_WEIGHTS_NAME, WEIGHTS_INDEX_NAME, WEIGHTS_NAME,
ImportError: cannot import name 'is_safetensors_available' from 'transformers.utils' (/nvme1/xxx/miniconda3/envs/py310/lib/python3.10/site-packages/transformers/utils/__init__.py)
No description provided.