[Kernel] [Helion] [4/N] Add silu_mul_fp8 Helion kernel (#33373)
Signed-off-by: Yanan Cao <gmagogsfm@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Helion integration for vLLM."""
|
||||
|
||||
import vllm.kernels.helion.ops # noqa: F401 Auto-register all Helion ops
|
||||
from vllm.kernels.helion.config_manager import (
|
||||
ConfigManager,
|
||||
ConfigSet,
|
||||
|
||||
@@ -104,9 +104,6 @@ class ConfigSet:
|
||||
result[platform] = {}
|
||||
|
||||
for config_key, config in config_keys_dict.items():
|
||||
# Convert helion.Config to dict using to_json() + json.loads()
|
||||
import json
|
||||
|
||||
result[platform][config_key] = json.loads(config.to_json())
|
||||
|
||||
return result
|
||||
|
||||
@@ -0,0 +1,550 @@
|
||||
{
|
||||
"nvidia_h200": {
|
||||
"intermediate_2048_batchsize_256": {
|
||||
"block_sizes": [
|
||||
64,
|
||||
128
|
||||
],
|
||||
"loop_orders": [
|
||||
[
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
"flatten_loops": [
|
||||
true
|
||||
],
|
||||
"l2_groupings": [
|
||||
2
|
||||
],
|
||||
"range_unroll_factors": [
|
||||
0
|
||||
],
|
||||
"range_num_stages": [
|
||||
0
|
||||
],
|
||||
"range_multi_buffers": [
|
||||
null
|
||||
],
|
||||
"range_flattens": [
|
||||
null
|
||||
],
|
||||
"load_eviction_policies": [
|
||||
"",
|
||||
"",
|
||||
""
|
||||
],
|
||||
"num_warps": 32,
|
||||
"num_stages": 1,
|
||||
"indexing": [
|
||||
"pointer",
|
||||
"tensor_descriptor",
|
||||
"pointer",
|
||||
"pointer"
|
||||
],
|
||||
"pid_type": "flat",
|
||||
"range_warp_specializes": []
|
||||
},
|
||||
"intermediate_4096_batchsize_256": {
|
||||
"block_sizes": [
|
||||
16,
|
||||
64
|
||||
],
|
||||
"loop_orders": [
|
||||
[
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
"flatten_loops": [
|
||||
false
|
||||
],
|
||||
"l2_groupings": [
|
||||
1
|
||||
],
|
||||
"range_unroll_factors": [
|
||||
0
|
||||
],
|
||||
"range_num_stages": [
|
||||
0
|
||||
],
|
||||
"range_multi_buffers": [
|
||||
null
|
||||
],
|
||||
"range_flattens": [
|
||||
null
|
||||
],
|
||||
"load_eviction_policies": [
|
||||
"",
|
||||
"",
|
||||
""
|
||||
],
|
||||
"num_warps": 2,
|
||||
"num_stages": 1,
|
||||
"indexing": [
|
||||
"pointer",
|
||||
"pointer",
|
||||
"pointer",
|
||||
"pointer"
|
||||
],
|
||||
"pid_type": "flat",
|
||||
"range_warp_specializes": []
|
||||
},
|
||||
"default": {
|
||||
"block_sizes": [
|
||||
1,
|
||||
512
|
||||
],
|
||||
"loop_orders": [
|
||||
[
|
||||
1,
|
||||
0
|
||||
]
|
||||
],
|
||||
"flatten_loops": [
|
||||
false
|
||||
],
|
||||
"l2_groupings": [
|
||||
4
|
||||
],
|
||||
"range_unroll_factors": [
|
||||
0
|
||||
],
|
||||
"range_num_stages": [
|
||||
0
|
||||
],
|
||||
"range_multi_buffers": [
|
||||
null
|
||||
],
|
||||
"range_flattens": [
|
||||
null
|
||||
],
|
||||
"load_eviction_policies": [
|
||||
"",
|
||||
"first",
|
||||
""
|
||||
],
|
||||
"num_warps": 8,
|
||||
"num_stages": 2,
|
||||
"indexing": [
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"pointer"
|
||||
],
|
||||
"pid_type": "flat",
|
||||
"range_warp_specializes": []
|
||||
}
|
||||
},
|
||||
"nvidia_h100_pcie": {
|
||||
"intermediate_2048_batchsize_256": {
|
||||
"block_sizes": [
|
||||
1,
|
||||
512
|
||||
],
|
||||
"loop_orders": [
|
||||
[
|
||||
1,
|
||||
0
|
||||
]
|
||||
],
|
||||
"flatten_loops": [
|
||||
false
|
||||
],
|
||||
"l2_groupings": [
|
||||
4
|
||||
],
|
||||
"range_unroll_factors": [
|
||||
0
|
||||
],
|
||||
"range_num_stages": [
|
||||
0
|
||||
],
|
||||
"range_multi_buffers": [
|
||||
null
|
||||
],
|
||||
"range_flattens": [
|
||||
null
|
||||
],
|
||||
"load_eviction_policies": [
|
||||
"",
|
||||
"first",
|
||||
""
|
||||
],
|
||||
"num_warps": 8,
|
||||
"num_stages": 2,
|
||||
"indexing": [
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"pointer"
|
||||
],
|
||||
"pid_type": "flat",
|
||||
"range_warp_specializes": []
|
||||
},
|
||||
"intermediate_4096_batchsize_256": {
|
||||
"block_sizes": [
|
||||
256,
|
||||
128
|
||||
],
|
||||
"loop_orders": [
|
||||
[
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
"flatten_loops": [
|
||||
true
|
||||
],
|
||||
"l2_groupings": [
|
||||
1
|
||||
],
|
||||
"range_unroll_factors": [
|
||||
2
|
||||
],
|
||||
"range_num_stages": [
|
||||
3
|
||||
],
|
||||
"range_multi_buffers": [
|
||||
false
|
||||
],
|
||||
"range_flattens": [
|
||||
true
|
||||
],
|
||||
"load_eviction_policies": [
|
||||
"last",
|
||||
"last",
|
||||
""
|
||||
],
|
||||
"num_warps": 32,
|
||||
"num_stages": 3,
|
||||
"indexing": [
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"pointer"
|
||||
],
|
||||
"pid_type": "persistent_blocked",
|
||||
"range_warp_specializes": []
|
||||
},
|
||||
"default": {
|
||||
"block_sizes": [
|
||||
1,
|
||||
512
|
||||
],
|
||||
"loop_orders": [
|
||||
[
|
||||
1,
|
||||
0
|
||||
]
|
||||
],
|
||||
"flatten_loops": [
|
||||
false
|
||||
],
|
||||
"l2_groupings": [
|
||||
4
|
||||
],
|
||||
"range_unroll_factors": [
|
||||
0
|
||||
],
|
||||
"range_num_stages": [
|
||||
0
|
||||
],
|
||||
"range_multi_buffers": [
|
||||
null
|
||||
],
|
||||
"range_flattens": [
|
||||
null
|
||||
],
|
||||
"load_eviction_policies": [
|
||||
"",
|
||||
"first",
|
||||
""
|
||||
],
|
||||
"num_warps": 8,
|
||||
"num_stages": 2,
|
||||
"indexing": [
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"pointer"
|
||||
],
|
||||
"pid_type": "flat",
|
||||
"range_warp_specializes": []
|
||||
}
|
||||
},
|
||||
"nvidia_h100_sxm5": {
|
||||
"intermediate_2048_batchsize_256": {
|
||||
"block_sizes": [
|
||||
1,
|
||||
512
|
||||
],
|
||||
"loop_orders": [
|
||||
[
|
||||
1,
|
||||
0
|
||||
]
|
||||
],
|
||||
"flatten_loops": [
|
||||
false
|
||||
],
|
||||
"l2_groupings": [
|
||||
4
|
||||
],
|
||||
"range_unroll_factors": [
|
||||
0
|
||||
],
|
||||
"range_num_stages": [
|
||||
0
|
||||
],
|
||||
"range_multi_buffers": [
|
||||
null
|
||||
],
|
||||
"range_flattens": [
|
||||
null
|
||||
],
|
||||
"load_eviction_policies": [
|
||||
"",
|
||||
"first",
|
||||
""
|
||||
],
|
||||
"num_warps": 8,
|
||||
"num_stages": 2,
|
||||
"indexing": [
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"pointer"
|
||||
],
|
||||
"pid_type": "flat",
|
||||
"range_warp_specializes": []
|
||||
},
|
||||
"intermediate_4096_batchsize_256": {
|
||||
"block_sizes": [
|
||||
256,
|
||||
128
|
||||
],
|
||||
"loop_orders": [
|
||||
[
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
"flatten_loops": [
|
||||
true
|
||||
],
|
||||
"l2_groupings": [
|
||||
1
|
||||
],
|
||||
"range_unroll_factors": [
|
||||
2
|
||||
],
|
||||
"range_num_stages": [
|
||||
3
|
||||
],
|
||||
"range_multi_buffers": [
|
||||
false
|
||||
],
|
||||
"range_flattens": [
|
||||
true
|
||||
],
|
||||
"load_eviction_policies": [
|
||||
"last",
|
||||
"last",
|
||||
""
|
||||
],
|
||||
"num_warps": 32,
|
||||
"num_stages": 3,
|
||||
"indexing": [
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"pointer"
|
||||
],
|
||||
"pid_type": "persistent_blocked",
|
||||
"range_warp_specializes": []
|
||||
},
|
||||
"default": {
|
||||
"block_sizes": [
|
||||
1,
|
||||
512
|
||||
],
|
||||
"loop_orders": [
|
||||
[
|
||||
1,
|
||||
0
|
||||
]
|
||||
],
|
||||
"flatten_loops": [
|
||||
false
|
||||
],
|
||||
"l2_groupings": [
|
||||
4
|
||||
],
|
||||
"range_unroll_factors": [
|
||||
0
|
||||
],
|
||||
"range_num_stages": [
|
||||
0
|
||||
],
|
||||
"range_multi_buffers": [
|
||||
null
|
||||
],
|
||||
"range_flattens": [
|
||||
null
|
||||
],
|
||||
"load_eviction_policies": [
|
||||
"",
|
||||
"first",
|
||||
""
|
||||
],
|
||||
"num_warps": 8,
|
||||
"num_stages": 2,
|
||||
"indexing": [
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"pointer"
|
||||
],
|
||||
"pid_type": "flat",
|
||||
"range_warp_specializes": []
|
||||
}
|
||||
},
|
||||
"nvidia_h100": {
|
||||
"intermediate_2048_batchsize_256": {
|
||||
"block_sizes": [
|
||||
1,
|
||||
512
|
||||
],
|
||||
"loop_orders": [
|
||||
[
|
||||
1,
|
||||
0
|
||||
]
|
||||
],
|
||||
"flatten_loops": [
|
||||
false
|
||||
],
|
||||
"l2_groupings": [
|
||||
4
|
||||
],
|
||||
"range_unroll_factors": [
|
||||
0
|
||||
],
|
||||
"range_num_stages": [
|
||||
0
|
||||
],
|
||||
"range_multi_buffers": [
|
||||
null
|
||||
],
|
||||
"range_flattens": [
|
||||
null
|
||||
],
|
||||
"load_eviction_policies": [
|
||||
"",
|
||||
"first",
|
||||
""
|
||||
],
|
||||
"num_warps": 8,
|
||||
"num_stages": 2,
|
||||
"indexing": [
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"pointer"
|
||||
],
|
||||
"pid_type": "flat",
|
||||
"range_warp_specializes": []
|
||||
},
|
||||
"intermediate_4096_batchsize_256": {
|
||||
"block_sizes": [
|
||||
256,
|
||||
128
|
||||
],
|
||||
"loop_orders": [
|
||||
[
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
"flatten_loops": [
|
||||
true
|
||||
],
|
||||
"l2_groupings": [
|
||||
1
|
||||
],
|
||||
"range_unroll_factors": [
|
||||
2
|
||||
],
|
||||
"range_num_stages": [
|
||||
3
|
||||
],
|
||||
"range_multi_buffers": [
|
||||
false
|
||||
],
|
||||
"range_flattens": [
|
||||
true
|
||||
],
|
||||
"load_eviction_policies": [
|
||||
"last",
|
||||
"last",
|
||||
""
|
||||
],
|
||||
"num_warps": 32,
|
||||
"num_stages": 3,
|
||||
"indexing": [
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"pointer"
|
||||
],
|
||||
"pid_type": "persistent_blocked",
|
||||
"range_warp_specializes": []
|
||||
},
|
||||
"default": {
|
||||
"block_sizes": [
|
||||
1,
|
||||
512
|
||||
],
|
||||
"loop_orders": [
|
||||
[
|
||||
1,
|
||||
0
|
||||
]
|
||||
],
|
||||
"flatten_loops": [
|
||||
false
|
||||
],
|
||||
"l2_groupings": [
|
||||
4
|
||||
],
|
||||
"range_unroll_factors": [
|
||||
0
|
||||
],
|
||||
"range_num_stages": [
|
||||
0
|
||||
],
|
||||
"range_multi_buffers": [
|
||||
null
|
||||
],
|
||||
"range_flattens": [
|
||||
null
|
||||
],
|
||||
"load_eviction_policies": [
|
||||
"",
|
||||
"first",
|
||||
""
|
||||
],
|
||||
"num_warps": 8,
|
||||
"num_stages": 2,
|
||||
"indexing": [
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"tensor_descriptor",
|
||||
"pointer"
|
||||
],
|
||||
"pid_type": "flat",
|
||||
"range_warp_specializes": []
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Auto-import all Helion op modules to trigger kernel registration."""
|
||||
|
||||
import importlib
|
||||
import pkgutil
|
||||
|
||||
# Automatically import all submodules so that @register_kernel
|
||||
# decorators execute and register ops with torch.ops.vllm_helion.
|
||||
for _module_info in pkgutil.iter_modules(__path__):
|
||||
importlib.import_module(f"{__name__}.{_module_info.name}")
|
||||
@@ -0,0 +1,100 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from typing import Any
|
||||
|
||||
import torch
|
||||
|
||||
from vllm.logger import init_logger
|
||||
from vllm.utils.import_utils import has_helion
|
||||
|
||||
if not has_helion():
|
||||
raise ImportError(
|
||||
"silu_mul_fp8 Helion kernel requires helion to be installed. "
|
||||
"Install it with: pip install helion"
|
||||
)
|
||||
|
||||
import helion.language as hl
|
||||
|
||||
from vllm.kernels.helion.register import register_kernel
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
@register_kernel # type: ignore[misc]
|
||||
def silu_mul_fp8(input: torch.Tensor, scale: torch.Tensor) -> torch.Tensor:
|
||||
original_shape = input.shape
|
||||
two_d = hl.specialize(original_shape[-1])
|
||||
d = two_d // 2
|
||||
output_shape = original_shape[:-1] + (d,)
|
||||
|
||||
input_2d = input.view(-1, original_shape[-1])
|
||||
m = input_2d.shape[0]
|
||||
|
||||
# TODO(gmagogsfm): Support for more float8 subtypes (e4m3fnuz, e5m2) coming
|
||||
out = torch.empty((m, d), device=input.device, dtype=torch.float8_e4m3fn)
|
||||
|
||||
input_part_a = input_2d[:, :d]
|
||||
input_part_b = input_2d[:, d:]
|
||||
|
||||
assert scale.numel() == 1, "Scale must be a scalar Tensor"
|
||||
|
||||
for tile_m, tile_n in hl.tile([m, d]):
|
||||
a_vals = input_part_a[tile_m, tile_n]
|
||||
silu_result = torch.nn.functional.silu(a_vals)
|
||||
b_vals = input_part_b[tile_m, tile_n]
|
||||
result = silu_result * b_vals
|
||||
result_f32 = result.to(torch.float32)
|
||||
scale_val = hl.load(scale, [0])
|
||||
inv_scale = 1.0 / scale_val
|
||||
result_scaled = result_f32 * inv_scale
|
||||
out[tile_m, tile_n] = result_scaled.to(out.dtype)
|
||||
|
||||
return out.view(output_shape)
|
||||
|
||||
|
||||
@silu_mul_fp8.register_config_picker # type: ignore[misc]
|
||||
def pick_silu_mul_fp8_config(
|
||||
args: tuple[Any, ...], config_keys: list[str]
|
||||
) -> str | None:
|
||||
if not config_keys:
|
||||
return None
|
||||
|
||||
input_tensor, scale = args
|
||||
intermediate_size = input_tensor.shape[-1] // 2
|
||||
|
||||
# TODO(gmagosfm): Rerun autotuning to capture config for
|
||||
# other batch sizes.
|
||||
target_key = f"intermediate_{intermediate_size}_batchsize_256"
|
||||
if target_key in config_keys:
|
||||
return target_key
|
||||
|
||||
intermediate_sizes = []
|
||||
for key in config_keys:
|
||||
if key.startswith("intermediate_") and "_batchsize_256" in key:
|
||||
try:
|
||||
size_str = key.split("_")[1]
|
||||
size = int(size_str)
|
||||
intermediate_sizes.append((abs(size - intermediate_size), key))
|
||||
except (ValueError, IndexError):
|
||||
continue
|
||||
|
||||
if intermediate_sizes:
|
||||
_, best_key = min(intermediate_sizes)
|
||||
logger.debug(
|
||||
"No exact config for intermediate_size=%d, using closest match: %s",
|
||||
intermediate_size,
|
||||
best_key,
|
||||
)
|
||||
return best_key
|
||||
if "default" in config_keys:
|
||||
return "default"
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def silu_mul_fp8_baseline(input: torch.Tensor, scale: torch.Tensor) -> torch.Tensor:
|
||||
output_shape = input.shape[:-1] + (input.shape[-1] // 2,)
|
||||
out = torch.empty(output_shape, dtype=torch.float8_e4m3fn, device=input.device)
|
||||
torch.ops._C.silu_and_mul_quant(out, input, scale)
|
||||
return out
|
||||
Reference in New Issue
Block a user