Skip to content

Commit e2e4735

Browse files
authored
[API Compatibility] Add more test cases (#897)
* [API Compatibility] Add more test cases * [API Compatibility] Add more test cases * [API Compatibility] fix * [API Compatibility] fix * [API Compatibility] fix * [API Compatibility] fix * fix * fix
1 parent 9d0279a commit e2e4735

42 files changed

Lines changed: 1822 additions & 163 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

paconvert/api_mapping.json

Lines changed: 32 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -4381,6 +4381,9 @@
43814381
"Matcher": "ChangeAPIMatcher",
43824382
"paddle_api": "paddle.distribution.constraint.Constraint"
43834383
},
4384+
"torch.distributions.constraints.positive_definite.check": {
4385+
"Matcher": "ChangePrefixMatcher"
4386+
},
43844387
"torch.distributions.continuous_bernoulli.ContinuousBernoulli": {
43854388
"Matcher": "GenericMatcher",
43864389
"paddle_api": "paddle.distribution.ContinuousBernoulli",
@@ -4413,55 +4416,46 @@
44134416
"Matcher": "ChangePrefixMatcher"
44144417
},
44154418
"torch.distributions.distribution.Distribution.cdf": {
4419+
"Matcher": "ChangePrefixMatcher",
44164420
"min_input_args": 1
44174421
},
44184422
"torch.distributions.distribution.Distribution.entropy": {
4423+
"Matcher": "ChangePrefixMatcher",
44194424
"min_input_args": 0
44204425
},
44214426
"torch.distributions.distribution.Distribution.enumerate_support": {
4427+
"Matcher": "ChangePrefixMatcher",
44224428
"min_input_args": 0
44234429
},
44244430
"torch.distributions.distribution.Distribution.expand": {
44254431
"min_input_args": 1
44264432
},
44274433
"torch.distributions.distribution.Distribution.icdf": {
4434+
"Matcher": "ChangePrefixMatcher",
44284435
"min_input_args": 1
44294436
},
44304437
"torch.distributions.distribution.Distribution.log_prob": {
4431-
"Matcher": "ChangeAPIMatcher",
4432-
"paddle_api": "paddle.distribution.Distribution.log_prob",
4438+
"Matcher": "ChangePrefixMatcher",
44334439
"min_input_args": 1
44344440
},
44354441
"torch.distributions.distribution.Distribution.perplexity": {
4442+
"Matcher": "ChangePrefixMatcher",
44364443
"min_input_args": 0
44374444
},
44384445
"torch.distributions.distribution.Distribution.rsample": {
4439-
"Matcher": "GenericMatcher",
4440-
"paddle_api": "paddle.distribution.Distribution.rsample",
4441-
"args_list": [
4442-
"sample_shape"
4443-
],
4444-
"kwargs_change": {
4445-
"sample_shape": "shape"
4446-
},
4446+
"Matcher": "ChangePrefixMatcher",
44474447
"min_input_args": 0
44484448
},
44494449
"torch.distributions.distribution.Distribution.sample": {
4450-
"Matcher": "GenericMatcher",
4451-
"paddle_api": "paddle.distribution.Distribution.sample",
4452-
"args_list": [
4453-
"sample_shape"
4454-
],
4455-
"kwargs_change": {
4456-
"sample_shape": "shape"
4457-
},
4450+
"Matcher": "ChangePrefixMatcher",
44584451
"min_input_args": 0
44594452
},
44604453
"torch.distributions.distribution.Distribution.sample_n": {
4454+
"Matcher": "ChangePrefixMatcher",
44614455
"min_input_args": 1
44624456
},
44634457
"torch.distributions.distribution.Distribution.set_default_validate_args": {
4464-
"min_input_args": 1
4458+
"Matcher": "ChangePrefixMatcher"
44654459
},
44664460
"torch.distributions.exp_family.ExponentialFamily": {
44674461
"Matcher": "GenericMatcher",
@@ -4622,17 +4616,7 @@
46224616
"Matcher": "ChangePrefixMatcher"
46234617
},
46244618
"torch.distributions.normal.Normal": {
4625-
"Matcher": "GenericMatcher",
4626-
"paddle_api": "paddle.distribution.Normal",
4627-
"min_input_args": 2,
4628-
"args_list": [
4629-
"loc",
4630-
"scale",
4631-
"validate_args"
4632-
],
4633-
"kwargs_change": {
4634-
"validate_args": ""
4635-
}
4619+
"Matcher": "ChangePrefixMatcher"
46364620
},
46374621
"torch.distributions.poisson.Poisson": {
46384622
"Matcher": "GenericMatcher",
@@ -5546,6 +5530,9 @@
55465530
"example_inputs": "input_spec"
55475531
}
55485532
},
5533+
"torch.kaiser_window": {
5534+
"Matcher": "ChangePrefixMatcher"
5535+
},
55495536
"torch.kl_div": {},
55505537
"torch.kron": {
55515538
"Matcher": "ChangePrefixMatcher"
@@ -6388,76 +6375,16 @@
63886375
"Matcher": "ChangePrefixMatcher"
63896376
},
63906377
"torch.nn.BatchNorm1d": {
6391-
"Matcher": "ReverseMomentumMatcher",
6392-
"paddle_api": "paddle.nn.BatchNorm1D",
6393-
"min_input_args": 1,
6394-
"args_list": [
6395-
"num_features",
6396-
"eps",
6397-
"momentum",
6398-
"affine",
6399-
"track_running_stats",
6400-
"device",
6401-
"dtype"
6402-
],
6403-
"kwargs_change": {
6404-
"eps": "epsilon",
6405-
"affine": [
6406-
"weight_attr",
6407-
"bias_attr"
6408-
],
6409-
"track_running_stats": "",
6410-
"device": "",
6411-
"dtype": ""
6412-
}
6378+
"Matcher": "ChangeAPIMatcher",
6379+
"paddle_api": "paddle.compat.nn.BatchNorm1d"
64136380
},
64146381
"torch.nn.BatchNorm2d": {
6415-
"Matcher": "ReverseMomentumMatcher",
6416-
"paddle_api": "paddle.nn.BatchNorm2D",
6417-
"min_input_args": 1,
6418-
"args_list": [
6419-
"num_features",
6420-
"eps",
6421-
"momentum",
6422-
"affine",
6423-
"track_running_stats",
6424-
"device",
6425-
"dtype"
6426-
],
6427-
"kwargs_change": {
6428-
"eps": "epsilon",
6429-
"affine": [
6430-
"weight_attr",
6431-
"bias_attr"
6432-
],
6433-
"track_running_stats": "",
6434-
"device": "",
6435-
"dtype": ""
6436-
}
6382+
"Matcher": "ChangeAPIMatcher",
6383+
"paddle_api": "paddle.compat.nn.BatchNorm2d"
64376384
},
64386385
"torch.nn.BatchNorm3d": {
6439-
"Matcher": "ReverseMomentumMatcher",
6440-
"paddle_api": "paddle.nn.BatchNorm3D",
6441-
"min_input_args": 1,
6442-
"args_list": [
6443-
"num_features",
6444-
"eps",
6445-
"momentum",
6446-
"affine",
6447-
"track_running_stats",
6448-
"device",
6449-
"dtype"
6450-
],
6451-
"kwargs_change": {
6452-
"eps": "epsilon",
6453-
"affine": [
6454-
"weight_attr",
6455-
"bias_attr"
6456-
],
6457-
"track_running_stats": "",
6458-
"device": "",
6459-
"dtype": ""
6460-
}
6386+
"Matcher": "ChangeAPIMatcher",
6387+
"paddle_api": "paddle.compat.nn.BatchNorm3d"
64616388
},
64626389
"torch.nn.Bilinear": {
64636390
"Matcher": "GenericMatcher",
@@ -6942,7 +6869,7 @@
69426869
"Matcher": "ChangePrefixMatcher"
69436870
},
69446871
"torch.nn.Module.get_extra_state": {
6945-
"min_input_args": 0
6872+
"Matcher": "ChangePrefixMatcher"
69466873
},
69476874
"torch.nn.Module.get_parameter": {
69486875
"Matcher": "ChangePrefixMatcher"
@@ -7034,7 +6961,7 @@
70346961
"Matcher": "ChangePrefixMatcher"
70356962
},
70366963
"torch.nn.Module.set_extra_state": {
7037-
"min_input_args": 1
6964+
"Matcher": "ChangePrefixMatcher"
70386965
},
70396966
"torch.nn.Module.share_memory": {
70406967
"min_input_args": 0
@@ -7520,6 +7447,12 @@
75207447
"torch.nn.attention._cur_sdpa_kernel_backends": {
75217448
"Matcher": "ChangePrefixMatcher"
75227449
},
7450+
"torch.nn.attention.flex_attention.and_masks": {
7451+
"Matcher": "ChangePrefixMatcher"
7452+
},
7453+
"torch.nn.attention.flex_attention.or_masks": {
7454+
"Matcher": "ChangePrefixMatcher"
7455+
},
75237456
"torch.nn.attention.sdpa_kernel": {
75247457
"Matcher": "ChangePrefixMatcher"
75257458
},
@@ -7872,16 +7805,7 @@
78727805
}
78737806
},
78747807
"torch.nn.functional.hardswish": {
7875-
"Matcher": "GenericMatcher",
7876-
"paddle_api": "paddle.nn.functional.hardswish",
7877-
"min_input_args": 1,
7878-
"args_list": [
7879-
"input",
7880-
"inplace"
7881-
],
7882-
"kwargs_change": {
7883-
"input": "x"
7884-
}
7808+
"Matcher": "ChangePrefixMatcher"
78857809
},
78867810
"torch.nn.functional.hardtanh": {
78877811
"Matcher": "GenericMatcher",

paconvert/attribute_mapping.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@
190190
"torch.float8_e4m3fn.itemsize": {
191191
"Matcher": "ChangePrefixMatcher"
192192
},
193+
"torch.float8_e5m2": {
194+
"Matcher": "ChangePrefixMatcher"
195+
},
193196
"torch.half": {
194197
"Matcher": "ChangePrefixMatcher"
195198
},
@@ -241,6 +244,15 @@
241244
"torch.short": {
242245
"Matcher": "ChangePrefixMatcher"
243246
},
247+
"torch.uint16": {
248+
"Matcher": "ChangePrefixMatcher"
249+
},
250+
"torch.uint32": {
251+
"Matcher": "ChangePrefixMatcher"
252+
},
253+
"torch.uint64": {
254+
"Matcher": "ChangePrefixMatcher"
255+
},
244256
"torch.uint8": {
245257
"Matcher": "ChangePrefixMatcher"
246258
},

paconvert/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ def parse_kwargs(self, kwargs, allow_none=False):
430430
def parse_func(self, func):
431431
func_str = astor.to_source(func).strip("\n")
432432
self.paddleClass = func_str[0 : func_str.rfind(".")]
433-
class_str = "paddle.Tensor|paddle.nn.Module|paddle.optimizer.Optimizer|paddle.optim.Optimizer|paddle.distribution.Distribution|paddle.autograd.function.FunctionCtx|paddle.profiler.Profiler"
433+
class_str = "paddle.Tensor|paddle.nn.Module|paddle.optimizer.Optimizer|paddle.optim.Optimizer|paddle.distribution.Distribution|paddle.distributions.distribution.Distribution|paddle.autograd.function.FunctionCtx|paddle.profiler.Profiler"
434434
if self.get_paddle_api():
435435
new_paddle_api = re.sub(
436436
class_str,
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import paddle
22

33
print("#########################case1#########################")
4-
paddle.nn.BatchNorm1D(num_features=3, epsilon=0.001, momentum=1 - 0.01)
4+
paddle.compat.nn.BatchNorm1d(3, eps=0.001, momentum=0.01)
55
print("#########################case2#########################")
6-
bn = paddle.nn.BatchNorm1D(num_features=27)
6+
bn = paddle.compat.nn.BatchNorm1d(27)
77
print("#########################case3#########################")
8-
paddle.nn.BatchNorm1D(
9-
num_features=10, epsilon=1e-05, weight_attr=False, bias_attr=False
10-
)
8+
paddle.compat.nn.BatchNorm1d(10, eps=1e-05, affine=False)
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import paddle
22

33
print("#########################case1#########################")
4-
bn = paddle.nn.BatchNorm2D(num_features=5)
4+
bn = paddle.compat.nn.BatchNorm2d(5)
55
print("#########################case2#########################")
6-
bn = paddle.nn.BatchNorm2D(num_features=27)
6+
bn = paddle.compat.nn.BatchNorm2d(27)
77
print("#########################case3#########################")
8-
paddle.nn.BatchNorm2D(
9-
num_features=10, epsilon=1e-05, weight_attr=False, bias_attr=False
10-
)
8+
paddle.compat.nn.BatchNorm2d(10, eps=1e-05, affine=False)

tests/test_Tensor_index_copy_.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,42 @@ def test_case_10():
160160
"""
161161
)
162162
obj.run(pytorch_code, ["result"])
163+
164+
165+
def test_case_11():
166+
pytorch_code = textwrap.dedent(
167+
"""
168+
import torch
169+
x = torch.zeros(2, 3, dtype=torch.float32)
170+
source = torch.tensor([[1, 2], [4, 5]], dtype=torch.float32)
171+
index = torch.tensor([2, 0])
172+
result = x.index_copy_(dim=-1, index=index, source=source)
173+
"""
174+
)
175+
obj.run(pytorch_code, ["result"])
176+
177+
178+
def test_case_12():
179+
pytorch_code = textwrap.dedent(
180+
"""
181+
import torch
182+
x = torch.tensor(0.0)
183+
source = torch.tensor(5.0)
184+
index = torch.tensor([0])
185+
result = x.index_copy_(0, index, source)
186+
"""
187+
)
188+
obj.run(pytorch_code, ["result"])
189+
190+
191+
def test_case_13():
192+
pytorch_code = textwrap.dedent(
193+
"""
194+
import torch
195+
x = torch.arange(6, dtype=torch.float32).reshape(2, 3)
196+
source = torch.empty([2, 0], dtype=torch.float32)
197+
index = torch.tensor([], dtype=torch.int64)
198+
result = x.index_copy_(1, index, source)
199+
"""
200+
)
201+
obj.run(pytorch_code, ["result"])

tests/test_Tensor_reshape_as.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,15 @@ def test_case_7():
106106
"""
107107
)
108108
obj.run(pytorch_code, ["result"])
109+
110+
111+
def test_case_8():
112+
pytorch_code = textwrap.dedent(
113+
"""
114+
import torch
115+
a = torch.arange(24, dtype=torch.float64)
116+
b = torch.zeros([2, 3, 4], dtype=torch.float32)
117+
result = a.reshape_as(b)
118+
"""
119+
)
120+
obj.run(pytorch_code, ["result"])

0 commit comments

Comments
 (0)