Skip to content

bailingmoe3 : fuse ssm_conv + silu and remove redundant copies - #33081

Merged
ngxson merged 2 commits into
ggml-org:masterfrom
stornic56:e1-e2b-pr
Nov 26, 2026
Merged

ngxson merged 2 commits into
ggml-org:masterfrom
stornic56:e1-e2b-pr

Conversation

@stornic56

Copy link
Copy Markdown
Contributor

Overview

This small PR makes two bit-exact graph optimizations in src/models/bailingmoe3.cpp without requiring GGUF layout changes:

  1. Enable SSM_CONV_SILU fusion in build_causal_conv1d: Move ggml_silu before ggml_reshape_2d on the contiguous ggml_ssm_conv output. Backends can then fuse the convolution and activation into a single kernel (replacing 54 separate SSM_CONV + SILU ops with 54 fused SSM_CONV_SILU ops per token).
  2. Remove redundant ggml_cont / ggml_cont_2d ops: Replace unnecessary copies on already-contiguous tensors after build_recurrent_attn and ggml_mul with ggml_reshape_2d or direct tensor usage (reducing CONT ops from 48 to 6 per token; the remaining 6 come from generic build_attn_mha).

Benchmarks (llama-bench)

Tested on Intel Arc B580 (Vulkan, Mesa), i3-12100F, -t 4 -ngl 99, Ling-3.0-tiny-256K-Q8_0.gguf, paired AB/BA runs ($n=10$):

Depth Metric Gain (E1+E2b vs base) 95% CI $p$-value
d=0 tg64 +1.73% [+1.21%, +2.24%] 0.00003
d=4096 tg64 +2.68% [+1.74%, +3.62%] 0.00012
d=0 / 4096 pp128 No regression — n.s.

Additional information

Verification

  • Bit-exactness: Identical greedy outputs (--temp 0 --seed 42, 200 tokens) and identical perplexity (13.4126 +/- 0.48464) across CPU (-ngl 0) and Vulkan (-ngl 99).
  • Batching and concurrency: Verified with llama-server -np 4 (4 concurrent requests), llama-batched-bench -npl 1,2,4,8, chunked prefill (-b 128 -ub 64), and --spec-type ngram-mod (identical 200-token output).
  • Scale and quantizations: Verified across Q8_0, Q4_K_M, and IQ4_XS up to 16k context (pp16384), as well as Ling-3.0-flash (IQ1_S, 124B-A5.1B, -ncmoe 31) and the SYCL backend.
  • Memory: Compute buffer footprint is unchanged (60.51 / 12.53 MiB at decode).

Notes

  • graph_mtp was left untouched because Ling-3.0-tiny has n_layer_nextn = 0.
  • Similar silu after reshape_2d patterns exist in other recurrent models (glm5-next, kimi-linear, inkling2), left out of scope for this PR.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: Yes. AI assists and help me in implementing the code and completing functional testing.

@stornic56
stornic56 requested a review from a team as a code owner November 26, 2026 04:56
@ggml-gh-bot

ggml-gh-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

Hi @stornic56, thanks for your contribution!

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

  • 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.

@github-actions github-actions Bot added the model Model specific label Nov 26, 2026

@CISC CISC 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.

@CISC CISC added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Nov 26, 2026
@stornic56

Copy link
Copy Markdown
Contributor Author

Nice, thanks, optional to fix: https://github.com/ggml-org/llama.cpp/actions/runs/45758339973/job/139833451441?pr=33081#step:6:398

hiii thank youuu. I dont have a Mac to test and debug that tolerance diff locally, so im happy to leave it as is if its fine for merge.

@ngxson
ngxson merged commit 492d23c into ggml-org:master Nov 26, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. model Model specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants