2023-12-14 12:35:58 -05:00
|
|
|
#pragma once
|
|
|
|
|
2024-06-26 17:53:04 -04:00
|
|
|
#include <optional>
|
2024-06-09 16:23:30 -04:00
|
|
|
#include <torch/library.h>
|
2023-11-23 16:31:19 -08:00
|
|
|
|
2024-05-25 01:00:52 -04:00
|
|
|
void paged_attention_v1(
|
|
|
|
torch::Tensor& out, torch::Tensor& query, torch::Tensor& key_cache,
|
2024-06-09 16:23:30 -04:00
|
|
|
torch::Tensor& value_cache, int64_t num_kv_heads, double scale,
|
|
|
|
torch::Tensor& block_tables, torch::Tensor& seq_lens, int64_t block_size,
|
|
|
|
int64_t max_seq_len, const c10::optional<torch::Tensor>& alibi_slopes,
|
2024-07-16 18:31:32 -04:00
|
|
|
const std::string& kv_cache_dtype, double k_scale, double v_scale,
|
|
|
|
const int64_t tp_rank, const int64_t blocksparse_local_blocks,
|
2024-06-09 16:23:30 -04:00
|
|
|
const int64_t blocksparse_vert_stride, const int64_t blocksparse_block_size,
|
|
|
|
const int64_t blocksparse_head_sliding_step);
|
2024-05-22 03:18:41 -04:00
|
|
|
|
2024-05-25 01:00:52 -04:00
|
|
|
void paged_attention_v2(
|
|
|
|
torch::Tensor& out, torch::Tensor& exp_sums, torch::Tensor& max_logits,
|
|
|
|
torch::Tensor& tmp_out, torch::Tensor& query, torch::Tensor& key_cache,
|
2024-06-09 16:23:30 -04:00
|
|
|
torch::Tensor& value_cache, int64_t num_kv_heads, double scale,
|
|
|
|
torch::Tensor& block_tables, torch::Tensor& seq_lens, int64_t block_size,
|
|
|
|
int64_t max_seq_len, const c10::optional<torch::Tensor>& alibi_slopes,
|
2024-07-16 18:31:32 -04:00
|
|
|
const std::string& kv_cache_dtype, double k_scale, double v_scale,
|
|
|
|
const int64_t tp_rank, const int64_t blocksparse_local_blocks,
|
2024-06-09 16:23:30 -04:00
|
|
|
const int64_t blocksparse_vert_stride, const int64_t blocksparse_block_size,
|
|
|
|
const int64_t blocksparse_head_sliding_step);
|
2024-05-22 03:18:41 -04:00
|
|
|
|
|
|
|
void rms_norm(torch::Tensor& out, torch::Tensor& input, torch::Tensor& weight,
|
2024-06-09 16:23:30 -04:00
|
|
|
double epsilon);
|
2024-05-22 03:18:41 -04:00
|
|
|
|
|
|
|
void fused_add_rms_norm(torch::Tensor& input, torch::Tensor& residual,
|
2024-06-09 16:23:30 -04:00
|
|
|
torch::Tensor& weight, double epsilon);
|
2024-05-22 03:18:41 -04:00
|
|
|
|
|
|
|
void rotary_embedding(torch::Tensor& positions, torch::Tensor& query,
|
2024-06-09 16:23:30 -04:00
|
|
|
torch::Tensor& key, int64_t head_size,
|
2024-05-22 03:18:41 -04:00
|
|
|
torch::Tensor& cos_sin_cache, bool is_neox);
|
|
|
|
|
|
|
|
void batched_rotary_embedding(torch::Tensor& positions, torch::Tensor& query,
|
2024-06-09 16:23:30 -04:00
|
|
|
torch::Tensor& key, int64_t head_size,
|
2024-05-22 03:18:41 -04:00
|
|
|
torch::Tensor& cos_sin_cache, bool is_neox,
|
2024-06-09 16:23:30 -04:00
|
|
|
int64_t rot_dim,
|
2024-05-22 03:18:41 -04:00
|
|
|
torch::Tensor& cos_sin_cache_offsets);
|
|
|
|
|
|
|
|
void silu_and_mul(torch::Tensor& out, torch::Tensor& input);
|
|
|
|
|
|
|
|
void gelu_and_mul(torch::Tensor& out, torch::Tensor& input);
|
|
|
|
|
|
|
|
void gelu_tanh_and_mul(torch::Tensor& out, torch::Tensor& input);
|
|
|
|
|
|
|
|
void gelu_new(torch::Tensor& out, torch::Tensor& input);
|
|
|
|
|
|
|
|
void gelu_fast(torch::Tensor& out, torch::Tensor& input);
|
2023-11-23 16:31:19 -08:00
|
|
|
|
2024-06-20 04:52:09 -07:00
|
|
|
void gelu_quick(torch::Tensor& out, torch::Tensor& input);
|
|
|
|
|
2024-07-17 17:30:28 -04:00
|
|
|
void advance_step(int64_t num_seqs, int64_t num_queries, int64_t block_size,
|
|
|
|
torch::Tensor& input_tokens, torch::Tensor& sampled_token_ids,
|
|
|
|
torch::Tensor& input_positions, torch::Tensor& seq_lens,
|
|
|
|
torch::Tensor& slot_mapping, torch::Tensor& block_tables);
|
|
|
|
|
2023-12-08 15:16:52 +08:00
|
|
|
#ifndef USE_ROCM
|
2024-05-22 03:18:41 -04:00
|
|
|
torch::Tensor aqlm_gemm(const torch::Tensor& input, const torch::Tensor& codes,
|
|
|
|
const torch::Tensor& codebooks,
|
|
|
|
const torch::Tensor& scales,
|
|
|
|
const torch::Tensor& codebook_partition_sizes,
|
|
|
|
const std::optional<torch::Tensor>& bias);
|
|
|
|
|
|
|
|
torch::Tensor aqlm_dequant(const torch::Tensor& codes,
|
|
|
|
const torch::Tensor& codebooks,
|
|
|
|
const torch::Tensor& codebook_partition_sizes);
|
|
|
|
|
|
|
|
torch::Tensor awq_gemm(torch::Tensor _in_feats, torch::Tensor _kernel,
|
|
|
|
torch::Tensor _scaling_factors, torch::Tensor _zeros,
|
2024-06-09 16:23:30 -04:00
|
|
|
int64_t split_k_iters);
|
2024-05-22 03:18:41 -04:00
|
|
|
|
|
|
|
torch::Tensor awq_dequantize(torch::Tensor _kernel,
|
|
|
|
torch::Tensor _scaling_factors,
|
2024-06-09 16:23:30 -04:00
|
|
|
torch::Tensor _zeros, int64_t split_k_iters,
|
|
|
|
int64_t thx, int64_t thy);
|
2024-05-22 03:18:41 -04:00
|
|
|
|
|
|
|
torch::Tensor marlin_gemm(torch::Tensor& a, torch::Tensor& b_q_weight,
|
|
|
|
torch::Tensor& b_scales, torch::Tensor& workspace,
|
|
|
|
int64_t size_m, int64_t size_n, int64_t size_k);
|
|
|
|
|
|
|
|
torch::Tensor gptq_marlin_24_gemm(torch::Tensor& a, torch::Tensor& b_q_weight,
|
|
|
|
torch::Tensor& b_meta,
|
|
|
|
torch::Tensor& b_scales,
|
|
|
|
torch::Tensor& workspace, int64_t num_bits,
|
|
|
|
int64_t size_m, int64_t size_n,
|
|
|
|
int64_t size_k);
|
|
|
|
|
|
|
|
torch::Tensor gptq_marlin_gemm(torch::Tensor& a, torch::Tensor& b_q_weight,
|
2024-07-21 19:41:42 -04:00
|
|
|
torch::Tensor& b_scales, torch::Tensor& b_zeros,
|
|
|
|
torch::Tensor& g_idx, torch::Tensor& perm,
|
|
|
|
torch::Tensor& workspace, int64_t num_bits,
|
|
|
|
int64_t size_m, int64_t size_n, int64_t size_k,
|
2024-07-27 17:52:33 -04:00
|
|
|
bool is_k_full, bool has_zp,
|
|
|
|
bool use_fp32_reduce);
|
2024-05-22 03:18:41 -04:00
|
|
|
|
|
|
|
torch::Tensor gptq_marlin_repack(torch::Tensor& b_q_weight, torch::Tensor& perm,
|
|
|
|
int64_t size_k, int64_t size_n,
|
|
|
|
int64_t num_bits);
|
|
|
|
|
2024-07-21 19:41:42 -04:00
|
|
|
torch::Tensor awq_marlin_repack(torch::Tensor& b_q_weight, int64_t size_k,
|
|
|
|
int64_t size_n, int64_t num_bits);
|
|
|
|
|
2024-07-03 13:38:00 -04:00
|
|
|
torch::Tensor fp8_marlin_gemm(torch::Tensor& a, torch::Tensor& b_q_weight,
|
|
|
|
torch::Tensor& b_scales, torch::Tensor& workspace,
|
|
|
|
int64_t num_bits, int64_t size_m, int64_t size_n,
|
|
|
|
int64_t size_k);
|
|
|
|
|
2024-06-20 14:36:10 -04:00
|
|
|
bool cutlass_scaled_mm_supports_fp8(int64_t cuda_device_capability);
|
|
|
|
|
2024-06-13 14:22:19 -04:00
|
|
|
void cutlass_scaled_mm(torch::Tensor& out, torch::Tensor const& a,
|
|
|
|
torch::Tensor const& b, torch::Tensor const& a_scales,
|
2024-06-26 11:16:00 -04:00
|
|
|
torch::Tensor const& b_scales,
|
|
|
|
c10::optional<torch::Tensor> const& bias);
|
2024-05-16 18:32:50 -04:00
|
|
|
|
2024-07-31 21:55:21 +08:00
|
|
|
torch::Tensor marlin_qqq_gemm(torch::Tensor const& a,
|
|
|
|
torch::Tensor const& b_q_weight,
|
|
|
|
torch::Tensor const& s_tok,
|
|
|
|
torch::Tensor const& s_ch,
|
|
|
|
torch::Tensor const& s_group,
|
|
|
|
torch::Tensor& workspace, int64_t size_m,
|
|
|
|
int64_t size_n, int64_t size_k);
|
2023-12-08 15:16:52 +08:00
|
|
|
#endif
|
2023-11-23 16:31:19 -08:00
|
|
|
|
2024-06-03 12:52:30 -04:00
|
|
|
void static_scaled_int8_quant(torch::Tensor& out, torch::Tensor const& input,
|
|
|
|
torch::Tensor const& scale);
|
2024-05-23 17:29:18 -04:00
|
|
|
|
2024-06-07 12:36:26 -04:00
|
|
|
void dynamic_scaled_int8_quant(torch::Tensor& out, torch::Tensor const& input,
|
|
|
|
torch::Tensor& scales);
|
|
|
|
|
2024-05-22 03:18:41 -04:00
|
|
|
void squeezellm_gemm(torch::Tensor vec, torch::Tensor mat, torch::Tensor mul,
|
|
|
|
torch::Tensor lookup_table);
|
|
|
|
|
|
|
|
torch::Tensor gptq_gemm(torch::Tensor a, torch::Tensor b_q_weight,
|
|
|
|
torch::Tensor b_gptq_qzeros,
|
|
|
|
torch::Tensor b_gptq_scales, torch::Tensor b_g_idx,
|
2024-06-09 16:23:30 -04:00
|
|
|
bool use_exllama, int64_t bit);
|
2024-05-22 03:18:41 -04:00
|
|
|
|
2024-06-09 16:23:30 -04:00
|
|
|
void gptq_shuffle(torch::Tensor q_weight, torch::Tensor q_perm, int64_t bit);
|
2024-05-22 03:18:41 -04:00
|
|
|
|
2024-07-17 21:38:35 -04:00
|
|
|
void static_scaled_fp8_quant(torch::Tensor& out, torch::Tensor const& input,
|
|
|
|
torch::Tensor const& scale);
|
2024-05-22 03:18:41 -04:00
|
|
|
|
2024-07-17 21:38:35 -04:00
|
|
|
void dynamic_scaled_fp8_quant(torch::Tensor& out, torch::Tensor const& input,
|
2024-05-22 03:18:41 -04:00
|
|
|
torch::Tensor& scale);
|
|
|
|
|
2024-07-19 21:15:26 -04:00
|
|
|
void dynamic_per_token_scaled_fp8_quant(
|
|
|
|
torch::Tensor& out, torch::Tensor const& input, torch::Tensor& scale,
|
|
|
|
c10::optional<torch::Tensor> const& scale_ub);
|
2024-07-17 21:38:35 -04:00
|
|
|
|
2024-06-09 16:23:30 -04:00
|
|
|
void moe_align_block_size(torch::Tensor topk_ids, int64_t num_experts,
|
|
|
|
int64_t block_size, torch::Tensor sorted_token_ids,
|
2024-05-22 03:18:41 -04:00
|
|
|
torch::Tensor experts_ids,
|
|
|
|
torch::Tensor num_tokens_post_pad);
|
2024-01-28 04:46:35 +08:00
|
|
|
|
|
|
|
#ifndef USE_ROCM
|
2024-06-09 16:23:30 -04:00
|
|
|
using fptr_t = int64_t;
|
2024-05-22 03:18:41 -04:00
|
|
|
fptr_t init_custom_ar(torch::Tensor& meta, torch::Tensor& rank_data,
|
|
|
|
const std::vector<std::string>& handles,
|
2024-06-09 16:23:30 -04:00
|
|
|
const std::vector<int64_t>& offsets, int64_t rank,
|
2024-05-22 03:18:41 -04:00
|
|
|
bool full_nvlink);
|
2024-06-09 16:23:30 -04:00
|
|
|
bool should_custom_ar(torch::Tensor& inp, int64_t max_size, int64_t world_size,
|
2024-01-28 04:46:35 +08:00
|
|
|
bool full_nvlink);
|
2024-05-22 03:18:41 -04:00
|
|
|
void all_reduce_reg(fptr_t _fa, torch::Tensor& inp, torch::Tensor& out);
|
|
|
|
void all_reduce_unreg(fptr_t _fa, torch::Tensor& inp, torch::Tensor& reg_buffer,
|
|
|
|
torch::Tensor& out);
|
2024-01-28 04:46:35 +08:00
|
|
|
void dispose(fptr_t _fa);
|
2024-06-09 16:23:30 -04:00
|
|
|
int64_t meta_size();
|
2024-05-22 03:18:41 -04:00
|
|
|
void register_buffer(fptr_t _fa, torch::Tensor& t,
|
|
|
|
const std::vector<std::string>& handles,
|
|
|
|
const std::vector<int64_t>& offsets);
|
2024-06-09 16:23:30 -04:00
|
|
|
std::tuple<torch::Tensor, std::vector<int64_t>> get_graph_buffer_ipc_meta(
|
2024-05-22 03:18:41 -04:00
|
|
|
fptr_t _fa);
|
|
|
|
void register_graph_buffers(fptr_t _fa, const std::vector<std::string>& handles,
|
|
|
|
const std::vector<std::vector<int64_t>>& offsets);
|
2024-01-28 04:46:35 +08:00
|
|
|
#endif
|