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;
#ifdef WGPU_BACKEND_KV_F16
// f16 KV opt-in: looser tol for f16 K/V read precision (shader-f16 device).
const WebGPUContext* kv_ctx = get_default_webgpu_context();
if (kv_ctx != nullptr && kv_ctx->shader_f16_supported) {
atol = 2e-3f;
rtol = 1e-2f;
}
#endif
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