Skip to content

tests : refactor test-recurrent-state-rollback - #29426

Merged
ggerganov merged 7 commits into
masterfrom
gg/tests-recurrent-refactor
Sep 28, 2026
Merged

ggerganov merged 7 commits into
masterfrom
gg/tests-recurrent-refactor

Conversation

@ggerganov

@ggerganov ggerganov commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Overview

Refactor tests/test-recurrent-state-rollback.cpp to hold contexts in llama_context_ptr (unique_ptr with llama_context_deleter) instead of raw llama_context * pointers. The manual llama_free calls and the cleanup() lambda are removed; contexts are released automatically on scope exit, including all early-return error paths.

Add a --models DIR mode that mirrors test-save-load-state: iterate every generated dummy model, report PASS/FAIL/SKIP per model in a table, and fail only when a model fails. Register a single ctest entry with ARGS --models instead of four per-model registrations, covering all architectures that support recurrent rollback.

Run test_multi_seq_split_replay as a separate test instead of calling it at the end of test_rollback: it returns its own status, both tests run independently over both cache fills through a shared run_tests helper, and the --models table reports rollback and split replay columns with per-test summaries. The exit code fails when either test fails.

Fix the unexpected graph reallocations reported by GGML_SCHED_DEBUG_REALLOC (hit by qwen4exp): decoding batches with no outputs leaves the last layer's MoE tensors empty, the Metal fusion logic excluded 0-element nodes, so the optimizer packed and reordered the graph differently from the worst-case reserved graph and ggml_gallocr_needs_realloc failed on the layout mismatch. ggml_metal_fusion_max and the topk-moe/moe-reduce checks now match 0-element tensors like their non-empty counterparts; the fused kernels dispatch zero threadgroups for them, which is a legal no-op. The reserved graph and the no-output decode now produce identical node order and no longer trigger a re-reserve.

Verified with GGML_SCHED_DEBUG_REALLOC=1 over all dummy models (no reallocations, 10 passed / 117 skipped / 0 failed), the test-fusion baseline check (264 ok, 0 failed, counts unchanged), and the full ctest suite.

Note: test-generate-models seeds from std::random_device, and some generated lfm2 models drift up to ~1.7e-5 nmse on the split replay; the bound is raised to 1e-4f here so the random generations no longer flake, verified over 4 full model-set seeds plus targeted lfm2 seeds.

Requirements

  • I have read and agreed with the contributing guidelines
  • AI usage disclosure: YES. pi:llama.cpp/MiMo-V2.6-Flash-RL

@github-actions github-actions Bot added the testing Everything test related label Sep 25, 2026
@ggerganov ggerganov changed the title tests : use llama_context_ptr in test-recurrent-state-rollback tests : use llama_context_ptr and --models in test-recurrent-state-rollback Sep 25, 2026
@ggerganov
ggerganov force-pushed the gg/tests-recurrent-refactor branch from b899b86 to dfdc64f Compare September 27, 2026 14:19
Replace raw llama_context pointers with llama_context_ptr and drop the
manual llama_free calls and cleanup lambda.

Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-RL
Add a --models DIR mode that mirrors test-save-load-state: iterate every
dummy model, report PASS/FAIL/SKIP in a table and fail only when a model
fails. Register a single ctest entry with ARGS --models instead of the four
per-model registrations.

Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-RL
…pendent

The fusion packing in ggml_metal_fusion_max excluded 0-element tensors and
the topk_moe/moe_reduce checks rejected n_tokens == 0, so graphs decoding
batches with no outputs packed differently from the worst-case reserved
graph. The Metal optimizer then reordered the nodes differently and
ggml_gallocr_needs_realloc failed on the layout mismatch, forcing an
unexpected graph re-reserve (caught by GGML_SCHED_DEBUG_REALLOC).

Treat empty tensors like their non-empty counterparts: match them in the
pattern sequence and only reject genuinely malformed shapes. Fused kernels
dispatch zero threadgroups for empty graphs, which is a legal no-op.

Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-RL
test_multi_seq_split_replay was invoked at the end of test_rollback,
so its result was folded into the rollback status and it only ran when
the rollback part passed.

Give it its own test_status return, run both tests independently over
both cache fills via a shared run_tests helper, and report them as
separate rollback / split replay columns in the --models table with
per-test summaries. The exit code fails when either test fails.

Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-RL
@ggerganov
ggerganov force-pushed the gg/tests-recurrent-refactor branch from d1d98a3 to 1e20fe5 Compare September 28, 2026 07:24
@ggerganov ggerganov changed the title tests : use llama_context_ptr and --models in test-recurrent-state-rollback tests : refactor test-recurrent-state-rollback and allow fusing 0-element nodes Sep 28, 2026
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning Apple Metal https://en.wikipedia.org/wiki/Metal_(API) labels Sep 28, 2026
@ggerganov ggerganov changed the title tests : refactor test-recurrent-state-rollback and allow fusing 0-element nodes tests : refactor test-recurrent-state-rollback Sep 28, 2026
test-generate-models seeds its weights from std::random_device, and some
generated lfm2 models drift up to ~1.7e-5 nmse on the split replay due to
rounding noise, tripping the previous 1e-5 bound. Raise the bound to 1e-4
so the random generations stop flaking.

Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-RL
@ggerganov
ggerganov marked this pull request as ready for review September 28, 2026 10:31
@ggerganov
ggerganov requested a review from a team as a code owner September 28, 2026 10:31
@ggerganov

Copy link
Copy Markdown
Member Author

@ggml-org/ggml-vulkan There seems to be a SEGFAULT after the refactor of test-recurrent-state-rollback in this PR: https://github.com/ggml-org/llama.cpp/actions/runs/36400623987/job/108857352937?pr=29426#step:3:1221

Might be some issue during the tear-down phase since the tests are all successful. Probably something to look into if it continues happening. I don't have a suitable CM2 env to try to reproduce.

The single-model path duplicated the model init and the non-recurrent
check from run_tests_for_model; route it through the shared helper
instead. Model load failures now return FAIL rather than SKIP so that
--model with a broken file still exits non-zero, and the helper loads
with model_only like the --models loop does since the tests create
their own contexts.

Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-RL
@ggerganov
ggerganov merged commit d77dd08 into master Sep 28, 2026
31 of 35 checks passed
@ggerganov
ggerganov deleted the gg/tests-recurrent-refactor branch September 28, 2026 13:36
@0cc4m

0cc4m commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

I managed to reproduce it once, it seems to be another spurious nvidia driver cleanup bug, something similar was fixed in the driver before.

pwilkin added a commit to timkhronos/llama.cpp that referenced this pull request Sep 28, 2026
Bring the PR current with ggml-org master (f00a64c). The only conflict was in
tests/CMakeLists.txt: master's ggml-org#29426 refactored test-recurrent-state-rollback
to run across every generated model via --models, which already covers glm5-next
(it is generated by test-llama-archs and is recurrent, so not skipped, and the
runner fails if any model fails). The PR's separate per-arch glm5-next
invocation was therefore redundant and dropped; glm5-next rollback is still
exercised by the all-archs run.
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 7, 2026
* tests : use llama_context_ptr in test-recurrent-state-rollback

Replace raw llama_context pointers with llama_context_ptr and drop the
manual llama_free calls and cleanup lambda.

Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-RL

* tests : run test-recurrent-state-rollback over all dummy models

Add a --models DIR mode that mirrors test-save-load-state: iterate every
dummy model, report PASS/FAIL/SKIP in a table and fail only when a model
fails. Register a single ctest entry with ARGS --models instead of the four
per-model registrations.

Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-RL

* cont : fix typo

* metal : allow fusing 0-element nodes to keep graph packing shape-independent

The fusion packing in ggml_metal_fusion_max excluded 0-element tensors and
the topk_moe/moe_reduce checks rejected n_tokens == 0, so graphs decoding
batches with no outputs packed differently from the worst-case reserved
graph. The Metal optimizer then reordered the nodes differently and
ggml_gallocr_needs_realloc failed on the layout mismatch, forcing an
unexpected graph re-reserve (caught by GGML_SCHED_DEBUG_REALLOC).

Treat empty tensors like their non-empty counterparts: match them in the
pattern sequence and only reject genuinely malformed shapes. Fused kernels
dispatch zero threadgroups for empty graphs, which is a legal no-op.

Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-RL

* tests : run test_multi_seq_split_replay as a separate test

test_multi_seq_split_replay was invoked at the end of test_rollback,
so its result was folded into the rollback status and it only ran when
the rollback part passed.

Give it its own test_status return, run both tests independently over
both cache fills via a shared run_tests helper, and report them as
separate rollback / split replay columns in the --models table with
per-test summaries. The exit code fails when either test fails.

Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-RL

* tests : loosen the split replay nmse bound to 1e-4

test-generate-models seeds its weights from std::random_device, and some
generated lfm2 models drift up to ~1.7e-5 nmse on the split replay due to
rounding noise, tripping the previous 1e-5 bound. Raise the bound to 1e-4
so the random generations stop flaking.

Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-RL

* tests : reuse run_tests_for_model in single-model mode

The single-model path duplicated the model init and the non-recurrent
check from run_tests_for_model; route it through the shared helper
instead. Model load failures now return FAIL rather than SKIP so that
--model with a broken file still exits non-zero, and the helper loads
with model_only like the --models loop does since the tests create
their own contexts.

Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-RL
(cherry picked from commit d77dd08)
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) ggml changes relating to the ggml tensor library for machine learning testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants