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

Method init_device

fastdeploy/worker/gpu_worker.py:58–94  ·  view source on GitHub ↗

Initialize device and construct model runner

(self)

Source from the content-addressed store, hash-verified

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 """

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected