Skip to content

cpu: add F16 SWIGLU_OAI reference implementation and validation - #29200

Merged
ggerganov merged 2 commits into
ggml-org:masterfrom
qualcomm:upstream-f16-swiglu-reference
Oct 15, 2026
Merged

ggerganov merged 2 commits into
ggml-org:masterfrom
qualcomm:upstream-f16-swiglu-reference

Conversation

@cqderek

@cqderek cqderek commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Add the CPU F16 reference implementation for "SWIGLU_OAI".

This implementation mirrors the existing F32 path and provides a CPU reference for validating downstream backend implementations.

The related test changes provide correctness validation for the F16 "SWIGLU_OAI" path. They are not intended to be performance benchmarks.

Requirements

I have read and agree with the contributing guidelines
AI usage disclosure: AI tools were used to assist with code review and documentation. I reviewed and verified all submitted changes.

@cqderek
cqderek requested a review from ggerganov as a code owner September 21, 2026 05:47
@github-actions github-actions Bot added testing Everything test related ggml changes relating to the ggml tensor library for machine learning labels Sep 21, 2026
@cqderek

cqderek commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

@max-krasnyansky

Could you kindly help to review this PR? Thanks in advance!

@max-krasnyansky

Copy link
Copy Markdown
Member

I'm going to close this for a sec to undraft the PR for F16 activations

@max-krasnyansky max-krasnyansky Sep 29, 2026 •

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.

@cqderek why are we removing this?

@max-krasnyansky

Copy link
Copy Markdown
Member

@cqderek good that we split the test :) see the CI failures. Let's try to fix those.
Ping me here so that I can kick the pipeline

@cqderek
cqderek force-pushed the upstream-f16-swiglu-reference branch 2 times, most recently from 1682f26 to 932bc47 Compare October 4, 2026 02:21
@cqderek

cqderek commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@max-krasnyansky

Fixed the CI failures, please help to review again, thx.

@max-krasnyansky

Copy link
Copy Markdown
Member

Looks good to me.
@CISC @ggerganov any objections/suggestions?

Comment thread tests/test-backend-ops.cpp Resolved
@CISC

CISC commented Oct 5, 2026

Copy link
Copy Markdown
Member

You may want to add check in cuda backend.

@ggml-org/ggml-cuda Unless F16 is worth adding support for?

@am17an

am17an commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Sure, we're looking at various intermediate activations apart from f32. bf16/f16 support is welcome

@cqderek cqderek changed the title cpu: add F16 SWIGLU_OAI reference implementation and F16 activation o… cpu: add F16 SWIGLU_OAI reference and activation-op test coverage Oct 7, 2026
@cqderek
cqderek force-pushed the upstream-f16-swiglu-reference branch from 932bc47 to 2c8da6a Compare October 7, 2026 15:40
@cqderek

cqderek commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Sure, we're looking at various intermediate activations apart from f32. bf16/f16 support is welcome

CUDA F16 support is outside the scope of this CPU reference and backend-validation change; it can be handled separately.

@cqderek

cqderek commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@CISC @max-krasnyansky Please help to review again, thanks.

@cqderek
cqderek force-pushed the upstream-f16-swiglu-reference branch from 2c8da6a to 45978ea Compare October 8, 2026 02:39
@cqderek

cqderek commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@CISC I removed the GLU, ABS, and LOG cases from the function "make_test_cases_perf()", please help to review again, thanks.

@cqderek cqderek changed the title cpu: add F16 SWIGLU_OAI reference and activation-op test coverage cpu: add F16 SWIGLU_OAI reference implementation Oct 8, 2026
@cqderek cqderek changed the title cpu: add F16 SWIGLU_OAI reference implementation cpu: add F16 SWIGLU_OAI reference implementation and validation Oct 8, 2026
@CISC

CISC commented Oct 8, 2026

Copy link
Copy Markdown
Member

Since you haven't ticked the box to allow us to push changes you will have to modify this so that CIs won't fail while swiglu_oai+F16 is unsupported in cuda backend before we can merge:
https://github.com/ggml-org/llama.cpp/blob/45978eaaa955b25accf8a198620579c8c91718af/ggml/src/ggml-cuda/ggml-cuda.cu#L5304-L5306

@cqderek
cqderek force-pushed the upstream-f16-swiglu-reference branch from 45978ea to ad770af Compare October 8, 2026 09:13
@cqderek
cqderek requested a review from a team as a code owner October 8, 2026 09:13
@cqderek
cqderek force-pushed the upstream-f16-swiglu-reference branch 3 times, most recently from 01930f7 to 4e8ab78 Compare October 8, 2026 13:19
@cqderek
cqderek requested a review from a team as a code owner October 8, 2026 13:19
@github-actions github-actions Bot added the Vulkan Issues specific to the Vulkan backend label Oct 8, 2026
@0cc4m

0cc4m commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

do not do unrelated Vulkan changes. That CI failure is covered by #30145

@cqderek
cqderek force-pushed the upstream-f16-swiglu-reference branch from 4e8ab78 to 5332b0f Compare October 8, 2026 13:32
@CISC
CISC removed the request for review from a team October 8, 2026 14:52
…p test coverage

Adds ggml_compute_forward_swiglu_oai_f16() to the CPU backend, mirroring
the existing F32 path, and extends test-backend-ops with F16 test cases
for SWIGLU_OAI so downstream backends(e.g. Hexagon) can be CPU-diffed
for correctness.
@cqderek
cqderek force-pushed the upstream-f16-swiglu-reference branch from 5332b0f to 6ead3ef Compare October 14, 2026 08:45
@cqderek
cqderek requested a review from CISC October 14, 2026 08:47
@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 Oct 14, 2026
@CISC

CISC commented Oct 14, 2026

Copy link
Copy Markdown
Member

cc/ @ggml-org/ggml-openvino @ggml-org/ggml-openvino-triage OpenVINO fails, probably needs a check as well:
https://github.com/ggml-org/llama.cpp/actions/runs/38537440881/job/115772341648?pr=29200#step:5:27298

@ravi9

ravi9 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

@cqderek : Could you please cherry-pick the fix for OpenVINO backend :

git fetch https://github.com/ravi9/llama.cpp ov-fix-swiglu-oai-f16
git cherry-pick 8481ba11bb37b1bb801a78da5698ff58388f8a7e 

cc: @CISC

translate_glu_swiglu_oai creates alpha_const and one as f32 constants
unconditionally, so f16 inputs hit a type mismatch in Swish/Add on GPU
("Swish inputs must have the same type but they are: f16 and f32").
translate_glu_swiglu_clamp already upcasts to f32 and converts back at
the end; apply the same pattern here.
@max-krasnyansky

Copy link
Copy Markdown
Member

@cqderek : Could you please cherry-pick the fix for OpenVINO backend :

git fetch https://github.com/ravi9/llama.cpp ov-fix-swiglu-oai-f16
git cherry-pick 8481ba11bb37b1bb801a78da5698ff58388f8a7e 

cc: @CISC

Done

@ggerganov
ggerganov merged commit 5a638ae into ggml-org:master Oct 15, 2026
40 of 42 checks passed
@BrewTestBot BrewTestBot mentioned this pull request Oct 15, 2026
1 task done
wanghqc added a commit to qualcomm/llama.cpp that referenced this pull request Oct 22, 2026
kernel_swiglu_oai is f32-only, but supports_op accepted f16 too, so an f16
SWIGLU_OAI read its inputs as f32: wrong values and a write past the output
(the f16 test-backend-ops cases from ggml-org#29200 catch both).
wanghqc added a commit to qualcomm/llama.cpp that referenced this pull request Oct 23, 2026
supports_op accepted f16 SWIGLU_OAI, but only an f32 kernel existed, so the
f16 inputs were read as f32: wrong values and a write past the output (the
f16 test-backend-ops cases from ggml-org#29200 catch both). Add kernel_swiglu_oai_f16,
which, like swiglu_clamp_f16, loads half, computes in float and stores half.
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 24, 2026
…-org#29200)

* cpu: add F16 SWIGLU_OAI reference implementation and F16 activation op test coverage

Adds ggml_compute_forward_swiglu_oai_f16() to the CPU backend, mirroring
the existing F32 path, and extends test-backend-ops with F16 test cases
for SWIGLU_OAI so downstream backends(e.g. Hexagon) can be CPU-diffed
for correctness.

* ggml-openvino: fix f16 SWIGLU_OAI type mismatch in alpha/one constants

translate_glu_swiglu_oai creates alpha_const and one as f32 constants
unconditionally, so f16 inputs hit a type mismatch in Swish/Add on GPU
("Swish inputs must have the same type but they are: f16 and f32").
translate_glu_swiglu_clamp already upcasts to f32 and converts back at
the end; apply the same pattern here.

---------

Co-authored-by: ravi9 <ravi.panchumarthy@intel.com>
auRose94 pushed a commit to auRose94/llama.cpp that referenced this pull request Oct 28, 2026
…-org#29200)

* cpu: add F16 SWIGLU_OAI reference implementation and F16 activation op test coverage

Adds ggml_compute_forward_swiglu_oai_f16() to the CPU backend, mirroring
the existing F32 path, and extends test-backend-ops with F16 test cases
for SWIGLU_OAI so downstream backends(e.g. Hexagon) can be CPU-diffed
for correctness.

* ggml-openvino: fix f16 SWIGLU_OAI type mismatch in alpha/one constants

translate_glu_swiglu_oai creates alpha_const and one as f32 constants
unconditionally, so f16 inputs hit a type mismatch in Swish/Add on GPU
("Swish inputs must have the same type but they are: f16 and f32").
translate_glu_swiglu_clamp already upcasts to f32 and converts back at
the end; apply the same pattern here.

---------

Co-authored-by: ravi9 <ravi.panchumarthy@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. OpenVINO testing Everything test related Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants