quant_ops.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #pragma once
  2. #include <torch/extension.h>
  3. #ifndef USE_ROCM
  4. // AQLM
  5. torch::Tensor aqlm_gemm(
  6. const torch::Tensor& input,
  7. const torch::Tensor& codes,
  8. const torch::Tensor& codebooks,
  9. const torch::Tensor& scales,
  10. const torch::Tensor& codebook_partition_sizes,
  11. const std::optional<torch::Tensor>& bias
  12. );
  13. // AWQ
  14. torch::Tensor awq_gemm(
  15. torch::Tensor _in_feats,
  16. torch::Tensor _kernel,
  17. torch::Tensor _scaling_factors,
  18. torch::Tensor _zeros,
  19. int split_k_iters);
  20. torch::Tensor awq_dequantize(
  21. torch::Tensor _kernel,
  22. torch::Tensor _scaling_factors,
  23. torch::Tensor _zeros,
  24. int split_k_iters,
  25. int thx,
  26. int thy);
  27. torch::Tensor awq_group_gemm(
  28. torch::Tensor _in_feats,
  29. torch::Tensor _kernel,
  30. torch::Tensor _scaling_factors,
  31. torch::Tensor _zeros,
  32. torch::Tensor _topk_weights,
  33. torch::Tensor _sorted_token_ids_ptr,
  34. torch::Tensor _expert_ids_ptr,
  35. torch::Tensor _num_tokens_post_padded,
  36. bool mul_weights,
  37. int split_k_iters);
  38. #endif
  39. // ExLlamav2
  40. torch::Tensor exl2_gemm(
  41. torch::Tensor a,
  42. uintptr_t b
  43. );
  44. uintptr_t make_q_matrix(
  45. torch::Tensor q_weight,
  46. torch::Tensor q_perm,
  47. torch::Tensor q_invperm,
  48. torch::Tensor q_scale,
  49. torch::Tensor q_scale_max,
  50. torch::Tensor q_groups,
  51. torch::Tensor q_group_map
  52. );
  53. #ifndef USE_ROCM
  54. // GGUF
  55. torch::Tensor ggml_dequantize(
  56. torch::Tensor X,
  57. int8_t type,
  58. int64_t m,
  59. int64_t n
  60. );
  61. torch::Tensor ggml_mul_mat_vec(
  62. torch::Tensor W, // quant weight
  63. torch::Tensor X, // input
  64. int8_t type,
  65. int64_t m
  66. );
  67. torch::Tensor ggml_mul_mat_vec_a8(
  68. torch::Tensor W, // quant weight
  69. torch::Tensor X, // input
  70. int8_t type,
  71. int64_t row
  72. );
  73. torch::Tensor ggml_mul_mat_a8(
  74. torch::Tensor W, // quant weight
  75. torch::Tensor X, // input
  76. int8_t type,
  77. int64_t row
  78. );
  79. #endif
  80. // GPTQ
  81. torch::Tensor gptq_gemm(
  82. torch::Tensor a,
  83. torch::Tensor b_q_weight,
  84. torch::Tensor b_gptq_qzeros,
  85. torch::Tensor b_gptq_scales,
  86. torch::Tensor b_g_idx,
  87. bool use_exllama,
  88. int bit);
  89. void gptq_shuffle(
  90. torch::Tensor q_weight,
  91. torch::Tensor q_perm,
  92. int bit);
  93. torch::Tensor group_gptq_gemm(
  94. torch::Tensor a,
  95. torch::Tensor b_q_weight,
  96. torch::Tensor b_gptq_qzeros,
  97. torch::Tensor b_gptq_scales,
  98. torch::Tensor b_g_idx,
  99. torch::Tensor topk_weights,
  100. torch::Tensor sorted_token_ids_ptr,
  101. torch::Tensor expert_ids_ptr,
  102. torch::Tensor num_tokens_post_padded,
  103. bool mul_weights,
  104. bool use_exllama
  105. );
  106. torch::Tensor dequant_gptq(
  107. torch::Tensor b_q_weight,
  108. torch::Tensor b_gptq_qzeros,
  109. torch::Tensor b_gptq_scales,
  110. torch::Tensor b_g_idx,
  111. int bits,
  112. bool use_exllama
  113. );
  114. #ifndef USE_ROCM
  115. // Marlin
  116. torch::Tensor marlin_gemm(
  117. torch::Tensor& a,
  118. torch::Tensor& b_q_weight,
  119. torch::Tensor& b_scales,
  120. torch::Tensor& workspace,
  121. int64_t size_m,
  122. int64_t size_n,
  123. int64_t size_k);
  124. // QuIP#
  125. at::Tensor e8p_mm_origorder(
  126. const at::Tensor& A,
  127. const at::Tensor& B,
  128. const at::Tensor& CB);
  129. void decompress_e8p_origorder(
  130. torch::Tensor YIs,
  131. torch::Tensor CB,
  132. torch::Tensor &Y
  133. );
  134. // SmoothQuant+
  135. torch::Tensor autoquant_s4_f16_gemm(
  136. torch::Tensor _in_feats,
  137. torch::Tensor _kernel,
  138. torch::Tensor _scales_zeros);
  139. void autoquant_convert_s4_k_m8(
  140. torch::Tensor _weight_dest,
  141. torch::Tensor _quant_scales_zeros_dest,
  142. torch::Tensor _workspace,
  143. torch::Tensor _quant_weight_src,
  144. torch::Tensor _quant_scales,
  145. torch::Tensor _quant_zeros,
  146. int m,
  147. int k,
  148. int group_size);
  149. #endif
  150. // SqueezeLLM
  151. void squeezellm_gemm(
  152. torch::Tensor vec,
  153. torch::Tensor mat,
  154. torch::Tensor mul,
  155. torch::Tensor lookup_table);