fix(testing): Fix MoonshineEncoder UnboundLocalError and Florence2VisionBackbone dtype mismatch#44503
Merged
Rocketknight1 merged 1 commit intohuggingface:mainfrom Mar 9, 2026
Conversation
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: florence2, moonshine |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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?
The following failing tests were identified and fixed in this PR:
→ Moonshine: In MoonshineEncoder.forward, the var
output_attention_maskis only assigned inside the if attention_mask is not None clause, but create_bidirectional_mask called immediately after withattention_mask=Nonestill returns a non-None tensor. Undertorch.compile(dynamic=True),is_tracing()returnsTrueinside _ignore_bidirectional_mask_sdpa → not is_tracing(padding_mask) fails and _ignore_bidirectional_mask_sdpa returnsFalse, so the allow_is_bidirectional_skip early-exit in sdpa_mask clause never fires and a full batched tensor is materialized (shown in the trace). Speaking to the return-time guard, attention_mask is not None becomes truthy even when no padding mask was provided, leavingoutput_attention_maskunset. The aforementioned case is hit by test_sdpa_can_compile_dynamic since it drops all attention masks before calling the model and causes anUnboundLocalError; this change should fix that.Here are the trace outputs that led to arrive at the above explanation:
→ Florence2Vision: test_sdpa_can_compile_dynamic loads the model in
bfloat16, but Florence2VisionBackbone.forward gotfloat32activations from upstream processing but (its conv weights self.convs[0].conv.weight) werebfloat16. Casting the dtype fixes this :)CI Failures:
Before the fix (feel free to cross-check; these errors are reproducible):
After the fix (feel free to cross-check):
cc: @Rocketknight1
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.