NN.Runtime.PyTorch.Import #
Reusable PyTorch weight-import surface.
The general import path is JSON-first:
- PyTorch loads the original checkpoint /
state_dict. - The adapter emitted by
NN.Runtime.PyTorch.Export.StateDictwrites nested-list JSON. Import.Coreparses that JSON into shape-checked TorchLean tensors.
For graphs, the matching path is:
- PyTorch captures an
nn.Modulewith the adapter emitted byNN.Runtime.PyTorch.Export.TorchExport. Import.TorchExportparses the resultingtorchlean.ir.v1graph JSON intoNN.IR.Graph.- The parser runs the shared IR well-formedness and shape checkers before accepting the graph.
This is the supported graph-import path today. The ONNX adapter emitted by
NN.Runtime.PyTorch.Export.ONNX follows the same rule: lower ONNX nodes into the
torchlean.ir.v1 artifact, then reuse this parser and the shared IR validators. Keeping the
artifact boundary explicit avoids a second, looser graph semantics.
Graph import and payload import remain separate phases. A Conv/Gemm/BatchNorm graph can be validated as TorchLean IR once the adapter expands it into supported nodes; executing the graph then requires the matching constants/linear/conv payload store.
Architecture-specific example loaders live beside their reference artifacts under
NN.Examples.Interop.PyTorch.{MLP,CNN,Transformer}.Import. They may support
serious verification workflows, but they still bake in model-family key conventions. The runtime
bridge stays model-agnostic.