Skip to content

[Fix][Relax] Preserve attention semantics in ToMixedPrecision - #21071

Open
charan-rathore wants to merge 2 commits into
apache:mainfrom
charan-rathore:fix/attention-mixed-precision-semantics
Open

charan-rathore wants to merge 2 commits into
apache:mainfrom
charan-rathore:fix/attention-mixed-precision-semantics

Conversation

@charan-rathore

Copy link
Copy Markdown

Fixes #21067.

The shared mixed-precision callback rebuilt every attention call as a plain three-input attention operation with default attributes. This dropped scale, causal_mask and window_size, changed attention_bias into plain attention while discarding its bias, and changed attention_var_len into plain attention while discarding sequence metadata.

Return the existing call instead. The mixed-precision rewriter already remaps and casts floating-point inputs, preserves integer inputs, and clears the inferred type before normalization. Attention has no separate accumulator or output dtype attribute to rewrite.

Add structural regression cases for plain, biased and variable-length attention, default and non-default attributes, and both ToMixedPrecision output dtype settings. The expected modules retain all operands and attributes while casting floating-point inputs to float16 and restoring the function output to float32. Integer sequence metadata remains int32.

Testing on current main 1091f2f with a native CPU build and supported apache-tvm-tirx 0.1.0:

  • Regression before the fix: 16 failed, 2 passed.
  • Regression after the fix: 18 passed.
  • Entire test_transform_to_mixed_precision.py: 34 passed.
  • Ruff check, Ruff format check and git diff --check passed.

These are structural compiler regression tests, not numerical attention execution or a performance benchmark.

This change was developed with AI assistance.

Retain the attention operator, arguments and semantic attributes while the mixed-precision rewriter handles dtype conversion. Developed with AI assistance.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [Relax] ToMixedPrecision silently drops scale, causal_mask, window_size, and bias on attention ops

1 participant