-
Notifications
You must be signed in to change notification settings - Fork 19
[MetaxGPU][quantize] Use portable C++ MXFP4 dequant on Maca #114
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
Open
ventijing
wants to merge
13
commits into
tile-ai:dev
Choose a base branch
from
ventijing:dev_dequantize
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1d335ad
[MetaxGPU][quantize] Use portable C++ MXFP4 dequant on Maca
b3ac85a
[MetaxGPU][regression] Default regression_all scan root to examples
1a6a8cb
[MetaxGPU][regression] Default regression_all scan root to examples
3393e0b
[CI] Update flash_linear_attention version to 0.4.0+metax3.7.2.0torch2.8
a09c835
[CI] Update flash_linear_attention version
3ce4d43
[CI] Update flash_linear_attention version
3eca72d
[CI] Update flash_linear_attention version
a66f8b6
[MetaxGPU][quantize] Use portable C++ MXFP4 dequant on Maca
6959071
[CI] Update flash_linear_attention version
eb23897
[MetaxGPU][quantize] Use portable C++ MXFP4 dequant on Maca
e78ebdd
[CI] Update flash_linear_attention version
3404026
[CI] Update flash_linear_attention version
6ed645f
[CI] Update flash_linear_attention version
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 |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| from typing import Literal | ||
|
|
||
| from tvm.target import Target | ||
|
|
||
| from tilelang import language as T | ||
| from tilelang.backend.target import determine_target | ||
| from tilelang.rocm.target import target_is_gfx950, target_is_hip | ||
|
|
||
| # Implementation asm for fp4 to bf16, using twiddling | ||
| # Reference: https://github.com/triton-lang/triton/blob/main/python/triton_kernels/triton_kernels/tensor_details/layout_details/hopper_value.py#L11-L18 | ||
|
|
@@ -157,6 +162,28 @@ | |
| """ | ||
|
|
||
|
|
||
| def _resolve_mxfp_target(target): | ||
| if target is not None and target != "auto": | ||
| return target | ||
| current = Target.current(allow_none=True) | ||
| if current is not None: | ||
| return current | ||
| return determine_target("auto", return_object=True) | ||
|
ventijing marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def _target_uses_portable_mxfp_dequant(target) -> bool: | ||
| """Return True for targets that cannot compile CUDA PTX inline asm (e.g. Maca, AMD gfx950).""" | ||
| if target is None: | ||
| return False | ||
| if not isinstance(target, Target): | ||
| target = Target(target) | ||
| if target.kind.name == "maca": | ||
| return True | ||
| if target_is_hip(target): | ||
| return target_is_gfx950(target) | ||
| return False | ||
|
|
||
|
|
||
| def get_mxfp_intrin_group( | ||
| out_dtype: Literal[T.float16, T.bfloat16] = T.bfloat16, | ||
| source_format: Literal[T.int, T.uint] = T.uint, | ||
|
|
@@ -195,33 +222,26 @@ def get_mxfp_intrin_group( | |
| assert source_format in [T.int, T.uint], f"Invalid source_format: {source_format}. Expected 'int' or 'uint'." | ||
| assert storage_dtype in [T.int32, T.int8, T.uint8], f"Invalid storage_dtype: {storage_dtype}. Expected 'int32' or 'int8' or 'uint8'." | ||
|
|
||
| # Detect AMD gfx950 target to select the HIP C++ dequantization implementation. | ||
| # All other targets (NV, RDNA, MI300) use the default CUDA PTX path below. | ||
| _is_gfx950 = False | ||
| if target is not None: | ||
| try: | ||
| from tilelang.rocm.target import target_is_gfx950 | ||
|
|
||
| _is_gfx950 = target_is_gfx950(target) | ||
| except (ImportError, ModuleNotFoundError, AttributeError): | ||
| # target_is_gfx950 unavailable in this build; assume non-gfx950. | ||
| pass | ||
| # Maca and AMD gfx950 cannot compile CUDA PTX; use portable C++ below. | ||
| # All other targets (NV, RDNA, MI300) use the default CUDA PTX path. | ||
| # target=None keeps the CUDA PTX default; only target="auto" resolves from context. | ||
| _resolved = _resolve_mxfp_target(target) if target == "auto" else target | ||
| _use_portable = _target_uses_portable_mxfp_dequant(_resolved) | ||
|
|
||
| dtype_map = {T.float16: "f16", T.bfloat16: "bf16"} | ||
| func_name = f"decode_fp{source_bit}_to_{dtype_map[out_dtype]}" | ||
| if use_twiddling: | ||
| func_name += "_twiddling" | ||
|
|
||
| if _is_gfx950: | ||
| # AMD gfx950 path: use portable HIP C++ implementations. | ||
| # The function name stays the same so the call site is unchanged. | ||
| if _use_portable: | ||
| # Portable C++ path (Maca / AMD gfx950). Function name unchanged for call sites. | ||
| if use_twiddling and source_bit == 4 and out_dtype == T.bfloat16: | ||
| return {"func_name": func_name, "c_source": decode_f4_to_bf16_twiddling_hip} | ||
| elif not use_twiddling and source_bit == 4 and out_dtype == T.bfloat16: | ||
| return {"func_name": func_name, "c_source": decode_f4_to_bf16_simple_hip} | ||
| else: | ||
| raise AssertionError( | ||
| f"AMD gfx950 MXFP dequant only supports source_bit=4 and out_dtype=bfloat16, " | ||
| f"Portable MXFP dequant only supports source_bit=4 and out_dtype=bfloat16, " | ||
| f"got source_bit={source_bit}, out_dtype={out_dtype}" | ||
| ) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add if branch in here like gfx950 to resolve same issue with maca target. |
||
|
|
||
|
|
||
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.
Expanded examples scope can silently drop benchmark results due to name collisions.
By switching discovery to the repo-wide
examplestree (Line 60),regression_all()now has a much higher chance of encountering duplicate benchmark names across different drivers. The current merge logic (if k not in merged) silently ignores later entries, which can hide regressions and undercount totals.A safer approach is to either fail on duplicate names or namespace keys by file path when merging.
Suggested fix (fail fast on duplicate benchmark names)
🤖 Prompt for AI Agents