"vscode:/vscode.git/clone" did not exist on "3bc65505fc0801e3d9ff741ec725fb0cb4d863d6"
Unverified Commit d2295708 authored by Sylvain Gugger's avatar Sylvain Gugger Committed by GitHub
Browse files

Better error message when signal is not supported on OS (#25049)

* Better error message when signal is not supported on OS

* Address review comments
parent c0d1c330
......@@ -532,6 +532,7 @@ def resolve_trust_remote_code(trust_remote_code, model_name, has_local_code, has
if has_local_code:
trust_remote_code = False
elif has_remote_code and TIME_OUT_REMOTE_CODE > 0:
try:
signal.signal(signal.SIGALRM, _raise_timeout_error)
signal.alarm(TIME_OUT_REMOTE_CODE)
while trust_remote_code is None:
......@@ -545,6 +546,13 @@ def resolve_trust_remote_code(trust_remote_code, model_name, has_local_code, has
elif answer.lower() in ["no", "n", "0", ""]:
trust_remote_code = False
signal.alarm(0)
except AttributeError:
# OS which does not support signal.SIGALRM
raise ValueError(
"Loading this model requires you to execute execute some code in that repo on your local machine. "
f"Make sure you have read the code at https://hf.co/{model_name} to avoid malicious use, then set "
"the option `trust_remote_code=True` to remove this error."
)
elif has_remote_code:
# For the CI which puts the timeout at 0
_raise_timeout_error(None, None)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment