Module Execution #
This file connects typed module definitions to executable scalar modules. It provides parameter initialization, execution settings, and helpers that select a scalar type and device from command line arguments.
ScalarModuleDef describes the forward and loss programs together with their parameter and input
shapes. Instantiating it produces a mutable ScalarModule that can evaluate inputs, run backward,
and update parameters. The shape lists remain part of both types, so construction and execution use
the same parameter ordering.
Instantiate a ScalarModuleDef under explicit Torch options such as backend and device.
The supplied options are passed unchanged to module construction, including the selected device and execution strategy.
Instances For
Instantiate a Float module with runtime layer parameter initializers.
The initializer plan is indexed by the same paramShapes list as the module, so Lean checks that
every parameter has exactly one initializer.
In CUDA mode, supported initializers allocate device buffers directly instead of first constructing
every parameter as a large nested Lean tensor.
Instances For
List-based wrapper for checkpoint/JSON boundaries.
If the caller has a statically known parameter list, prefer
instantiateFloatWithPlan; this wrapper checks the list length before applying it.
Instances For
Execution configuration parsed from CLI flags.
Supported flags (parsed by ExecConfig.parseAndStrip):
--dtype .../--float32-mode ...(seeTorchLean.Runtime.DType)--backend eager|compiled--device auto|cpu|cuda|rocm|metal|wasm|tpu|trainium|custom|external--show-backend(print backend capsules when the eager runtime first executes them)
- dtype : Runtime.DType
Scalar dtype selection.
- backend : Backend
Execution backend selection.
- device : NN.Backend.Device
Explicit eager execution device.
- showBackend : Bool
Print each backend capsule when the eager runtime first executes it.
Instances For
Instances For
Parse a CLI device selector. auto currently resolves to the portable CPU runtime.
Instances For
Whether a raw CLI argument list explicitly requests CUDA.
Instances For
Parse CLI flags handled by ExecConfig and return (cfg, rest).
Consumed flags:
--backend eager|compiled(at most once),--device auto|cpu|cuda|rocm|metal|wasm|tpu|trainium|custom|external,--show-backend(boolean flag; removed fromrest).
All dtype/Float32 selection flags are delegated to
TorchLean.Runtime.DType.parseAndStripWithDefault.
Default dtype policy:
- If the user does not specify
--dtype/--float32-modeand CUDA is selected, default todtype=float(CUDA eager supportsFloatupload/download). - Otherwise default to
dtype=float32(executable IEEE-754 float32 semantics).
Named future devices are accepted at parse time so --show-backend and planning diagnostics can
explain them. Runtime session creation still rejects devices that this build cannot execute.
The selected device chooses its normal registered kernels. Users do not need a second performance flag after selecting CUDA or another accelerator.
Instances For
Convert a parsed CLI execution config to runtime Options.
Instances For
Parse CLI flags with the standard TorchLean default dtype policy.
Instances For
Log the chosen execution config to stdout for reproducible runs.
Instances For
Parse runtime flags (--dtype, --backend, --device, --show-backend) and choose an executable
scalar α, then call k with:
cast : Float → αfor building inputs from literalsopts : Optionsselecting the backend/kernel moderest : List Stringcontaining the remaining CLI arguments
This is useful for scripts that need to build a dataset/loader (and maybe determine shapes/batch
sizes) before instantiating a concrete ScalarModuleDef.
Instances For
Instantiate a ScalarModuleDef under CLI runtime flags (--dtype, --backend, --device,
--show-backend), then call a continuation.
This provides the cast function Float → α so call sites can build inputs from float literals.
Instances For
Like withModule, but also provides an _root_.TorchLean.Runtime.FromFloat α instance (for numeric literals).