#827 fix_yolov5

Merged
Erpim merged 11 commits from lzh/MSAdapter:fix_yolov5 into master 4 months ago
lzh commented 4 months ago
lzh commented 4 months ago
Poster
修复yolov5定位中发现的nonzero(影响where)、T、repeat接口bug
zoulq reviewed 4 months ago
mindtorch/torch/functional.py
@@ -1195,2 +1195,4 @@
res = ms.ops.split(res, 1, axis=0)
output = cast_to_adapter_tensor(res)
else:
output = (tensor([], dtype=mstype.int64), tensor([], dtype=mstype.int64))
zoulq commented 4 months ago
tensor([])是期望创建一个什么样的tensor?
lzh commented 4 months ago
nonzero(as_tuple=True)在入参全False时返回包含两个shape为0的tensor的元组,dtype固定为int64 ![image](/attachments/f234e524-88f2-4f76-8356-be412bc6937e)
zoulq reviewed 4 months ago
mindtorch/torch/tensor.py
@@ -1175,0 +1174,4 @@
if input_x.numel() == 0:
input_shape = input_x.shape
new_shape = sizes[:-len(input_shape)] + tuple(np.array(sizes[-len(input_shape):]) * np.array(input_shape))
output = tensor([]).reshape(new_shape)
zoulq commented 4 months ago
为什么不能直接创建指定shape的空tensor?
lzh commented 4 months ago
已修改
zoulq reviewed 4 months ago
mindtorch/torch/tensor.py
@@ -1672,2 +1674,2 @@
warning(warning_msg)
output = input_ms.transpose()
if input_ms.numel() == 0:
output = input_ms.reshape(input_ms.shape[::-1])
zoulq commented 4 months ago
空tensor不要用reshape了
lzh commented 4 months ago
已修改
zoulq reviewed 4 months ago
mindtorch/torch/tensor.py
@@ -1674,0 +1675,4 @@
output = input_ms.reshape(input_ms.shape[::-1])
else:
if input_ms.ndim <= 2:
warning_msg = ("The use of Tensor.T() on tensors of dimension other than 2 to reverse "
zoulq commented 4 months ago
这个告警有什么意义?
lzh commented 4 months ago
与torch对标:![image](/attachments/26b6fc16-2dac-4ea3-beb5-f322e7888c10)
zoulq reviewed 4 months ago
testing/ut/pytorch/functional/test_other.py
@@ -86,3 +86,3 @@
ms_out = ms_torch.nonzero(ms_tensor, as_tuple=True)

for i in range(len(ms_out)):
for i in range(len(torch_out)):
zoulq commented 4 months ago
这个有什么区别?理论上两个len是一样的,如果存在两个不一样的场景,可以在前面加上len(ms_out) == len(torch_out)的判断
lzh commented 4 months ago
已改为用param_compare,会比较结果长度
Erpim reviewed 4 months ago
@@ -125,1 +116,3 @@
assert ms_out[i].numpy().dtype == torch_out[i].numpy().dtype
param_compare(torch_out, ms_out)

def test_nonzero6():
Erpim commented 4 months ago
如果是3维输入呢?
lzh commented 4 months ago
验证之后发现tuple中包含的空tensor个数与input维度数一致,已修改
lzh commented 4 months ago
已增加新用例看护
Erpim reviewed 4 months ago
mindtorch/torch/tensor.py
@@ -1673,2 +1675,2 @@
warning(warning_msg)
output = input_ms.transpose()
if input_ms.numel() == 0:
output = Tensor(*(input_ms.shape[::-1]), inner=False)
Erpim commented 4 months ago
inner默认就是false,不用加,inner是内部用法
lzh commented 4 months ago
已修改
Erpim merged commit d25ee430a4 into master 4 months ago
The pull request has been merged as d25ee430a4.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.