Skip to content

Commit 0b13b5c

Browse files
authored
[Unity] Enhance Torch-consistency in rehsape (#16360)
This PR introduces the following signature changes: - `Tensor.reshape(shape)` to `Tensor.reshape(*shape)` - `Tensor.permute_dims(axes)` to `Tensor.permute_dims(*axes)`
1 parent 155dd73 commit 0b13b5c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

python/tvm/relax/frontend/nn/_tensor_op.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ def minimum(self, other):
7878
other = _convert_scalar(other, self)
7979
return _op().minimum(self, other)
8080

81-
def reshape(self, shape):
81+
def reshape(self, *shape):
8282
return _op().reshape(self, shape)
8383

84-
def permute_dims(self, axes):
84+
def permute_dims(self, *axes):
8585
return _op().permute_dims(self, axes)
8686

8787
def repeat(self, repeats: int, axis: Optional[int] = None):

tests/python/relax/test_frontend_nn_tensor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
import numpy as np
1718
import pytest
19+
1820
import tvm
1921
import tvm.testing
2022
from tvm import relax
21-
from tvm.relax.frontend.nn import Tensor, Module, spec
23+
from tvm.relax.frontend.nn import Module, Tensor, spec
2224
from tvm.script import relax as R
2325

24-
import numpy as np
25-
2626

2727
def test_tensor_from_numpy():
2828
x = np.random.rand(1, 10)
@@ -136,8 +136,8 @@ def test(x: R.Tensor((1, 10), dtype="float32"), _io: R.Object) -> R.Tuple(R.Tens
136136
def test_tensor_op_manipulate():
137137
class Model(Module):
138138
def test(self, x: Tensor):
139-
z0 = x.reshape([2, 5, 2])
140-
z1 = x.permute_dims([2, 1, 0])
139+
z0 = x.reshape(2, 5, 2)
140+
z1 = x.permute_dims(2, 1, 0)
141141
z2 = x.repeat(2, axis=1)
142142
return (z0, z1, z2)
143143

0 commit comments

Comments
 (0)