Skip to content

[12/n] final _C library kernel migration - #45415

Merged
WoosukKwon merged 11 commits into
vllm-project:mainfrom
cleonard530:new-stable-abi-final-_C
Jun 19, 2026
Merged

[12/n] final _C library kernel migration#45415
WoosukKwon merged 11 commits into
vllm-project:mainfrom
cleonard530:new-stable-abi-final-_C

Conversation

@cleonard530

@cleonard530 cleonard530 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Purpose

This PR continues the libtorch stable ABI migration (see #26946) for vLLM and is the final _C library kernels to move to the _C_stable_libtorch library. The PR moves csrc/quantization/activation_kernels.cu to csrc/libtorch_stable/quantization/activation_kernels.cu, along with the weak_ref_tensor (defined in ops.h), silu_and_mul_quant, and persistent_masked_m_silu_mul_quant kernels.

Test Plan

pytest tests/kernels/test_fused_quant_activation.py
pytest tests/kernels/moe/test_silu_mul_fp8_quant_deep_gemm.py
pytest tests/compile/passes/test_silu_mul_quant_fusion.py
pytest tests/compile/passes/test_functionalization.py

Test Result

image image image image
Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
Bundled libs: 0
  -- extensions --
    [STABLE  ] [abi3-ok               ] _C_stable_libtorch.abi3.so  (stable_shim=87, unstable=0)
    [UNSTABLE] [abi3-ok               ] _flashmla_C.abi3.so  (stable_shim=0, unstable=72)
    [UNSTABLE] [abi3-ok               ] _flashmla_extension_C.abi3.so  (stable_shim=0, unstable=68)
    [STABLE  ] [abi3-ok               ] _moe_C_stable_libtorch.abi3.so  (stable_shim=72, unstable=0)
    [NO-TORCH] [abi3-ok               ] cumem_allocator.abi3.so
    [NO-TORCH] [abi3-ok               ] spinloop.abi3.so
    [UNSTABLE] [uses-private-api      ] third_party/deep_gemm/_C.cpython-312-x86_64-linux-gnu.so  (stable_shim=0, unstable=57)
    [UNSTABLE] [abi3-ok               ] vllm_flash_attn/_vllm_fa2_C.abi3.so  (stable_shim=0, unstable=84)
    [UNSTABLE] [abi3-ok               ] vllm_flash_attn/_vllm_fa3_C.abi3.so  (stable_shim=0, unstable=80)

Note, no more C_.abi.so library! It has all been moved to _C_stable_libtorch.abi3.so (similarly for _moe_C).

@cleonard530 cleonard530 changed the title New stable abi final c [12/n] final _C library kernel migration Jun 12, 2026
VLLM_STABLE_DISPATCH_FLOATING_TYPES( \
input.scalar_type(), "act_and_mul_kernel", [&] { \
VLLM_STABLE_DISPATCH_FP8_TYPES( \
out.scalar_type(), "act_and_mul_quant_kernel_fp8_type", [&] { \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, this kernel string was renamed to indicate what kernel was actually being called.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did this work before?

void* data_ptr = const_cast<void*>(tensor.mutable_data_ptr());

// Create a new tensor from the raw data pointer
return torch::stable::from_blob(data_ptr, tensor.sizes(), tensor.strides(),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can pass tensor.sizes() and tensor.strides() straight into stable::from_blob without having to convert them to std::vectors first

Comment thread csrc/libtorch_stable/ops.h Outdated
// Create a new tensor from the raw data pointer
return torch::stable::from_blob(data_ptr, tensor.sizes(), tensor.strides(),
tensor.device(), tensor.scalar_type(),
[base = tensor](void*) {});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, this only works because we are on torch >= 2.11, this would not build on torch 2.10

Comment thread csrc/libtorch_stable/torch_bindings.cpp Outdated
// See the following document for more info on custom types and ops that use
// custom types:
// https://docs.google.com/document/d/18fBMPuOJ0fY5ZQ6YyrHUppw9FA332CpNtgB6SOIgyuA

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should have been moved over during the marlin/machete migrations

Comment thread csrc/torch_bindings.cpp
// kernels from being torch.compile'd.
// See the following document for more info on custom types and ops that use
// custom types:
// https://docs.google.com/document/d/18fBMPuOJ0fY5ZQ6YyrHUppw9FA332CpNtgB6SOIgyuA

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the marlin/machete migrations (#45176 and #45304) this #ifndef block should have been removed.

Comment thread CMakeLists.txt

#
# _C extension
# Legacy _C extension (ROCm only — CUDA ops migrated to _C_stable_libtorch)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated comment to encourage others to use _C_stable_libtorch for cuda kernels,

@cleonard530
cleonard530 marked this pull request as ready for review June 12, 2026 18:12
@cleonard530

Copy link
Copy Markdown
Contributor Author

@Harry-Chen, reminder to add the rocm tag

@Harry-Chen

Copy link
Copy Markdown
Member

Please fix the pre-commit format error, thanks!

@Harry-Chen Harry-Chen added rocm Related to AMD ROCm ready ONLY add when PR is ready to merge/full CI is needed labels Jun 14, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Jun 14, 2026
@mergify

mergify Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @cleonard530.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Jun 14, 2026
@Harry-Chen

Copy link
Copy Markdown
Member

I think my PR #45277 has created some conflicts -- sorry for that, could you rebase / merge again?

@cleonard530
cleonard530 force-pushed the new-stable-abi-final-_C branch from 765e48f to 3469b5c Compare June 15, 2026 12:15
@mergify mergify Bot removed the needs-rebase label Jun 15, 2026
@cleonard530

Copy link
Copy Markdown
Contributor Author

I think my PR #45277 has created some conflicts -- sorry for that, could you rebase / merge again?

Done!

@Harry-Chen

Copy link
Copy Markdown
Member

Seems qutlass is expecting a _C target to build. You could also fix that.

@cleonard530

Copy link
Copy Markdown
Contributor Author

Seems qutlass is expecting a _C target to build. You could also fix that.

Fixed. Also, there was an issue with the ROCm build since the new stable weak_ref_tensor requires torch >=2.11, so I added a guard around it to not build with ROCm and left the old weak_ref_tensor in the csrc/ops.h file.

@mergify

mergify Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @cleonard530.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@Harry-Chen

Copy link
Copy Markdown
Member

I have not checked thoroughly, but there seem to be a lot of RuntimeErrors -- might still be related to the changes?

Yes, I think the same errors keep failing so I assume it has something to do with this PR. Most of the errors are OOM memory errors, like No available memory for the cache blocks. or torch.OutOfMemoryError: CUDA out of memory.

I am still not too sure why but it seems the memory from CUDA graphs are possibly not being freed between test. I am still looking into this to figure out the cause, but please let me know if you have any insight into why this might be happening.

Sorry I do not have much idea either :-(. BTW we just have #44681 merged, which removed some MoE kernels and caused some conflicts. I'm just thinking -- if you are intereseted -- you can also invetigate if there are more unused kernels during migration, so that we could just remove it instead of putting extra work into it.

@cleonard530

Copy link
Copy Markdown
Contributor Author

Sorry I do not have much idea either :-(. BTW we just have #44681 merged, which removed some MoE kernels and caused some conflicts. I'm just thinking -- if you are intereseted -- you can also invetigate if there are more unused kernels during migration, so that we could just remove it instead of putting extra work into it.

@Harry-Chen, Yes, I can definitely look into that while I am migrating over. After this PR, I am planning on doing another PR to clean up anything I missed during the migration (like moving some headers I missed over to the libtorch_stable directory) and I can check for unused kernels as well when I am doing this.

…/quantization/activation_kernels.cu

Signed-off-by: Chris Leonard <chleonar@redhat.com>
…e abi stable and removed the last cuda kernels from csrc/ops.h and csrc/torch_bindings.cpp and moved them to the libtorch_stable files

Signed-off-by: Chris Leonard <chleonar@redhat.com>
… to clearly indicate where _C HIP ends in CMakeLists.txt

Signed-off-by: Chris Leonard <chleonar@redhat.com>
Signed-off-by: Chris Leonard <chleonar@redhat.com>
…s no longer built with cuda. Also, the new stable version of weak_ref_tensor requires torch 2.11 but ROCm is still built with 2.10, so I added the old implementation back in csrc/ops.h which is no longer built on cuda.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
…elow the set_gencode_flags_for_srcs to avoid conflicting sm_100 and sm_100f flags

Signed-off-by: Chris Leonard <chleonar@redhat.com>
…istration.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
…ensions via import_kernels.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
…that should of been const_data_ptr.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
@cleonard530
cleonard530 force-pushed the new-stable-abi-final-_C branch from 84ee0e3 to 549bae4 Compare June 18, 2026 12:33
@mergify mergify Bot removed the needs-rebase label Jun 18, 2026
…erge conflict, removing it again

Signed-off-by: Chris Leonard <chleonar@redhat.com>
…eter was saving the tensor data, causing the memory buildup to cascade until we reached OOM errors. This should fix that. Also, Since from_blob was replaced with an overload that is on torch 2.10, we no longer need the ifndef ROCM flag or the legacy weak_ref_tensor method in the non-stable ops.h file.

Signed-off-by: Chris Leonard <chleonar@redhat.com>
@cleonard530

Copy link
Copy Markdown
Contributor Author

@Harry-Chen, I figure out the issue. The custom deleter in the stable::from_blob method was saving the tensor data, causing memory usage to grow until we hit OOM errors.The tensor data is no longer saved and works the same way it did in the unstable path now.

I believe the three test failures are flaky test, are you able to rerun them to check?

@Harry-Chen Harry-Chen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!

@github-project-automation github-project-automation Bot moved this to Ready in NVIDIA Jun 19, 2026
@Harry-Chen
Harry-Chen enabled auto-merge (squash) June 19, 2026 07:04
@WoosukKwon
WoosukKwon merged commit b9a7cd4 into vllm-project:main Jun 19, 2026
195 of 197 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AMD Jun 19, 2026
@github-project-automation github-project-automation Bot moved this from Ready to Done in NVIDIA Jun 19, 2026
@Harry-Chen

Copy link
Copy Markdown
Member

Sorry I do not have much idea either :-(. BTW we just have #44681 merged, which removed some MoE kernels and caused some conflicts. I'm just thinking -- if you are intereseted -- you can also invetigate if there are more unused kernels during migration, so that we could just remove it instead of putting extra work into it.

@Harry-Chen, Yes, I can definitely look into that while I am migrating over. After this PR, I am planning on doing another PR to clean up anything I missed during the migration (like moving some headers I missed over to the libtorch_stable directory) and I can check for unused kernels as well when I am doing this.

That's really great! I think you can also fix some existing issues (e.g. constness of parameters) that were kept as-is during the whole migration. I think @janeyx99 has pointed out a lot of them in the PR series.

divineearthly pushed a commit to divineearthly/vllm that referenced this pull request Jun 19, 2026
Signed-off-by: divineearthly <divineearthly@gmail.com>
xuebwang-amd pushed a commit to xuebwang-amd/vllm that referenced this pull request Jun 21, 2026
nkzhenhua pushed a commit to nkzhenhua/vllm that referenced this pull request Jun 24, 2026
qli88 pushed a commit to qli88/vllm that referenced this pull request Jun 26, 2026
Signed-off-by: Qiang Li <qiang.li2@amd.com>
Dao007forever pushed a commit to Dao007forever/vllm that referenced this pull request Jul 18, 2026
philippesic pushed a commit to philippesic/vllm-semantic-cache that referenced this pull request Jul 19, 2026
plasticchris pushed a commit to plasticchris/vllm that referenced this pull request Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/build nvidia ready ONLY add when PR is ready to merge/full CI is needed rocm Related to AMD ROCm

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants