Skip to content

Commit 0db2ea2

Browse files
committed
update
1 parent 1b26e30 commit 0db2ea2

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/diffusers/utils/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
DIFFUSERS_ATTN_CHECKS = os.getenv("DIFFUSERS_ATTN_CHECKS", "0") in ENV_VARS_TRUE_VALUES
4646
DEFAULT_HF_PARALLEL_LOADING_WORKERS = 8
4747
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
4949

5050
# Below should be `True` if the current version of `peft` and `transformers` are compatible with
5151
# PEFT backend. Will automatically fall back to PEFT backend if the correct versions of the libraries are

src/diffusers/utils/dynamic_modules_utils.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,23 @@ def _raise_timeout_error(signum, frame):
168168

169169
def resolve_trust_remote_code(trust_remote_code, model_name, has_remote_code):
170170
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+
171176
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"
176188
)
177189

178190
return trust_remote_code

0 commit comments

Comments
 (0)