Files
tilelang/examples/dequantize_gemm
8ce2778221 [CI][Refactor] Merge test CI workflow files into one (#973)
* refactor: merge test CI workflow files into one

* chore: set `UV_INDEX_STRATEGY=unsafe-best-match`

* feat: add AST test with Python 3.8

* feat: implement manual caching mechanism for self-hosted runners

* refactor: simplify cache logic for self-hosted runners

* chore: clear uv cache on failure

* chore: print format.sh output to logs

* chore: improve uv caching

* chore: disable parallel test

* chore: use `PYTHONDEVMODE=1` in CI

* feat: enable coredump generation

* fix: fix perfbench condition

* Revert "feat: enable coredump generation"

This reverts commit c52da65cb5.

* chore: move example CI down

* Revert "chore: move example CI down"

This reverts commit 9d8e65055e.

* chore: skip example `test_example_mha_sink_bwd_bhsd`

* chore: skip example `test_example_gqa_sink_bwd_bhsd`

* fix: fix example argument passing

* fix: loosen test criteria

* chore: rename `CMAKE_CONFIGURE_OPTIONS` -> `CLANG_TIDY_CMAKE_OPTIONS` for clarity

* feat: enable parallel testings

* chore: update pytest options

* remove skipped test as now been resolved

* chore: empty commit to re-trigger ci

* test for n 1

* chore: remove ` --numprocesses=1` option in example

* chore: disable failfast

* chore: update cibw selection

* fix: fix git submodule clone

* chore: update cibw commands

* fix: fix yapf multiprocessing

* chore: setup ccache for CIBW on macOS only

* chore: update comments

* chore: update artifact listing

* fix: do not fail if not found nvcc in PATH

* fix: fix flash-attn installation

* chore: update dist workflow trigger

* chore: remove outdated comments

* chore(workflows/dist): simplify build matrix strategy

* fix: fix CUDA path finding

* fix: fix CUDA path finding

* chore: imcrease CI timeout

* ci: disable failfast

* fix: hide path prefix

* chore: more verbose

* chore: disable PR trigger for dist workflow

* fix: seed for tests

* fix: use nightly torch for ROCm tests

* chore: enable PR trigger for dist workflow

* chore: stop uploading debug wheels as artifacts in PR

* chore: do not run workflows in forks

* chore: housekeep requirements

* chore: use Nightly-ROCm-6.3 for CI

* chore: use Nightly-ROCm-6.4 for CI

* Update ROCm toolkit version to 7.0

* chore: restore previous rocm-ci.yml for test

* fix: cleanup PYTHONPATH

* chore: remove previous rocm-ci.yml

* ci fix

* chore: remove previous rocm-ci.yml

* chore: enable parallel example run

---------

Co-authored-by: LeiWang1999 <leiwang1999@outlook.com>
Co-authored-by: alex_xiao <xinyuxiao2024@gmail.com>
2025-10-15 22:12:41 +08:00
..

Dequantization GEMM

An example of implementing a dequantization GEMM:

@T.prim_func
def dequant_matmul(
    A: T.Tensor(A_shape, in_dtype),
    B: T.Tensor(B_shape, storage_dtype),
    Ct: T.Tensor((N, M), out_dtype),
):
    with T.Kernel(T.ceildiv(N, block_N), T.ceildiv(M, block_M), threads=threads) as (bx, by):
        A_shared = T.alloc_shared(A_shared_shape, in_dtype)
        B_shared = T.alloc_shared(B_shared_shape, storage_dtype)
        B_local = T.alloc_fragment(B_shared_shape, storage_dtype)
        B_dequantize_local = T.alloc_fragment(B_dequantize_shared_shape, in_dtype)
        Ct_local = T.alloc_fragment((block_N, block_M), accum_dtype)

        T.clear(Ct_local)
        for k in T.Pipelined(
            T.ceildiv(K, block_K), 
            num_stages=num_stages
        ):
            T.copy(A[by * block_M, k * block_K], A_shared)
            T.copy(B[bx * block_N, k * block_K // num_elems_per_byte], B_shared)
            T.copy(B_shared, B_local)
            for i, j in T.Parallel(block_N, block_K):
                B_dequantize_local[i, j] = _tir_packed_to_unsigned_convert("int", 8)(
                    num_bits,
                    B_local[i, j // 2],
                    j % 2,
                    dtype=in_dtype,
                )
            T.gemm(B_dequantize_local, A_shared, Ct_local, transpose_B=True)
        T.copy(Ct_local, Ct[bx * block_N, by * block_M])

Notes: Dequantize GEMM with magic layout transformations to get optimal performance can be found at project BitBLAS, example kernels can be found at testing/python/kernel/test_tilelang_dequantize_gemm.py, detailed explanation and examples is coming soon.