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

Class IluvatarWorker

fastdeploy/worker/iluvatar_worker.py:34–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32
33
34class IluvatarWorker(GpuWorker):
35 """ """
36
37 def __init__(
38 self,
39 fd_config: FDConfig,
40 local_rank: int,
41 rank: int,
42 ):
43 if fd_config.model_config.enable_mm:
44 paddle.set_flags({"FLAGS_enable_ixattnbkd": True, "FLAGS_enable_ixdnn_attn": False})
45 super(IluvatarWorker, self).__init__(
46 fd_config=fd_config,
47 local_rank=local_rank,
48 rank=rank,
49 )
50
51 def init_device(self):
52 """
53 Initialize device and construct model runner
54 """
55 if paddle.is_compiled_with_custom_device("iluvatar_gpu"):
56 # Set environment variable
57 self.device = f"iluvatar_gpu:{self.local_rank}"
58 paddle.device.set_device(self.device)
59 paddle.set_default_dtype(self.model_config.dtype)
60 self.device_ids = self.parallel_config.device_ids.split(",")
61
62 gc.collect()
63 else:
64 raise RuntimeError(f"Not support device type: {self.device_config.device}")
65
66 set_random_seed(self.fd_config.model_config.seed)
67 # Construct model runner
68 self.model_runner: IluvatarModelRunner = IluvatarModelRunner(
69 fd_config=self.fd_config,
70 device=self.device,
71 device_id=self.device_ids[self.local_rank],
72 rank=self.rank,
73 local_rank=self.local_rank,
74 )
75
76 def determine_available_memory(self) -> int:
77 """
78 Profiles the peak memory usage of the model to determine how much
79 memory can be used for KV cache without OOMs.
80
81 The engine will first conduct a profiling of the existing memory usage.
82 Then, it calculate the maximum possible number of GPU and CPU blocks
83 that can be allocated with the remaining free memory.
84
85 Tip:
86 You may limit the usage of GPU memory
87 by adjusting the `gpu_memory_utilization` parameter.
88 """
89 # 1. Record memory state before profile run
90 return int(float(os.getenv("FD_ILUVATAR_KVCACHE_MEM", "3")) * 1024**3)
91

Callers 1

get_workerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected