Skip to content

Commit 0181aa2

Browse files
authored
MIRA: clear error when the hosted checkpoint cannot be downloaded (#1636)
MIRA-Mode/MIRA, the Hugging Face repository that pretrained=True and load_mira_checkpoint() download from, no longer answers anonymous requests (401). The call failed with a raw huggingface_hub traceback. - load_mira_checkpoint: wrap the download and raise a RuntimeError that names the repository and revision and explains how to load a local snapshot instead. The original error is chained. - docs: note that the repository is not publicly available and that pretrained=<path> still works. - tests: a failed download raises the new error. Signed-off-by: Irvi Aini <irvi.fa@gmail.com>
1 parent de36ac2 commit 0181aa2

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

‎docs/api/models/pyhealth.models.MIRA.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ channel-independently on the inputs of
1515
:class:`~pyhealth.tasks.PhysioNet2012Forecasting`, like
1616
:class:`~pyhealth.models.APN`.
1717

18+
.. note::
19+
20+
As of November 2026, ``MIRA-Mode/MIRA`` is no longer publicly available on
21+
Hugging Face (anonymous requests return 401), so ``pretrained=True`` raises
22+
a ``RuntimeError``. If you have a copy of the snapshot, pass its directory
23+
(holding ``config.json`` and ``model.safetensors``) as ``pretrained``.
24+
Randomly initialized models (``pretrained=False``) are not affected.
25+
1826
See ``examples/mira_physionet2012_forecasting.ipynb`` for zero-shot MIRA on
1927
PhysioNet 2012 next to APN and last observation carried forward.
2028

‎pyhealth/models/mira.py‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,11 @@ def load_mira_checkpoint(
626626
``(config, state_dict)`` for :class:`MIRABackbone`; the weights are
627627
stored in bfloat16 and cast when loaded into a float32 model.
628628
629+
Raises:
630+
RuntimeError: If ``path`` is None and the download fails, for
631+
example because :data:`HF_REPO_ID` is offline or no longer
632+
public. The message says how to load a local snapshot instead.
633+
629634
Examples:
630635
>>> config, state = load_mira_checkpoint() # doctest: +SKIP
631636
>>> backbone = MIRABackbone(config) # doctest: +SKIP
@@ -639,10 +644,22 @@ def load_mira_checkpoint(
639644
if path is None:
640645
from huggingface_hub import hf_hub_download
641646

642-
config_path = hf_hub_download(HF_REPO_ID, "config.json", revision=revision)
643-
weights_path = hf_hub_download(
644-
HF_REPO_ID, "model.safetensors", revision=revision
645-
)
647+
try:
648+
config_path = hf_hub_download(
649+
HF_REPO_ID, "config.json", revision=revision
650+
)
651+
weights_path = hf_hub_download(
652+
HF_REPO_ID, "model.safetensors", revision=revision
653+
)
654+
except OSError as err: # every huggingface_hub download error
655+
raise RuntimeError(
656+
f"Could not download the MIRA checkpoint from {HF_REPO_ID} at "
657+
f"revision {revision}: {err}\nIf the repository is offline or "
658+
"no longer public, pass the path of a local snapshot holding "
659+
"config.json and model.safetensors instead: "
660+
"MIRA(dataset, pretrained='/path/to/snapshot') or "
661+
"load_mira_checkpoint('/path/to/snapshot')."
662+
) from err
646663
else:
647664
config_path = os.path.join(path, "config.json")
648665
weights_path = os.path.join(path, "model.safetensors")

‎tests/core/test_mira.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,14 @@ def fake_download(repo_id, filename, revision=None):
315315
self.assertEqual(call.args[0], HF_REPO_ID)
316316
self.assertEqual(call.kwargs["revision"], HF_REVISION)
317317

318+
def test_failed_download_says_how_to_load_a_local_snapshot(self):
319+
error = OSError("401 Client Error: Repository Not Found")
320+
with mock.patch("huggingface_hub.hf_hub_download", side_effect=error):
321+
with self.assertRaisesRegex(RuntimeError, "local snapshot") as caught:
322+
MIRA(self.dataset, pretrained=True)
323+
self.assertIn(HF_REPO_ID, str(caught.exception))
324+
self.assertIs(caught.exception.__cause__, error)
325+
318326
def test_pretrained_rejects_config(self):
319327
with self.assertRaisesRegex(ValueError, "pretrained"):
320328
MIRA(self.dataset, pretrained=True, config=_tiny_config())

0 commit comments

Comments
 (0)