Skip to content

Commit 1b26e30

Browse files
committed
update
1 parent 4d9b822 commit 1b26e30

File tree

3 files changed

+7
-38
lines changed

3 files changed

+7
-38
lines changed

src/diffusers/modular_pipelines/modular_pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def outputs(self) -> List[OutputParam]:
290290
def from_pretrained(
291291
cls,
292292
pretrained_model_name_or_path: str,
293-
trust_remote_code: Optional[bool] = None,
293+
trust_remote_code: bool = False,
294294
**kwargs,
295295
):
296296
hub_kwargs_names = [

src/diffusers/utils/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +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
4849

4950
# Below should be `True` if the current version of `peft` and `transformers` are compatible with
5051
# 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: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import os
2121
import re
2222
import shutil
23-
import signal
2423
import sys
2524
import threading
2625
from pathlib import Path
@@ -34,6 +33,7 @@
3433

3534
from .. import __version__
3635
from . import DIFFUSERS_DYNAMIC_MODULE_NAME, HF_MODULES_CACHE, logging
36+
from .constants import DIFFUSERS_DISABLE_REMOTE_CODE
3737

3838

3939
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
@@ -167,44 +167,12 @@ def _raise_timeout_error(signum, frame):
167167

168168

169169
def resolve_trust_remote_code(trust_remote_code, model_name, has_remote_code):
170-
if trust_remote_code is None:
171-
if has_remote_code and TIME_OUT_REMOTE_CODE > 0:
172-
prev_sig_handler = None
173-
try:
174-
prev_sig_handler = signal.signal(signal.SIGALRM, _raise_timeout_error)
175-
signal.alarm(TIME_OUT_REMOTE_CODE)
176-
while trust_remote_code is None:
177-
answer = input(
178-
f"The repository for {model_name} contains custom code which must be executed to correctly "
179-
f"load the model. You can inspect the repository content at https://hf.co/{model_name}.\n"
180-
f"You can avoid this prompt in future by passing the argument `trust_remote_code=True`.\n\n"
181-
f"Do you wish to run the custom code? [y/N] "
182-
)
183-
if answer.lower() in ["yes", "y", "1"]:
184-
trust_remote_code = True
185-
elif answer.lower() in ["no", "n", "0", ""]:
186-
trust_remote_code = False
187-
signal.alarm(0)
188-
except Exception:
189-
# OS which does not support signal.SIGALRM
190-
raise ValueError(
191-
f"The repository for {model_name} contains custom code which must be executed to correctly "
192-
f"load the model. You can inspect the repository content at https://hf.co/{model_name}.\n"
193-
f"Please pass the argument `trust_remote_code=True` to allow custom code to be run."
194-
)
195-
finally:
196-
if prev_sig_handler is not None:
197-
signal.signal(signal.SIGALRM, prev_sig_handler)
198-
signal.alarm(0)
199-
elif has_remote_code:
200-
# For the CI which puts the timeout at 0
201-
_raise_timeout_error(None, None)
202-
170+
trust_remote_code = trust_remote_code and not DIFFUSERS_DISABLE_REMOTE_CODE
203171
if has_remote_code and not trust_remote_code:
204172
raise ValueError(
205-
f"Loading {model_name} requires you to execute the configuration file in that"
206-
" repo on your local machine. Make sure you have read the code there to avoid malicious use, then"
207-
" set the option `trust_remote_code=True` to remove this error."
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."
208176
)
209177

210178
return trust_remote_code

0 commit comments

Comments
 (0)