818c380fd0
giant predict and giant rollout each carried a ~65-line, independently drifting copy of "load checkpoint -> validate -> resolve conditioning axes -> restore normalizers/vocab maps -> build models -> load weights", plus a third partial copy of _conditioning_axes in analysis/router_gating.py. A silent divergence there doesn't crash, it makes the two commands run different physics from the same checkpoint with no test coverage anywhere along that path. giant/checkpoint_io.py now holds the single implementation: load_for_inference() + an InferenceContext dataclass, raising CheckpointCompatibilityError (verbatim message text preserved) instead of calling typer directly, so it can be unit-tested and imported from non-Typer code. router_gating.py's load_router imports conditioning_axes from it lazily, keeping its "no torch at module scope" contract intact. Adds 17 direct unit tests for load_for_inference/conditioning_axes/stage_cfg plus CLI smoke tests confirming the error surfaces as typer.Exit(1) through predict and rollout — previously zero coverage on this path. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
34 lines
960 B
Python
34 lines
960 B
Python
"""Thin CLI smoke coverage for `giant rollout` (issues.md Issue 5) — confirms
|
|
the CheckpointCompatibilityError raised by giant.checkpoint_io.load_for_inference
|
|
surfaces as a clean typer.Exit(1) with the expected message, end-to-end
|
|
through the CLI, not just at the giant.checkpoint_io unit level."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import torch
|
|
from typer.testing import CliRunner
|
|
|
|
from giant.cli import app
|
|
|
|
runner = CliRunner()
|
|
|
|
|
|
def test_rollout_exits_1_on_checkpoint_missing_model_config(tmp_path):
|
|
checkpoint = tmp_path / "bad.pt"
|
|
torch.save({"sec_decoder": {}, "normalizer": {"sec_phys": {}}}, checkpoint)
|
|
|
|
result = runner.invoke(
|
|
app,
|
|
[
|
|
"rollout",
|
|
"dummy.parquet",
|
|
"--checkpoint",
|
|
str(checkpoint),
|
|
"--geometry",
|
|
"dummy_geometry.pkl",
|
|
],
|
|
)
|
|
|
|
assert result.exit_code == 1
|
|
assert "checkpoint has no model_config" in result.output
|