Skip to content

Use TORCH_LIBRARY to register function#60

Draft
yanbing-j wants to merge 2 commits intomingfeima:cpu_opt_ww11from
yanbing-j:yanbing/py_bind
Draft

Use TORCH_LIBRARY to register function#60
yanbing-j wants to merge 2 commits intomingfeima:cpu_opt_ww11from
yanbing-j:yanbing/py_bind

Conversation

@yanbing-j
Copy link
Collaborator

Motivation

Modifications

std::optional<at::Tensor>& will use const std::optional<at::Tensor>& instead, to pass build errors of cannot bind non-const lvalue reference of type 'std::optional<at::Tensor>&' to an rvalue of type 'std::optional<at::Tensor>' .
PyTorch schema float equals C++ double.

Now use torch.ops.sgl_kernel.silu_and_mul_cpu to call the function in cpu.py. No need to change the wrapper in deepseek model, still use sgl_kernel.cpu.silu_and_mul.

shm_allreduce is WIP.

Checklist

@gau-nernst
Copy link

I'm experimenting with torch.compile and also need to convert PyBind11 module to PyTorch custom op. Initial results have been promising so far. Will share more details when I have something more complete.

shm_allreduce was also a blocker for me due to ProcessGroup and ReduceOp argument. I think we can follow PyTorch c10d_functional approach, which convert ProcessGroup to group_name string and ReduceOp to op_name string

https://github.com/pytorch/pytorch/blob/2f09e7914268ff5c5e4a4a54158fcf93d5f528dd/torch/csrc/distributed/c10d/Functional.cpp#L239-L241

CaoE pushed a commit to CaoE/sglang that referenced this pull request Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants