Repository navigation
fix(rocke): reach _resolve_attention_arch through the module handle #10508
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
AnaghaRaoAMD
merged 6 commits into
develop
from
users/anarao/fix-attention-arch-patch-seam
Aug 17, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
756dc0e
fix(rocke): reach _resolve_attention_arch through the module handle
AnaghaRaoAMD 818c75f
fix(rocke): restore attention_d256 in the golden IR parity gate
aosewski adfc04a
test(rocke): contain attention arch state leaks between tests
aosewski 7c47e74
test(rocke): pin the lazy arch-resolver binding with a guard test
aosewski 55c3ecb
test(rocke): restate the arch-pin failure deterministically
aosewski b22397f
Merge branch 'develop' into users/anarao/fix-attention-arch-patch-seam
aosewski 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
103 changes: 103 additions & 0 deletions
103
dnn-providers/hip-kernel-provider/rocke/library/tests/test_arch_binding_guard.py
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,103 @@ | ||
| # Copyright (c) Advanced Micro Devices, Inc., or its affiliates. | ||
| # SPDX-License-Identifier: MIT | ||
| """Guard: the spec builder must reach ``_resolve_attention_arch`` lazily. | ||
|
|
||
| ``builders.common.attention_spec_builder`` used to bind the resolver with | ||
| ``from kernels.common.attention_unified import _resolve_attention_arch``. A bound | ||
| import freezes the reference at import time, so ``mock.patch.object(au, | ||
| "_resolve_attention_arch", ...)`` -- which rebinds the attribute on the *module* | ||
| -- never reached the builder. The builder then resolved the real device arch, | ||
| and the gfx950-only spec overrides raised ``TypeError`` against a gfx942 spec | ||
| class. The binding dates to #9057 and turned load-bearing in #9233. | ||
|
|
||
| The rule is now: reach the resolver through the ``_kau`` module handle. Nothing | ||
| in the language enforces that, so these tests do -- one statically, one through | ||
| observable behaviour. | ||
|
|
||
| Both tests are host-independent. The behavioural one pins *two* archs, because | ||
| the resolver falls back to ``"gfx950"`` with no device and ``_tiled_2d_impl`` | ||
| maps every arch except gfx942/gfx1250 onto the gfx950 impl -- so a single pin | ||
| can pass by coincidence on most hosts. Both builder entry points are covered: | ||
| ``_tiled_spec_from_problem`` and ``_tiled_3d_spec_from_problem`` each hold their | ||
| own ``_kau._resolve_attention_arch()`` call site, and both were served by the | ||
| same bound import before the fix. | ||
|
|
||
| gfx1250 is deliberately NOT pinned: it needs its own problem shape (2D rejects | ||
| ``block_size=16``, 3D rejects ``head_size=128``), so it would couple this guard | ||
| to the evolving gfx1250 support matrix while adding no discriminating power -- | ||
| the gfx942 pin alone already fails on the unfixed builder. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import unittest | ||
| from unittest import mock | ||
|
|
||
| import builders.common.attention_spec_builder as asb | ||
| import kernels.common.attention_unified as au | ||
| from kernels import UnifiedAttentionProblem | ||
|
|
||
| # Plain bf16 D128 prefill: no sinks / sliding-window / softcap / alibi / bias, so | ||
| # it routes onto the ordinary 2D tiled path on every arch under test and is not | ||
| # diverted by any arch-specific fast route. | ||
| _PROBLEM = UnifiedAttentionProblem( | ||
| total_q=1024, | ||
| num_seqs=2, | ||
| num_query_heads=16, | ||
| num_kv_heads=2, | ||
| head_size=128, | ||
| block_size=16, | ||
| max_seqlen_q=512, | ||
| max_seqlen_k=4096, | ||
| dtype="bf16", | ||
| ) | ||
|
|
||
| # Decode-shaped variant of the same plain bf16 problem, for the 3D entry point. | ||
| _PROBLEM_3D = UnifiedAttentionProblem( | ||
| total_q=2, | ||
| num_seqs=2, | ||
| num_query_heads=16, | ||
| num_kv_heads=2, | ||
| head_size=128, | ||
| block_size=16, | ||
| max_seqlen_q=1, | ||
| max_seqlen_k=4096, | ||
| dtype="bf16", | ||
| ) | ||
|
|
||
| _BOUND_IMPORT_TRAP = ( | ||
| "attention_spec_builder must reach _resolve_attention_arch through its " | ||
| "attention_unified module handle -- a bound import freezes the reference at " | ||
| "import time and silently defeats mock.patch.object on the module" | ||
| ) | ||
|
|
||
|
|
||
| class TestArchResolverBinding(unittest.TestCase): | ||
| def test_builder_does_not_bind_the_resolver(self): | ||
| """Static form: the name must not be an attribute of the builder.""" | ||
| # assertFalse(hasattr(...)), not assertNotIn(..., vars(asb)) -- the | ||
| # latter prints the builder's entire module dict on failure. | ||
| self.assertFalse(hasattr(asb, "_resolve_attention_arch"), _BOUND_IMPORT_TRAP) | ||
|
|
||
| def test_patching_the_module_steers_the_builder(self): | ||
| """Behavioural form: the pin must reach the spec class the builder picks.""" | ||
| entries = ( | ||
| ("2d", asb._tiled_spec_from_problem, _PROBLEM), | ||
| ("3d", asb._tiled_3d_spec_from_problem, _PROBLEM_3D), | ||
| ) | ||
| for arch in ("gfx942", "gfx950"): | ||
| for label, build, problem in entries: | ||
| with self.subTest(arch=arch, entry=label): | ||
| with mock.patch.object( | ||
| au, "_resolve_attention_arch", return_value=arch | ||
| ): | ||
| spec = build(problem) | ||
| self.assertTrue( | ||
| type(spec).__module__.startswith(f"kernels.{arch}."), | ||
| f"{_BOUND_IMPORT_TRAP}; {label} pinned {arch} but got " | ||
| f"{type(spec).__module__}", | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.