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

Class DcuWorker

fastdeploy/worker/dcu_worker.py:30–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28
29
30class DcuWorker(GpuWorker):
31 """ """
32
33 def __init__(
34 self,
35 fd_config: FDConfig,
36 local_rank: int,
37 rank: int,
38 ):
39 super().__init__(
40 fd_config=fd_config,
41 local_rank=local_rank,
42 rank=rank,
43 )
44 pass
45
46 def init_device(self):
47 """
48 Initialize device and construct model runner
49 """
50 self.max_chips_per_node = 8
51 if self.device_config.device_type == "cuda" and paddle.device.is_compiled_with_cuda():
52 # Set environment variable
53 self.device_ids = self.parallel_config.device_ids.split(",")
54 self.device = f"gpu:{self.local_rank % self.max_chips_per_node}"
55 paddle.device.set_device(self.device)
56 paddle.set_default_dtype(self.model_config.dtype)
57
58 gc.collect()
59 paddle.device.cuda.empty_cache()
60 if (
61 self.parallel_config.enable_custom_all_reduce
62 and self.parallel_config.tensor_parallel_size > 1
63 and paddle.is_compiled_with_cuda()
64 ):
65 from fastdeploy.distributed.communication import use_custom_allreduce
66
67 use_custom_allreduce(self.fd_config.parallel_config.tp_group)
68 else:
69 raise RuntimeError(f"Not support device type: {self.device_config.device}")
70
71 set_random_seed(self.fd_config.model_config.seed)
72 # Construct model runner
73 self.model_runner: DCUModelRunner = DCUModelRunner(
74 fd_config=self.fd_config,
75 device=self.device,
76 device_id=self.device_ids[self.local_rank % self.max_chips_per_node],
77 rank=self.rank,
78 local_rank=self.local_rank,
79 )
80
81 def determine_available_memory(self) -> int:
82 """
83 Profiles the peak memory usage of the model to determine how much
84 memory can be used for KV cache without OOMs.
85
86 The engine will first conduct a profiling of the existing memory usage.
87 Then, it calculate the maximum possible number of GPU and CPU blocks

Callers 1

get_workerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected