Repository navigation
engine: let a ragged attention node declare its activation dtype #291
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1b172ed
Let a ragged attention config declare its activation dtype
merceod 98f1f31
Build the ragged manager from the config dtype, KV dtype as fallback
merceod fb3ac2a
Test the ragged attention dtype resolution
merceod 747ef79
comment fix
NSagan271 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """CPU tests for the ragged attention resource's activation dtype. | ||
|
|
||
| A cacheless attention has no KV cache to inherit a dtype from, so a node without a | ||
| KV-backed attention (a DiT) declares it on the config; the engine's KV dtype stays the | ||
| fallback for nodes that have one, and neither being set is an error, not an fp32 kernel. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| sys.path.insert(0, ".") | ||
|
|
||
| from mstar.engine.resources import RaggedAttentionConfig, RaggedAttentionSpec # noqa: E402 | ||
| from mstar.engine.resources.attn.ragged.base import RaggedAttnManager # noqa: E402 | ||
| from mstar.engine.resources.base import EngineResourceInfo # noqa: E402 | ||
|
|
||
| CPU = torch.device("cpu") | ||
|
|
||
|
|
||
| def _spec(dtype=None) -> RaggedAttentionSpec: | ||
| return RaggedAttentionSpec( | ||
| resource_key="dit_attn", nodes={"dit"}, | ||
| config=RaggedAttentionConfig(num_qo_heads=2, num_kv_heads=2, head_dim=128, dtype=dtype), | ||
| ) | ||
|
|
||
|
|
||
| def test_config_dtype_reaches_the_kernel_without_a_kv_dtype(): | ||
| manager = RaggedAttnManager.build(_spec(torch.bfloat16), EngineResourceInfo(device=CPU, kv_dtype=None)) | ||
| assert manager._kwargs["q_data_type"] is torch.bfloat16 | ||
|
|
||
|
|
||
| def test_config_dtype_wins_over_the_engine_kv_dtype(): | ||
| manager = RaggedAttnManager.build(_spec(torch.float16), EngineResourceInfo(device=CPU, kv_dtype=torch.bfloat16)) | ||
| assert manager._kwargs["q_data_type"] is torch.float16 | ||
|
|
||
|
|
||
| def test_engine_kv_dtype_is_the_fallback(): | ||
| manager = RaggedAttnManager.build(_spec(None), EngineResourceInfo(device=CPU, kv_dtype=torch.bfloat16)) | ||
| assert manager._kwargs["q_data_type"] is torch.bfloat16 | ||
|
|
||
|
|
||
| def test_no_dtype_anywhere_is_an_error(): | ||
| with pytest.raises(ValueError, match="no activation dtype"): | ||
| RaggedAttnManager.build(_spec(None), EngineResourceInfo(device=CPU, kv_dtype=None)) |
Oops, something went wrong.
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.
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.
Nit: kv_dtype is actually a misnamed engine autocast dtype (legacy naming from when the kv cache was hardcoded into the engine). So this config field is good to have, but a node with no KV-backed attention does work fine, but it just inherits the engine autocast dtype.
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.
@NSagan271 would you please make this fix and merge? I am working on reviewing comments on 5 of my PRs currently and also reviewing the Rust PR.