Repository navigation
flashnext: opt-in shared-expert ANE column share for prompt passes (qwen4_exp) - #6467
joshuaswarren wants to merge 5 commits into
Conversation
Synthena Initial Review — Needs changes (
|
|
Sequencing note from the #6334/#6435 column-share work: this PR and those both add Related finding from the same hardware probe (details: #6435 (comment)): on M1 Ultra the ANE conv emits fp16 only — |
|
Thanks @joshuaswarren. The sequencing note is clear, and the shared TensorFold ANE machinery can be reconciled according to landing order. The exactness issue remains at this head. Please make the shared gate/up values and served output bit-exact with the GPU path, or keep this nonexact share out of the served Flashnext route. An explicit opt-in does not satisfy the exactness requirement. The related fp16-output probe explains the limitation but does not resolve it.
|
Move columns [0, TF_ANE_COLUMNS) of each layer's shared-expert gate/up projection to the Apple Neural Engine during prompt passes, leaving the GPU the packed column tail, the silu*up merge and the down projection. - metal/ane_share.zig: the generic Share — per-slice fp16 surfaces, a per-layer gate/up program, a worker thread driven by a SharedEvent counter, and the signal/wait handoff that splits a prompt lane's command stream behind a fence. - families/flashnext: gate/up slice MIL (raw columns, no activation — the merge rounds to the bf16 grid before silu so both paths match stock pf_act), the pack/merge kernels, and the prompt-pass tail that slices columns [columns, 640) off the recorded (bits, group) weights. - The lane's cb/enc are resynced from the run state before each handoff: the fsr stream's pause/overlap commits and replaces them mid-run, and encoders reopen in the stream's own dispatch mode. - Off by default; exact_output_qualified=false. A load or build failure warns and falls back to the GPU path. Live-verified on jw-core-4b (8-bit/GS128 shared expert, --ssd-experts): loaded_columns=384, coherent greedy output. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Keeps Hooks.at's signature unchanged so the hunk stays disjoint from the TP pair hand-off edits in ashhart#3480.
CI lean rule wants one-line comments within 120 columns and zig fmt on replay_prompt; reword the folded doc comments to fit. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The coverage suite requires every kernel_sources export to appear in a generated library; the share's fnext_ane merge text was compiled ad hoc in replay_prompt but never inventoried. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
846e6a6 to
b369d82
Compare
|
Rebased onto current main ( |
What this changes
TF_ANE_COLUMNS=Nonqwen4_exp(Flash Next) moves the first N output columns of each layer's shared-expert gate+up prompt matmul onto the Neural Engine. The shared expert runs every token on all 48 layers on A3B-class checkpoints, so this is the largest prompt-side ANE surface after the qwen27/dense shares.Weights: at load, the first N columns of
shared_expert.gate_proj/up_projare dequantized to fp16 (genericbits/groupfromxw, verified againstqmmw_nax'ss*q+bconvention) and baked into oneconvMIL program per layer (ane.gateUpSlice, byte-identical shape to the qwen27 generator).Dispatch: in
Prompt.moe's shared-expert phase the GPU tail runs through a width-resolvedqmmSlice(offset weightBufs, sameprompt_w.qmmdriver, no kernel changes); the ANE half is fenced withSharedEventsignal/wait around the silu·up stage, and a merge kernel overwritessa[0..c)on the bf16 grid identical to stockpf_act.Opt-in only:
exact_output_qualified = falseis logged at load; withoutTF_ANE_COLUMNSnothing changes (m.ane == null, the tail is byte-identical to today). Disabled underr.xpack/r.tp.FSR path (
--ssd-experts, the only way current qwen4_exp checkpoints fit): the lane'scb/encare resynced fromcommands.active/r.encaround each fence op, and encoders reopen with the stream's own dispatch mode.Issue: Refs Metal: Neural Engine prompt-MLP share beyond qwen27 (qwen3.5 row split, reusable ane_share) #6310 — shared-expert coverage for qwen4_exp; the reusable
metal/ane_share.zigring/fence/worker machinery is ported unchanged in shape from the qwen27 share.Not stacked: branched off upstream/main.
atc overlap --json:{"complete": false, "limitations": ["pullFilesUnavailable", "timeLimit"], "overlaps": [{"pullRequest": 2273, "conflict": "clean"}, {"pullRequest": 2634, "conflict": "unknown"}, {"pullRequest": 2342, "conflict": "conflicts", "conflictFiles": 1}, {"pullRequest": 3480, "conflict": "conflicts", "conflictFiles": 5}, {"pullRequest": 3045, "conflict": "clean"}, {"pullRequest": 3380, "conflict": "unknown"}, {"pullRequest": 1635, "conflict": "unknown"}]}— every conflict hunk was inspected against both PR heads withgit merge-tree: none contains a line this branch changes. The flash next pair: hand off through shared events and host-published epochs #3480 conflicts are its own staleness vs upstream (tryontp.send/waitWord/combine/argmax,copyPeer,l.encwrite-backs it predates) and the qwen27 metal: qk projections, flat glue and Metal 4 verify passes, each bit-identical and switchable #2342 conflict is its stale end-of-filesources.zigappend; this branch'sflashnext_aneentry sits mid-file. The one intentionally adjacent hunk — share binding inHooks.begin— was moved out ofat()specifically to stay disjoint from flash next pair: hand off through shared events and host-published epochs #3480'spairSend/pairTakeedits.Head commit: 846e6a6 (on e60cafe).
Verification
zig buildandzig build nativeclean on macstudio.flashnext_recording_metalneeded theane/ane_sharestub exports, now added; remaining suite failures (residency_recording_metalmissingphase_trace, tfq5/inkling2/paged/rope) reproduce identically on the base commit — pre-existing upstream.jw-core-4b(qwen4_exp, 48L, shared_expert_intermediate=640,--ssd-experts 8 --ple-on-ssd):TF_ANE_COLUMNS=384→loaded=true loaded_columns=384, warm-up and chat prompts pass through the share path; greedy17*23?→391.846e6a6bdbuild,TF_ANE_COLUMNS=384, 4 greedy prompts, 128 tok): output is NOT identical — common prefixes then divergence (prose 322/700, code 578/655, reasoning 178/378, logprobs 226/462 chars). An early argmax flip cascades; consistent withexact_output_qualified=false— the share at 384 cols is a semantic-changing fast path and stays opt-in.zig fmt --check,git diff --check,zig ast-checkon all touched files: clean.Receipt
Live-verified engagement plus a measured drift A/B: share output diverges from stock on all 4 greedy prompts after a common prefix — expected and consistent with
exact_output_qualified=false. Correctness of the stock path is unchanged (opt-in); merge rounding is pinned identical topf_act— merge rounding is pinned identical topf_act, input planes are bf16-lossless, and the ANE's fp16 in-chip accumulation residual is documented on #6334.Checklist
exact_output_qualified=falseopt-in, matching qwen3_5 Metal: opt-in ANE share of prompt MLP columns (TF_ANE_COLUMNS) #6334's documented non-exact pattern.