Skip to content

Commit 0243684

Browse files
committed
[feat](eplb): support eplb on rocm platform
1 parent f6f462b commit 0243684

6 files changed

Lines changed: 69 additions & 16 deletions

File tree

vllm/config/parallel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def _validate_parallel_config(self) -> Self:
267267
)
268268

269269
if self.enable_eplb:
270-
if not current_platform.is_cuda():
270+
if not (current_platform.is_cuda() or current_platform.is_rocm()):
271271
raise ValueError(
272272
"Expert parallelism load balancing is only supported on "
273273
"CUDA devices now."

vllm/distributed/eplb/eplb_state.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ def step(
429429
# rearrangement step and perform rearrangement to ensure all ranks are
430430
# performing collective communication.
431431
self.expert_rearrangement_step += 1
432+
print("self.expert_step: ", self.expert_rearrangement_step)
432433
if self.expert_rearrangement_step >= self.expert_rearrangement_step_interval:
433434
self.expert_rearrangement_step = 0
434435
self.rearrange(model)

vllm/distributed/eplb/rebalance_execute.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def shuffle_layer(
141141

142142
p2p_ops: list[P2POp] = []
143143

144+
144145
# 2. Initiate sending of weights.
145146
experts_send_loc: dict[int, int] = {}
146147
for src in range(num_local_experts):
@@ -224,11 +225,42 @@ def shuffle_layer(
224225
for weight in expert_weights_buffer
225226
]
226227

228+
# op_info = []
229+
# for op in p2p_ops:
230+
# if op is None:
231+
# op_info.append(None)
232+
# continue
233+
234+
# op_data = {
235+
# 'isend': op.op.__name__ == "isend",
236+
# 'peer': op.peer,
237+
# 'tag': getattr(op, 'tag', 0),
238+
# 'tensor_shape': op.tensor.shape,
239+
# 'tensor_dtype': op.tensor.dtype,
240+
# 'tensor_device': op.tensor.device,
241+
# }
242+
# op_info.append(op_data)
243+
# torch.save({"op":op_info}, f"op_info_device_{ep_rank}.pt")
244+
227245
# 4. Execute the P2P operations. The real communication happens here.
228246
if p2p_ops:
229247
reqs = batch_isend_irecv(p2p_ops)
230248
for req in reqs:
231249
req.wait()
250+
# if p2p_ops:
251+
# reqs = []
252+
# for op in p2p_ops:
253+
# if op is None:
254+
# continue
255+
# if op.op.__name__ == "isend":
256+
# print("isend: ", op.peer)
257+
# req = torch.distributed.isend(op.tensor, op.peer, op.group, op.tag)
258+
# else:
259+
# print("irecv: ", op.peer)
260+
# req = torch.distributed.irecv(op.tensor, op.peer, op.group, op.tag)
261+
# reqs.append(req)
262+
# for req in reqs:
263+
# req.wait()
232264

233265
# 5. Copy the weights from the buffer back to the original weights.
234266
for dst in range(num_local_experts):
@@ -325,6 +357,7 @@ def rearrange_expert_weights_inplace(
325357
# NOTE(bowen): We need this synchronize to run, but I don't know why.
326358
# If you figure out the reason, please let me know -- thank you!
327359
torch.cuda.synchronize()
360+
print("layer: ", layer)
328361
shuffle_layer(
329362
num_local_physical_experts,
330363
ep_rank,

vllm/model_executor/layers/fused_moe/layer.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,17 +1271,17 @@ def __init__(
12711271
if self.enable_eplb:
12721272
from vllm.model_executor.layers.quantization.fp8 import Fp8MoEMethod
12731273

1274-
if not isinstance(quant_method, (Fp8MoEMethod, UnquantizedFusedMoEMethod)):
1275-
# TODO: Add support for additional quantization methods.
1276-
# The implementation for other quantization methods does not
1277-
# contain essential differences, but the current quant API
1278-
# design causes duplicated work when extending to new
1279-
# quantization methods, so I'm leaving it for now.
1280-
# If you plan to add support for more quantization methods,
1281-
# please refer to the implementation in `Fp8MoEMethod`.
1282-
raise NotImplementedError(
1283-
"EPLB is only supported for FP8 quantization for now."
1284-
)
1274+
# if not isinstance(quant_method, (Fp8MoEMethod, UnquantizedFusedMoEMethod)):
1275+
# # TODO: Add support for additional quantization methods.
1276+
# # The implementation for other quantization methods does not
1277+
# # contain essential differences, but the current quant API
1278+
# # design causes duplicated work when extending to new
1279+
# # quantization methods, so I'm leaving it for now.
1280+
# # If you plan to add support for more quantization methods,
1281+
# # please refer to the implementation in `Fp8MoEMethod`.
1282+
# raise NotImplementedError(
1283+
# "EPLB is only supported for FP8 quantization for now."
1284+
# )
12851285

12861286
moe_quant_params = {
12871287
"num_experts": self.local_num_experts,
@@ -1890,7 +1890,7 @@ def load_weights(
18901890

18911891
def get_expert_weights(self) -> Iterable[torch.Tensor]:
18921892
weights = list(self.named_parameters())
1893-
assert all(weight.is_contiguous() for _, weight in weights)
1893+
# assert all(weight.is_contiguous() for _, weight in weights)
18941894

18951895
# Filter out the non-expert weights.
18961896
# `e_score_correction_bias` is a bias for each logical expert,

vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors_moe.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,10 +1037,16 @@ def apply(
10371037
logical_to_physical_map: torch.Tensor | None = None,
10381038
logical_replica_count: torch.Tensor | None = None,
10391039
) -> torch.Tensor | tuple[torch.Tensor, torch.Tensor]:
1040+
# if enable_eplb:
1041+
# raise NotImplementedError(
1042+
# "EPLB not supported for `CompressedTensorsW8A8Fp8MoEMethod` yet."
1043+
# )
1044+
10401045
if enable_eplb:
1041-
raise NotImplementedError(
1042-
"EPLB not supported for `CompressedTensorsW8A8Fp8MoEMethod` yet."
1043-
)
1046+
assert expert_load_view is not None
1047+
assert logical_to_physical_map is not None
1048+
assert logical_replica_count is not None
1049+
assert isinstance(layer, FusedMoE)
10441050

10451051
topk_weights, topk_ids, _ = FusedMoE.select_experts(
10461052
hidden_states=x,
@@ -1056,6 +1062,11 @@ def apply(
10561062
e_score_correction_bias=e_score_correction_bias,
10571063
indices_type=self.topk_indices_dtype,
10581064
num_fused_shared_experts=layer.num_fused_shared_experts,
1065+
enable_eplb=enable_eplb,
1066+
expert_map=expert_map,
1067+
expert_load_view=expert_load_view,
1068+
logical_to_physical_map=logical_to_physical_map,
1069+
logical_replica_count=logical_replica_count,
10591070
)
10601071

10611072
per_act_token = self.input_quant.strategy == QuantizationStrategy.TOKEN

vllm/model_executor/layers/quantization/utils/w8a8_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,13 @@ def __init__(
503503
and current_platform.is_fp8_fnuz()
504504
and pad_output is not True
505505
)
506+
# if pad_output:
507+
# print("aa")
508+
self.pad_output = pad_output
509+
self.aiter = envs.VLLM_ROCM_USE_AITER
510+
self.rocm = envs.VLLM_ROCM_USE_AITER_LINEAR
511+
self.pla = current_platform.is_rocm()
512+
self.f8 = current_platform.is_fp8_fnuz()
506513

507514
if self.use_aiter_and_is_supported:
508515
self.preferred_backend = "aiter"
@@ -515,6 +522,7 @@ def __init__(
515522
self.preferred_backend = "cutlass"
516523
else:
517524
self.preferred_backend = "torch"
525+
self.bak = self.preferred_backend
518526

519527
# Note: we pad the input because torch._scaled_mm is more performant
520528
# for matrices with batch dimension > 16.

0 commit comments

Comments
 (0)