From 8ae2214bad26051fca023cb1c637418ce83bd9ad Mon Sep 17 00:00:00 2001 From: biondizzle Date: Mon, 11 May 2026 18:48:07 +0000 Subject: [PATCH] fix: reorder Dockerfile ARG before COPY for proper cache busting --- Dockerfile | 5 ++--- patches/deepseek_v4.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8f78ea0..921ea60 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,11 +18,10 @@ ENV PYTHONPATH="/root/DeepGEMM:${PYTHONPATH}" RUN ln -sf /usr/local/lib/python3.12/dist-packages/nvidia/cu13/lib/libnvrtc.so.13 /usr/local/cuda/lib64/libnvrtc.so RUN cd /root/DeepGEMM && python3 setup.py build_ext --inplace +# Bust cache for patch changes — ARG before COPY ensures layer invalidation +ARG PATCH_CACHE_BUSTER=26 # Copy our DeepSeek V4 patch over vLLM's model file COPY patches/deepseek_v4.py /usr/local/lib/python3.12/dist-packages/vllm/model_executor/models/deepseek_v4.py -# Bust cache for patch changes -ARG PATCH_CACHE_BUSTER=24 -RUN echo "Patch cache buster: $PATCH_CACHE_BUSTER" > /dev/null # Verify everything imports RUN python3 -c "import deep_gemm; print('DeepGEMM NVFP4 OK')" && \ diff --git a/patches/deepseek_v4.py b/patches/deepseek_v4.py index 6997dfb..7fb63c1 100644 --- a/patches/deepseek_v4.py +++ b/patches/deepseek_v4.py @@ -323,11 +323,15 @@ def _deepseek_v4_stage_mega_moe_inputs_kernel( # Reconstruct the dequantized scale for FP8 activation quantization # UE4M3 dequant: if exp == 0: value = (mant/8) * 2^(1-7) = (mant/8) * 2^-6 # else: value = (1 + mant/8) * 2^(exp-7) - e4m3_value = tl.where( - e4m3_exp == 0, - (e4m3_mant.to(tl.float32) / 8.0) * (2.0 ** -6), - (1.0 + e4m3_mant.to(tl.float32) / 8.0) * (2.0 ** (e4m3_exp.to(tl.float32) - 7.0)) - ) + # Use bit manipulation: 2^n = (n+127) << 23 reinterpreted as float32 + e4m3_exp_for_recon = tl.maximum(e4m3_exp.to(tl.int32) - 7, -126) + # For exp=0 (subnormal): already handled separately + # For normal: (1 + mant/8) * 2^(exp-7) + two_pow_exp_bits = (e4m3_exp_for_recon + 127).to(tl.uint32) << 23 + two_pow_exp = two_pow_exp_bits.to(tl.float32, bitcast=True) + normal_value = (1.0 + e4m3_mant.to(tl.float32) / 8.0) * two_pow_exp + subnormal_value = (e4m3_mant.to(tl.float32) / 8.0) * 0.015625 # 2^-6 + e4m3_value = tl.where(e4m3_exp == 0, subnormal_value, normal_value) hidden_groups_f = tl.reshape(hidden, [num_groups, GROUP_K]) scaled = hidden_groups_f * (1.0 / tl.maximum(e4m3_value, 1e-6))[:, None]