2025-02-07 19:32:45 +08:00
|
|
|
import ctypes
|
|
|
|
|
import os
|
2025-04-30 00:06:16 +02:00
|
|
|
import platform
|
2025-02-07 19:32:45 +08:00
|
|
|
|
2025-03-02 15:19:06 -08:00
|
|
|
import torch
|
|
|
|
|
|
2025-04-30 00:06:16 +02:00
|
|
|
SYSTEM_ARCH = platform.machine()
|
|
|
|
|
|
|
|
|
|
cuda_path = f"/usr/local/cuda/targets/{SYSTEM_ARCH}-linux/lib/libcudart.so.12"
|
|
|
|
|
if os.path.exists(cuda_path):
|
|
|
|
|
ctypes.CDLL(cuda_path, mode=ctypes.RTLD_GLOBAL)
|
2025-02-07 19:32:45 +08:00
|
|
|
|
2025-03-08 22:54:51 -08:00
|
|
|
from sgl_kernel import common_ops
|
|
|
|
|
from sgl_kernel.allreduce import *
|
2025-04-11 22:16:51 -07:00
|
|
|
from sgl_kernel.attention import (
|
|
|
|
|
cutlass_mla_decode,
|
|
|
|
|
cutlass_mla_get_workspace_size,
|
|
|
|
|
lightning_attention_decode,
|
2025-04-12 21:14:04 -07:00
|
|
|
merge_state,
|
2025-04-15 12:28:23 +08:00
|
|
|
merge_state_v2,
|
2025-04-11 22:16:51 -07:00
|
|
|
)
|
2025-03-08 22:54:51 -08:00
|
|
|
from sgl_kernel.elementwise import (
|
2025-03-03 06:36:40 -08:00
|
|
|
apply_rope_with_cos_sin_cache_inplace,
|
|
|
|
|
fused_add_rmsnorm,
|
|
|
|
|
gelu_and_mul,
|
|
|
|
|
gelu_tanh_and_mul,
|
|
|
|
|
gemma_fused_add_rmsnorm,
|
|
|
|
|
gemma_rmsnorm,
|
|
|
|
|
rmsnorm,
|
|
|
|
|
silu_and_mul,
|
|
|
|
|
)
|
2025-03-08 22:54:51 -08:00
|
|
|
from sgl_kernel.gemm import (
|
2025-03-12 00:10:02 -07:00
|
|
|
awq_dequantize,
|
2025-03-03 06:36:40 -08:00
|
|
|
bmm_fp8,
|
2025-03-24 19:50:23 -07:00
|
|
|
cutlass_scaled_fp4_mm,
|
2025-06-29 17:52:24 +08:00
|
|
|
dsv3_fused_a_gemm,
|
2025-06-29 23:31:55 -07:00
|
|
|
dsv3_router_gemm,
|
2025-03-03 06:36:40 -08:00
|
|
|
fp8_blockwise_scaled_mm,
|
|
|
|
|
fp8_scaled_mm,
|
|
|
|
|
int8_scaled_mm,
|
2025-05-22 10:48:59 +08:00
|
|
|
qserve_w4a8_per_chn_gemm,
|
|
|
|
|
qserve_w4a8_per_group_gemm,
|
2025-06-02 13:48:03 -07:00
|
|
|
scaled_fp4_experts_quant,
|
2025-03-24 19:50:23 -07:00
|
|
|
scaled_fp4_quant,
|
2025-03-07 10:05:43 +08:00
|
|
|
sgl_per_tensor_quant_fp8,
|
2025-03-03 06:36:40 -08:00
|
|
|
sgl_per_token_group_quant_fp8,
|
2025-03-23 23:44:17 -07:00
|
|
|
sgl_per_token_group_quant_int8,
|
2025-03-06 20:53:05 -08:00
|
|
|
sgl_per_token_quant_fp8,
|
2025-06-02 13:48:03 -07:00
|
|
|
shuffle_rows,
|
2025-03-03 06:36:40 -08:00
|
|
|
)
|
2025-04-23 01:18:30 -07:00
|
|
|
from sgl_kernel.grammar import apply_token_bitmask_inplace_cuda
|
2025-06-23 11:58:59 -07:00
|
|
|
from sgl_kernel.kvcacheio import (
|
|
|
|
|
transfer_kv_all_layer,
|
|
|
|
|
transfer_kv_all_layer_mla,
|
|
|
|
|
transfer_kv_per_layer,
|
|
|
|
|
transfer_kv_per_layer_mla,
|
|
|
|
|
)
|
2025-04-22 22:28:20 -07:00
|
|
|
from sgl_kernel.moe import (
|
2025-06-07 15:24:39 -07:00
|
|
|
apply_shuffle_mul_sum,
|
2025-06-02 13:48:03 -07:00
|
|
|
cutlass_fp4_group_mm,
|
2025-06-05 15:33:47 +08:00
|
|
|
ep_moe_post_reorder,
|
2025-06-02 11:49:01 +08:00
|
|
|
ep_moe_pre_reorder,
|
2025-06-12 11:43:08 +08:00
|
|
|
ep_moe_silu_and_mul,
|
2025-04-22 22:28:20 -07:00
|
|
|
fp8_blockwise_scaled_grouped_mm,
|
|
|
|
|
moe_align_block_size,
|
|
|
|
|
moe_fused_gate,
|
2025-05-16 13:14:07 -07:00
|
|
|
prepare_moe_input,
|
2025-04-22 22:28:20 -07:00
|
|
|
topk_softmax,
|
|
|
|
|
)
|
2025-03-08 22:54:51 -08:00
|
|
|
from sgl_kernel.sampling import (
|
2025-03-03 06:36:40 -08:00
|
|
|
min_p_sampling_from_probs,
|
|
|
|
|
top_k_renorm_prob,
|
|
|
|
|
top_k_top_p_sampling_from_probs,
|
|
|
|
|
top_p_renorm_prob,
|
|
|
|
|
top_p_sampling_from_probs,
|
|
|
|
|
)
|
2025-03-08 22:54:51 -08:00
|
|
|
from sgl_kernel.speculative import (
|
2025-03-03 06:36:40 -08:00
|
|
|
build_tree_kernel_efficient,
|
2025-03-16 00:58:26 -07:00
|
|
|
segment_packbits,
|
2025-03-03 06:36:40 -08:00
|
|
|
tree_speculative_sampling_target_only,
|
2025-03-16 00:58:26 -07:00
|
|
|
verify_tree_greedy,
|
2025-03-03 06:36:40 -08:00
|
|
|
)
|
2025-06-16 03:28:30 -07:00
|
|
|
from sgl_kernel.top_k import fast_topk
|
2025-03-03 03:20:23 -08:00
|
|
|
from sgl_kernel.version import __version__
|
2025-03-16 00:58:26 -07:00
|
|
|
|
|
|
|
|
build_tree_kernel = (
|
2025-05-12 12:53:26 -07:00
|
|
|
None # TODO(ying): remove this after updating the sglang python code.
|
2025-03-16 00:58:26 -07:00
|
|
|
)
|