PyTorch nn.Module → TorchLean IR Smoke Test #
This executable example exercises the model-agnostic PyTorch graph bridge:
- write the generated Python graph-capture adapter;
- write several compact supported PyTorch models (MLP/CNN/CNN head/attention/MHA blocks);
- capture them to
torchlean.ir.v1JSON; - parse and validate each JSON artifact back into
NN.IR.Graph; and - exercise a real
torch.save(model.state_dict())checkpoint reload path; and - run deliberate unsupported-op cases to confirm the bridge reports unsupported semantics clearly.
The example is intentionally small. Its job is not to benchmark PyTorch; it is to test the trust boundary we care about: PyTorch may produce an artifact, but TorchLean accepts it only after parsing and validating the explicit IR JSON.
Run:
lake exe torchlean pytorch_export_smoke
Instances For
Instances For
Write a real PyTorch checkpoint used by TinyCheckpointMLP.
This is intentionally a compact state_dict round-trip: Python owns .pt loading/saving, and the graph
bridge only sees the resulting initialized nn.Module. That mirrors the intended user workflow:
load trained weights in Python, capture the model graph, then ask Lean to validate the exported IR.
Instances For
Keep subprocess failures readable in the smoke output.
The full IO.userError still contains command, args, exit code, and stderr. The smoke only prints
the first informative lines so unsupported-op tests explain the boundary without hiding the signal.
Instances For
Run one supported capture path and parse the resulting graph in Lean.
Instances For
Run the supported capture paths and parse the resulting graphs in Lean.
Instances For
Run a deliberate unsupported op and require the Python bridge to reject it.
Instances For
Run a PyTorch graph that can be captured as a value graph but must not lower into the tensor IR yet.
This is the intended behavior for container-valued PyTorch ops: the JSON keeps the tuple, then Lean rejects tensor lowering with a semantic explanation instead of the Python bridge crashing or incorrectly treating the tuple producer as a tensor op.
Instances For
Run deliberate unsupported ops and require the Python bridge to reject them.
Instances For
Main smoke-test body.