File tree Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change 45
45
DIFFUSERS_ATTN_CHECKS = os .getenv ("DIFFUSERS_ATTN_CHECKS" , "0" ) in ENV_VARS_TRUE_VALUES
46
46
DEFAULT_HF_PARALLEL_LOADING_WORKERS = 8
47
47
HF_ENABLE_PARALLEL_LOADING = os .environ .get ("HF_ENABLE_PARALLEL_LOADING" , "" ).upper () in ENV_VARS_TRUE_VALUES
48
- DIFFUSERS_DISABLE_CUSTOM_CODE = os .getenv ("DIFFUSERS_DISABLE_CUSTOM_CODE " , "false" ).lower () in ENV_VARS_TRUE_VALUES
48
+ DIFFUSERS_DISABLE_REMOTE_CODE = os .getenv ("DIFFUSERS_DISABLE_REMOTE_CODE " , "false" ).lower () in ENV_VARS_TRUE_VALUES
49
49
50
50
# Below should be `True` if the current version of `peft` and `transformers` are compatible with
51
51
# PEFT backend. Will automatically fall back to PEFT backend if the correct versions of the libraries are
Original file line number Diff line number Diff line change @@ -168,11 +168,23 @@ def _raise_timeout_error(signum, frame):
168
168
169
169
def resolve_trust_remote_code (trust_remote_code , model_name , has_remote_code ):
170
170
trust_remote_code = trust_remote_code and not DIFFUSERS_DISABLE_REMOTE_CODE
171
+ if DIFFUSERS_DISABLE_REMOTE_CODE :
172
+ logger .warning (
173
+ "Remote code execution has been disabled globally via DIFFUSERS_DISABLE_REMOTE_CODE environment variable. Ignoring `trust_remote_code`."
174
+ )
175
+
171
176
if has_remote_code and not trust_remote_code :
172
- raise ValueError (
173
- f"The repository for { model_name } contains custom code which must be executed to correctly "
174
- f"load the model. You can inspect the repository content at https://hf.co/{ model_name } .\n "
175
- f"Please pass the argument `trust_remote_code=True` to allow custom code to be run."
177
+ error_msg = f"The repository for { model_name } contains custom code. "
178
+ error_msg += (
179
+ "Remote code is disabled globally via DIFFUSERS_DISABLE_REMOTE_CODE."
180
+ if DIFFUSERS_DISABLE_REMOTE_CODE
181
+ else "Pass `trust_remote_code=True` to allow loading remote code modules."
182
+ )
183
+ raise ValueError (error_msg )
184
+
185
+ elif has_remote_code and trust_remote_code :
186
+ logger .warning (
187
+ f"`trust_remote_code` is enabled. Downloading code from { model_name } . Please ensure you trust the contents of this repository"
176
188
)
177
189
178
190
return trust_remote_code
You can’t perform that action at this time.
0 commit comments