Documentation
¶
Overview ¶
Experimental — this package is not yet wired into the main framework.
Package modeldsl provides a declarative DSL for defining custom model architectures using Go structs. Model definitions are validated and compiled into runnable graphs that support forward inference.
Package modeldsl provides a declarative DSL for defining custom model architectures using Go structs. Model definitions are validated and compiled into runnable graphs that support forward inference.
Package modeldsl provides training support for DSL-defined models.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnectionDef ¶
ConnectionDef specifies a directed edge from one layer to another.
type LayerType ¶
type LayerType string
LayerType identifies the kind of neural network layer.
const FusedLayerType LayerType = "fused"
FusedLayerType is the type used for fused operator layers.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is a runnable model built from a ModelGraph.
func (*Model) Parameters ¶
Parameters returns all trainable parameters of the model.
func (*Model) Train ¶
func (m *Model) Train(config TrainConfig, samples []Sample) (*TrainResult, error)
Train runs a training loop over the given samples using mean squared error loss. It performs gradient descent using the specified learning rate.
type ModelDef ¶
type ModelDef struct {
Name string
Layers []LayerDef
Connections []ConnectionDef
}
ModelDef is the top-level model definition.
type ModelGraph ¶
type ModelGraph struct {
// contains filtered or unexported fields
}
ModelGraph is the validated internal representation of a model definition. Use Build to instantiate a runnable Model from it.
func ConstantFolding ¶
func ConstantFolding(g *ModelGraph) *ModelGraph
ConstantFolding removes layers whose output can be determined statically. In this DSL, identity-like element-wise layers (RMSNorm, SiLU, Softmax) that feed into another element-wise layer of the same type are collapsed: the duplicate is removed because applying the same normalization/activation twice is redundant. Additionally, consecutive identical element-wise layers are folded into one.
func DeadNodeElimination ¶
func DeadNodeElimination(g *ModelGraph) *ModelGraph
DeadNodeElimination removes layers that do not contribute to the model's terminal output. A node is "dead" if no path from it reaches any node that is both an output (no children) and reachable from an input (no parents). When there are dangling branches (leaf nodes only reachable through a fork), they are pruned because they don't contribute to the primary output path.
Specifically, it traces backward from each output that lies on a path starting from an input, matching Model.Forward semantics.
func OperatorFusion ¶
func OperatorFusion(g *ModelGraph) *ModelGraph
OperatorFusion merges sequences of compatible layers into fused operators. Currently supported fusions:
- RMSNorm followed by SiLU → fused "rmsnorm_silu"
- SiLU followed by RMSNorm → fused "silu_rmsnorm"
func Optimize ¶
func Optimize(g *ModelGraph, passes ...OptimizePass) *ModelGraph
Optimize applies a sequence of optimization passes to a graph, returning a new optimized graph. The original graph is not modified.
func Parse ¶
func Parse(def *ModelDef) (*ModelGraph, error)
Parse validates a ModelDef and builds a ModelGraph.
func (*ModelGraph) Build ¶
func (g *ModelGraph) Build(inputDim, outputDim int) (*Model, error)
Build instantiates a runnable Model from the graph. inputDim and outputDim specify the dimensions of the model's input and output vectors.
func (*ModelGraph) BuildTrainable ¶
func (g *ModelGraph) BuildTrainable(inputDim, outputDim int) (*Model, error)
BuildTrainable instantiates a trainable Model from the graph. Unlike Build, the returned Model supports backward pass and parameter updates.
func (*ModelGraph) Inputs ¶
func (g *ModelGraph) Inputs() []string
Inputs returns the names of input layers (layers with no parents).
func (*ModelGraph) Order ¶
func (g *ModelGraph) Order() []string
Order returns the topological execution order of layer names.
func (*ModelGraph) Outputs ¶
func (g *ModelGraph) Outputs() []string
Outputs returns the names of output layers (layers with no children).
type OptimizePass ¶
type OptimizePass func(g *ModelGraph) *ModelGraph
OptimizePass is a named graph transformation.
type TrainConfig ¶
TrainConfig configures a training run.