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

Class GpuWorker

fastdeploy/worker/gpu_worker.py:44–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43
44class GpuWorker(WorkerBase):
45 def __init__(
46 self,
47 fd_config: FDConfig,
48 local_rank: int,
49 rank: int,
50 ):
51 super().__init__(
52 fd_config=fd_config,
53 local_rank=local_rank,
54 rank=rank,
55 )
56 pass
57
58 def init_device(self):
59 """
60 Initialize device and construct model runner
61 """
62 self.max_chips_per_node = 16 if current_platform.is_iluvatar() else 8
63 if self.device_config.device_type == "cuda" and paddle.device.is_compiled_with_cuda():
64 # Set environment variable
65 self.device_ids = self.parallel_config.device_ids.split(",")
66 self.device = f"gpu:{self.local_rank % self.max_chips_per_node}"
67 paddle.device.set_device(self.device)
68 paddle.set_default_dtype(self.model_config.dtype)
69
70 gc.collect()
71 paddle.device.cuda.empty_cache()
72 if (
73 not self.parallel_config.disable_custom_all_reduce
74 and self.parallel_config.tensor_parallel_size > 1
75 and paddle.is_compiled_with_cuda()
76 ):
77 from fastdeploy.distributed.communication import use_custom_allreduce
78
79 use_custom_allreduce(self.fd_config.parallel_config.tp_group)
80 else:
81 raise RuntimeError(f"Not support device type: {self.device_config.device}")
82
83 if self.local_rank == 0:
84 report_usage_stats(self.fd_config)
85
86 set_random_seed(self.fd_config.model_config.seed)
87 # Construct model runner
88 self.model_runner: ModelRunnerBase = ModelRunner(
89 fd_config=self.fd_config,
90 device=self.device,
91 device_id=int(self.device_ids[self.local_rank % self.max_chips_per_node]),
92 rank=self.rank,
93 local_rank=self.local_rank,
94 )
95
96 def exist_prefill(self):
97 """
98 check whether prefill stage exist
99 """
100 return self.model_runner.exist_prefill()
101

Callers 1

get_workerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected