Documentation
¶
Overview ¶
Command e5rtblock runs a transformer block on the Neural Engine through the private e5rt direct-dispatch route, and checks what comes back against a float64 CPU reference of the whole block.
The other e5rt example, e5rtdispatch, proves the route runs by dispatching a 1x1 convolution. This one runs work with the shape of a real model: RMSNorm, a QKV projection, multi-head attention with a causal mask, an output projection and a residual, then a second RMSNorm and a ReLU-squared feed forward network. The MIL comes from x/ane/mil's GenSDPAForward and GenFFNForwardRMSReLU2, which until now had only ever been checked for compiling — nothing verified that either computes what its name says.
The two programs share a buffer ¶
Attention and the feed forward network are separate compiled programs, and they are chained without a host round trip: the buffer object bound to the attention program's output port is bound again to the feed forward program's input port, so the second reads the first's result in place. Both operations are encoded into one execution stream and dispatched by one execute call. Nothing copies the intermediate activation, and the host never sees it.
The residual the generator does not add ¶
GenFFNForwardRMSReLU2 computes W2(relu(W1(rms_norm(x)))^2) and stops there. It has no residual add, so the block output is the attention result plus the feed forward result, and this program does that last add on the host. That is a gap in the generator rather than a choice made here: a caller who wires the two together and takes the second program's output as the block output gets a transformer block missing one of its two residual connections, silently and with plausible-looking numbers.
What is checked ¶
The reference recomputes the entire block in float64 from the same weights. Everything on the engine runs in fp16, so the comparison is to an fp16-scale tolerance and the program prints the worst difference it saw next to the magnitude of the reference, rather than claiming agreement.
Two controls, because a matching number is weak evidence on its own. The compiled bundle is read for which backend the compiler chose, since the device mask is a permission and not a placement, and a block that fell back to the CPU would produce the same correct answer. And one input element is perturbed and the block re-dispatched, which must move the output and must still match a reference recomputed from the perturbed input; a program bound to a stale buffer, or returning a constant, passes the first check and fails this one.
go run ./examples/ane/e5rtblock go run ./examples/ane/e5rtblock -dim 128 -heads 8 -seq 32 -hidden 256