Skip to content

Initial changes for Recurrent state rollback for nemotron for cuda - #26623

Merged
ggerganov merged 17 commits into
ggml-org:masterfrom
lnigam:lnigam/recurrent-state-rollback
Aug 14, 2026
Merged

Initial changes for Recurrent state rollback for nemotron for cuda#26623
ggerganov merged 17 commits into
ggml-org:masterfrom
lnigam:lnigam/recurrent-state-rollback

Conversation

@lnigam

@lnigam lnigam commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Initial changes for Recurrent state rollback for nemotron for cpu and cuda

Overview

This PR adds support for Recurrent state rollback for nemotron model. It creates separate copies of states for every draft token and then rollback to the last accepted token's state. Also added test case to verify the ssm support

Additional information

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: yes, for code review and help with test case creation

@ggml-gh-bot

ggml-gh-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

Hi @lnigam, thanks for your contribution!

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

  • Multiple open PRs from a new contributor: We limit new contributors (those without a previously merged PR) to 1 open PR at a time. You currently have 2 open PRs.

  • Multiple backend changes in one PR: When adding support for a new model or feature, focus on CPU support only in the initial PR. Add support for other backends like CUDA in follow-up PRs. If you have a good reason to modify multiple backends in one PR, please explain it.


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

@github-actions github-actions Bot added model Model specific testing Everything test related ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Aug 5, 2026
@ruixiang63
ruixiang63 requested review from am17an and ruixiang63 August 5, 2026 10:03
@lnigam lnigam changed the title Initial changes for Recurrent state rollback for nemotron for cpu and… Initial changes for Recurrent state rollback for nemotron for cuda Aug 5, 2026
Comment thread src/llama-arch.cpp Outdated
Comment thread src/models/mamba-base.cpp
Comment thread ggml/src/ggml-cuda/ssm-scan.cu Outdated
@ggerganov ggerganov self-assigned this Aug 6, 2026
@lnigam
lnigam marked this pull request as ready for review August 6, 2026 17:30
@lnigam
lnigam requested review from a team and CISC as code owners August 6, 2026 17:30
Comment thread ggml/src/ggml-cuda/ssm-scan.cu
Comment thread ggml/src/ggml.c Outdated
@lnigam
lnigam requested a review from a team as a code owner August 7, 2026 06:36
@github-actions github-actions Bot added the Vulkan Issues specific to the Vulkan backend label Aug 7, 2026
Comment thread src/llama-context.cpp Outdated
Comment thread src/llama-context.cpp Outdated
Comment thread src/llama-context.cpp Outdated
Comment thread ggml/src/ggml-cuda/ggml-cuda.cu Outdated
@lnigam
lnigam requested review from a team and marty1885 as code owners August 10, 2026 14:35
@github-actions github-actions Bot added SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language Apple Metal https://en.wikipedia.org/wiki/Metal_(API) WebGPU labels Aug 10, 2026
Comment thread tests/CMakeLists.txt Outdated
Comment thread src/llama-context.cpp Outdated
Comment thread src/llama-context.cpp Outdated
Comment thread tests/CMakeLists.txt Outdated
Comment thread tests/CMakeLists.txt Outdated
Comment thread tests/CMakeLists.txt Outdated

@ggerganov ggerganov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main problem atm is that I missed the fact that when the new operator is not supported, we don't just need to update the compute graph - we also have to communicate back to the app that the requested n_rs_seq was not satisfied. This gets messy as it requires some extra logic outside of libllama and generally it is something that I would like to avoid.

My suggestion is to drop the llm_fused_op_probe and cparams.fused_ssm_scan related stuff and directly implement the new op across all backends. This is what we actually did for the ggml_gated_delta_net op - a very similar case to this one:

#24086

We can do that because the change in the backends is relatively minimal and an agent should be able to do it correctly single-shot. Just make sure the provided tests in test-backend-ops.cpp are good enough in order to catch in the CI if some of the backends failed it (I think the current ones are good).

cc @gaugarg-nv for vis, as you successfully did this for the ggml_gated_delta_net op before.


If this turns to be difficult to do for all the backends, then a simpler option is to just do it for the CPU and CUDA backend (i.e. you already did that) and then mark all backends that they do not support the op. This will cause the computation to fallback to CPU on these devices until it gets implemented. But that should be fine and more importantly, the rollback logic would still work - it would just be a bit slower, since it is going to run on the CPU.

@gaugarg-nv
gaugarg-nv force-pushed the lnigam/recurrent-state-rollback branch from 3483a70 to a078c8a Compare August 14, 2026 11:18
@ggerganov ggerganov added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Aug 14, 2026
@ggerganov
ggerganov merged commit 1692f9e into ggml-org:master Aug 14, 2026
48 of 50 checks passed
Ooooze pushed a commit to AtomicBot-ai/atomic-llama-cpp-turboquant-nightly that referenced this pull request Aug 14, 2026
* Initial changes for Recurrent state rollback for nemotron for cpu and cuda

* Removing CPU RS rollback. Will enable it in subsequent PRs

* addition of test case

* Removing assert and calling runtime API to check if op is supported

* removing extra API and updating the call sites for K

* replace static cuda detection to runtime fused_op api

* address review comments and fallback when SSM rollback not supprted

* Adding changes for supporting RS-rollback in CPU. Also added test-backend-ops for cpu and cuda

* removing memory manipulation as rs rollback is now supported in CPU

* removing the static probe which is not needed now

* correcting the format

* address review comments

* enabling test for all the backends, unsupported backends will fallback to CPU

* Apply suggestions from code review

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* choose different graph based on the result of fused_ssm_op is supported or not and also handled memory->n_rs_seq >1 case incase of op is not supported

* Support K > 1 in ssm_scan for all backends

* Fix CI Issues

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Co-authored-by: Gaurav Garg <gaugarg@nvidia.com>
(cherry picked from commit 1692f9e)
brittlewis12 pushed a commit to brittlewis12/llama.cpp that referenced this pull request Aug 17, 2026
* Initial changes for Recurrent state rollback for nemotron for cpu and cuda

* Removing CPU RS rollback. Will enable it in subsequent PRs

* addition of test case

* Removing assert and calling runtime API to check if op is supported

* removing extra API and updating the call sites for K

* replace static cuda detection to runtime fused_op api

* address review comments and fallback when SSM rollback not supprted

* Adding changes for supporting RS-rollback in CPU. Also added test-backend-ops for cpu and cuda

* removing memory manipulation as rs rollback is now supported in CPU

* removing the static probe which is not needed now

* correcting the format

* address review comments

* enabling test for all the backends, unsupported backends will fallback to CPU

* Apply suggestions from code review

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* choose different graph based on the result of fused_ssm_op is supported or not and also handled memory->n_rs_seq >1 case incase of op is not supported

* Support K > 1 in ssm_scan for all backends

* Fix CI Issues

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Co-authored-by: Gaurav Garg <gaugarg@nvidia.com>
ravel7524 pushed a commit to ravel7524/llama.cpp that referenced this pull request Aug 30, 2026
* Initial changes for Recurrent state rollback for nemotron for cpu and cuda

* Removing CPU RS rollback. Will enable it in subsequent PRs

* addition of test case

* Removing assert and calling runtime API to check if op is supported

* removing extra API and updating the call sites for K

* replace static cuda detection to runtime fused_op api

* address review comments and fallback when SSM rollback not supprted

* Adding changes for supporting RS-rollback in CPU. Also added test-backend-ops for cpu and cuda

* removing memory manipulation as rs rollback is now supported in CPU

* removing the static probe which is not needed now

* correcting the format

* address review comments

* enabling test for all the backends, unsupported backends will fallback to CPU

* Apply suggestions from code review

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* choose different graph based on the result of fused_ssm_op is supported or not and also handled memory->n_rs_seq >1 case incase of op is not supported

* Support K > 1 in ssm_scan for all backends

* Fix CI Issues

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Co-authored-by: Gaurav Garg <gaugarg@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Apple Metal https://en.wikipedia.org/wiki/Metal_(API) CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. model Model specific SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language testing Everything test related Vulkan Issues specific to the Vulkan backend WebGPU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants