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

Method init_device

fastdeploy/worker/dcu_worker.py:46–79  ·  view source on GitHub ↗

Initialize device and construct model runner

(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

use_custom_allreduceFunction · 0.90
set_random_seedFunction · 0.90
DCUModelRunnerClass · 0.90
splitMethod · 0.80
collectMethod · 0.80

Tested by

no test coverage detected