Fix dtype mismatches in SwitchTransformers and TimmWrapperModel for bfloat16#45085
Closed
hkc5 wants to merge 1 commit intohuggingface:mainfrom
Closed
Fix dtype mismatches in SwitchTransformers and TimmWrapperModel for bfloat16#45085hkc5 wants to merge 1 commit intohuggingface:mainfrom
hkc5 wants to merge 1 commit intohuggingface:mainfrom
Conversation
…float16 - SwitchTransformersTop1Router: Don't reassign router_logits, use router_max_probs instead - TimmWrapperModel: Cast pixel_values to model dtype in forward() Fixes huggingface#45072
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: switch_transformers, timm_wrapper |
Contributor
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45085&sha=4005bd |
Member
|
Duplicate of #45074! |
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.
This PR fixes #45072.
Changes
SwitchTransformers
SwitchTransformersTop1Router.forward()whererouter_logitswas being reassigned to the max probability values instead of keeping the raw logits from the classifier. This caused dtype mismatches when using bfloat16.router_max_probsas a new variable to hold the max probability values, whilerouter_logitsnow correctly retains the raw logits for computing the router z-loss.TimmWrapperModel
pixel_valueswas only being cast to the device but not to the model's dtype inTimmWrapperModel.forward(). This caused dtype mismatches when the model was loaded in bfloat16 but the input was float32.TimmWrapperModelwithTimmWrapperForImageClassificationwhich already had the correct behavior.Testing
Both fixes have been verified to resolve the dtype mismatch issues described in #45072.