TECHNOLOGY

MLX sequence packing: real tokens, segment isolation and warm timing

In this article
THE QUICK TAKE

Packing must preserve segment attention and loss semantics; the reported token speed depends on short-example shape and how compilation is timed.

The sequence-packing result attributed vaguely to MLX comes from the separate mlx-train-perf project. Its author reports faster processing of short instruction examples by grouping them into fixed-size rows. The relevant comparison measures useful sequence content per second under a particular training harness; it is not a universal speed multiplier for MLX.

Recover the exact experiment

The pinned project README identifies an M1 Max with 32 GB, MLX 0.32.0 and an Alpaca sample. The documented Qwen3-8B-4bit comparison moves from 33.1 to 99.2 real tokens/s. Conditions include rank 8 LoRA, batch 1, gradient checkpointing, bf16 computation and a packing length of 4096.

These details establish an author measurement with a reproducible starting point, rather than an independent reproduction. A four-bit checkpoint describes weight storage, while the computation dtype is a separate condition. Neither label establishes the optimizer state, attention workspace or maximum trainable context on another machine.

Understand what packing changes

The packing implementation groups examples with a seeded per-epoch shuffle and tracks segment boundaries. Packed rows retain separate example identities instead of allowing ordinary causal attention to cross from one example into another. The project’s custom attention path consumes segment information, avoiding a large explicitly materialized block mask.

That boundary is part of the training objective. A fast concatenation that exposes one example to the preceding unrelated example changes the problem. Check token-level attention permissions and response-loss masking independently. Similar average loss on a small fixture is useful evidence, but does not certify identical long-run optimization or downstream quality.

The numerator is content, not just supervised answers

The benchmark worker computes throughput from deterministic content counts and median measured step time. Padding and separators are excluded from the reported real-token numerator. That does not make the numerator synonymous with response-only supervised tokens: instruction content can occupy the sequence even when its loss is masked.

For a local comparison, report content tokens, supervised tokens and completed examples separately. Equal step counts do not imply equal amounts of data when a packed row contains many examples. The gradient-accumulation denominator guide explains why the unit used to average loss also deserves preservation.

Compilation affects the advertised ratio

The author explicitly notes that stock batch widths vary, so initial compiled traces can enter their median timings. Fixed packed shapes avoid that variation. A long run amortizes the stock traces, and the README gives a more conservative warm-step interpretation around 2.0–2.3 times, rather than treating the headline ratio as invariant.

Therefore, separate cold preparation, compilation and repeated warm execution. A short experiment can legitimately include initialization costs, but that choice needs to match the intended workload. A short-example corpus and a corpus already filling each context are different capacity and throughput cases.

Evaluate the complete training result

The inspected worker performs actual training steps and distinguishes valid measurements from aborted conditions. This review inspected code without running it. The published throughput does not establish improved task accuracy, lower peak memory for every configuration or equal time to a chosen quality target.

Preserve the dataset digest, tokenizer, packing seed, model revision and timing window alongside final validation. Use the reproducible stack guide to record the custom kernels as well as MLX itself. Packing is useful when segment isolation, learning semantics and measured workload efficiency all survive that comparison.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles