HF endpoint auto-fallback: when huggingface.co is unreachable, probe mirrors (hf-mirror.com) and switch automatically with a one-line notice; error only if all fail
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8ea83fea4f
commit
dd7e1933ff
@ -462,22 +462,36 @@ def _load_from_hub(spec: DatasetSpec) -> List[Dict[str, Any]]:
|
|||||||
return [dict(r) for r in ds]
|
return [dict(r) for r in ds]
|
||||||
|
|
||||||
|
|
||||||
|
_HF_MIRROR_FALLBACKS = ['https://hf-mirror.com']
|
||||||
|
|
||||||
|
|
||||||
def _probe_hub_reachable(spec: DatasetSpec) -> None:
|
def _probe_hub_reachable(spec: DatasetSpec) -> None:
|
||||||
"""Fail fast when the HF endpoint is unreachable -- otherwise the hub
|
"""Fail fast when the HF endpoint is unreachable -- otherwise the hub
|
||||||
client retries silently for minutes and looks like a hang."""
|
client retries silently for minutes and looks like a hang.
|
||||||
|
|
||||||
|
When the DEFAULT endpoint is down but a mirror answers, switch to it
|
||||||
|
automatically (one-line notice, same behavior as --hf-endpoint)."""
|
||||||
base = _hf_base()
|
base = _hf_base()
|
||||||
try:
|
err = None
|
||||||
req = urllib.request.Request(base, method='HEAD',
|
for candidate in [base] + (_HF_MIRROR_FALLBACKS if base == 'https://huggingface.co' else []):
|
||||||
headers={'User-Agent': 'evalharness/0.1'})
|
try:
|
||||||
urllib.request.urlopen(req, timeout=8)
|
req = urllib.request.Request(candidate, method='HEAD',
|
||||||
return
|
headers={'User-Agent': 'evalharness/0.1'})
|
||||||
except Exception as e:
|
urllib.request.urlopen(req, timeout=8)
|
||||||
raise RuntimeError(
|
if candidate != base:
|
||||||
f'HuggingFace endpoint unreachable: {base}\n'
|
os.environ['HF_ENDPOINT'] = candidate
|
||||||
f' reason: {type(e).__name__}: {str(e)[:80]}\n'
|
print(f'· {base} unreachable -- falling back to {candidate}',
|
||||||
f' dataset {spec.source!r} cannot download. Fix:\n'
|
flush=True)
|
||||||
f' evalharness eval run ... --hf-endpoint https://hf-mirror.com\n'
|
return
|
||||||
f' (or export HF_ENDPOINT=https://hf-mirror.com)') from e
|
except Exception as e:
|
||||||
|
err = e
|
||||||
|
raise RuntimeError(
|
||||||
|
f'HuggingFace endpoint unreachable: {base}'
|
||||||
|
+ (f' (mirrors tried: {", ".join(_HF_MIRROR_FALLBACKS)})'
|
||||||
|
if base == 'https://huggingface.co' else '')
|
||||||
|
+ f'\n reason: {type(err).__name__}: {str(err)[:80]}\n'
|
||||||
|
f' dataset {spec.source!r} cannot download. Fix:\n'
|
||||||
|
f' evalharness eval run ... --hf-endpoint <a reachable endpoint>') from err
|
||||||
|
|
||||||
|
|
||||||
def field_spec_to_record_fn(fields: FieldSpec) -> Callable[[Dict[str, Any]], Sample]:
|
def field_spec_to_record_fn(fields: FieldSpec) -> Callable[[Dict[str, Any]], Sample]:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user