Enhance Device Compatibility#78066
Open
Le-soleile wants to merge 10 commits intoPaddlePaddle:developfrom
Open
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #78066 +/- ##
==========================================
Coverage ? 90.24%
==========================================
Files ? 3
Lines ? 41
Branches ? 0
==========================================
Hits ? 37
Misses ? 4
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
BingooYang
reviewed
Mar 1, 2026
| types = {{ | ||
| {"cpu", DeviceType::CPU}, | ||
| {"cuda", DeviceType::CUDA}, | ||
| {"gpu", DeviceType::GPU}, |
Contributor
There was a problem hiding this comment.
cuda和gpu的区别是什么,这里增加一个gpu的理由是什么
Contributor
Author
There was a problem hiding this comment.
没什么区别,就是这样写也不会报错了: torch::set_device("gpu:0");
是不是有点多余🥲,我看了下torch的代码现在应该只会写cuda了,可能不会有这种情况
Contributor
Author
There was a problem hiding this comment.
对Torch的兼容应该不需要"gpu",我删掉了
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Category
Execute Infrastructure
PR Types
Bug fixes
Description
补充的测试#38对比输出:
Paddle 兼容层实现的
c10::Device与 PyTorch 原生在以下边界情况存在行为差异:index()=0,has_index()=trueindex()=-1,has_index()=falsecpu:0,PyTorch 输出cpu修改后测试结果变为match
修改说明
把 Paddle 的 Device 兼容层行为对齐到 Torch:以前在某些场景下(例如是从底层 place 转成 Device 时),CPU 默认会被当成“有 index=0”,导致输出和 Torch 不一致;现在改成了“只有显式写了 index 才算有 index”,否则统一按 -1 处理,这样
index()/has_index()/str()的结果就一致了。同时在兼容层里明确区分 CPU/CUDA/GPU,并通过统一的转换函数来互转,避免同一语义在多处重复判断。是否引起精度变化
否