MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / capture_model

Method capture_model

fastdeploy/worker/gpu_model_runner.py:2081–2147  ·  view source on GitHub ↗

Trigger CUDA Graph capture for all shapes in cuda graph capture list

(self)

Source from the content-addressed store, hash-verified

2079
2080 @sot_warmup_guard(True)
2081 def capture_model(self) -> None:
2082 """
2083 Trigger CUDA Graph capture for all shapes in cuda graph capture list
2084 """
2085 if not self.use_cudagraph:
2086 logger.info("Skipping CUDA graph capture. Please check GraphOptimizationConfig")
2087 return
2088 time_before_capture = time.perf_counter()
2089 expected_decode_len = 1
2090 capture_sizes = self.cudagraph_capture_sizes.copy()
2091 try:
2092 if self.fd_config.graph_opt_config.cudagraph_only_prefill:
2093 for num_tokens in sorted(capture_sizes, reverse=True):
2094 self._dummy_run(
2095 num_tokens=num_tokens,
2096 batch_size=self.scheduler_config.max_num_seqs,
2097 in_capturing=True,
2098 expected_decode_len=expected_decode_len,
2099 capture_prefill=True,
2100 )
2101 logger.info(
2102 f"Warm up the model with the num_tokens:{num_tokens}, expected_decode_len:{expected_decode_len}"
2103 )
2104 elif self.speculative_decoding:
2105 # Capture Target Model without bsz 1
2106 for capture_size in sorted(capture_sizes, reverse=True):
2107 expected_decode_len = self.speculative_config.num_speculative_tokens * 2 + 1
2108 self._dummy_run(
2109 num_tokens=self.fd_config.get_max_chunk_tokens(),
2110 batch_size=int(capture_size / (self.speculative_config.num_speculative_tokens + 1)),
2111 in_capturing=True,
2112 expected_decode_len=expected_decode_len,
2113 accept_all_drafts=True,
2114 )
2115 logger.info(
2116 f"Warm up the model with the num_tokens:{capture_size}, expected_decode_len:{expected_decode_len}"
2117 )
2118 else:
2119 for batch_size in sorted(capture_sizes, reverse=True):
2120 self._dummy_run(
2121 num_tokens=self.fd_config.get_max_chunk_tokens(),
2122 batch_size=batch_size,
2123 in_capturing=True,
2124 expected_decode_len=expected_decode_len,
2125 )
2126 logger.info(
2127 f"Warm up the model with the batch size:{batch_size}, num tokens:{expected_decode_len}"
2128 )
2129 except RuntimeError as e:
2130 if "out of memory" in str(e):
2131 raise RuntimeError(
2132 "CUDA out of memory occurred when warming up CUDAGraph "
2133 f"with the capture sizes {capture_sizes}. Please try "
2134 "lowering `max_num_seqs` or `gpu_memory_utilization` when "
2135 "initializing the engine."
2136 ) from e
2137 if "CUDA error(700)" in str(e):
2138 raise RuntimeError(

Callers 2

update_parametersMethod · 0.95
wakeupMethod · 0.95

Calls 4

_dummy_runMethod · 0.95
get_max_chunk_tokensMethod · 0.80
infoMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected