int8 Autoregressive Generation
A decoder-only (GPT-style) nano language model that generates text one token at a time, entirely in int8. This is the decoder family in its real loop: QCausalAttention1D::step() over a fixed KV state, an output head, and greedy (argmax) decoding that feeds each predicted token back as the next input.
How it works
- Per step:
QEmbeddinggathers the current token, aQAddinjects the positional row, thenQLayerNorm1D→QCausalAttention1D::step()→QAddskip →QLayerNorm1D→QDense→qrelu→QDense→QAddskip →QDensehead →argmaxover the int8 logits picks the next token. - O(1) attention memory. The decode loop never calls
forward()— onlystep(). The entire attended history lives in a fixedE × EQLinearKVState(cpp/qkvcache.hpp), so the model generates an arbitrarily long sequence with the same state size after token 100 as after token 1. There is no growing KV cache — exactly what makes autoregressive decoding fit on an MCU. - int8 reproduces float.
argmaxis invariant under a positive affine map, so an int8 logit grid reproduces the float reference’s arg-max whenever the top-1 margin clears the quantization step. The driver runs the identical model in float and asserts the int8 greedy decode picks the same tokens — 48/48 on the bundled run. - The nano-LM is hand-wired as a deterministic “+1 counter”: orthogonal one-hot token embeddings carried by the residual path and a shift-by-one readout head, so greedy decode emits
token+1 (mod VOCAB)each step. That makes the output an interpretable sawtooth rather than a collapsed constant, while the attention/FFN/KV machinery still runs underneath.
Build and run
cd examples/tiny_generate_int8
make release
make run
make plot # needs matplotlib; a venv/pyenv works if it is not already in your Python
Built with -DTINYMIND_ENABLE_QUANTIZATION=1 (plus FLOAT=1 STD=1 for host calibration). Extra target:
make golden— generated int8 token streams for the bundled prompts tooutput/tiny_generate_int8.golden
Output

Each panel is one seed prompt’s generated sequence: the blue step line is the float reference, the orange ×-markers are the int8 greedy decode. Every marker lands on the float line — the int8 model picks the same token at every step (48/48). The sawtooth is the +1 (mod 8) counter each prompt continues from its last seed token.