Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Hackathon 5th No.45】convert 75-81 -part #341

Merged
merged 12 commits into from
Dec 22, 2023
75 changes: 75 additions & 0 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -5345,6 +5345,30 @@
"tag"
]
},
"torch.distributions.AbsTransform": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.distribution.AbsTransform",
"args_list": [
"cache_size"
],
"kwargs_change": {
"cache_size": ""
}
},
"torch.distributions.AffineTransform": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.distribution.AffineTransform",
"args_list": [
"loc",
"scale",
"event_dim",
"cache_size"
],
"kwargs_change": {
"event_dim": "",
"cache_size": ""
}
},
"torch.distributions.Bernoulli": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.distribution.Bernoulli",
Expand Down Expand Up @@ -5471,6 +5495,11 @@
},
"torch.distributions.Distribution.sample_n": {},
"torch.distributions.Distribution.set_default_validate_args": {},
"torch.distributions.ExpTransform": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.distribution.ExpTransform",
"args_list": []
},
"torch.distributions.ExponentialFamily": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.distribution.ExponentialFamily",
Expand Down Expand Up @@ -5524,6 +5553,18 @@
"validate_args": ""
}
},
"torch.distributions.IndependentTransform": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.distribution.IndependentTransform",
"args_list": [
"base_transform",
"reinterpreted_batch_ndims"
],
"kwargs_change": {
"base_transform": "base",
"reinterpreted_batch_ndims": "reinterpreted_batch_rank"
}
},
"torch.distributions.Laplace": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.distribution.Laplace",
Expand Down Expand Up @@ -5576,6 +5617,30 @@
"validate_args": ""
}
},
"torch.distributions.PowerTransform": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.distribution.PowerTransform",
"args_list": [
"exponent",
"cache_size"
],
"kwargs_change": {
"exponent": "power",
"cache_size": ""
}
},
"torch.distributions.ReshapeTransform": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.distribution.ReshapeTransform",
"args_list": [
"in_shape",
"out_shape"
],
"kwargs_change": {
"in_shape": "in_event_shape",
"out_shape": "out_event_shape"
}
},
"torch.distributions.SigmoidTransform": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.distribution.SigmoidTransform",
Expand Down Expand Up @@ -5620,6 +5685,16 @@
"cache_size": ""
}
},
"torch.distributions.TanhTransform": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.distribution.TanhTransform",
"args_list": [
"cache_size"
],
"kwargs_change": {
"cache_size": ""
}
},
"torch.distributions.Transform": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.distribution.Transform",
Expand Down
43 changes: 43 additions & 0 deletions tests/test_distributions_AbsTransform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.distributions.AbsTransform")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.ones((2,3))
t = torch.distributions.AbsTransform()
result = t(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.ones((2,3))
t = torch.distributions.AbsTransform(cache_size=0)
result = t(x)
"""
)
obj.run(pytorch_code, ["result"])
47 changes: 47 additions & 0 deletions tests/test_distributions_AffineTransform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.distributions.AffineTransform")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch

x = torch.tensor(1.)
y = torch.tensor(2.)
affine = torch.distributions.AffineTransform(x, y)
result = affine.forward_shape([1, 2])
"""
)
obj.run(pytorch_code, ["result"])


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch

x = torch.tensor(1.)
y = torch.tensor(2.)
affine = torch.distributions.AffineTransform(x, y, 1)
result = affine.forward_shape([1, 2])
"""
)
obj.run(pytorch_code, ["result"])
31 changes: 31 additions & 0 deletions tests/test_distributions_ExpTransform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.distributions.ExpTransform")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch

exp = torch.distributions.ExpTransform()
result = exp.forward_shape([1, 2])
"""
)
obj.run(pytorch_code, ["result"])
52 changes: 52 additions & 0 deletions tests/test_distributions_IndependentTransform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.distributions.IndependentTransform")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
multi_exp = torch.distributions.IndependentTransform(torch.distributions.Transform(), 1)
result = multi_exp.forward_shape([1, 2])
"""
)
obj.run(pytorch_code, ["result"])


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
multi_exp = torch.distributions.IndependentTransform(torch.distributions.SoftmaxTransform(), 2)
result = multi_exp.forward_shape([1, 2])
"""
)
obj.run(pytorch_code, ["result"])


def test_case_3():
pytorch_code = textwrap.dedent(
"""
import torch
multi_exp = torch.distributions.IndependentTransform(torch.distributions.SoftmaxTransform(), 2)
result = multi_exp.forward_shape([1, 2, 3])
"""
)
obj.run(pytorch_code, ["result"])
31 changes: 31 additions & 0 deletions tests/test_distributions_PowerTransform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.distributions.PowerTransform")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch

power = torch.distributions.PowerTransform(torch.tensor(2.))
result = power.forward_shape([1, 2])
"""
)
obj.run(pytorch_code, ["result"])
31 changes: 31 additions & 0 deletions tests/test_distributions_ReshapeTransform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.distributions.ReshapeTransform")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch

reshape_transform = torch.distributions.ReshapeTransform((2, 3), (3, 2))
result = reshape_transform.forward_shape((1,2,3))
"""
)
obj.run(pytorch_code, ["result"])
43 changes: 43 additions & 0 deletions tests/test_distributions_TanhTransform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.distributions.TanhTransform")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.ones((2,3))
t = torch.distributions.TanhTransform()
result = t(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.ones((2,3))
t = torch.distributions.TanhTransform(cache_size=0)
result = t(x)
"""
)
obj.run(pytorch_code, ["result"])