-
Notifications
You must be signed in to change notification settings - Fork 55
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
转换规则 No.234/236/237 #133
Merged
Merged
转换规则 No.234/236/237 #133
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
233b489
转换规则 No.234/236/237
txyugood 2395ee0
Merge branch 'master' into dev
txyugood 2bca96b
Merge branch 'master' of https://github.com/PaddlePaddle/PaConvert in…
txyugood 5323537
Merge branch 'master' of https://github.com/PaddlePaddle/PaConvert in…
txyugood 0a065c9
Fix variable naming in TensorDatasetMatcher.
txyugood c63fdca
Merge branch 'master' of https://github.com/PaddlePaddle/PaConvert in…
txyugood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# 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.utils.data.ChainDataset") | ||
|
||
|
||
def test_case_1(): | ||
pytorch_code = textwrap.dedent( | ||
""" | ||
import numpy as np | ||
import math | ||
import torch | ||
from torch.utils.data import IterableDataset, ChainDataset | ||
class MyIterableDataset(torch.utils.data.IterableDataset): | ||
def __init__(self, start, end): | ||
super(MyIterableDataset).__init__() | ||
assert end > start, "this example code only works with end >= start" | ||
self.start = start | ||
self.end = end | ||
|
||
def __iter__(self): | ||
iter_start = self.start | ||
iter_end = self.end | ||
return iter(range(iter_start, iter_end)) | ||
|
||
|
||
dataset = ChainDataset([MyIterableDataset(start=3, end=7), MyIterableDataset(start=3, end=7)]) | ||
result = [] | ||
for d in dataset: | ||
result.append(d) | ||
""" | ||
) | ||
obj.run(pytorch_code, ["result"]) | ||
|
||
|
||
def test_case_2(): | ||
pytorch_code = textwrap.dedent( | ||
""" | ||
import numpy as np | ||
import math | ||
import torch | ||
from torch.utils.data import IterableDataset, ChainDataset | ||
class MyIterableDataset(torch.utils.data.IterableDataset): | ||
def __init__(self, start, end): | ||
super(MyIterableDataset).__init__() | ||
assert end > start, "this example code only works with end >= start" | ||
self.start = start | ||
self.end = end | ||
|
||
def __iter__(self): | ||
iter_start = self.start | ||
iter_end = self.end | ||
return iter(range(iter_start, iter_end)) | ||
|
||
|
||
dataset = ChainDataset([MyIterableDataset(start=1, end=10), MyIterableDataset(start=1, end=3)]) | ||
result = [] | ||
for d in dataset: | ||
result.append(d) | ||
""" | ||
) | ||
obj.run(pytorch_code, ["result"]) | ||
|
||
|
||
def test_case_3(): | ||
pytorch_code = textwrap.dedent( | ||
""" | ||
import numpy as np | ||
import math | ||
import torch | ||
from torch.utils.data import IterableDataset, ChainDataset | ||
class MyIterableDataset(torch.utils.data.IterableDataset): | ||
def __init__(self, start, end): | ||
super(MyIterableDataset).__init__() | ||
assert end > start, "this example code only works with end >= start" | ||
self.start = start | ||
self.end = end | ||
|
||
def __iter__(self): | ||
iter_start = self.start | ||
iter_end = self.end | ||
return iter(range(iter_start, iter_end)) | ||
|
||
|
||
dataset = ChainDataset([MyIterableDataset(start=1, end=10)]) | ||
result = [] | ||
for d in dataset: | ||
result.append(d) | ||
""" | ||
) | ||
obj.run(pytorch_code, ["result"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# 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.utils.data.Subset") | ||
|
||
|
||
def test_case_1(): | ||
pytorch_code = textwrap.dedent( | ||
""" | ||
import torch | ||
from torch.utils.data import Dataset, Subset | ||
class MyDataset(Dataset): | ||
def __init__(self, size=10): | ||
super(Dataset).__init__() | ||
self.data = list(range(size)) | ||
|
||
def __getitem__(self, idx): | ||
return self.data[idx] | ||
|
||
def __len__(self): | ||
return len(self.data) | ||
|
||
dataset = Subset(MyDataset(10),[1, 2, 3, 4, 5, 6]) | ||
result = [] | ||
for d in dataset: | ||
result.append(d) | ||
""" | ||
) | ||
obj.run(pytorch_code, ["result"]) | ||
|
||
|
||
def test_case_2(): | ||
pytorch_code = textwrap.dedent( | ||
""" | ||
import torch | ||
from torch.utils.data import Dataset, Subset | ||
class MyDataset(Dataset): | ||
def __init__(self, size=10): | ||
super(Dataset).__init__() | ||
self.data = list(range(size)) | ||
|
||
def __getitem__(self, idx): | ||
return self.data[idx] | ||
|
||
def __len__(self): | ||
return len(self.data) | ||
|
||
dataset = Subset(MyDataset(10),[9, 1]) | ||
result = [] | ||
for d in dataset: | ||
result.append(d) | ||
""" | ||
) | ||
obj.run(pytorch_code, ["result"]) | ||
|
||
|
||
def test_case_3(): | ||
pytorch_code = textwrap.dedent( | ||
""" | ||
import torch | ||
from torch.utils.data import Dataset, Subset | ||
class MyDataset(Dataset): | ||
def __init__(self, size=10): | ||
super(Dataset).__init__() | ||
self.data = list(range(size)) | ||
|
||
def __getitem__(self, idx): | ||
return self.data[idx] | ||
|
||
def __len__(self): | ||
return len(self.data) | ||
|
||
dataset = Subset(MyDataset(10),[9, 1, 3]) | ||
result = [] | ||
for d in dataset: | ||
result.append(d) | ||
""" | ||
) | ||
obj.run(pytorch_code, ["result"]) | ||
|
||
|
||
def test_case_4(): | ||
pytorch_code = textwrap.dedent( | ||
""" | ||
import torch | ||
from torch.utils.data import Dataset, Subset | ||
class MyDataset(Dataset): | ||
def __init__(self, size=10): | ||
super(Dataset).__init__() | ||
self.data = list(range(size)) | ||
|
||
def __getitem__(self, idx): | ||
return self.data[idx] | ||
|
||
def __len__(self): | ||
return len(self.data) | ||
data = MyDataset(10) | ||
indices = [9, 1, 3] | ||
dataset = Subset(data, indices) | ||
result = [] | ||
for d in dataset: | ||
result.append(d) | ||
""" | ||
) | ||
obj.run(pytorch_code, ["result"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# 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.utils.data.TensorDataset") | ||
|
||
|
||
def test_case_1(): | ||
pytorch_code = textwrap.dedent( | ||
""" | ||
import numpy as np | ||
import torch | ||
from torch.utils.data import TensorDataset | ||
np.random.seed(0) | ||
input_np = np.random.random([2, 3, 4]).astype('float32') | ||
input = torch.from_numpy(input_np) | ||
dataset = TensorDataset(input) | ||
result = [] | ||
for d in dataset: | ||
result.append(d) | ||
""" | ||
) | ||
obj.run(pytorch_code, ["result"]) | ||
|
||
|
||
def test_case_2(): | ||
pytorch_code = textwrap.dedent( | ||
""" | ||
import numpy as np | ||
import torch | ||
from torch.utils.data import TensorDataset | ||
np.random.seed(0) | ||
input_np = np.random.random([2, 3, 4]).astype('float32') | ||
input = torch.from_numpy(input_np) | ||
label_np = np.random.random([2, 1]).astype('int32') | ||
label = torch.from_numpy(label_np) | ||
dataset = TensorDataset(input, label) | ||
result = [] | ||
for d in dataset: | ||
result.append(d) | ||
""" | ||
) | ||
obj.run(pytorch_code, ["result"]) | ||
|
||
|
||
def test_case_3(): | ||
pytorch_code = textwrap.dedent( | ||
""" | ||
import numpy as np | ||
import torch | ||
from torch.utils.data import TensorDataset | ||
np.random.seed(0) | ||
input_np = np.random.random([2, 3, 4]).astype('float32') | ||
input = torch.from_numpy(input_np) | ||
input_np2 = np.random.random([2, 5, 5]).astype('float32') | ||
input2 = torch.from_numpy(input_np2) | ||
label_np = np.random.random([2, 1]).astype('int32') | ||
label = torch.from_numpy(label_np) | ||
dataset = TensorDataset(input, input2, label) | ||
result = [] | ||
for d in dataset: | ||
result.append(d) | ||
""" | ||
) | ||
obj.run(pytorch_code, ["result"]) | ||
|
||
|
||
def test_case_4(): | ||
pytorch_code = textwrap.dedent( | ||
""" | ||
import numpy as np | ||
import torch | ||
from torch.utils.data import TensorDataset | ||
np.random.seed(0) | ||
input_np = np.random.random([2, 3, 4]).astype('float32') | ||
input = torch.from_numpy(input_np) | ||
input_np2 = np.random.random([2, 5, 5]).astype('float32') | ||
input2 = torch.from_numpy(input_np2) | ||
label_np = np.random.random([2, 1]).astype('int32') | ||
label = torch.from_numpy(label_np) | ||
data = [input, input2, label] | ||
|
||
dataset = TensorDataset(*data) | ||
result = [] | ||
for d in dataset: | ||
result.append(d) | ||
""" | ||
) | ||
obj.run(pytorch_code, ["result"]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是一个参数,不是最后的code,建议这个变量命名换个名字
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.