Skip to content
Open
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
9 changes: 8 additions & 1 deletion sam3/perflib/fused.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@

def addmm_act(activation, linear, mat1):
if torch.is_grad_enabled():
raise ValueError("Expected grad to be disabled.")
# Training path: the fused kernel below is inference-only (detached
# weights, bf16 cast), so fall back to standard autograd-friendly ops.
y = linear(mat1)
if activation in [torch.nn.functional.relu, torch.nn.ReLU]:
return torch.nn.functional.relu(y)
if activation in [torch.nn.functional.gelu, torch.nn.GELU]:
return torch.nn.functional.gelu(y)
raise ValueError(f"Unexpected activation {activation}")
self = linear.bias.detach()
mat2 = linear.weight.detach()
self = self.to(torch.bfloat16)
Expand Down