Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a workaround for saving internvl2 with latest transformers #2583

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lmdeploy/lite/apis/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ class name or the class type itself.
print(f'Move {mod_name} to GPU.')


# TODO to be removed
def make_compatible_internvl_config(model_path):
"""Patch model.config since after transformers v4.45.0, InternVL models
can't use `save_pretrained`"""
from lmdeploy.archs import get_model_arch
arch, _ = get_model_arch(model_path)
if arch == 'InternVLChatModel':
import transformers
from packaging import version
if version.parse(transformers.__version__) >= version.parse('4.45.0'):

def _get_non_default_generation_parameters(self):
return {}

from transformers import PretrainedConfig
PretrainedConfig._get_non_default_generation_parameters = _get_non_default_generation_parameters # noqa


def calibrate(model: str,
calib_dataset: str = 'ptb',
calib_samples: int = 128,
Expand Down Expand Up @@ -175,6 +193,7 @@ def calibrate(model: str,
'Support only `c4`, `ptb`, `wikitext2` or `pileval`.'

model_type, _ = get_task(model)
make_compatible_internvl_config(model)
if model_type == 'llm':
# Load tokenizer and configuration
tokenizer = AutoTokenizer.from_pretrained(model,
Expand Down
Loading