NPU case rl update weights for tensor load_format == None and flatten bucket (#29503)
This commit is contained in:
@@ -68,7 +68,6 @@ from sglang.srt.utils import (
|
||||
get_bool_env_var,
|
||||
is_cpu,
|
||||
is_hip,
|
||||
is_npu,
|
||||
print_info_once,
|
||||
round_up,
|
||||
)
|
||||
@@ -77,7 +76,6 @@ from sglang.srt.utils.custom_op import register_custom_op
|
||||
_is_hip = is_hip()
|
||||
_is_cpu_amx_available = cpu_has_amx_support()
|
||||
_is_cpu = is_cpu()
|
||||
_is_npu = is_npu()
|
||||
_use_aiter = get_bool_env_var("SGLANG_USE_AITER") and _is_hip
|
||||
|
||||
|
||||
@@ -791,13 +789,6 @@ class FusedMoE(torch.nn.Module):
|
||||
# expert weights into block layout. During weight update, we must restore
|
||||
# canonical load-time shapes before copying checkpoint tensors.
|
||||
if isinstance(method, UnquantizedFusedMoEMethod):
|
||||
if _is_npu:
|
||||
if weight_name.endswith(".experts.w2_weight"):
|
||||
if param.data.shape[1] != loaded_weight.shape[0]:
|
||||
param.data = param.data.transpose(1, 2).contiguous()
|
||||
if weight_name.endswith(".experts.w13_weight"):
|
||||
if param.data.shape[2] != loaded_weight.shape[1]:
|
||||
param.data = param.data.transpose(1, 2).contiguous()
|
||||
method.maybe_restore_flashinfer_trtllm_bf16_weight_shape_for_load(
|
||||
layer=self,
|
||||
param=param,
|
||||
|
||||
@@ -337,14 +337,10 @@ class UnquantizedFusedMoEMethod(FusedMoEMethodBase, MultiPlatformOp):
|
||||
layer.w2_weight.data = layer.w2_weight.data.reshape(
|
||||
layer.num_local_experts, *new_shape_w2
|
||||
)
|
||||
|
||||
if _is_npu:
|
||||
for weight_name in ["w13_weight", "w2_weight"]:
|
||||
weight = getattr(layer, weight_name)
|
||||
origin_weight = weight.data.transpose(1, 2)
|
||||
new_weight = origin_weight.contiguous()
|
||||
origin_weight.untyped_storage().resize_(0)
|
||||
weight.data = npu_format_cast(new_weight)
|
||||
weight.data = npu_format_cast(weight)
|
||||
|
||||
return
|
||||
|
||||
@@ -697,7 +693,7 @@ class UnquantizedFusedMoEMethod(FusedMoEMethodBase, MultiPlatformOp):
|
||||
# gmm1: gate_up_proj
|
||||
hidden_states = torch.ops.npu.npu_grouped_matmul(
|
||||
x=[hidden_states],
|
||||
weight=[layer.w13_weight],
|
||||
weight=[layer.w13_weight.transpose(1, 2)],
|
||||
bias=w13_bias,
|
||||
split_item=2,
|
||||
group_list_type=1,
|
||||
@@ -733,7 +729,7 @@ class UnquantizedFusedMoEMethod(FusedMoEMethodBase, MultiPlatformOp):
|
||||
# gmm2: down_proj
|
||||
hidden_states = torch.ops.npu.npu_grouped_matmul(
|
||||
x=[hidden_states],
|
||||
weight=[layer.w2_weight],
|
||||
weight=[layer.w2_weight.transpose(1, 2)],
|
||||
bias=w2_bias,
|
||||
split_item=2,
|
||||
group_list_type=1,
|
||||
|
||||
Reference in New Issue
Block a user