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

Method capture_model

fastdeploy/worker/xpu_model_runner.py:1483–1512  ·  view source on GitHub ↗

Trigger CUDA Graph capture for all shapes in 'CudaGraphConfig.cudagraph_capture_sizes'

(self)

Source from the content-addressed store, hash-verified

1481 paddle.device.xpu.set_debug_level(debug_level)
1482
1483 def capture_model(self) -> None:
1484 """
1485 Trigger CUDA Graph capture for all shapes in 'CudaGraphConfig.cudagraph_capture_sizes'
1486 """
1487 time_before_capture = time.perf_counter()
1488 expected_decode_len = 1
1489 capture_sizes = self.cudagraph_capture_sizes.copy()
1490
1491 try:
1492 for batch_size in sorted(capture_sizes, reverse=True):
1493 self._dummy_run(
1494 num_tokens=self.scheduler_config.max_num_batched_tokens,
1495 batch_size=batch_size,
1496 expected_decode_len=expected_decode_len,
1497 in_capturing=True,
1498 )
1499 logger.info(f"Warm up the model with the batch size:{batch_size}, num tokens:{expected_decode_len}")
1500 except RuntimeError as e:
1501 if "out of memory" in str(e):
1502 raise RuntimeError(
1503 "CUDA out of memory occurred when warming up CUDAGraph "
1504 f"with the capture sizes {capture_sizes}. Please try "
1505 "lowering `max_num_seqs` or `gpu_memory_utilization` when "
1506 "initializing the engine."
1507 ) from e
1508 else:
1509 raise e
1510
1511 time_after_capture = time.perf_counter()
1512 logger.info(f"Cuda Graph capturing took {time_after_capture - time_before_capture} seconds")
1513
1514 @sot_warmup_guard(True)
1515 def sot_warmup(self) -> None:

Callers

nothing calls this directly

Calls 3

_dummy_runMethod · 0.95
copyMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected