Skip to content

llama : update the GDN recurrent state in place on the CPU (#28841) - #29121

Open
alenizy361 wants to merge 4 commits into
ggml-org:masterfrom
alenizy361:upstream-gdn-inplace-state
Open

alenizy361 wants to merge 4 commits into
ggml-org:masterfrom
alenizy361:upstream-gdn-inplace-state

Conversation

@alenizy361

@alenizy361 alenizy361 commented Sep 19, 2026 •

Copy link
Copy Markdown

Overview

  • I ran an experiment to run a 27B model (from the hybrid Qwen3.5 series) on a laptop that has no GPU and uses single-channel RAM.
  • While running concurrent sequences, perf showed that about 27% of the step time is wasted in get_rows and cpy operations for the GDN layer states, even though the state is already in place.
  • I added an in-place state update inside the cache, applied only when all sequences read their own cells; otherwise the previous path is used, with an environment variable to go back to the old behavior for comparison. I also made the zeroing of the state memory lazy via mmap instead of memset, so inactive cells do not consume RAM.
  • Results on my machine (using the AVX2 kernels from the PrismML fork): for 16 sequences the speed went from 9.5 to 13.5 tokens/s, for 8 sequences from 10.1 to 13.3 tokens/s, and RAM usage for 16 slots with speculative decoding dropped from 12.8 to 8.4 GB.

Additional information

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES — the code was written by Claude Code under my supervision; I defined the problem and the goal, ran the tests and measurements on my computer, and reviewed the results.

@github-actions github-actions Bot added model Model specific testing Everything test related ggml changes relating to the ggml tensor library for machine learning labels Sep 19, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Sep 19, 2026

Copy link
Copy Markdown

Hi @alenizy361, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

  • AI-generated content: While code is allowed to be generated by AI, please write the PR description and commit messages on your own without the help of AI.


Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Sep 19, 2026
@github-actions
github-actions Bot marked this pull request as draft September 19, 2026 08:08
@github-actions github-actions Bot removed the draft PR will be changed to draft by github-actions bot label Sep 19, 2026
alenizy361 and others added 4 commits September 19, 2026 12:18
… in place

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QrdPnP5KL449GsoWBZx52R
… their own cells, with an environment variable as a fallback

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QrdPnP5KL449GsoWBZx52R
@alenizy361
alenizy361 force-pushed the upstream-gdn-inplace-state branch from 138bc09 to cbea4a4 Compare September 19, 2026 09:18
@alenizy361
alenizy361 marked this pull request as ready for review September 19, 2026 09:28

This branch has not been deployed

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

Labels

ggml changes relating to the ggml tensor library for machine learning model Model specific testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: skip redundant recurrent-state gather when n_rs == 1 && n_seqs == 1

1 participant