mirror of
https://github.com/saymrwulf/pytorch.git
synced 2026-05-14 20:57:59 +00:00
Separate libtorch tests from libtorch build. (#26927)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26927 When we build a "normal" copy of PyTorch, we internally build a copy of libtorch. If we want to test libtorch: we have a choice: test against the regular PyTorch build, or test against the libtorch only build. All of our libtorch tests require Python-side PyTorch to run. So it makes more sense to test the regular PyTorch build. There is probably still utility in making sure that it is still possible to build libtorch only, but in that case we should endeavour to run tests that ONLY require libtorch build, and not Python side stuff. Signed-off-by: Edward Z. Yang <ezyang@fb.com> Test Plan: Imported from OSS Differential Revision: D17695384 Pulled By: ezyang fbshipit-source-id: 02522a8be0f5944f2b6255a8f1281e53ce2dcc6f
This commit is contained in:
parent
eeaef217b3
commit
33db4e02cb
4 changed files with 44 additions and 26 deletions
|
|
@ -168,6 +168,9 @@ else
|
|||
python setup.py install
|
||||
fi
|
||||
|
||||
# TODO: I'm not sure why, but somehow we lose verbose commands
|
||||
set -x
|
||||
|
||||
if which sccache > /dev/null; then
|
||||
echo 'PyTorch Build Statistics'
|
||||
sccache --show-stats
|
||||
|
|
@ -205,19 +208,20 @@ if [[ "$BUILD_TEST_LIBTORCH" == "1" ]]; then
|
|||
pushd ../cpp-build/caffe2
|
||||
WERROR=1 VERBOSE=1 DEBUG=1 python $BUILD_LIBTORCH_PY
|
||||
popd
|
||||
|
||||
# Build custom operator tests.
|
||||
CUSTOM_OP_BUILD="$PWD/../custom-op-build"
|
||||
CUSTOM_OP_TEST="$PWD/test/custom_operator"
|
||||
SITE_PACKAGES="$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
|
||||
mkdir "$CUSTOM_OP_BUILD"
|
||||
pushd "$CUSTOM_OP_BUILD"
|
||||
CMAKE_PREFIX_PATH="$SITE_PACKAGES/torch" cmake "$CUSTOM_OP_TEST"
|
||||
make VERBOSE=1
|
||||
popd
|
||||
assert_git_not_dirty
|
||||
fi
|
||||
|
||||
# Build custom operator tests.
|
||||
CUSTOM_OP_BUILD="$PWD/../custom-op-build"
|
||||
CUSTOM_OP_TEST="$PWD/test/custom_operator"
|
||||
python --version
|
||||
SITE_PACKAGES="$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
|
||||
mkdir "$CUSTOM_OP_BUILD"
|
||||
pushd "$CUSTOM_OP_BUILD"
|
||||
cmake "$CUSTOM_OP_TEST" -DCMAKE_PREFIX_PATH="$SITE_PACKAGES/torch" -DPYTHON_EXECUTABLE="$(which python)"
|
||||
make VERBOSE=1
|
||||
popd
|
||||
assert_git_not_dirty
|
||||
|
||||
# Test XLA build
|
||||
if [[ "${BUILD_ENVIRONMENT}" == *xla* ]]; then
|
||||
# TODO: Move this to Dockerfile.
|
||||
|
|
|
|||
|
|
@ -138,24 +138,23 @@ test_torchvision() {
|
|||
}
|
||||
|
||||
test_libtorch() {
|
||||
if [[ "$BUILD_TEST_LIBTORCH" == "1" ]]; then
|
||||
if [[ "$BUILD_ENVIRONMENT" != *rocm* ]]; then
|
||||
echo "Testing libtorch"
|
||||
python test/cpp/jit/tests_setup.py setup
|
||||
CPP_BUILD="$PWD/../cpp-build"
|
||||
if [[ "$BUILD_ENVIRONMENT" == *cuda* ]]; then
|
||||
"$CPP_BUILD"/caffe2/build/bin/test_jit
|
||||
build/bin/test_jit
|
||||
else
|
||||
"$CPP_BUILD"/caffe2/build/bin/test_jit "[cpu]"
|
||||
build/bin/test_jit "[cpu]"
|
||||
fi
|
||||
python test/cpp/jit/tests_setup.py shutdown
|
||||
python tools/download_mnist.py --quiet -d test/cpp/api/mnist
|
||||
OMP_NUM_THREADS=2 TORCH_CPP_TEST_MNIST_PATH="test/cpp/api/mnist" "$CPP_BUILD"/caffe2/build/bin/test_api
|
||||
OMP_NUM_THREADS=2 TORCH_CPP_TEST_MNIST_PATH="test/cpp/api/mnist" build/bin/test_api
|
||||
assert_git_not_dirty
|
||||
fi
|
||||
}
|
||||
|
||||
test_custom_script_ops() {
|
||||
if [[ "$BUILD_TEST_LIBTORCH" == "1" ]]; then
|
||||
if [[ "$BUILD_ENVIRONMENT" != *rocm* ]] && [[ "$BUILD_ENVIRONMENT" != *asan* ]] ; then
|
||||
echo "Testing custom script operators"
|
||||
CUSTOM_OP_BUILD="$PWD/../custom-op-build"
|
||||
pushd test/custom_operator
|
||||
|
|
|
|||
|
|
@ -265,18 +265,22 @@ AnyModule::Value make_value(T&& value) {
|
|||
struct AnyValueTest : torch::test::SeedingFixture {};
|
||||
|
||||
TEST_F(AnyValueTest, CorrectlyAccessesIntWhenCorrectType) {
|
||||
auto value = make_value(5);
|
||||
// const and non-const types have the same typeid()
|
||||
auto value = make_value<int>(5);
|
||||
ASSERT_NE(value.try_get<int>(), nullptr);
|
||||
ASSERT_NE(value.try_get<const int>(), nullptr);
|
||||
// const and non-const types have the same typeid(),
|
||||
// but casting Holder<int> to Holder<const int> is undefined
|
||||
// behavior according to UBSAN: https://github.com/pytorch/pytorch/issues/26964
|
||||
// ASSERT_NE(value.try_get<const int>(), nullptr);
|
||||
ASSERT_EQ(value.get<int>(), 5);
|
||||
}
|
||||
TEST_F(AnyValueTest, CorrectlyAccessesConstIntWhenCorrectType) {
|
||||
auto value = make_value(5);
|
||||
ASSERT_NE(value.try_get<const int>(), nullptr);
|
||||
ASSERT_NE(value.try_get<int>(), nullptr);
|
||||
ASSERT_EQ(value.get<const int>(), 5);
|
||||
}
|
||||
// This test does not work at all, because it looks like make_value
|
||||
// decays const int into int.
|
||||
//TEST_F(AnyValueTest, CorrectlyAccessesConstIntWhenCorrectType) {
|
||||
// auto value = make_value<const int>(5);
|
||||
// ASSERT_NE(value.try_get<const int>(), nullptr);
|
||||
// // ASSERT_NE(value.try_get<int>(), nullptr);
|
||||
// ASSERT_EQ(value.get<const int>(), 5);
|
||||
//}
|
||||
TEST_F(AnyValueTest, CorrectlyAccessesStringLiteralWhenCorrectType) {
|
||||
auto value = make_value("hello");
|
||||
ASSERT_NE(value.try_get<const char*>(), nullptr);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from torch import ops
|
|||
import torch.jit as jit
|
||||
import glob
|
||||
import os
|
||||
import sys
|
||||
|
||||
def get_custom_class_library_path():
|
||||
library_filename = glob.glob("build/*custom_class*")
|
||||
|
|
@ -19,6 +20,16 @@ def test_equality(f, cmp_key):
|
|||
return (cmp_key(obj1), cmp_key(obj2))
|
||||
|
||||
class TestCustomOperators(unittest.TestCase):
|
||||
if sys.version_info < (3, 2):
|
||||
# assertRegexpMatches renamed to assertRegex in 3.2
|
||||
assertRegex = unittest.TestCase.assertRegexpMatches
|
||||
# assertRaisesRegexp renamed to assertRaisesRegex in 3.2
|
||||
assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
|
||||
|
||||
if sys.version_info < (3, 5):
|
||||
# assertNotRegexpMatches renamed to assertNotRegex in 3.5
|
||||
assertNotRegex = unittest.TestCase.assertNotRegexpMatches
|
||||
|
||||
def setUp(self):
|
||||
ops.load_library(get_custom_class_library_path())
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue