fix(rvt): AxialRotaryEmbedding preserves float16 / bfloat16 input dtype - #373
Open
tritsystem wants to merge 1 commit into
Open
tritsystem wants to merge 1 commit into
tritsystem wants to merge 1 commit into
Conversation
AxialRotaryEmbedding.forward unpacks dtype from x but never uses it - seq is built with torch.linspace(..., device = device) and no dtype=, so it is always float32. scales.to(x) does not rescue it (float32 * half -> float32), so the returned sin / cos are float32. In RvT those multiply the half-precision q / k in apply_rotary_emb, and the model raises "RuntimeError: expected m1 and m2 to have the same dtype" - RvT does not run in half precision at all. Pass dtype = dtype to torch.linspace. float32 output is unchanged. test_rvt.py builds RvT in float16 and bfloat16 and asserts the output shape and dtype. Fails on main (RuntimeError: mixed dtype), passes here. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
tritsystem
force-pushed
the
fix/rvt-preserve-input-dtype
branch
from
September 4, 2026 12:21
4bfd6e5 to
d5e8943
Compare
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
RvTdoes not run in half precision —RuntimeError: expected m1 and m2 to have the same dtype.AxialRotaryEmbedding.forwardunpacksdtypefromxbut never uses it:scales.to(x)doesn't rescue it (float32 * half -> float32), sosin/coscome backfloat32. InRvTthose multiply the half-precisionq/kinsideapply_rotary_emband the attention matmul raises.Repro (on
main)AxialRotaryEmbeddingalone:float16/bfloat16in ->float32sin, cosout.Fix
Pass
dtype = dtypetotorch.linspace— thedtypethe method already unpacks.float32output is unchanged;float16/bfloat16now round-trip.Test
tests/test_rvt.pybuildsRvTinfloat16andbfloat16and asserts the output shape and dtype.main:2 failed(RuntimeError: expected m1 and m2 to have the same dtype)2 passedAI disclosure
Found by a metamorphic dtype-preservation sweep that flagged
AxialRotaryEmbedding'storch.linspace(..., device = device)with nodtype=and the unuseddtypelocal, then confirmedfloat16in ->float32out. I verified the repro, the fix, and fail-on-main/ pass-with-fix.