[1 / 2] register weak_ref_tensor in sgl-kernel#12999
Conversation
Summary of ChangesHello @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 introduces a new mechanism for handling weak references to PyTorch tensors within the Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a weak_ref_tensor utility function, which creates a weak reference to a PyTorch tensor by wrapping a custom C++ operator. The changes include adding the Python wrapper and exporting it from the sgl_kernel package.
My review has identified a critical issue: the custom C++ operator sgl_kernel.weak_ref_tensor is called, but its registration appears to be missing from this pull request. This will cause a runtime failure. I've also included a suggestion to add type hints to the new function for consistency and better maintainability. The critical issue must be addressed for the code to be functional.
|
|
||
| def weak_ref_tensor(tensor): | ||
| return ( | ||
| torch.ops.sgl_kernel.weak_ref_tensor(tensor) |
There was a problem hiding this comment.
This line calls a custom PyTorch operator sgl_kernel.weak_ref_tensor. Based on the provided context, the C++ implementation in sgl-kernel/csrc/memory/weak_ref_tensor.cpp appears to be missing the necessary TORCH_LIBRARY macros to register this operator. Without this registration, the Python code will raise an AttributeError at runtime. The C++ operator registration needs to be included in this pull request or must already exist in the target branch for this code to work.
| v_cache[loc] = v | ||
|
|
||
|
|
||
| def weak_ref_tensor(tensor): |
Motivation
Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist