[PyTorch] Fix AttentionParams comparison logic #1397
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.
Description
DotProductAttention
callsget_attention_backend()
to choose an appropriate backend for a givenAttentionParams
. This call is CPU intensive and is only called whenattention_params != _attention_backends["attention_params"]
. For FP8, there are a number of entries inAttentionParams.fp8_meta
, for example,fp8_meta["scaling_fwd"]
, but what's really important isfp8_meta["recipe"]
. This PR overwrites the__eq__
function ofAttentionParams
to only compare the recipe entry for FP8 configs.Before this PR,
NVTE_DEBUG=1 NVTE_DEBUG_LEVEL=1 pytest -o log_cli=true --log-cli-level=INFO -s -v tests/pytorch/test_sanity.py::test_sanity_attention_extra_state[dtype0-large]
produces:After this PR:
This
test_sanity_attention_extra_state
test runs an FP8 config in multiple ways (i.e. with and without checkpointing), but it's the same FP8 config, so there should be only one INFO message (i.e. oneget_attention_backend
call), which is what's happening after the PR change.Fixes #1348
Type of change
Changes
Please list the changes introduced in this PR:
AttentionParams.fp8_meta
comparison to justfp8_meta["recipe"]
Checklist: