From 8252a5a118c03f3b2c537ab63b9326d881062f3d Mon Sep 17 00:00:00 2001 From: co63oc Date: Thu, 21 Dec 2023 09:16:25 +0800 Subject: [PATCH] Fix --- tests/test_Tensor_index_fill.py | 2 +- tests/test_Tensor_index_fill_.py | 2 +- tests/test_Tensor_masked_fill.py | 2 +- tests/test_Tensor_masked_fill_.py | 2 +- tests/test_Tensor_signbit.py | 4 +-- tests/test_combinations.py | 4 +-- tests/test_histogramdd.py | 4 +-- tests/test_hypot.py | 2 +- tests/test_nn_Module_type.py | 4 +-- ...r_scheduler_CosineAnnealingWarmRestarts.py | 31 +++++++++---------- tests/test_optim_lr_scheduler_LinearLR.py | 28 ++++++++++------- tests/test_signbit.py | 16 +++++----- 12 files changed, 52 insertions(+), 49 deletions(-) diff --git a/tests/test_Tensor_index_fill.py b/tests/test_Tensor_index_fill.py index 159082842..c6a1a9b96 100644 --- a/tests/test_Tensor_index_fill.py +++ b/tests/test_Tensor_index_fill.py @@ -51,7 +51,7 @@ def test_case_3(): indices = torch.tensor([0, 1]) dim = 0 value = -1 - result = torch.eye(3, 4).index_fill(dim, indices, value) + result = torch.eye(3, 4).index_fill(index=indices, dim=dim, value=value) """ ) obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_index_fill_.py b/tests/test_Tensor_index_fill_.py index e3579a2da..82bccf538 100644 --- a/tests/test_Tensor_index_fill_.py +++ b/tests/test_Tensor_index_fill_.py @@ -53,7 +53,7 @@ def test_case_3(): indices = torch.tensor([0, 1]) dim = 0 value = -1 - result = x.index_fill_(dim, indices, value) + result = x.index_fill_(index=indices, dim=dim, value=value) """ ) obj.run(pytorch_code, ["result", "x"]) diff --git a/tests/test_Tensor_masked_fill.py b/tests/test_Tensor_masked_fill.py index 755444d1b..9d96aac74 100644 --- a/tests/test_Tensor_masked_fill.py +++ b/tests/test_Tensor_masked_fill.py @@ -73,7 +73,7 @@ def test_case_5(): import torch a = torch.Tensor([[1.0,0.2], [0.3,0.4]]) b = torch.Tensor([[1,0], [1,1]]) - result = a.masked_fill(value=0.1, mask=b==1) + result = a.masked_fill(b==1, 0.1) """ ) obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_masked_fill_.py b/tests/test_Tensor_masked_fill_.py index 2394360c7..e1d7bc171 100644 --- a/tests/test_Tensor_masked_fill_.py +++ b/tests/test_Tensor_masked_fill_.py @@ -73,7 +73,7 @@ def test_case_5(): import torch a = torch.Tensor([[1.0,0.2], [0.3,0.4]]) b = torch.Tensor([[1,0], [1,1]]) - result = a.masked_fill_(value=0.1, mask=b==1) + result = a.masked_fill_(b==1, 0.1) """ ) obj.run(pytorch_code, ["result", "a"]) diff --git a/tests/test_Tensor_signbit.py b/tests/test_Tensor_signbit.py index b5cad33ec..ced4f975f 100644 --- a/tests/test_Tensor_signbit.py +++ b/tests/test_Tensor_signbit.py @@ -23,7 +23,7 @@ def test_case_1(): pytorch_code = textwrap.dedent( """ import torch - x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype='float32') + x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype=torch.float32) result = x.signbit() """ ) @@ -34,7 +34,7 @@ def test_case_2(): pytorch_code = textwrap.dedent( """ import torch - x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype='float64') + x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype=torch.float64) result = x.signbit() """ ) diff --git a/tests/test_combinations.py b/tests/test_combinations.py index e6fa50ac6..ec26d0efa 100644 --- a/tests/test_combinations.py +++ b/tests/test_combinations.py @@ -25,7 +25,7 @@ def test_case_1(): """ import torch x = torch.tensor([1, 2, 3], dtype=torch.int32) - result = torch.combinations(input=x, r=2) + result = torch.combinations(input=x) """ ) obj.run(pytorch_code, ["result"]) @@ -36,7 +36,7 @@ def test_case_2(): """ import torch x = torch.tensor([1, 2, 3], dtype=torch.int32) - result = torch.combinations(x, r=2) + result = torch.combinations(x) """ ) obj.run(pytorch_code, ["result"]) diff --git a/tests/test_histogramdd.py b/tests/test_histogramdd.py index 20d4cce1d..17fc07d94 100644 --- a/tests/test_histogramdd.py +++ b/tests/test_histogramdd.py @@ -26,7 +26,7 @@ def test_case_1(): x = torch.tensor([[0., 1.], [1., 0.], [2.,0.], [2., 2.]]) bins = [3,3] weights = torch.tensor([1., 2., 4., 8.]) - result = torch.histogramdd(x, bins=bins, weight=weights) + result = torch.histogramdd(x, bins=bins) """ ) obj.run(pytorch_code, ["result"]) @@ -39,7 +39,7 @@ def test_case_2(): x = torch.tensor([[0., 1.], [1., 0.], [2.,0.], [2., 2.]]) bins = [3,3] weights = torch.tensor([1., 2., 4., 8.]) - result = torch.histogramdd(input=x, bins=bins, weight=weights) + result = torch.histogramdd(input=x, bins=bins) """ ) obj.run(pytorch_code, ["result"]) diff --git a/tests/test_hypot.py b/tests/test_hypot.py index 99132f2fa..e3cab61b4 100644 --- a/tests/test_hypot.py +++ b/tests/test_hypot.py @@ -49,7 +49,7 @@ def test_case_3(): a = torch.tensor([1., 2, 3]) b = torch.tensor([4., 5, 6]) out = torch.tensor([4., 5, 6]) - result = torch.hypot(input=a, other=b, out=out) + result = torch.hypot(other=b, input=a, out=out) """ ) obj.run(pytorch_code, ["out"]) diff --git a/tests/test_nn_Module_type.py b/tests/test_nn_Module_type.py index 06f743210..a38c4acfe 100644 --- a/tests/test_nn_Module_type.py +++ b/tests/test_nn_Module_type.py @@ -33,8 +33,8 @@ def test_case_1(): obj.run(pytorch_code, ["result"]) -# Will match torch.nn.Module, the named parameter "dst_type" cannot be resolved. -def _test_case_2(): +# Will match torch.Tensor.type to resolve "dst_type" parameter. +def test_case_2(): pytorch_code = textwrap.dedent( """ import torch diff --git a/tests/test_optim_lr_scheduler_CosineAnnealingWarmRestarts.py b/tests/test_optim_lr_scheduler_CosineAnnealingWarmRestarts.py index 91bfcf098..fb6a9f90a 100644 --- a/tests/test_optim_lr_scheduler_CosineAnnealingWarmRestarts.py +++ b/tests/test_optim_lr_scheduler_CosineAnnealingWarmRestarts.py @@ -15,14 +15,14 @@ import textwrap from apibase import APIBase -from lr_scheduler_helper import generate_torch_code +from lr_scheduler_helper import generate_lr_scheduler_test_code obj = APIBase("torch.optim.lr_scheduler.CosineAnnealingWarmRestarts") def test_case_1(): pytorch_code = textwrap.dedent( - generate_torch_code( + generate_lr_scheduler_test_code( "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(sgd, 10)" ) ) @@ -31,8 +31,8 @@ def test_case_1(): def test_case_2(): pytorch_code = textwrap.dedent( - generate_torch_code( - "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(sgd, T_0=10)" + generate_lr_scheduler_test_code( + "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(sgd, T_0=10, T_mult=1)" ) ) obj.run(pytorch_code, ["result1", "result2"], rtol=1.0e-5) @@ -40,8 +40,8 @@ def test_case_2(): def test_case_3(): pytorch_code = textwrap.dedent( - generate_torch_code( - "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(optimizer=sgd, T_0=10)" + generate_lr_scheduler_test_code( + "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(T_mult=1, optimizer=sgd, T_0=10)" ) ) obj.run(pytorch_code, ["result1", "result2"], rtol=1.0e-5) @@ -49,8 +49,8 @@ def test_case_3(): def test_case_4(): pytorch_code = textwrap.dedent( - generate_torch_code( - "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(optimizer=sgd, T_0=10, eta_min=0.0, last_epoch=-1, verbose=True)" + generate_lr_scheduler_test_code( + "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(optimizer=sgd, T_0=10, T_mult=1, eta_min=0.0, last_epoch=-1, verbose=True)" ) ) obj.run(pytorch_code, ["result1", "result2"], rtol=1.0e-5) @@ -58,8 +58,8 @@ def test_case_4(): def test_case_5(): pytorch_code = textwrap.dedent( - generate_torch_code( - "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(optimizer=sgd, T_0=10, eta_min=0.05, verbose=True)" + generate_lr_scheduler_test_code( + "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(optimizer=sgd, T_0=10, T_mult=1, eta_min=0.05, verbose=True)" ) ) obj.run(pytorch_code, ["result1", "result2"], rtol=1.0e-5) @@ -67,22 +67,19 @@ def test_case_5(): def test_case_6(): pytorch_code = textwrap.dedent( - generate_torch_code( + generate_lr_scheduler_test_code( "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(sgd, 10, 1, 1.0, -1, False)" ) ) obj.run(pytorch_code, ["result1", "result2"], rtol=1.0e-5) -# reference: https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/optimizer/lr/CosineAnnealingDecay_en.html -# note: paddle not support restart -# paddle result has diff with pytorch result def test_case_7(): pytorch_code = textwrap.dedent( - generate_torch_code( + generate_lr_scheduler_test_code( [ - "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(optimizer=sgd, T_0=10, eta_min=0.0, last_epoch=-1, verbose=False)", - "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(optimizer=sgd, T_0=10, eta_min=0.0, last_epoch=scheduler_1.last_epoch, verbose=False)", + "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(optimizer=sgd, T_0=10, T_mult=1, eta_min=0.0, last_epoch=-1, verbose=False)", + "torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(optimizer=sgd, T_0=10, T_mult=2, eta_min=0.0, last_epoch=scheduler_1.last_epoch, verbose=False)", ] ) ) diff --git a/tests/test_optim_lr_scheduler_LinearLR.py b/tests/test_optim_lr_scheduler_LinearLR.py index f39c8ab8d..8d9c7bb37 100644 --- a/tests/test_optim_lr_scheduler_LinearLR.py +++ b/tests/test_optim_lr_scheduler_LinearLR.py @@ -15,21 +15,23 @@ import textwrap from apibase import APIBase -from lr_scheduler_helper import generate_torch_code +from lr_scheduler_helper import generate_lr_scheduler_test_code obj = APIBase("torch.optim.lr_scheduler.LinearLR") def test_case_1(): pytorch_code = textwrap.dedent( - generate_torch_code("torch.optim.lr_scheduler.LinearLR(sgd, verbose=True)") + generate_lr_scheduler_test_code( + "torch.optim.lr_scheduler.LinearLR(sgd, verbose=True)" + ) ) obj.run(pytorch_code, ["result1", "result2"], rtol=1.0e-5) def test_case_2(): pytorch_code = textwrap.dedent( - generate_torch_code( + generate_lr_scheduler_test_code( "torch.optim.lr_scheduler.LinearLR(sgd, start_factor=0.05, end_factor=1.0)" ) ) @@ -38,21 +40,25 @@ def test_case_2(): def test_case_3(): pytorch_code = textwrap.dedent( - generate_torch_code("torch.optim.lr_scheduler.LinearLR(sgd, total_iters=3)") + generate_lr_scheduler_test_code( + "torch.optim.lr_scheduler.LinearLR(sgd, total_iters=3)" + ) ) obj.run(pytorch_code, ["result1", "result2"], rtol=1.0e-5) def test_case_4(): pytorch_code = textwrap.dedent( - generate_torch_code("torch.optim.lr_scheduler.LinearLR(sgd, 0.05, 1)") + generate_lr_scheduler_test_code( + "torch.optim.lr_scheduler.LinearLR(sgd, 0.05, 1)" + ) ) obj.run(pytorch_code, ["result1", "result2"], rtol=1.0e-5) def test_case_5(): pytorch_code = textwrap.dedent( - generate_torch_code( + generate_lr_scheduler_test_code( "torch.optim.lr_scheduler.LinearLR(optimizer=sgd, start_factor=0.05, end_factor=1.0, total_iters=3)" ) ) @@ -61,7 +67,7 @@ def test_case_5(): def test_case_6(): pytorch_code = textwrap.dedent( - generate_torch_code( + generate_lr_scheduler_test_code( "torch.optim.lr_scheduler.LinearLR(start_factor=0.05, end_factor=1.0, total_iters=3, optimizer=sgd)" ) ) @@ -70,7 +76,7 @@ def test_case_6(): def test_case_7(): pytorch_code = textwrap.dedent( - generate_torch_code( + generate_lr_scheduler_test_code( "torch.optim.lr_scheduler.LinearLR(sgd, 0.05, 1.0, 3, -1, False)" ) ) @@ -79,7 +85,7 @@ def test_case_7(): def test_case_8(): pytorch_code = textwrap.dedent( - generate_torch_code( + generate_lr_scheduler_test_code( "torch.optim.lr_scheduler.LinearLR(optimizer=sgd, start_factor=0.05, end_factor=1.0, total_iters=3, last_epoch=-1, verbose=False)" ) ) @@ -88,7 +94,7 @@ def test_case_8(): def test_case_9(): pytorch_code = textwrap.dedent( - generate_torch_code( + generate_lr_scheduler_test_code( [ "torch.optim.lr_scheduler.LinearLR(optimizer=sgd, start_factor=0.05, end_factor=1.0, total_iters=3, last_epoch=-1, verbose=False)", "torch.optim.lr_scheduler.LinearLR(optimizer=sgd, start_factor=0.05, end_factor=1.0, total_iters=3, last_epoch=scheduler_1.last_epoch, verbose=False)", @@ -100,6 +106,6 @@ def test_case_9(): def test_case_10(): pytorch_code = textwrap.dedent( - generate_torch_code("torch.optim.lr_scheduler.LinearLR(sgd)") + generate_lr_scheduler_test_code("torch.optim.lr_scheduler.LinearLR(sgd)") ) obj.run(pytorch_code, ["result1", "result2"], rtol=1.0e-5) diff --git a/tests/test_signbit.py b/tests/test_signbit.py index 3ecc5aee4..bb87afebc 100644 --- a/tests/test_signbit.py +++ b/tests/test_signbit.py @@ -23,7 +23,7 @@ def test_case_1(): pytorch_code = textwrap.dedent( """ import torch - x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype='float32') + x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype=torch.float32) result = torch.signbit(x) """ ) @@ -34,7 +34,7 @@ def test_case_2(): pytorch_code = textwrap.dedent( """ import torch - x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype='float32') + x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype=torch.float32) result = torch.signbit(input=x) """ ) @@ -45,8 +45,8 @@ def test_case_3(): pytorch_code = textwrap.dedent( """ import torch - x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype='float32') - out = torch.tensor([]) + x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype=torch.float32) + out = torch.tensor([], dtype=torch.bool) result = torch.signbit(out=out, input=x) """ ) @@ -57,8 +57,8 @@ def test_case_4(): pytorch_code = textwrap.dedent( """ import torch - x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype='float32') - out = torch.tensor([]) + x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype=torch.float32) + out = torch.tensor([], dtype=torch.bool) result = torch.signbit(input=x, out=out) """ ) @@ -69,8 +69,8 @@ def test_case_5(): pytorch_code = textwrap.dedent( """ import torch - x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype='float32') - out = torch.tensor([]) + x = torch.tensor([-0., 1.1, -2.1, 0., 2.5], dtype=torch.float32) + out = torch.tensor([], dtype=torch.bool) result = torch.signbit(x, out=out) """ )