Skip to content

Commit

Permalink
Add a workaround for saving internvl2 with latest transformers (#2583)
Browse files Browse the repository at this point in the history
* Add a workaround for saving internvl2 with latest transformers

* fix lint

* use arch
  • Loading branch information
AllentDan authored Oct 17, 2024
1 parent b689cbc commit fec94c9
Showing 1 changed file with 19 additions and 0 deletions.
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

0 comments on commit fec94c9

Please sign in to comment.