
Implement binary focal loss for logits and its gradient with respect to each logit. Given a list of real-valued logits logits, binary labels labels in {0,1}, focusing parameter gamma, balancing factor alpha, and reduction mode ("none", "sum", or "mean"), return both the forward loss and the backward gradient vector. Use a numerically stable sigmoid/log-sigmoid formulation.
1 <= len(logits) == len(labels) <= 10^5labels[i] is either 0 or 10 <= alpha <= 10 <= gamma <= 5reduction is one of "none", "sum", or "mean"