[AMD] rocm 7.2 image release, PR test, Nightly Test (#17799)
Co-authored-by: Alan Kao <akao@amd.com> Co-authored-by: bingxche <Bingxu.Chen@amd.com> Co-authored-by: Michael <13900043+michaelzhang-ai@users.noreply.github.com>
This commit is contained in:
co-authored by
Alan Kao
bingxche
Michael
parent
93ede0db19
commit
20554a0a4f
@@ -64,6 +64,7 @@ if _is_cuda:
|
||||
enable_sgl_per_token_group_quant_8bit = False
|
||||
|
||||
if _is_hip:
|
||||
_has_vllm = False
|
||||
if _use_aiter:
|
||||
try:
|
||||
from aiter import ( # v0.1.3
|
||||
@@ -76,8 +77,11 @@ if _is_hip:
|
||||
else:
|
||||
try:
|
||||
import vllm._C # noqa: F401
|
||||
|
||||
_has_vllm = True
|
||||
except ImportError:
|
||||
raise ImportError("vllm is required when SGLANG_USE_AITER is set to False")
|
||||
# Fallback: vllm not available, will use native PyTorch implementation
|
||||
_has_vllm = False
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -1537,6 +1541,37 @@ Raises:
|
||||
"""
|
||||
if _is_hip:
|
||||
|
||||
def _native_dynamic_per_token_quant_fp8(output, input, scale):
|
||||
"""Native PyTorch fallback for dynamic per-token FP8 quantization when vLLM is unavailable."""
|
||||
M, N = input.shape
|
||||
eps = 1e-12
|
||||
# Compute per-token scale
|
||||
absmax = input.abs().max(dim=1, keepdim=True).values
|
||||
absmax = torch.clamp(absmax, min=eps)
|
||||
scale_val = absmax / fp8_max
|
||||
scale.copy_(scale_val)
|
||||
# Quantize
|
||||
output_data = torch.clamp(input / scale_val, fp8_min, fp8_max).to(fp8_dtype)
|
||||
output.copy_(output_data)
|
||||
|
||||
def _native_dynamic_per_tensor_quant_fp8(output, input, scale):
|
||||
"""Native PyTorch fallback for dynamic per-tensor FP8 quantization when vLLM is unavailable."""
|
||||
eps = 1e-12
|
||||
absmax = input.abs().max()
|
||||
absmax = torch.clamp(absmax, min=eps)
|
||||
scale_val = absmax / fp8_max
|
||||
# Use copy_ instead of fill_ with .item() to avoid CPU-GPU sync
|
||||
scale.view(-1).copy_(scale_val.view(-1))
|
||||
# Quantize
|
||||
output_data = torch.clamp(input / scale_val, fp8_min, fp8_max).to(fp8_dtype)
|
||||
output.copy_(output_data)
|
||||
|
||||
def _native_static_quant_fp8(output, input, scale):
|
||||
"""Native PyTorch fallback for static FP8 quantization when vLLM is unavailable."""
|
||||
# Use tensor directly instead of .item() to avoid CPU-GPU sync
|
||||
output_data = torch.clamp(input / scale, fp8_min, fp8_max).to(fp8_dtype)
|
||||
output.copy_(output_data)
|
||||
|
||||
def scaled_fp8_quant(
|
||||
input: torch.Tensor,
|
||||
scale: Optional[torch.Tensor] = None,
|
||||
@@ -1557,16 +1592,20 @@ if _is_hip:
|
||||
)
|
||||
if _use_aiter:
|
||||
dynamic_per_token_scaled_quant(output, input, scale)
|
||||
else:
|
||||
elif _has_vllm:
|
||||
torch.ops._C.dynamic_per_token_scaled_fp8_quant(
|
||||
output, input.contiguous(), scale, None
|
||||
)
|
||||
else:
|
||||
_native_dynamic_per_token_quant_fp8(output, input, scale)
|
||||
else:
|
||||
scale = torch.zeros(1, device=input.device, dtype=torch.float32)
|
||||
if _use_aiter:
|
||||
dynamic_per_tensor_quant(output, input, scale)
|
||||
else:
|
||||
elif _has_vllm:
|
||||
torch.ops._C.dynamic_scaled_fp8_quant(output, input, scale)
|
||||
else:
|
||||
_native_dynamic_per_tensor_quant_fp8(output, input, scale)
|
||||
else:
|
||||
# Static scaling
|
||||
assert (
|
||||
@@ -1574,8 +1613,10 @@ if _is_hip:
|
||||
), f"Expected scalar scale, got numel={scale.numel()}"
|
||||
if _use_aiter:
|
||||
static_per_tensor_quant(output, input, scale)
|
||||
else:
|
||||
elif _has_vllm:
|
||||
torch.ops._C.static_scaled_fp8_quant(output, input, scale)
|
||||
else:
|
||||
_native_static_quant_fp8(output, input, scale)
|
||||
|
||||
return output, scale
|
||||
|
||||
|
||||
@@ -224,7 +224,10 @@ class UnquantizedFusedMoEMethod(FusedMoEMethodBase, MultiPlatformOp):
|
||||
set_weight_attrs(w2_weight_bias, extra_weight_attrs)
|
||||
|
||||
def process_weights_after_loading(self, layer: torch.nn.Module) -> None:
|
||||
if _use_aiter:
|
||||
# Skip aiter weight shuffle when using non-auto MoE backend (e.g., triton, triton_kernels)
|
||||
# because aiter CK kernels don't support all GEMM dimensions
|
||||
_should_use_aiter_moe = _use_aiter and get_moe_runner_backend().is_auto()
|
||||
if _should_use_aiter_moe:
|
||||
layer.w13_weight = torch.nn.Parameter(
|
||||
shuffle_weight(layer.w13_weight.data, (16, 16)),
|
||||
requires_grad=False,
|
||||
@@ -383,7 +386,10 @@ class UnquantizedFusedMoEMethod(FusedMoEMethodBase, MultiPlatformOp):
|
||||
)[0]
|
||||
return StandardCombineInput(hidden_states=output)
|
||||
else:
|
||||
if _use_aiter:
|
||||
# Skip aiter fused_moe when using non-auto MoE backend (e.g., triton, triton_kernels)
|
||||
# because aiter CK kernels don't support all GEMM dimensions
|
||||
_should_use_aiter_moe = _use_aiter and get_moe_runner_backend().is_auto()
|
||||
if _should_use_aiter_moe:
|
||||
assert not moe_runner_config.no_combine, "unsupported"
|
||||
topk_weights, topk_ids, _ = topk_output
|
||||
if moe_runner_config.apply_router_weight_on_input:
|
||||
|
||||
Reference in New Issue
Block a user