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
4 changes: 4 additions & 0 deletions sam3/train/loss/loss_fns.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ def sigmoid_focal_loss(
"""
if not (0 <= alpha <= 1) and triton:
raise RuntimeError(f"Alpha should be in [0,1], got {alpha}")
# The Triton backward path is numerically invalid for gamma == 0 because it
# computes (1 - p_t) ** (gamma - 1), i.e. an inverse power at zero.
if triton and float(gamma) == 0.0:
triton = False
if triton:
if reduce and not loss_on_multimask:
loss = triton_sigmoid_focal_loss_reduce(inputs, targets, alpha, gamma)
Expand Down