[AMD] Support ds3.2 on gfx942 platform (#17504)
Co-authored-by: Hubert Lu <55214931+hubertlu-tw@users.noreply.github.com>
This commit is contained in:
+23
-3
@@ -69,6 +69,10 @@ ARG TILELANG_REPO="https://github.com/HaiShaw/tilelang.git"
|
|||||||
ARG TILELANG_BRANCH="dsv32-mi35x"
|
ARG TILELANG_BRANCH="dsv32-mi35x"
|
||||||
ARG TILELANG_COMMIT="ae938cf885743f165a19656d1122ad42bb0e30b8"
|
ARG TILELANG_COMMIT="ae938cf885743f165a19656d1122ad42bb0e30b8"
|
||||||
|
|
||||||
|
ARG TILELANG_GFX942_REPO="https://github.com/tile-ai/tilelang.git"
|
||||||
|
ARG TILELANG_GFX942_BRANCH="main"
|
||||||
|
ARG TILELANG_GFX942_COMMIT="2d8d3676eda18bd3d8e6fa783399ff96d3cd4ded"
|
||||||
|
|
||||||
ARG FHT_REPO="https://github.com/jeffdaily/fast-hadamard-transform.git"
|
ARG FHT_REPO="https://github.com/jeffdaily/fast-hadamard-transform.git"
|
||||||
ARG FHT_BRANCH="rocm"
|
ARG FHT_BRANCH="rocm"
|
||||||
ARG FHT_COMMIT="46efb7d776d38638fc39f3c803eaee3dd7016bd1"
|
ARG FHT_COMMIT="46efb7d776d38638fc39f3c803eaee3dd7016bd1"
|
||||||
@@ -215,12 +219,13 @@ ENV LIBGL_ALWAYS_INDIRECT=1
|
|||||||
RUN echo "LC_ALL=en_US.UTF-8" >> /etc/environment
|
RUN echo "LC_ALL=en_US.UTF-8" >> /etc/environment
|
||||||
|
|
||||||
RUN /bin/bash -lc 'set -euo pipefail; \
|
RUN /bin/bash -lc 'set -euo pipefail; \
|
||||||
# Build TileLang only for gfx950
|
# Build TileLang for gfx950 and gfx942-rocm700
|
||||||
if [ "${GPU_ARCH:-}" != "gfx950" ]; then \
|
if [ "${GPU_ARCH:-}" != "gfx950" ] && [ "${GPU_ARCH:-}" != "gfx942-rocm700" ]; then \
|
||||||
echo "[TileLang] Skipping (GPU_ARCH=${GPU_ARCH:-unset})"; \
|
echo "[TileLang] Skipping (GPU_ARCH=${GPU_ARCH:-unset})"; \
|
||||||
exit 0; \
|
exit 0; \
|
||||||
fi; \
|
fi; \
|
||||||
echo "[TileLang] Building TileLang for ${GPU_ARCH}"; \
|
echo "[TileLang] Building TileLang for ${GPU_ARCH}"; \
|
||||||
|
if [ "$GPU_ARCH" = "gfx950" ]; then \
|
||||||
\
|
\
|
||||||
# System dependencies (NO llvm-dev to avoid llvm-config-16 shadowing)
|
# System dependencies (NO llvm-dev to avoid llvm-config-16 shadowing)
|
||||||
apt-get update && apt-get install -y --no-install-recommends \
|
apt-get update && apt-get install -y --no-install-recommends \
|
||||||
@@ -274,7 +279,22 @@ RUN /bin/bash -lc 'set -euo pipefail; \
|
|||||||
git checkout -f "${TILELANG_COMMIT}" && \
|
git checkout -f "${TILELANG_COMMIT}" && \
|
||||||
git submodule update --init --recursive && \
|
git submodule update --init --recursive && \
|
||||||
export CMAKE_ARGS="-DLLVM_CONFIG=${LLVM_CONFIG} ${CMAKE_ARGS:-}" && \
|
export CMAKE_ARGS="-DLLVM_CONFIG=${LLVM_CONFIG} ${CMAKE_ARGS:-}" && \
|
||||||
bash ./install_rocm.sh'
|
bash ./install_rocm.sh; \
|
||||||
|
else \
|
||||||
|
# Build GoogleTest static libs (Ubuntu package ships sources only)
|
||||||
|
apt-get install -y libgtest-dev libgmock-dev && \
|
||||||
|
cmake -S /usr/src/googletest -B /tmp/build-gtest -DBUILD_GTEST=ON -DBUILD_GMOCK=ON -DCMAKE_BUILD_TYPE=Release && \
|
||||||
|
cmake --build /tmp/build-gtest -j && \
|
||||||
|
cp -v /tmp/build-gtest/lib/*.a /usr/lib/x86_64-linux-gnu/ && \
|
||||||
|
rm -rf /tmp/build-gtest; \
|
||||||
|
# Build TileLang for gfx942-rocm700
|
||||||
|
git clone --branch "${TILELANG_GFX942_BRANCH}" "${TILELANG_GFX942_REPO}" /opt/tilelang && \
|
||||||
|
cd /opt/tilelang && \
|
||||||
|
git checkout -f "${TILELANG_GFX942_COMMIT}" && \
|
||||||
|
git submodule update --init --recursive && \
|
||||||
|
sed -i "/^[[:space:]]*\"torch/d" pyproject.toml && \
|
||||||
|
USE_ROCM=1 USE_CUDA=0 pip install -e . -v ; \
|
||||||
|
fi'
|
||||||
|
|
||||||
# -----------------------
|
# -----------------------
|
||||||
# Hadamard-transform (HIP build)
|
# Hadamard-transform (HIP build)
|
||||||
|
|||||||
@@ -4,8 +4,12 @@ import torch
|
|||||||
import triton
|
import triton
|
||||||
import triton.language as tl
|
import triton.language as tl
|
||||||
|
|
||||||
|
from sglang.srt.layers.quantization.fp8_kernel import is_fp8_fnuz
|
||||||
from sglang.srt.utils import is_hip
|
from sglang.srt.utils import is_hip
|
||||||
|
|
||||||
|
_is_hip = is_hip()
|
||||||
|
_is_fp8_fnuz = is_fp8_fnuz()
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from sglang.srt.mem_cache.memory_pool import NSATokenToKVPool
|
from sglang.srt.mem_cache.memory_pool import NSATokenToKVPool
|
||||||
|
|
||||||
@@ -349,20 +353,23 @@ def _set_k_and_s_triton(
|
|||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"index_k_scale must be 1D or 2D, got shape {index_k_scale.shape}"
|
f"index_k_scale must be 1D or 2D, got shape {index_k_scale.shape}"
|
||||||
)
|
)
|
||||||
if is_hip():
|
if _is_hip:
|
||||||
assert buf_numel_per_page == 1 * (128 + 4)
|
assert buf_numel_per_page == 1 * (128 + 4)
|
||||||
else:
|
else:
|
||||||
assert buf_numel_per_page == 64 * (128 + 4)
|
assert buf_numel_per_page == 64 * (128 + 4)
|
||||||
assert num_tokens_to_write == num_tokens_to_write_ == num_tokens_to_write__
|
assert num_tokens_to_write == num_tokens_to_write_ == num_tokens_to_write__
|
||||||
assert index_head_dim == 128
|
assert index_head_dim == 128
|
||||||
assert scale_dim == 1
|
assert scale_dim == 1
|
||||||
if is_hip():
|
if _is_hip:
|
||||||
assert page_size == 1
|
assert page_size == 1
|
||||||
else:
|
else:
|
||||||
assert page_size == 64
|
assert page_size == 64
|
||||||
|
|
||||||
assert buf.dtype == torch.uint8
|
assert buf.dtype == torch.uint8
|
||||||
assert loc.dtype == torch.int64, f"{loc.dtype=}" # can be int32
|
assert loc.dtype == torch.int64, f"{loc.dtype=}" # can be int32
|
||||||
|
if _is_fp8_fnuz:
|
||||||
|
assert index_k.dtype == torch.float8_e4m3fnuz
|
||||||
|
else:
|
||||||
assert index_k.dtype == torch.float8_e4m3fn
|
assert index_k.dtype == torch.float8_e4m3fn
|
||||||
assert index_k_scale.dtype == torch.float32
|
assert index_k_scale.dtype == torch.float32
|
||||||
|
|
||||||
@@ -371,6 +378,9 @@ def _set_k_and_s_triton(
|
|||||||
assert index_k.is_contiguous()
|
assert index_k.is_contiguous()
|
||||||
assert index_k_scale.is_contiguous()
|
assert index_k_scale.is_contiguous()
|
||||||
|
|
||||||
|
if _is_fp8_fnuz:
|
||||||
|
buf_fp8 = buf.view(torch.float8_e4m3fnuz)
|
||||||
|
else:
|
||||||
buf_fp8 = buf.view(torch.float8_e4m3fn)
|
buf_fp8 = buf.view(torch.float8_e4m3fn)
|
||||||
buf_fp32 = buf.view(torch.float32)
|
buf_fp32 = buf.view(torch.float32)
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import torch
|
|||||||
from einops import rearrange
|
from einops import rearrange
|
||||||
|
|
||||||
from sglang.srt.layers.layernorm import LayerNorm
|
from sglang.srt.layers.layernorm import LayerNorm
|
||||||
|
from sglang.srt.layers.quantization.fp8_kernel import is_fp8_fnuz
|
||||||
from sglang.srt.layers.utils import MultiPlatformOp
|
from sglang.srt.layers.utils import MultiPlatformOp
|
||||||
from sglang.srt.utils import add_prefix, ceil_align, is_cuda, is_hip, is_npu
|
from sglang.srt.utils import add_prefix, ceil_align, is_cuda, is_hip, is_npu
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ global _use_multi_stream
|
|||||||
_is_cuda = is_cuda()
|
_is_cuda = is_cuda()
|
||||||
_is_hip = is_hip()
|
_is_hip = is_hip()
|
||||||
_is_npu = is_npu()
|
_is_npu = is_npu()
|
||||||
|
_is_fp8_fnuz = is_fp8_fnuz()
|
||||||
if _is_cuda:
|
if _is_cuda:
|
||||||
try:
|
try:
|
||||||
import deep_gemm
|
import deep_gemm
|
||||||
@@ -504,7 +506,9 @@ class Indexer(MultiPlatformOp):
|
|||||||
)
|
)
|
||||||
k_fp8_list.append(k_fp8)
|
k_fp8_list.append(k_fp8)
|
||||||
k_scale_list.append(k_scale)
|
k_scale_list.append(k_scale)
|
||||||
|
if _is_fp8_fnuz:
|
||||||
|
k_fp8 = torch.cat(k_fp8_list, dim=0).view(torch.float8_e4m3fnuz)
|
||||||
|
else:
|
||||||
k_fp8 = torch.cat(k_fp8_list, dim=0).view(torch.float8_e4m3fn)
|
k_fp8 = torch.cat(k_fp8_list, dim=0).view(torch.float8_e4m3fn)
|
||||||
k_scale = torch.cat(k_scale_list, dim=0).view(torch.float32).squeeze(-1)
|
k_scale = torch.cat(k_scale_list, dim=0).view(torch.float32).squeeze(-1)
|
||||||
kv_fp8 = (k_fp8, k_scale)
|
kv_fp8 = (k_fp8, k_scale)
|
||||||
@@ -569,9 +573,9 @@ class Indexer(MultiPlatformOp):
|
|||||||
from aiter.ops.triton.fp8_mqa_logits import fp8_mqa_logits
|
from aiter.ops.triton.fp8_mqa_logits import fp8_mqa_logits
|
||||||
|
|
||||||
kv, scale = kv_fp8
|
kv, scale = kv_fp8
|
||||||
logits = fp8_mqa_logits(
|
logits_chunk = fp8_mqa_logits(
|
||||||
q_fp8[start:end],
|
q_fp8[start:end],
|
||||||
kv_fp8,
|
kv,
|
||||||
scale,
|
scale,
|
||||||
weights[start:end],
|
weights[start:end],
|
||||||
ks[start:end],
|
ks[start:end],
|
||||||
@@ -1001,11 +1005,12 @@ class Indexer(MultiPlatformOp):
|
|||||||
.view(m, ng, group)
|
.view(m, ng, group)
|
||||||
.mul_(x_s.to(torch.float32).unsqueeze(-1))
|
.mul_(x_s.to(torch.float32).unsqueeze(-1))
|
||||||
.view(m, n)
|
.view(m, n)
|
||||||
|
.to(torch.bfloat16)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
x_for_gate = x_q.to(torch.float32)
|
x_for_gate = x_q.to(torch.bfloat16)
|
||||||
else:
|
else:
|
||||||
x_for_gate = x_q.to(torch.float32)
|
x_for_gate = x_q.to(torch.bfloat16)
|
||||||
else:
|
else:
|
||||||
x_for_gate = x
|
x_for_gate = x
|
||||||
|
|
||||||
|
|||||||
@@ -4,21 +4,28 @@ import tilelang
|
|||||||
import tilelang.language as T
|
import tilelang.language as T
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
from sglang.srt.utils import is_hip
|
from sglang.srt.layers.quantization.fp8_kernel import is_fp8_fnuz
|
||||||
|
from sglang.srt.utils import is_gfx95_supported, is_hip
|
||||||
|
|
||||||
tilelang.set_log_level("WARNING")
|
tilelang.set_log_level("WARNING")
|
||||||
|
|
||||||
pass_configs = {
|
pass_configs = {
|
||||||
tilelang.PassConfigKey.TL_DISABLE_WARP_SPECIALIZED: True,
|
tilelang.PassConfigKey.TL_DISABLE_WARP_SPECIALIZED: True,
|
||||||
tilelang.PassConfigKey.TL_DISABLE_TMA_LOWER: True,
|
tilelang.PassConfigKey.TL_DISABLE_TMA_LOWER: True,
|
||||||
tilelang.PassConfigKey.TL_DISABLE_FAST_MATH: True,
|
|
||||||
}
|
}
|
||||||
|
# TL_DISABLE_FAST_MATH has deprecated in v0.1.7.post1 tilelang
|
||||||
BF16 = "bfloat16"
|
if hasattr(tilelang.PassConfigKey, "TL_DISABLE_FAST_MATH"):
|
||||||
FP8 = "float8_e4m3"
|
pass_configs[tilelang.PassConfigKey.TL_DISABLE_FAST_MATH] = True
|
||||||
FP32 = "float32"
|
elif hasattr(tilelang.PassConfigKey, "TL_ENABLE_FAST_MATH"):
|
||||||
|
pass_configs[tilelang.PassConfigKey.TL_ENABLE_FAST_MATH] = False
|
||||||
|
|
||||||
_is_hip = is_hip()
|
_is_hip = is_hip()
|
||||||
|
_is_gfx95_supported = is_gfx95_supported()
|
||||||
|
_is_fp8_fnuz = is_fp8_fnuz()
|
||||||
|
|
||||||
|
BF16 = "bfloat16"
|
||||||
|
FP8 = "float8_e4m3fnuz" if _is_fp8_fnuz else "float8_e4m3"
|
||||||
|
FP32 = "float32"
|
||||||
|
|
||||||
|
|
||||||
def fast_log2_ceil(x):
|
def fast_log2_ceil(x):
|
||||||
@@ -42,8 +49,8 @@ def act_quant_kernel(
|
|||||||
N, in_dtype=BF16, out_dtype=FP8, scale_dtype=FP32, round_scale=False
|
N, in_dtype=BF16, out_dtype=FP8, scale_dtype=FP32, round_scale=False
|
||||||
):
|
):
|
||||||
M = T.symbolic("M")
|
M = T.symbolic("M")
|
||||||
fp8_min = -448.0
|
fp8_min = -224.0 if _is_fp8_fnuz else -448.0
|
||||||
fp8_max = 448.0
|
fp8_max = 224.0 if _is_fp8_fnuz else 448.0
|
||||||
fp8_max_inv = 1 / fp8_max
|
fp8_max_inv = 1 / fp8_max
|
||||||
num_stages = 0 if round_scale else 2
|
num_stages = 0 if round_scale else 2
|
||||||
blk_m = 32
|
blk_m = 32
|
||||||
@@ -108,6 +115,9 @@ def act_quant(
|
|||||||
x.size(-1) % block_size == 0
|
x.size(-1) % block_size == 0
|
||||||
), f"Last dimension size must be divisible by block_size (block_size={block_size})"
|
), f"Last dimension size must be divisible by block_size (block_size={block_size})"
|
||||||
N = x.size(-1)
|
N = x.size(-1)
|
||||||
|
if _is_fp8_fnuz:
|
||||||
|
y = torch.empty_like(x, dtype=torch.float8_e4m3fnuz)
|
||||||
|
else:
|
||||||
y = torch.empty_like(x, dtype=torch.float8_e4m3fn)
|
y = torch.empty_like(x, dtype=torch.float8_e4m3fn)
|
||||||
s = x.new_empty(*x.size()[:-1], N // block_size, dtype=torch.float32)
|
s = x.new_empty(*x.size()[:-1], N // block_size, dtype=torch.float32)
|
||||||
kernel = act_quant_kernel(N, round_scale=scale_fmt is not None)
|
kernel = act_quant_kernel(N, round_scale=scale_fmt is not None)
|
||||||
@@ -777,9 +787,21 @@ def tilelang_sparse_fwd(
|
|||||||
topk = indices.shape[-1]
|
topk = indices.shape[-1]
|
||||||
assert topk == 2048
|
assert topk == 2048
|
||||||
if _is_hip:
|
if _is_hip:
|
||||||
|
if _is_gfx95_supported:
|
||||||
kernel = sparse_attention_fwd_kernel_v1(
|
kernel = sparse_attention_fwd_kernel_v1(
|
||||||
num_heads, d_v, tail_dim, topk, sm_scale=sm_scale, num_stages=1
|
num_heads, d_v, tail_dim, topk, sm_scale=sm_scale, num_stages=1
|
||||||
)
|
)
|
||||||
|
else: # reduce LDS usage on gfx942 target
|
||||||
|
kernel = sparse_attention_fwd_kernel_v1(
|
||||||
|
num_heads,
|
||||||
|
d_v,
|
||||||
|
tail_dim,
|
||||||
|
topk,
|
||||||
|
sm_scale=sm_scale,
|
||||||
|
block_I=32,
|
||||||
|
num_stages=1,
|
||||||
|
threads=128,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
kernel = sparse_attention_fwd_kernel_v2(
|
kernel = sparse_attention_fwd_kernel_v2(
|
||||||
num_heads, d_v, tail_dim, topk, sm_scale=sm_scale
|
num_heads, d_v, tail_dim, topk, sm_scale=sm_scale
|
||||||
|
|||||||
Reference in New Issue
Block a user