[API Compatibility] Add torch-compatible NVTX range context manager#79251
Conversation
ShigureNyako
left a comment
There was a problem hiding this comment.
Self-review:
- Diff is limited to
paddle.cuda.nvtx.range, mirroredpaddle.device.nvtx.range, and focusedTestNvtxcoverage. - The wrapper matches
torch.cuda.nvtx.rangecall shape (msg.format(*args, **kwargs)) and guaranteesrange_pop()infinallyfor normal and exceptional exits. - No torch dependency is introduced; no stream/current_stream code is touched.
@SigureMo 请帮忙 review,谢谢。
|
|
||
| @staticmethod | ||
| @contextmanager | ||
| def range(msg: str, *args, **kwargs): |
There was a problem hiding this comment.
| def range(msg: str, *args, **kwargs): | |
| def range(msg: str, *args: Any, **kwargs: Any) -> generator 的返回值咋标来着太久了我忘了,你自己查去: |
There was a problem hiding this comment.
Done,已在 bedbde59a5daedb2e00463161c8fc9e44db9bb5b 中补上类型标注:
*args: Any**kwargs: Any-> Generator[None, None, None]
Generator 按 Paddle 现有 contextmanager 写法放在 TYPE_CHECKING 下从 collections.abc 引入,并同步更新了 paddle.cuda.nvtx.range / paddle.device.nvtx.range。
验证:pre-commit run --files python/paddle/cuda/__init__.py python/paddle/device/__init__.py test/legacy_test/test_cuda_unittest.py 通过。
4841b38 to
bedbde5
Compare
|
/re-run all-failed |
1 similar comment
|
/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 #79251 +/- ##
===========================================
Coverage ? 100.00%
===========================================
Files ? 2
Lines ? 18
Branches ? 0
===========================================
Hits ? 18
Misses ? 0
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/re-run all-failed |
2 similar comments
|
/re-run all-failed |
|
/re-run all-failed |
|
停停停,先别 rerun 了,得等 #79240 修好了我给你 rerun |
|
收到,先不继续 rerun 了,等 #79240 修好后再处理。 |
|
CI 已全部通过,PR 现在是 approved / clean。我这边没有 merge 权限(MergePullRequest 权限不足),麻烦 @SigureMo 合并一下,谢谢。 |
PR Category
User Experience
PR Types
Improvements
Description
This PR adds a torch-compatible NVTX range context manager to Paddle's existing NVTX namespace:
paddle.cuda.nvtx.range(msg, *args, **kwargs)paddle.device.nvtx.range(msg, *args, **kwargs)The wrapper follows
torch.cuda.nvtx.rangebehavior: it formatsmsg, calls the existingrange_push, yields as a context manager/decorator, and always callsrange_popinfinally. It does not introduce a torch dependency and preserves Paddle's current CUDA/NVTX availability behavior by reusing the existingrange_push/range_popAPIs.Background: in NVIDIA/cudnn-frontend's Paddle adaptation,
with torch.cuda.nvtx.range(...)call sites had to be replaced by a local context manager wrappingpaddle.cuda.nvtx.range_push/pop. Adding this compatibility wrapper lets such external projects keep the torch-style call shape when usingimport paddle as torch.Validation:
pre-commit run --files python/paddle/cuda/__init__.py python/paddle/device/__init__.py test/legacy_test/test_cuda_unittest.pygit diff --checkpython3 - <<'PY' ... compile edited files ... PYTestNvtxruntime was not runnable in this source checkout because there is no builtlibpaddle; CUDA/NVTX runtime behavior remains covered by the existing guarded CUDA test path plus the new monkeypatched no-CUDA behavior test.是否引起精度变化
否