Skip to content

perf: use ggml rope apply op on supported backends - #2113

Merged
leejet merged 1 commit into
masterfrom
perf/apply_rope_kernel
Oct 8, 2026
Merged

leejet merged 1 commit into
masterfrom
perf/apply_rope_kernel

Conversation

@leejet

@leejet leejet commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Replace the multi-operation RoPE graph with ggml_rope_apply when the input layout, type and backend support it.

Related Issue / Discussion

N/A

Additional Information

.\bin\Release\sd-cli.exe --diffusion-model  ..\models\diffusion_models\qwen_image_2.1-Q4_K.gguf --vae ..\models\vae\qwen_image_2.1_vae_bf16.safetensors  --llm ..\models\text_encoders\Qwen3VL-8B-Instruct-Q4_K_M.gguf  -p "a lovely cat holding a sign says 'qwen2.1.cpp'" --cfg-scale 1.0 --sampling-method euler -v --offload-to-cpu --fa

cuda: 8.88it/s -> 9.82it/s
vulkan: 7.76it/s -> 8.31it/s

Checklist

Summary by CodeRabbit

  • Performance
    • Rotary position processing can now use supported backend operations in eligible cases, with the existing fallback retained when those operations are unavailable. This may improve performance in supported configurations across several attention-based models.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d95fc3e6-4328-4f7d-b53e-58e345cf3beb
📥 Commits

Reviewing files that changed from the base of the PR and between e16d26a and fe552fa.

📒 Files selected for processing (7)
  • ggml
  • src/model/common/rope.hpp
  • src/model/diffusion/anima.hpp
  • src/model/diffusion/ltxv.hpp
  • src/model/diffusion/minimax_h3.hpp
  • src/model/diffusion/qwen_image_2_1.hpp
  • src/model/vae/minimax_h3_vae.hpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

RoPE now accepts a GGMLRunnerContext and can use ggml_rope_apply for eligible inputs when the backend supports it. Attention helpers and call sites pass the runner context. The ggml subproject reference also changes.

Changes

Runner-aware RoPE

Layer / File(s) Summary
Runner-aware RoPE dispatch
ggml, src/model/common/rope.hpp
apply_rope receives the runner context and attempts ggml_rope_apply for eligible inputs outside upstream GGML builds. If the backend cannot perform the operation, the existing manual implementation uses the runner's GGML context. The ggml subproject reference changes.
Model attention call sites
src/model/diffusion/anima.hpp, src/model/diffusion/ltxv.hpp, src/model/diffusion/minimax_h3.hpp, src/model/diffusion/qwen_image_2_1.hpp, src/model/vae/minimax_h3_vae.hpp
Attention helpers and call sites pass the runner context for query and key RoPE operations. Helpers that reshape tensors obtain the GGML context from the runner.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: daniandtheweb

Merge Risk: ⚪ Minimal · up to fe552

This change switches RoPE to a faster backend operation where it is supported, and keeps the existing path everywhere else. No concrete merge-blocking risk was found.

Security Architecture Review

Security architecture risk: 🔵 Low · up to fe552

The change does not visibly add external access or privileges and retains a compatibility fallback. The newly selected operation could not be fully inspected, so its memory-safety and output guarantees remain unverified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — For the reviewed callers, the changed execution remains within the existing inference process and runner-selected backend, affecting query/key transformations across diffusion and VAE attention. No new privilege or external access route is evidenced; hosting and tenant isolation were not established.

Trust Boundaries and Controls

  • observed — RoPE derives execution authority from the existing runner-owned backend and context. It reads neither credentials nor an alternative execution target, and an unsupported candidate is not returned to its consumers.

Resilience and Maintainability Implications

  • observed — The runner rejects reentrant graph execution and centrally cleans graph resources on normal return and failure unwinding. Whether repeated rejected RoPE candidates require additional cleanup remains unresolved without the dependency source.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 6 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description includes all required sections. It clearly states the RoPE performance change, provides verification results for CUDA and Vulkan, and confirms the contribution checklist.
Title check ✅ Passed The title clearly and concisely describes the main change: using the GGML RoPE operation on supported backends for performance.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 6 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@leejet
leejet merged commit 228c707 into master Oct 8, 2026
12 checks passed
@leejet
leejet deleted the perf/apply_rope_kernel branch October 8, 2026 20:33
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.

1 participant