mindXtrain / docs /architecture.md
Gregory-L's picture
fork mindXtrain from GitHub (Professor-Codephreak/mindXtrain@661bd41) as the mindX-specific line
dfb775d verified
|
Raw History Blame Contribute Delete
9.17 kB
# Architecture
`mindxtrain` is a single-package training framework producing checkpoints with
verifiable provenance, served through an OpenAI-compatible API. The repository
is organized per `docs/blueprints/mindxtrain2.md` Β§Part 4.
```
mindxtrain/
β”œβ”€β”€ cli/ entry point (typer): init|bench|train|eval|quantize|serve|publish|receipt
β”œβ”€β”€ config/ Pydantic schema + JSON / YAML loaders
β”œβ”€β”€ data/ curate -> dedupe -> filter -> tokenize -> pack -> synth -> verify
β”œβ”€β”€ models/ ModelRegistry + ChatTemplate + per-base presets
β”œβ”€β”€ train/ sft, dpo, grpo, rlhf, tool_use, distributed, callbacks, recipes/*.yaml
β”œβ”€β”€ eval/ lighteval, inspect_ai, bfcl, persona/agenda regression, tau_bench, card
β”œβ”€β”€ autotune/ 60-second AOT MI300X probe (the differentiator)
β”œβ”€β”€ operator/ FastAPI app, Coach UI, ml-intern patterns (tool_router, agent_loop, …)
β”œβ”€β”€ storage/ StorageProvider interface + local_fs / hf_hub / lighthouse / ipfs
β”œβ”€β”€ provenance/ TrainingRun manifest, BLAKE3, ERC-8004, Algorand, x402
β”œβ”€β”€ deploy/ content-addressed registry, hot_swap, ab_test, vllm/sglang launchers, quark
└── budget/ psutil-derived ResourceBudget + per-provider pricing
```
## The five conceptual layers
The codebase is concentric β€” each inner layer is consumed by the next, never
the reverse.
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 1. CLI layer (typer) β”‚
β”‚ init | bench | train | dataset prep | eval | quantize β”‚
β”‚ serve | publish | receipt β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 2. Autotune layer (60s AOT probe β€” DIFFERENTIATOR) β”‚
β”‚ attention_probe (CK vs Triton) β”‚ gemm_probe β”‚ rccl β”‚
β”‚ ↓ β”‚
β”‚ AutotunePlan (JSON, AOT β€” JIT autotune is forbidden) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 3. Dataset layer β”‚
β”‚ HF datasets streaming β†’ MinHash + SemDeDup β†’ packing β”‚
β”‚ β†’ FSDP sharding β†’ Lighthouse-pinned CIDs β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 4. Training layer (backend dispatch) β”‚
β”‚ axolotl β”‚ unsloth β”‚ torchtune β”‚ primus β”‚
β”‚ LoRA β”‚ QLoRA β”‚ full SFT β”‚ DPO β”‚ ORPO β”‚ GRPO β”‚ GSPO β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 5. Artifact + Integration layer β”‚
β”‚ Quark FP8 / MXFP4 β†’ lm-eval-harness β”‚
β”‚ β†’ HF Hub push β†’ Lighthouse pin β”‚
β”‚ β†’ mindX register β†’ AgenticPlace listing β”‚
β”‚ β†’ BANKON ENS subname β†’ x402 Algorand metering β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
The CLI never reaches into the training backend; it consumes the autotune plan
and a Pydantic-validated config and dispatches downward through
`mindxtrain/train/dispatch.py`. The training backend never reaches up to the
CLI; it returns a checkpoint directory that the artifact layer consumes.
## Autotune is the spine
The single architectural choice that distinguishes mindxtrain from Axolotl,
LLaMA-Factory, Unsloth, torchtune and Primus is the autotune layer. It runs a
**60-second MI300X micro-benchmark** (CK-vs-Triton SDPA, hipBLASLt heuristic
check, RCCL bus-bandwidth probe) and emits a static `AutotunePlan` JSON
consumed at training start.
**AOT-only β€” JIT autotune is forbidden in production.** The plan is fixed at
training start; no Triton / Inductor / MIOpen JIT autotune runs in the live
training loop. This is reproducible, latency-stable, and the point of the
entire framework.
See [autotune.md](autotune.md) for the full probe taxonomy and the
`AutotunePlan` schema.
## MI300X-specific invariants (non-negotiable)
These are encoded in the schema and the recipe library; violating them is a
deployment bug.
1. **FSDP topology must be 1- or 8-GPU** (`hardware.gpus: Literal[1, 8]`). The
2- and 4-GPU groups have asymmetric xGMI bandwidth on MI300X β€” kills
throughput silently. Enforced by the schema; tested in
`tests/test_config_schema.py`.
2. **`PYTORCH_ROCM_ARCH=gfx942`** must be set; AOTriton compiles for the GPU
arch and `gfx942` is MI300X. Default in every recipe's `train.env`.
3. **`HSA_NO_SCRATCH_RECLAIM=1`** + **`HIP_FORCE_DEV_KERNARG=1`** +
**`GPU_MAX_HW_QUEUES=1`** β€” the three runtime knobs that make Primus-Turbo
MI300X paths stable. Default in every recipe's `train.env`.
4. **Numpy must be pinned `<2.0`** against `torch==2.9.1+rocm7.2.1.lw`. Pinned
in the project `pyproject.toml`.
5. **Container is `rocm/primus:v26.2`**; SHA256 digest snapshot lives in
`ops/containerfiles/digest.lock`.
## End-to-end data flow
```
examples/demo_qwen3_8b_sft.yaml
β”‚
β”œβ”€[parse, validate]─► XTrainConfig (Pydantic v2)
β”‚
β”œβ”€[mindxtrain bench]─► AutotunePlan {ck/triton, gemm, rccl, …}
β”‚ β”‚
β”‚ β–Ό
β”œβ”€[mindxtrain train]──► dispatch_training(cfg, plan, out_dir)
β”‚ β”‚
β”‚ β–Ό (Axolotl YAML, env vars set)
β”‚ checkpoint_dir/ + train.log
β”‚ β”‚
β”œβ”€[mindxtrain eval]─────► eval.json (lm-eval-harness)
β”‚ β”‚
β”œβ”€[mindxtrain quantize]─► checkpoint_dir/quantized/ (Quark FP8 PTPC)
β”‚ β”‚
└─[mindxtrain publish]──► Manifest with BLAKE3 of YAML+dataset+
checkpoint+eval, plus HF/Lighthouse/
INFT/ASA pointers
β”‚
β–Ό
mindxtrain.operator.app serves the FP8
weights on /v1/chat/completions
```
`mindxtrain receipt` re-hashes the artifacts and verifies the BLAKE3 fields
against the manifest. That round-trip is the cypherpunk2048 reproducibility
guarantee.
## Model strategy (per mindxtrain2.md Β§Part 6)
mindxtrain targets a **family**, not a single flagship: edge β†’ mid β†’
flagship β†’ specialist. Per the rigorous comparison in
[`blueprints/mindXtrain2.md`](blueprints/mindXtrain2.md) Β§Part 6:
- **Primary base = Qwen3.5** (Apache-2.0, contiguous family from 0.6 B β†’
235 B β†’ Qwen3.5-122B-A10B; mature PEFT/Axolotl/Unsloth recipes; BFCL
leadership in the Qwen lineage).
- **Specialist track = GLM-5.1** (MIT-licensed weights; SOTA SWE-Bench Pro
58.4; long-horizon agentic reasoning with 200 K-context DSA). Used where
8-hour autonomous SWE sessions matter; otherwise overkill.
- DeepSeek V3.2 / Mistral Large 3 / Phi-4-mini / Gemma 4 are watchlist or
jurisdictional secondary tracks.
The five `mindxtrain.models.{glm51,qwen35,deepseek_v32,mistral3,phi4_mini}.py`
preset modules auto-register on import so `mindxtrain init` and the
`ModelRegistry` know all five from day one.
## Actualization status
The framework ships with **38 modules actualized** as real Python on a
CPU-only laptop, **6 optional-dep groups** (`ml`, `eval`, `data`, `serve`,
`chain`, `obs`) for the heavyweight paths, and **5 cloud-provider stubs**
preserved in `budget/providers/*` for future work. Per-module map at
[actualization_status.md](actualization_status.md).
Verification gate that should always pass on the base install:
```bash
uv run pytest -q # β†’ 564 passed
uv run ruff check . # clean
```
## What lives outside the Python tree
- `contracts/` β€” Foundry workspace for `mindxtrain_registry.sol` (write-once
anchor) and `x402_receiver.sol` (immutable facilitator). No proxies, no
admin keys, no setters.
- `examples/` β€” `demo_qwen3_8b_sft.yaml` (the hero config).
- `Containerfile`, `compose.yaml` β€” top-level Podman / podman-compose entries.
- `ops/` β€” per-role container files, compose stacks, k8s manifests, vmm and
Gensyn definitions.
- `docs/blueprints/` β€” the source design briefs the project was built against.