Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions megatron/core/transformer/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,8 @@ def flash_decode_and_prefill(
q = q.squeeze(1)
if getattr(self, "softmax_scale", None) is not None:
softmax_scale = self.softmax_scale
elif self.config.softmax_scale is not None:
softmax_scale = self.config.softmax_scale
else:
softmax_scale = q.shape[-1] ** -0.5
if HAVE_FA3:
Expand Down
10 changes: 9 additions & 1 deletion megatron/core/transformer/multi_latent_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,15 @@ def __init__(
self.qkv_up_checkpoint = None

mscale = _yarn_get_mscale(self.config.rotary_scaling_factor, self.config.mscale_all_dim)
self.softmax_scale = mscale * mscale / math.sqrt(self.q_head_dim)
self.softmax_scale = (
mscale
* mscale
* (
(1 / math.sqrt(self.q_head_dim))
if self.config.softmax_scale is None
else self.config.softmax_scale
)
)
self.cache_mla_latents = self.config.cache_mla_latents

if self.config.rope_type == "rope":
Expand Down
Loading