Skip to content

Commit bf685e6

Browse files
Add unit test for interpretermanager instantiation and module registry (#116)
Summary: The InterpreterManager instantiation is throwing a segfault for cpython 3.10; debugging points to individual interpreter instantiation : https://github.com/pytorch/multipy/blob/a0b1f945bf79ab335bbc141f72b2e92910fe5577/multipy/runtime/interpreter/interpreter_impl.cpp#L415, which in turn has a fixed number of frozen python modules. Creating a basic unit test to ensure InterpreterManager can be built, and the explicit module registration (https://github.com/pytorch/multipy/blob/a0b1f945bf79ab335bbc141f72b2e92910fe5577/multipy/runtime/deploy.cpp#L125) works. Pull Request resolved: #116 Reviewed By: PaliC Differential Revision: D38429675 Pulled By: anirbanr-fb-r2p fbshipit-source-id: f3d1123f0b92d8411db00089a4e04659b8bda1d5
1 parent caadc42 commit bf685e6

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

multipy/runtime/deploy.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ struct TORCH_API InterpreterManager {
158158
registeredModuleSource_[std::move(name)] = std::move(src);
159159
}
160160

161+
// Util function for debugging.
162+
size_t countRegisteredModuleSources() {
163+
return registeredModuleSource_.size();
164+
}
165+
161166
InterpreterManager(const InterpreterManager&) = delete;
162167
InterpreterManager& operator=(const InterpreterManager&) = delete;
163168
InterpreterManager& operator=(InterpreterManager&&) = delete;

multipy/runtime/interpreter/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,27 @@ include(GoogleTest)
4949
# We find the built python modules, this is confusing because python build already outputs
5050
# the modules in a strange nested path, and then that path is relative to the
5151
# Cmake ExternalProject root in the cmake build dir.
52-
## From test devsrvr
5352
ExternalProject_Get_property(cpython SOURCE_DIR)
5453
SET(PYTHON_MODULE_DIR "${SOURCE_DIR}/build/temp.linux-x86_64-${CPYTHON_VERSION}/${SOURCE_DIR}/Modules")
5554
SET(PYTHON_STDLIB_DIR "${SOURCE_DIR}/Lib")
5655
SET(PYTHON_STDLIB "${PYTHON_INSTALL_DIR}/lib/libpython_stdlib${CPYTHON_VERSION}.a")
56+
57+
if(${CPYTHON_VERSION} MATCHES "3\.(7|8)")
58+
SET(PYTHON_MEM_MODULE "${PYTHON_MODULE_DIR}/_decimal/libmpdec/memory.o")
59+
SET(LEGACY_PARSER_MODULE "${PYTHON_MODULE_DIR}/parsermodule.o")
60+
elseif(${CPYTHON_VERSION} MATCHES "3\.(9|1[0-9]*)")
61+
SET(PYTHON_MEM_MODULE "${PYTHON_MODULE_DIR}/_decimal/libmpdec/mpalloc.o")
62+
SET(LEGACY_PARSER_MODULE "")
63+
endif()
64+
5765
# Then we use a hardcoded list of expected module names and include them in our lib
5866
include("CMakePythonModules.txt")
5967
ExternalProject_Add_Step(
6068
cpython
6169
archive_stdlib
6270
DEPENDEES install
6371
BYPRODUCTS ${PYTHON_STDLIB}
64-
COMMAND ar -rc ${PYTHON_STDLIB} ${PYTHON_MODULES}
72+
COMMAND ar -rc ${PYTHON_STDLIB} ${PYTHON_MODULES} ${PYTHON_MEM_MODULE} ${LEGACY_PARSER_MODULE}
6573
VERBATIM
6674
)
6775

multipy/runtime/interpreter/CMakePythonModules.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ SET(PYTHON_MODULES
3939
${PYTHON_MODULE_DIR}/nismodule.o
4040
${PYTHON_MODULE_DIR}/_opcode.o
4141
${PYTHON_MODULE_DIR}/ossaudiodev.o
42-
${PYTHON_MODULE_DIR}/parsermodule.o
4342
${PYTHON_MODULE_DIR}/_pickle.o
4443
${PYTHON_MODULE_DIR}/_posixsubprocess.o
4544
${PYTHON_MODULE_DIR}/pyexpat.o ${PYTHON_MODULE_DIR}/expat/xmlparse.o ${PYTHON_MODULE_DIR}/expat/xmlrole.o ${PYTHON_MODULE_DIR}/expat/xmltok.o

multipy/runtime/test_deploy.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ const char* path(const char* envname, const char* path) {
4848
return e ? e : path;
4949
}
5050

51+
TEST(TorchpyTest, InitManagerBasic) {
52+
torch::deploy::InterpreterManager m(1);
53+
ASSERT_EQ(m.countRegisteredModuleSources(), 1);
54+
}
55+
5156
TEST(TorchpyTest, LoadLibrary) {
5257
torch::deploy::InterpreterManager m(1);
5358
torch::deploy::Package p = m.loadPackage(

0 commit comments

Comments
 (0)