torch_bindings.cpp 1002 B

1234567891011121314151617181920212223242526272829
  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, "
  18. "__torch__.torch.classes._core_C.ScalarType b_q_type, int size_m, "
  19. "int size_n, int size_k, bool is_k_full, int num_experts, int topk, "
  20. "int moe_block_size, bool replicate_input, bool apply_weights)"
  21. " -> Tensor");
  22. m.impl("marlin_gemm_moe", torch::kCUDA, &marlin_gemm_moe);
  23. #endif
  24. }
  25. REGISTER_EXTENSION(TORCH_EXTENSION_NAME)