Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

fix(docker): check_torch reports a missing argument and a missing torch by name

Aashish1081966743b1
diff --git a/docker/check_torch.py b/docker/check_torch.py
index b41a52f9..ed5d722a 100644
--- a/docker/check_torch.py
+++ b/docker/check_torch.py
@@ -49,6 +49,15 @@ def repair_cusparselt(dist):
def main():
+ # The build always passes the wheel tag it installed (Dockerfile:19 ->
+ # `python /opt/check_torch.py "${TORCH_INDEX}"`). Run without it, the line that
+ # reads `sys.argv[1]` below used to raise `IndexError: list index out of range`,
+ # which names neither this script's argument nor what it accepts.
+ if len(sys.argv) != 2:
+ sys.stderr.write(
+ "usage: check_torch.py <cpu|cu###> -- the TORCH_INDEX the image was built with\n"
+ " (the Dockerfile passes cpu, cu128 or cu130; see its TORCH_INDEX ARG)\n")
+ sys.exit(2)
if platform.system() == "Linux" and platform.machine() in ("aarch64", "arm64"):
try:
dist = distribution("nvidia-cusparselt-cu13")
@@ -56,7 +65,14 @@ def main():
pass
else:
repair_cusparselt(dist)
- import torch
+ try:
+ import torch
+ except ImportError as exc:
+ # The wheel this check exists to verify is the thing that is missing; the
+ # import machinery's own traceback names the module, not the situation.
+ raise RuntimeError(
+ "PyTorch is not installed, so there is nothing to verify; install the wheel "
+ "this image expects first") from exc
expected = sys.argv[1]
actual = "cpu" if torch.version.cuda is None else "cu" + torch.version.cuda.replace(".", "")
diff --git a/tests/test_docker_torch.py b/tests/test_docker_torch.py
index 5d298bef..64ab9707 100644
--- a/tests/test_docker_torch.py
+++ b/tests/test_docker_torch.py
@@ -1,9 +1,12 @@
"""Check the narrow NVIDIA metadata repair without installing CUDA."""
import base64
+import contextlib
import csv
import hashlib
import importlib.util
+import io
from pathlib import Path
+import sys
import tempfile
import unittest
from unittest.mock import patch
@@ -78,5 +81,33 @@ class WheelRepairTests(unittest.TestCase):
self.assertEqual(before, (dist.wheel.read_bytes(), dist.record.read_bytes()))
+class MainEntryTests(unittest.TestCase):
+ """`main()`'s own contract: a missing argument is a usage error, a missing torch is named.
+
+ The build always calls this with the TORCH_INDEX it installed (`Dockerfile`:19), so both
+ paths are for a person running the script by hand or in a bare environment -- where the
+ old behaviour was `IndexError: list index out of range` and `ModuleNotFoundError`
+ respectively, neither of which says what was wrong with the invocation.
+ """
+
+ def test_missing_expected_tag_is_a_usage_error(self):
+ stderr = io.StringIO()
+ with patch.object(sys, "argv", [str(SCRIPT)]), contextlib.redirect_stderr(stderr):
+ with self.assertRaises(SystemExit) as caught:
+ check.main()
+ self.assertEqual(caught.exception.code, 2)
+ self.assertIn("usage", stderr.getvalue())
+ self.assertIn("cu128", stderr.getvalue())
+
+ def test_missing_torch_is_reported_by_name(self):
+ with patch.object(check, "repair_cusparselt"): # never touch a real env in a unit test
+ with patch.object(sys, "argv", [str(SCRIPT), "cpu"]):
+ with patch.dict(sys.modules, {"torch": None}): # `import torch` raises
+ with self.assertRaises(RuntimeError) as caught:
+ check.main()
+ self.assertIn("not installed", str(caught.exception))
+ self.assertIsInstance(caught.exception.__cause__, ImportError)
+
+
if __name__ == "__main__":
unittest.main()