Skip to content

Commit 64963c1

Browse files
Remove custom python version preproc flag (#234)
Summary: As title, replace with py_version_hex. Pull Request resolved: #234 Test Plan: Unit tests should pass. Reviewed By: d4l3k, PaliC Differential Revision: D40733843 Pulled By: anirbanr-fb-r2p fbshipit-source-id: 3f75ae057a130d77055b49945e5d5df811170a95
1 parent b25b90a commit 64963c1

File tree

7 files changed

+10
-23
lines changed

7 files changed

+10
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Requirements:
1515
* x86_64 (Beta)
1616
* arm64/aarch64 (Prototype)
1717

18-
> ℹ️ This is project is in Beta. `torch::deploy` is ready for use in production environments but may have some rough edges that we're continuously working on improving. We're always interested in hearing feedback and usecases that you might have. Feel free to reach out!
18+
> ℹ️ `torch::deploy` is ready for use in production environments, but is in Beta and may have some rough edges that we're continuously working on improving. We're always interested in hearing feedback and usecases that you might have. Feel free to reach out!
1919
2020
## Installation
2121

multipy/runtime/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ project(MultipyRuntime)
1212
option(BUILD_CUDA_TESTS "Set to ON in order to build cuda tests. By default we do not" OFF)
1313
option(GDB_ON "Sets to debug mode (for gdb), defaults to OFF" OFF)
1414

15-
OPTION(LEGACY_PYTHON_PRE_3_8 "Whether to use Python 3.7 codepaths." OFF)
16-
1715
if(GDB_ON)
1816
set(CMAKE_BUILD_TYPE Debug)
1917
endif()
@@ -95,10 +93,6 @@ set(INTERPRETER_TEST_SOURCES_GPU
9593

9694
add_executable(test_deploy ${INTERPRETER_TEST_SOURCES})
9795
# target_compile_definitions(test_deploy PUBLIC TEST_CUSTOM_LIBRARY)
98-
if (${LEGACY_PYTHON_PRE_3_8})
99-
message(STATUS "LEGACY_PYTHON_PRE_3_8 set in parent cmakefile.")
100-
target_compile_definitions(test_deploy PUBLIC LEGACY_PYTHON_PRE_3_8)
101-
endif()
10296
target_include_directories(test_deploy PRIVATE ${PYTORCH_ROOT}/torch)
10397
target_link_libraries(test_deploy
10498
PUBLIC "-Wl,--no-as-needed -rdynamic" gtest dl torch_deploy_interface c10 torch_cpu

multipy/runtime/interpreter/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ SET(INTERPRETER_DIR "${DEPLOY_DIR}/interpreter" PARENT_SCOPE)
1111

1212
SET(MULTIPY_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../../utils")
1313

14-
OPTION(LEGACY_PYTHON_PRE_3_8 "Whether to use Python 3.7 codepaths." OFF)
15-
1614
message(STATUS "Python3_EXECUTABLE - ${Python3_EXECUTABLE}" )
1715
message(STATUS "Python3_SITELIB - ${Python3_SITELIB}" )
1816
message(STATUS "Python3_LIBRARIES - ${Python3_LIBRARIES}" )
@@ -27,11 +25,6 @@ message(STATUS "Python3_STATIC_LIBRARIES - ${Python3_STATIC_LIBRARIES}" )
2725

2826
include_directories(BEFORE ${CMAKE_SOURCE_DIR}/../..)
2927

30-
if (${LEGACY_PYTHON_PRE_3_8})
31-
message(STATUS "LEGACY_PYTHON_PRE_3_8 set")
32-
add_compile_definitions(LEGACY_PYTHON_PRE_3_8)
33-
endif()
34-
3528
# add gtest dependency
3629
include(FetchContent)
3730
FetchContent_Declare(
@@ -89,5 +82,3 @@ target_link_libraries(torch_deployinterpreter PRIVATE fmt::fmt-header-only)
8982
target_link_libraries(torch_deployinterpreter PRIVATE torch_python)
9083
target_link_libraries(torch_deployinterpreter PRIVATE gtest)
9184
target_link_libraries(torch_deployinterpreter PRIVATE multipy_torch)
92-
93-
unset(LEGACY_PYTHON_PRE_3_8)

multipy/runtime/interpreter/builtin_registry.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ void BuiltinRegistry::runPreInitialization() {
6464
appendCPythonInittab();
6565
}
6666

67-
#ifndef LEGACY_PYTHON_PRE_3_8
67+
#if PY_VERSION_HEX >= 0x03080100
68+
// For Python 3.8+.
6869
const char* metaPathSetupTemplate = R"PYTHON(
6970
import sys
7071
from importlib.metadata import DistributionFinder, Distribution
@@ -109,6 +110,7 @@ class DummyDistribution(Distribution):
109110
sys.meta_path.insert(0, F())
110111
)PYTHON";
111112
#else
113+
// For Python 3.7.
112114
const char* metaPathSetupTemplate = R"PYTHON(
113115
import sys
114116
class F:

multipy/runtime/interpreter/interpreter_impl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ ConcreteInterpreterImplConstructorCommon(
369369
const std::vector<std::string>& plugin_paths) {
370370
BuiltinRegistry::runPreInitialization();
371371

372-
#ifndef LEGACY_PYTHON_PRE_3_8
372+
#if PY_VERSION_HEX >= 0x03080100
373+
// For Python 3.8+.
373374
PyPreConfig preconfig;
374375
PyPreConfig_InitIsolatedConfig(&preconfig);
375376
PyStatus status = Py_PreInitialize(&preconfig);
@@ -408,6 +409,7 @@ ConcreteInterpreterImplConstructorCommon(
408409
TORCH_INTERNAL_ASSERT(!PyStatus_Exception(status))
409410

410411
#else
412+
// For Python 3.7.
411413
Py_InitializeEx(1);
412414
TORCH_INTERNAL_ASSERT(Py_IsInitialized);
413415
#endif

multipy/runtime/test_deploy.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ result = torch.Tensor([1,2,3])
473473
EXPECT_TRUE(w_grad0.equal(w_grad1));
474474
}
475475

476-
#ifndef LEGACY_PYTHON_PRE_3_8
476+
// For Python 3.8+ only.
477+
#if PY_VERSION_HEX >= 0x03080100
477478
TEST(TorchpyTest, ImportlibMetadata) {
478479
torch::deploy::InterpreterManager m(1);
479480
m.registerModuleSource("importlib_test", R"PYTHON(

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,11 @@ def run(self):
7878
build_dir_abs = base_dir + "/" + build_dir
7979
if not os.path.exists(build_dir_abs):
8080
os.makedirs(build_dir_abs)
81-
legacy_python_cmake_flag = "OFF" if sys.version_info.minor > 7 else "ON"
8281

8382
print(f"-- Running multipy runtime makefile in dir {build_dir_abs}")
8483
try:
8584
subprocess.run(
86-
[
87-
f"cmake -DBUILD_CUDA_TESTS={self.cuda_tests_flag} -DLEGACY_PYTHON_PRE_3_8={legacy_python_cmake_flag} .."
88-
],
85+
[f"cmake -DBUILD_CUDA_TESTS={self.cuda_tests_flag} .."],
8986
cwd=build_dir_abs,
9087
shell=True,
9188
check=True,

0 commit comments

Comments
 (0)