From b465579a0279adafa41b70f41753d9ee297f0d1c Mon Sep 17 00:00:00 2001 From: biondizzle Date: Sat, 16 May 2026 04:10:42 +0000 Subject: [PATCH] cleanup: nuke all debug prints and env var gates from vLLM patch Removed: - [WT-LOAD] weight loader debug (MEGA_MOE_DEBUG gate) - [NVFP4 DEBUG] shape logging in _run_mega_moe - [NVFP4_DEBUG] post-load expert weight counting - [NVFP4] post-load sync + CUDA OK print (NVFP4_DEBUG_SYNC gate) - [POST-LOAD] all-zero param tensor scanning - [LOGITS] top-k printing + Paris probe - SKIP_ATTENTION env var gate for skipping attention - Unused total_fp8/total_bf16 variables Debugging belongs in layertest.py, not in the vLLM serving path. These prints polluted logs, bloated context windows, and slowed loading. --- vllm/patches/deepseek_v4.py | 92 +------------------------------------ 1 file changed, 1 insertion(+), 91 deletions(-) diff --git a/vllm/patches/deepseek_v4.py b/vllm/patches/deepseek_v4.py index 902d3a28..06bac7eb 100644 --- a/vllm/patches/deepseek_v4.py +++ b/vllm/patches/deepseek_v4.py @@ -355,13 +355,6 @@ class DeepseekV4MegaMoEExperts(nn.Module): if local_expert_id == -1: return False - # DEBUG: log weight loads for expert params (weight only, not scales) - if int(os.environ.get('MEGA_MOE_DEBUG', '0')) and shard_id in ("w1", "w3") and local_expert_id < 2 and loaded_weight.dtype in (torch.uint8, torch.int8): - print(f"[WT-LOAD] {weight_name} expert={expert_id}→local={local_expert_id} " - f"shard={shard_id} loaded_shape={tuple(loaded_weight.shape)} " - f"param_shape={tuple(param.data[local_expert_id].shape)} " - f"loaded_absmax={loaded_weight.view(torch.int8).abs().max().item()}") - # Scalar params (weight_scale_2, input_scale): per-expert if "weight_scale_2" in weight_name or "input_scale" in weight_name: if "w13_" in weight_name and "weight_scale_2" in weight_name: @@ -567,23 +560,8 @@ class DeepseekV4MegaMoEExperts(nn.Module): except Exception as exc: import traceback traceback.print_exc() - # Debug: print shapes - runner = self._cutedsl_runner - print(f"[NVFP4 DEBUG] num_local_experts={self.num_local_experts} " - f"hidden={self.hidden_size} intermediate={self.intermediate_size}") - if runner.l1_fp4: - print(f"[NVFP4 DEBUG] l1_fp4[0] shape={runner.l1_fp4[0].shape} " - f"l1_sf[0] shape={runner.l1_sf[0].shape} l1_gs[0]={runner.l1_gs[0]}") - if runner.l2_fp4: - print(f"[NVFP4 DEBUG] l2_fp4[0] shape={runner.l2_fp4[0].shape} " - f"l2_sf[0] shape={runner.l2_sf[0].shape} l2_gs[0]={runner.l2_gs[0]}") - print(f"[NVFP4 DEBUG] hidden_states shape={hidden_states.shape} " - f"topk_ids shape={topk_ids.shape}") raise - if os.environ.get('NVFP4_DEBUG_SYNC', '') == '1': - torch.cuda.synchronize() - DeepseekV4MegaMoEExperts.weight_loader.supports_moe_loading = True # type: ignore[attr-defined] @@ -1124,15 +1102,6 @@ class DeepseekV4DecoderLayer(nn.Module): positions: torch.Tensor, input_ids: torch.Tensor | None, ) -> torch.Tensor: - # DEBUG: skip attention entirely, just run FFN on raw input - if int(os.environ.get('SKIP_ATTENTION', '0')): - # Flatten to 2D for ffn, then restore - org_shape = x.shape - x_2d = x.view(-1, x.shape[-1]) - x_2d = self.ffn_norm(x_2d) - x_2d = self.ffn(x_2d, input_ids) - return x_2d.view(org_shape) - residual = x x, post, comb = self.hc_pre( x, self.hc_attn_fn, self.hc_attn_scale, self.hc_attn_base @@ -1692,12 +1661,7 @@ class DeepseekV4Model(nn.Module): compressor_converted += self._reconstruct_compressor_weight( idx_compressor.fused_wkv_wgate, indexer, layer_idx, E2M1_LUT, sub_path=".indexer", _shard_index=_shard_index) - total_fp8 = fp8_converted + fp8_from_bf16 - total_bf16 = compressor_converted - if int(os.environ.get('NVFP4_DEBUG', '0')) and (total_fp8 > 0 or total_bf16 > 0): - print(f"NVFP4 post-load: {fp8_converted} NVFP4->FP8, " - f"{fp8_from_bf16} BF16->FP8, " - f"{compressor_converted} compressor->BF16") + def _dequant_nvfp4_to_bf16(self, mod, e2m1_lut): @@ -2202,29 +2166,6 @@ class DeepseekV4ForCausalLM(nn.Module): hidden_states: torch.Tensor, ) -> torch.Tensor | None: logits = self.logits_processor(self.lm_head, hidden_states) - last = logits[-1].float() - top_vals, top_idx = last.topk(10) - print(f"[LOGITS] shape={tuple(logits.shape)} " - f"max={last.max().item():.4e} min={last.min().item():.4e} " - f"mean={last.mean().item():.4e} std={last.std().item():.4e} " - f"finite_frac={torch.isfinite(last).float().mean().item():.4f}") - print(f"[LOGITS] top10 ids: {top_idx.tolist()}") - print(f"[LOGITS] top10 vals: {[f'{v:.3f}' for v in top_vals.tolist()]}") - print(f"[LOGITS] gap top1-top10: {(top_vals[0] - top_vals[-1]).item():.3f}") - - # Probe for "Paris" specifically - try: - from transformers import AutoTokenizer - if not hasattr(self, '_tok'): - self._tok = AutoTokenizer.from_pretrained('/model', trust_remote_code=True) - for v in [' Paris', 'Paris', ' paris', 'paris']: - tid = self._tok.encode(v, add_special_tokens=False)[0] - logit_val = last[tid].item() - rank = (last > logit_val).sum().item() - print(f"[LOGITS-PROBE] {repr(v)}→id={tid} logit={logit_val:.2f} rank={rank}") - except Exception as e: - print(f"[LOGITS-PROBE] failed: {e}") - return logits def forward( @@ -2266,37 +2207,6 @@ class DeepseekV4ForCausalLM(nn.Module): loaded_params.add("lm_head.weight") self.model.finalize_mega_moe_weights() self.model._convert_nvfp4_post_load() - if int(os.environ.get('NVFP4_DEBUG', '0')): - # Count loaded expert weights to catch silent load failures - for i, layer in enumerate(self.model.layers): - ffn = layer.ffn - if hasattr(ffn, 'experts') and hasattr(ffn.experts, 'w13_weight'): - w13 = ffn.experts.w13_weight - w13_sf = ffn.experts.w13_weight_scale - w13_sf2 = ffn.experts.w13_weight_scale_2 - w2 = ffn.experts.w2_weight - n_experts = w13.shape[0] - nonzero_w13 = (w13.abs().amax(dim=(1,2)) > 0).sum().item() - nonzero_w2 = (w2.abs().amax(dim=(1,2)) > 0).sum().item() - print(f"[NVFP4_DEBUG] Layer {i}: {nonzero_w13}/{n_experts} w13 nonzero, " - f"{nonzero_w2}/{n_experts} w2 nonzero, " - f"w13_sf shape={w13_sf.shape}, w13_sf2 shape={w13_sf2.shape}") - if os.environ.get('NVFP4_DEBUG_SYNC', '') == '1': - torch.cuda.synchronize() - print("[NVFP4] post-load conversion done, CUDA OK") - - # POST-LOAD: scan for all-zero params (missed renames, failed loads) - zero_attrs = [] - for name, p in self.named_parameters(): - if not torch.is_tensor(p): - continue - sample = p.flatten()[:1024] if p.numel() > 1024 else p.flatten() - if (sample == 0).all().item(): - if (p == 0).all().item(): - zero_attrs.append((name, tuple(p.shape), str(p.dtype))) - print(f"[POST-LOAD] {len(zero_attrs)} all-zero param tensors:") - for n, s, d in zero_attrs[:50]: - print(f" {n} shape={s} dtype={d}") return loaded_params