mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-04-20 06:49:15 +00:00
[DOCS] Documentation Addition (Readme updates) (#2495)
* GH-2368 Adding a basic glossary GH-2368 Minor edits GH-2368 Adding missing READMEs and standardization. resolving readme updates GH-2368 Minor improvements to documentation. Improving some readmes. Further improvement for readmes. Cleaned up the documentation in 'client_example' (#2468) Update for PR Update ACRONYMS.md to remove trivial terms Update ACRONYMS.md to provide detailed explanations for BF16 and BF8 formats Apply suggestion from @spolifroni-amd Co-authored-by: spolifroni-amd <Sandra.Polifroni@amd.com> Apply suggestion from @spolifroni-amd Co-authored-by: spolifroni-amd <Sandra.Polifroni@amd.com> Update README.md to clarify CK Tile API description and remove outdated references to the Tile Engine. revise 37_transpose readme revise 36_copy readme Remove references to the Tile Engine in README files for 19_gemm_multi_d and 35_batched_transpose, and update distribution links for clarity. Remove references to the Tile Engine in multiple README files and update distribution links for consistency and clarity. Remove references to the Tile Engine in README files across multiple examples * GH-2368 Adding a basic glossary GH-2368 Minor edits GH-2368 Adding missing READMEs and standardization. resolving readme updates GH-2368 Minor improvements to documentation. Improving some readmes. Further improvement for readmes. Cleaned up the documentation in 'client_example' (#2468) Update for PR Update ACRONYMS.md to remove trivial terms Update ACRONYMS.md to provide detailed explanations for BF16 and BF8 formats Apply suggestion from @spolifroni-amd Co-authored-by: spolifroni-amd <Sandra.Polifroni@amd.com> Apply suggestion from @spolifroni-amd Co-authored-by: spolifroni-amd <Sandra.Polifroni@amd.com> Update README.md to clarify CK Tile API description and remove outdated references to the Tile Engine. revise 37_transpose readme revise 36_copy readme Remove references to the Tile Engine in README files for 19_gemm_multi_d and 35_batched_transpose, and update distribution links for clarity. Remove references to the Tile Engine in multiple README files and update distribution links for consistency and clarity. Remove references to the Tile Engine in README files across multiple examples Refine README files by removing outdated references to the Tile Engine * Updates based on PR feedback 1 * Updates based on PR feedback 2 * Updates based on PR feedback 3 * Updates based on PR feedback 4 * Updates based on PR feedback 5 * Updates based on PR feedback 6 * Updates based on PR feedback 7 * Updates based on PR feedback 8 * Content Modification of CK Tile Example * Modify the ck_tile gemm config --------- Co-authored-by: AviralGoelAMD <aviral.goel@amd.com> Co-authored-by: ThomasNing <thomas.ning@amd.com>
This commit is contained in:
committed by
GitHub
parent
013ba3c737
commit
92c67a824f
@@ -1,18 +1,78 @@
|
||||
# moe-smoothquant
|
||||
# MoE-SmoothQuant with CK Tile
|
||||
|
||||
This folder contains example for moe-smoothquant using ck_tile tile-programming implementation.
|
||||
This example demonstrates MoE-SmoothQuant, a fused quantization operation for Mixture-of-Experts (MoE) models, using the CK Tile programming model. Unlike standard SmoothQuant, the input scale is expert-dependent, and the operation is fused with top-k expert selection. Specifically, it quantizes the top-k experts' outputs for each token using their respective expert scales. The input scale is from different expert `[expert, hidden]`, and we need reuse the `topk-id` from previous `topk-softmax` and select the corresponding `expert` from current topk, and expand the output/per-token-scale by `topk`.
|
||||
|
||||
This diagram depicts moe-smoothquant using ck_tile tile-programming implementation.
|
||||

|
||||
|
||||
Unlike standard smoothquant op, the input scale is from different expert `[expert, hidden]`, we need reuse the `topk-id` from previous `topk-softmax` and select the corresponding `expert` from current topk, and expand the output/per-token-scale by `topk`
|
||||
---
|
||||
|
||||
## build
|
||||
```
|
||||
# in the root of ck_tile
|
||||
## Algorithm and Math
|
||||
|
||||
Given:
|
||||
- **Input**: $X$ of shape $[\text{tokens}, \text{topk}, \text{hidden}]$
|
||||
- **Expert scales**: $S$ of shape $[\text{experts}, \text{hidden}]$
|
||||
- **TopK indices**: $I$ of shape $[\text{tokens}, \text{topk}]$
|
||||
|
||||
**Steps:**
|
||||
1. For each token $t$ and its $k$ selected experts:
|
||||
- Select scale $S_{I_{t,k}, :}$ for the $k$-th expert.
|
||||
- Scale: $Y_{t,k,j} = X_{t,k,j} \cdot S_{I_{t,k}, j}$
|
||||
2. **Rowwise Dynamic Quantization** (per token-expert pair):
|
||||
- $s_{t,k} = \max_j |Y_{t,k,j}| / 127$
|
||||
- $Q_{t,k,j} = \text{round}(Y_{t,k,j} / s_{t,k})$, $Q_{t,k,j} \in \text{int8}$
|
||||
|
||||
**Output**:
|
||||
- Quantized tensor $Q$ (int8)
|
||||
- Per-token-expert scale $s$ (fp32)
|
||||
|
||||
---
|
||||
|
||||
## Tile Programming Model
|
||||
|
||||
- **Tiles**: Each thread block processes a tile (block of tokens, experts, or hidden units).
|
||||
- **Tile Engine**: Loads input, selects expert scales via top-k indices, applies scaling and quantization, and writes results.
|
||||
- **Pipeline**: Modular, can be extended for further fusion.
|
||||
|
||||
---
|
||||
|
||||
## Build & Run
|
||||
|
||||
```bash
|
||||
mkdir build && cd build
|
||||
sh ../script/cmake-ck-dev.sh ../ <arch> # you can replace this <arch> to gfx90a, gfx942...
|
||||
sh ../script/cmake-ck-dev.sh ../ <arch>
|
||||
make tile_example_moe_smoothquant -j`nproc`
|
||||
./bin/tile_example_moe_smoothquant -?
|
||||
```
|
||||
This will result in an executable `build/bin/tile_example_moe_smoothquant`
|
||||
|
||||
---
|
||||
|
||||
## Source Structure
|
||||
|
||||
- **Kernel**: [`moe_smoothquant.hpp`](moe_smoothquant.hpp) (tile-programming kernel template)
|
||||
- **Executable**: [`moe_smoothquant.cpp`](moe_smoothquant.cpp)
|
||||
- **Build**: `CMakeLists.txt`, `instances/`, `misc/`, `script/`
|
||||
|
||||
---
|
||||
|
||||
## Technical Notes
|
||||
|
||||
- **Expert-dependent scaling**: Each token's top-k experts use their own per-hidden-unit scale, requiring indirect indexing and efficient memory access.
|
||||
- **Fused with top-k**: The kernel uses top-k indices from gating to select the correct expert scale for each token.
|
||||
- **Rowwise quantization**: Each token-expert pair is quantized independently for maximum accuracy.
|
||||
|
||||
---
|
||||
|
||||
## Related CK Tile Examples
|
||||
|
||||
- [09_topk_softmax](../09_topk_softmax/README.md): TopK-Softmax for MoE gating
|
||||
- [13_moe_sorting](../13_moe_sorting/README.md): MoE sorting for expert dispatch
|
||||
- [12_smoothquant](../12_smoothquant/README.md): Standard SmoothQuant
|
||||
|
||||
For distribution, see [`include/ck_tile/tile_program/tile_distribution/`](../../../include/ck_tile/tile_program/tile_distribution/).
|
||||
|
||||
---
|
||||
[Back to CK Tile Examples](../README.md)
|
||||
|
||||
## example
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user