Documentation
¶
Overview ¶
Command espressoe5rtstack runs a stack of transformer blocks on the Neural Engine through the private e5rt direct-dispatch route, in one dispatch, and checks what comes back against a float64 CPU reference of the whole stack. It calls the generated private/espresso binding through the example-local espressoe5rt adapter.
e5rtblock runs one block and closes its second residual on the host. That is fine for one block and wrong for a stack: a host round trip between every layer is most of the cost of a small model, and it makes the example say nothing about whether a deep graph can be encoded at all. This program keeps everything on the engine. The host writes the input once, calls execute once, and reads the output once, whatever the depth.
Closing the residual on the device ¶
Each layer is three programs. GenSDPAForward ends in add(x, projection), so it carries the first residual itself. GenFFNForwardRMSReLU2 carries neither, so the second residual is a third program here: a two-input elementwise add, generated by genAdd below, whose output buffer is the next layer's input buffer. Nothing is copied between layers and the host never sees an intermediate activation.
That makes 3N programs, all encoded into an execution stream in order. Order is what the stream runs them in; it does not reorder operations to satisfy a dependency, so encoding a layer's residual add before the feed forward it reads yields a stale result rather than an error.
Fifteen functions, and how to go deeper ¶
A process can hold a live precompiled compute operation on at most fifteen distinct functions at once. The first operation on a sixteenth function fails with status 13, which caps this design at five layers, since each layer is three functions.
The limit counts functions, not operations and not weights. Five hundred operations on one function are accepted, and so are forty compiled functions that carry no operations; what is refused is the operation that would bring one more function into use. It is a different limit from the weight file ceiling. The program measures it on every run rather than assuming it, by taking an operation on each compiled function in turn until one is refused — see probeFunctionBudget.
Releasing an operation frees its function's slot, but releasing one that has already been encoded does not, because the stream holds it. Releasing the stream frees them all. So a stack deeper than five layers runs in phases: encode what fits, execute, release the stream, encode the next group. Every buffer is allocated once and stays bound across the boundary, so the phases hand activations to each other in place — what a phase boundary costs is the encode, not a copy or a host round trip. Sixteen layers run this way here.
The pool is shared between processes rather than reserved per process, so a second copy of this program running at the same time gets whatever is left. That is why the budget is measured rather than assumed, and why execute narrows its phases further if a phase will not encode.
The weight file ceiling is per compile ¶
One attention program needs six weight files and one feed forward program needs three. Nine per layer, and the compiler stops accepting weight files at sixteen — so a stack that put every layer's weights in one directory would fail to compile at two layers. It compiles here because each program is compiled separately from its own directory, which is what makes the ceiling a per-compile limit rather than a limit on model size. Packing many tensors into one file is the other way around it; see x/ane/mil's BlobWriter.
What is checked ¶
The reference recomputes every layer in float64 from the same weights. Depth is the thing this program adds over e5rtblock, so it also checks that the depth is real: each layer's attention scores must have enough spread that the softmax selects rather than averages, and the N-layer result must differ from the (N-1)-layer result by more than the tolerance. Without that second check a stack whose later layers contributed nothing would pass exactly as well as one that worked.
Residual growth is reported per layer. Every value on the engine is fp16, and a residual stream that grows geometrically with depth runs out of range; the program prints the peak magnitude after each layer so a stack approaching that limit is visible rather than silently wrong.
go run ./examples/ane/espressoe5rtstack go run ./examples/ane/espressoe5rtstack -layers 6 -dim 128 -heads 8 -seq 32 -hidden 256