[API Compatibility] Fix Tensor.type - #79641
Conversation
… three_Tensor_and_PReLU
… three_Tensor_and_PReLU
… three_Tensor_and_PReLU
… three_Tensor_and_PReLU
… three_Tensor_and_PReLU
… three_Tensor_and_PReLU
… three_Tensor_and_PReLU
There was a problem hiding this comment.
| 序号 | 位置 | 优先级 | 状态 |
|---|---|---|---|
| 1 | decorator_utils.py:279 | 🟡 | |
| 2 | compat/proxy.py:551 | 🟡 | |
| 3 | compat/init.py:112 | ✅ | |
| 4 | compat/init.py:156 | ✅ | |
| 5 | compat/init.py:116 | 🚧 |
| and args[4] in data_formats | ||
| ) | ||
| is_paddle_place = isinstance(args[3], paddle.base.libpaddle.Place) | ||
| is_device = args[3] is None or ( |
| _register_compat_override() | ||
| _swap_torch_modules_to_cache() | ||
| _modify_scope_of_torch_proxy(scope, silent=silent) | ||
| sys.meta_path.insert(0, TORCH_PROXY_FINDER) |
| if tensor_type is None: | ||
| return str(input.dtype) | ||
| segments = ["torch"] | ||
| if input.place.is_gpu_place(): |
There was a problem hiding this comment.
当前 head 已补齐 GPU、XPU 和 custom place 的类型名分支,并加入对应覆盖测试,原问题已修复。
| return _tensor_type_name(input) | ||
|
|
||
| device = None | ||
| if getattr(dtype, "__name__", None) in _TENSOR_TYPE_DTYPES: |
There was a problem hiding this comment.
当前 head 已改为带设备标记的独立 CUDA factory,并加入 CUDA 构造覆盖测试,原问题已修复。
|
/re-run all-failed |
… three_Tensor_and_PReLU
|
/re-run all-failed |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #79641 +/- ##
==========================================
Coverage ? 96.75%
==========================================
Files ? 8
Lines ? 185
Branches ? 0
==========================================
Hits ? 179
Misses ? 6
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/re-run all-failed |
|
/re-run all-failed |
1 similar comment
|
/re-run all-failed |
|
@risemeup1111 关于 enable_compat 计数问题和 PReLU 函数的问题你已经在 #79550 里通过了,这个 PR 里也没有涉及这两处的修改,所以通过一下 |
| segments = ["torch"] | ||
| place = input.place | ||
| if place.is_gpu_place(): | ||
| segments.append("cuda") |
There was a problem hiding this comment.
There was a problem hiding this comment.
XPU/custom 的解析已补齐,但当前修改仍不完整:torch.FloatTensor/paddle.FloatTensor 这类无设备段的 tensor type 现在返回 device=None,GPU Tensor 调用后会保留在 GPU;PyTorch 中这些名称表示 CPU tensor type,应转到 CPU。请让已识别的 tensor-type 字符串在无设备段时默认 cpu,同时保留 torch.float32 这类 dtype-only 字符串的 device=None,并补 GPU→torch.FloatTensor 回归测试。
There was a problem hiding this comment.
@risemeup1111 我觉得像 torch.FloatTensor/paddle.FloatTensor 这样的调用,本身就不应该涉及设备的转换,所以 device=None 保持设备不变是对的;即参数中有设备段或者显式表明了类(比如 paddle.cuda.DoubleTensor)才要管设备,否则保持不变
There was a problem hiding this comment.
这里的 device=None 只适用于 dtype-only 参数(例如 torch.float32),不适用于 tensor type factory。PyTorch 中 torch.FloatTensor 是 CPU tensor class,torch.cuda.FloatTensor 才是 CUDA class;本 PR 的 _tensor_type_name() 也明确把 CPU Tensor 编码成 torch.FloatTensor、GPU Tensor 编码成 torch.cuda.FloatTensor。因此 t.type(t.type()) 必须保持 round-trip,GPU Tensor 的 t.type("torch.FloatTensor") 应转换到 CPU;否则返回的类型名不能表达并恢复 Tensor 的 place。请将无设备段的 tensor-type 字符串区分为 device="cpu",同时继续让 torch.float32 保持 device=None。
|
/re-run all-failed |
… fix_Tensor_type
|
/re-run all-failed |
|
/re-run all-failed |
1 similar comment
|
/re-run all-failed |
PR Category
User Experience
PR Types
New features
Description
修正 compat 模式下
Tensor.type()的两处行为:dtype字符串(如paddle.float32),而 torch 返回的是 tensor type 名。现在按torch.Tensor.type的规则拼出torch.FloatTensor/torch.cuda.FloatTensor/torch.cuda.sparse.FloatTensor,把dtype、device和sparse COO布局都编码进名字里;没有对应 tensor type 名的dtype仍回退到dtype字符串dtype当字符串传递,再靠去掉paddle.前缀的字符串比较来判断是否需要转换。现在统一转成真正的 paddledtype对象,直接比较input.dtype,避免字符串绕路这样 paconvert 对应用例不用再加
check_value=False就能通过是否引起精度变化
否