Skip to content

dory support for llama.cpp - #30306

Open
brianchmielNV wants to merge 10 commits into
ggml-org:masterfrom
brianchmielNV:dory-support
Open

brianchmielNV wants to merge 10 commits into
ggml-org:masterfrom
brianchmielNV:dory-support

Conversation

@brianchmielNV

@brianchmielNV brianchmielNV commented Oct 10, 2026 •

Copy link
Copy Markdown

Overview

NVIDIA-Nemotron-Labs-Dory1.0-4B-BF16 is a latent-recurrent / looped large language Model (LLM) trained by NVIDIA. This is the full-precision (BF16) release of Dory1.0-4B. The model employs normalized-GPT architecture with interleaved hybrid sliding window attention (SWA) and full attention layers. By repeatedly applying a shared block of layers, Dory1.0-4B can trade inference compute for accuracy by changing the loop count.

The PR include:
HF-to-GGUF conversion to support Dory model
Support for recurrent loops k=1-4
support of kv cache separate per loops and slaos last loop kv cache shared. last_loop retains historical tokens’ final-loop KV. It changes predictions compared with separate caches, and prefill chunk size matters.
Tested: bf16, q4_k_m and q5_k_m formats

Additional information

Referencing vLLM PR #60149 (vllm-project/vllm#60149).
include: 96/96 numerical comparisons on CPU and CUDA separately; 36/36 real-checkpoint serving smoke tests
limitations: Metal untested; full CI and long-context qualification incomplete; context shifting, runtime re-save, and K>4 unsupported.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure:
    Yes, Use gpt-6-astra to create the code and tests. including debuging.

@brianchmielNV
brianchmielNV requested review from a team, CISC and ggerganov as code owners October 10, 2026 17:13
@github-actions github-actions Bot added documentation Improvements or additions to documentation model Model specific testing Everything test related ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend conversion labels Oct 10, 2026
@brianchmielNV
brianchmielNV marked this pull request as draft October 10, 2026 17:17
@ggml-gh-bot

This comment was marked as resolved.

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Oct 10, 2026
@brianchmielNV
brianchmielNV marked this pull request as ready for review October 10, 2026 17:28
@CISC
CISC marked this pull request as draft October 10, 2026 18:54
@CISC

CISC commented Oct 10, 2026

Copy link
Copy Markdown
Member

Sorry, this is not ready, here's just a brief list of things that need to improve, but I also suggest you study other model PRs closely to get the general gist:

  • do not use metadata key strings directly, and esp. not the architecture part
  • if you have a good reason for allow_non_f32_vectors it may be solved differently
  • tensors should be named after task, not arch
  • do not add new test files unless absolutely necessary
  • do not touch ops docs unless you are regenerating them

…tions.

  - BF16 parameters: removed the broad allow_non_f32_vectors switch; retained BF16 handling specifically for Dory scale parameters.
  - Tensor naming: renamed tensors by their function rather than the Dory architecture.
  - Tests: moved upstream coverage into existing test files; corrected shared-KV tests to respect chunk-dependent behavior.
  - Generated documentation: removed manual edits to generated operation-support files.
@brianchmielNV

Copy link
Copy Markdown
Author

I pushed and review changes that should adress all 5 points raised.

@JohannesGaessler JohannesGaessler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR is making unrelated changes to the CUDA backend. For our bookkeeping this is unacceptable for a PR that adds model support.

@brianchmielNV

Copy link
Copy Markdown
Author

I removed in commit a99be4a the CUDA fix and its dedicated tests. without changing the Dory support.
BF16 / q4 and q5 passed checks,
Does this answer the reviewer concern?

@JohannesGaessler
JohannesGaessler dismissed their stale review October 13, 2026 11:42

CUDA specific issue resolved, no comment regarding the rest.

@brianchmielNV

Copy link
Copy Markdown
Author

@CISC I’ve addressed the five points from your review and removed the unrelated CUDA changes. Johannes confirmed that the CUDA-specific concern is resolved. Could you please re-review the Dory changes and approve the CI workflows when you have time? Please let me know if anything else needs fixing before this is ready for review. Thank you for your time

@coder543

Copy link
Copy Markdown
Contributor

This model looks compelling. Are there any remaining blockers to merging?

image

ricardodeazambuja added a commit to ricardodeazambuja/gemma4-26B-only-8B-VRAM that referenced this pull request Oct 19, 2026
…sh PATCH=

The Dory build no longer depends on the PR author's fork: the full diff of
ggml-org/llama.cpp#30306 (base 6e66cb5 -> head 43e865e, 17 files,
+507/-9, MIT notice in the header) is kept in patches/, and
build-llama-cuda.sh gained PATCH= to git-apply it on top of stock
llama.cpp (skipped if already applied, fails if it doesn't apply).

Verified: the patch on 6e66cb5 reproduces the PR tree exactly, and a
from-scratch build that way serves Dory at the same speed (28.8 vs 29.3
tok/s, prefill 852 tok/s both, tool call ok).

docs/dory-on-8gb.md: new section explaining what the patch adds (dory
arch, virtual layers = 16 + 40 x loops + 16 -> why -ngl 999, loop/nGPT
graph, KV modes, converter) and the alternative of building the PR
commit straight from ggml-org. Corrects the earlier claim that the PR
head adds a CUDA precision fix: it moved that TF32 change out, which is
a no-op on Turing anyway.
@Exploder98

Copy link
Copy Markdown
Contributor

The current conversion code does not work with the published checkpoints at https://huggingface.co/nvidia/NVIDIA-Nemotron-Labs-Dory1.0-4B-BF16. Almost all of the parameters in required dict are missing from config.json, and even after that the code tries to access other keys that are missing from that config.

arimoshe pushed a commit to arimoshe/llama.rn that referenced this pull request Nov 7, 2026
Dory (NVIDIA-Nemotron-Labs-Dory1.0-4B) is a looped normalized-GPT: 16
input, 40 recurrent and 16 output layers, the recurrent block run
num_loops times per token, with sliding-window and full attention.

- Port ggml-org/llama.cpp#30306 (brianchmielNV/llama.cpp @ 98a74c9) as
  scripts/patches/llama.cpp/dory-*.patch. Only src/ is needed here; the
  PR's CUDA change does not apply to these builds. sync-vendor.sh on a
  clean tree reproduces vendor/llama.cpp byte for byte.
- kv_overrides (JS load option): model metadata overrides keyed as in
  the GGUF, e.g. { 'dory.num_loops': 2,
  'dory.recurrent_kv_cache_mode': 'last_loop' }. A whole number is an
  int, any other number a float.
- The K2-Horizon release now also fails if a library lacks Dory.
- Version 0.13.0-rc.6-k2h.10.

Tested on x86 (4 threads) with NVIDIA's Q5_K_M GGUF: coherent output at
1, 2 and 4 loops, and at 2 loops with last_loop caching; 6.1, 4.3 and
2.4 tokens/s at 1, 2 and 4 loops.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JV9oPdgsGMH9vsUiWtW1v4
TysAIs added a commit to TysAIs/slm-gauntlet that referenced this pull request Nov 7, 2026
…ving on the 1070 Ti

The excluded dory and lfm3 rows were gated on an engine upgrade, not a retry.
That upgrade is now built and proven: /opt/llama.cpp-dory (PR ggml-org/llama.cpp#30306,
1c3cdd2, CUDA sm_61) loaded Dory Q5_K_M and LFM3-1.7B-IQ2_M and answered real
chat completions on 127.0.0.1:8892. The running campaign keeps a2878d3 so its 48
configs stay comparable; the next sweep can re-enable those rows as an
engine-vs-engine change. Dory per_loop KV costs ~4x normal KV per token.
@maternion

Copy link
Copy Markdown
Contributor

Any idea when this could get merged? Looped models seem to work great at these scales.

…A numerical, serving, conversion, FP8 and KV-shift checks.
@brianchmielNV
brianchmielNV marked this pull request as ready for review November 12, 2026 11:23
@brianchmielNV
brianchmielNV requested review from a team as code owners November 12, 2026 11:23
Daniele-Felicetta pushed a commit to Daniele-Felicetta/Palamede that referenced this pull request Nov 12, 2026
Dory1.0 4B usa l'arch. `dory`, che non esiste in llama.cpp (solo nella PR
ggml-org/llama.cpp#30306): con b11457/b11707 il load muore con "unknown model
architecture". Il hub ora risolve il binario per modello (engine: 'dory' ->
tools/llama-cpp-dory) e tiene il modello fuori dalla lista finché quel motore
manca, così non compare mai elencato e rotto.

Nemotron 3.5 Bolt E4B era nel registry del hub ma invisibile in Chat: mancava
la voce in text.ts. Correggo anche catalogo (puntava a un UD-Q4_K_XL da 5,06 GB
con lo SHA del file locale: ogni download finiva con "SHA256 non corrisponde"),
manifest, percorsi dei bench ARC/probe-thinking e documentazione.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <[email protected]>
@pwilkin

pwilkin commented Nov 14, 2026

Copy link
Copy Markdown
Member

/bot review

@ggml-gh-bot

ggml-gh-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Automated code review

Review of PR #30306 (dory support)

Checklists run: General, Security, New model/architecture, Approach & design, Tests, plus the quick-reject gate. Overall this is a well-contained, single-purpose arch PR. The physical/virtual layer indroduction (n_layer_physical() / layer_physical() virtuals) is behavior-preserving for all other archs (default n_layer_physical() == hparams.n_layer_all, and the fit.cpp/n_gpu_layers() math reduces to the old expressions), and the metadata validation in load_arch_hparams is thorough (n_loops bounded, n_virtual computed in u64 and checked against LLAMA_MAX_LAYERS before any array write, pattern charset + length checks). The shared-cache WAW ordering in last_loop mode is safe because each loop's cache write is serialized through the activation chain of the preceding loop.

Should fix

(point 1) Direct ggml_rope_ext bypasses rope scaling and duplicates existing machinery - src/models/dory.cpp:160-161. The call hardcodes freq_scale = 1.0f and no yarn factors, so user-specified rope scaling (--rope-scaling, --rope-freq-scale, yarn) is silently ignored for this arch - a user extending context this way gets no effect and no warning. The per-profile theta you select by hand is already encoded in hparams (rope_freq_base_train = theta_1, and you set rope_freq_base_train_swa = theta_2, with profile-2 == SWA layers by construction), so build_rope(cur, pos, il) reproduces the exact same graph while honoring runtime scaling. The model.profile[p] != 0 gate at line 158 also duplicates what hparams.rope_pattern (set at line 78) already expresses via has_rope(). Per the convention from #31683, RoPE in src/models/ should go through build_rope; the remaining direct calls elsewhere are not a pattern to copy.

(point 2) Graph-wide ggml_prec_set_src post-pass reinvents the existing precision hook - src/models/dory.cpp:195-199. There is already a llama_prec_policy with a prec_src1 map keyed by weight tensor, applied inside build_lora_mm (src/llama-graph.cpp:1691, src/llama-model.h:700). Every MUL_MAT in the dory graph is built via build_lora_mm/build_qkv, so registering the F32 rule in the prec policy (or calling ggml_prec_set_src at the matmul creation site, as the GLM4 path does with ggml_prec_set_acc) covers the same nodes at the right layer. The blanket post-pass is fragile (it silently also changes LoRA matmuls, and any future non-build_lora_mm matmul in this file would need to remember the walk exists) and its comment does not explain why the creation-site approach was not used.

(point 3) Redundant special case in conversion/base.py:1567-1580 - the F32-override skip for the six scale tensor roles duplicates DoryModel.tensor_force_quant (conversion/dory.py:15-27), which already returns F16/BF16/F32 for exactly those tensors. For every ftype the two code paths produce the same result, so one of them is dead weight, and the two copies of the 6-key list will drift. Keep the arch-local override (it is the standard mechanism) and drop the base.py hunk, or share one module-level constant.

(point 4) No quantized KV-cache coverage - the new attention path (per-loop caches, shared-cache repeated writes, iswa wrapper) is exactly the kind of feature that silently breaks with -ctk/-ctv q8_0, but neither the fixture test nor the PR description exercises quantized KV. Please add a config to test-llama-archs with type_k/type_v = Q8_0 (both cache modes), or state in the PR why it is deferred.

Nits

(point 5) Formatting drift in src/llama-arch.cpp: the added LLM_KV_RECURRENT_KV_CACHE_MODE/LLM_KV_ROPE_FREQ_BASE_2 entries in LLM_KV_NAMES, four entries in LLM_TENSOR_NAMES, and LLM_TENSOR_OUTPUT_SCALE in LLM_TENSOR_INFOS are misaligned with their neighbors. Run clang-format over the touched files.

(point 6) src/llama-model.cpp:3417: the filter's hparams.n_head_kv(il) > 0 re-checks what has_kv() already enforces before the filter is consulted (src/llama-kv-cache.cpp:167); dory.cache_layer[il] == (int) il alone is sufficient.

(point 7) src/models/dory.cpp:192: ggml_build_forward_expand(gf, cur) on t_logits is redundant - build_graph() expands logits via build_logits().

(point 8) conversion/dory.py: h.get("attention_output_gate_logit_scale_init") or h["hidden_size"]**0.5 (line 107) silently substitutes when the value is present but 0; and missing public-config keys (n_input_layers, n_recurrent_layers, n_output_layers, n_recurrent_loops) surface as raw KeyError instead of a ValueError explaining the requirement. The --fuse-qkv error message (line 89) mentions Q4_K_M specifically although the restriction is general.

(point 9) Process notes: I don't see a linked llama.cpp issue for this feature - features are supposed to start with an issue/discussion first; there is clearly maintainer engagement in the comments already, but linking one would help. The AI disclosure is filled in, thank you - just keep in mind that per CONTRIBUTING.md/AGENTS.md you are expected to be able to explain and debug every line here without assistance. Given the shared-core touches (llama-model.cpp offload placement, llama-context.cpp, common/fit.cpp), expect this to need extra maintainer scrutiny; those hunks all verified as no-ops for existing archs.

This review was generated automatically by pi coding agent using zai-org/GLM-5.3. It may contain mistakes. Maintainers make the final call.

@pwilkin

pwilkin commented Nov 14, 2026

Copy link
Copy Markdown
Member

@brianchmielNV PTAL at the review notes and fix the major ones.

bagumamartin added a commit to bagumamartin/dory-metal-fix that referenced this pull request Nov 17, 2026
The same fix landed in ggml-org/llama.cpp#30306 on 2026-10-20 (9e2f3be).
NVIDIA's model card still pins 98a74c9, which predates it. Reframe the
patch as a backport for that revision and point readers to a newer one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TysAIs added a commit to TysAIs/slm-gauntlet that referenced this pull request Nov 17, 2026
…ving on the 1070 Ti

The excluded dory and lfm3 rows were gated on an engine upgrade, not a retry.
That upgrade is now built and proven: /opt/llama.cpp-dory (PR ggml-org/llama.cpp#30306,
1c3cdd2, CUDA sm_61) loaded Dory Q5_K_M and LFM3-1.7B-IQ2_M and answered real
chat completions on 127.0.0.1:8892. The running campaign keeps a2878d3 so its 48
configs stay comparable; the next sweep can re-enable those rows as an
engine-vs-engine change. Dory per_loop KV costs ~4x normal KV per token.
Fangyuan025 pushed a commit to Fangyuan025/llama.cpp that referenced this pull request Nov 21, 2026
ggml-org#30306 squashed onto master: NVIDIA's Nemotron-Labs Dory
1.0, input, looped recurrent and output layer groups, the recurrent group run
num_loops times with a cache for each pass.

On top of the pull request: its graph budget, 128 nodes a layer, is the
model's graph_nodes_per_tensor, as master now sizes graphs; its test harness
changes, which no longer apply to master's, are left out.

Chaty-Carry: optional
Fangyuan025 pushed a commit to Fangyuan025/llama.cpp that referenced this pull request Nov 21, 2026
ggml-org#30306 squashed onto master: NVIDIA's Nemotron-Labs Dory
1.0, input, looped recurrent and output layer groups, the recurrent group run
num_loops times with a cache for each pass.

On top of the pull request: its graph budget, 128 nodes a layer, is the
model's graph_nodes_per_tensor, as master now sizes graphs; its test harness
changes, which no longer apply to master's, are left out.

Chaty-Carry: optional
Fangyuan025 pushed a commit to Fangyuan025/llama.cpp that referenced this pull request Nov 21, 2026
ggml-org#30306 squashed onto master: NVIDIA's Nemotron-Labs Dory
1.0, input, looped recurrent and output layer groups, the recurrent group run
num_loops times with a cache for each pass.

On top of the pull request: its graph budget, 128 nodes a layer, is the
model's graph_nodes_per_tensor, as master now sizes graphs; its test harness
changes, which no longer apply to master's, are left out.

Chaty-Carry: optional
Fangyuan025 pushed a commit to Fangyuan025/llama.cpp that referenced this pull request Nov 21, 2026
ggml-org#30306 squashed onto master: NVIDIA's Nemotron-Labs Dory
1.0, input, looped recurrent and output layer groups, the recurrent group run
num_loops times with a cache for each pass.

On top of the pull request: its graph budget, 128 nodes a layer, is the
model's graph_nodes_per_tensor, as master now sizes graphs; its test harness
changes, which no longer apply to master's, are left out.

Chaty-Carry: optional
@shan18 shan18 mentioned this pull request Nov 21, 2026
  - Use standard RoPE and precision-policy helpers
  - Improve converter validation and share scale-tensor definitions
  - Add Q8_0 KV-cache and FFN-only offload regression tests
  - Fix architecture-test graph reservations
@brianchmielNV

Copy link
Copy Markdown
Author

@pwilkin I pushed the the review fixes in 8481bd0 and resolved the upstream merge conflicts.

Changes:

  • Use build_rope and the existing precision-policy mechanism.
  • Share the converter’s scale-tensor definitions and improve metadata validation.
  • Add Q8_0 KV-cache tests for both cache modes.
  • Fix the architecture-test buffer reservation issue.
  • Apply the formatting and redundant graph-expansion cleanups.

Two suggested removals were not safe:

  • I retained the head-count check. has_kv() checks cache ownership, not whether a layer has KV heads. Removing the check
    broke automatic fitting when only the final FFN and output head were offloaded. Regression tests now cover this.
  • I retained the base converter guard, using the shared definitions. Without it, the generic conversion path overrides
    the intended BF16/F16 scale storage with F32.

Could you please re-review and approve the pending CI workflows? Thank you.

Comment thread src/llama-kv-cache.cpp
Comment on lines +1226 to +1229
// Dory uses physical-layer RoPE profiles and post-RoPE normalization.
if (model.arch == LLM_ARCH_DORY) {
return false;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you sure about this? build_rope can already handled this

add a test case in test_kv_shift just to be use

JoytaHkN added a commit to JoytaHkN/PyroHorns that referenced this pull request Nov 25, 2026
Fangyuan025 pushed a commit to Fangyuan025/llama.cpp that referenced this pull request Nov 26, 2026
ggml-org#30306 squashed onto master: NVIDIA's Nemotron-Labs Dory
1.0, input, looped recurrent and output layer groups, the recurrent group run
num_loops times with a cache for each pass.

On top of the pull request: its graph budget, 128 nodes a layer, is the
model's graph_nodes_per_tensor, as master now sizes graphs; its test harness
changes, which no longer apply to master's, are left out.

Chaty-Carry: optional
Fangyuan025 pushed a commit to Fangyuan025/llama.cpp that referenced this pull request Nov 27, 2026
ggml-org#30306 (8481bd0) squashed onto master: NVIDIA's
Nemotron-Labs Dory 1.0, input, looped recurrent and output layer groups, the
recurrent group run num_loops times with a cache for each pass.

On top of the pull request: its quantization recipe names master's tensor
categories as master spells them now (TENSOR_CATEGORY_FFN_*), and its test
harness changes, which no longer apply beside master's, are left out.

Chaty-Carry: optional

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

conversion CUDA Related to the CUDA backend documentation Improvements or additions to documentation draft PR will be changed to draft by github-actions bot 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.

10 participants