torch_bindings.cpp 932 B

12345678910111213141516171819202122232425262728
  1. #ifdef _WIN32
  2. #include <crtdefs.h>
  3. #endif
  4. #include "../core/registration.h"
  5. #include "moe_ops.h"
  6. #include "marlin_moe_ops.h"
  7. TORCH_LIBRARY_EXPAND(TORCH_EXTENSION_NAME, m) {
  8. // Apply topk softmax to the gating outputs.
  9. m.def(
  10. "topk_softmax(Tensor! topk_weights, Tensor! topk_indices, Tensor! "
  11. "token_expert_indices, Tensor gating_output) -> ()");
  12. m.impl("topk_softmax", torch::kCUDA, &topk_softmax);
  13. #ifndef USE_ROCM
  14. m.def(
  15. "marlin_gemm_moe(Tensor! a, Tensor! b_q_weights, Tensor! sorted_ids, "
  16. "Tensor! topk_weights, Tensor! topk_ids, Tensor! b_scales, Tensor! "
  17. "g_idx, Tensor! perm, Tensor! workspace, int size_m, int size_n, int "
  18. "size_k, bool is_k_full, int num_experts, int topk, int moe_block_size, "
  19. "bool replicate_input, bool apply_weights) -> Tensor");
  20. m.impl("marlin_gemm_moe", torch::kCUDA, &marlin_gemm_moe);
  21. #endif
  22. }
  23. REGISTER_EXTENSION(TORCH_EXTENSION_NAME)