2026-07-30 15:33:44 +00:00
|
|
|
|
FROM git.modelhub.org.cn:9443/enginex-iluvatar/bi100-3.2.3-x86-ubuntu20.04-py3.10-poc-llm-infer:v1.2.3
|
|
|
|
|
|
|
|
|
|
|
|
RUN mkdir /workspace
|
|
|
|
|
|
WORKDIR /workspace/
|
[OPT] PagedAttention V2 implementation — fill the NotImplementedError hole
The single biggest performance bottleneck in the baseline:
paged_attention_v2 = raise NotImplementedError()
paged_attn.py: use_v1 = True (hardcoded to avoid calling V2)
V1 limitation: processes entire KV sequence in one kernel launch.
For seq_len=100K, this is a single massive attention computation.
V2: splits into PARTITION_SIZE=512 chunks, runs them in parallel,
then reduces with log-sum-exp. 195 parallel partitions vs 1.
Implementation (paged_attention_v2_pytorch.py):
Phase 1: Per-partition attention
- For each (seq, head, partition): compute QK^T, softmax, weighted V sum
- Store partial: tmp_output, exp_sums, max_logits (per partition)
Phase 2: Cross-partition reduction (log-sum-exp)
- global_max = max(max_logits across partitions)
- rescale = exp(partition_max - global_max) × partition_exp_sum
- output = Σ (rescale / total_sum) × partition_output
This is the same algorithm as vllm's paged_attention_v2_kernel.cu:
- The reduction pattern is identical to CCCL's block_reduce_warp_reductions
(combine partial statistics from independent segments)
- The online softmax tiling is the same as Flash Attention's partitioning
Integration:
- patch_paged_attention_v2.py patches _custom_ops.py and paged_attn.py
- Removes use_v1=True hardcode → V2 used for seq_len > 8192
- Dockerfile adds the patch step
This is a PyTorch implementation (no CUDA compilation needed).
Next step: if /usr/local/corex/ has ixcc or nvcc-compatible compiler,
replace with compiled CUDA kernel for further speedup.
2026-07-30 15:40:14 +00:00
|
|
|
|
|
|
|
|
|
|
# Copy all scripts and the V2 module
|
2026-07-30 15:33:44 +00:00
|
|
|
|
COPY ./qwen3_6_scripts /workspace/qwen3_6_scripts
|
[OPT] PagedAttention V2 implementation — fill the NotImplementedError hole
The single biggest performance bottleneck in the baseline:
paged_attention_v2 = raise NotImplementedError()
paged_attn.py: use_v1 = True (hardcoded to avoid calling V2)
V1 limitation: processes entire KV sequence in one kernel launch.
For seq_len=100K, this is a single massive attention computation.
V2: splits into PARTITION_SIZE=512 chunks, runs them in parallel,
then reduces with log-sum-exp. 195 parallel partitions vs 1.
Implementation (paged_attention_v2_pytorch.py):
Phase 1: Per-partition attention
- For each (seq, head, partition): compute QK^T, softmax, weighted V sum
- Store partial: tmp_output, exp_sums, max_logits (per partition)
Phase 2: Cross-partition reduction (log-sum-exp)
- global_max = max(max_logits across partitions)
- rescale = exp(partition_max - global_max) × partition_exp_sum
- output = Σ (rescale / total_sum) × partition_output
This is the same algorithm as vllm's paged_attention_v2_kernel.cu:
- The reduction pattern is identical to CCCL's block_reduce_warp_reductions
(combine partial statistics from independent segments)
- The online softmax tiling is the same as Flash Attention's partitioning
Integration:
- patch_paged_attention_v2.py patches _custom_ops.py and paged_attn.py
- Removes use_v1=True hardcode → V2 used for seq_len > 8192
- Dockerfile adds the patch step
This is a PyTorch implementation (no CUDA compilation needed).
Next step: if /usr/local/corex/ has ixcc or nvcc-compatible compiler,
replace with compiled CUDA kernel for further speedup.
2026-07-30 15:40:14 +00:00
|
|
|
|
COPY ./paged_attention_v2_pytorch.py /workspace/paged_attention_v2_pytorch.py
|
2026-07-30 16:07:09 +00:00
|
|
|
|
COPY ./paged_attention_v2_triton.py /workspace/paged_attention_v2_triton.py
|
[OPT] PagedAttention V2 implementation — fill the NotImplementedError hole
The single biggest performance bottleneck in the baseline:
paged_attention_v2 = raise NotImplementedError()
paged_attn.py: use_v1 = True (hardcoded to avoid calling V2)
V1 limitation: processes entire KV sequence in one kernel launch.
For seq_len=100K, this is a single massive attention computation.
V2: splits into PARTITION_SIZE=512 chunks, runs them in parallel,
then reduces with log-sum-exp. 195 parallel partitions vs 1.
Implementation (paged_attention_v2_pytorch.py):
Phase 1: Per-partition attention
- For each (seq, head, partition): compute QK^T, softmax, weighted V sum
- Store partial: tmp_output, exp_sums, max_logits (per partition)
Phase 2: Cross-partition reduction (log-sum-exp)
- global_max = max(max_logits across partitions)
- rescale = exp(partition_max - global_max) × partition_exp_sum
- output = Σ (rescale / total_sum) × partition_output
This is the same algorithm as vllm's paged_attention_v2_kernel.cu:
- The reduction pattern is identical to CCCL's block_reduce_warp_reductions
(combine partial statistics from independent segments)
- The online softmax tiling is the same as Flash Attention's partitioning
Integration:
- patch_paged_attention_v2.py patches _custom_ops.py and paged_attn.py
- Removes use_v1=True hardcode → V2 used for seq_len > 8192
- Dockerfile adds the patch step
This is a PyTorch implementation (no CUDA compilation needed).
Next step: if /usr/local/corex/ has ixcc or nvcc-compatible compiler,
replace with compiled CUDA kernel for further speedup.
2026-07-30 15:40:14 +00:00
|
|
|
|
|
|
|
|
|
|
# Run baseline patches (model registration, xformers fallback, tool parser, etc.)
|
2026-07-30 15:33:44 +00:00
|
|
|
|
RUN cd ./qwen3_6_scripts && ./patch_ops.sh
|
|
|
|
|
|
|
[OPT] PagedAttention V2 implementation — fill the NotImplementedError hole
The single biggest performance bottleneck in the baseline:
paged_attention_v2 = raise NotImplementedError()
paged_attn.py: use_v1 = True (hardcoded to avoid calling V2)
V1 limitation: processes entire KV sequence in one kernel launch.
For seq_len=100K, this is a single massive attention computation.
V2: splits into PARTITION_SIZE=512 chunks, runs them in parallel,
then reduces with log-sum-exp. 195 parallel partitions vs 1.
Implementation (paged_attention_v2_pytorch.py):
Phase 1: Per-partition attention
- For each (seq, head, partition): compute QK^T, softmax, weighted V sum
- Store partial: tmp_output, exp_sums, max_logits (per partition)
Phase 2: Cross-partition reduction (log-sum-exp)
- global_max = max(max_logits across partitions)
- rescale = exp(partition_max - global_max) × partition_exp_sum
- output = Σ (rescale / total_sum) × partition_output
This is the same algorithm as vllm's paged_attention_v2_kernel.cu:
- The reduction pattern is identical to CCCL's block_reduce_warp_reductions
(combine partial statistics from independent segments)
- The online softmax tiling is the same as Flash Attention's partitioning
Integration:
- patch_paged_attention_v2.py patches _custom_ops.py and paged_attn.py
- Removes use_v1=True hardcode → V2 used for seq_len > 8192
- Dockerfile adds the patch step
This is a PyTorch implementation (no CUDA compilation needed).
Next step: if /usr/local/corex/ has ixcc or nvcc-compatible compiler,
replace with compiled CUDA kernel for further speedup.
2026-07-30 15:40:14 +00:00
|
|
|
|
# 1. PagedAttention V2 — fills the NotImplementedError hole
|
|
|
|
|
|
# Enables partitioned attention for long sequences (>8192 tokens)
|
|
|
|
|
|
RUN python3 /workspace/qwen3_6_scripts/patch_paged_attention_v2.py
|
|
|
|
|
|
|
2026-07-30 15:41:01 +00:00
|
|
|
|
# 2. Triton kernel tuning: BLOCK=64, NUM_WARPS=4
|
|
|
|
|
|
# SMEM: BLOCK_N=64 × head_dim=128 × 2B × 2(K+V) = 32KB ≤ 48KB
|
|
|
|
|
|
# Occupancy: 4 warps allows 2 blocks/SM vs 1 at 8 warps
|
2026-07-30 15:33:44 +00:00
|
|
|
|
RUN python3 /workspace/qwen3_6_scripts/patch_triton_tuning.py
|
2026-07-30 15:41:01 +00:00
|
|
|
|
|
|
|
|
|
|
# 3. Enable Triton kernels with automatic fallback to PyTorch if they hang
|
|
|
|
|
|
# Triton Flash Attention is 10-50x faster than PyTorch for-loop fallback
|
|
|
|
|
|
RUN python3 /workspace/qwen3_6_scripts/patch_enable_triton.py
|
|
|
|
|
|
|
2026-07-30 16:05:01 +00:00
|
|
|
|
# 5. head_dim=256 support: Qwen3.6 uses head_dim=256
|
|
|
|
|
|
# BLOCK=64 overflows SMEM (64×256×2×2=64KB > 48KB)
|
|
|
|
|
|
# → BLOCK=32 for head_dim=256 (32×256×2×2=32KB ≤ 48KB)
|
|
|
|
|
|
RUN python3 /workspace/qwen3_6_scripts/patch_head256_triton.py
|
|
|
|
|
|
|
2026-07-30 15:41:01 +00:00
|
|
|
|
# 4. Raise decode threshold: compiled paged_attention_v1 up to 65536
|
|
|
|
|
|
# instead of falling back to Python at 32768
|
|
|
|
|
|
RUN python3 /workspace/qwen3_6_scripts/patch_vectorized_decode.py
|