Skip to content

Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.

5.4 KB
Raw Blame
py::class_<TritonKernel, std::shared_ptr<TritonKernel>>(m, "TritonKernel")
    .def_readwrite("grid_y", &TritonKernel::grid_y).def
(
    py::init<py::bytes, std::string, int, int>(),
    py::arg("cubin"),
    py::arg("name"),
    py::arg("num_warps"),
    py::arg("shared_bytes")
);

py::class_<BC_Attention, std::shared_ptr<BC_Attention>>(m, "BC_Attention").def
(
    py::init<
        int,
        int,
        int,
        int,
        int,
        int,
        std::shared_ptr<BC_LinearEXL3>,
        std::shared_ptr<BC_LinearEXL3>,
        std::shared_ptr<BC_LinearEXL3>,
        c10::optional<at::Tensor>,
        c10::optional<at::Tensor>,
        c10::optional<at::Tensor>,
        int,
        bool,
        bool,
        std::shared_ptr<BC_LinearEXL3>,
        bool,
        int,
        bool,
        std::shared_ptr<BC_LinearEXL3>,
        c10::optional<at::Tensor>,
        c10::optional<at::Tensor>,
        c10::optional<at::Tensor>,
        c10::optional<at::Tensor>,
        int,
        bool,
        bool,
        c10::optional<at::Tensor>,
        c10::optional<at::Tensor>,
        c10::optional<at::Tensor>,
        c10::optional<at::Tensor>,
        int,
        bool,
        bool,
        c10::optional<at::Tensor>,
        c10::optional<at::Tensor>,
        float,
        float,
        bool,
        c10::optional<at::Tensor>,
        float,
        float,
        float,
        c10::optional<at::Tensor>,
        int,
        float,
        float,
        int,
        int,
        bool,
        at::Tensor,
        at::Tensor,
        c10::optional<at::Tensor>,
        c10::optional<at::Tensor>,
        at::Tensor,
        at::Tensor,
        c10::optional<at::Tensor>
    >(),
    py::arg("num_q_heads"),
    py::arg("num_kv_heads"),
    py::arg("head_dim"),
    py::arg("hidden_size"),
    py::arg("hidden_size_padded"),
    py::arg("page_size"),
    py::arg("q_proj"),
    py::arg("k_proj"),
    py::arg("v_proj"),
    py::arg("kv_ptrs_trellis"),
    py::arg("kv_ptrs_suh"),
    py::arg("kv_ptrs_svh"),
    py::arg("kv_K"),
    py::arg("kv_mcg"),
    py::arg("kv_mul1"),
    py::arg("o_proj"),
    py::arg("use_k_as_v"),
    py::arg("gate_mode"),
    py::arg("gate_softplus"),
    py::arg("g_proj"),
    py::arg("g_weight"),
    py::arg("qg_ptrs_trellis"),
    py::arg("qg_ptrs_suh"),
    py::arg("qg_ptrs_svh"),
    py::arg("qg_K"),
    py::arg("qg_mcg"),
    py::arg("qg_mul1"),
    py::arg("qkv_ptrs_trellis"),
    py::arg("qkv_ptrs_suh"),
    py::arg("qkv_ptrs_svh"),
    py::arg("qkv_meta"),
    py::arg("qkv_K"),
    py::arg("qkv_mcg"),
    py::arg("qkv_mul1"),
    py::arg("q_norm"),
    py::arg("k_norm"),
    py::arg("norm_eps"),
    py::arg("norm_constant_bias"),
    py::arg("v_norm"),
    py::arg("v_norm_w"),
    py::arg("v_norm_eps"),
    py::arg("v_norm_constant_bias"),
    py::arg("v_norm_constant_scale"),
    py::arg("inv_freq"),
    py::arg("rope_style"),
    py::arg("attn_factor"),
    py::arg("l4_scaling_beta"),
    py::arg("l4_scaling_original"),
    py::arg("rotate_dims"),
    py::arg("quant_cache"),
    py::arg("cache_k"),
    py::arg("cache_v"),
    py::arg("cache_k_scales"),
    py::arg("cache_v_scales"),
    py::arg("xh"),
    py::arg("h32"),
    py::arg("sinks")
)
.def("needs_configure", &BC_Attention::needs_configure)
.def("set_qsa", &BC_Attention::set_qsa,
    py::arg("qk_proj"),
    py::arg("q_norm_w"),
    py::arg("k_norm_w"),
    py::arg("norm_eps"),
    py::arg("n_heads"),
    py::arg("head_dim"),
    py::arg("topk"),
    py::arg("compress_ratio"),
    py::arg("raw_plane"),
    py::arg("pool_plane")
)
.def("configure_slot", &BC_Attention::configure_slot,
    py::arg("bsz"),
    py::arg("q_len"),
    py::arg("regime"),
    py::arg("q"),
    py::arg("kv"),
    py::arg("o"),
    py::arg("partial_o"),
    py::arg("partial_ml"),
    py::arg("gate_a"),
    py::arg("gate_b"),
    py::arg("k_split"),
    py::arg("k_combine"),
    py::arg("k_update"),
    py::arg("block_n"),
    py::arg("splits_cap"),
    py::arg("programs"),
    py::arg("xp"),
    py::arg("yp")
)
.def("set_kvwin", &BC_Attention::set_kvwin,
    py::arg("ov_k"),
    py::arg("ov_v"),
    py::arg("sinks"),
    py::arg("window"),
    py::arg("cyclic_rows"),
    py::arg("ring_rows")
)
.def("configure_slot_kvwin", &BC_Attention::configure_slot_kvwin,
    py::arg("bsz"),
    py::arg("q_len"),
    py::arg("regime"),
    py::arg("pool_len"),
    py::arg("k_ovw"),
    py::arg("k_ring"),
    py::arg("ovw_gy")
)
.def("configure_slot_qsa", &BC_Attention::configure_slot_qsa,
    py::arg("bsz"),
    py::arg("q_len"),
    py::arg("regime"),
    py::arg("qk"),
    py::arg("q"),
    py::arg("kraw"),
    py::arg("k_stage"),
    py::arg("k_raw_append"),
    py::arg("k_pool_update"),
    py::arg("rotate_dims"),
    py::arg("wts") = c10::nullopt,
    py::arg("scores") = c10::nullopt,
    py::arg("pool_idx") = c10::nullopt,
    py::arg("indices") = c10::nullopt,
    py::arg("k_fewq") = nullptr,
    py::arg("k_expand") = nullptr,
    py::arg("k_split") = nullptr,
    py::arg("k_combine") = nullptr,
    py::arg("fewq_gy") = 0,
    py::arg("qsa_splits") = 0,
    py::arg("qsa_split_len") = 0,
    py::arg("qsa_programs") = 0
)
.def("run", &BC_Attention::run,
    py::arg("bsz"),
    py::arg("q_len"),
    py::arg("x"),
    py::arg("y"),
    py::arg("cache_seqlens"),
    py::arg("block_table"),
    py::arg("position"),
    py::arg("positions"),
    py::arg("position_ids"),
    py::arg("inv_freq_override"),
    py::arg("regime"),
    py::arg("t_total"),
    py::arg("kvwin_slots") = c10::nullopt
);