Skip to content

Commit 3733f07

Browse files
committed
fix some bug
Signed-off-by: noemotiovon <757486878@qq.com>
1 parent 46d485f commit 3733f07

9 files changed

Lines changed: 44 additions & 17 deletions

File tree

roll/platforms/cpu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CpuPlatform(Platform):
1313
communication_backend: str = "gloo"
1414

1515
@classmethod
16-
def clear_cublas_workspaces(cls):
16+
def clear_cublas_workspaces(cls) -> None:
1717
pass
1818

1919
@classmethod

roll/platforms/cuda.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CudaPlatform(Platform):
1616
communication_backend: str = "nccl"
1717

1818
@classmethod
19-
def clear_cublas_workspaces(cls):
19+
def clear_cublas_workspaces(cls) -> None:
2020
torch._C._cuda_clearCublasWorkspaces()
2121

2222
@classmethod
@@ -39,7 +39,7 @@ def get_vllm_worker_class(clas):
3939
raise RuntimeError("vLLM is not installed or not properly configured.") from e
4040

4141
@classmethod
42-
def set_allocator_settings(cls):
42+
def set_allocator_settings(cls) -> None:
4343
torch.cuda.memory._set_allocator_settings("expandable_segments:False")
4444

4545
@classmethod

roll/platforms/npu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class NpuPlatform(Platform):
1414
communication_backend: str = "hccl"
1515

1616
@classmethod
17-
def clear_cublas_workspaces(cls):
17+
def clear_cublas_workspaces(cls) -> None:
1818
pass
1919

2020
@classmethod
@@ -37,7 +37,7 @@ def get_vllm_worker_class(clas):
3737
raise RuntimeError("vLLM is not installed or not properly configured.") from e
3838

3939
@classmethod
40-
def set_allocator_settings(cls):
40+
def set_allocator_settings(cls) -> None:
4141
pass
4242

4343
@classmethod

roll/platforms/platform.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __getattr__(self, key: str):
8989
return None
9090

9191
@classmethod
92-
def clear_cublas_workspaces(cls):
92+
def clear_cublas_workspaces(cls) -> None:
9393
raise NotImplementedError
9494

9595
@classmethod
@@ -98,16 +98,33 @@ def get_vllm_worker_class(cls):
9898
raise NotImplementedError
9999

100100
@classmethod
101-
def set_allocator_settings(cls):
101+
def set_allocator_settings(cls) -> None:
102102
"""Configure memory allocator settings based on the device type."""
103103
raise NotImplementedError
104104

105105
@classmethod
106106
def get_custom_env_vars(cls) -> dict:
107+
"""
108+
Return custom environment variables specific to the platform.
109+
110+
Returns:
111+
dict: A dictionary of environment variable key-value pairs.
112+
"""
107113
raise NotImplementedError
108114

109115
@classmethod
110-
def update_env_vars_for_visible_devices(cls, env_vars: dict, gpu_ranks: list):
116+
def update_env_vars_for_visible_devices(cls, env_vars: dict, gpu_ranks: list) -> None:
117+
"""
118+
Update environment variables to control device visibility.
119+
120+
Args:
121+
env_vars (dict): Dictionary of current environment variables to modify.
122+
gpu_ranks (list): List of device IDs to expose to the process.
123+
124+
Behavior:
125+
- Sets the platform-specific visibility environment variable.
126+
- Sets the corresponding Ray experimental flag if needed.
127+
"""
111128
visible_devices_env_vars = {
112129
cls.device_control_env_var: ",".join(map(str, gpu_ranks)),
113130
cls.ray_experimental_noset: "1",
@@ -116,6 +133,12 @@ def update_env_vars_for_visible_devices(cls, env_vars: dict, gpu_ranks: list):
116133

117134
@classmethod
118135
def get_visible_gpus(cls) -> list:
136+
"""
137+
Return the list of currently visible device IDs.
138+
139+
Returns:
140+
list: A list of device ID strings parsed from the visibility environment variable.
141+
"""
119142
if cls.device_control_env_var is not None:
120143
return os.environ.get(cls.device_control_env_var, "").split(",")
121144
return []

roll/platforms/rocm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class RocmPlatform(Platform):
1616
communication_backend: str = "nccl"
1717

1818
@classmethod
19-
def clear_cublas_workspaces(cls):
19+
def clear_cublas_workspaces(cls) -> None:
2020
torch._C._cuda_clearCublasWorkspaces()
2121

2222
@classmethod
@@ -39,7 +39,7 @@ def get_vllm_worker_class(clas):
3939
raise RuntimeError("vLLM is not installed or not properly configured.") from e
4040

4141
@classmethod
42-
def set_allocator_settings(cls):
42+
def set_allocator_settings(cls) -> None:
4343
torch.cuda.memory._set_allocator_settings("expandable_segments:False")
4444

4545
@classmethod

roll/platforms/unknown.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class UnknownPlatform(Platform):
1616
communication_backend: str = "nccl"
1717

1818
@classmethod
19-
def clear_cublas_workspaces(cls):
19+
def clear_cublas_workspaces(cls) -> None:
2020
torch._C._cuda_clearCublasWorkspaces()
2121

2222
@classmethod
@@ -39,7 +39,7 @@ def get_vllm_worker_class(clas):
3939
raise RuntimeError("vLLM is not installed or not properly configured.") from e
4040

4141
@classmethod
42-
def set_allocator_settings(cls):
42+
def set_allocator_settings(cls) -> None:
4343
torch.cuda.memory._set_allocator_settings("expandable_segments:False")
4444

4545
@classmethod

roll/third_party/vllm/vllm_0_8_4/llm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ def update_parameter(self, parameter_name, weight, ranks_in_worker):
216216
"dtype": weight.dtype,
217217
"weight": weight.cpu().tolist()
218218
}
219+
else:
220+
weight_dict = weight
219221
self.collective_rpc(method="update_parameter", args=(parameter_name, weight_dict, ranks_in_worker))
220222

221223
def update_parameter_in_bucket(self, meta_infos, buffer, ranks_in_worker):

roll/third_party/vllm/vllm_0_8_4/v1/worker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, *args, **kwargs):
2626

2727
def update_parameter(self, parameter_name, weight, ranks_in_worker):
2828
weight_dict = weight
29-
weight = torch.tensor(weight_dict["weight"], dtype=weight_dict["dtype"]).cuda()
29+
weight = torch.tensor(weight_dict["weight"], dtype=weight_dict["dtype"]).to(current_platform.device_type)
3030
super().update_parameter(parameter_name, weight, ranks_in_worker)
3131

3232
def broadcast_bucket(self, src_pp_rank, meta_infos, bucket_size):
@@ -35,7 +35,7 @@ def broadcast_bucket(self, src_pp_rank, meta_infos, bucket_size):
3535

3636
def update_parameter_in_bucket(self, meta_infos, buffer, ranks_in_worker):
3737
RecvBucketManager.dict_to_meta(meta_infos)
38-
buffer = torch.tensor(buffer, dtype=torch.int8, device='cuda')
38+
buffer = torch.tensor(buffer, dtype=torch.int8, device=current_platform.device_type)
3939
super().update_parameter_in_bucket(meta_infos, buffer, ranks_in_worker)
4040

4141
def add_lora(self, peft_config) -> bool:

tests/models/cuda_mem/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import torch
22

3+
from roll.platforms import current_platform
4+
35

46
def log_gpu_memory_usage(head: str):
5-
memory_allocated = torch.cuda.memory_allocated() / 1024**3
6-
memory_reserved = torch.cuda.memory_reserved() / 1024**2
7-
memory_reserved_max = torch.cuda.max_memory_reserved() / 1024**3
7+
memory_allocated = current_platform.memory_allocated() / 1024**3
8+
memory_reserved = current_platform.memory_reserved() / 1024**2
9+
memory_reserved_max = current_platform.max_memory_reserved() / 1024**3
810
message = (
911
f"{head}, memory allocated (GB): {memory_allocated}, memory reserved (MB): {memory_reserved}, "
1012
f"memory max reserved (GB): {memory_reserved_max}"

0 commit comments

Comments
 (0)