Commit 6ac648d7a for llama.cpp
commit 6ac648d7a9ef8f1a8141aaa52d0bdb780e2571b7
Author: Nikhil Jain <nikhil.jain0987@gmail.com>
Date: Tue Nov 24 03:37:56 2026 -0800
webgpu : Fix indexing bug in softmax kernel (#32691)
* Only run webgpu CI on my fork
* Add webgpu only workflow
* resolve merge conflicts
* add row check for softmax
* add test
* Add test to test case eval
diff --git a/ggml/src/ggml-webgpu/ggml-webgpu.cpp b/ggml/src/ggml-webgpu/ggml-webgpu.cpp
index 74e6581b6..8bf62e1ca 100644
--- a/ggml/src/ggml-webgpu/ggml-webgpu.cpp
+++ b/ggml/src/ggml-webgpu/ggml-webgpu.cpp
@@ -3237,7 +3237,8 @@ static webgpu_encoded_op ggml_webgpu_soft_max(webgpu_context & ctx,
ggml_webgpu_u32_from_f32(max_bias),
ggml_webgpu_u32_from_f32(n_head_log2),
ggml_webgpu_u32_from_f32(m0),
- ggml_webgpu_u32_from_f32(m1)
+ ggml_webgpu_u32_from_f32(m1),
+ (uint32_t) ggml_nrows(dst)
};
std::vector<wgpu::BindGroupEntry> entries = { ggml_webgpu_make_bind_group_entry(
diff --git a/ggml/src/ggml-webgpu/wgsl-shaders/soft_max.wgsl b/ggml/src/ggml-webgpu/wgsl-shaders/soft_max.wgsl
index 8f92a04c1..86d4828aa 100644
--- a/ggml/src/ggml-webgpu/wgsl-shaders/soft_max.wgsl
+++ b/ggml/src/ggml-webgpu/wgsl-shaders/soft_max.wgsl
@@ -40,6 +40,7 @@ struct Params {
n_head_log2: f32,
m0: f32,
m1: f32,
+ nrows: u32,
};
#define SRC_BINDING 0
@@ -128,6 +129,9 @@ fn main(@builtin(workgroup_id) wid: vec3<u32>,
@builtin(local_invocation_id) lid: vec3<u32>) {
var i = wid.x + wid.y * num_wg.x;
+ if (i >= params.nrows) {
+ return;
+ }
let i3 = i / (params.ne2 * params.ne1);
i = i % (params.ne2 * params.ne1);
let i2 = i / params.ne1;
diff --git a/tests/test-backend-ops.cpp b/tests/test-backend-ops.cpp
index 2d50c607c..a7380dcb1 100644
--- a/tests/test-backend-ops.cpp
+++ b/tests/test-backend-ops.cpp
@@ -13170,6 +13170,7 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
test_cases.emplace_back(new test_soft_max(GGML_TYPE_F32, {4, 1, 1, 1}, false, false, GGML_TYPE_F32, {1, 1}, 1.0f, 0.0f));
test_cases.emplace_back(new test_soft_max(GGML_TYPE_F32, {4, 1023, 1, 1}, false, false, GGML_TYPE_F32, {1, 1}, 1.0f, 0.0f));
test_cases.emplace_back(new test_soft_max(GGML_TYPE_F32, {643251, 3, 1, 1}, false, false, GGML_TYPE_F32, {1, 1}, 1.0f, 0.0f));
+ test_cases.emplace_back(new test_soft_max(GGML_TYPE_F32, {16, 65537, 1, 1}));
for (float max_bias : {0.0f, 8.0f}) {
for (float scale : {1.0f, 0.1f}) {
@@ -14515,6 +14516,8 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_perf() {
test_cases.emplace_back(new test_soft_max(GGML_TYPE_F32, {256, 256, 20, 1}, false, false, GGML_TYPE_F32, {1, 1}, 1.0f, 0.0f));
test_cases.emplace_back(new test_soft_max(GGML_TYPE_F32, {64, 64, 20, 1}, false, false, GGML_TYPE_F32, {1, 1}, 1.0f, 0.0f));
test_cases.emplace_back(new test_soft_max(GGML_TYPE_F32, {77, 64, 20, 1}, false, false, GGML_TYPE_F32, {1, 1}, 1.0f, 0.0f));
+ test_cases.emplace_back(new test_soft_max(GGML_TYPE_F32, {16, 65537, 1, 1}));
+
for (int64_t n : {256, 1024}) {
test_cases.emplace_back(new test_count_equal(GGML_TYPE_F32, {4, n, 1, 1}));