Trigger CUDA Graph capture for all shapes in cuda graph capture list
(self)
| 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( |
no test coverage detected