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

Add export_testcase to support length 1 arrays and lists #822

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pytorch_pfn_extras/onnx/export_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ def write_to_pb(f: str, tensor: torch.Tensor, name: Optional[str] = None) -> Non
for pb_name in glob.glob(os.path.join(data_set_path, "*.pb")):
os.remove(pb_name)
for i, (arg, name) in enumerate(zip(named_args, input_names)):
if isinstance(arg, (list, tuple)):
assert len(arg) == 1, \
'Models that receive nested lists/tuples are not supported yet'
arg = arg[0]
f = os.path.join(data_set_path, 'input_{}.pb'.format(i))
write_to_pb(f, arg, name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,31 @@ def forward(self, x, labels=None, bias=torch.zeros(10)):
)

check_inputs(output_dir, ["x", "bias"])


def test_export_tuple_input():

class Net(nn.Module):
def __init__(self):
super().__init__()
self.linear = nn.Linear(5, 10, bias=False)
self.in_channels = [5, 10]

def forward(self, inputs):
assert isinstance(inputs, tuple), f"{type(inputs)=}"
linears = [self.linear(x) for x in inputs]
return linears


model = Net()
x = torch.rand(2, 5)

export_testcase(
model,
((x,),),
output_dir,
input_names=["x"],
training=model.training,
do_constant_folding=False,
opset_version=12,
)
Loading