Skip to content

Commit ffb7cab

Browse files
committed
Added new argument trust_remote_code in infer which will help for emote code execution
Signed-off-by: Amit Raj <[email protected]>
1 parent a33fb48 commit ffb7cab

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

QEfficient/base/common.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ def from_pretrained(cls, pretrained_model_name_or_path: str, *args, **kwargs) ->
4040
"""
4141
Downloads HuggingFace model if already doesn't exist locally, returns QEFFAutoModel object based on type of model.
4242
"""
43-
config = AutoConfig.from_pretrained(pretrained_model_name_or_path, trust_remote_code=True)
43+
config = AutoConfig.from_pretrained(pretrained_model_name_or_path, *args, **kwargs)
4444

45-
# class_name = MODEL_CLASS_MAPPING.get(config.__class__.__name__, None) OR MODEL_EXTERNAL_CLASS_MAPPING(config.__class__.__name__)
4645
class_name = (
4746
MODEL_CLASS_MAPPING.get(config.__class__.__name__, None)
4847
or EXTERNAL_MODEL_CLASS_MAPPING[config.__class__.__name__]
@@ -65,7 +64,6 @@ def from_pretrained(cls, pretrained_model_name_or_path: str, *args, **kwargs) ->
6564
pretrained_model_name_or_path=(local_model_dir if local_model_dir else pretrained_model_name_or_path),
6665
token=hf_token,
6766
continuous_batching=continuous_batching,
68-
trust_remote_code=True,
6967
**kwargs,
7068
)
7169
return qeff_model

QEfficient/cloud/infer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def main(
111111
allow_mxint8_mdp_io: bool = False,
112112
enable_qnn: Optional[bool] = False,
113113
qnn_config: Optional[str] = None,
114+
trust_remote_code: Optional[bool] = False,
114115
**kwargs,
115116
) -> None:
116117
"""
@@ -140,6 +141,7 @@ def main(
140141
:allow_mxint8_mdp_io (bool): Allows MXINT8 compression of MDP IO traffic. ``Defaults to False.``
141142
:enable_qnn (bool): Enables QNN Compilation. ``Defaults to False.``
142143
:qnn_config (str): Path of QNN Config parameters file. ``Defaults to None.``
144+
:trust_remote_code (bool): Trust remote code execution. ``Defaults to False.``
143145
:kwargs: Pass any compiler option as input. Any flag that is supported by `qaic-exec` can be passed. Params are converted to flags as below:
144146
-allocator_dealloc_delay=1 -> -allocator-dealloc-delay=1
145147
-qpc_crc=True -> -qpc-crc
@@ -164,6 +166,7 @@ def main(
164166
hf_token=hf_token,
165167
full_batch_size=full_batch_size,
166168
local_model_dir=local_model_dir,
169+
trust_remote_code=trust_remote_code,
167170
)
168171

169172
image_path = kwargs.pop("image_path", None)
@@ -264,6 +267,12 @@ def main(
264267
action="store_true",
265268
help="Compress constant MatMul weights to MXFP6 E2M3, default is no compression",
266269
)
270+
parser.add_argument(
271+
"--trust_remote_code",
272+
action="store_true",
273+
default=False,
274+
help="Enable trusting remote code when loading models. Default is False; set to True by passing this flag.",
275+
)
267276
parser.add_argument(
268277
"--mxint8",
269278
"--mxint8_kv_cache",

QEfficient/transformers/modeling_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ def build_model_class_mapping(auto_model_class, qeff_class_name):
284284

285285

286286
EXTERNAL_MODEL_CLASS_MAPPING = {"Grok1Config": "QEFFAutoModelForCausalLM"}
287+
287288
MODEL_CLASS_MAPPING = {
288289
**build_model_class_mapping(mapping.AutoModelForCausalLM, "QEFFAutoModelForCausalLM"),
289290
**build_model_class_mapping(mapping.AutoModelForImageTextToText, "QEFFAutoModelForImageTextToText"),

0 commit comments

Comments
 (0)