[API Compatibility] Add cuda_stream to Paddle stream wrapper#79250
Conversation
|
自查完成:本 PR 只补齐 |
| def cuda_stream(self) -> int: | ||
| if isinstance(self.stream_base, core.CUDAStream): | ||
| return self.stream_base.cuda_stream | ||
| raise AttributeError("cuda_stream is only available for CUDA streams") |
There was a problem hiding this comment.
确实,这个非 CUDA 分支之前没覆盖。已补一个 CPU-safe 的最小测试:用未初始化的 paddle.device.Stream 配一个非 CUDA stream_base,断言访问 cuda_stream 会抛出这个 AttributeError,避免 coverage 漏掉这行。
11921d9 to
97a57f9
Compare
| expected_cuda_stream = stream.stream_base.cuda_stream | ||
| expected_raw_stream = stream.stream_base.raw_stream | ||
|
|
||
| with paddle.use_compat_guard(): |
There was a problem hiding this comment.
如果只是测 use_compat_guard 下,没必要,因为在 API 对齐的情况下,这就是天然对齐的,这个 case 清理掉吧
There was a problem hiding this comment.
Done,已清理这个 use_compat_guard / import torch 的测试,只保留直接 API 对齐测试。
| if isinstance(self.stream_base, core.CUDAStream): | ||
| return self.stream_base.cuda_stream | ||
| raise AttributeError("cuda_stream is only available for CUDA streams") |
There was a problem hiding this comment.
你改成这样
| if isinstance(self.stream_base, core.CUDAStream): | |
| return self.stream_base.cuda_stream | |
| raise AttributeError("cuda_stream is only available for CUDA streams") | |
| assert isinstance(self.stream_base, core.CUDAStream), "cuda_stream is only available for CUDA streams" | |
| return self.stream_base.cuda_stream |
There was a problem hiding this comment.
Done,已按建议改成 assert isinstance(self.stream_base, core.CUDAStream) 后直接返回 self.stream_base.cuda_stream。
| def test_cuda_stream_non_cuda_stream(self): | ||
| stream = object.__new__(paddle.device.Stream) | ||
| stream.stream_base = object() | ||
|
|
||
| with self.assertRaisesRegex( | ||
| AttributeError, "cuda_stream is only available for CUDA streams" | ||
| ): | ||
| _ = stream.cuda_stream |
There was a problem hiding this comment.
Done,已移除这个通过 object.__new__ 构造的非正常测试。
Co-authored-by: Codex <noreply@openai.com>
97a57f9 to
775654c
Compare
|
/re-run all-failed |
2 similar comments
|
/re-run all-failed |
|
/re-run all-failed |
|
/re-run all-failed |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #79250 +/- ##
===========================================
Coverage ? 100.00%
===========================================
Files ? 1
Lines ? 4
Branches ? 0
===========================================
Hits ? 4
Misses ? 0
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/re-run all-failed |
1 similar comment
|
/re-run all-failed |
|
停停停,先别 rerun 了,得等 #79240 修好了我给你 rerun |
|
收到,我这边先不再触发 rerun,等 #79240 修好后由你来 rerun。谢谢! |
PR Category
User Experience
PR Types
Improvements
Description
参考 NVIDIA/cudnn-frontend@develop...PFCCLab:cudnn-frontend:paddle 中 Paddle 适配对当前 CUDA stream 的处理:外部库原本使用 PyTorch 形态的
torch.cuda.current_stream().cuda_stream获取cudaStream_t,Paddle 适配需要改成stream_base.raw_stream。本 PR 在 Paddle 的
Stream包装层补齐最小兼容接口:paddle.device.Stream增加只读属性cuda_stream,CUDA stream 返回底层stream_base.cuda_stream的整型 handle,可被外部 CUDA/C++/Python 库继续作为当前 stream 使用。AttributeError,保持设备语义明确。paddle.use_compat_guard()下,import torch后的torch.cuda.current_stream().cuda_stream可直接走 Paddle 兼容代理,不引入 PyTorch 依赖。这样外部项目不需要为了 Paddle 每次把
torch.cuda.current_stream().cuda_stream改写成 Paddle 专用路径,也不混入 nvtx.range 相关改动。验证:
python3 -m py_compile python/paddle/device/__init__.py test/legacy_test/test_cuda_stream_event.pyruff check python/paddle/device/__init__.py test/legacy_test/test_cuda_stream_event.pyruff format --check python/paddle/device/__init__.py test/legacy_test/test_cuda_stream_event.pyprek --files python/paddle/device/__init__.py test/legacy_test/test_cuda_stream_event.pyprekhook 已通过本地限制:当前源码 checkout 没有构建/安装
libpaddle,PYTHONPATH=python import paddle会失败,因此无法在本机完成 CUDA 单测运行;新增测试已按 CUDA 可用性 guard。是否引起精度变化
否