Skip to content

Fix BiC bias-correction loss to use logits - #103

Open
marcus-campbell wants to merge 1 commit into
LAMDA-CL:masterfrom
marcus-campbell:fix/bic-bias-correction-loss
Open

Fix BiC bias-correction loss to use logits#103
marcus-campbell wants to merge 1 commit into
LAMDA-CL:masterfrom
marcus-campbell:fix/bic-bias-correction-loss

Conversation

@marcus-campbell

@marcus-campbell marcus-campbell commented Aug 21, 2026

Copy link
Copy Markdown

Description

During BiC’s bias-correction stage, _run applies torch.softmax to the bias-corrected logits before passing them to F.cross_entropy. However, F.cross_entropy expects unnormalized logits and already applies log-softmax internally. Passing normalized probabilities as its input therefore changes the loss and the gradients used to train the bias-layer parameters.

This PR passes the bias-corrected logits directly to F.cross_entropy. The same call form is already used by BiC’s stage-one training path.

Validation

If you look at the original BiC formulation:

  • Equations 4 and 5 of the BiC paper define affine-corrected logits q and optimize -log(softmax(q)).
  • The paper authors’ reference implementation passes its corrected logits directly to TensorFlow’s softmax_cross_entropy.

The patched BiC._run(..., stage="bias_correction") path produces exactly the paper-form gradients in a focused PyTorch check. The current "softmax before cross-entropy" expression produced different loss and gradients.

References:

Pass the bias-corrected logits directly to F.cross_entropy during
stage-two training. F.cross_entropy already applies log-softmax
internally, so normalizing the logits first changes the loss and
gradients. This fix matches the loss defined by the original BiC paper
and reference implementation.
@caoshuai888

caoshuai888 commented Aug 21, 2026 via email

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants