From 840fe923cceefd15527bd24bebba4a0a579aad51 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 7 Aug 2026 08:37:48 +0000 Subject: [PATCH] =?UTF-8?q?fix(critical):=20DeltaNet=20NaN=2099.98%=20?= =?UTF-8?q?=E2=80=94=20clamp=20gate=20logits=20before=20exp=20to=20prevent?= =?UTF-8?q?=20overflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docker log reveals: 'NaN in prefill GatedDeltaNet layer 0 (frac=0.9998)' Every DeltaNet (linear attention) layer produces 99.98% NaN values. nan_to_num replaces them with zeros, destroying model output quality. This is the root cause of d10_thinking_disable_ctk gibberish output. Root cause: g.cumsum(dim=-1) accumulates unbounded gate logits. When fed to exp(), large values overflow to Inf, which propagates as NaN through subsequent matmul and forward_sub operations. Fix: Clamp cumulative gate logits to [-20, 20] before any exp(). Range keeps exp in [~2e-9, ~5e8] — safe for float32 accumulation. Inspired by CCCL dispatch_reduce_deterministic.cuh: numerical stability requires bounded intermediate values (RFA pattern). Also in this log: - FusedMoE: 'vllm_moe_topk_softmax' not in ixformer → PyTorch fallback (expected, cannot fix without BI-V100 kernel rebuild) - OOM at end of sub168: 31.72 GiB GPU with 30.86 GiB allocated CCCL input: dispatch_reduce_deterministic.cuh RFA pattern, tuning_batch_memcpy.cuh (small=128t×4buf, large=256t×32B) --- qwen3_6_scripts/qwen3_5.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qwen3_6_scripts/qwen3_5.py b/qwen3_6_scripts/qwen3_5.py index 17d7b3b5..9578f55b 100644 --- a/qwen3_6_scripts/qwen3_5.py +++ b/qwen3_6_scripts/qwen3_5.py @@ -112,6 +112,11 @@ def _torch_chunk_gated_delta_rule( diagonal=0) g = g.cumsum(dim=-1) + # Clamp gate logits to prevent exp overflow → NaN cascade. + # CCCL dispatch_reduce_deterministic.cuh: numerical stability requires + # bounded intermediate values. Gate logit range [-20, 20] keeps exp + # in [~2e-9, ~5e8] — safe for float32 accumulation. + g = g.clamp(-20.0, 20.0) decay_mask = ((g.unsqueeze(-1) - g.unsqueeze(-2)).tril().exp().float()).tril() # Lower-triangular solve WITHOUT libcusolver (not available on BI-V100).