MCPcopy Create free account
hub / github.com/modelscope/modelscope / fix_transformers_upgrade

Function fix_transformers_upgrade

modelscope/utils/automodel_utils.py:44–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42
43
44def fix_transformers_upgrade():
45 if is_transformers_available() and is_torch_available():
46 # from 4.35.0, transformers changes its arguments of _set_gradient_checkpointing
47 import transformers
48 from transformers import PreTrainedModel
49 from packaging import version
50 if version.parse(transformers.__version__) >= version.parse('4.35.0') \
51 and not hasattr(PreTrainedModel, 'post_init_origin'):
52 PreTrainedModel.post_init_origin = PreTrainedModel.post_init
53 PreTrainedModel.post_init = post_init
54
55
56def _can_load_by_hf_automodel(automodel_class: type, config) -> bool:

Callers 1

__init__.pyFile · 0.90

Calls 2

is_torch_availableFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…