Draft from a reference implementation
spec new reads a graph exported with torch.export. It strips engineering nodes (KV-cache updates, device and dtype moves, views that only reorganise memory, backend branches) and maps recognised subgraphs onto Op Specs:
Unrecognised compute nodes are kept as placeholders marked
-- REVIEW:. The draft is a starting point: publish it only after a human review and a conformance check.
How models are defined in the library
The spec library (specs/) defines each architecture family as a function from its Hugging Face hyperparameters to a model configuration (ModelCfg). That is where the architecture knowledge lives: which norms, which RoPE variant, which multipliers. specs/TheFormalEra/Spec/Families.lean has five families today: Qwen3Hyper, Qwen35Hyper, GraniteHyper, Gemma4Hyper and MuseHyper.
A model is then one record of hyperparameters plus one registry entry (specs/TheFormalEra/Spec/Registry.lean):
toHF, which renders the hyperparameters back in config.json form. The conformance check compares that rendering with the published config.json, field by field.
To add a checkpoint of an existing family, add its record, a reduced record with the same layer pattern, and a registry entry. To add a new architecture, add a family. The compute graph (TheFormalEra.Models.Graph), the executable oracle and the CLI then pick it up.
Check a spec package
spec check:
- runs
lake build: the definitions type-check and every proof is checked; - runs the axiom audit (
Audit.lean): every listed theorem depends only onpropext,Classical.choiceandQuot.sound; - exports each model’s graph and checks it is connected: every node input is produced by another node, except the graph’s inputs (
tokens,positions,seq_lens) and cache values.
