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_dynamicinput_convert.py 736 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright 2021 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):
  13. x = F.relu(x)
  14. return x
  15. def test_export():
  16. net = Model()
  17. net.eval()
  18. torch.manual_seed(0)
  19. x = torch.rand(1, 16)
  20. x1 = torch.rand(1, 128)
  21. a0 = net(x)
  22. a1 = net(x1)
  23. mod = torch.jit.trace(net, x)
  24. mod.save("test_F_relu_dconvert.pt")
  25. net2 = pnnx.convert("test_F_relu_dconvert.pt", x, x1)
  26. b0 = net2(x)
  27. b1 = net2(x1)
  28. assert torch.equal(a0, b0) and torch.equal(a1, b1)