Skip to content

CBv2: commit Gemma 4's plain decode steps by operation count - #376

Merged
davidtai merged 2 commits into
mainfrom
perf/gemma-decode-command-buffers
Nov 3, 2026
Merged

davidtai merged 2 commits into
mainfrom
perf/gemma-decode-command-buffers

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 1, 2026 •

Copy link
Copy Markdown

Proposed changes

Plain decode steps of Gemma 4 (every row one token) now commit a Metal command buffer every 100 operations, with no input-size bound, through CBv2DecodeCommandBufferLimitsProviding. MLX's defaults commit every 40 to 50 operations or 40 to 50 M distinct input elements. A step's inputs include the weights and each 64 MiB KV segment its history reads, so decode committed many times per step, reached MLX's limit of ten command buffers in flight, and waited inside evaluation instead of encoding ahead of the GPU. Results do not depend on the partitioning.

Longer prefill chunks and MTP rounds keep MLX's defaults. A one-token prompt, or a one-token final prompt chunk, is decode-shaped and takes the limits too, under the shared helper's existing rule.

Provider side and evidence: Layr-Labs/d-inference#1712. Target: 0.10.7. Overlaps #364, which declares limits on the same class bundled with its GeGLU change.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes (not run)
  • I have added tests that prove my fix is effective or that my feature works (Gemma4DecodeCommandBufferTests: limits reach the steppable adapter, MTP rounds keep the defaults, logits bitwise equal under the limits)
  • I have updated the necessary documentation (if needed) (the provider PR carries the docs)

AI usage

  • I have read this PR description in full and approve it as my own, and it
    accurately describes the code changes.
  • AI usage disclosure: the code, tests, measurements and this description were produced by Claude (Claude Code, Opus 5.5). The agent opened this draft at the repository owner's request. A human has not yet reviewed the code or this description.

🤖 Generated with Claude Code

jonathan308 and others added 2 commits October 31, 2026 07:46
MLX's defaults commit every 40-50 operations or 40-50 M distinct input elements. A step's inputs include the weights and each 64 MiB KV segment the history reads, so decode committed many times per step, reached MLX's limit of ten command buffers in flight, and waited inside evaluation. Plain decode steps now commit every 100 operations with no input bound, as Nemotron Super, Flint and GLM do. Prefill chunks and MTP rounds keep MLX's defaults. Results do not depend on the partitioning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CONTRIBUTING gives each new test one type; the kernel tests live in KernelTests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan308
jonathan308 marked this pull request as ready for review November 2, 2026 19:19
@jonathan308
jonathan308 requested a review from davidtai November 2, 2026 19:19
@davidtai
davidtai merged commit 2311af6 into main Nov 3, 2026
52 of 54 checks passed
@davidtai
davidtai deleted the perf/gemma-decode-command-buffers branch November 3, 2026 12:23
jonathan308 added a commit that referenced this pull request Nov 9, 2026
The 2026-11-08 rebase onto 67110e7 dropped the scoped 100/512
command-buffer limits: main already commits Gemma 4's plain decode steps
every 100 operations (#376). The README still described those limits and
claimed 14 tests, of which six remain.

The README now says that the screen measured both changes and that the
GeGLU change alone is unmeasured, names the six tests that cover it, and
says that cluster ranks get the shared product with an SDK pin alone. The
receipt is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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