Skip to content

Commit

Permalink
add trust_remote_code note (modelscope#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jintao-Huang authored Sep 6, 2023
1 parent 4345f3a commit 5c5f050
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modelscope/utils/automodel_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def try_to_load_hf_model(model_dir: str, task_name: str,

if use_hf and automodel_class is None:
raise ValueError(f'Model import failed. You used `use_hf={use_hf}`, '
'but the model is not a model of hf')
'but the model is not a model of hf.')

model = None
if automodel_class is not None:
Expand Down
15 changes: 11 additions & 4 deletions modelscope/utils/hf_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,29 @@ def check_hf_code(model_dir: str, auto_class: type,
# trust_remote_code is False or has_remote_code is False
model_type = config_dict.get('model_type', None)
if model_type is None:
raise ValueError(f'`model_type` key is not found in {config_path}')
raise ValueError(f'`model_type` key is not found in {config_path}.')

trust_remote_code_info = '.'
if not trust_remote_code:
trust_remote_code_info = ', You can try passing `trust_remote_code=True`.'
if auto_class is AutoConfigHF:
if model_type not in CONFIG_MAPPING:
raise ValueError(f'{model_type} not found in HF CONFIG_MAPPING')
raise ValueError(
f'{model_type} not found in HF `CONFIG_MAPPING`{trust_remote_code_info}'
)
elif auto_class is AutoTokenizerHF:
if model_type not in TOKENIZER_MAPPING_NAMES:
raise ValueError(
f'{model_type} not found in HF TOKENIZER_MAPPING_NAMES')
f'{model_type} not found in HF `TOKENIZER_MAPPING_NAMES`{trust_remote_code_info}'
)
else:
mapping_names = [
m.model_type for m in auto_class._model_mapping.keys()
]
if model_type not in mapping_names:
raise ValueError(
f'{model_type} not found in HF auto_class._model_mapping')
f'{model_type} not found in HF `auto_class._model_mapping`{trust_remote_code_info}'
)


def get_wrapped_class(module_class, ignore_file_pattern=[], **kwargs):
Expand Down

0 comments on commit 5c5f050

Please sign in to comment.