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-08-02 16:51:58 -04:00
|
|
|
#include "core/scalar_type.hpp"
|
|
|
|
|
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-09-12 11:16:22 -07:00
|
|
|
void advance_step_flashattn(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);
|
|
|
|
|
|
|
|
void advance_step_flashinfer(
|
|
|
|
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,
|
|
|
|
torch::Tensor& paged_kv_indices, torch::Tensor& paged_kv_indptr,
|
|
|
|
torch::Tensor& paged_kv_last_page_len, torch::Tensor& block_table_bounds);
|
2024-07-17 17:30:28 -04:00
|
|
|
|
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,
|
2024-08-16 17:00:11 -04:00
|
|
|
const std::vector<int64_t>& codebook_partition_sizes,
|
2024-05-22 03:18:41 -04:00
|
|
|
const std::optional<torch::Tensor>& bias);
|
|
|
|
|
2024-08-16 17:00:11 -04:00
|
|
|
torch::Tensor aqlm_dequant(
|
|
|
|
const torch::Tensor& codes, const torch::Tensor& codebooks,
|
|
|
|
const std::vector<int64_t>& codebook_partition_sizes);
|
2024-05-22 03:18:41 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
2024-09-23 13:46:26 -04:00
|
|
|
torch::Tensor permute_cols(torch::Tensor const& A, torch::Tensor const& perm);
|
|
|
|
|
2024-08-16 17:00:11 -04:00
|
|
|
torch::Tensor ggml_dequantize(torch::Tensor W, int64_t type, int64_t m,
|
2024-08-06 07:54:23 +08:00
|
|
|
int64_t n);
|
|
|
|
|
2024-08-16 17:00:11 -04:00
|
|
|
torch::Tensor ggml_mul_mat_vec_a8(torch::Tensor W, torch::Tensor X,
|
|
|
|
int64_t type, int64_t row);
|
2024-08-06 07:54:23 +08:00
|
|
|
|
2024-08-16 17:00:11 -04:00
|
|
|
torch::Tensor ggml_mul_mat_a8(torch::Tensor W, torch::Tensor X, int64_t type,
|
2024-08-06 07:54:23 +08:00
|
|
|
int64_t row);
|
|
|
|
|
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-08-06 14:17:08 -04:00
|
|
|
void cutlass_scaled_mm_azp(torch::Tensor& out, torch::Tensor const& a,
|
|
|
|
torch::Tensor const& b,
|
|
|
|
torch::Tensor const& a_scales,
|
|
|
|
torch::Tensor const& b_scales,
|
|
|
|
torch::Tensor const& azp_adj,
|
|
|
|
c10::optional<torch::Tensor> const& azp,
|
|
|
|
c10::optional<torch::Tensor> const& bias);
|
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,
|
2024-09-16 14:52:40 -04:00
|
|
|
torch::Tensor const& scale,
|
|
|
|
c10::optional<torch::Tensor> const& azp);
|
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,
|
2024-09-16 14:52:40 -04:00
|
|
|
torch::Tensor& scales,
|
|
|
|
c10::optional<torch::Tensor> const& azp);
|
2024-06-07 12:36:26 -04:00
|
|
|
|
2024-05-22 03:18:41 -04:00
|
|
|
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
|
|
|
|
2024-09-30 00:35:58 +03:00
|
|
|
void selective_scan_fwd(const torch::Tensor& u, const torch::Tensor& delta,
|
|
|
|
const torch::Tensor& A, const torch::Tensor& B,
|
|
|
|
const torch::Tensor& C,
|
|
|
|
const c10::optional<torch::Tensor>& D_,
|
|
|
|
const c10::optional<torch::Tensor>& z_,
|
|
|
|
const c10::optional<torch::Tensor>& delta_bias_,
|
|
|
|
bool delta_softplus,
|
|
|
|
const c10::optional<torch::Tensor>& query_start_loc,
|
|
|
|
const c10::optional<torch::Tensor>& cache_indices,
|
|
|
|
const c10::optional<torch::Tensor>& has_initial_state,
|
|
|
|
const torch::Tensor& ssm_states);
|
2024-08-29 01:06:52 +03:00
|
|
|
|
2024-09-17 19:44:27 -04:00
|
|
|
at::Tensor causal_conv1d_update(
|
|
|
|
const at::Tensor& x, const at::Tensor& conv_state, const at::Tensor& weight,
|
2024-09-30 00:35:58 +03:00
|
|
|
const c10::optional<at::Tensor>& bias_, bool silu_activation,
|
|
|
|
const c10::optional<at::Tensor>& cache_seqlens_,
|
|
|
|
const c10::optional<at::Tensor>& conv_state_indices_);
|
2024-08-29 01:06:52 +03:00
|
|
|
|
|
|
|
at::Tensor causal_conv1d_fwd(const at::Tensor& x, const at::Tensor& weight,
|
|
|
|
const c10::optional<at::Tensor>& bias_,
|
2024-09-30 00:35:58 +03:00
|
|
|
const c10::optional<at::Tensor>& conv_states,
|
|
|
|
const c10::optional<at::Tensor>& query_start_loc,
|
|
|
|
const c10::optional<at::Tensor>& cache_indices,
|
|
|
|
const c10::optional<at::Tensor>& has_initial_state,
|
2024-08-29 01:06:52 +03:00
|
|
|
bool silu_activation);
|
|
|
|
|
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);
|
|
|
|
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
|