Skip to content

Commit 342bf2d

Browse files
committed
Revert blockwise CUDAGraph and support piecewise CUDAGraph in prefill
1 parent 4474188 commit 342bf2d

14 files changed

Lines changed: 30 additions & 801 deletions

File tree

fastdeploy/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,13 @@ def _set_cudagraph_sizes(
12111211
# Shape [256, 288, ... 992, 1024]
12121212
draft_capture_sizes += [32 * i for i in range(9, 33)]
12131213

1214+
# Shape [1024, 1088, ... 2048] step=64
1215+
draft_capture_sizes += [64 * i for i in range(17, 33)]
1216+
# Shape [2048, 2176, ... 4096] step=128
1217+
draft_capture_sizes += [128 * i for i in range(17, 33)]
1218+
# Shape [4096, 4352, ... 8192] step=256
1219+
draft_capture_sizes += [256 * i for i in range(17, 33)]
1220+
12141221
draft_capture_sizes_prefill = draft_capture_sizes.copy()
12151222
draft_capture_sizes.append(max_capture_size)
12161223
self.cudagraph_capture_sizes = sorted(draft_capture_sizes)

fastdeploy/envs.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,6 @@ def _validate_split_kv_size(value: int) -> int:
263263
"FD_SAVE_OUTPUT_CACHE_FOR_PREEMPTED_REQUEST": lambda: bool(
264264
int(os.getenv("FD_SAVE_OUTPUT_CACHE_FOR_PREEMPTED_REQUEST", "1"))
265265
),
266-
# Whether to enable block-wise CUDA Graph capture/replay.
267-
# When enabled, individual layer forward methods decorated with @block_wise_cuda_graph_wrap
268-
# will be captured and replayed as CUDA Graphs for improved performance.
269-
# Set to 1 to enable; defaults to 0 (disabled).
270-
"FD_USE_BLOCK_WISE_CUDA_GRAPH": lambda: bool(int(os.getenv("FD_USE_BLOCK_WISE_CUDA_GRAPH", "0"))),
271-
# Comma-separated list of token counts to pre-capture for block-wise CUDA Graphs.
272-
# Used during the warmup phase to pre-capture graphs for these specific sizes.
273-
# At runtime, token counts not in this list fall back to eager execution.
274-
# Example: "1,2,4,8,16,32,64,128,256,512"
275-
"FD_BLOCK_WISE_CUDA_GRAPH_SIZES": lambda: os.getenv("FD_BLOCK_WISE_CUDA_GRAPH_SIZES", "128,256,512,1024,2048"),
276266
# Suspend rollouting routing replay
277267
"FD_SUSPEND_ROUTING_REPLAY": lambda: bool(int(os.getenv("FD_SUSPEND_ROUTING_REPLAY", "0"))),
278268
# train-infer consistency, used in RL

fastdeploy/model_executor/graph_optimization/cuda_graph_op.py

Lines changed: 0 additions & 320 deletions
This file was deleted.

fastdeploy/model_executor/graph_optimization/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,9 @@ def get_state():
140140

141141
sot_warmup_guard, in_sot_warmup_mode = create_guard(False)
142142
profile_run_guard, in_profile_run_mode = create_guard(False)
143+
144+
# Guard for the prefill SOT warmup + piecewise-CUDAGraph capture phase.
145+
# When active, keep the SOT-compiled graph intact during prefill capture
146+
# by avoiding extra graph break points or graph fragmentation.
147+
# The decode-only CUDAGraph capture runs OUTSIDE this guard.
148+
prefill_cudagraph_guard, in_prefill_cudagraph_mode = create_guard(False)

fastdeploy/model_executor/layers/attention/append_attn_backend.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,6 @@ def forward_mixed(
321321
q_norm_weight = getattr(layer, "q_norm_weight", None) if norm_after_rope_in_kernel else None
322322
k_norm_weight = getattr(layer, "k_norm_weight", None) if norm_after_rope_in_kernel else None
323323

324-
if self.rope_3d:
325-
assert len(forward_meta.rotary_embs.shape) == 6
326-
else:
327-
assert len(forward_meta.rotary_embs.shape) == 5
328-
if layer.use_neox_rotary_style:
329-
assert forward_meta.rotary_embs.shape[0:4] == [2, 1, self.max_seq_len, 1]
330-
# 128 is qwen3
331-
# 32 is glm
332-
# 64 is gpt-oss
333-
assert forward_meta.rotary_embs.shape[4] in [128, 32, 64]
334-
335324
if self.pd_disaggregation_mode == "per_query":
336325
metadata.kv_signal_data_list[layer.layer_id] = init_signal_layerwise(
337326
metadata.kv_signal_metadata,

fastdeploy/model_executor/layers/linear.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
decode_alltoall_transpose,
2626
tensor_model_parallel_all_reduce,
2727
)
28-
from fastdeploy.model_executor.graph_optimization.cuda_graph_op import (
29-
block_wise_cuda_graph_wrap,
30-
)
3128
from fastdeploy.model_executor.layers.quantization.quant_base import QuantMethodBase
3229
from fastdeploy.model_executor.utils import (
3330
default_weight_loader,
@@ -272,7 +269,6 @@ def load_state_dict(self, state_dict: dict):
272269
bias_tensor = paddle.to_tensor(get_tensor(state_dict.pop(self.bias_key)))
273270
self.bias.set_value(bias_tensor)
274271

275-
@block_wise_cuda_graph_wrap(inputs=["x"], self_attrs=["weight", "weight_scale_inv", "bias"])
276272
def forward_cuda(self, x: paddle.Tensor) -> paddle.Tensor:
277273
"""
278274
Forward function for Linear.

0 commit comments

Comments
 (0)