Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
Merged
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
8 changes: 6 additions & 2 deletions torchchat/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def forward(self, x, freqs_cis, mask, input_pos=None, cache_lane: int = 0):
input_pos[-1].item(),
seqlen,
)
output = output.view(bsz, seqlen, self.dim).to(dtype=x.dtype)
output = output.view(bsz, seqlen, self.dim).to(dtype=q.dtype)
return self.wo(output)

def replace_attention_with_custom_sdpa_attention(module: nn.Module):
Expand Down Expand Up @@ -291,7 +291,11 @@ def export_for_et(model, device, output_path) -> str:
model = model.to(dtype=target_precision)
state_dict_dtype = target_precision

replace_attention_with_custom_sdpa_attention(model)
# Custom SDPA does not work with bfloat16 on CPU currently. (The op doesn't
# support anything but bfloat32, and our attempt to use it anyway by converting
# to and from float causes other errors.)
if target_precision != torch.bfloat16:
replace_attention_with_custom_sdpa_attention(model)

with torch.nn.attention.sdpa_kernel(
[torch.nn.attention.SDPBackend.MATH]
Expand Down
Loading