OpenFlowLM-Next icon indicating copy to clipboard operation
OpenFlowLM-Next copied to clipboard

Open kernels: what is left before the closed engine can go — batched prefill, long-context attention, vision

Open Cyronius opened this issue 2 months ago • 1 comments

Three gaps stand between the open kernel path and actually replacing the closed engine. Decode is at parity on the 35B MoE (~7 tok/s open vs ~6.8 closed, logits corr 0.999998 against the fp64 replica) and the four families that run today are numerically exact — but only for single-token decode, short context, text only. Filing them together because they are the whole remaining list; each is separable work and can be split out if someone picks one up.

Background and all numbers: src/open_qwen36/README.md ("What is still not closed").

1. Batched prefill

Prompt tokens go through the decode step one at a time. Exact, but slow:

model prefill
Qwen3.6-35B-A3B 124 ms/token
Qwen3-4B 129 ms/token
Llama-3.1-8B 125 ms/token
Gemma3-4B 63 ms/token

A 500-token prompt is roughly a minute; model_list.json advertises max_prefill_len: 4096 for these models, which the open path cannot honour in any reasonable time. The closed engine has batch kernels; no open equivalent exists. phlegm's estimate was "weeks, gated on one experiment" — the experiment being whether the q4_1 GEMV dataflow in open_kernels/designs/layer_x/ can be turned into a GEMM that amortizes the weight stream across a token block, since today every token re-streams the model's full weight bytes.

Done when: a multi-token prefill dispatch exists, produces the same logits as N sequential decode steps, and drops TTFT on a 500-token prompt by a large constant factor.

2. Long-context attention cost

The attention kernel is one core walking the KV cache: ~24 µs per cached row per attention layer. On the 35B (10 full-attention layers) a 4096-token context adds roughly 1 s per token. Capacity is not the problem — KV buffers are sized from the app's context length and a 6000-row window runs with finite logits — this is purely kernel throughput.

Done when: attention work is spread across cores (or the walk is restructured) so decode at 4096+ context stays within a small multiple of decode at short context, with the fp64 replica still agreeing.

3. Vision

Qwen3.6-35B-A3B is a VLM and the open engine has no vision path: an image payload is refused with a clear error rather than silently ignored (src/common/AutoModel/modeling_qwen3_6_moe_image.cpp:218), and the model falls back to the closed engine. Gemma3-4B is the same story. Beyond those two, the vision label covers qwen3vl, qwen2vl, all four qwen3.5 sizes and the gemma4* family — so the vision encoder is a prerequisite for a large fraction of the catalogue, not a nice-to-have for one model.

Done when: the vision encoder runs on open kernels for at least one VLM and FLM_QWEN36_ENGINE=open accepts an image payload with output matching the closed engine's on a fixed image.

Cyronius avatar Sep 06 '26 13:09 Cyronius

pr got merged, we're done with this

Cyronius avatar Sep 10 '26 23:09 Cyronius