Commit 075841f3 authored by wujl5's avatar wujl5
Browse files

DS_v2_w4a8_CRQ增加slilu_mul_quant支持

parent 8c646ebe
...@@ -1536,6 +1536,15 @@ class RowParallelLinear(LinearBase): ...@@ -1536,6 +1536,15 @@ class RowParallelLinear(LinearBase):
# Only fuse bias add into GEMM for rank 0 (this ensures that # Only fuse bias add into GEMM for rank 0 (this ensures that
# bias will not get added more than once in TP>1 case) # bias will not get added more than once in TP>1 case)
bias_ = None if (self.tp_rank > 0 or self.skip_bias_add) else self.bias bias_ = None if (self.tp_rank > 0 or self.skip_bias_add) else self.bias
if use_fused_silu_mul_quant:
xq, xs = lm_fuse_silu_mul_quant(input_parallel)
silu_quant_args = [xq, xs]
output_parallel = self.quant_method.apply(self,
input_parallel,
bias=bias_,
silu_quant_args=silu_quant_args)
else:
output_parallel = self.quant_method.apply(self, output_parallel = self.quant_method.apply(self,
input_parallel, input_parallel,
bias=bias_) bias=bias_)
...@@ -1561,7 +1570,7 @@ class RowParallelLinear(LinearBase): ...@@ -1561,7 +1570,7 @@ class RowParallelLinear(LinearBase):
return output return output
return output, resi, xq, xs, output_bias return output, resi, xq, xs, output_bias
else: else: # RQ and Defualt forward
if self.input_is_parallel: if self.input_is_parallel:
input_parallel = input_ input_parallel = input_
else: else:
......
...@@ -167,6 +167,8 @@ class SlimQuantW4A8Int8LinearMethod(LinearMethodBase): ...@@ -167,6 +167,8 @@ class SlimQuantW4A8Int8LinearMethod(LinearMethodBase):
elif envs.USE_FUSED_CUSTOM_ALL_REDUCE_RMS_QUANT and input_quant_args is not None: elif envs.USE_FUSED_CUSTOM_ALL_REDUCE_RMS_QUANT and input_quant_args is not None:
assert len(input_quant_args) == 2 assert len(input_quant_args) == 2
x_q, x_scale = input_quant_args x_q, x_scale = input_quant_args
elif envs.USE_FUSED_CUSTOM_ALL_REDUCE_RMS_QUANT and silu_quant_args is not None:
x_q, x_scale = silu_quant_args
else: else:
x_q, x_scale = per_token_quant_int8(x) x_q, x_scale = per_token_quant_int8(x)
......
...@@ -109,6 +109,9 @@ class DeepseekV2MLP(nn.Module): ...@@ -109,6 +109,9 @@ class DeepseekV2MLP(nn.Module):
return x, new_resi return x, new_resi
elif envs.USE_FUSED_CUSTOM_ALL_REDUCE_RMS_QUANT and xqxs is not None: elif envs.USE_FUSED_CUSTOM_ALL_REDUCE_RMS_QUANT and xqxs is not None:
gate_up, _ = self.gate_up_proj(x, xqxs=xqxs) gate_up, _ = self.gate_up_proj(x, xqxs=xqxs)
if envs.USE_FUSED_SILU_MUL_QUANT:
x, _ = self.down_proj(gate_up, use_fused_silu_mul_quant=True)
else:
x = self.act_fn(gate_up) x = self.act_fn(gate_up)
x, _ = self.down_proj(x) x, _ = self.down_proj(x)
return x return x
...@@ -930,8 +933,6 @@ class DeepseekV2DecoderLayer(nn.Module): ...@@ -930,8 +933,6 @@ class DeepseekV2DecoderLayer(nn.Module):
return forward_func(positions=positions, hidden_states=hidden_states, residual=residual ) return forward_func(positions=positions, hidden_states=hidden_states, residual=residual )
@support_torch_compile @support_torch_compile
class DeepseekV2Model(nn.Module): class DeepseekV2Model(nn.Module):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment