Fix BiC bias-correction loss to use logits - #103
Open
marcus-campbell wants to merge 1 commit into
Open
Conversation
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.
|
这是来自QQ邮箱的假期自动回复邮件。
您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
During BiC’s bias-correction stage,
_runappliestorch.softmaxto the bias-corrected logits before passing them toF.cross_entropy. However,F.cross_entropyexpects 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:
qand optimize-log(softmax(q)).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:
cross_entropydocumentation