From 75a684ca940d5dec19dec0da406b2b1bba356228 Mon Sep 17 00:00:00 2001 From: Xuxuanang <1829994704@qq.com> Date: Fri, 23 Aug 2024 15:12:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E6=B5=8Bcase=E8=A6=86=E7=9B=96=20(#45?= =?UTF-8?q?3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * case add * case add * case add * case add * case add * fix testcase --- paconvert/api_mapping.json | 10 +- tests/test_cuda_amp_autocast.py | 16 ++- tests/test_diff.py | 12 +++ tests/test_distributed_rpc_shutdown.py | 105 ++++++++++++++++++-- tests/test_distributions_AffineTransform.py | 42 ++++++++ tests/test_distributions_ExpTransform.py | 24 +++++ tests/test_distributions_PowerTransform.py | 36 +++++++ tests/test_histogramdd.py | 13 +++ tests/test_hub_download_url_to_file.py | 33 ++++++ tests/test_inference_mode.py | 14 +++ tests/test_median.py | 25 ++++- tests/test_nanmedian.py | 50 +++++++--- tests/test_nn_CrossEntropyLoss.py | 48 ++++++++- tests/test_nn_KLDivLoss.py | 45 +++++++++ tests/test_nn_LayerNorm.py | 13 +++ tests/test_nn_functional_grid_sample.py | 42 ++++++++ tests/test_nn_functional_kl_div.py | 26 +++++ tests/test_nn_functional_softmin.py | 26 +++++ tests/test_nn_init_xavier_normal_.py | 24 +++++ 19 files changed, 569 insertions(+), 35 deletions(-) diff --git a/paconvert/api_mapping.json b/paconvert/api_mapping.json index 6a7ca1037..c4aa8c614 100644 --- a/paconvert/api_mapping.json +++ b/paconvert/api_mapping.json @@ -6029,7 +6029,11 @@ "args_list": [ "graceful", "timeout" - ] + ], + "kwargs_change": { + "graceful": "", + "timeout": "" + } }, "torch.distributed.scatter": { "Matcher": "ScatterMatcher", @@ -11808,8 +11812,8 @@ "input", "grid", "mode", - "align_corners", - "padding_mode" + "padding_mode", + "align_corners" ], "kwargs_change": { "input": "x" diff --git a/tests/test_cuda_amp_autocast.py b/tests/test_cuda_amp_autocast.py index 672ff3582..ffdfeb05f 100644 --- a/tests/test_cuda_amp_autocast.py +++ b/tests/test_cuda_amp_autocast.py @@ -90,9 +90,8 @@ def test_case_4(): @pytest.mark.skipif( - condition=not paddle.device.is_compiled_with_cuda() - or not paddle.device.cuda.get_device_properties(0).major >= 8, - reason="computational capabilities less 8", + condition=not paddle.device.is_compiled_with_cuda(), + reason="can only run on paddle with CUDA", ) def test_case_5(): pytorch_code = textwrap.dedent( @@ -110,11 +109,9 @@ def test_case_5(): obj.run(pytorch_code, ["result"]) -# generated by validate_unittest autofix, based on test_case_5 @pytest.mark.skipif( - condition=not paddle.device.is_compiled_with_cuda() - or not paddle.device.cuda.get_device_properties(0).major >= 8, - reason="computational capabilities less 8", + condition=not paddle.device.is_compiled_with_cuda(), + reason="can only run on paddle with CUDA", ) def test_case_6(): pytorch_code = textwrap.dedent( @@ -134,9 +131,8 @@ def test_case_6(): # generated by validate_unittest autofix, based on test_case_5 @pytest.mark.skipif( - condition=not paddle.device.is_compiled_with_cuda() - or not paddle.device.cuda.get_device_properties(0).major >= 8, - reason="computational capabilities less 8", + condition=not paddle.device.is_compiled_with_cuda(), + reason="can only run on paddle with CUDA", ) def test_case_7(): pytorch_code = textwrap.dedent( diff --git a/tests/test_diff.py b/tests/test_diff.py index 3d657e05c..55eab72b2 100644 --- a/tests/test_diff.py +++ b/tests/test_diff.py @@ -130,3 +130,15 @@ def test_case_9(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_10(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([1, 3, 2]) + b = torch.tensor([4, 5]) + result = torch.diff(x, 1, 0, b, b) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_distributed_rpc_shutdown.py b/tests/test_distributed_rpc_shutdown.py index 1b0eacb0a..11d17750f 100644 --- a/tests/test_distributed_rpc_shutdown.py +++ b/tests/test_distributed_rpc_shutdown.py @@ -14,17 +14,11 @@ import textwrap -import paddle -import pytest from apibase import APIBase obj = APIBase("torch.distributed.rpc.shutdown") -@pytest.mark.skipif( - condition=paddle.is_compiled_with_cinn(), - reason="WITH_RPC = OFF, if WITH_CINN = ON.", -) def test_case_1(): pytorch_code = textwrap.dedent( """ @@ -56,3 +50,102 @@ def test_case_1(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import os + import torch + import socket + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + start = 25000 + end = 30000 + for port in range(start, end): + try: + s.bind(('localhost', port)) + s.close() + break + except socket.error: + continue + print("port: " + str(port)) + + from torch.distributed import rpc + os.environ['MASTER_ADDR'] = 'localhost' + os.environ['MASTER_PORT'] = str(port) + os.environ['PADDLE_MASTER_ENDPOINT'] = 'localhost:' + str(port) + rpc.init_rpc( + "worker1", + rank=0, + world_size=1 + ) + result = rpc.shutdown(graceful=False, timeout=2) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import os + import torch + import socket + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + start = 25000 + end = 30000 + for port in range(start, end): + try: + s.bind(('localhost', port)) + s.close() + break + except socket.error: + continue + print("port: " + str(port)) + + from torch.distributed import rpc + os.environ['MASTER_ADDR'] = 'localhost' + os.environ['MASTER_PORT'] = str(port) + os.environ['PADDLE_MASTER_ENDPOINT'] = 'localhost:' + str(port) + rpc.init_rpc( + "worker1", + rank=0, + world_size=1 + ) + result = rpc.shutdown(timeout=2, graceful=False) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import os + import torch + import socket + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + start = 25000 + end = 30000 + for port in range(start, end): + try: + s.bind(('localhost', port)) + s.close() + break + except socket.error: + continue + print("port: " + str(port)) + + from torch.distributed import rpc + os.environ['MASTER_ADDR'] = 'localhost' + os.environ['MASTER_PORT'] = str(port) + os.environ['PADDLE_MASTER_ENDPOINT'] = 'localhost:' + str(port) + rpc.init_rpc( + "worker1", + rank=0, + world_size=1 + ) + result = rpc.shutdown(True, 1) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_distributions_AffineTransform.py b/tests/test_distributions_AffineTransform.py index 150d7738e..90ab4db9b 100644 --- a/tests/test_distributions_AffineTransform.py +++ b/tests/test_distributions_AffineTransform.py @@ -45,3 +45,45 @@ def test_case_2(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + + x = torch.tensor(1.) + y = torch.tensor(2.) + affine = torch.distributions.AffineTransform(x, y, 1, 1) + result = affine.forward_shape([1, 2]) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + + x = torch.tensor(1.) + y = torch.tensor(2.) + affine = torch.distributions.AffineTransform(loc=x, scale=y, event_dim=1, cache_size=1) + result = affine.forward_shape([1, 2]) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + + x = torch.tensor(1.) + y = torch.tensor(2.) + affine = torch.distributions.AffineTransform(event_dim=1, cache_size=1, loc=x, scale=y) + result = affine.forward_shape([1, 2]) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_distributions_ExpTransform.py b/tests/test_distributions_ExpTransform.py index d8e08348b..8215f10dd 100644 --- a/tests/test_distributions_ExpTransform.py +++ b/tests/test_distributions_ExpTransform.py @@ -29,3 +29,27 @@ def test_case_1(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + + exp = torch.distributions.ExpTransform(cache_size=1) + result = exp.forward_shape([1, 2]) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + + exp = torch.distributions.ExpTransform(1) + result = exp.forward_shape([1, 2]) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_distributions_PowerTransform.py b/tests/test_distributions_PowerTransform.py index 9b62147ab..ad13efe02 100644 --- a/tests/test_distributions_PowerTransform.py +++ b/tests/test_distributions_PowerTransform.py @@ -29,3 +29,39 @@ def test_case_1(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + + power = torch.distributions.PowerTransform(exponent=torch.tensor(2.),cache_size=1) + result = power.forward_shape([1, 2]) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + + power = torch.distributions.PowerTransform(cache_size=1, exponent=torch.tensor(2.)) + result = power.forward_shape([1, 2]) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + + power = torch.distributions.PowerTransform(torch.tensor(2.), 0) + result = power.forward_shape([1, 2]) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_histogramdd.py b/tests/test_histogramdd.py index f0cea451f..6399238bd 100644 --- a/tests/test_histogramdd.py +++ b/tests/test_histogramdd.py @@ -87,3 +87,16 @@ def test_case_5(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_6(): + pytorch_code = textwrap.dedent( + """ + import torch + 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) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_hub_download_url_to_file.py b/tests/test_hub_download_url_to_file.py index 9e235aa24..d93e6ba76 100644 --- a/tests/test_hub_download_url_to_file.py +++ b/tests/test_hub_download_url_to_file.py @@ -65,3 +65,36 @@ def test_case_3(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.hub.download_url_to_file(url='https://paddle-paconvert.bj.bcebos.com/model.params', dst='/tmp/temporary_file', + hash_prefix="e1bf0a03102811bb2168e9952fe4edfa09cceb3343278bd4e5876b33b6889e9b", progress=False) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.hub.download_url_to_file(url='https://paddle-paconvert.bj.bcebos.com/model.params', dst='/tmp/temporary_file', + hash_prefix="e1bf0a03102811bb2168e9952fe4edfa09cceb3343278bd4e5876b33b6889e9b", progress=False) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_6(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.hub.download_url_to_file(dst='/tmp/temporary_file', + hash_prefix="e1bf0a03102811bb2168e9952fe4edfa09cceb3343278bd4e5876b33b6889e9b", url='https://paddle-paconvert.bj.bcebos.com/model.params', progress=False) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_inference_mode.py b/tests/test_inference_mode.py index 206cc733f..85cc22716 100644 --- a/tests/test_inference_mode.py +++ b/tests/test_inference_mode.py @@ -73,3 +73,17 @@ def test_case_4(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.ones(1, 2, 3, requires_grad=True) + @torch.inference_mode(mode= False) + def doubler(x): + return x * 2 + result = (doubler(x).requires_grad, doubler(x)) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_median.py b/tests/test_median.py index 0c4745be1..9a7b06792 100644 --- a/tests/test_median.py +++ b/tests/test_median.py @@ -78,7 +78,7 @@ def test_case_5(): import torch input = torch.tensor([[1.4907, 1.0593, 1.5696], [1.4907, 1.0593, 1.5696]]) out = (torch.tensor([[1.1], [1.2]]), torch.tensor([[1], [2]])) - result = torch.median(input, dim=1, keepdim=True, out=out) + result = torch.median(input=input, dim=1, keepdim=True, out=out) """ ) obj.run(pytorch_code, ["result", "out"]) @@ -107,3 +107,26 @@ def test_case_7(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_8(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1.4907, 1.0593, 1.5696], [1.4907, 1.0593, 1.5696]]) + result = torch.median(input, 1, True) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_9(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1.4907, 1.0593, 1.5696], [1.4907, 1.0593, 1.5696]]) + out = (torch.tensor([[1.1], [1.2]]), torch.tensor([[1], [2]])) + result = torch.median(keepdim=True, out=out, input=input, dim=1) + """ + ) + obj.run(pytorch_code, ["result", "out"]) diff --git a/tests/test_nanmedian.py b/tests/test_nanmedian.py index c375ccc3a..5cfc7b15e 100644 --- a/tests/test_nanmedian.py +++ b/tests/test_nanmedian.py @@ -38,10 +38,7 @@ def test_case_2(): result = torch.nanmedian(input, 1) """ ) - obj.run( - pytorch_code, - ["result"], - ) + obj.run(pytorch_code, ["result"]) def test_case_3(): @@ -63,10 +60,7 @@ def test_case_4(): result = torch.nanmedian(input, dim=1, keepdim=True) """ ) - obj.run( - pytorch_code, - ["result"], - ) + obj.run(pytorch_code, ["result"]) def test_case_5(): @@ -78,10 +72,7 @@ def test_case_5(): result = torch.nanmedian(input, dim=1, keepdim=True, out=out) """ ) - obj.run( - pytorch_code, - ["result"], - ) + obj.run(pytorch_code, ["result", "out"]) def test_case_6(): @@ -93,3 +84,38 @@ def test_case_6(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_7(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1.4907, 1.0593, 1.5696], [1.4907, 1.0593, 1.5696]]) + out = (torch.tensor([[1.1], [1.2]]), torch.tensor([[1], [2]])) + result = torch.nanmedian(input=input, dim=1, keepdim=True, out=out) + """ + ) + obj.run(pytorch_code, ["result", "out"]) + + +def test_case_8(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1.4907, 1.0593, 1.5696], [1.4907, 1.0593, 1.5696]]) + result = torch.nanmedian(input, 1, True) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_9(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1.4907, 1.0593, 1.5696], [1.4907, 1.0593, 1.5696]]) + out = (torch.tensor([[1.1], [1.2]]), torch.tensor([[1], [2]])) + result = torch.nanmedian(input=input, keepdim=True, dim=1, out=out) + """ + ) + obj.run(pytorch_code, ["result", "out"]) diff --git a/tests/test_nn_CrossEntropyLoss.py b/tests/test_nn_CrossEntropyLoss.py index 06c03e5d0..95a8af628 100644 --- a/tests/test_nn_CrossEntropyLoss.py +++ b/tests/test_nn_CrossEntropyLoss.py @@ -134,7 +134,49 @@ def test_case_8(): result = loss(input, target) """ ) - obj.run( - pytorch_code, - ["result"], + obj.run(pytorch_code, ["result"]) + + +def test_case_9(): + pytorch_code = textwrap.dedent( + """ + import torch + import torch.nn as nn + weight = torch.Tensor([1, 3, 4, 3, 2]) + input = torch.ones(3, 5) + target = torch.ones(3, dtype=torch.long) + loss = nn.CrossEntropyLoss(weight=weight, size_average=False, ignore_index=0, reduce=True, reduction='sum', label_smoothing=0.1) + result = loss(input, target) + """ ) + obj.run(pytorch_code, ["result"]) + + +def test_case_10(): + pytorch_code = textwrap.dedent( + """ + import torch + import torch.nn as nn + weight = torch.Tensor([1, 3, 4, 3, 2]) + input = torch.ones(3, 5) + target = torch.ones(3, dtype=torch.long) + loss = nn.CrossEntropyLoss(weight, False, 0, True, 'sum', 0.1) + result = loss(input, target) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_11(): + pytorch_code = textwrap.dedent( + """ + import torch + import torch.nn as nn + weight = torch.Tensor([1, 3, 4, 3, 2]) + input = torch.ones(3, 5) + target = torch.ones(3, dtype=torch.long) + loss = nn.CrossEntropyLoss(weight=weight, label_smoothing=0.1, reduce=True, size_average=False, ignore_index=0, reduction='sum') + result = loss(input, target) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_nn_KLDivLoss.py b/tests/test_nn_KLDivLoss.py index b6e6dc7a6..e9369da5f 100644 --- a/tests/test_nn_KLDivLoss.py +++ b/tests/test_nn_KLDivLoss.py @@ -152,3 +152,48 @@ def test_case_9(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_10(): + pytorch_code = textwrap.dedent( + """ + import torch + import torch.nn as nn + input = torch.tensor([[-1.2837, -0.0297, 0.0355], + [ 0.9112, -1.7526, -0.4061]]) + target = torch.tensor([[1.,2.,3.],[4.,5.,6.]]) + loss = torch.nn.KLDivLoss(size_average=False, reduce=True, reduction='batchmean', log_target=False) + result = loss(input,target) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_11(): + pytorch_code = textwrap.dedent( + """ + import torch + import torch.nn as nn + input = torch.tensor([[-1.2837, -0.0297, 0.0355], + [ 0.9112, -1.7526, -0.4061]]) + target = torch.tensor([[1.,2.,3.],[4.,5.,6.]]) + loss = torch.nn.KLDivLoss(False, True, 'batchmean', False) + result = loss(input,target) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_12(): + pytorch_code = textwrap.dedent( + """ + import torch + import torch.nn as nn + input = torch.tensor([[-1.2837, -0.0297, 0.0355], + [ 0.9112, -1.7526, -0.4061]]) + target = torch.tensor([[1.,2.,3.],[4.,5.,6.]]) + loss = torch.nn.KLDivLoss(reduction='batchmean', log_target=False, size_average=False, reduce=True, ) + result = loss(input,target) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_nn_LayerNorm.py b/tests/test_nn_LayerNorm.py index b7ebe0e29..bdc92de74 100644 --- a/tests/test_nn_LayerNorm.py +++ b/tests/test_nn_LayerNorm.py @@ -123,3 +123,16 @@ def test_case_8(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_9(): + pytorch_code = textwrap.dedent( + """ + import torch.nn as nn + import torch + m = nn.LayerNorm(device="cpu", dtype=torch.float32, normalized_shape=10, eps=1e-05, elementwise_affine=False) + input = torch.ones(2, 5, 10) + result = m(input) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_nn_functional_grid_sample.py b/tests/test_nn_functional_grid_sample.py index b1c2b53df..1171b1c70 100644 --- a/tests/test_nn_functional_grid_sample.py +++ b/tests/test_nn_functional_grid_sample.py @@ -91,3 +91,45 @@ def test_case_5(): """ ) obj.run(pytorch_code, ["result"], check_value=False, check_stop_gradient=False) + + +def test_case_6(): + pytorch_code = textwrap.dedent( + """ + import torch + import torch.nn.functional as F + x = torch.tensor([[[[[-0.6, 0.8, -0.5], [-0.5, 0.2, 1.2], [ 1.4, 0.3, -0.2]]]]]) + grid = torch.tensor([[[[[ 0.2, 0.2, 0.3],[-0.4, 0.2, -0.3],[-0.9, 0.2, 0.3],[-0.9, 0.9, -0.6]], + [[ 0.2, 0.2, 0.3],[-0.4, 0.2, -0.3],[-0.9, 0.2, 0.3],[-0.9, 0.9, -0.6]]]]]) + result = F.grid_sample(input=x, grid=grid, mode='bilinear', padding_mode="border", align_corners=True) + """ + ) + obj.run(pytorch_code, ["result"], check_value=False, check_stop_gradient=False) + + +def test_case_7(): + pytorch_code = textwrap.dedent( + """ + import torch + import torch.nn.functional as F + x = torch.tensor([[[[[-0.6, 0.8, -0.5], [-0.5, 0.2, 1.2], [ 1.4, 0.3, -0.2]]]]]) + grid = torch.tensor([[[[[ 0.2, 0.2, 0.3],[-0.4, 0.2, -0.3],[-0.9, 0.2, 0.3],[-0.9, 0.9, -0.6]], + [[ 0.2, 0.2, 0.3],[-0.4, 0.2, -0.3],[-0.9, 0.2, 0.3],[-0.9, 0.9, -0.6]]]]]) + result = F.grid_sample(input=x, padding_mode="border", align_corners=True, grid=grid, mode='bilinear') + """ + ) + obj.run(pytorch_code, ["result"], check_value=False, check_stop_gradient=False) + + +def test_case_8(): + pytorch_code = textwrap.dedent( + """ + import torch + import torch.nn.functional as F + x = torch.tensor([[[[[-0.6, 0.8, -0.5], [-0.5, 0.2, 1.2], [ 1.4, 0.3, -0.2]]]]]) + grid = torch.tensor([[[[[ 0.2, 0.2, 0.3],[-0.4, 0.2, -0.3],[-0.9, 0.2, 0.3],[-0.9, 0.9, -0.6]], + [[ 0.2, 0.2, 0.3],[-0.4, 0.2, -0.3],[-0.9, 0.2, 0.3],[-0.9, 0.9, -0.6]]]]]) + result = F.grid_sample(x, grid, 'bilinear', "border", True) + """ + ) + obj.run(pytorch_code, ["result"], check_value=False, check_stop_gradient=False) diff --git a/tests/test_nn_functional_kl_div.py b/tests/test_nn_functional_kl_div.py index 66d44bda0..ef88ee407 100644 --- a/tests/test_nn_functional_kl_div.py +++ b/tests/test_nn_functional_kl_div.py @@ -173,3 +173,29 @@ def test_case_12(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_13(): + pytorch_code = textwrap.dedent( + """ + import torch.nn.functional as F + import torch + input = torch.arange(0, 15,dtype=torch.float32, requires_grad=True).reshape((3, 5)) + target = torch.arange(100, 160, 4, dtype=torch.float32, requires_grad=True).reshape((3, 5)) + 4 + result = F.kl_div(input, target, True, True, reduction="sum", log_target=True) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_14(): + pytorch_code = textwrap.dedent( + """ + import torch.nn.functional as F + import torch + input = torch.arange(0, 15,dtype=torch.float32, requires_grad=True).reshape((3, 5)) + target = torch.arange(100, 160, 4, dtype=torch.float32, requires_grad=True).reshape((3, 5)) + 4 + result = F.kl_div(input=input, target=target, reduction="sum", log_target=True, size_average=False, reduce=True) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_nn_functional_softmin.py b/tests/test_nn_functional_softmin.py index 08a99e4af..d368ea853 100644 --- a/tests/test_nn_functional_softmin.py +++ b/tests/test_nn_functional_softmin.py @@ -69,3 +69,29 @@ def test_case_4(): """ ) obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + import torch.nn.functional as F + input = torch.tensor([[-1.2837, -0.0297, 0.0355], + [ 0.9112, -1.7526, -0.4061]]) + result = F.softmin(input, -1, 3, torch.float64) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_6(): + pytorch_code = textwrap.dedent( + """ + import torch + import torch.nn.functional as F + input = torch.tensor([[-1.2837, -0.0297, 0.0355], + [ 0.9112, -1.7526, -0.4061]]) + result = F.softmin(_stacklevel=3, dtype=torch.float64, input=input, dim=-1) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_nn_init_xavier_normal_.py b/tests/test_nn_init_xavier_normal_.py index e2a37bf42..e90a744a0 100644 --- a/tests/test_nn_init_xavier_normal_.py +++ b/tests/test_nn_init_xavier_normal_.py @@ -53,3 +53,27 @@ def test_case_3(): """ ) obj.run(pytorch_code, ["result"], check_value=False) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + conv = torch.nn.Conv2d(3, 6, (3, 3)) + torch.nn.init.xavier_normal_(conv.weight, 2.) + result = conv.weight + """ + ) + obj.run(pytorch_code, ["result"], check_value=False) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + conv = torch.nn.Conv2d(3, 6, (3, 3)) + torch.nn.init.xavier_normal_(gain=2., tensor=conv.weight) + result = conv.weight + """ + ) + obj.run(pytorch_code, ["result"], check_value=False)