-
Notifications
You must be signed in to change notification settings - Fork 269
[CK_Tile] Support for a4w4 (fp4) in block scale gemm AB quant #3603
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
Draft
ErwinTerpstra
wants to merge
21
commits into
develop
Choose a base branch
from
eterpstr/206-block-scale-gemm-fp4-support
base: develop
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.
Draft
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9891903
chore: split block scale example instances in more separate files to …
ErwinTerpstra e43fd33
wip: fp4 scaffolding for abquant
ErwinTerpstra 6dea234
feat: add fp4 decoding-while-loading to abquant pipeline
ErwinTerpstra d0cd610
feat: add support for fp4 CPU verification in abquant
ErwinTerpstra 58088a5
chore: add time tracking to reference calculation
ErwinTerpstra 3d8bfdb
feat: add a4w4 test for blockscale gemm
ErwinTerpstra 761ba1b
feat: optimize reference calculation by preconverting values to AccType
ErwinTerpstra a477fb8
feat: add fp4 to fp8 look-up table
ErwinTerpstra 72a94bd
fix: reference to wrong ComputeDataType field in QuantProblem
ErwinTerpstra 7563031
Merge branch 'develop' into eterpstr/206-block-scale-gemm-fp4-support
ErwinTerpstra e76d18e
feat: type utilities for determining MFMA compute types
ErwinTerpstra 37af217
feat: packed fp4 for abquant weight preshuffle
ErwinTerpstra 32d5757
feat: add separate tests for a4w4 base case, padding and preshuffleB
ErwinTerpstra f55d902
fix: fp4 conversion on gfx950 attempting to use non-supported method
ErwinTerpstra c0d869b
fix: test case was using quant group sizes which don't work on gfx950…
ErwinTerpstra 9eab310
chore: add fp4 preshuffleb mode to block scale example
ErwinTerpstra ce9c308
Merge branch 'develop' into eterpstr/206-block-scale-gemm-fp4-support
ErwinTerpstra 116c82a
chore: sanity check for packed types being 1 byte
ErwinTerpstra d735292
chore: clarify tensor dimension indices with constants
ErwinTerpstra 33ab9ba
chore: replace traits check with specialized check for packed types
ErwinTerpstra 8883173
Merge branch 'develop' into eterpstr/206-block-scale-gemm-fp4-support
ErwinTerpstra 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
75 changes: 75 additions & 0 deletions
75
example/ck_tile/38_block_scale_gemm/gemm_abquant_quantgrouped_bf8.cpp
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,75 @@ | ||
| // Copyright (c) Advanced Micro Devices, Inc., or its affiliates. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #include "run_gemm_quant_example.inc" | ||
|
|
||
| template <typename T> | ||
| using GemmConfig = GemmConfigABQuantPrefill<T>; | ||
|
|
||
| template <typename T> | ||
| using GemmConfigPreshuffleB = GemmConfigPreshuffleB_ABQuant_Prefill<T>; | ||
|
|
||
| void abquant_quantgrouped_bf8_instance_factory( | ||
| std::unordered_map<size_t, std::function<int(const ck_tile::ArgParser&)>>& lut) | ||
| { | ||
| lut[hash_multiple_strings({"bf8", | ||
| "abquant", | ||
| "non-preshuffleb", | ||
| "non-preshufflequant", | ||
| "1x1x128"})] = [](const ck_tile::ArgParser& arg_parser) { | ||
| using AQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 1, 128>>; | ||
| using BQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 1, 128>>; | ||
| using TypeConfig = | ||
| decltype(GemmQuantTypeConfig<ck_tile::bf8_t, ck_tile::bf8_t, ck_tile::half_t, float>{}); | ||
| return run_gemm_example_prec_type<GemmConfig<ck_tile::bf8_t>, | ||
| TypeConfig, | ||
| AQuantGroupSize, | ||
| BQuantGroupSize, | ||
| ck_tile::QuantType::ABQuantGrouped>(arg_parser); | ||
| }; | ||
| lut[hash_multiple_strings({"bf8", | ||
| "abquant", | ||
| "non-preshuffleb", | ||
| "non-preshufflequant", | ||
| "1x128x128"})] = [](const ck_tile::ArgParser& arg_parser) { | ||
| using AQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 1, 128>>; | ||
| using BQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 128, 128>>; | ||
| using TypeConfig = | ||
| decltype(GemmQuantTypeConfig<ck_tile::bf8_t, ck_tile::bf8_t, ck_tile::half_t, float>{}); | ||
| return run_gemm_example_prec_type<GemmConfig<ck_tile::bf8_t>, | ||
| TypeConfig, | ||
| AQuantGroupSize, | ||
| BQuantGroupSize, | ||
| ck_tile::QuantType::ABQuantGrouped>(arg_parser); | ||
| }; | ||
| lut[hash_multiple_strings({"bf8", | ||
| "abquant", | ||
| "preshuffleb", | ||
| "non-preshufflequant", | ||
| "1x1x128"})] = [](const ck_tile::ArgParser& arg_parser) { | ||
| using AQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 1, 128>>; | ||
| using BQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 1, 128>>; | ||
| using TypeConfig = | ||
| decltype(GemmQuantTypeConfig<ck_tile::bf8_t, ck_tile::bf8_t, ck_tile::half_t, float>{}); | ||
| return run_gemm_example_prec_type<GemmConfigPreshuffleB<ck_tile::bf8_t>, | ||
| TypeConfig, | ||
| AQuantGroupSize, | ||
| BQuantGroupSize, | ||
| ck_tile::QuantType::ABQuantGrouped>(arg_parser); | ||
| }; | ||
| lut[hash_multiple_strings({"bf8", | ||
| "abquant", | ||
| "preshuffleb", | ||
| "non-preshufflequant", | ||
| "1x128x128"})] = [](const ck_tile::ArgParser& arg_parser) { | ||
| using AQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 1, 128>>; | ||
| using BQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 128, 128>>; | ||
| using TypeConfig = | ||
| decltype(GemmQuantTypeConfig<ck_tile::bf8_t, ck_tile::bf8_t, ck_tile::half_t, float>{}); | ||
| return run_gemm_example_prec_type<GemmConfigPreshuffleB<ck_tile::bf8_t>, | ||
| TypeConfig, | ||
| AQuantGroupSize, | ||
| BQuantGroupSize, | ||
| ck_tile::QuantType::ABQuantGrouped>(arg_parser); | ||
| }; | ||
| } |
27 changes: 27 additions & 0 deletions
27
example/ck_tile/38_block_scale_gemm/gemm_abquant_quantgrouped_fp4.cpp
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,27 @@ | ||
| // Copyright (c) Advanced Micro Devices, Inc., or its affiliates. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #include "run_gemm_quant_example.inc" | ||
|
|
||
| template <typename T> | ||
| using GemmConfig = GemmConfigQuantPrefill<T>; | ||
|
|
||
| void abquant_quantgrouped_fp4_instance_factory( | ||
| std::unordered_map<size_t, std::function<int(const ck_tile::ArgParser&)>>& lut) | ||
| { | ||
| lut[hash_multiple_strings( | ||
| {"fp4", "abquant", "non-preshuffleb", "non-preshufflequant", "1x128x128"})] = | ||
| [](const ck_tile::ArgParser& arg_parser) { | ||
| using AQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 1, 128>>; | ||
| using BQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 128, 128>>; | ||
| using TypeConfig = decltype(GemmQuantTypeConfig<ck_tile::pk_fp4_t, | ||
| ck_tile::pk_fp4_t, | ||
| ck_tile::half_t, | ||
| float>{}); | ||
| return run_gemm_example_prec_type<GemmConfig<ck_tile::pk_fp4_raw_t>, | ||
| TypeConfig, | ||
| AQuantGroupSize, | ||
| BQuantGroupSize, | ||
| ck_tile::QuantType::ABQuantGrouped>(arg_parser); | ||
| }; | ||
| } |
75 changes: 75 additions & 0 deletions
75
example/ck_tile/38_block_scale_gemm/gemm_abquant_quantgrouped_fp8.cpp
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,75 @@ | ||
| // Copyright (c) Advanced Micro Devices, Inc., or its affiliates. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #include "run_gemm_quant_example.inc" | ||
|
|
||
| template <typename T> | ||
| using GemmConfig = GemmConfigABQuantPrefill<T>; | ||
|
|
||
| template <typename T> | ||
| using GemmConfigPreshuffleB = GemmConfigPreshuffleB_ABQuant_Prefill<T>; | ||
|
|
||
| void abquant_quantgrouped_fp8_instance_factory( | ||
| std::unordered_map<size_t, std::function<int(const ck_tile::ArgParser&)>>& lut) | ||
| { | ||
| lut[hash_multiple_strings({"fp8", | ||
| "abquant", | ||
| "non-preshuffleb", | ||
| "non-preshufflequant", | ||
| "1x1x128"})] = [](const ck_tile::ArgParser& arg_parser) { | ||
| using AQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 1, 128>>; | ||
| using BQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 1, 128>>; | ||
| using TypeConfig = | ||
| decltype(GemmQuantTypeConfig<ck_tile::fp8_t, ck_tile::fp8_t, ck_tile::half_t, float>{}); | ||
| return run_gemm_example_prec_type<GemmConfig<ck_tile::fp8_t>, | ||
| TypeConfig, | ||
| AQuantGroupSize, | ||
| BQuantGroupSize, | ||
| ck_tile::QuantType::ABQuantGrouped>(arg_parser); | ||
| }; | ||
| lut[hash_multiple_strings({"fp8", | ||
| "abquant", | ||
| "non-preshuffleb", | ||
| "non-preshufflequant", | ||
| "1x128x128"})] = [](const ck_tile::ArgParser& arg_parser) { | ||
| using AQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 1, 128>>; | ||
| using BQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 128, 128>>; | ||
| using TypeConfig = | ||
| decltype(GemmQuantTypeConfig<ck_tile::fp8_t, ck_tile::fp8_t, ck_tile::half_t, float>{}); | ||
| return run_gemm_example_prec_type<GemmConfig<ck_tile::fp8_t>, | ||
| TypeConfig, | ||
| AQuantGroupSize, | ||
| BQuantGroupSize, | ||
| ck_tile::QuantType::ABQuantGrouped>(arg_parser); | ||
| }; | ||
| lut[hash_multiple_strings({"fp8", | ||
| "abquant", | ||
| "preshuffleb", | ||
| "non-preshufflequant", | ||
| "1x1x128"})] = [](const ck_tile::ArgParser& arg_parser) { | ||
| using AQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 1, 128>>; | ||
| using BQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 1, 128>>; | ||
| using TypeConfig = | ||
| decltype(GemmQuantTypeConfig<ck_tile::fp8_t, ck_tile::fp8_t, ck_tile::half_t, float>{}); | ||
| return run_gemm_example_prec_type<GemmConfigPreshuffleB<ck_tile::fp8_t>, | ||
| TypeConfig, | ||
| AQuantGroupSize, | ||
| BQuantGroupSize, | ||
| ck_tile::QuantType::ABQuantGrouped>(arg_parser); | ||
| }; | ||
| lut[hash_multiple_strings({"fp8", | ||
| "abquant", | ||
| "preshuffleb", | ||
| "non-preshufflequant", | ||
| "1x128x128"})] = [](const ck_tile::ArgParser& arg_parser) { | ||
| using AQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 1, 128>>; | ||
| using BQuantGroupSize = ck_tile::QuantGroupShape<ck_tile::sequence<1, 128, 128>>; | ||
| using TypeConfig = | ||
| decltype(GemmQuantTypeConfig<ck_tile::fp8_t, ck_tile::fp8_t, ck_tile::half_t, float>{}); | ||
| return run_gemm_example_prec_type<GemmConfigPreshuffleB<ck_tile::fp8_t>, | ||
| TypeConfig, | ||
| AQuantGroupSize, | ||
| BQuantGroupSize, | ||
| ck_tile::QuantType::ABQuantGrouped>(arg_parser); | ||
| }; | ||
| } |
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.
Can't this and the non-preshuffleb variant be in the same file/function like we do on fp8 and bf8?
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.
I split them specifically since the preshuffleb pipeline is really slow to compile. This way it can already start compiling simultaneously with the other instances, and we don't extend compile times by a single translation unit taking longer than necessary. Other instances (e.g. bquant instances) the preshuffleb are also split.
So for consistency actually we could also split fp8/bf8 instances to a preshuffle-specific file