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

Method init_device

fastdeploy/worker/metax_worker.py:51–76  ·  view source on GitHub ↗

Initialize device and construct model runner

(self)

Source from the content-addressed store, hash-verified

49 pass
50
51 def init_device(self):
52 """
53 Initialize device and construct model runner
54 """
55 self.max_chips_per_node = 8
56 # Set environment variable
57 self.device_ids = self.parallel_config.device_ids.split(",")
58 self.device = f"metax_gpu:{self.local_rank % self.max_chips_per_node}"
59 paddle.device.set_device(self.device)
60 paddle.set_default_dtype(self.model_config.dtype)
61
62 gc.collect()
63 paddle.device.empty_cache()
64
65 if self.local_rank == 0:
66 report_usage_stats(self.fd_config)
67
68 set_random_seed(self.fd_config.model_config.seed)
69 # Construct model runner
70 self.model_runner: MetaxModelRunner = MetaxModelRunner(
71 fd_config=self.fd_config,
72 device=self.device,
73 device_id=int(self.device_ids[self.local_rank % self.max_chips_per_node]),
74 rank=self.rank,
75 local_rank=self.local_rank,
76 )
77
78 def exist_prefill(self):
79 """

Callers

nothing calls this directly

Calls 5

report_usage_statsFunction · 0.90
set_random_seedFunction · 0.90
MetaxModelRunnerClass · 0.90
splitMethod · 0.80
collectMethod · 0.80

Tested by

no test coverage detected