Repository navigation
Preserve single-output bias shape when reversing fusion - #2539
Open
kocean9-freedom wants to merge 1 commit into
Open
kocean9-freedom wants to merge 1 commit into
kocean9-freedom wants to merge 1 commit into
Conversation
3 tasks done
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.
What does this PR do?
Preserve a one-element bias vector when reversing
FuseBiasInLinear.module.weight[:, -1]already has shape[out_features]; the extrasqueeze()turns it into a scalar whenout_features=1. The restored layer's state dict then fails to load into the originalnn.Linear, withsize mismatch for bias: torch.Size([]) ... torch.Size([1]). Single-output classification/regression heads, including text rerankers, are affected.Remove only that redundant squeeze. Multi-output and biasless layers keep their behavior; no dependency or API changes.
Validation on Python 3.12 / PyTorch 2.10 / Transformers 5.19:
cross-encoder-testing/reranker-bert-tiny-gooaq-bce-STv54reproduces the checkpoint-loading failure on upstream. With the fix, CPU and MPS paired-text scores, strict state loading, model save/reload, gradients, and one SGD update match the untransformed reference. These checks also pass from an isolated built wheel.git diff --check, sdist and wheel builds pass. The complete downloaded-model FX/Optimum test suite and CUDA were not run.The shared-call fix in #2538 is a separate issue and its current head retains this squeeze. In a separate checkout, combining its patch with this one-line fix passes all 24 shared-call and single-output cases. That patch is not included here. The dtype issue in #2533 is also outside this change.
Before submitting
AI assistance: implementation, validation, review, and PR preparation used OpenAI Codex.
Additional legacy source compatibility
A separate checkout combining #2535, #2539 and #2540 passes 33 offline cases with Transformers 4.57.6 on both PyTorch 2.10.0 and 2.5.1: the two new 14-case suites, #2535's three layouts, and two existing offline helper tests. This is a source compatibility overlay using Hub 0.36.2, which does not satisfy current main's Hub >=1.31 requirement; repository dependency pins are unchanged. It is not a fully resolved legacy installation or a downloaded-model/full-suite claim.