TorchLean API

NN.Runtime.PyTorch.Import.MLP

MLP PyTorch Reference Import #

MLP reference weight import from a PyTorch-style state_dict.

On the Python side we usually write JSON (nested lists of floats) under keys that mirror the names you would see in model.state_dict():

This file keeps the parsing logic in one place so the rest of the codebase can talk in terms of typed Lean tensors.

structure Import.PyTorch.MLP.Parameters (inputWidth hiddenWidth outputWidth : ) :

Parameters for a two-layer MLP imported from a PyTorch state_dict.

We keep the tensors as Float because these importers are meant for runtime examples: train in Python, export to JSON, then run/verify in TorchLean.

Instances For
    def Import.PyTorch.MLP.load (inputWidth hiddenWidth outputWidth : ) (json : Lean.Json) :
    Option (Parameters inputWidth hiddenWidth outputWidth)

    Load MLP parameters from JSON using either supported PyTorch key convention.

    Instances For
      def Import.PyTorch.MLP.forward {inputWidth hiddenWidth outputWidth : } (parameters : Parameters inputWidth hiddenWidth outputWidth) (input : TorchLean.Tensor Float [inputWidth]) :

      Run the imported two-layer MLP.

      Instances For