TorchLean API

NN.Runtime.PyTorch.Export.CNN

Convolutional PyTorch Reference Export #

PyTorch exporter for the two-block convolutional round-trip reference model.

The Lean configuration is rank-parametric. PyTorch itself exposes separate Conv1d, Conv2d, and Conv3d classes, so that distinction is introduced only while rendering the external Python code.

The generated model has two convolution, ReLU, and max-pool blocks followed by Flatten and one Linear head.

structure Export.PyTorch.CNN.ConvolutionConfig (spatialRank : ) :

Rank-parametric configuration for a PyTorch convolution layer.

Instances For
    structure Export.PyTorch.CNN.PoolingConfig (spatialRank : ) :

    Rank-parametric configuration for a PyTorch max-pooling layer.

    Instances For
      structure Export.PyTorch.CNN.Config (spatialRank : ) :

      Configuration for the 2-block CNN exporter.

      • className : String

        Class name to use in the generated Python.

      • inputChannels :

        Input channels.

      • inputSpatial : TorchLean.Tensor [spatialRank]

        Input extent along each spatial axis.

      • firstConvolution : ConvolutionConfig spatialRank

        First convolution.

      • firstPooling : PoolingConfig spatialRank

        First pooling layer.

      • secondConvolution : ConvolutionConfig spatialRank

        Second convolution.

      • secondPooling : PoolingConfig spatialRank

        Second pooling layer.

      • flattenedWidth :

        Flattened feature count consumed by the linear head.

      • outputWidth :

        Output width of the linear head.

      Instances For

        Render a tensor shape as a Python tuple.

        Instances For

          Select the rank-specific class name required by PyTorch's public API.

          Instances For
            def Export.PyTorch.CNN.classSource {spatialRank : } (config : Config spatialRank) :

            Render the two-block CNN as a Python nn.Module class definition.

            Instances For
              def Export.PyTorch.CNN.withParameters {spatialRank : } (config : Config spatialRank) (firstConvolutionWeight firstConvolutionBias secondConvolutionWeight secondConvolutionBias classifierWeight classifierBias : String) :

              Generate a Python CNN module plus a helper that loads explicit weights from string literals.

              This is mainly used for examples: you can paste JSON/Lean-rendered weight arrays into Python and run the model without writing an extra serializer.

              Instances For