Skip to content

Commit dc70b0c

Browse files
authored
fix q class models on OrangePi (#2211)
1 parent 8955546 commit dc70b0c

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

mindtorch/_apis/npu.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,10 @@ def clamp_scalar(value, min_value, max_value):
693693
return value
694694

695695
def cumsum(self, dim, dtype):
696-
if use_pyboost():
696+
if use_pyboost() and not ON_ORANGE_PI:
697697
return pyboost.cumsum_ext_op(self, dim, dtype)
698+
if self.shape[dim] == 0:
699+
return mindtorch.tensor([], dtype=self.dtype, device=self.device)
698700
return legacy.cum_sum(self, dim, False, False)
699701

700702
def reduce_any(input, axis, keepdims):
@@ -1275,12 +1277,16 @@ def square(input):
12751277
def lgamma(input):
12761278
return legacy.lgamma(input)
12771279

1278-
def reverse_v2(input, axis):
1279-
if isinstance(axis, int):
1280-
axis = (axis,)
1281-
if use_pyboost():
1282-
return pyboost.reverse_v2_impl(input, axis)
1283-
return legacy.reverse_v2(input, axis)
1280+
def reverse_v2(input, dims):
1281+
if isinstance(dims, int):
1282+
dims = (dims,)
1283+
if use_pyboost() and not ON_ORANGE_PI:
1284+
return pyboost.reverse_v2_impl(input, dims)
1285+
1286+
for dim in dims:
1287+
idx = arange(input.size(dim) - 1, -1, -1, None)
1288+
input = index_select(input, dim, idx)
1289+
return input
12841290

12851291
def unique_consecutive(input, return_inverse, return_counts, dim):
12861292
if use_pyboost():
@@ -1579,9 +1585,36 @@ def adaptive_avg_pool1d(input, output_size):
15791585
return legacy.adaptive_avg_pool1d(input, output_size)
15801586

15811587
def conv3d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1):
1582-
if use_pyboost():
1588+
if use_pyboost() and not ON_ORANGE_PI:
15831589
return pyboost.conv3d_ext_op(input, weight, bias, stride, padding, dilation, groups)
1584-
return legacy.conv3d(input, weight, bias, stride, padding, dilation, groups)
1590+
pad_mode = 'pad'
1591+
pad = padding
1592+
if isinstance(padding, (tuple, list)):
1593+
pad = (padding[0], padding[0], padding[1], padding[1], padding[2], padding[2])
1594+
elif isinstance(padding, int):
1595+
pad = (padding,) * 6
1596+
if not isinstance(padding, (int, tuple, list)):
1597+
pad_mode = padding
1598+
pad = (0,) * 6
1599+
1600+
out_channels = weight.shape[0]
1601+
kernel_size = weight.shape[2:]
1602+
1603+
output = legacy.conv3_d(input, weight,
1604+
out_channels,
1605+
kernel_size,
1606+
1,
1607+
pad_mode,
1608+
pad,
1609+
tuple(stride),
1610+
dilation,
1611+
groups,
1612+
"NCDHW")
1613+
1614+
if bias is not None:
1615+
output = legacy.bias_add(output, bias, 'NCHW')
1616+
return output
1617+
15851618

15861619
def outer(input, other):
15871620
if use_pyboost():

0 commit comments

Comments
 (0)