__init__.py 2.57 KB
Newer Older
1
2
import ctypes
import os
3
import platform
4

5
6
import torch

7
8
9
10
11
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)
12

13
14
from sgl_kernel import common_ops
from sgl_kernel.allreduce import *
15
16
17
18
from sgl_kernel.attention import (
    cutlass_mla_decode,
    cutlass_mla_get_workspace_size,
    lightning_attention_decode,
Yineng Zhang's avatar
Yineng Zhang committed
19
    merge_state,
20
    merge_state_v2,
21
)
22
from sgl_kernel.cutlass_moe import cutlass_w4a8_moe_mm, get_cutlass_w4a8_moe_mm_data
23
from sgl_kernel.elementwise import (
24
    FusedSetKVBufferArg,
25
26
27
28
29
30
31
32
33
    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,
)
34
from sgl_kernel.fused_moe import fused_marlin_moe
35
36
37
38

if torch.version.hip is not None:
    from sgl_kernel.elementwise import gelu_quick

39
from sgl_kernel.gemm import (
40
    awq_dequantize,
41
    bmm_fp8,
Trevor Morris's avatar
Trevor Morris committed
42
    cutlass_scaled_fp4_mm,
43
    dsv3_fused_a_gemm,
44
    dsv3_router_gemm,
45
46
47
    fp8_blockwise_scaled_mm,
    fp8_scaled_mm,
    int8_scaled_mm,
HandH1998's avatar
HandH1998 committed
48
49
    qserve_w4a8_per_chn_gemm,
    qserve_w4a8_per_group_gemm,
50
    scaled_fp4_experts_quant,
Trevor Morris's avatar
Trevor Morris committed
51
    scaled_fp4_quant,
52
    sgl_per_tensor_quant_fp8,
53
    sgl_per_token_group_quant_fp8,
54
    sgl_per_token_group_quant_int8,
55
    sgl_per_token_quant_fp8,
56
    shuffle_rows,
57
)
58
from sgl_kernel.grammar import apply_token_bitmask_inplace_cuda
59
60
61
62
63
64
from sgl_kernel.kvcacheio import (
    transfer_kv_all_layer,
    transfer_kv_all_layer_mla,
    transfer_kv_per_layer,
    transfer_kv_per_layer_mla,
)
65
66
67
68
69
from sgl_kernel.marlin import (
    awq_marlin_moe_repack,
    awq_marlin_repack,
    gptq_marlin_repack,
)
70
from sgl_kernel.moe import (
71
    apply_shuffle_mul_sum,
72
    cutlass_fp4_group_mm,
73
    ep_moe_post_reorder,
74
    ep_moe_pre_reorder,
75
    ep_moe_silu_and_mul,
76
77
78
    fp8_blockwise_scaled_grouped_mm,
    moe_align_block_size,
    moe_fused_gate,
79
    prepare_moe_input,
80
81
    topk_softmax,
)
82
from sgl_kernel.sampling import (
83
84
85
86
87
88
    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,
)
89
from sgl_kernel.spatial import create_greenctx_stream_by_value, get_sm_available
90
from sgl_kernel.speculative import (
91
    build_tree_kernel_efficient,
92
    segment_packbits,
93
    tree_speculative_sampling_target_only,
94
    verify_tree_greedy,
95
)
96
from sgl_kernel.top_k import fast_topk
Lianmin Zheng's avatar
Lianmin Zheng committed
97
from sgl_kernel.version import __version__
98
99

build_tree_kernel = (
100
    None  # TODO(ying): remove this after updating the sglang python code.
101
)