[OPT] DeepSeekV3.2: optimize indexer weight_proj-mma performance (#17205)
This commit is contained in:
@@ -182,12 +182,11 @@ class Indexer(MultiPlatformOp):
|
||||
quant_config=quant_config,
|
||||
prefix=add_prefix("wk", prefix),
|
||||
)
|
||||
# NOTE: weights_proj in the checkpoint is stored in bf16, while the parameters here are stored in fp32 for convenience
|
||||
self.weights_proj = ReplicatedLinear(
|
||||
self.hidden_size,
|
||||
self.n_heads,
|
||||
bias=False,
|
||||
params_dtype=torch.float32,
|
||||
params_dtype=torch.bfloat16,
|
||||
prefix=add_prefix("weights_proj", prefix),
|
||||
)
|
||||
self.k_norm = LayerNorm(self.head_dim, dtype=torch.float32)
|
||||
@@ -221,13 +220,15 @@ class Indexer(MultiPlatformOp):
|
||||
|
||||
@torch.compile(dynamic=True) if not _is_hip else lambda f: f
|
||||
def _project_and_scale_head_gates(self, x: torch.Tensor):
|
||||
weights, _ = self.weights_proj(x.float())
|
||||
weights, _ = self.weights_proj(x)
|
||||
weights = weights.float()
|
||||
weights = weights * self.n_heads**-0.5
|
||||
return weights
|
||||
|
||||
@torch.compile(dynamic=True) if not _is_hip else lambda f: f
|
||||
def _get_logits_head_gate(self, x: torch.Tensor, q_scale: torch.Tensor):
|
||||
weights, _ = self.weights_proj(x.float())
|
||||
weights, _ = self.weights_proj(x)
|
||||
weights = weights.float()
|
||||
weights = weights * self.n_heads**-0.5
|
||||
weights = weights.unsqueeze(-1) * q_scale * self.softmax_scale
|
||||
return weights
|
||||
|
||||
Reference in New Issue
Block a user