Bring model definitions into Go.
Extract supported model definitions into an inspectable representation, check their structure, and generate Go implementations. ModelIR connects model source and configuration to the MLX-Go toolchain.
Experimental. Source is private, available for technical review on request.
What it does- Read model structure. Frontends handle supported Python, Go, and Swift definitions. A configuration reader turns Hugging Face model metadata into ModelIR.
- Keep the model inspectable. Represent graph operations, architecture metadata, and cache contracts in a form that can be formatted, validated, and compared.
- Generate implementations. Emit Go source and target-specific artifacts from supported definitions. Each target owns its lowering rules.
- Track upstream changes. The
mlx-go-lmgenerator consumes ModelIR while owning model discovery, package layout, and runtime integration.
ModelIR keeps model structure separate from the runtime that executes it. Inspect the definition, compare a changed version, and generate the supported implementation for the chosen target.
modelir from-config config.json
modelir fmt model.modelir
modelir diff before.modelir after.modelir
What has to survive translation
A model port needs more than a matching list of layers. Weight paths, precision choices, normalization stages, and state carried between tokens affect execution. ModelIR makes these facts explicit so a target can preserve them or report what it cannot support.
- Source identity. Freshness checks bind selected artifacts to the source bytes they describe, so changed inputs require a new check.
- Checkpoint geometry. Source-derived weight structure is checked before materialization. A plausible tensor shape alone is insufficient.
- State across tokens. Selected Gated Delta Network fixtures check that returned caches reach the following decode step.
- Numerical comparisons. Reference checks use explicit tolerances. Generating source and comparing runtime outputs are separate stages.
Recent work strengthens source freshness, checkpoint checks, and cache continuity in selected conformance fixtures. Host checks describe the tested fixtures; numerical and hardware qualification remain specific to the model, target, and revision.
Read the build note: what a generated model needs to preserve ↗
Related workmlx-go supplies the array runtime. mlx-go-lm uses ModelIR in its model-generation pipeline and provides loading, inference, serving, and fine-tuning.
source private, available for technical review on request
contact Discuss a model integration ↗