Skip to content

Engine equivalence suite

tests/engine/ holds every kernel a stage can compute with to its reference: the same logits as the eager float32 model, within a tolerance set by the dtype the kernel computes in. A new kernel, cache layout or backend passes it before it merges; a swapped kernel (another int4 matmul, say) is safe once it does.

It runs on tiny random models (Llama, Qwen3, Qwen3.5 hybrid, GPT-2: two to four layers of width 64, no downloads), on the CPU in CI in well under a minute, and by hand on a card. Every model family with an architecture adapter (pipe/engine/arch/) has a tiny model too - Qwen2, Qwen3-MoE, Mixtral, Qwen3.5-MoE, Qwen3-Next, GPT-NeoX, and Mistral for the families read structurally - checked by test_arch.py. CI runs the suite on the oldest transformers pyproject.toml allows and on the fellow image's pin (OLDEST_TRANSFORMERS / NEWEST_TRANSFORMERS in pipe/engine/arch/family.py, held to the CI matrix by tests/unit/pipe/engine/test_arch_families.py), and a third time on the newest release under the cap (latest): requirements-runtime.txt does not pin transformers, so a fellow installed by the bootstrap gets that one. The latest leg warns rather than blocks a merge.

What it checks

File Kernel or path Reference
test_attention.py sdpa, swarm_sdpa (expanded KV heads, training), swarm_grouped, swarm_lean over sdpa and over grouped; prefill whole and in pieces, decode, batched decode; float32, bfloat16, float16 eager float32 over the whole sequence, no cache; forward and a gradient for training
test_kv_cache.py growing cache stored native, float16, int8: append, roll back (speculative decoding), park and unpark, copy a prefix, trim; the hybrid cache the eager reference, and a fresh run of the same storage
test_graphs.py decode graphs (uncaptured on the CPU, recorded on CUDA), the check at load, a replay repeated bit for bit, the draft model's static decoder the eager step of the same engine; the eager reference
test_weights.py half-stored frozen weights (whole and in row chunks, forward and backward), bitsandbytes 4-bit and 8-bit, 4-bit calls split by rows or computed in float32, torchao int4 float32 weights with the same rounded values; the layer's own dequantized weight; the layer called as it is
test_fused.py the fused small ops (#82): RMSNorm, and rotary with the cache write per layer, as torch ops and as Triton kernels (in Triton's interpreter on the CPU, compiled on a card); one session eager and from recorded steps, batched on slots (eager and recorded) and copied; the check at load and what it refuses the same stage with the ops unfused; transformers' arithmetic op by op
test_linear_attention.py flash-linear-attention's delta rule and conv update transformers' torch path (itself held to the reference by every Qwen3.5 case above)
test_arch.py every architecture adapter: a stage prefilling (whole and in pieces) and decoding, two stages passing only the hidden state; the adapter's layer kinds, linear-attention state, experts, numbers and draft support against the loaded model the family's own eager float32 forward; the model's modules and cache
test_parallel.py exact tensor parallel (pipe/engine/parallel.py): Llama, Qwen2 and Qwen3 split over two ranks (gloo, one process each) - key/value heads split and replicated, biases, query/key norms, a tied head, an uneven vocabulary; prefill then decode over the cache; families without a plan refused the unsplit float32 model's logits, on rank 0
test_boundary.py every boundary codec: fixed_intN, a bottleneck's N-bit and float16 codes, plain and bfloat16 frames what the model trained on: bit for bit where the boundary is quantized
test_select_rows.py every choice of the kernel selection table (pipe/engine/select.py): each row's every value maps to a case above the table itself, over a grid of cards, dtypes, models and settings

Which of these kernels a stage runs is decided in one place, pipe/engine/select.py: a pure function of the cards (backend, compute capabilities, installed kernel packages), the stage (dtype, model, quantization) and what was asked, unit-tested per card class in tests/unit/pipe/engine/. A stage prints its choices with their reasons once at load ([stageN kernels] lines in the fellow log) and reports them in its ready event, which the fellow passes on in the loaded model's entry of its heartbeat (kernels). The rows that depend on the cards alone (training attention, linear attention, int4 serving, decode graphs) are in the node's runtime report (RuntimeReport.kernels), and the fellow declares serve-int4-fast on the table's own rule (select.int4_serving). A new value in the table needs a case here.

Each tolerance is written beside its check with the reason for it: runtime/torch/equivalence.py (KERNEL_TOLERANCE) has the per-dtype ones, the test files the ones a storage or a quantizer adds. A wrong mask, position or head mapping is off by tenths, far above every limit; do not widen one to make a kernel pass.

fellow conformance runs the checks it shares with the suite - the 4-bit and int4 layers, CUDA graph replay, a repeatable forward, the wire codecs - from the same module, so a fellow's card is held to the same arithmetic.

Run it

python -m pytest tests/engine -q                  # CPU, what CI runs
python -m pytest tests/engine -q --device cuda    # on a GPU fellow (or cuda:1, mps)
python -m pytest tests/engine -q --device cuda -m gpu   # only the cases that need NVIDIA

It needs the runtime extra (torch and transformers); without them nothing is collected. SWARM_ENGINE_DEVICE=cuda does what --device cuda does. On a machine you care about, put it under scripts/memcap.sh.

test_parallel.py also checks a real checkpoint when asked: SWARM_TP_REAL_MODEL=Qwen/Qwen3-0.6B (a model already in the Hugging Face cache) splits it over two ranks and compares their logits with the unsplit model's. Each rank loads it in bfloat16, keeps its slice and upcasts only that (about 1.4 GB resident per rank for Qwen3-0.6B); rank 0 computes the unsplit reference first, alone. It runs under scripts/memcap.sh --max 4G.

The run on a card

On the CPU these cases skip, each with its reason (-rs lists them):

Cases Need
every float16 case of test_attention.py a card (--device cuda or mps): the CPU's half kernels are not the ones a card runs
the expanded-KV branch taken natively an NVIDIA card older than Ampere (GTX 10xx/16xx, RTX 20xx)
decode graphs recorded and replayed, the draft model's graphs, graph_replay_error CUDA
torchao int4 (layer, conformance check, block placement) CUDA, compute capability 8.0 or newer, torchao
flash-linear-attention delta rule and conv update CUDA, compute capability 8.0 or newer, fla and triton

So a release wants the suite run with --device cuda on one pre-Ampere card and one Ampere or newer card, and with --device mps on an Apple silicon Mac. The 4-bit cases already run on the CPU, which bitsandbytes serves by dequantizing; on a card they reach its fused kernels.

Adding a kernel

  1. Import it in tests/engine/kernels.py, the one place the suite names production modules, and if it is an attention implementation add it to ATTENTION and set_attention.
  2. Add it to the parametrization of the file that checks its kind, with the reference it must match. A kernel that needs a card calls needs(device, ...) with what it needs.
  3. If the kernel computes in a way the existing tolerances do not describe, give it its own limit and write down why next to it.

Adding a model family

  1. Write its adapter, pipe/engine/arch/<family>.py: a Family subclass (from family.py, or DenseRotary, LinearAttentionHybrid, RoutedExperts) overriding only what differs, and list it in registry.FAMILIES. It must stay torch-free (only adapter.py imports torch): the leader plans with the same adapters (tests/unit/test_layering.py, zone pipe.engine.rules). A family known not to run block by block goes into registry.UNSUPPORTED with its reason instead, so a job asking for it is held at plan time.
  2. Add a tiny config to MORE_FAMILIES in tests/engine/harness.py; test_arch.py fails until every registered adapter has one.
  3. Run the suite on both transformers releases CI runs (a pip install --target of the older one on PYTHONPATH is enough on a dev machine).