Skip to content

Commit ddfdf47

Browse files
authored
Add trust_remote_code arg to get_config (#405)
1 parent b6fbb9a commit ddfdf47

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

vllm/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(
5454
self.use_dummy_weights = use_dummy_weights
5555
self.seed = seed
5656

57-
self.hf_config = get_config(model)
57+
self.hf_config = get_config(model, trust_remote_code)
5858
self.dtype = _get_and_verify_dtype(self.hf_config, dtype)
5959
self._verify_tokenizer_mode()
6060

vllm/transformers_utils/config.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,21 @@
77
}
88

99

10-
def get_config(model: str) -> PretrainedConfig:
11-
config = AutoConfig.from_pretrained(model, trust_remote_code=True)
10+
def get_config(model: str, trust_remote_code: bool) -> PretrainedConfig:
11+
try:
12+
config = AutoConfig.from_pretrained(
13+
model, trust_remote_code=trust_remote_code)
14+
except ValueError as e:
15+
if (not trust_remote_code and
16+
"requires you to execute the configuration file" in str(e)):
17+
err_msg = (
18+
"Failed to load the model config. If the model is a custom "
19+
"model not yet available in the HuggingFace transformers "
20+
"library, consider setting `trust_remote_code=True` in LLM "
21+
"or using the `--trust-remote-code` flag in the CLI.")
22+
raise RuntimeError(err_msg) from e
23+
else:
24+
raise e
1225
if config.model_type in _CONFIG_REGISTRY:
1326
config_class = _CONFIG_REGISTRY[config.model_type]
1427
config = config_class.from_pretrained(model)

vllm/transformers_utils/tokenizer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def get_tokenizer(
3434
try:
3535
tokenizer = AutoTokenizer.from_pretrained(
3636
tokenizer_name,
37-
trust_remote_code=trust_remote_code,
3837
*args,
38+
trust_remote_code=trust_remote_code,
3939
**kwargs)
4040
except TypeError as e:
4141
# The LLaMA tokenizer causes a protobuf error in some environments.
@@ -47,13 +47,14 @@ def get_tokenizer(
4747
except ValueError as e:
4848
# If the error pertains to the tokenizer class not existing or not
4949
# currently being imported, suggest using the --trust-remote-code flag.
50-
if (e is not None and
50+
if (not trust_remote_code and
5151
("does not exist or is not currently imported." in str(e)
5252
or "requires you to execute the tokenizer file" in str(e))):
5353
err_msg = (
5454
"Failed to load the tokenizer. If the tokenizer is a custom "
5555
"tokenizer not yet available in the HuggingFace transformers "
56-
"library, consider using the --trust-remote-code flag.")
56+
"library, consider setting `trust_remote_code=True` in LLM "
57+
"or using the `--trust-remote-code` flag in the CLI.")
5758
raise RuntimeError(err_msg) from e
5859
else:
5960
raise e

0 commit comments

Comments
 (0)