Skip to content

Migrate weak_ref_tensor to sgl-kernel#12505

Merged
ispobock merged 4 commits intomainfrom
bbuf/migrate-weak-ref-tensor
Nov 2, 2025
Merged

Migrate weak_ref_tensor to sgl-kernel#12505
ispobock merged 4 commits intomainfrom
bbuf/migrate-weak-ref-tensor

Conversation

@BBuf
Copy link
Copy Markdown
Collaborator

@BBuf BBuf commented Nov 2, 2025

  • Add weak_ref_tensor implementation in sgl-kernel/csrc/memory/
  • Register weak_ref_tensor kernel in common_extension.cc
  • Add function declaration in sgl_kernel_ops.h
  • Update CMakeLists.txt to include new source file

Motivation

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

BBuf added 2 commits November 2, 2025 09:34
- Add weak_ref_tensor implementation in sgl-kernel/csrc/memory/
- Register weak_ref_tensor kernel in common_extension.cc
- Add function declaration in sgl_kernel_ops.h
- Update CMakeLists.txt to include new source file
- Modify cuda_piecewise_backend.py to use sgl_kernel version
- Remove JIT compilation dependency on weak_ref_tensor_jit
- Use ATen headers instead of torch/extension.h for Python 3.12 compatibility
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @BBuf, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates the weak_ref_tensor functionality directly into the sgl-kernel module. This migration involves adding a new C++ implementation for weak_ref_tensor, registering it as a native PyTorch operator, and updating the build configuration to include the new source file. The change aims to provide a more integrated and potentially optimized way to handle weak tensor references within the kernel.

Highlights

  • New weak_ref_tensor Implementation: A new C++ file, sgl-kernel/csrc/memory/weak_ref_tensor.cpp, has been added to provide the core logic for creating a weak reference to a CUDA tensor using at::from_blob.
  • Kernel Registration: The weak_ref_tensor function is now registered as a PyTorch operator (sgl_kernel::weak_ref_tensor) for CUDA tensors within sgl-kernel/csrc/common_extension.cc, making it callable from Python.
  • Build System Update: sgl-kernel/CMakeLists.txt has been updated to include the newly added weak_ref_tensor.cpp source file, ensuring it is compiled as part of the kernel.
  • Header Declaration: The function signature for weak_ref_tensor has been added to sgl-kernel/include/sgl_kernel_ops.h, making its declaration available for other parts of the kernel.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request successfully migrates the weak_ref_tensor function to the sgl-kernel, which is a good step for code organization. The changes are correct and follow the intended goal. I have one suggestion to improve the efficiency of the weak_ref_tensor implementation by avoiding unnecessary memory allocations.

Comment thread sgl-kernel/csrc/memory/weak_ref_tensor.cpp
@ispobock
Copy link
Copy Markdown
Collaborator

ispobock commented Nov 2, 2025

@BBuf Could you fix the lint?

@BBuf
Copy link
Copy Markdown
Collaborator Author

BBuf commented Nov 2, 2025

@BBuf Could you fix the lint?

Done.

@ispobock ispobock merged commit 95191eb into main Nov 2, 2025
44 of 65 checks passed
@ispobock ispobock deleted the bbuf/migrate-weak-ref-tensor branch November 2, 2025 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants