You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_export.py 884 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright 2020 Tencent
  2. # SPDX-License-Identifier: BSD-3-Clause
  3. import pytest
  4. import pnnx
  5. import torch
  6. import torch.nn as nn
  7. import torch.nn.functional as F
  8. from packaging import version
  9. class Model(nn.Module):
  10. def __init__(self):
  11. super(Model, self).__init__()
  12. def forward(self, x, y, z, w):
  13. x = F.relu(x)
  14. y = F.relu(y)
  15. z = F.relu(z)
  16. w = F.relu(w)
  17. return x, y, z, w
  18. def test_export():
  19. net = Model()
  20. net.eval()
  21. torch.manual_seed(0)
  22. x = torch.rand(1, 16)
  23. y = torch.rand(12, 2, 16)
  24. z = torch.rand(1, 3, 12, 16)
  25. w = torch.rand(1, 5, 7, 9, 11)
  26. a0, a1, a2, a3 = net(x, y, z, w)
  27. net_pnnx = pnnx.export(net, "test_F_relu_export", (x, y, z, w))
  28. b0, b1, b2, b3 = net_pnnx(x, y, z, w)
  29. assert torch.equal(a0, b0) and torch.equal(a1, b1) and torch.equal(a2, b2) and torch.equal(a3, b3)