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

Method init_device

fastdeploy/worker/xpu_worker.py:57–90  ·  view source on GitHub ↗

Initialize device and Construct model runner

(self)

Source from the content-addressed store, hash-verified

55 pass
56
57 def init_device(self):
58 """Initialize device and Construct model runner"""
59 self.max_chips_per_node = 16 if current_platform.is_iluvatar() else 8
60 if paddle.is_compiled_with_xpu():
61 # Set environment variable
62 self.device_ids = self.parallel_config.device_ids.split(",")
63 self.device = f"xpu:{self.local_rank % self.max_chips_per_node}"
64 paddle.device.set_device(self.device)
65 self.device_id = int(self.device_ids[self.local_rank % self.max_chips_per_node])
66 assert (
67 self.device_id is not None
68 ), f"device_id is none for rank {self.local_rank % self.max_chips_per_node}"
69 assert len(self.device_ids) > (
70 self.local_rank % self.max_chips_per_node
71 ), f"device number must be greater than local rank, but get device number is {len(self.device_ids)}, rank is {self.local_rank % self.max_chips_per_node}"
72 paddle.set_default_dtype(self.model_config.dtype)
73
74 gc.collect()
75 paddle.device.xpu.empty_cache()
76 else:
77 raise RuntimeError(f"Not support device type: {self.device_config.device}")
78
79 if self.local_rank == 0:
80 report_usage_stats(self.fd_config)
81
82 set_random_seed(self.fd_config.model_config.seed)
83 # Construct model runner
84 self.model_runner: XPUModelRunner = XPUModelRunner(
85 fd_config=self.fd_config,
86 device=self.device,
87 rank=self.rank,
88 device_id=self.device_id,
89 local_rank=self.local_rank,
90 )
91
92 def exist_prefill(self):
93 """

Callers

nothing calls this directly

Calls 6

report_usage_statsFunction · 0.90
set_random_seedFunction · 0.90
XPUModelRunnerClass · 0.90
splitMethod · 0.80
collectMethod · 0.80
is_iluvatarMethod · 0.45

Tested by

no test coverage detected