|
20 | 20 | import os |
21 | 21 | import re |
22 | 22 | import shutil |
23 | | -import signal |
24 | 23 | import sys |
25 | 24 | import threading |
26 | 25 | from pathlib import Path |
|
34 | 33 |
|
35 | 34 | from .. import __version__ |
36 | 35 | from . import DIFFUSERS_DYNAMIC_MODULE_NAME, HF_MODULES_CACHE, logging |
| 36 | +from .constants import DIFFUSERS_DISABLE_REMOTE_CODE |
37 | 37 |
|
38 | 38 |
|
39 | 39 | logger = logging.get_logger(__name__) # pylint: disable=invalid-name |
@@ -167,44 +167,12 @@ def _raise_timeout_error(signum, frame): |
167 | 167 |
|
168 | 168 |
|
169 | 169 | 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 |
203 | 171 | if has_remote_code and not trust_remote_code: |
204 | 172 | 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." |
208 | 176 | ) |
209 | 177 |
|
210 | 178 | return trust_remote_code |
|
0 commit comments