Skip to content

Commit

Permalink
[pytorch] deprecate default_op_deps.yaml (pytorch#59573)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#59573

To do mobile selective build, we have several options:
1. static dispatch;
2. dynamic dispatch + static analysis (to create the dependency graph);
3. dynamic dispatch + tracing;

We are developing 3. For open source, we used to only support 1, and
currently we support both 1 and 2.

This file is only used for 2. It was introduced when we deprecated
the static dispatch (1). The motivation was to make sure we have a
low-friction selective build workflow for dynamic dispatch (2).
As the name indicates, it is the *default* dependency graph that users
can try if they don't bother to run the static analyzer themselves.
We have a CI to run the full workflow of 2 on every PR, which creates
the dependency graph on-the-fly instead of using the committed file.

Since the workflow to automatically update the file has been broken
for a while, it started to confuse other pytorch developers as people
are already manually editing it, and it might be broken for some models
already.

We reintroduced the static dispatch recently, so we decide to deprecate
this file now and automatically turn on static dispatch if users run
selective build without providing the static analysis graph.

The tracing-based selective build will be the ultimate solution we'd
like to provide for OSS, but it will take some more effort to polish
and release.

Differential Revision:
D28941020
D28941020

Test Plan: Imported from OSS

Reviewed By: dhruvbird

Pulled By: ljk53

fbshipit-source-id: 9977ab8568e2cc1bdcdecd3d22e29547ef63889e
  • Loading branch information
ljk53 authored and facebook-github-bot committed Jun 8, 2021
1 parent c436426 commit 501320e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12,222 deletions.
47 changes: 28 additions & 19 deletions cmake/Codegen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -166,31 +166,40 @@ if(INTERN_BUILD_ATEN_OPS)
endif()
endif()

if(STATIC_DISPATCH_BACKEND)
message(STATUS "Custom build with static dispatch backend: ${STATIC_DISPATCH_BACKEND}")
list(APPEND CUSTOM_BUILD_FLAGS
--static_dispatch_backend ${STATIC_DISPATCH_BACKEND})
endif()

if(SELECTED_OP_LIST)
# With static dispatch we can omit the OP_DEPENDENCY flag. It will not calculate the transitive closure
# of used ops. It only needs to register used root ops.
if(NOT STATIC_DISPATCH_BACKEND AND NOT OP_DEPENDENCY)
message(INFO "Use default op dependency graph .yaml file for custom build with dynamic dispatch.")
set(OP_DEPENDENCY ${CMAKE_CURRENT_LIST_DIR}/../tools/code_analyzer/default_op_deps.yaml)
message(WARNING
"For custom build with dynamic dispatch you have to provide the dependency graph of PyTorch operators.\n"
"Switching to STATIC_DISPATCH_BACKEND=CPU. If you run into problems with static dispatch and still want"
" to use selective build with dynamic dispatch, please try:\n"
"1. Run the static analysis tool to generate the dependency graph, e.g.:\n"
" LLVM_DIR=/usr ANALYZE_TORCH=1 tools/code_analyzer/build.sh\n"
"2. Run the custom build with the OP_DEPENDENCY option pointing to the generated dependency graph, e.g.:\n"
" scripts/build_android.sh -DSELECTED_OP_LIST=<op_list.yaml> -DOP_DEPENDENCY=<dependency_graph.yaml>\n"
)
set(STATIC_DISPATCH_BACKEND CPU)
else()
execute_process(
COMMAND
"${PYTHON_EXECUTABLE}" ${CMAKE_CURRENT_LIST_DIR}/../tools/code_analyzer/gen_op_registration_allowlist.py
--op-dependency "${OP_DEPENDENCY}"
--root-ops "${SELECTED_OP_LIST}"
OUTPUT_VARIABLE OP_REGISTRATION_WHITELIST
)
separate_arguments(OP_REGISTRATION_WHITELIST)
message(STATUS "Custom build with op registration whitelist: ${OP_REGISTRATION_WHITELIST}")
list(APPEND CUSTOM_BUILD_FLAGS
--force_schema_registration
--op_registration_whitelist ${OP_REGISTRATION_WHITELIST})
endif()
execute_process(
COMMAND
"${PYTHON_EXECUTABLE}" ${CMAKE_CURRENT_LIST_DIR}/../tools/code_analyzer/gen_op_registration_allowlist.py
--op-dependency "${OP_DEPENDENCY}"
--root-ops "${SELECTED_OP_LIST}"
OUTPUT_VARIABLE OP_REGISTRATION_WHITELIST
)
separate_arguments(OP_REGISTRATION_WHITELIST)
message(STATUS "Custom build with op registration whitelist: ${OP_REGISTRATION_WHITELIST}")
endif()

if(STATIC_DISPATCH_BACKEND)
message(STATUS "Custom build with static dispatch backend: ${STATIC_DISPATCH_BACKEND}")
list(APPEND CUSTOM_BUILD_FLAGS
--force_schema_registration
--op_registration_whitelist ${OP_REGISTRATION_WHITELIST})
--static_dispatch_backend ${STATIC_DISPATCH_BACKEND})
endif()

set(GEN_COMMAND
Expand Down
3 changes: 2 additions & 1 deletion test/mobile/custom_build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ run_custom_build_with_static_dispatch() {
# by the JIT runtime. The intermediate ops will be automatically kepted
# by the linker as they are statically referenced by the static dispatch
# code, for which we can bypass the registration.
# We don't set '-DSTATIC_DISPATCH_BACKEND=CPU' explicitly to test automatic
# fallback to static dispatch when '-DOP_DEPENDENCY' is omitted.
BUILD_ROOT="${LIBTORCH_BUILD_ROOT}" \
"${SRC_ROOT}/scripts/build_mobile.sh" \
-DCMAKE_CXX_FLAGS="-DSTRIP_ERROR_MESSAGES" \
-DSTATIC_DISPATCH_BACKEND=CPU \
-DSELECTED_OP_LIST="${ROOT_OPS}"
}

Expand Down
Loading

0 comments on commit 501320e

Please sign in to comment.