[PyTorch] Add caching for attention backend selection results #1381
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
This PR adds caching for multiple attention configurations in the same run.
Currently we only cache one
attention_params
and its correspondingavailable_backends
andselected_backend
. If there are multiple configurations in the same training/inference job, for example, it runs like this:config 1
,config 2
, ...,config 1
,config 2
, ..., then the secondconfig 1
orconfig 2
still needs to go through theget_attention_backend()
call, which is CPU intensive. With this PR, we cache the backend analysis results for multiple configs, so the second time a config is run, no repeated analysis is needed. The max number of configs cached is currently set to 10.Fixes #1349
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: