fix: add None check before stream synchronization#2810
Conversation
Prevent AttributeError by ensuring the stream object is not None before calling stream.synchronize(). Signed-off-by: Tony Lin <tony.lin@intel.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Summary of ChangesHello, 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 addresses a critical bug that could lead to an 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses a potential AttributeError by adding a None check before calling stream.synchronize() in the allocate_and_copy_objects function. This change prevents a crash when running on non-CUDA devices where the CUDA stream object would be None. The fix is correct and well-targeted. I've added one suggestion to improve type hinting for maintainability.
| if stream is not None: | ||
| stream.synchronize() |
There was a problem hiding this comment.
This check correctly handles cases where stream can be None. To improve type safety and make this explicit for future developers, consider updating the function's type hint for the stream parameter from torch.cuda.Stream to Optional[torch.cuda.Stream].
For example:
def allocate_and_copy_objects(
...,
stream: Optional[torch.cuda.Stream],
) -> ...:Prevent AttributeError by ensuring the stream object is not None before calling stream.synchronize(). Signed-off-by: Tony Lin <tony.lin@intel.com>
Prevent AttributeError by ensuring the stream object is not None before calling stream.synchronize(). Signed-off-by: Tony Lin <tony.lin@intel.com> Signed-off-by: Aaron Wu <aaron.wu@dell.com>
Prevent AttributeError by ensuring the stream object is not None before calling stream.synchronize(). Signed-off-by: Tony Lin <tony.lin@intel.com>
Prevent AttributeError by ensuring the stream object is not None before calling stream.synchronize(). Signed-off-by: Tony Lin <tony.lin@intel.com>
Prevent AttributeError by ensuring the stream object is not None before calling stream.synchronize(). Signed-off-by: Tony Lin <tony.lin@intel.com>
Prevent AttributeError by ensuring the stream object is not None before calling stream.synchronize(). Signed-off-by: Tony Lin <tony.lin@intel.com>
Prevent AttributeError by ensuring the stream object is not None before calling stream.synchronize(). Signed-off-by: Tony Lin <tony.lin@intel.com>
Prevent AttributeError by ensuring the stream object is not None before calling stream.synchronize().
otherwise, crash will happen on non-cuda devices.