Skip to content

Gemma 4 E4B on the Intel Arc Pro B70 (Xe2) - #1552

Merged
ashhart merged 21 commits into
ashhart:mainfrom
hygurlabs:e4b-xpu
Oct 30, 2026
Merged

ashhart merged 21 commits into
ashhart:mainfrom
hygurlabs:e4b-xpu

Conversation

@Mirrdhyn

Copy link
Copy Markdown
Contributor

What this changes

Part of #1222, on top of #1402. Gemma 4 E4B (here NVIDIA Nemotron 3.5 Bolt E4B) served on the Intel Arc Pro B70 (Xe2) through the XPU lane host: admission through the family config, loader, forward with per-layer inputs on the family's bf16 steps, DPAS dense and attention kernels, prompt cache, several streams with shared forwards, /v1/decisions on the engine thread, and 8-bit attention projections.

No converter: the engine reads mlx_lm.convert checkpoints. The audio tower and the DFlash drafter are not in this PR (mlx-lm drops the audio tensors, and the drafter is published only as GGUF or NVFP4); they can follow separately.

Checkpoints

From nvidia/NVIDIA-Nemotron-3.5-Bolt-E4B-BF16 with mlx-lm 0.32.2 (MLX 0.32.4), 4-bit, group 64:

from mlx_lm import convert
PLE = ("per_layer_input_gate", "per_layer_projection", "per_layer_model_projection")
ATT = ("self_attn.q_proj", "self_attn.k_proj", "self_attn.v_proj", "self_attn.o_proj")

def ple16(path, module):          # per-layer input linears kept bf16
    return not path.endswith(PLE)

def a8(path, module):             # same, plus 8-bit attention projections
    if path.endswith(PLE):
        return False
    if path.endswith(ATT):
        return {"group_size": 64, "bits": 8, "mode": "affine"}
    return True

convert(SRC, OUT, quantize=True, q_bits=4, q_group_size=64, quant_predicate=ple16)  # or a8

With mlx-lm's defaults the per-layer input linears are quantized too. The engine still loads that checkpoint and prints one warning per such tensor. Against the BF16 model, over 358 positions of the 14 reference prompts, its top-1 token agrees 94.7% of the time (mean KL 0.148), against 97.2% (mean KL 0.039) with ple16.

Receipt

On this branch (main 5225426 plus 21 commits), Arc Pro B70:

  • zig build test passes; the Gemma 4 host targets, test-qwen27-equality-host and test-flashnext-score-host pass; zig fmt clean.
  • Logits of 14 prompts, ple16 and a8: byte-equal across rebases on main, and between a branch build and the checkpoints written by mlx_lm.convert above.
  • Decode windows give the same logits as row-by-row steps; the top-64 drawn on the card equals the host's in 24 of 24 steps.
  • Served: concurrent replies equal solo replies (56/56 alone, 30/30 serial, ple16 and a8); resumed prompt cache gives the same replies as fresh; /v1/decisions returns the same 808 keys sequential, 2 and 4 concurrent.
  • Prompt cache (reuse_served.py): after a tool reply the cache resumes one turn late (33/43 rows as cached as planned). That comes from the shared server code, not this engine, and is fixed separately in server: keep the history mark inside what the next turn repeats after a tool reply #1551 (43/43 on top of it).

Speeds (median of 2 passes, alternated with the branch on the previous main):

prompt tok/s (2048) decode tok/s
ple16 6772 135.6
a8 3950 118.6

Served, 256 tokens, chat prompt, greedy, aggregate tok/s at 1 / 2 / 4 streams: ple16 140 / 253 / 426, a8 122 / 223 / 380.

Other XPU families

This branch touches shared XPU files (qwen27/gemm.cl, xpu_lane.zig, xpu_nem.zig, xpu.zig, zig/build/xpu.zig); nothing outside the XPU build, kernels and natives and the gemma4_e4b tools. Against main 0d51120, same B70, two alternated passes (main then branch, branch then main); after the rebase on 5225426 the host steps, Qwen3.8 27B GPTQ (oracle, served fingerprints, concurrent = alone) and the speeds above were run again with the same results:

  • gemm.cl built with ocloc for BMG: the existing kernels' machine code is byte-identical; the two new kernels are only called by Gemma 4.
  • Qwen3.8 27B (GPTQ, GPTQ with XPU_PREFILL_INT8=1, MLX 4-bit) and Nemotron 3.5 Lightning 30B-A3B MLX 4-bit: same greedy outputs (oracle, verify/multi contracts, served fingerprints, 27B means/seam/close checks, Nemotron programs), concurrent = alone in every pass (120/120 and 56/56), single-stream prefill and decode within 0.3%.
  • Multi-stream aggregates: 5 of 99 cells outside 2%, mixed signs, with the two passes of one tree already 2 to 8% apart; a targeted ABBA rerun flips their signs.
  • Host steps: 54 steps (including test, test-golden, test-kernel-contract, fuzz-cortheon, test-cuda-host, the server, lane and Gemma 4 steps) give the same exits and counts on both trees, plus the new xpu_config tests; test-qwen27-keep-host aborts on both without a GPU.

@ashhart

ashhart commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Thank you @Mirrdhyn, this is a big, careful piece of work. We especially value the receipts for the other XPU models (identical machine code for the existing GEMMs, and concurrent equal to alone). We'd like to land it in 1.2.0. Two things first:

  1. tools/zig/gemma4_e4b_mstreams.py (added in "one sequence per stream and shared forwards over several streams") has paths from your machine: sys.path.insert(0, "/home/mirrdhyn/tf-xpu-bolt/tools/zig") and the prompt files under /data/ref/.... The sys.path line isn't needed because the script imports nothing local. Could the two prompt files be arguments, as in the other gemma4_e4b_* scripts? Please change this in that commit itself, not in a commit on top, since we land the branch's commits as they are and the path would stay in history.

  2. In zig/src/native/xpu_nem.zig, the prompt cache is now created whenever the engine has snapSave (kept), not only when it drafts. Gemma 4 always counts as drafted, so this only changes Nemotron-H without its MTP head (--no-drafts, TENSORFOLD_XPU_MTP=0, or a checkpoint without mtp-4bit.safetensors). That path now reports a prompt cache, but its prefill never restores a state, and its saves fail because no stream is bound. Could you return to if (drafted and budget > 0)? Related: the cached constant in xpu_lane.zig (!has_head and snapSave) is never true now that the Gemma engine has verifyRows, so its branches can go too.

A small optional one: copy_match defaults to 4, but an XPU_COPY_MATCH value that doesn't parse falls back to 8. It might be clearer if both were the same.

Everything else looks good to us. The rebase onto current main is clean, formatting and whitespace checks pass, and the new xpu_config tests pass. Thanks again!

@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review. All three are fixed inside the commits that introduced them, so no path stays in history:

  1. gemma4_e4b_mstreams.py (in "one sequence per stream and shared forwards over several streams"): the sys.path line is gone, and the two prompt files are now positional arguments (prompts french), with --port, --sampled, --nodraft and --max-tokens as options, like the other gemma4_e4b_* scripts.
  2. xpu_nem.zig is back to if (drafted and budget > 0). cached and its branches in xpu_lane.zig are removed in "windows of up to 16 rows for the lane core copy drafts", the commit that gave the Gemma engine verifyRows. The earlier commits keep them because they are still used there.
  3. An XPU_COPY_MATCH value that doesn't parse now falls back to 4, the same as the default.

The branch diff against the previous head is these three files only (+21/-28). Rechecked on the B70 against the previous head: logits of the 14 reference prompts byte-equal (ple16 and a8), /v1/decisions byte-equal sequential and at 2 and 4 concurrent requests, concurrent replies equal to solo, the same reuse_served verdicts, the same host steps, Qwen 27B unchanged, speeds within 0.8%, and the three edited commits and the head build. Nemotron Lightning without its MTP head (--no-drafts and TENSORFOLD_XPU_MTP=0) no longer reports a prompt cache, as on main, with the same replies.

@ashhart
ashhart merged commit 2fc7736 into ashhart:main Oct 30, 2026
9 checks passed
@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Thank you @Mirrdhyn. This is in TensorFold 1.2.0, released today: https://github.com/ashhart/TensorFold/releases/tag/v1.2.0

It landed with your commits under your own name, so you're listed as a TensorFold contributor, and it's credited to you in the release notes and the changelog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants