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_conv.py 1.2 kB

1234567891011121314151617181920212223242526272829303132333435
  1. # -*- coding: utf-8 -*-
  2. # MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  3. #
  4. # Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  5. #
  6. # Unless required by applicable law or agreed to in writing,
  7. # software distributed under the License is distributed on an
  8. # "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. import itertools
  10. import numpy as np
  11. import pytest
  12. import megengine as mge
  13. import megengine.module as M
  14. from megengine import tensor
  15. # NOTE: test in module for convenience. should really test in functional
  16. @pytest.mark.parametrize(
  17. "name",
  18. ["Conv1d", "Conv2d", "Conv3d", "ConvTranspose2d", "ConvTranspose3d", "LocalConv2d"],
  19. )
  20. def test_conv_dtype_promotion(name):
  21. old = mge.config.deterministic_kernel
  22. mge.config.deterministic_kernel = True
  23. N, Ci, Co, K = 2, 16, 32, 3
  24. S = (7,) * int(name[-2])
  25. if "Local" in name:
  26. m = getattr(M, name)(Ci, Co, *S, K)
  27. else:
  28. m = getattr(M, name)(Ci, Co, K)
  29. x = tensor(np.random.random(size=(N, Ci) + S).astype("float16"))
  30. np.testing.assert_equal(m(x).numpy(), m(x.astype("float32")).numpy())
  31. mge.config.deterministic_kernel = old