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_export.py 673 B

123456789101112131415161718192021222324252627282930313233343536
  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. x2 = torch.rand(1, 128)
  21. a0 = net(x)
  22. a1 = net(x2)
  23. net_pnnx = pnnx.export(net, "test_F_relu_dexport", x, x2)
  24. b0 = net_pnnx(x)
  25. b1 = net_pnnx(x2)
  26. assert torch.equal(a0, b0) and torch.equal(a1, b1)