Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion backends/webgpu/test/test_webgpu_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,23 @@ bool sdpa_within_tol(
int n,
float* ma,
float* mr) {
float atol = 1e-4f, rtol = 1e-3f;
// f16 KV (runtime opt-in) reads K/V at reduced precision; loosen the tol on a
// shader-f16 device to cover that rounding. Harmless for f32 KV (looser
// gate).
const WebGPUContext* kv_ctx = get_default_webgpu_context();
if (kv_ctx != nullptr && kv_ctx->shader_f16_supported) {
atol = 2e-3f;
rtol = 1e-2f;
}
float max_abs = 0.0f, max_rel = 0.0f;
bool ok = true;
for (int i = 0; i < n; i++) {
const float ae = std::abs(out[i] - golden[i]);
const float re = ae / std::max(std::abs(golden[i]), 1e-6f);
max_abs = std::max(max_abs, ae);
max_rel = std::max(max_rel, re);
if (ae > 1e-4f && re > 1e-3f) {
if (ae > atol && re > rtol) {
ok = false;
}
}
Expand Down
Loading