-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add attention_backend to let user choose #1456
base: main
Are you sure you want to change the base?
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchchat/1456
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making these changes! This looks good to me.
cc @Jack-Khuu
Looks like the ET pin needs bumping so I'll spin that up |
torchchat/generate.py
Outdated
if self.builder_args.device == "cpu" and (self.builder_args.attention_backend == "efficient_attention" | ||
or self.builder_args.attention_backend == "cudnn_attention"): | ||
print(f"Warning: {self.builder_args.attention_backend} is not supported on CPU. Using math instead.") | ||
self.builder_args.attention_backend = "math" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we bump this into the constructor of BuilderArgs?
@@ -69,6 +69,7 @@ class BuilderArgs: | |||
prefill_possible: bool = False | |||
dynamic_shapes: bool = False | |||
max_seq_length: Optional[int] = None | |||
attention_backend: str = "math" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the change!! Mind bumping the casting to the actual kernel into the body here?
That way we can do any sanity checks early and aren't passing around a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have updated. Please review again!
@angelayi I recall you mentioning that there might be export issue with the other SDP backend? Do you know if this issue was addressed? Or should be gate the backends to non-export? |
Seems like yall had a chance to explore the export issue in the tagged issue Let's add a check in |
torchchat/generate.py
Outdated
sdp_backend_dict = { | ||
'math': torch.nn.attention.SDPBackend.MATH, | ||
'flash_attention': torch.nn.attention.SDPBackend.FLASH_ATTENTION, | ||
'efficient_attention': torch.nn.attention.SDPBackend.EFFICIENT_ATTENTION, | ||
'cudnn_attention': torch.nn.attention.SDPBackend.CUDNN_ATTENTION, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we push this into the builder.py as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
d22fdb6
to
48f3c19
Compare
bump this into the constructor of BuilderArgs
This PR is submitted for #1452, to add an argument
attention_backend
to let user choose the backend used in SDPA.For CPU, only
math
andflash_attention
are valid. For CUDA, all 4 backends are valid.