Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce67fc0403 | ||
|
|
25a75f9138 | ||
|
|
46be05d4a2 | ||
|
|
10a621ac7e | ||
|
|
0d912b623e | ||
|
|
d65305484e | ||
|
|
bc2de075f5 | ||
|
|
b9b85d8bb7 | ||
|
|
af55dd59af | ||
|
|
2e1a17d4b1 | ||
|
|
ab5f233823 | ||
|
|
4146762193 | ||
|
|
c24a2a26f2 | ||
|
|
99baa47bac | ||
|
|
3aad7226de | ||
|
|
2c1766a041 | ||
|
|
58402d67d2 | ||
|
|
22a5bf8eba | ||
|
|
7ec3a5a42a | ||
|
|
8611e0e3d5 | ||
|
|
a2ed4eb074 | ||
|
|
c6d5d99656 | ||
|
|
c927f4d52e | ||
|
|
a52a2a7582 | ||
|
|
28b81ba784 | ||
|
|
118cead9db | ||
|
|
37983612eb | ||
|
|
a0d5f0413a | ||
|
|
3f7654bb90 | ||
|
|
6f3c3f8c93 | ||
|
|
663e48a628 | ||
|
|
4c0b1766ab | ||
|
|
69547a0826 | ||
|
|
5b9b7041b2 | ||
|
|
bc0fbdcac9 | ||
|
|
ea561b97c9 | ||
|
|
f431153967 | ||
|
|
e82066018d | ||
|
|
a4fdc51ac9 | ||
|
|
42badebbad | ||
|
|
9d43973a43 | ||
|
|
9d4224f9a5 | ||
|
|
c2a7dc3f17 | ||
|
|
be21b4c339 | ||
|
|
851cc9e42e | ||
|
|
6963a9c6f5 | ||
|
|
f38ae2d871 | ||
|
|
cc3ebabbca | ||
|
|
d70ae50d78 | ||
|
|
f99298b02b | ||
|
|
8d64c91316 | ||
|
|
a40e37d953 | ||
|
|
5996fed7b1 | ||
|
|
3be7bcf63d | ||
|
|
6fc30ad19f | ||
|
|
81a39d545f | ||
|
|
75a9089e09 | ||
|
|
b256f3cfcd | ||
|
|
a03b990d2f | ||
|
|
b1de459aab | ||
|
|
78bb23dcfc | ||
|
|
358e163e2b | ||
|
|
e3cacd1240 | ||
|
|
5a675a23c2 | ||
|
|
62e6edd1be | ||
|
|
8b0bb12ed2 | ||
|
|
08895e3452 | ||
|
|
eb19e5be07 | ||
|
|
dbbb5b935b | ||
|
|
27b2513f2f | ||
|
|
18cee26cfb | ||
|
|
d9c203af66 | ||
|
|
a96f349728 | ||
|
|
08d67bb93b | ||
|
|
9d1f8c2062 | ||
|
|
e56d176f63 | ||
|
|
46d2c88c76 | ||
|
|
16c6efb99c | ||
|
|
3deb4f4041 | ||
|
|
63f22cf38d | ||
|
|
95bc96954a | ||
|
|
a323bfb26d | ||
|
|
4c28fae7ff | ||
|
|
d73f7d15d1 | ||
|
|
64142762fb | ||
|
|
2671012415 | ||
|
|
9cb88c4ae8 | ||
|
|
3015977115 | ||
|
|
25e1415cb4 | ||
|
|
9276d4c441 | ||
|
|
3ab4642abd | ||
|
|
aa1466742a | ||
|
|
9bfd72d468 | ||
|
|
0fa13028d3 | ||
|
|
358cba8b6d | ||
|
|
c684b7c74a | ||
|
|
d836a9cb3c | ||
|
|
369ebefd2e | ||
|
|
e1b754a902 | ||
|
|
c6ad5c5cc5 | ||
|
|
54af470c20 | ||
|
|
c56e5299d5 | ||
|
|
edfe8b0306 | ||
|
|
0143c1c06e | ||
|
|
fe09035482 | ||
|
|
e8f0e0055c | ||
|
|
255e1b94f6 | ||
|
|
b184e1c1d3 | ||
|
|
a85cb62301 | ||
|
|
1500208c7f | ||
|
|
073ad70cc4 | ||
|
|
6741696481 | ||
|
|
48dd2489e0 | ||
|
|
7e0b4081ac | ||
|
|
88d5c2c545 | ||
|
|
c39847cbba | ||
|
|
8fa79690b2 | ||
|
|
b6464ff2b2 | ||
|
|
a12b0dd319 | ||
|
|
b9c513ed2d | ||
|
|
e7218aaf60 | ||
|
|
5de5ce6d04 | ||
|
|
62992d4000 | ||
|
|
34f84c6ca4 | ||
|
|
4ebeb1fd6a | ||
|
|
c4c5da1ed0 | ||
|
|
4ad96e17f4 | ||
|
|
f6bd4ea357 | ||
|
|
6c52cd2a5d | ||
|
|
11ee398a57 | ||
|
|
c4c9340104 | ||
|
|
931f3c3878 | ||
|
|
a48b4fd558 | ||
|
|
d44bc70aae | ||
|
|
021efdf1da | ||
|
|
1d607dcf4f | ||
|
|
b2afdd7871 | ||
|
|
37fc10168a | ||
|
|
6432bc6349 | ||
|
|
4160ab8ab6 | ||
|
|
afaa4d4e88 | ||
|
|
91014cd3b8 | ||
|
|
798f0c3b16 | ||
|
|
c28c47c9cd | ||
|
|
bda914c574 | ||
|
|
edb5c70443 | ||
|
|
4689a0514b | ||
|
|
63950d1412 | ||
|
|
16fb2692c6 | ||
|
|
193cd1f80d | ||
|
|
6b5302218a | ||
|
|
a27e4f60c6 | ||
|
|
ae48832f81 | ||
|
|
08403764d6 | ||
|
|
998d0c88b9 | ||
|
|
7a0a5a6eb0 | ||
|
|
cb9b8627b9 | ||
|
|
6b80c3e7d6 | ||
|
|
b6069682fd | ||
|
|
9cb7f795df | ||
|
|
7024d04779 | ||
|
|
70f0613df8 | ||
|
|
2468dd37ae | ||
|
|
7446763b5f | ||
|
|
a45cb145e9 | ||
|
|
6bbc1db7d2 | ||
|
|
59d9f9fe86 | ||
|
|
c682f1e267 | ||
|
|
1505864443 | ||
|
|
fdfb70af54 | ||
|
|
aac3e9f237 | ||
|
|
cb5937bf50 | ||
|
|
45a79b8865 | ||
|
|
18a27fad1f | ||
|
|
2ae4953208 | ||
|
|
2e90ba92b9 | ||
|
|
dfb77c9348 | ||
|
|
eca80895e7 | ||
|
|
30722c29f5 | ||
|
|
e0003631b5 | ||
|
|
a83ecb1f7f | ||
|
|
b2b33bd531 |
@@ -1,24 +0,0 @@
|
||||
<!-- Thanks for sending a pull request!
|
||||
-->
|
||||
|
||||
**What type of PR is this?**
|
||||
> Uncomment only one ` /kind <>` line, hit enter to put that in a new line, and remove leading whitespaces from that line:
|
||||
>
|
||||
> /kind bug
|
||||
> /kind task
|
||||
> /kind feature
|
||||
|
||||
|
||||
**What does this PR do / why do we need it**:
|
||||
|
||||
|
||||
**Which issue(s) this PR fixes**:
|
||||
<!--
|
||||
*Automatically closes linked issue when PR is merged.
|
||||
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
|
||||
-->
|
||||
Fixes #
|
||||
|
||||
**Special notes for your reviewers**:
|
||||
|
||||
|
||||
@@ -1,203 +0,0 @@
|
||||
# READ THIS BEFORE YOU REFACTOR ME
|
||||
#
|
||||
# setup.py uses the list of patterns in this file to decide
|
||||
# what to delete, but it's not 100% sound. So, for example,
|
||||
# if you delete aten/build/ because it's redundant with build/,
|
||||
# aten/build/ will stop being cleaned. So be careful when
|
||||
# refactoring this file!
|
||||
|
||||
## PyTorch
|
||||
.coverage
|
||||
coverage.xml
|
||||
.dmypy.json
|
||||
.gradle
|
||||
.hypothesis
|
||||
.mypy_cache
|
||||
*/*.so*
|
||||
*/**/__pycache__
|
||||
*/**/*.dylib*
|
||||
*/**/*.pyd
|
||||
*/**/*.so*
|
||||
log
|
||||
# Root level file used in CI to specify certain env configs.
|
||||
# E.g., see .circleci/config.yaml
|
||||
env
|
||||
.circleci/scripts/COMMIT_MSG
|
||||
|
||||
# IPython notebook checkpoints
|
||||
.ipynb_checkpoints
|
||||
|
||||
# Editor temporaries
|
||||
*.swn
|
||||
*.swo
|
||||
*.swp
|
||||
*.swm
|
||||
*~
|
||||
|
||||
# macOS dir files
|
||||
.DS_Store
|
||||
|
||||
# Ninja files
|
||||
.ninja_deps
|
||||
.ninja_log
|
||||
compile_commands.json
|
||||
*.egg-info/
|
||||
|
||||
## General
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.cuo
|
||||
*.obj
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Compiled protocol buffers
|
||||
*.pb.h
|
||||
*.pb.cc
|
||||
*_pb2.py
|
||||
|
||||
# Compiled python
|
||||
*.pyc
|
||||
*.pyd
|
||||
|
||||
# Compiled MATLAB
|
||||
*.mex*
|
||||
|
||||
# IPython notebook checkpoints
|
||||
.ipynb_checkpoints
|
||||
|
||||
# Editor temporaries
|
||||
*.swn
|
||||
*.swo
|
||||
*.swp
|
||||
*~
|
||||
|
||||
# Sublime Text settings
|
||||
*.sublime-workspace
|
||||
*.sublime-project
|
||||
|
||||
# Eclipse Project settings
|
||||
*.*project
|
||||
.settings
|
||||
|
||||
# QtCreator files
|
||||
*.user
|
||||
|
||||
# PyCharm files
|
||||
.idea
|
||||
|
||||
# OSX dir files
|
||||
.DS_Store
|
||||
|
||||
# GDB history
|
||||
.gdb_history
|
||||
|
||||
## Caffe2
|
||||
|
||||
# build, distribute, and bins (+ python proto bindings)
|
||||
build
|
||||
build_host_protoc
|
||||
build_android
|
||||
build_ios
|
||||
/build_*
|
||||
.build_debug/*
|
||||
.build_release/*
|
||||
.build_profile/*
|
||||
distribute/*
|
||||
*.testbin
|
||||
*.bin
|
||||
cmake_build
|
||||
.cmake_build
|
||||
gen
|
||||
.setuptools-cmake-build
|
||||
.pytest_cache
|
||||
aten/build/*
|
||||
dist
|
||||
|
||||
# Bram
|
||||
plsdontbreak
|
||||
|
||||
# Generated documentation
|
||||
docs/_site
|
||||
docs/gathered
|
||||
_site
|
||||
doxygen
|
||||
docs/dev
|
||||
|
||||
# LevelDB files
|
||||
*.sst
|
||||
*.ldb
|
||||
LOCK
|
||||
CURRENT
|
||||
MANIFEST-*
|
||||
|
||||
# generated version file
|
||||
caffe2/version.py
|
||||
|
||||
# setup.py intermediates
|
||||
.eggs
|
||||
caffe2.egg-info
|
||||
|
||||
# Atom/Watchman required file
|
||||
.watchmanconfig
|
||||
|
||||
# Files generated by CLion
|
||||
cmake-build-debug
|
||||
|
||||
# BEGIN NOT-CLEAN-FILES (setup.py handles this marker. Do not change.)
|
||||
#
|
||||
# Below files are not deleted by "setup.py clean".
|
||||
|
||||
# Visual Studio Code files
|
||||
.vscode
|
||||
.vs
|
||||
|
||||
# YouCompleteMe config file
|
||||
.ycm_extra_conf.py
|
||||
|
||||
# Files generated when a patch is rejected
|
||||
*.orig
|
||||
*.rej
|
||||
|
||||
# Files generated by ctags
|
||||
CTAGS
|
||||
GTAGS
|
||||
GRTAGS
|
||||
GSYMS
|
||||
GPATH
|
||||
tags
|
||||
TAGS
|
||||
|
||||
|
||||
# ccls file
|
||||
.ccls-cache/
|
||||
|
||||
# clang-format storage location used by apply_clang_format.py
|
||||
.clang-format-bin
|
||||
|
||||
# clangd background index
|
||||
.clangd/
|
||||
.cache/
|
||||
|
||||
# bazel symlinks
|
||||
bazel-*
|
||||
|
||||
# Generated files
|
||||
torch_npu/version.py
|
||||
torch_npu/csrc/aten/NPUNativeFunctions.h
|
||||
torch_npu/csrc/aten/RegisterAutogradNPU.cpp
|
||||
torch_npu/csrc/aten/RegisterCPU.cpp
|
||||
torch_npu/csrc/aten/RegisterNPU.cpp
|
||||
torch_npu/csrc/aten/python_custom_functions.cpp
|
||||
@@ -1,222 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
||||
|
||||
project(TORCHNPU CXX C)
|
||||
|
||||
option(USE_GRAPH_MODE "enable graph mode" OFF)
|
||||
|
||||
if(USE_GRAPH_MODE)
|
||||
add_definitions(-DUSE_GRAPH_MODE=1)
|
||||
endif()
|
||||
if(DEFINED TORCH_VERSION)
|
||||
add_definitions(-DPYTORCH_NPU_VERSION="${TORCH_VERSION}")
|
||||
endif()
|
||||
|
||||
set(LINUX TRUE)
|
||||
set(CMAKE_INSTALL_MESSAGE NEVER)
|
||||
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
set(PLUGIN_NAME torch_npu)
|
||||
|
||||
set(RPATH_VALUE $ORIGIN)
|
||||
set(CMAKE_SKIP_BUILD_RPATH FALSE)
|
||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
||||
set(CMAKE_INSTALL_RPATH "${RPATH_VALUE}/lib/:${RPATH_VALUE}/")
|
||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${TORCHNPU_INSTALL_LIBDIR})
|
||||
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
|
||||
|
||||
# check and set CMAKE_CXX_STANDARD
|
||||
string(FIND "${CMAKE_CXX_FLAGS}" "-std=c++" env_cxx_standard)
|
||||
if(env_cxx_standard GREATER -1)
|
||||
message(
|
||||
WARNING "C++ standard version definition detected in environment variable."
|
||||
"PyTorch requires -std=c++14. Please remove -std=c++ settings in your environment.")
|
||||
endif()
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(TORCHNPU_ROOT "${PROJECT_SOURCE_DIR}/torch_npu/csrc")
|
||||
set(TORCHNPU_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
|
||||
|
||||
set(Torch_DIR ${PYTORCH_INSTALL_DIR}/share/cmake/Torch)
|
||||
FIND_PACKAGE(Torch REQUIRED)
|
||||
|
||||
set(LINUX TRUE)
|
||||
set(CMAKE_INSTALL_MESSAGE NEVER)
|
||||
#set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
# Define build type
|
||||
IF(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
message("Debug build.")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DEBUG")
|
||||
ELSEIF(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
|
||||
message("RelWithDebInfo build")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
|
||||
ELSE()
|
||||
message("Release build.")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
|
||||
ENDIF()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
|
||||
# Eigen fails to build with some versions, so convert this to a warning
|
||||
# Details at http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1459
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-type-limits")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-array-bounds")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-result")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-overflow")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-ignored-qualifiers")
|
||||
if (CMAKE_COMPILER_IS_GNUCXX AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0))
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-overflow")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=pedantic")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=redundant-decls")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=old-style-cast")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(notdir $(abspath $<))\"'")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
|
||||
# These flags are not available in GCC-4.8.5. Set only when using clang.
|
||||
# Compared against https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/Option-Summary.html
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-partial-specialization")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-typedef-redefinition")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-aligned-allocation-unavailable")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++14-extensions")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-constexpr-not-const")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-braces")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments")
|
||||
if (${COLORIZE_OUTPUT})
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
|
||||
endif()
|
||||
endif()
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
|
||||
if (${COLORIZE_OUTPUT})
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
|
||||
endif()
|
||||
endif()
|
||||
if ((APPLE AND (NOT ("${CLANG_VERSION_STRING}" VERSION_LESS "9.0")))
|
||||
OR (CMAKE_COMPILER_IS_GNUCXX
|
||||
AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0 AND NOT APPLE)))
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -faligned-new")
|
||||
endif()
|
||||
if (WERROR)
|
||||
check_cxx_compiler_flag("-Werror" COMPILER_SUPPORT_WERROR)
|
||||
if (NOT COMPILER_SUPPORT_WERROR)
|
||||
set(WERROR FALSE)
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
||||
endif()
|
||||
endif(WERROR)
|
||||
if (NOT APPLE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-uninitialized")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -O0")
|
||||
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -O0")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-math-errno")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-trapping-math")
|
||||
|
||||
if (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
set(CMAKE_C_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CMAKE_C_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CMAKE_CXX_FLAGS}")
|
||||
set(CXXFLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CXXFLAGS}")
|
||||
else()
|
||||
set(CMAKE_C_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-s,-z,noexecstack -fPIE -pie ${CMAKE_C_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-s,-z,noexecstack -fPIE -pie ${CMAKE_CXX_FLAGS}")
|
||||
set(CXXFLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-s,-z,noexecstack -fPIE -pie ${CXXFLAGS}")
|
||||
endif()
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR})
|
||||
include_directories(${PROJECT_SOURCE_DIR}/torch_npu/csrc/aten)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/third_party/hccl/inc)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/third_party/acl/inc)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/patch/include)
|
||||
|
||||
# Set installed PyTorch dir
|
||||
if(DEFINED PYTORCH_INSTALL_DIR)
|
||||
include_directories(${PYTORCH_INSTALL_DIR}/include)
|
||||
include_directories(${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include/)
|
||||
else()
|
||||
message(FATAL_ERROR, "Cannot find installed PyTorch directory")
|
||||
endif()
|
||||
|
||||
# Set Python include dir
|
||||
if(DEFINED PYTHON_INCLUDE_DIR)
|
||||
include_directories(${PYTHON_INCLUDE_DIR})
|
||||
else()
|
||||
message(FATAL_ERROR, "Cannot find installed Python head file directory")
|
||||
endif()
|
||||
|
||||
# sources
|
||||
set(ATEN_SRCS)
|
||||
set(CORE_SRCS)
|
||||
set(DIST_SRCS)
|
||||
set(FRAMEWORK_SRCS)
|
||||
set(NPU_SRCS)
|
||||
set(PROF_SRCS)
|
||||
set(UTILS_SRCS)
|
||||
|
||||
add_subdirectory(${TORCHNPU_ROOT}/aten)
|
||||
add_subdirectory(${TORCHNPU_ROOT}/core)
|
||||
add_subdirectory(${TORCHNPU_ROOT}/distributed)
|
||||
add_subdirectory(${TORCHNPU_ROOT}/framework)
|
||||
add_subdirectory(${TORCHNPU_ROOT}/npu)
|
||||
add_subdirectory(${TORCHNPU_ROOT}/profiler)
|
||||
add_subdirectory(${TORCHNPU_ROOT}/utils)
|
||||
|
||||
# Compile code with pybind11
|
||||
set(CPP_SRCS ${ATEN_SRCS} ${CORE_SRCS} ${DIST_SRCS} ${FRAMEWORK_SRCS} ${NPU_SRCS} ${PROF_SRCS} ${UTILS_SRCS})
|
||||
|
||||
|
||||
add_library(${PLUGIN_NAME} SHARED ${CPP_SRCS})
|
||||
|
||||
link_directories(${PYTORCH_INSTALL_DIR}/lib)
|
||||
link_directories(${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs)
|
||||
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libhccl.so)
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC ${PYTORCH_INSTALL_DIR}/lib/libtorch_python.so)
|
||||
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libascendcl.so)
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libacl_op_compiler.so)
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libge_runner.so)
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libgraph.so)
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libacl_tdt_channel.so)
|
||||
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC torch torch_cpu c10 python3.7m)
|
||||
|
||||
set(ATEN_THREADING "OMP" CACHE STRING "ATen parallel backend")
|
||||
message(STATUS "Using ATen parallel backend: ${ATEN_THREADING}")
|
||||
if ("${ATEN_THREADING}" STREQUAL "OMP")
|
||||
target_compile_definitions(${PLUGIN_NAME} PUBLIC "-DAT_PARALLEL_OPENMP=1")
|
||||
elseif ("${ATEN_THREADING}" STREQUAL "NATIVE")
|
||||
target_compile_definitions(${PLUGIN_NAME} PUBLIC "-DAT_PARALLEL_NATIVE=1")
|
||||
elseif ("${ATEN_THREADING}" STREQUAL "TBB")
|
||||
target_compile_definitions(${PLUGIN_NAME} PUBLIC "-DAT_PARALLEL_NATIVE_TBB=1")
|
||||
else()
|
||||
message(FATAL_ERROR "Unknown ATen parallel backend: ${ATEN_THREADING}")
|
||||
endif()
|
||||
|
||||
include(GNUInstallDirs)
|
||||
target_compile_options(${PLUGIN_NAME} PRIVATE "-DC10_BUILD_MAIN_LIB")
|
||||
install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
add_subdirectory(${TORCHNPU_ROOT}/toolkit)
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC npu_profiler)
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
- 在[Gitee](https://gitee.com/ascend/pytorch)上Fork存储库。
|
||||
- 阅读[README.md](#https://gitee.com/ascend/pytorch/blob/master/README.zh.md)以获取项目信息和构建说明。
|
||||
- 行为准则 [coc](https://gitee.com/ascend/community/blob/master/code-of-conduct_zh_cn.md)。
|
||||
|
||||
<h2 id="开发指导.md">开发指导</h2>
|
||||
|
||||
@@ -41,20 +40,19 @@
|
||||
|
||||
1. 编写测试脚本。
|
||||
|
||||
以add运算为例,在“pytorch/test/test\_network\_ops“路径下编写测试脚本文件: test\_add.py。
|
||||
以add运算为例,在“pytorch/test/test\_npu/test\_network\_ops“路径下编写测试脚本文件: test\_add.py。
|
||||
|
||||
以下示例仅为一个简单的用例实现,供用户参考。具体测试用例的实现,需要根据运算定义进行完整的覆盖才能保证功能的基本正确。
|
||||
|
||||
```
|
||||
# 引入依赖库
|
||||
import sys
|
||||
sys.path.append('..')
|
||||
import torch
|
||||
import torch_npu
|
||||
import numpy as np
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.testing.common_utils import create_common_tensor
|
||||
|
||||
from common_utils import TestCase, run_tests
|
||||
from common_device_type import dtypes, instantiate_device_type_tests
|
||||
from util_test import create_common_tensor
|
||||
|
||||
# 定义add测试用例类
|
||||
class TestAdd(TestCase):
|
||||
@@ -86,20 +84,21 @@
|
||||
self.assertRtolEqual(cpu_output, npu_output)
|
||||
|
||||
# 定义具体add场景的测试用例,用例函数需要以test_开头
|
||||
def test_add_shape_format_fp32_2d(self):
|
||||
def test_add_shape_format_fp32_2d(self, device):
|
||||
format_list = [0, 3, 29]
|
||||
shape_format = [
|
||||
[np.float32, i, [5, 256]] for i in format_list
|
||||
]
|
||||
self.add_result(shape_format)
|
||||
|
||||
instantiate_device_type_tests(TestAdd, globals(), except_for="cpu")
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
```
|
||||
|
||||
2. 设置环境变量。
|
||||
|
||||
进入"pytorch"根目录,并执行env.sh脚本。
|
||||
进入“pytorh/src“路径,并执行env.sh脚本。
|
||||
|
||||
```
|
||||
bash env.sh
|
||||
@@ -120,11 +119,11 @@
|
||||
|
||||
- 编码指南
|
||||
|
||||
请在PyTorch社区使用规统一的编码分格,python建议的编码风格是[PEP 8编码样式](https://pep8.org/),C++编码所建议的风格是 [Google C++编码指南](http://google.github.io/styleguide/cppguide.html) 。可以使用[CppLint](https://github.com/cpplint/cpplint),[CppCheck](http://cppcheck.sourceforge.net/),[CMakeLint](https://github.com/cmake-lint/cmake-lint),[CodeSpell](https://github.com/codespell-project/codespell), [Lizard](http://www.lizard.ws/),[ShellCheck](https://github.com/koalaman/shellcheck)和[pylint](https://pylint.org/)检查代码的格式,建议在您的IDE中安装这些插件。
|
||||
请在PyTorch社区使用规统一的编码分格,_Python__中_建议的编码风格是[PEP 8编码样式](https://pep8.org/),_C++_编码所建议的风格是 [Google C++编码指南](http://google.github.io/styleguide/cppguide.html) 。可以使用[CppLint](https://github.com/cpplint/cpplint),[CppCheck](http://cppcheck.sourceforge.net/),[CMakeLint](https://github.com/cmake-lint/cmake-lint),[CodeSpell](https://github.com/codespell-project/codespell), [Lizard](http://www.lizard.ws/),[ShellCheck](https://github.com/koalaman/shellcheck)和[pylint](https://pylint.org/)检查代码的格式,建议在您的IDE中安装这些插件。
|
||||
|
||||
- 单元测试指南
|
||||
|
||||
请在PyTorch社区使用统一的单元测试风格, Python中建议的单元测试风格是[pytest](http://www.pytest.org/en/latest/),C++单元测试所建议的风格是 [Googletest Primer](#https://github.com/google/googletest/blob/master/docs/primer.md) 。测试用例的设计意图应该通过它的注释名称来反映。
|
||||
请在PyTorch社区使用统一的单元测试风格, _Python_中建议的单元测试风格是[pytest](http://www.pytest.org/en/latest/),_C++_单元测试所建议的风格是 [Googletest Primer](#https://github.com/google/googletest/blob/master/docs/primer.md) 。测试用例的设计意图应该通过它的注释名称来反映。
|
||||
|
||||
- 重构指南
|
||||
|
||||
@@ -166,7 +165,7 @@
|
||||
|
||||
3. 本地开发代码。
|
||||
|
||||
为了避免多个分支之间的不一致,建议创建新的分支进行开发:
|
||||
为了避免多个分支之间的不一致,建议签出到一个新的分支:
|
||||
|
||||
```
|
||||
git checkout -b {new_branch_name} origin/master
|
||||
@@ -186,7 +185,7 @@
|
||||
git push origin {new_branch_name}
|
||||
```
|
||||
|
||||
5. 向 PyTorch存储库拉取请求。
|
||||
5. 向 PyTorh存储库拉取请求。
|
||||
|
||||
在最后一步中,您需要在新分支和“PyTorch master“分支之间拉取比较请求。完成拉取请求后,“Jenkins CI“将自动设置为构建测试。您的pull request应该尽快合并到上游 master 分支,以降低合并的风险。
|
||||
|
||||
@@ -225,3 +224,4 @@
|
||||
- 确保你的提交历史被排序。
|
||||
- 始终将您的分支与主分支保持一致。
|
||||
- 对于错误修复 PR,请确保链接所有相关问题。
|
||||
|
||||
|
||||
@@ -1,57 +1,19 @@
|
||||
approvers:
|
||||
- weili10
|
||||
- li_jing_hw
|
||||
- clinglai
|
||||
- xiepeng20
|
||||
- guang-jun-zhang2
|
||||
- xuepenginnanjing
|
||||
- yskhhh
|
||||
- brightlyking
|
||||
- wangjiangben_hw
|
||||
- zhangzhongzt
|
||||
reviewers:
|
||||
- xiaxia3
|
||||
- ascendzyj
|
||||
- yskhhh
|
||||
- li_jing_hw
|
||||
- wangjiangben_hw
|
||||
- qingfenxiaochong
|
||||
- you-ansheng
|
||||
- weili10
|
||||
- granpad7
|
||||
- clinglai
|
||||
- shaoyf
|
||||
- yanpengquan07
|
||||
- xiong05
|
||||
- liu-jiaweikf
|
||||
- xiepeng20
|
||||
- brightlyking
|
||||
- chenhao_1209
|
||||
- wbigat
|
||||
- will-devil
|
||||
- ckirchhoff
|
||||
- liu-tianlong
|
||||
- jayshu
|
||||
- lvpeiyuan
|
||||
- luyoubing
|
||||
- dai-yuwen
|
||||
- jia8liang
|
||||
- w_a_n_g_q_i
|
||||
- simonzhouchun
|
||||
- luo-hui46
|
||||
- yang-renfeihuawei
|
||||
- y00580292
|
||||
- AllenYaWang
|
||||
- lidezhao1
|
||||
- ma-dongfang
|
||||
- wangchao285
|
||||
- dilililiwhy
|
||||
- sunjiayang
|
||||
- huangyunlong2022
|
||||
- misty-rain-typhoid
|
||||
- du-jin-hang
|
||||
- xqiangx1991
|
||||
- jiangpengfei712
|
||||
- blian
|
||||
- nalinaly
|
||||
reviewers:
|
||||
- zhou_sinan
|
||||
- shibo19
|
||||
- Ronnie_zheng
|
||||
- xiaxia3
|
||||
- li_chao10
|
||||
- petissue
|
||||
- td__lihan
|
||||
- ascendzyj
|
||||
- wangyu0516
|
||||
- yskhhh
|
||||
- lvpeiyuan
|
||||
- li-xulong
|
||||
- xchu42
|
||||
- weili10
|
||||
- goodjobwubai
|
||||
- fairwarning
|
||||
@@ -1,499 +0,0 @@
|
||||
# AscendPyTorch
|
||||
## Overview
|
||||
|
||||
This project develops the PyTorch Adapter plugin to adapt Ascend to the PyTorch framework so that developers who use the PyTorch framework can obtain powerful compute capabilities of Ascend AI Processors. When setting up the environments for PyTorch model development and operating, developers can manually compile related modules on servers.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- The development or operating environment of CANN has been installed. For details, see the *CANN Software Installation Guide*.
|
||||
- Python 3.7.5, 3.8, and 3.9 are supported.
|
||||
|
||||
# System Dependencies
|
||||
|
||||
## CentOS & EulerOS
|
||||
|
||||
yum install -y patch zlib-devel libffi-devel openssl-devel libjpeg-turbo-devel gcc-c++ sqlite-devel dos2unix openblas git dos2unix
|
||||
|
||||
yum install -y gcc==7.3.0 cmake==3.12.0
|
||||
|
||||
## Ubuntu
|
||||
|
||||
apt-get install -y patch g++ make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev m4 dos2unix libopenblas-dev git dos2unix
|
||||
|
||||
apt-get install -y gcc==7.3.0 cmake==3.12.0
|
||||
|
||||
> **NOTE:**
|
||||
>If an error occurs during the installation of the GCC and CMake dependency commands, use the source code for installation. For details, see the FAQ.
|
||||
# Ascend Auxiliary Software
|
||||
| AscendPyTorch Version| CANN Version| Supported PyTorch Version| Gitee Branch|
|
||||
| :------------ | :----------- | :----------- | ------------- |
|
||||
| 2.0.2 | CANN 5.0.2 | 1.5.0.post2 | 2.0.2.tr5 |
|
||||
| 2.0.3 | CANN 5.0.3 | 1.5.0.post3 | 2.0.3.tr5 |
|
||||
| 2.0.4 | CANN 5.0.4 | 1.5.0.post4 | 2.0.4.tr5 |
|
||||
| 3.0.rc1 | CANN 5.1.RC1 | 1.5.0.post5 | v1.5.0-3.0.rc1 |
|
||||
| 3.0.rc1 | CANN 5.1.RC1 | 1.8.1.rc1 | v1.8.1-3.0.rc1 |
|
||||
| 3.0.rc2 | CANN 5.1.RC2 | 1.5.0.post6 | v1.5.0-3.0.rc2 |
|
||||
| 3.0.rc2 | CANN 5.1.RC2 | 1.8.1.rc2 | v1.8.1-3.0.rc2 |
|
||||
|
||||
# Installation Methods
|
||||
|
||||
## Install the PyTorch environment dependencies.
|
||||
|
||||
If you install dependencies as a non-root user, add **--user** at the end of each command in this step, for example, **pip3 install pyyaml --user**.
|
||||
|
||||
```sh
|
||||
pip3 install pyyaml
|
||||
pip3 install wheel
|
||||
```
|
||||
|
||||
## Compile and install the PyTorch and Ascend plugin.
|
||||
|
||||
Install the official torch package, and then compile and install the plugin.
|
||||
|
||||
```sh
|
||||
#x86_64
|
||||
pip3 install torch==1.8.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
|
||||
# If an error is reported when you run the pip command to install PyTorch of the CPU version, manually download the .whl package from https://download.pytorch.org/whl/torch.
|
||||
|
||||
#AArch64
|
||||
#The community does not provide the CPU installation package of the ARM architecture. For details, see the first FAQ to compile and install PyTorch using the source code.
|
||||
```
|
||||
|
||||
Compile and generate the binary installation package of the PyTorch plugin.
|
||||
Download code of the corresponding branch and go to the root directory of the plugin.
|
||||
```
|
||||
#
|
||||
git clone -b v1.8.1-3.0.rc2 https://gitee.com/ascend/pytorch.git
|
||||
cd pytorch
|
||||
# Specify the Python version packaging mode:
|
||||
bash ci/build.sh --python=3.7
|
||||
# or
|
||||
bash ci/build.sh --python=3.8
|
||||
# or
|
||||
bash ci/build.sh --python=3.9
|
||||
```
|
||||
|
||||
Install the **torch_npu** package generated in the **pytorch/dist** directory. *{arch}* indicates the architecture name.
|
||||
|
||||
```
|
||||
pip3 install --upgrade dist/torch_npu-1.8.1rc2-cp37-cp37m-linux_{arch}.whl
|
||||
```
|
||||
Download TorchVision.
|
||||
```
|
||||
pip3 install torchvision==0.9.1
|
||||
```
|
||||
|
||||
|
||||
# Running
|
||||
|
||||
## Execute environment variables.
|
||||
|
||||
Run the script for setting environment variables in the root directory of the current repository.
|
||||
|
||||
```
|
||||
source env.sh
|
||||
```
|
||||
|
||||
|
||||
## Customize environment variables.
|
||||
|
||||
The following are optional environment variables that may affect running models:
|
||||
|
||||
```
|
||||
export COMBINED_ENABLE=1 # (Optional) Discontinuous-to-continuous level-2 derivation optimization. To enable this function, set the value to 1. When a large number of time-consuming AsStrided operators are called in the model, you can enable this function to improve the device execution efficiency.
|
||||
export ACL_DUMP_DATA=1 # (Optional) Operator data dump function, which is used for debugging. To enable this function, set the value to 1.
|
||||
```
|
||||
|
||||
**Table 1** Description of environment variables
|
||||
<a name="zh-cn_topic_0000001152616261_table42017516135"></a>
|
||||
|
||||
<table><thead align="left"><tr id="zh-cn_topic_0000001152616261_row16198951191317"><th class="cellrowborder" valign="top" width="55.48%" id="mcps1.2.3.1.1"><p id="zh-cn_topic_0000001152616261_p51981251161315"><a name="zh-cn_topic_0000001152616261_p51981251161315"></a><a name="zh-cn_topic_0000001152616261_p51981251161315"></a>Environment Variable</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="44.519999999999996%" id="mcps1.2.3.1.2"><p id="zh-cn_topic_0000001152616261_p9198135114133"><a name="zh-cn_topic_0000001152616261_p9198135114133"></a><a name="zh-cn_topic_0000001152616261_p9198135114133"></a>Description</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row78312162301"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1832171673019"><a name="p1832171673019"></a><a name="p1832171673019"></a>COMBINED_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p583261643014"><a name="p583261643014"></a><a name="p583261643014"></a>(Optional) Discontinuous-to-continuous level-2 derivation optimization. To enable this function, set the value to 1. When a large number of time-consuming AsStrided operators are called in the model, you can enable this function to improve the device execution efficiency. However, the host delivery performance may deteriorate.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row183041355123411"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p730435533415"><a name="p730435533415"></a><a name="p730435533415"></a>ACL_DUMP_DATA</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p16304105533412"><a name="p16304105533412"></a><a name="p16304105533412"></a>(Optional) Operator data dump function, which is used for debugging. To enable this function, set the value to 1.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
## Run the unit test script.
|
||||
|
||||
Verify the running. The output is **OK**.
|
||||
|
||||
```shell
|
||||
cd test/test_network_ops/
|
||||
python3 test_div.py
|
||||
```
|
||||
|
||||
# (Optional) Installing the Mixed Precision Module
|
||||
|
||||
AscendPyTorch 1.8.1 integrates the AMP module and can be used for training with mixed precision. The differences between the AMP module and the Apex module are as follows. You can select a desired module. For details about how to compile and install the Apex module, see the related [**README.en**](https://gitee.com/ascend/apex) file.
|
||||
|
||||
- AMP
|
||||
- Dynamic loss scale: The loss scale value is dynamically calculated to determine whether overflow occurs.
|
||||
- Tensor fusion is not supported.
|
||||
|
||||
- Apex
|
||||
|
||||
- O1 configuration mode: Conv and Matmul use the float16 precision for computing, and Softmax and BN use float32.
|
||||
- O2 configuration mode: BN uses the float32 precision for computing, and others use float16.
|
||||
- Static loss scale: Parameters are statically set to ensure the convergence of training with mixed precision.
|
||||
- Dynamic loss scale: The loss scale value is dynamically calculated to determine whether overflow occurs.
|
||||
|
||||
|
||||
|
||||
|
||||
# Documents
|
||||
|
||||
For more details about the installation guide, model porting and training/inference tutorials, and API list, see [User Documents](https://gitee.com/ascend/pytorch/tree/master/docs/en).
|
||||
|
||||
# Suggestions and Communication
|
||||
|
||||
We sincerely welcome you to join discussions in the community and contribute your suggestions. We will reply to you as soon as possible.
|
||||
|
||||
# Branch Maintenance Policies
|
||||
|
||||
The version branches of AscendPyTorch have the following maintenance phases:
|
||||
|
||||
| **Status** | **Duration** | **Description** |
|
||||
|-------------|---------------|--------------------------------------------------|
|
||||
| Planning | 1-3 months | Plan features. |
|
||||
| Development | 3 months | Develop features. |
|
||||
| Maintained | 6-12 months | Allow the incorporation of all resolved issues and release the version.|
|
||||
| Unmaintained| 0-3 months | Allow the incorporation of all resolved issues. No dedicated maintenance personnel are available. No version will be released. |
|
||||
| End Of Life (EOL) | N/A | Do not accept any modification to a branch. |
|
||||
|
||||
# Maintenance Status of Existing Branches
|
||||
|
||||
| **Branch Name**| **Status** | **Launch Date** | **Subsequent Status** | **EOL Date**|
|
||||
|------------|--------------|----------------------|----------------------------------------|------------|
|
||||
| **v2.0.2** | Maintained | 2021-07-29 | Unmaintained <br> 2022-07-29 estimated | |
|
||||
| **v2.0.3** | Maintained | 2021-10-15 | Unmaintained <br> 2022-10-15 estimated | |
|
||||
| **v2.0.4** | Maintained | 2022-01-15 | Unmaintained <br> 2023-01-15 estimated | |
|
||||
| **v3.0.rc1** | Maintained | 2022-04-10 | Unmaintained <br> 2023-04-10 estimated | |
|
||||
| **v3.0.rc2** | Maintained | 2022-07-15 | Unmaintained <br> 2023-07-15 estimated |
|
||||
# FAQs
|
||||
|
||||
## When the CPU architecture is ARM, PyTorch 1.8.1 cannot be installed using the PIP3 command because the community does not provide the torch package for the ARM CPU architecture. In this case, use the source code to compile and install PyTorch 1.8.1.
|
||||
|
||||
Download the PyTorch 1.8.1 source package.
|
||||
|
||||
```
|
||||
git clone -b v1.8.1 https://github.com/pytorch/pytorch.git --depth=1 pytorch_v1.8.1
|
||||
```
|
||||
|
||||
Access the source package to obtain the passive dependency code.
|
||||
|
||||
```
|
||||
cd pytorch_v1.8.1
|
||||
git submodule sync
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
Compile and install PyTorch 1.8.1.
|
||||
|
||||
```
|
||||
python3 setup.py install
|
||||
```
|
||||
|
||||
## When PIP is set to the Huawei source, a Python environment error occurs after the typing dependency in the **requirements.txt** file is installed.
|
||||
|
||||
When PIP is set to the Huawei source, open the **requirements.txt** file, delete the typing dependency, and then run the following command:
|
||||
|
||||
```
|
||||
pip3 install -r requirments.txt
|
||||
```
|
||||
|
||||
## The error message "no module named yaml/typing_extensions." is displayed when **bash build.sh** is run during compilation.
|
||||
|
||||
PyTorch compilation depends on the YAML and typing_extensions libraries, which need to be manually installed.
|
||||
|
||||
```
|
||||
pip3 install pyyaml
|
||||
|
||||
pip3 install typing_extensions
|
||||
```
|
||||
|
||||
After the installation is successful, run **make clean** and then **bash build.sh** to perform compilation. Otherwise, an unknown compilation error may occur due to the cache.
|
||||
|
||||
## TE cannot be found during running.
|
||||
|
||||
Development state:
|
||||
|
||||
```
|
||||
cd /urs/local/Ascend/ascend-toolkit/latest/{arch}-linux/lib64 # {arch} is the architecture name.
|
||||
|
||||
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
|
||||
|
||||
pip3 install --upgrade te-0.4.0-py3-none-any.whl
|
||||
```
|
||||
|
||||
User state:
|
||||
|
||||
```
|
||||
cd /urs/local/Ascend/nnae/latest/{arch}-linux/lib64 # {arch} is the architecture name.
|
||||
|
||||
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
|
||||
|
||||
pip3 install --upgrade te-0.4.0-py3-none-any.whl
|
||||
```
|
||||
|
||||
## During CMake installation through the CLI, an error is reported indicating that the package cannot be found. During CMake compilation, another error is reported indicating that the version is too early. In this cause, you can use the installation script or source code to compile and install CMake.
|
||||
|
||||
Method 1: Download the installation script and install CMake. (For details, see the CMake official website.)
|
||||
|
||||
x86_64 environment: cmake-3.12.0-Linux-x86_64.sh
|
||||
AArch64 environment: cmake-3.12.0-Linux-aarch64.sh
|
||||
1. Run the following command:
|
||||
|
||||
```
|
||||
./cmake-3.12.0-Linux-{arch}.sh # {arch} indicates the architecture name.
|
||||
```
|
||||
|
||||
2. Set the soft link.
|
||||
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
|
||||
3. Run the following command to check whether CMake has been installed:
|
||||
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
If the message "cmake version 3.12.0" is displayed, the installation is successful.
|
||||
|
||||
Method 2: Use the source code to compile and install.
|
||||
|
||||
1. Obtain the CMake software package.
|
||||
|
||||
```
|
||||
wget https://cmake.org/files/v3.12/cmake-3.12.0.tar.gz --no-check-certificate
|
||||
```
|
||||
|
||||
2. Decompress the package and go to the software package directory.
|
||||
|
||||
```
|
||||
tar -xf cmake-3.12.0.tar.gz
|
||||
cd cmake-3.12.0/
|
||||
```
|
||||
|
||||
3. Run the configuration, compilation, and installation commands.
|
||||
|
||||
```
|
||||
./configure --prefix=/usr/local/cmake
|
||||
make && make install
|
||||
```
|
||||
|
||||
4. Set the soft link.
|
||||
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
|
||||
5. Run the following command to check whether CMake has been installed:
|
||||
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
If the message "cmake version 3.12.0" is displayed, the installation is successful.
|
||||
|
||||
## During GCC installation through the CLI, an error is reported indicating that the package cannot be found. During GCC compilation, another error is reported.
|
||||
|
||||
When downloading GCC from some sources, you may be prompted by an error message indicating that the package cannot be found. In this case, use the source code to compile and install GCC.
|
||||
|
||||
Perform the following steps as the **root** user.
|
||||
|
||||
1. Download **gcc-7.3.0.tar.gz** from [https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz](https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz).
|
||||
|
||||
2. GCC installation requires adequate temporary space. Run the following command to clear the **/tmp** directory in advance:
|
||||
|
||||
```
|
||||
sudo rm -rf /tmp/*
|
||||
```
|
||||
|
||||
3. Install the dependency package. (CentOS and Ubuntu are used as examples.)
|
||||
|
||||
- For CentOS, run the following command:
|
||||
|
||||
```
|
||||
yum install bzip2
|
||||
```
|
||||
|
||||
- For Ubuntu, run the following command:
|
||||
|
||||
```
|
||||
apt-get install bzip2
|
||||
```
|
||||
|
||||
4. Compile and install GCC.
|
||||
|
||||
1. Go to the directory where the source package **gcc-7.3.0.tar.gz** is located and run the following command to decompress it:
|
||||
|
||||
```
|
||||
tar -zxvf gcc-7.3.0.tar.gz
|
||||
```
|
||||
|
||||
2. Go to the extracted directory and download the GCC dependency packages:
|
||||
|
||||
```
|
||||
cd gcc-7.3.0
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
If an error is reported during the command execution, run the following commands in the **gcc-7.3.0/** directory to download the dependency packages:
|
||||
|
||||
```
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
|
||||
```
|
||||
|
||||
After the preceding dependencies are downloaded, run the following command again:
|
||||
|
||||
```
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
If the verification fails, check whether there are duplicate dependency packages in the folder. If yes, delete duplicate ones.
|
||||
|
||||
3. <a name="zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310"></a>Run the configuration, compilation, and installation commands.
|
||||
|
||||
```
|
||||
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.3.0
|
||||
make -j15 # Check the number of CPUs by running **grep -w processor /proc/cpuinfo|wc -l**. In this example, the number is 15. You can set the parameters as required.
|
||||
make install
|
||||
```
|
||||
|
||||
> **NOTICE:**
|
||||
>The **--prefix** option is used to specify the **linux\_gcc7.3.0** installation path, which is configurable. Do not set it to **/usr/local** or **/usr,** which is the default installation path for the GCC installed by using the software source. Otherwise, a conflict occurs and the original GCC compilation environment of the system is damaged. In this example, the installation path is set to **/usr/local/linux\_gcc7.3.0**.
|
||||
4. Change the soft links.
|
||||
|
||||
```
|
||||
ln -s ${install_path}/bin/gcc /usr/bin/gcc
|
||||
ln -s ${install_path}/bin/g++ /usr/bin/g++
|
||||
ln -s ${install_path}/bin/c++ /usr/bin/c++
|
||||
```
|
||||
|
||||
|
||||
5. Configure the environment variable.
|
||||
|
||||
|
||||
Training must be performed in the compilation environment with GCC upgraded. If you want to run training, configure the following environment variable in your training script:
|
||||
|
||||
```
|
||||
export LD_LIBRARY_PATH=${install_path}/lib64:${LD_LIBRARY_PATH}
|
||||
```
|
||||
|
||||
**${install_path}** indicates the GCC 7.3.0 installation path configured in [3](#zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310). In this example, the GCC 7.3.0 installation path is **/usr/local/gcc7.3.0/**.
|
||||
|
||||
> **NOTE:**
|
||||
>Skip this step if you do not need to use the compilation environment with GCC upgraded.
|
||||
|
||||
If the PyTorch compilation fails, check whether the soft link library is correct.
|
||||
|
||||
libstdc++->libstdc++.so.6.0.24(7.3.0)
|
||||
|
||||
## libblas.so cannot be found.
|
||||
|
||||
The OpenBLAS library is missing in the environment. You need to install it.
|
||||
|
||||
CentOS and EulerOS
|
||||
|
||||
```sh
|
||||
yum -y install openblas
|
||||
```
|
||||
|
||||
Ubuntu
|
||||
|
||||
```sh
|
||||
apt install libopenblas-dev
|
||||
```
|
||||
|
||||
## No device is mounted to the container.
|
||||
|
||||
An NPU-related error is reported when a script is run in the container. The **device** parameter is not set before container instance startup. As a result, the instance cannot be started.
|
||||
|
||||

|
||||
|
||||
Run the following command to restart the container:
|
||||
|
||||
```sh
|
||||
docker run -it --ipc=host \
|
||||
--device=/dev/davinciX \
|
||||
--device=/dev/davinci_manager \
|
||||
--device=/dev/devmm_svm \
|
||||
--device=/dev/hisi_hdc \
|
||||
-v /usr/local/Ascend/driver \
|
||||
-v /usr/local/dcmi \
|
||||
-v /usr/local/bin/npu-smi \
|
||||
${image name}:{tag} \
|
||||
/bin/bash
|
||||
```
|
||||
|
||||
Parameter description:
|
||||
|
||||
**/dev/davinci*X***: NPU device. *X* is the physical ID of the chip, for example, **davinci0**.
|
||||
|
||||
**/dev/davinci_manager**: management device
|
||||
|
||||
**/dev/devmm_svm**: management device
|
||||
|
||||
**/dev/hisi_hdc**: management device
|
||||
|
||||
**/usr/local/Ascend/driver**: driver directory
|
||||
|
||||
**/usr/local/dcmi**: DCMI directory
|
||||
|
||||
**/usr/local/bin/npu-smi**: npu-smi tool
|
||||
|
||||
**$*{image name}:{tag}***: image name and version
|
||||
|
||||
## An error is reported during installation of -torch--whl-, indicating that -torch-1-5-0xxxx- and -torchvision- versions do not match.
|
||||
|
||||
During installation of **torch-\*.whl**, the message "ERROR: torchvision 0.6.0 has requirement torch==1.5.0, but you'll have torch 1.5.0a0+1977093 which is incompatible" is displayed.
|
||||

|
||||
|
||||
When the PyTorch is installed, the version check is automatically triggered. The version of the torchvision installed in the environment is 0.6.0. During the check, it is found that the version of the **torch-\*.whl** is inconsistent with the required version 1.5.0. As a result, an error message is displayed, but the installation is successful.
|
||||
|
||||
This problem does not affect the actual result, and no action is required.
|
||||
|
||||
|
||||
## When you run **import torch_npu**, if "_has_compatible_shallow_copy_type" is output, a warning about a repeated registration error is displayed.
|
||||
|
||||
The warning is triggered by the shallow copy operation of **Tensor.set_data**, as shown in the following figure. The main cause is that after the PyTorch plugin is decoupled, `_has_compatible_shallow_copy_type` cannot detect shallow copy of NPU tensors. You need to register `_has_compatible_shallow_copy_type` again.
|
||||
|
||||
This error can be ignored because it does not affect the model accuracy and performance.
|
||||
|
||||
It will be resolved after the NPU's device ID is incorporated into the community or the `_has_compatible_shallow_copy_type` registration mode is changed in a later PyTorch version.
|
||||
|
||||

|
||||
|
||||
## An error is reported when torch_npu is referenced with Python commands in the compilation directory.
|
||||
|
||||
To verify the torch_npu reference, switch to another directory. If you perform the verification in the compilation directory, the following error message is displayed:
|
||||
|
||||
<img src="figures/FAQ torch_npu.png" style="zoom:150%;" />
|
||||
|
||||
## Multi card training is stuck in initialization stage until timeout
|
||||
|
||||
IPv6 address is used in the "init_process_group" function of multi card communication, for example ::1 (Note that the localhost may point to the IPv6 address)
|
||||
Use IPv4 to avoid this problem
|
||||
|
||||
# Version Description
|
||||
|
||||
For details, see [Release Notes](https://gitee.com/ascend/pytorch/tree/master/docs/en/RELEASENOTE).
|
||||
@@ -1,289 +1,166 @@
|
||||
# AscendPyTorch
|
||||
<h2 id="简介md">简介</h2>
|
||||
|
||||
本项目开发了PyTorch Adapter插件,用于昇腾适配PyTorch框架,为使用PyTorch框架的开发者提供昇腾AI处理器的超强算力。用户在准备相关环境进行基于PyTorch框架模型的开发、运行时,可以选择在服务器中手动编译相关模块。
|
||||
|
||||
# 项目简介
|
||||
本项目开发了PyTorch Adapter插件,用于昇腾适配PyTorch框架,为使用PyTorch框架的开发者提供昇腾AI处理器的超强算力。
|
||||
|
||||
# 编译/执行约束
|
||||
|
||||
gcc版本: 7.3.0(只在编译场景要求)
|
||||
|
||||
cmake版本:3.12.0以上版本(只在编译场景要求)
|
||||
|
||||
python版本:3.7.5 和 3.8.x(编译方法有差别,详见脚本编译章节)
|
||||
|
||||
|
||||
# 系统依赖库
|
||||
|
||||
## CentOS & EulerOS
|
||||
|
||||
yum install -y cmake zlib-devel libffi-devel openssl-devel libjpeg-turbo-devel gcc-c++ sqlite-devel dos2unix openblas
|
||||
|
||||
## Ubuntu
|
||||
|
||||
apt-get install -y gcc g++ make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev m4 cmake dos2unix libopenblas-dev
|
||||
|
||||
|
||||
# Ascend配套软件
|
||||
|
||||
| AscendPyTorch版本 | CANN版本 |
|
||||
| :------------ | :----------- |
|
||||
| 2.0.2 | CANN 5.0.2 |
|
||||
| 2.0.3 | CANN 5.0.3 |
|
||||
|
||||
# 使用方式 --生成全量代码并编译
|
||||
|
||||
## 获取原生PyTorch源代码和third_party代码
|
||||
|
||||
当前支持pytorch 1.5.0和1.8.1的版本。根据需求,在当前仓库根目录pytorch/下获取原生PyTorch的源代码
|
||||
|
||||
```sh
|
||||
// 1.5.0 版本
|
||||
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
// 1.8.1 版本
|
||||
git clone -b v1.8.1 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
```
|
||||
|
||||
进入到pytorch/pytorch/目录下, 获取PyTorch被动依赖代码(获取时间较长,请耐心等待)。
|
||||
|
||||
```sh
|
||||
git submodule sync
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
完成且没有报错之后就生成了PyTorch及其依赖的三方代码
|
||||
|
||||
## 生成适配昇腾AI处理器的PyTorch代码。
|
||||
|
||||
进入到pytorch/scripts目录,根据选择的版本执行,执行脚本(注意:下载原生Pytorch源代码和下面版本要对应,否则可能出错)
|
||||
|
||||
```sh
|
||||
// 默认为1.5.0版本
|
||||
bash gen.sh
|
||||
// 对于1.8.1版本,则通过-v 参数指定
|
||||
bash gen.sh -v 1.8.1
|
||||
```
|
||||
|
||||
会在pytorch/pytorch/目录中生成npu适配全量代码
|
||||
|
||||
|
||||
## python依赖库
|
||||
|
||||
进入到pytorch/pytorch/目录,依赖库安装:
|
||||
|
||||
```python3
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
|
||||
## 编译torch的二进制包
|
||||
|
||||
进入到pytorch/pytorch/目录,执行
|
||||
|
||||
```sh
|
||||
# python3.7版本
|
||||
bash build.sh
|
||||
或者
|
||||
bash build.sh --python=3.7(推荐)
|
||||
|
||||
# python3.8版本
|
||||
bash build.sh --python=3.8
|
||||
```
|
||||
|
||||
生成的二进制包在pytorch/pytorch/dist/目录下
|
||||
|
||||
# 安装
|
||||
|
||||
### (以1.5.0版本为例,1.8.1版本同理)
|
||||
|
||||
**x86_64:**
|
||||
|
||||
torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl (实际可能附带小版本号例如torch-1.5.0.post2+ascend-cp37-cp37m-linux_x86_64.whl)
|
||||
|
||||
```shell
|
||||
pip3 uninstall torch
|
||||
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl
|
||||
```
|
||||
|
||||
|
||||
**arm:**
|
||||
|
||||
torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl (实际可能附带小版本号例如torch-1.5.0.post2+ascend-cp37-cp37m-linux_aarch64.whl)
|
||||
|
||||
```shell
|
||||
pip3 uninstall torch
|
||||
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
|
||||
```
|
||||
|
||||
|
||||
# 运行
|
||||
|
||||
## 运行环境变量
|
||||
|
||||
在当前仓库根目录中执行设置环境变量脚本
|
||||
|
||||
```
|
||||
source pytorch/env.sh
|
||||
```
|
||||
|
||||
|
||||
## 自定义环境变量
|
||||
|
||||
以下环境变量为NPU场景下使用的功能类或可以提升性能的环境变量:
|
||||
|
||||
```
|
||||
export TASK_QUEUE_ENABLE=1 # 使用异步任务下发,异步调用acl接口,建议默认开启,开启设置为1
|
||||
export PTCOPY_ENABLE=1 # 使用PTCopy算子模式,加速转连续及copy等过程,建议默认开启,开启设置为1
|
||||
```
|
||||
|
||||
可选的环境变量可能会对运行的模型产生影响:
|
||||
|
||||
```
|
||||
export DYNAMIC_COMPILE_ENABLE=1 # 动态shape特性功能,针对shape变化场景,可选,开启设置为1
|
||||
export COMBINED_ENABLE=1 # 非连续两个算子组合类场景优化,可选,开启设置为1
|
||||
export TRI_COMBINED_ENABLE=1 # 非连续三个算子组合类场景优化,可选,开启设置为1
|
||||
export ACL_DUMP_DATA=1 # 算子数据dump功能,调试时使用,可选,开启设置为1
|
||||
export DYNAMIC_OP="ADD#MUL" # 算子实现,ADD和MUL算子在不同场景下有不同的性能表现。可选
|
||||
```
|
||||
|
||||
|
||||
## 执行单元测试脚本
|
||||
|
||||
验证运行, 输出结果OK
|
||||
|
||||
```shell
|
||||
// 根据前述版本,选择对应的测试脚本,以下为1.5.0版本
|
||||
python3 pytorch1.5.0/test/test_npu/test_div.py
|
||||
// 以下为1.8.1版本
|
||||
python3 pytorch1.8.1/test/test_npu/test_div.py
|
||||
```
|
||||
|
||||
# 文档
|
||||
|
||||
有关安装指南、模型迁移和训练/推理教程和API列表等更多详细信息,请参考[昇腾社区PyTorch Adapter](https://www.hiascend.com/software/ai-frameworks/commercial)。
|
||||
|
||||
| 文档名称 | 文档链接 |
|
||||
| -------------------------- | ------------------------------------------------------------ |
|
||||
| PyTorch 安装指南 | [参考链接](https://www.hiascend.com/document/detail/zh/canncommercial/601/envdeployment/instg/instg_000035.html) |
|
||||
| PyTorch 网络模型迁移和训练 | [参考链接](https://www.hiascend.com/document/detail/zh/canncommercial/601/modeldevpt/ptmigr/ptmigr_0001.html) |
|
||||
| PyTorch 在线推理 | [参考链接](https://www.hiascend.com/document/detail/zh/canncommercial/601/modeldevpt/ptonlineinfer/ptonlineinfer_000001.html) |
|
||||
| PyTorch 算子适配 | [参考链接](https://www.hiascend.com/document/detail/zh/canncommercial/601/operatordev/operatordevg/atlasopdev_10_0081.html) |
|
||||
| PyTorch API清单 | [参考链接](https://www.hiascend.com/document/detail/zh/canncommercial/601/oplist/fwoperator/fwoperatorlist_0301.html) |
|
||||
|
||||
|
||||
|
||||
# 快速安装PyTorch
|
||||
|
||||
昇腾开发PyTorch Adapter插件用于适配PyTorch框架,为使用PyTorch框架的开发者提供昇腾AI处理器的超强算力,本章节指导用户安装PyTorch框架和PyTorch Adapter插件。
|
||||
|
||||
**对应分支代码包下载<a name="zh-cn_topic_0000001435374593_section5248152713711"></a>**
|
||||
|
||||
> **说明:**
|
||||
>PyTorch配套的Python版本是:Python3.7.x(3.7.5\~3.7.11)、Python3.8.x(3.8.0\~3.8.11)、Python3.9.x(3.9.0\~3.9.2)。
|
||||
|
||||
安装PyTorch时,请参见[表1](#zh-cn_topic_0000001435374593_table723553621419)下载对应分支代码包。
|
||||
|
||||
**表 1** Ascend配套软件
|
||||
|
||||
<a name="zh-cn_topic_0000001435374593_table723553621419"></a>
|
||||
|
||||
<table><thead align="left"><tr id="zh-cn_topic_0000001435374593_row723593618147"><th class="cellrowborder" valign="top" width="18.16%" id="mcps1.2.6.1.1"><p id="zh-cn_topic_0000001435374593_p12634164910142"><a name="zh-cn_topic_0000001435374593_p12634164910142"></a><a name="zh-cn_topic_0000001435374593_p12634164910142"></a>AscendPyTorch版本</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="15.78%" id="mcps1.2.6.1.2"><p id="zh-cn_topic_0000001435374593_p7634174921415"><a name="zh-cn_topic_0000001435374593_p7634174921415"></a><a name="zh-cn_topic_0000001435374593_p7634174921415"></a>CANN版本</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="17.080000000000002%" id="mcps1.2.6.1.3"><p id="zh-cn_topic_0000001435374593_p36341149111412"><a name="zh-cn_topic_0000001435374593_p36341149111412"></a><a name="zh-cn_topic_0000001435374593_p36341149111412"></a>支持PyTorch版本</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="17.05%" id="mcps1.2.6.1.4"><p id="zh-cn_topic_0000001435374593_p163414971418"><a name="zh-cn_topic_0000001435374593_p163414971418"></a><a name="zh-cn_topic_0000001435374593_p163414971418"></a>代码分支名称</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="31.929999999999996%" id="mcps1.2.6.1.5"><p id="p99351717112212"><a name="p99351717112212"></a><a name="p99351717112212"></a>AscendHub镜像版本/名称(<a href="https://ascendhub.huawei.com/#/index" target="_blank" rel="noopener noreferrer">获取链接</a>)</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr id="row1452975217222"><td class="cellrowborder" rowspan="3" valign="top" width="18.16%" headers="mcps1.2.6.1.1 "><p id="p1849173117229"><a name="p1849173117229"></a><a name="p1849173117229"></a>5.0.RC2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" rowspan="3" valign="top" width="15.78%" headers="mcps1.2.6.1.2 "><p id="p13849183142218"><a name="p13849183142218"></a><a name="p13849183142218"></a>CANN 6.3.RC2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.080000000000002%" headers="mcps1.2.6.1.3 "><p id="p197571831182710"><a name="p197571831182710"></a><a name="p197571831182710"></a>2.0.1.rc1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.05%" headers="mcps1.2.6.1.4 "><p id="p18655452182620"><a name="p18655452182620"></a><a name="p18655452182620"></a>v2.0.1-5.0.rc2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="31.929999999999996%" headers="mcps1.2.6.1.5 "><p id="p2087128165411"><a name="p2087128165411"></a><a name="p2087128165411"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<td class="cellrowborder" valign="top" width="17.080000000000002%" headers="mcps1.2.6.1.3 "><p id="p197571831182710"><a name="p197571831182710"></a><a name="p197571831182710"></a>1.8.1.post2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.05%" headers="mcps1.2.6.1.4 "><p id="p18655452182620"><a name="p18655452182620"></a><a name="p18655452182620"></a>v1.8.1-5.0.rc2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="31.929999999999996%" headers="mcps1.2.6.1.5 "><p id="p2087128165411"><a name="p2087128165411"></a><a name="p2087128165411"></a>-</p>
|
||||
</td>
|
||||
<tr id="row16995654102215"><td class="cellrowborder" valign="top" headers="mcps1.2.6.1.1 "><p id="p48506347263"><a name="p48506347263"></a><a name="p48506347263"></a>1.11.0.post1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.2 "><p id="p10655452142612"><a name="p10655452142612"></a><a name="p10655452142612"></a>v1.11.0-5.0.rc2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.3 "><p id="p2087118825410"><a name="p2087118825410"></a><a name="p2087118825410"></a>-</p>
|
||||
</td>
|
||||
<tr id="row1452975217222"><td class="cellrowborder" rowspan="2" valign="top" width="18.16%" headers="mcps1.2.6.1.1 "><p id="p1849173117229"><a name="p1849173117229"></a><a name="p1849173117229"></a>5.0.RC1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" rowspan="2" valign="top" width="15.78%" headers="mcps1.2.6.1.2 "><p id="p13849183142218"><a name="p13849183142218"></a><a name="p13849183142218"></a>CANN 6.3.RC1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.080000000000002%" headers="mcps1.2.6.1.3 "><p id="p197571831182710"><a name="p197571831182710"></a><a name="p197571831182710"></a>1.8.1.post1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.05%" headers="mcps1.2.6.1.4 "><p id="p18655452182620"><a name="p18655452182620"></a><a name="p18655452182620"></a>v1.8.1-5.0.rc1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="31.929999999999996%" headers="mcps1.2.6.1.5 "><p id="p2087128165411"><a name="p2087128165411"></a><a name="p2087128165411"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row16995654102215"><td class="cellrowborder" valign="top" headers="mcps1.2.6.1.1 "><p id="p48506347263"><a name="p48506347263"></a><a name="p48506347263"></a>1.11.0</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.2 "><p id="p10655452142612"><a name="p10655452142612"></a><a name="p10655452142612"></a>v1.11.0-5.0.rc1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.3 "><p id="p2087118825410"><a name="p2087118825410"></a><a name="p2087118825410"></a>-</p>
|
||||
</td>
|
||||
<tr id="row1452975217222"><td class="cellrowborder" rowspan="3" valign="top" width="18.16%" headers="mcps1.2.6.1.1 "><p id="p1849173117229"><a name="p1849173117229"></a><a name="p1849173117229"></a>3.0.0</p>
|
||||
</td>
|
||||
<td class="cellrowborder" rowspan="3" valign="top" width="15.78%" headers="mcps1.2.6.1.2 "><p id="p13849183142218"><a name="p13849183142218"></a><a name="p13849183142218"></a>CANN 6.0.1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.080000000000002%" headers="mcps1.2.6.1.3 "><p id="p197571831182710"><a name="p197571831182710"></a><a name="p197571831182710"></a>1.5.0.post8</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.05%" headers="mcps1.2.6.1.4 "><p id="p18655452182620"><a name="p18655452182620"></a><a name="p18655452182620"></a>v1.5.0-3.0.0</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="31.929999999999996%" headers="mcps1.2.6.1.5 "><p id="p2087128165411"><a name="p2087128165411"></a><a name="p2087128165411"></a>22.0.0/pytorch-modelzoo</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row16995654102215"><td class="cellrowborder" valign="top" headers="mcps1.2.6.1.1 "><p id="p48506347263"><a name="p48506347263"></a><a name="p48506347263"></a>1.8.1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.2 "><p id="p10655452142612"><a name="p10655452142612"></a><a name="p10655452142612"></a>v1.8.1-3.0.0</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.3 "><p id="p2087118825410"><a name="p2087118825410"></a><a name="p2087118825410"></a>22.0.0-1.8.1/pytorch-modelzoo</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row6631331153118"><td class="cellrowborder" valign="top" headers="mcps1.2.6.1.1 "><p id="p20696104313275"><a name="p20696104313275"></a><a name="p20696104313275"></a>1.11.0.rc2(beta)</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.2 "><p id="p156551352122620"><a name="p156551352122620"></a><a name="p156551352122620"></a>v1.11.0-3.0.0</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.3 "><p id="p587113885411"><a name="p587113885411"></a><a name="p587113885411"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001435374593_row423610361140"><td class="cellrowborder" rowspan="3" valign="top" width="18.16%" headers="mcps1.2.6.1.1 "><p id="p597121514227"><a name="p597121514227"></a><a name="p597121514227"></a>3.0.rc3</p>
|
||||
</td>
|
||||
<td class="cellrowborder" rowspan="3" valign="top" width="15.78%" headers="mcps1.2.6.1.2 "><p id="p69712015122215"><a name="p69712015122215"></a><a name="p69712015122215"></a>CANN 6.0.RC1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.080000000000002%" headers="mcps1.2.6.1.3 "><p id="p89718154228"><a name="p89718154228"></a><a name="p89718154228"></a>1.5.0.post7</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.05%" headers="mcps1.2.6.1.4 "><p id="p139712015142217"><a name="p139712015142217"></a><a name="p139712015142217"></a>v1.5.0-3.0.rc3</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="31.929999999999996%" headers="mcps1.2.6.1.5 "><p id="p587138125420"><a name="p587138125420"></a><a name="p587138125420"></a>22.0.RC3/pytorch-modelzoo</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001435374593_row72366365141"><td class="cellrowborder" valign="top" headers="mcps1.2.6.1.1 "><p id="p39711715202219"><a name="p39711715202219"></a><a name="p39711715202219"></a>1.8.1.rc3</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.2 "><p id="p159721515162214"><a name="p159721515162214"></a><a name="p159721515162214"></a>v1.8.1-3.0.rc3</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.3 "><p id="p17935111716221"><a name="p17935111716221"></a><a name="p17935111716221"></a>22.0.RC3-1.8.1/pytorch-modelzoo</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row14248651114319"><td class="cellrowborder" valign="top" headers="mcps1.2.6.1.1 "><p id="p117920554298"><a name="p117920554298"></a><a name="p117920554298"></a>1.11.0.rc1(beta)</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.2 "><p id="p10179125515298"><a name="p10179125515298"></a><a name="p10179125515298"></a>v1.11.0-3.0.rc3</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.3 "><p id="p7179115512292"><a name="p7179115512292"></a><a name="p7179115512292"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001435374593_row823643641415"><td class="cellrowborder" rowspan="2" valign="top" width="18.16%" headers="mcps1.2.6.1.1 "><p id="p8972131519223"><a name="p8972131519223"></a><a name="p8972131519223"></a>3.0.rc2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" rowspan="2" valign="top" width="15.78%" headers="mcps1.2.6.1.2 "><p id="p9972915202212"><a name="p9972915202212"></a><a name="p9972915202212"></a>CANN 5.1.RC2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.080000000000002%" headers="mcps1.2.6.1.3 "><p id="p18972215192215"><a name="p18972215192215"></a><a name="p18972215192215"></a>1.5.0.post6</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.05%" headers="mcps1.2.6.1.4 "><p id="p17972111510220"><a name="p17972111510220"></a><a name="p17972111510220"></a>v1.5.0-3.0.rc2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="31.929999999999996%" headers="mcps1.2.6.1.5 "><p id="p79355171226"><a name="p79355171226"></a><a name="p79355171226"></a>22.0.RC2/pytorch-modelzoo</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001435374593_row17236133611148"><td class="cellrowborder" valign="top" headers="mcps1.2.6.1.1 "><p id="p7972101514227"><a name="p7972101514227"></a><a name="p7972101514227"></a>1.8.1.rc2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.2 "><p id="p1897217155228"><a name="p1897217155228"></a><a name="p1897217155228"></a>v1.8.1-3.0.rc2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.3 "><p id="p109351117122215"><a name="p109351117122215"></a><a name="p109351117122215"></a>22.0.RC2-1.8.1/pytorch-modelzoo</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001435374593_row17237123610141"><td class="cellrowborder" rowspan="2" valign="top" width="18.16%" headers="mcps1.2.6.1.1 "><p id="p169723153221"><a name="p169723153221"></a><a name="p169723153221"></a>3.0.rc1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" rowspan="2" valign="top" width="15.78%" headers="mcps1.2.6.1.2 "><p id="p159721915182216"><a name="p159721915182216"></a><a name="p159721915182216"></a>CANN 5.1.RC1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.080000000000002%" headers="mcps1.2.6.1.3 "><p id="p18972815162217"><a name="p18972815162217"></a><a name="p18972815162217"></a>1.5.0.post5</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.05%" headers="mcps1.2.6.1.4 "><p id="p79721155222"><a name="p79721155222"></a><a name="p79721155222"></a>v1.5.0-3.0.rc1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="31.929999999999996%" headers="mcps1.2.6.1.5 "><p id="p20935131722217"><a name="p20935131722217"></a><a name="p20935131722217"></a>22.0.RC1/pytorch-modelzoo</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001435374593_row0237103681420"><td class="cellrowborder" valign="top" headers="mcps1.2.6.1.1 "><p id="p897216157226"><a name="p897216157226"></a><a name="p897216157226"></a>1.8.1.rc1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.2 "><p id="p1972101515223"><a name="p1972101515223"></a><a name="p1972101515223"></a>v1.8.1-3.0.rc1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.3 "><p id="p16935151722212"><a name="p16935151722212"></a><a name="p16935151722212"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001435374593_row15574104531416"><td class="cellrowborder" valign="top" width="18.16%" headers="mcps1.2.6.1.1 "><p id="p99721715182217"><a name="p99721715182217"></a><a name="p99721715182217"></a>2.0.4</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="15.78%" headers="mcps1.2.6.1.2 "><p id="p2097281518228"><a name="p2097281518228"></a><a name="p2097281518228"></a>CANN 5.0.4</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.080000000000002%" headers="mcps1.2.6.1.3 "><p id="p1297218156226"><a name="p1297218156226"></a><a name="p1297218156226"></a>1.5.0.post4</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.05%" headers="mcps1.2.6.1.4 "><p id="p15973915192218"><a name="p15973915192218"></a><a name="p15973915192218"></a>2.0.4.tr5</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="31.929999999999996%" headers="mcps1.2.6.1.5 "><p id="p193515171225"><a name="p193515171225"></a><a name="p193515171225"></a>21.0.4/pytorch-modelzoo</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001435374593_row14742104715146"><td class="cellrowborder" valign="top" width="18.16%" headers="mcps1.2.6.1.1 "><p id="p149734151227"><a name="p149734151227"></a><a name="p149734151227"></a>2.0.3</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="15.78%" headers="mcps1.2.6.1.2 "><p id="p1397317155220"><a name="p1397317155220"></a><a name="p1397317155220"></a>CANN 5.0.3</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.080000000000002%" headers="mcps1.2.6.1.3 "><p id="p79734156229"><a name="p79734156229"></a><a name="p79734156229"></a>1.5.0.post3</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.05%" headers="mcps1.2.6.1.4 "><p id="p997341592219"><a name="p997341592219"></a><a name="p997341592219"></a>2.0.3.tr5</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="31.929999999999996%" headers="mcps1.2.6.1.5 "><p id="p193551715225"><a name="p193551715225"></a><a name="p193551715225"></a>21.0.3/pytorch-modelzoo</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001435374593_row17748104281412"><td class="cellrowborder" valign="top" width="18.16%" headers="mcps1.2.6.1.1 "><p id="p797371515225"><a name="p797371515225"></a><a name="p797371515225"></a>2.0.2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="15.78%" headers="mcps1.2.6.1.2 "><p id="p20973615192217"><a name="p20973615192217"></a><a name="p20973615192217"></a>CANN 5.0.2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.080000000000002%" headers="mcps1.2.6.1.3 "><p id="p1997314151227"><a name="p1997314151227"></a><a name="p1997314151227"></a>1.5.0.post2</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="17.05%" headers="mcps1.2.6.1.4 "><p id="p697311512219"><a name="p697311512219"></a><a name="p697311512219"></a>2.0.2.tr5</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="31.929999999999996%" headers="mcps1.2.6.1.5 "><p id="p693510174221"><a name="p693510174221"></a><a name="p693510174221"></a>21.0.2/pytorch-modelzoo</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
**安装PyTorch环境依赖<a name="section311512324315"></a>**
|
||||
|
||||
执行如下命令安装。如果使用非root用户安装,需要在命令后加**--user**,例如:**pip3 install pyyaml --user,pip3 install wheel --user**。
|
||||
|
||||
```
|
||||
pip3 install pyyaml
|
||||
pip3 install wheel
|
||||
```
|
||||
|
||||
**安装PyTorch<a name="section1762728142316"></a>**
|
||||
|
||||
推荐用户使用编好的二进制whl包安装PyTorch 1.8.1。用户也可选择编译安装方式安装PyTorch 1.8.1。请参考[编译安装PyTorch](#使用源码编译安装PyTorch框架)。
|
||||
|
||||
1. 安装官方torch包。
|
||||
|
||||
- x86\_64
|
||||
|
||||
```
|
||||
pip3 install torch==1.8.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
|
||||
```
|
||||
|
||||
若执行以上命令安装cpu版本PyTorch报错,请点击下方PyTorch官方链接下载whl包安装。
|
||||
|
||||
PyTorch 1.8.1版本:[下载链接](https://download.pytorch.org/whl/cpu/torch-1.8.1%2Bcpu-cp37-cp37m-linux_x86_64.whl)。
|
||||
|
||||
- aarch64
|
||||
|
||||
1. 进入安装目录,执行如下命令获取鲲鹏文件共享中心上对应版本的whl包。
|
||||
|
||||
```
|
||||
# 安装1.8.1版本
|
||||
wget https://repo.huaweicloud.com/kunpeng/archive/Ascend/PyTorch/torch-1.8.1-cp37-cp37m-linux_aarch64.whl
|
||||
```
|
||||
|
||||
2. 执行如下命令安装。如果使用非root用户安装,需要在命令后加**--user。**
|
||||
|
||||
```
|
||||
# 安装1.8.1版本
|
||||
pip3 install torch-1.8.1-cp37-cp37m-linux_aarch64.whl
|
||||
```
|
||||
|
||||
|
||||
2. 安装PyTorch插件torch\_npu。以下命令以在aarch64架构下安装为例。
|
||||
|
||||
1. 进入安装目录,执行如下命令获取PyTorch插件的whl包。
|
||||
|
||||
```
|
||||
# 若用户在x86架构下安装插件,请将命令中文件包名中的“aarch64”改为“x86_64”。
|
||||
wget https://gitee.com/ascend/pytorch/releases/download/v5.0.rc2-pytorch1.8.1/torch_npu-1.8.1.post2-cp37-cp37m-linux_aarch64.whl
|
||||
```
|
||||
|
||||
2. 执行如下命令安装。如果使用非root用户安装,需要在命令后加**--user。**
|
||||
|
||||
```
|
||||
# 若用户在x86架构下安装插件,请将命令中文件包名中的“aarch64”改为“x86_64”。
|
||||
pip3 install torch_npu-1.8.1.post2-cp37-cp37m-linux_aarch64.whl
|
||||
```
|
||||
|
||||
3. 安装对应框架版本的torchvision。
|
||||
|
||||
```
|
||||
#PyTorch 1.8.1需安装0.9.1版本
|
||||
pip3 install torchvision==0.9.1
|
||||
```
|
||||
|
||||
|
||||
**安装APEX混合精度模块<a name="section154215015416"></a>**
|
||||
|
||||
混合精度训练是在训练时混合使用单精度(float32)与半精度\(float16\)数据类型,将两者结合在一起,并使用相同的超参数实现了与float32几乎相同的精度。在迁移完成、训练开始之前,基于NPU芯片的架构特性,用户需要开启混合精度,可以提升模型的性能。APEX混合精度模块是一个集优化性能、精度收敛于一身的综合优化库,可以提供不同场景下的混合精度训练支持。APEX模块的使用介绍可参考《[PyTorch 网络模型迁移和训练指南](https://www.hiascend.com/document/detail/zh/canncommercial/601/modeldevpt/ptmigr/ptmigr_0001.html)》中的“混合精度说明“章节。
|
||||
|
||||
请参见[apex: Ascend apex adapter (gitee.com)](https://gitee.com/ascend/apex)安装混合精度模块。
|
||||
|
||||
|
||||
有关安装指南、模型迁移和训练/推理教程和API列表等更多详细信息,请参考[用户文档](docs/zh)。
|
||||
|
||||
# 建议与交流
|
||||
|
||||
@@ -303,161 +180,20 @@ Ascend PyTorch的版本分支有以下几种维护阶段:
|
||||
|
||||
# 现有分支维护状态
|
||||
|
||||
| 分支名 | 当前状态 | 上线时间 | 后续状态 | EOL 日期 |
|
||||
| -------- | ------------ | ---------- | --------------------------------- | -------- |
|
||||
| v2.0.2 | EOL | 2021/7/29 | N/A | |
|
||||
| v2.0.3 | EOL | 2021/10/15 | N/A | |
|
||||
| v2.0.4 | EOL | 2022/1/15 | N/A | |
|
||||
| v3.0.rc1 | EOL | 2022/4/10 | N/A | |
|
||||
| v3.0.rc2 | UnMaintained | 2022/7/15 | EOL 2023-10-15 estimated | |
|
||||
| v3.0.rc3 | Maintained | 2022/10/20 | Unmaintained 2023-10-20 estimated | |
|
||||
| v3.0.0 | Maintained | 2023/1/18 | Unmaintained 2024-1-18 estimated | |
|
||||
| v5.0.rc1 | Maintained | 2023/4/19 | Unmaintained 2024-4-19 estimated | |
|
||||
| v5.0.rc2 | Maintained | 2023/7/19 | Unmaintained 2024-7-19 estimated | |
|
||||
| **分支名** | **当前状态** | **上线时间** | **后续状态** | **EOL 日期**|
|
||||
|------------|--------------|----------------------|----------------------------------------|------------|
|
||||
| **v2.0.2** | Maintained | 2021-07-29 | Unmaintained <br> 2022-07-29 estimated | |
|
||||
| **v2.0.3** | Maintained | 2021-10-15 | Unmaintained <br> 2022-10-15 estimated | |
|
||||
|
||||
|
||||
# FAQ
|
||||
|
||||
## 使用PyTorch原生框架在ARM CPU上算子计算结果异常
|
||||
|
||||
当前使用的PyTorch官方原生框架在ARM CPU上运行时,算子计算结果会出现异常,此问题为原生框架社区的已知问题,详细内容可参考PyTorch官方社区[ISSUE](https://github.com/pytorch/pytorch/issues/75411)。
|
||||
|
||||
可通过以下方式解决:
|
||||
|
||||
- 修改算子输入数据类型,使用float64数据类型进行运算。
|
||||
- 升级编译arm版本PyTorch使用的gcc编译器至9.4版本及以上,并使用相同编译器重新编译torch_npu、apex、mmcv等其他配套软件(避免因编译器版本不匹配导致兼容性问题)。
|
||||
|
||||
## 使用源码编译安装PyTorch框架。
|
||||
|
||||
**安装依赖<a name="section1832663918540"></a>**
|
||||
|
||||
选择编译安装方式安装时需要安装系统依赖。此处以CentOS与Ubuntu操作系统为例目前支持CentOS与Ubuntu操作系统。
|
||||
|
||||
EulerOS、OpenEuler、BCLinux、Kylin、UOS20 1020e系统可参考CentOS进行安装。
|
||||
|
||||
Debian、UOS20、UOS20 SP1、Linx系统可参考Ubuntu进行安装。
|
||||
|
||||
- CentOS
|
||||
|
||||
```
|
||||
yum install -y patch zlib-devel libffi-devel openssl-devel libjpeg-turbo-devel gcc-c++ sqlite-devel dos2unix openblas git
|
||||
yum install -y gcc==7.3.0 cmake==3.12.0 #gcc7.3.0版本及以上,cmake3.12.0版本及以上。
|
||||
```
|
||||
|
||||
- Ubuntu
|
||||
|
||||
```
|
||||
apt-get install -y patch g++ make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev m4 dos2unix libopenblas-dev git
|
||||
apt-get install -y gcc==7.3.0 cmake==3.12.0 #gcc7.3.0版本及以上,cmake3.12.0版本及以上。
|
||||
```
|
||||
|
||||
**安装PyTorch 1.8.1<a name="section462918122313"></a>**
|
||||
|
||||
以下操作步骤以安装PyTorch 1.8.1版本为例。
|
||||
|
||||
1. 安装官方torch包。
|
||||
- x86\_64
|
||||
|
||||
```
|
||||
pip3 install torch==1.8.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
|
||||
```
|
||||
|
||||
若执行以上命令安装cpu版本PyTorch报错,请点击下方PyTorch官方链接下载whl包安装。
|
||||
|
||||
PyTorch 1.8.1版本:[下载链接](https://download.pytorch.org/whl/cpu/torch-1.8.1%2Bcpu-cp37-cp37m-linux_x86_64.whl)。
|
||||
|
||||
- 在aarch64架构下,用户可以选择编译安装官方torch包。
|
||||
1. 下载PyTorch v1.8.1源码包。
|
||||
|
||||
```
|
||||
git clone -b v1.8.1 https://github.com/pytorch/pytorch.git --depth=1 pytorch_v1.8.1
|
||||
```
|
||||
|
||||
2. 进入源码包获取被动依赖代码。
|
||||
|
||||
```
|
||||
cd pytorch_v1.8.1
|
||||
git submodule sync
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
3. 配置环境变量。
|
||||
|
||||
```
|
||||
export USE_XNNPACK=0
|
||||
```
|
||||
|
||||
4. 执行编译安装。
|
||||
|
||||
```
|
||||
python3 setup.py install
|
||||
```
|
||||
|
||||
**安装torch_npu**
|
||||
|
||||
|
||||
1. 编译生成PyTorch插件的二进制安装包。
|
||||
|
||||
```
|
||||
# 下载对应PyTorch版本分支代码,进入插件根目录,以v1.8.1为例
|
||||
git clone -b v1.8.1 https://gitee.com/ascend/pytorch.git
|
||||
cd pytorch
|
||||
# 指定Python版本编包方式,以Python3.7为例,其他Python版本请使用 --python=3.8或--python3.9
|
||||
bash ci/build.sh --python=3.7
|
||||
```
|
||||
|
||||
2. 安装pytorch/dist目录下生成的插件torch\_npu包,如果使用非root用户安装,需要在命令后加**--user**。
|
||||
|
||||
```
|
||||
pip3 install --upgrade dist/torch_npu-1.8.1-cp37-cp37m-linux_aarch64.whl
|
||||
# 若用户在x86架构下安装插件请替换为对应的whl包。
|
||||
```
|
||||
|
||||
3. 安装对应框架版本的torchvision。
|
||||
|
||||
```
|
||||
#PyTorch 1.8.1需安装0.9.1版本
|
||||
pip3 install torchvision==0.9.1
|
||||
```
|
||||
|
||||
4. 配置环境变量,验证是否安装成功。
|
||||
1. 配置CANN环境变量脚本。
|
||||
|
||||
```
|
||||
source <CANN软件安装目录>/<CANN软件路径>/set_env.sh
|
||||
```
|
||||
|
||||
环境变量脚本的默认路径一般为:/usr/local/Ascend/ascend-toolkit/set_env.sh,其中ascend-toolkit路径取决于安装的CANN软件名称。
|
||||
|
||||
2. 执行如下命令,验证PyTorch是否安装成功。
|
||||
|
||||
```
|
||||
python3 -c "import torch;import torch_npu; a = torch.randn(3, 4).npu(); print(a + a);"
|
||||
```
|
||||
|
||||
显示以下内容证明PyTorch框架与插件安装成功。
|
||||
```
|
||||
tensor([[-0.6066, 6.3385, 0.0379, 3.3356],
|
||||
[ 2.9243, 3.3134, -1.5465, 0.1916],
|
||||
[-2.1807, 0.2008, -1.1431, 2.1523]], device='npu:0')
|
||||
```
|
||||
|
||||
## 在PIP设置为华为源时,安装requirements.txt中的typing依赖后,会导致python环境错误。
|
||||
|
||||
在PIP设置为华为源时,需打开requirements.txt文件,删除typing依赖,再执行命令。
|
||||
|
||||
```
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
## 编译过程执行bash build.sh报错no module named yaml/typing_extensions.
|
||||
|
||||
pytorch编译依赖 yaml库和typing_extensions库,需要手动安装。
|
||||
|
||||
```
|
||||
pip3 install pyyaml
|
||||
|
||||
pip3 install typing_extensions
|
||||
```
|
||||
|
||||
安装成功后,注意需要执行make clean在执行bash build.sh进行编译,否则可能因缓存出现未知编译错误。
|
||||
|
||||
@@ -465,179 +201,39 @@ pip3 install typing_extensions
|
||||
|
||||
开发态:
|
||||
|
||||
```
|
||||
cd /urs/local/Ascend/ascend-toolkit/latest/{arch}-linux/lib64 #{arch}为架构名称
|
||||
pip3 install --upgrade te-0.4.0-py3-none-any.whl
|
||||
```
|
||||
cd /urs/local/ascend-toolkit/latest/fwkacllib/lib64
|
||||
|
||||
用户态:
|
||||
|
||||
```
|
||||
cd /urs/local/Ascend/nnae/latest/{arch}-linux/lib64 #{arch}为架构名称
|
||||
cd /urs/local/nnae/latest/fwkacllib/lib64
|
||||
|
||||
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
|
||||
|
||||
pip3 install --upgrade te-0.4.0-py3-none-any.whl
|
||||
```
|
||||
|
||||
## 命令行安装cmake依赖时提示找不到包、编译cmake报错版本过低,可使用安装脚本或源码编译安装。
|
||||
|
||||
方法一:下载安装脚本安装cmake。(参考cmake官网)
|
||||
|
||||
X86_64环境脚本安装:cmake-3.12.0-Linux-x86_64.sh
|
||||
|
||||
aarch64环境脚本安装:cmake-3.12.0-Linux-aarch64.sh
|
||||
|
||||
1. 执行命令。
|
||||
|
||||
```
|
||||
./cmake-3.12.0-Linux-{arch}.sh #{arch}为架构名称
|
||||
```
|
||||
|
||||
2. 设置软连接。
|
||||
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
|
||||
3. 执行如下命令验证是否安装成功。
|
||||
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
如显示“cmake version 3.12.0”则表示安装成功。
|
||||
|
||||
|
||||
方法二:使用源码编译安装。
|
||||
|
||||
1. 获取cmake软件包。
|
||||
## 编译cmake报错版本过低
|
||||
|
||||
```
|
||||
wget https://cmake.org/files/v3.12/cmake-3.12.0.tar.gz --no-check-certificate
|
||||
```
|
||||
cmake官网下载linux版本安装(当前3.18.0)
|
||||
|
||||
2. 解压并进入软件包目录。
|
||||
1. 使用yum命令安装: yum install -y cmake==3.18.0
|
||||
|
||||
```
|
||||
tar -xf cmake-3.12.0.tar.gz
|
||||
cd cmake-3.12.0/
|
||||
```
|
||||
2. 下载cmake sh脚本安装:(参考cmake官网)
|
||||
|
||||
3. 执行配置、编译和安装命令。
|
||||
X86_64环境推荐脚本安装: cmake-3.18.2-Linux-x86_64.sh
|
||||
|
||||
```
|
||||
./configure --prefix=/usr/local/cmake
|
||||
make && make install
|
||||
```
|
||||
|
||||
|
||||
4. 设置软连接。
|
||||
## GCC版本问题切换问题
|
||||
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
目前存在测试环境从GCC4.8.5 切换到 GCC7.3.0。这个过程容易出现错误导致pytorch编译不过,以下是需要软连接的库
|
||||
|
||||
5. 执行如下命令验证是否安装成功。
|
||||
gcc, g++,c++(--version 必须是7.3.0)
|
||||
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
如显示“cmake version 3.12.0”则表示安装成功。
|
||||
|
||||
## 命令行安装gcc依赖时提示找不到包、编译时gcc报错问题
|
||||
|
||||
部分源下载gcc时会提示无法找到包,需要使用源码编译安装。
|
||||
|
||||
以下步骤请在root用户下执行。
|
||||
|
||||
1. 下载gcc-7.5.0.tar.gz,下载地址为[https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.5.0/gcc-7.5.0.tar.gz](https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.5.0/gcc-7.5.0.tar.gz)。
|
||||
|
||||
2. 安装gcc时候会占用大量临时空间,所以先执行下面的命令清空/tmp目录:
|
||||
|
||||
```
|
||||
sudo rm -rf /tmp/*
|
||||
```
|
||||
|
||||
3. 安装依赖(以CentOS和Ubuntu系统为例)。
|
||||
|
||||
- CentOS执行如下命令安装。
|
||||
|
||||
```
|
||||
yum install bzip2
|
||||
```
|
||||
|
||||
- Ubuntu执行如下命令安装。
|
||||
|
||||
```
|
||||
apt-get install bzip2
|
||||
```
|
||||
|
||||
4. 编译安装gcc。
|
||||
|
||||
1. 进入gcc-7.5.0.tar.gz源码包所在目录,解压源码包,命令为:
|
||||
|
||||
```
|
||||
tar -zxvf gcc-7.5.0.tar.gz
|
||||
```
|
||||
|
||||
2. 进入解压后的文件夹,执行如下命令下载gcc依赖包:
|
||||
|
||||
```
|
||||
cd gcc-7.5.0
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
如果执行上述命令报错,需要执行如下命令在“gcc-7.5.0/“文件夹下下载依赖包:
|
||||
|
||||
```
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
|
||||
```
|
||||
|
||||
下载好上述依赖包后,重新执行以下命令:
|
||||
|
||||
```
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
如果命令校验失败,需要确认上述依赖包在文件夹中的唯一性,无重复下载,若存在重复的依赖包,需删除。
|
||||
|
||||
3. <a name="zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310"></a>执行配置、编译和安装命令:
|
||||
|
||||
```
|
||||
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.5.0
|
||||
make -j15 # 通过grep -w processor /proc/cpuinfo|wc -l查看cpu数,示例为15,用户可自行设置相应参数。
|
||||
make install
|
||||
```
|
||||
|
||||
> **须知:**
|
||||
>其中“--prefix“参数用于指定linux\_gcc7.5.0安装路径,用户可自行配置,但注意不要配置为“/usr/local“及“/usr“,因为会与系统使用软件源默认安装的gcc相冲突,导致系统原始gcc编译环境被破坏。示例指定为“/usr/local/linux\_gcc7.5.0“。
|
||||
|
||||
4. 修改软连接。
|
||||
|
||||
```
|
||||
ln -s ${install_path}/gcc-7.5.0/bin/gcc /usr/bin/gcc
|
||||
ln -s ${install_path}/gcc-7.5.0/bin/g++ /usr/bin/g++
|
||||
ln -s ${install_path}/gcc-7.5.0/bin/c++ /usr/bin/c++
|
||||
```
|
||||
|
||||
5.配置环境变量。
|
||||
|
||||
当用户执行训练时,需要用到gcc升级后的编译环境,因此要在训练脚本中配置环境变量,通过如下命令配置。
|
||||
|
||||
```
|
||||
export LD_LIBRARY_PATH=${install_path}/lib64:${LD_LIBRARY_PATH}
|
||||
```
|
||||
|
||||
其中$\{install\_path\}为[3.](#zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310)中配置的gcc7.5.0安装路径,本示例为“/usr/local/gcc7.5.0/“。
|
||||
|
||||
> **说明:**
|
||||
>本步骤为用户在需要用到gcc升级后的编译环境时才配置环境变量。
|
||||
|
||||
若存在pytorch编译不过,请检查软连接的库是否正确。
|
||||
libstdc++->libstdc++.so.6.0.24(7.3.0)
|
||||
|
||||
|
||||
libstdc++->libstdc++.so.6.0.24(7.5.0)
|
||||
|
||||
## 找不到libblas.so问题
|
||||
|
||||
@@ -655,115 +251,6 @@ Ubuntu环境
|
||||
apt install libopenblas-dev
|
||||
```
|
||||
|
||||
## 容器中未挂载device问题
|
||||
|
||||
在容器中运行脚本出现NPU相关ERROR。由于启动容器实例时,未挂载device参数,导致无法正常启动实例。
|
||||
|
||||

|
||||
|
||||
请用户参考以下命令,重启容器。
|
||||
|
||||
```sh
|
||||
docker run -it --ipc=host \
|
||||
--device=/dev/davinciX \
|
||||
--device=/dev/davinci_manager \
|
||||
--device=/dev/devmm_svm \
|
||||
--device=/dev/hisi_hdc \
|
||||
-v /usr/local/Ascend/driver \
|
||||
-v /usr/local/dcmi \
|
||||
-v /usr/local/bin/npu-smi \
|
||||
${镜像名称}:{tag} \
|
||||
/bin/bash
|
||||
```
|
||||
|
||||
参数说明:
|
||||
|
||||
/dev/davinciX:NPU设配,X是芯片物理ID号例如davinci0。
|
||||
|
||||
/dev/davinci_manager:管理设备。
|
||||
|
||||
/dev/devmm_svm:管理设备。
|
||||
|
||||
/dev/hisi_hdc:管理设备。
|
||||
|
||||
/usr/local/Ascend/driver:驱动目录。
|
||||
|
||||
/usr/local/dcmi:DCMI目录。
|
||||
|
||||
/usr/local/bin/npu-smi:npu-smi工具。
|
||||
|
||||
${镜像名称}:{tag}:镜像名称与版本号。
|
||||
|
||||
## 安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配
|
||||
|
||||
安装“torch-\*.whl”时,提示"ERROR:torchvision 0.6.0 has requirement torch==1.5.0, but you'll have torch 1.5.0a0+1977093 which is incompatible"。
|
||||

|
||||
|
||||
安装torch时,会自动触发torchvision进行依赖版本检查,环境中安装的torchvision版本为0.6.0,检查时发现我们安装的torch-\*.whl的版本号与要求的1.5.0不一致,所以提示报错,但实际安装成功 。
|
||||
|
||||
对实际结果无影响,无需处理。
|
||||
|
||||
## import torch_npu 显示_has_compatible_shallow_copy_type重复注册warning问题
|
||||
|
||||
warning如下图所示,由Tensor.set_data浅拷贝操作触发。主要原因是PyTorch插件化解耦后,`_has_compatible_shallow_copy_type`缺乏对NPU Tensor的浅拷贝判断支持,因此需要重新注册`_has_compatible_shallow_copy_type`。
|
||||
|
||||
该warning不影响模型的精度和性能,可以忽略。
|
||||
|
||||
待NPU 设备号合入社区或者后续PyTorch版本`_has_compatible_shallow_copy_type`注册方式发生变动,该warning会被解决。
|
||||
|
||||

|
||||
|
||||
## 在编译torch_npu的目录进入python引用torch_npu报错问题
|
||||
|
||||
验证torch_npu的引入,请切换至其他目录进行,在编译目录执行会提示如下错误。
|
||||
|
||||
<img src="figures/FAQ torch_npu.png" style="zoom:150%;" />
|
||||
|
||||
## 在执行import torch_npu时出现ModuleNotFooundError: NO module named '_lzma'报错问题
|
||||
|
||||
在python命令行下,执行import torch_npu测试时,出现ModuleNotFooundError: NO module named '_lzma'问题,可能由于Python环境失效,重装Python即可。<img src="figures/QA.png" />
|
||||
|
||||
## 编译过程中出现XNNPACK相关的Make Error报错
|
||||
|
||||
编译原生pytorch时,未配置相关环境变量,导致编译不成功。
|
||||
|
||||

|
||||
|
||||
1. 执行命令设置环境变量
|
||||
|
||||
```
|
||||
export USE_XNNPACK=0
|
||||
```
|
||||
|
||||
2. 执行命令清除当前编译内容
|
||||
|
||||
```
|
||||
make clean
|
||||
```
|
||||
|
||||
3. 重新编译
|
||||
|
||||
## 编译时出现Breakpad error: field 'regs' has incomplete type 'google_breakpad::user_regs_struct'报错
|
||||
|
||||
编译原生pytorch时,未配置相关环境变量,导致编译不成功。
|
||||
|
||||
1. 执行命令配置环境变量
|
||||
|
||||
```
|
||||
export BUILD_BREAKPAD=0
|
||||
```
|
||||
|
||||
2. 执行命令清除当前编译内容
|
||||
|
||||
```
|
||||
make clean
|
||||
```
|
||||
|
||||
3. 重新编译
|
||||
|
||||
## 多卡训练初始化阶段卡顿至超时
|
||||
|
||||
init_process_group 函数中使用了IPV6地址,例如::1(注意localhost 可能指向IPv6的地址),使用IPv4可以避免这个问题
|
||||
# 版本说明
|
||||
|
||||
版本说明请参阅[ReleseNote](docs/zh/RELEASENOTE)
|
||||
@@ -1,270 +0,0 @@
|
||||
# Copyright (c) 2020 Huawei Technologies Co., Ltd
|
||||
# All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
import threading
|
||||
import queue
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
BASE_DIR = Path(__file__).absolute().parent.parent
|
||||
TEST_DIR = BASE_DIR / 'test'
|
||||
|
||||
|
||||
class AccurateTest(metaclass=ABCMeta):
|
||||
@abstractmethod
|
||||
def identify(self, modify_file):
|
||||
"""
|
||||
该接口提供代码对应的UT的路径信息
|
||||
"""
|
||||
raise Exception("abstract method. Subclasses should implement it.")
|
||||
|
||||
@staticmethod
|
||||
def find_ut_by_regex(regex):
|
||||
ut_files = []
|
||||
cmd = "find {} -name {}".format(str(TEST_DIR), regex)
|
||||
status, output = subprocess.getstatusoutput(cmd)
|
||||
if status or not output:
|
||||
pass # 对于找不到的暂时不作处理
|
||||
else:
|
||||
files = output.split('\n')
|
||||
for ut_file in files:
|
||||
if ut_file.endswith(".py"):
|
||||
ut_files.append(ut_file)
|
||||
return ut_files
|
||||
|
||||
|
||||
class OpStrategy(AccurateTest):
|
||||
"""
|
||||
通过对适配层的代码的识别
|
||||
"""
|
||||
def identify(self, modify_file):
|
||||
"""
|
||||
通过对于算子实现文件的文件名解析获取其单元测试的名字,比如:
|
||||
BinaryCrossEntropyWithLogitsBackwardKernelNpu.cpp
|
||||
针对这个文件,先识别关键字BinaryCrossEntropyWithLogitsBackward
|
||||
然后,获取其正则表达式*binary*cross*entropy*with*logits*backward*识别到符合要求的测试用例
|
||||
具体方法:通过大写字母切分关键字,再识别包含所有这些关键字的测试文件名。
|
||||
"""
|
||||
filename = Path(modify_file).name
|
||||
if filename.find('KernelNpu') >= 0:
|
||||
feature_line = filename.split('KernelNpu')[0]
|
||||
features = re.findall('[A-Z][^A-Z]*', feature_line)
|
||||
regex = '*' + '*'.join(["%s" % feature.lower() for feature in features]) + '*'
|
||||
return AccurateTest.find_ut_by_regex(regex)
|
||||
return []
|
||||
|
||||
|
||||
class DirectoryStrategy(AccurateTest):
|
||||
"""
|
||||
Determine whether the modified files are test cases
|
||||
"""
|
||||
def identify(self, modify_file):
|
||||
is_test_file = str(Path(modify_file).parts[0]) == "test" \
|
||||
and re.match("test_(.+).py", Path(modify_file).name)
|
||||
return [(str(BASE_DIR / modify_file))] if is_test_file else []
|
||||
|
||||
class CoreTestStrategy(AccurateTest):
|
||||
"""
|
||||
Determine whether the core tests should be runned
|
||||
"""
|
||||
block_list = ['test', 'docs']
|
||||
core_test_cases = [str(i) for i in (BASE_DIR / 'test/test_npu').rglob('test_*.py')]
|
||||
def identify(self, modify_file):
|
||||
modified_module = str(Path(modify_file).parts[0])
|
||||
if modified_module not in self.block_list:
|
||||
return self.core_test_cases
|
||||
return []
|
||||
|
||||
class CopyOptStrategy(AccurateTest):
|
||||
"""
|
||||
通过识别非连续转连续的测试用例
|
||||
"""
|
||||
def identify(self, modify_file):
|
||||
if modify_file.find('contiguous') > 0:
|
||||
regex = '*contiguous*'
|
||||
return AccurateTest.find_ut_by_regex(regex)
|
||||
return []
|
||||
|
||||
class DirectoryMappingStrategy(AccurateTest):
|
||||
"""
|
||||
Map the modified files to the corresponding test cases
|
||||
"""
|
||||
mapping_list = {
|
||||
'contrib': 'test/test_contrib',
|
||||
'cpp_extension': 'test/test_cpp_extension',
|
||||
'distributed': 'test/test_distributed',
|
||||
'fx': 'test/test_fx',
|
||||
'hooks': 'test/test_hooks',
|
||||
'optim': 'test/test_optim',
|
||||
'profiler': 'test/test_profiler',
|
||||
'onnx': 'test/test_onnx',
|
||||
'utils': 'test/test_utils',
|
||||
'testing': 'test/test_testing.py',
|
||||
}
|
||||
|
||||
def identify(self, modify_file):
|
||||
current_all_ut_path = []
|
||||
if str(Path(modify_file).parts[0]) == 'torch_npu':
|
||||
mapped_ut_path = []
|
||||
module_name = str(Path(modify_file).parts[1])
|
||||
if module_name == 'csrc':
|
||||
module_name = str(Path(modify_file).parts[2])
|
||||
if module_name in self.mapping_list:
|
||||
mapped_ut_path.append(self.mapping_list[module_name])
|
||||
file_name = str(Path(modify_file).stem)
|
||||
if file_name in self.mapping_list:
|
||||
mapped_ut_path.append(self.mapping_list[file_name])
|
||||
|
||||
for mapped_path in mapped_ut_path:
|
||||
if Path.is_file(BASE_DIR / mapped_path):
|
||||
current_all_ut_path.append(str(BASE_DIR / mapped_path))
|
||||
else:
|
||||
current_all_ut_path += [str(i) for i in (BASE_DIR / mapped_path).rglob('test_*.py')]
|
||||
return current_all_ut_path
|
||||
|
||||
class TestMgr():
|
||||
def __init__(self):
|
||||
self.modify_files = []
|
||||
self.test_files = []
|
||||
|
||||
def load(self, modify_files):
|
||||
with open(modify_files) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
self.modify_files.append(line)
|
||||
|
||||
def analyze(self):
|
||||
for modify_file in self.modify_files:
|
||||
self.test_files += DirectoryStrategy().identify(modify_file)
|
||||
self.test_files += CopyOptStrategy().identify(modify_file)
|
||||
self.test_files += OpStrategy().identify(modify_file)
|
||||
self.test_files += DirectoryMappingStrategy().identify(modify_file)
|
||||
self.test_files += CoreTestStrategy().identify(modify_file)
|
||||
unique_files = sorted(set(self.test_files))
|
||||
|
||||
exist_ut_file = [
|
||||
changed_file
|
||||
for changed_file in unique_files
|
||||
if Path(changed_file).exists()
|
||||
]
|
||||
self.test_files = exist_ut_file
|
||||
|
||||
def get_test_files(self):
|
||||
return self.test_files
|
||||
|
||||
def print_modify_files(self):
|
||||
print("modify files:")
|
||||
for modify_file in self.modify_files:
|
||||
print(modify_file)
|
||||
|
||||
def print_ut_files(self):
|
||||
print("ut files:")
|
||||
for ut_file in self.test_files:
|
||||
print(ut_file)
|
||||
|
||||
|
||||
def exec_ut(ut_files):
|
||||
"""
|
||||
执行单元测试文件,其中存在失败,则标识异常并打印相关信息
|
||||
"""
|
||||
def get_ut_name(ut_file):
|
||||
return str(Path(ut_file).relative_to(TEST_DIR))[:-3]
|
||||
|
||||
def get_ut_cmd(ut_file):
|
||||
return [sys.executable, "run_test.py", "-v", "-i", get_ut_name(ut_file)]
|
||||
|
||||
def wait_thread(process, event_timer):
|
||||
process.wait()
|
||||
event_timer.set()
|
||||
|
||||
def enqueue_output(out, log_queue):
|
||||
for line in iter(out.readline, b''):
|
||||
log_queue.put(line.decode('utf-8'))
|
||||
out.close()
|
||||
return
|
||||
|
||||
def start_thread(fn, *args):
|
||||
stdout_t = threading.Thread(target=fn, args=args)
|
||||
stdout_t.daemon = True
|
||||
stdout_t.start()
|
||||
|
||||
def print_subprocess_log(log_queue):
|
||||
while (not log_queue.empty()):
|
||||
print((log_queue.get()).strip())
|
||||
|
||||
def run_cmd_with_timeout(cmd):
|
||||
os.chdir(str(TEST_DIR))
|
||||
stdout_queue = queue.Queue()
|
||||
event_timer = threading.Event()
|
||||
|
||||
p = subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
|
||||
start_thread(wait_thread, p, event_timer)
|
||||
start_thread(enqueue_output, p.stdout, stdout_queue)
|
||||
|
||||
try:
|
||||
event_timer.wait(2000)
|
||||
ret = p.poll()
|
||||
if ret:
|
||||
print_subprocess_log(stdout_queue)
|
||||
if not event_timer.is_set():
|
||||
ret = 1
|
||||
p.kill()
|
||||
p.terminate()
|
||||
print("Timeout: Command '{}' timed out after 2000 seconds".format(" ".join(cmd)))
|
||||
print_subprocess_log(stdout_queue)
|
||||
except Exception as err:
|
||||
ret = 1
|
||||
print(err)
|
||||
return ret
|
||||
|
||||
def run_tests(ut_files):
|
||||
exec_infos = []
|
||||
has_failed = 0
|
||||
for ut_file in ut_files:
|
||||
cmd = get_ut_cmd(ut_file)
|
||||
ret = run_cmd_with_timeout(cmd)
|
||||
if ret:
|
||||
has_failed = ret
|
||||
exec_infos.append("exec ut {} failed.".format(cmd[-1]))
|
||||
else:
|
||||
exec_infos.append("exec ut {} success.".format(cmd[-1]))
|
||||
return has_failed, exec_infos
|
||||
|
||||
ret_status, exec_infos = run_tests(ut_files)
|
||||
|
||||
print("***** Total result:")
|
||||
for exec_info in exec_infos:
|
||||
print(exec_info)
|
||||
return ret_status
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cur_modify_files = str(BASE_DIR / 'modify_files.txt')
|
||||
test_mgr = TestMgr()
|
||||
test_mgr.load(cur_modify_files)
|
||||
test_mgr.analyze()
|
||||
cur_ut_files = test_mgr.get_test_files()
|
||||
|
||||
test_mgr.print_modify_files()
|
||||
test_mgr.print_ut_files()
|
||||
|
||||
ret_ut = exec_ut(cur_ut_files)
|
||||
sys.exit(ret_ut)
|
||||
@@ -1,137 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright (c) 2020 Huawei Technologies Co., Ltd
|
||||
# Copyright (c) 2019, Facebook CORPORATION.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
CUR_DIR=$(dirname $(readlink -f $0))
|
||||
SUPPORTED_PY_VERSION=(3.7 3.8 3.9)
|
||||
PY_VERSION='3.7' # Default supported python version is 3.7
|
||||
DEFAULT_SCRIPT_ARGS_NUM=1 # Default supported input parameters
|
||||
|
||||
# Parse arguments inside script
|
||||
function parse_script_args() {
|
||||
local args_num=0
|
||||
if [[ "x${1}" = "x" ]]; then
|
||||
# default: bash build.sh (python3.7)
|
||||
return 0
|
||||
fi
|
||||
|
||||
while true; do
|
||||
if [[ "x${1}" = "x" ]]; then
|
||||
break
|
||||
fi
|
||||
if [[ "$(echo "${1}"|cut -b1-|cut -b-2)" == "--" ]]; then
|
||||
args_num=$((args_num+1))
|
||||
fi
|
||||
if [[ ${args_num} -eq ${DEFAULT_SCRIPT_ARGS_NUM} ]]; then
|
||||
break
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
# if num of args are not fully parsed, throw an error.
|
||||
if [[ ${args_num} -lt ${DEFAULT_SCRIPT_ARGS_NUM} ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
while true; do
|
||||
case "${1}" in
|
||||
--python=*)
|
||||
PY_VERSION=$(echo "${1}"|cut -d"=" -f2)
|
||||
args_num=$((args_num-1))
|
||||
shift
|
||||
;;
|
||||
--tocpu=*)
|
||||
export 'NPU_TOCPU'=${1:8}
|
||||
args_num=$((args_num-1))
|
||||
shift
|
||||
;;
|
||||
-*)
|
||||
echo "ERROR Unsupported parameters: ${1}"
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
if [ "x${1}" != "x" ]; then
|
||||
echo "ERROR Unsupported parameters: ${1}"
|
||||
return 1
|
||||
fi
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# if some "--param=value" are not parsed correctly, throw an error.
|
||||
if [[ ${args_num} -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function check_python_version() {
|
||||
matched_py_version='false'
|
||||
for ver in ${SUPPORTED_PY_VERSION[*]}; do
|
||||
if [ "${PY_VERSION}" = "${ver}" ]; then
|
||||
matched_py_version='true'
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
if [ "${matched_py_version}" = 'false' ]; then
|
||||
echo "${PY_VERSION} is an unsupported python version, we suggest ${SUPPORTED_PY_VERSION[*]}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
if ! parse_script_args "$@"; then
|
||||
echo "Failed to parse script args. Please check your inputs."
|
||||
exit 1
|
||||
fi
|
||||
check_python_version
|
||||
|
||||
# Find matched dependent Python libraries to current Python version in HCCL compiling
|
||||
hccl_file=${CUR_DIR}/../third_party/acl/libs/build_stub.sh
|
||||
cmake_file=${CUR_DIR}/../CMakeLists.txt
|
||||
if [[ ${PY_VERSION} = '3.7' ]]; then
|
||||
dst_py_ver='3.7m'
|
||||
else
|
||||
dst_py_ver=${PY_VERSION}
|
||||
fi
|
||||
for src_py_ver in ${SUPPORTED_PY_VERSION[*]}; do
|
||||
if [[ ${src_py_ver} = '3.7' ]]; then
|
||||
src_py_ver='3.7m'
|
||||
fi
|
||||
if [[ $(grep -c "${src_py_ver}" ${hccl_file}) -ne 0 && ${src_py_ver} != ${dst_py_ver} ]]; then
|
||||
sed -i "s/libpython${src_py_ver}/libpython${dst_py_ver}/g" ${hccl_file}
|
||||
fi
|
||||
if [[ $(grep -c "${src_py_ver}" ${cmake_file}) -ne 0 && ${src_py_ver} != ${dst_py_ver} ]]; then
|
||||
sed -i "s/python${src_py_ver}/python${dst_py_ver}/g" ${cmake_file}
|
||||
fi
|
||||
done
|
||||
|
||||
cd ${CUR_DIR}/..
|
||||
# if you add or delete file/files in the project, you need to remove the following comment
|
||||
# make clean
|
||||
|
||||
python"${PY_VERSION}" setup.py build bdist_wheel
|
||||
if [ $? != 0 ]; then
|
||||
echo "Failed to compile the wheel file. Please check the source code by yourself."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -1,728 +0,0 @@
|
||||
# FrameworkPTAdapter 3.0.RC2 Release Notes
|
||||
|
||||
- [FrameworkPTAdapter 3.0.RC2 Release Notes](#frameworkptadapter-30rc2-release-notes)
|
||||
- [FrameworkPTAdapter 3.0.RC2](#frameworkptadapter-30rc2)
|
||||
- [Before You Start](#before-you-start)
|
||||
- [New Features](#new-features)
|
||||
- [Modified Features](#modified-features)
|
||||
- [Resolved Issues](#resolved-issues)
|
||||
- [Known Issues](#known-issues)
|
||||
- [Compatibility](#compatibility)
|
||||
- [FrameworkPTAdapter 3.0.RC1](#frameworkptadapter-30rc1)
|
||||
- [Before You Start](#before-you-start-1)
|
||||
- [New Features](#new-features-1)
|
||||
- [Modified Features](#modified-features-1)
|
||||
- [Resolved Issues](#resolved-issues-1)
|
||||
- [Known Issues](#known-issues-1)
|
||||
- [Compatibility](#compatibility-1)
|
||||
- [FrameworkPTAdapter 2.0.4](#frameworkptadapter-204)
|
||||
- [Before You Start](#before-you-start-2)
|
||||
- [New Features](#new-features-2)
|
||||
- [Modified Features](#modified-features-2)
|
||||
- [Resolved Issues](#resolved-issues-2)
|
||||
- [Known Issues](#known-issues-2)
|
||||
- [Compatibility](#compatibility-2)
|
||||
- [FrameworkPTAdapter 2.0.3](#frameworkptadapter-203)
|
||||
- [Before You Start](#before-you-start-3)
|
||||
- [New Features](#new-features-3)
|
||||
- [Modified Features](#modified-features-3)
|
||||
- [Resolved Issues](#resolved-issues-3)
|
||||
- [Known Issues](#known-issues-3)
|
||||
- [Compatibility](#compatibility-3)
|
||||
- [FrameworkPTAdapter 2.0.2](#frameworkptadapter-202)
|
||||
- [Before You Start](#before-you-start-4)
|
||||
- [New Features](#new-features-4)
|
||||
- [Modified Features](#modified-features-4)
|
||||
- [Resolved Issues](#resolved-issues-4)
|
||||
- [Known Issues](#known-issues-4)
|
||||
- [Compatibility](#compatibility-4)
|
||||
|
||||
|
||||
## FrameworkPTAdapter 3.0.RC2
|
||||
|
||||
|
||||
### Before You Start
|
||||
|
||||
This framework is modified based on the open-source PyTorch 1.5.0 and 1.8.1 developed by Facebook, inherits native PyTorch features, and uses NPUs for dynamic image training. Models are adapted by operator granularity, code can be reused, and current networks can be ported and used on NPUs with only device types or data types modified.
|
||||
|
||||
PyTorch 1.8.1 uses plug-in adaptation and is completely decoupled from the native PyTorch framework. The current functions and performance of PyTorch 1.8.1 are basically the same as those of PyTorch 1.5.0, providing good development experience for backend operator adaptation.
|
||||
AOE-based tuning is supported.
|
||||
|
||||
### New Features
|
||||
|
||||
**Table 1** Features supported by PyTorch
|
||||
|
||||
<a name="t76c34275cbb74753970f7c5a9eb594fa"></a>
|
||||
|
||||
<table><thead align="left"><tr id="r0c10e7163bf54fe8816ab5ca2d77ccc4"><th class="cellrowborder" valign="top" width="10.459999999999999%" id="mcps1.2.4.1.1"><p id="a7888762cf8294977b7d114b1c898d1bd"><a name="a7888762cf8294977b7d114b1c898d1bd"></a><a name="a7888762cf8294977b7d114b1c898d1bd"></a>Level-1 Feature</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="26.27%" id="mcps1.2.4.1.2"><p id="a4581ffde4a5f455faadfba144243a9d4"><a name="a4581ffde4a5f455faadfba144243a9d4"></a><a name="a4581ffde4a5f455faadfba144243a9d4"></a>Level-2 Feature</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="63.27%" id="mcps1.2.4.1.3"><p id="a2a1562364b09433a83133fa10b3cf2b3"><a name="a2a1562364b09433a83133fa10b3cf2b3"></a><a name="a2a1562364b09433a83133fa10b3cf2b3"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr id="row7979351559"><td class="cellrowborder" rowspan="2" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>PyTorch 1.5.0 features adapted to NPUs</p>
|
||||
</td>
|
||||
</tr>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p109832331055"><a name="p109832331055"></a><a name="p109832331055"></a> Basic framework functions</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p109832331055"><a name="p109832331055"></a><a name="p109832331055"></a> Fixed a few bugs.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row7979351559"><td class="cellrowborder" rowspan="3" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>PyTorch 1.8.1 features adapted to NPUs</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>Decoupled as plugins</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>Decoupled the torch_npu plugin from the native PyTorch framework completely.</p>
|
||||
</td>
|
||||
<tr>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>Performance optimization</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>Optimized the single-operator delivery and collective communication functions.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>API satisfaction</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>Added more APIs. (For details, see the API list.)</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### Modified Features
|
||||
|
||||
N/A
|
||||
|
||||
### Resolved Issues
|
||||
|
||||
N/A
|
||||
|
||||
### Known Issues
|
||||
|
||||
<a name="table1969972073016"></a>
|
||||
|
||||
<table><thead align="left"><tr id="row3699162017307"><th class="cellrowborder" valign="top" width="18.22%" id="mcps1.1.3.1.1"><p id="p16992020153010"><a name="p16992020153010"></a><a name="p16992020153010"></a>Known Issue</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="81.78%" id="mcps1.1.3.1.2"><p id="p269919203308"><a name="p269919203308"></a><a name="p269919203308"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row9699142003011"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1769932017300"><a name="p1769932017300"></a><a name="p1769932017300"></a>Data type support</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p13699152010301"><a name="p13699152010301"></a><a name="p13699152010301"></a>NPUs do not support the input or output of the inf/nan data of the float16 type</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row146991520153016"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p156997200308"><a name="p156997200308"></a><a name="p156997200308"></a>Data format</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p10699182020308"><a name="p10699182020308"></a><a name="p10699182020308"></a>Dimensions cannot be reduced when the format larger than 4D is used.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row11121205610549"><td class="cellrowborder" rowspan="3" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1647216219558"><a name="p1647216219558"></a><a name="p1647216219558"></a>Restrictions on collective communication</p>
|
||||
<p id="p0465121912402"><a name="p0465121912402"></a><a name="p0465121912402"></a></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p3116115695415"><a name="p3116115695415"></a><a name="p3116115695415"></a>The graphs executed on different devices in a training job must be the same.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row51211656105411"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p1311616560541"><a name="p1311616560541"></a><a name="p1311616560541"></a>Allocation at only 1, 2, 4, or 8 processors is supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row8647195765419"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p2064225716544"><a name="p2064225716544"></a><a name="p2064225716544"></a>Only the int8, int32, float16, and float32 data types are supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row4646195719548"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p4642195718541"><a name="p4642195718541"></a><a name="p4642195718541"></a>Apex function</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p864205725412"><a name="p864205725412"></a><a name="p864205725412"></a>In the current version, Apex is implemented mainly using Python, and the customized optimization of CUDA kernel in Apex is not supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### Compatibility
|
||||
|
||||
Atlas 800 (model 9010): CentOS 7.6, Ubuntu 18.04/2.04, BC-Linux 7.6, Debian 9.9, Debian 10, openEuler 20.03 LTS
|
||||
|
||||
Atlas 800 (model 9000): CentOS 7.6, Ubuntu 18.04/2.04, EulerOS 2.8/2.10, Kylin V10, BC-Linux 7.6, openEuler 20.03 LTS, UOS 20 1020e
|
||||
|
||||
## FrameworkPTAdapter 3.0.RC1
|
||||
### Before You Start
|
||||
|
||||
This framework is modified based on the open-source PyTorch 1.5.0 and 1.8.1 developed by Facebook, inherits native PyTorch features, and uses NPUs for dynamic image training. Models are adapted by operator granularity, code can be reused, and current networks can be ported and used on NPUs with only device types or data types modified.
|
||||
|
||||
PyTorch 1.8.1 adopts the plugin adaptation mode and inherits the features of PyTorch 1.5.0. Their functions are basically the same, but PyTorch 1.8.1 provides better development experience for backend operator adaptation. It supports AOE-based tuning.
|
||||
|
||||
### New Features
|
||||
|
||||
**Table 1** Features supported by PyTorch
|
||||
|
||||
<a name="t76c34275cbb74753970f7c5a9eb594fa"></a>
|
||||
|
||||
<table><thead align="left"><tr id="r0c10e7163bf54fe8816ab5ca2d77ccc4"><th class="cellrowborder" valign="top" width="10.459999999999999%" id="mcps1.2.4.1.1"><p id="a7888762cf8294977b7d114b1c898d1bd"><a name="a7888762cf8294977b7d114b1c898d1bd"></a><a name="a7888762cf8294977b7d114b1c898d1bd"></a>Level-1 Feature</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="26.27%" id="mcps1.2.4.1.2"><p id="a4581ffde4a5f455faadfba144243a9d4"><a name="a4581ffde4a5f455faadfba144243a9d4"></a><a name="a4581ffde4a5f455faadfba144243a9d4"></a>Level-2 Feature</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="63.27%" id="mcps1.2.4.1.3"><p id="a2a1562364b09433a83133fa10b3cf2b3"><a name="a2a1562364b09433a83133fa10b3cf2b3"></a><a name="a2a1562364b09433a83133fa10b3cf2b3"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr id="row7979351559"><td class="cellrowborder" rowspan="2" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>PyTorch 1.5.0 features adapted to NPUs</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>AOE-based tuning</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>Supported the AOE auto tuning tool to improve the model performance.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row13971435754"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p79831331353"><a name="p79831331353"></a><a name="p79831331353"></a>Basic framework functions</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p109832331055"><a name="p109832331055"></a><a name="p109832331055"></a> Added the function of adapted operator development. For details, see the API list.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row7979351559"><td class="cellrowborder" rowspan="3" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>PyTorch 1.8.1 features adapted to NPUs</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>Plugin decoupling</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>Decoupled the NPU-adapted code and ported it to the **torch_npu** plugin to decouple the Ascend-adapted code from the native PyTorch code.</p>
|
||||
</td>
|
||||
<tr>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>AOE-based tuning</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>Supported the AOE auto tuning tool to improve the model performance.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row109719353511"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18983183315515"><a name="p18983183315515"></a><a name="p18983183315515"></a>Improvement of framework API satisfaction</p>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p836221112812"><a name="p836221112812"></a><a name="p836221112812"></a>Supported APIs that have been adapted to Ascend PyTorch 1.5.0. For details, see the API list.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### Modified Features
|
||||
|
||||
N/A
|
||||
|
||||
### Resolved Issues
|
||||
|
||||
N/A
|
||||
|
||||
### Known Issues
|
||||
|
||||
<a name="table1969972073016"></a>
|
||||
|
||||
<table><thead align="left"><tr id="row3699162017307"><th class="cellrowborder" valign="top" width="18.22%" id="mcps1.1.3.1.1"><p id="p16992020153010"><a name="p16992020153010"></a><a name="p16992020153010"></a>Known Issue</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="81.78%" id="mcps1.1.3.1.2"><p id="p269919203308"><a name="p269919203308"></a><a name="p269919203308"></a>Symptom</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row9699142003011"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1769932017300"><a name="p1769932017300"></a><a name="p1769932017300"></a>Data type support</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p13699152010301"><a name="p13699152010301"></a><a name="p13699152010301"></a>NPUs do not support the input or output of the inf/nan data of the float16 type.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row146991520153016"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p156997200308"><a name="p156997200308"></a><a name="p156997200308"></a>Data format</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p10699182020308"><a name="p10699182020308"></a><a name="p10699182020308"></a>Dimensions cannot be reduced when the format larger than 4D is used.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row11121205610549"><td class="cellrowborder" rowspan="3" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1647216219558"><a name="p1647216219558"></a><a name="p1647216219558"></a>Restrictions on collective communication</p>
|
||||
<p id="p0465121912402"><a name="p0465121912402"></a><a name="p0465121912402"></a></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p3116115695415"><a name="p3116115695415"></a><a name="p3116115695415"></a>The graphs executed on different devices in a training job must be the same.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row51211656105411"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p1311616560541"><a name="p1311616560541"></a><a name="p1311616560541"></a>Allocation at only 1, 2, 4, or 8 processors is supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row8647195765419"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p2064225716544"><a name="p2064225716544"></a><a name="p2064225716544"></a>Only the int8, int32, float16, and float32 data types are supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row4646195719548"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p4642195718541"><a name="p4642195718541"></a><a name="p4642195718541"></a>Apex function</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p864205725412"><a name="p864205725412"></a><a name="p864205725412"></a>In the current version, Apex is implemented mainly using Python, and the customized optimization of CUDA kernel in Apex is not supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
### Compatibility
|
||||
|
||||
Atlas 800 (model 9010): CentOS 7.6, Ubuntu 18.04/2.04, BC-Linux 7.6, Debian 9.9, Debian 10, openEuler 20.03 LTS
|
||||
|
||||
Atlas 800 (model 9000): CentOS 7.6, Ubuntu 18.04/2.04, EulerOS 2.8/2.10, Kylin V10, BC-Linux 7.6, openEuler 20.03 LTS, UOS 20 1020e
|
||||
|
||||
## FrameworkPTAdapter 2.0.4
|
||||
### Before You Start
|
||||
|
||||
This framework is modified based on the open-source PyTorch 1.5.0 and 1.8.1 developed by Facebook, inherits native PyTorch features, and uses NPUs for dynamic image training. Models are adapted by operator granularity, code can be reused, and current networks can be ported and used on NPUs with only device types or data types modified.
|
||||
|
||||
PyTorch 1.8.1 inherits the features of PyTorch 1.5.0. Their functions are basically the same, but PyTorch 1.8.1 provides better development experience for backend operator adaptation. Currently, PyTorch 1.8.1 supports only the ResNet-50 network model.
|
||||
### New Features
|
||||
|
||||
**Table 1** Features supported by PyTorch
|
||||
|
||||
<table><thead align="left"><tr id="r0c10e7163bf54fe8816ab5ca2d77ccc4"><th class="cellrowborder" valign="top" width="10.459999999999999%" id="mcps1.2.4.1.1"><p id="a7888762cf8294977b7d114b1c898d1bd"><a name="a7888762cf8294977b7d114b1c898d1bd"></a><a name="a7888762cf8294977b7d114b1c898d1bd"></a>Level-1 Feature</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="26.27%" id="mcps1.2.4.1.2"><p id="a4581ffde4a5f455faadfba144243a9d4"><a name="a4581ffde4a5f455faadfba144243a9d4"></a><a name="a4581ffde4a5f455faadfba144243a9d4"></a>Level-2 Feature</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="63.27%" id="mcps1.2.4.1.3"><p id="a2a1562364b09433a83133fa10b3cf2b3"><a name="a2a1562364b09433a83133fa10b3cf2b3"></a><a name="a2a1562364b09433a83133fa10b3cf2b3"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row7979351559"><td class="cellrowborder" rowspan="3" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>PyTorch 1.5.0 features adapted to NPUs</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>Optimization of Model Accuracy Analyzer</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>Supported mapping between IR and TBE operators and enabled the NPU dump data to be loaded to the GPU side for comparison.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row109719353511"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18983183315515"><a name="p18983183315515"></a><a name="p18983183315515"></a>E2E prof</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p836221112812"><a name="p836221112812"></a><a name="p836221112812"></a>Integrated the profile data obtained by the native PyTorch Profiling tool and CANN prof tool to implement end-to-end model and operator performance analysis.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row13971435754"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p79831331353"><a name="p79831331353"></a><a name="p79831331353"></a>Basic framework functions</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p109832331055"><a name="p109832331055"></a><a name="p109832331055"></a>Added the function of adapted operator development. For details, see the operator list.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row7979351559"><td class="cellrowborder" rowspan="2" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>PyTorch 1.8.1 features adapted to NPUs</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>AMP</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>Supported the native training with automatic mixed precision (AMP) of PyTorch.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row109719353511"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18983183315515"><a name="p18983183315515"></a><a name="p18983183315515"></a>Profiling</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p836221112812"><a name="p836221112812"></a><a name="p836221112812"></a>Supported the native profiling function of PyTorch.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row7979351559"><td class="cellrowborder" rowspan="2" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>OS compatibility</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>OS compatibility</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>Supported Ubuntu 20.04 (x86 and ARM) and EulerOS 2.10 (ARM).</p>
|
||||
</td>
|
||||
<tr id="row13971435754"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p79831331353"><a name="p79831331353"></a><a name="p79831331353"></a>Python version compatibility</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p109832331055"><a name="p109832331055"></a><a name="p109832331055"></a>Supported compilation and use of Python 3.9 (only in PyTorch 1.8.1).</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### Modified Features
|
||||
|
||||
N/A
|
||||
### Resolved Issues
|
||||
|
||||
N/A
|
||||
### Known Issues
|
||||
|
||||
<table><thead align="left"><tr id="row3699162017307"><th class="cellrowborder" valign="top" width="18.22%" id="mcps1.1.3.1.1"><p id="p16992020153010"><a name="p16992020153010"></a><a name="p16992020153010"></a>Known Issue</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="81.78%" id="mcps1.1.3.1.2"><p id="p269919203308"><a name="p269919203308"></a><a name="p269919203308"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row9699142003011"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1769932017300"><a name="p1769932017300"></a><a name="p1769932017300"></a>Data type support</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p13699152010301"><a name="p13699152010301"></a><a name="p13699152010301"></a>NPUs do not support the input or output of the inf/nan data of the float16 type.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row146991520153016"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p156997200308"><a name="p156997200308"></a><a name="p156997200308"></a>Data format</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p10699182020308"><a name="p10699182020308"></a><a name="p10699182020308"></a>Dimensions cannot be reduced when the format larger than 4D is used.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row11121205610549"><td class="cellrowborder" rowspan="3" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1647216219558"><a name="p1647216219558"></a><a name="p1647216219558"></a>Restrictions on collective communication</p>
|
||||
<p id="p0465121912402"><a name="p0465121912402"></a><a name="p0465121912402"></a></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p3116115695415"><a name="p3116115695415"></a><a name="p3116115695415"></a>The graphs executed on different devices in a training job must be the same.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row51211656105411"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p1311616560541"><a name="p1311616560541"></a><a name="p1311616560541"></a>Allocation at only 1, 2, 4, or 8 processors is supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row8647195765419"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p2064225716544"><a name="p2064225716544"></a><a name="p2064225716544"></a>Only the int8, int32, float16, and float32 data types are supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row4646195719548"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p4642195718541"><a name="p4642195718541"></a><a name="p4642195718541"></a>Apex function</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p864205725412"><a name="p864205725412"></a><a name="p864205725412"></a>In the current version, Apex is implemented mainly using Python, and the customized optimization of CUDA kernel in Apex is not supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### Compatibility
|
||||
|
||||
Atlas 800 (model 9010): CentOS 7.6, Ubuntu 18.04/2.04, BC-Linux 7.6, Debian 9.9, Debian 10, openEuler 20.03 LTS
|
||||
|
||||
Atlas 800 (model 9000): CentOS 7.6, Ubuntu 18.04/2.04, EulerOS 2.8/2.10, Kylin V10, BC-Linux 7.6, openEuler 20.03 LTS, UOS 20 1020e
|
||||
## FrameworkPTAdapter 2.0.3
|
||||
### Before You Start
|
||||
|
||||
This framework is modified based on the open-source PyTorch 1.5.0 developed by Facebook, inherits native PyTorch features, and uses NPUs for dynamic image training. Models are adapted by operator granularity, code can be reused, and current networks can be ported and used on NPUs with only device types or data types modified.
|
||||
|
||||
PyTorch 1.8.1 is supported by this version and later, and this version inherits the features of PyTorch 1.5.0 and provides the same functions, except for the Profiling tool. In addition, it optimizes the backend operator adaptation. Currently, PyTorch 1.8.1 supports only the ResNet-50 network model.
|
||||
### New Features
|
||||
|
||||
**Table 1** Features supported by PyTorch
|
||||
|
||||
<table><thead align="left"><tr id="r0c10e7163bf54fe8816ab5ca2d77ccc4"><th class="cellrowborder" valign="top" width="10.459999999999999%" id="mcps1.2.4.1.1"><p id="a7888762cf8294977b7d114b1c898d1bd"><a name="a7888762cf8294977b7d114b1c898d1bd"></a><a name="a7888762cf8294977b7d114b1c898d1bd"></a>Level-1 Feature</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="26.27%" id="mcps1.2.4.1.2"><p id="a4581ffde4a5f455faadfba144243a9d4"><a name="a4581ffde4a5f455faadfba144243a9d4"></a><a name="a4581ffde4a5f455faadfba144243a9d4"></a>Level-2 Feature</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="63.27%" id="mcps1.2.4.1.3"><p id="a2a1562364b09433a83133fa10b3cf2b3"><a name="a2a1562364b09433a83133fa10b3cf2b3"></a><a name="a2a1562364b09433a83133fa10b3cf2b3"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row7979351559"><td class="cellrowborder" rowspan="5" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>PyTorch features adapted to NPUs</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>PyTorch 1.8.1</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>Added PyTorch 1.8.1. Currently, only the ResNet-50 network is supported, including the training scenario for distributed data parallel (DDP).</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row109719353511"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18983183315515"><a name="p18983183315515"></a><a name="p18983183315515"></a>Python 3.8</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p836221112812"><a name="p836221112812"></a><a name="p836221112812"></a>Supported compilation and use of Python 3.8.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row13971435754"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p79831331353"><a name="p79831331353"></a><a name="p79831331353"></a>Operator overflow/underflow detection tool</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p109832331055"><a name="p109832331055"></a><a name="p109832331055"></a>Supported IR-level operator overflow/underflow detection in the PyTorch framework. When an AI Core operator overflow/underflow occurs, the IR information is displayed.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row185381431133610"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p953883153611"><a name="p953883153611"></a><a name="p953883153611"></a>OS compatibility</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p13538203153618"><a name="p13538203153618"></a><a name="p13538203153618"></a>Supported UOS 20 1020e ARM.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row91681125173610"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p2168172519364"><a name="p2168172519364"></a><a name="p2168172519364"></a>Basic framework functions</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1416815259367"><a name="p1416815259367"></a><a name="p1416815259367"></a>Added the function of adapted operator development. For details, see the operator list.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row11970351050"><td class="cellrowborder" rowspan="26" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p298314333514"><a name="p298314333514"></a><a name="p298314333514"></a>Model training</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p19984193312511"><a name="p19984193312511"></a><a name="p19984193312511"></a>CenterFace</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p7517351258"><a name="p7517351258"></a><a name="p7517351258"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row9965351254"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1984033458"><a name="p1984033458"></a><a name="p1984033458"></a>PCBU</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p298411338513"><a name="p298411338513"></a><a name="p298411338513"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row14966351959"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p198414331957"><a name="p198414331957"></a><a name="p198414331957"></a>Net++</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1798413331756"><a name="p1798413331756"></a><a name="p1798413331756"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row20966351454"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p4984183317518"><a name="p4984183317518"></a><a name="p4984183317518"></a>FCN8S</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1698453311519"><a name="p1698453311519"></a><a name="p1698453311519"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row19653517518"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1298483319512"><a name="p1298483319512"></a><a name="p1298483319512"></a>OSNetRetinaFace</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1798423312519"><a name="p1798423312519"></a><a name="p1798423312519"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row39619351751"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1298414331513"><a name="p1298414331513"></a><a name="p1298414331513"></a>PSPnet</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p10984633254"><a name="p10984633254"></a><a name="p10984633254"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row496335654"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p19984433351"><a name="p19984433351"></a><a name="p19984433351"></a>EDSR</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p898473314517"><a name="p898473314517"></a><a name="p898473314517"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row17953357517"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p14984123312515"><a name="p14984123312515"></a><a name="p14984123312515"></a>Tsm</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p159841033855"><a name="p159841033855"></a><a name="p159841033855"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row16951435551"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p19984933457"><a name="p19984933457"></a><a name="p19984933457"></a>pnasnet5large</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p89846335512"><a name="p89846335512"></a><a name="p89846335512"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row2095113520514"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1798416331952"><a name="p1798416331952"></a><a name="p1798416331952"></a>Gaitset</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p098417336516"><a name="p098417336516"></a><a name="p098417336516"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row89516351511"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p11985153312516"><a name="p11985153312516"></a><a name="p11985153312516"></a>fcn</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p169858331155"><a name="p169858331155"></a><a name="p169858331155"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row5953353513"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18985103311514"><a name="p18985103311514"></a><a name="p18985103311514"></a>Albert</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p2098513334519"><a name="p2098513334519"></a><a name="p2098513334519"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row119533516513"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p598511336511"><a name="p598511336511"></a><a name="p598511336511"></a>AdvancedEast</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p119850331513"><a name="p119850331513"></a><a name="p119850331513"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row39511356512"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p698553311512"><a name="p698553311512"></a><a name="p698553311512"></a>ReidStrongBaseline</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1198514331659"><a name="p1198514331659"></a><a name="p1198514331659"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row129463518517"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p99851633158"><a name="p99851633158"></a><a name="p99851633158"></a>Fast-scnn</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1298514331359"><a name="p1298514331359"></a><a name="p1298514331359"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row9942035757"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p109854331151"><a name="p109854331151"></a><a name="p109854331151"></a>RDN</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1198583317511"><a name="p1198583317511"></a><a name="p1198583317511"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row79415357517"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p6985833351"><a name="p6985833351"></a><a name="p6985833351"></a>SRFlow</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p29851033350"><a name="p29851033350"></a><a name="p29851033350"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row12947357514"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p149859334518"><a name="p149859334518"></a><a name="p149859334518"></a>MGN</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p19851833850"><a name="p19851833850"></a><a name="p19851833850"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row3941735855"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p898533316518"><a name="p898533316518"></a><a name="p898533316518"></a>Roberta</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p998553318518"><a name="p998553318518"></a><a name="p998553318518"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row1093335856"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1985533451"><a name="p1985533451"></a><a name="p1985533451"></a>RegNetY</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p59851033355"><a name="p59851033355"></a><a name="p59851033355"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row49373518516"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p19986173311512"><a name="p19986173311512"></a><a name="p19986173311512"></a>VoVNet-39</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p798683310515"><a name="p798683310515"></a><a name="p798683310515"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row5930351357"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p189862336515"><a name="p189862336515"></a><a name="p189862336515"></a>RegNetX</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1398618331651"><a name="p1398618331651"></a><a name="p1398618331651"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row169312351655"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p149863337513"><a name="p149863337513"></a><a name="p149863337513"></a>RefineNet</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p2098615331959"><a name="p2098615331959"></a><a name="p2098615331959"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row11931235957"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1198616331657"><a name="p1198616331657"></a><a name="p1198616331657"></a>RefineDet</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1698611332518"><a name="p1698611332518"></a><a name="p1698611332518"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row189215359511"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p16986183319512"><a name="p16986183319512"></a><a name="p16986183319512"></a>AlignedReID</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1898715331055"><a name="p1898715331055"></a><a name="p1898715331055"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row89213351858"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p119878330511"><a name="p119878330511"></a><a name="p119878330511"></a>FaceBoxes</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p129878331158"><a name="p129878331158"></a><a name="p129878331158"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### Modified Features
|
||||
|
||||
N/A
|
||||
### Resolved Issues
|
||||
|
||||
N/A
|
||||
### Known Issues
|
||||
|
||||
<table><thead align="left"><tr id="row3699162017307"><th class="cellrowborder" valign="top" width="18.22%" id="mcps1.1.3.1.1"><p id="p16992020153010"><a name="p16992020153010"></a><a name="p16992020153010"></a>Known Issue</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="81.78%" id="mcps1.1.3.1.2"><p id="p269919203308"><a name="p269919203308"></a><a name="p269919203308"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row9699142003011"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1769932017300"><a name="p1769932017300"></a><a name="p1769932017300"></a>Data type support</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p13699152010301"><a name="p13699152010301"></a><a name="p13699152010301"></a>NPUs do not support the input or output of the inf/nan data of the float16 type.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row146991520153016"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p156997200308"><a name="p156997200308"></a><a name="p156997200308"></a>Data format</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p10699182020308"><a name="p10699182020308"></a><a name="p10699182020308"></a>Dimensions cannot be reduced when the format larger than 4D is used.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row11121205610549"><td class="cellrowborder" rowspan="3" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1647216219558"><a name="p1647216219558"></a><a name="p1647216219558"></a>Restrictions on collective communication</p>
|
||||
<p id="p0465121912402"><a name="p0465121912402"></a><a name="p0465121912402"></a></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p3116115695415"><a name="p3116115695415"></a><a name="p3116115695415"></a>The graphs executed on different devices in a training job must be the same.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row51211656105411"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p1311616560541"><a name="p1311616560541"></a><a name="p1311616560541"></a>Allocation at only 1, 2, 4, or 8 processors is supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row8647195765419"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p2064225716544"><a name="p2064225716544"></a><a name="p2064225716544"></a>Only the int8, int32, float16, and float32 data types are supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row4646195719548"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p4642195718541"><a name="p4642195718541"></a><a name="p4642195718541"></a>Apex function</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p864205725412"><a name="p864205725412"></a><a name="p864205725412"></a>In the current version, Apex is implemented mainly using Python, and the customized optimization of CUDA kernel in Apex is not supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### Compatibility
|
||||
|
||||
Atlas 800 (model 9010): CentOS 7.6, Ubuntu 18.04, BC-Linux 7.6, Debian 9.9, Debian 10, openEuler 20.03 LTS
|
||||
|
||||
Atlas 800 (model 9000): CentOS 7.6, Euler 2.8, Kylin v10, BC-Linux 7.6, openEuler 20.03 LTS, UOS 20 1020e
|
||||
|
||||
## FrameworkPTAdapter 2.0.2
|
||||
### Before You Start
|
||||
|
||||
This framework is modified based on the open-source PyTorch 1.5.0 primarily developed by Facebook, inherits native PyTorch features, and uses NPUs for dynamic image training. Models are adapted by operator granularity, code can be reused, and current networks can be ported and used on NPUs with only device types or data types modified.
|
||||
### New Features
|
||||
|
||||
**Table 1** Features supported by PyTorch
|
||||
|
||||
<table><thead align="left"><tr id="r0c10e7163bf54fe8816ab5ca2d77ccc4"><th class="cellrowborder" valign="top" width="10.489999999999998%" id="mcps1.2.4.1.1"><p id="a7888762cf8294977b7d114b1c898d1bd"><a name="a7888762cf8294977b7d114b1c898d1bd"></a><a name="a7888762cf8294977b7d114b1c898d1bd"></a>Level-1 Feature</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="26.3%" id="mcps1.2.4.1.2"><p id="a4581ffde4a5f455faadfba144243a9d4"><a name="a4581ffde4a5f455faadfba144243a9d4"></a><a name="a4581ffde4a5f455faadfba144243a9d4"></a>Level-2 Feature</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="63.21%" id="mcps1.2.4.1.3"><p id="a2a1562364b09433a83133fa10b3cf2b3"><a name="a2a1562364b09433a83133fa10b3cf2b3"></a><a name="a2a1562364b09433a83133fa10b3cf2b3"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row171322953713"><td class="cellrowborder" rowspan="7" valign="top" width="10.489999999999998%" headers="mcps1.2.4.1.1 "><p id="p10237517181"><a name="p10237517181"></a><a name="p10237517181"></a>Adapted training models</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.3%" headers="mcps1.2.4.1.2 "><p id="p6134294377"><a name="p6134294377"></a><a name="p6134294377"></a>YOLOv4</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.21%" headers="mcps1.2.4.1.3 "><p id="p314533811397"><a name="p314533811397"></a><a name="p314533811397"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row15990182233714"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p399019224374"><a name="p399019224374"></a><a name="p399019224374"></a>YOLOv3</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1714553816396"><a name="p1714553816396"></a><a name="p1714553816396"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row5301255373"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1530325123719"><a name="p1530325123719"></a><a name="p1530325123719"></a>DB</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p5146193819390"><a name="p5146193819390"></a><a name="p5146193819390"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row274203413712"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p197423343379"><a name="p197423343379"></a><a name="p197423343379"></a>RFCN</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p15828941153919"><a name="p15828941153919"></a><a name="p15828941153919"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row78671918163714"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p188671318183713"><a name="p188671318183713"></a><a name="p188671318183713"></a>CRNN</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p10828241123917"><a name="p10828241123917"></a><a name="p10828241123917"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row16912221171"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p6913132676"><a name="p6913132676"></a><a name="p6913132676"></a>Densenset161</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p209131221474"><a name="p209131221474"></a><a name="p209131221474"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row1016073314719"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p3160153320717"><a name="p3160153320717"></a><a name="p3160153320717"></a>Densenset191</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1516012331173"><a name="p1516012331173"></a><a name="p1516012331173"></a>-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row9627165910386"><td class="cellrowborder" rowspan="4" valign="top" width="10.489999999999998%" headers="mcps1.2.4.1.1 "><p id="p1561535993811"><a name="p1561535993811"></a><a name="p1561535993811"></a>PyTorch features adapted to NPUs</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.3%" headers="mcps1.2.4.1.2 "><p id="p136151659163819"><a name="p136151659163819"></a><a name="p136151659163819"></a>Basic framework functions</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.21%" headers="mcps1.2.4.1.3 "><p id="p1661535983813"><a name="p1661535983813"></a><a name="p1661535983813"></a>Added the function of adapted operator development. For details, see the operator list.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row7627155917380"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1561525916383"><a name="p1561525916383"></a><a name="p1561525916383"></a>Model Accuracy Analyzer</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p19616115953816"><a name="p19616115953816"></a><a name="p19616115953816"></a>Added the Model Accuracy Analyzer and supported training accuracy demarcation.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row46269593383"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p0616559163819"><a name="p0616559163819"></a><a name="p0616559163819"></a>Ascend 710 AI Processor</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p186161459193813"><a name="p186161459193813"></a><a name="p186161459193813"></a>Supported the online inference on Ascend 710 AI Processors.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row76261059153817"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p11616175953812"><a name="p11616175953812"></a><a name="p11616175953812"></a>OS compatibility</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p8935115971714"><a name="p8935115971714"></a><a name="p8935115971714"></a>Supported Ubuntu 18.04.5 and openEuler 20.03 LTS.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### Modified Features
|
||||
|
||||
N/A
|
||||
### Resolved Issues
|
||||
|
||||
N/A
|
||||
### Known Issues
|
||||
|
||||
<table><thead align="left"><tr id="row3699162017307"><th class="cellrowborder" valign="top" width="18.22%" id="mcps1.1.3.1.1"><p id="p16992020153010"><a name="p16992020153010"></a><a name="p16992020153010"></a>Known Issue</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="81.78%" id="mcps1.1.3.1.2"><p id="p269919203308"><a name="p269919203308"></a><a name="p269919203308"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row9699142003011"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1769932017300"><a name="p1769932017300"></a><a name="p1769932017300"></a>Data type support</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p13699152010301"><a name="p13699152010301"></a><a name="p13699152010301"></a>NPUs do not support the input or output of the inf/nan data of the float16 type.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row146991520153016"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p156997200308"><a name="p156997200308"></a><a name="p156997200308"></a>Data format</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p10699182020308"><a name="p10699182020308"></a><a name="p10699182020308"></a>Dimensions cannot be reduced when the format larger than 4D is used.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row11121205610549"><td class="cellrowborder" rowspan="3" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1647216219558"><a name="p1647216219558"></a><a name="p1647216219558"></a>Restrictions on collective communication</p>
|
||||
<p id="p0465121912402"><a name="p0465121912402"></a><a name="p0465121912402"></a></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p3116115695415"><a name="p3116115695415"></a><a name="p3116115695415"></a>The graphs executed on different devices in a training job must be the same.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row51211656105411"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p1311616560541"><a name="p1311616560541"></a><a name="p1311616560541"></a>Allocation at only 1, 2, 4, or 8 processors is supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row8647195765419"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p2064225716544"><a name="p2064225716544"></a><a name="p2064225716544"></a>Only the int8, int32, float16, and float32 data types are supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row4646195719548"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p4642195718541"><a name="p4642195718541"></a><a name="p4642195718541"></a>Apex function</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p864205725412"><a name="p864205725412"></a><a name="p864205725412"></a>In the current version, Apex is implemented mainly using Python, and the customized optimization CUDA kernel in Apex is not supported.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### Compatibility
|
||||
|
||||
Atlas 800 (model 9010): CentOS 7.6/Ubuntu 18.04/BC-Linux 7.6/Debian 9.9/Debian 10/openEuler 20.03 LTS
|
||||
|
||||
Atlas 800 (model 9000): CentOS 7.6/EulerOS 2.8/Kylin v10/BC-Linux 7.6/openEuler 20.03 LTS
|
||||
|
||||
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 394 B After Width: | Height: | Size: 394 B |
|
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 406 B |
|
Before Width: | Height: | Size: 253 B After Width: | Height: | Size: 253 B |
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 394 B After Width: | Height: | Size: 394 B |
|
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 406 B |
|
Before Width: | Height: | Size: 253 B After Width: | Height: | Size: 253 B |
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 580 B |
@@ -0,0 +1,555 @@
|
||||
# PyTorch Installation Guide
|
||||
- [Overview](#overview.md)
|
||||
- [Manual Build and Installation](#manual-build-and-installation.md)
|
||||
- [Prerequisites](#prerequisites.md)
|
||||
- [Installing the PyTorch Framework](#installing-the-pytorch-framework.md)
|
||||
- [Configuring Environment Variables](#configuring-environment-variables.md)
|
||||
- [Installing the Mixed Precision Module](#installing-the-mixed-precision-module.md)
|
||||
- [References](#references.md)
|
||||
- [Installing CMake](#installing-cmake.md)
|
||||
- [How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0.md)
|
||||
- [What Do I Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?](#what-do-i-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installed.md)
|
||||
<h2 id="overview.md">Overview</h2>
|
||||
|
||||
When setting up the environment for PyTorch model development and running, you can manually build and install the modules adapted to the PyTorch framework on a server.
|
||||
|
||||
**Figure 1** Environment setup process<a name="en-us_topic_0000001119176876_fig1938918396117"></a>
|
||||
|
||||
|
||||

|
||||
|
||||
<h2 id="manual-build-and-installation.md">Manual Build and Installation</h2>
|
||||
|
||||
- **[Prerequisites](#prerequisites.md)**
|
||||
|
||||
- **[Installing the PyTorch Framework](#installing-the-pytorch-framework.md)**
|
||||
|
||||
- **[Configuring Environment Variables](#configuring-environment-variables.md)**
|
||||
|
||||
- **[Installing the Mixed Precision Module](#installing-the-mixed-precision-module.md)**
|
||||
|
||||
|
||||
<h2 id="prerequisites.md">Prerequisites</h2>
|
||||
|
||||
## Prerequisites<a name="en-us_topic_0000001105856382_en-us_topic_0275872734_section108914373254"></a>
|
||||
|
||||
- The development or operating environment of CANN has been installed. For details, see the _CANN Software Installation Guide_.
|
||||
- CMake 3.12.0 or later has been installed. For details about how to install CMake, see [Installing CMake](#installing-cmake.md).
|
||||
- GCC 7.3.0 or later has been installed. For details about how to install and use GCC 7.3.0, see [How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0.md).
|
||||
- Python 3.7.5 or 3.8 has been installed.
|
||||
- The Patch and Git tools have been installed in the environment. To install the tools for Ubuntu and CentOS, run the following commands:
|
||||
- Ubuntu
|
||||
|
||||
```
|
||||
apt-get install patch
|
||||
apt-get install git
|
||||
```
|
||||
|
||||
- CentOS
|
||||
|
||||
```
|
||||
yum install patch
|
||||
yum install git
|
||||
```
|
||||
|
||||
|
||||
|
||||
<h2 id="installing-the-pytorch-framework.md">Installing the PyTorch Framework</h2>
|
||||
|
||||
## Installation Process<a name="en-us_topic_0000001152776301_section1611810384557"></a>
|
||||
|
||||
1. Log in to the server as the **root** user or a non-root user.
|
||||
2. Run the following commands in sequence to install the PyTorch dependencies.
|
||||
|
||||
If you install Python and its dependencies as a non-root user, add **--user** at the end of each command in this step. Example command: **pip3.7 install pyyaml --user**.
|
||||
|
||||
```
|
||||
pip3 install pyyaml
|
||||
pip3 install wheel
|
||||
```
|
||||
|
||||
3. Obtain the PyTorch source code.
|
||||
|
||||
1. Run the following command to obtain the PyTorch source code adapted to Ascend AI Processors:
|
||||
|
||||
```
|
||||
git clone https://gitee.com/ascend/pytorch.git
|
||||
```
|
||||
|
||||
The directory structure of the downloaded source code is as follows:
|
||||
|
||||
```
|
||||
├── patch # Directory of the patch adapted to Ascend AI Processors
|
||||
│ ├── pytorch1.5.0_npu.patch # Patch for PyTorch 1.5.0
|
||||
│ └── pytorch1.8.1_npu.patch # Patch for PyTorch 1.8.1
|
||||
├── pytorch1.5.0 # Source code and test directory for PyTorch 1.5.0
|
||||
│ ├── access_control_test.py
|
||||
│ ├── src # Source code directory
|
||||
│ └── test # Directory for storing test cases
|
||||
├── pytorch1.8.1 # Source code and test directory for PyTorch 1.8.1
|
||||
│ ├── access_control_test.py
|
||||
│ ├── src # Source code directory
|
||||
│ └── test # Directory for storing test cases
|
||||
└── scripts # Build and create a directory.
|
||||
```
|
||||
|
||||
2. Obtain the native PyTorch source code from the root directory **/pytorch** of the current repository.
|
||||
- If PyTorch 1.5.0 is installed, run the following command:
|
||||
|
||||
```
|
||||
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
```
|
||||
|
||||
- If PyTorch 1.8.1 is installed, run the following command:
|
||||
|
||||
```
|
||||
git clone -b v1.8.1 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
```
|
||||
|
||||
3. Run the following commands to go to the native PyTorch code directory **pytorch** and obtain the PyTorch passive dependency code:
|
||||
|
||||
```
|
||||
cd pytorch
|
||||
git submodule sync
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
> **NOTE:**
|
||||
>Due to network fluctuation, it may take a long time to obtain the source code. If no error is reported after the download is complete, the PyTorch and third-party code on which PyTorch depends are generated.
|
||||
|
||||
4. Generate the PyTorch installation package adapted to Ascend AI Processors.
|
||||
1. Go to the **pytorch/scripts** directory and run the conversion script to generate full code adapted to Ascend AI Processors.
|
||||
|
||||
```
|
||||
cd ../scripts
|
||||
# If PyTorch 1.5.0 is installed:
|
||||
bash gen.sh
|
||||
# If PyTorch 1.8.1 is installed:
|
||||
bash gen.sh -v 1.8.1
|
||||
```
|
||||
|
||||
The full code adapted to Ascend AI Processors is generated in the **pytorch/pytorch** directory.
|
||||
|
||||
2. Go to the **pytorch/pytorch/** directory and install the dependency library.
|
||||
|
||||
```
|
||||
cd ../pytorch
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
3. Build and generate the binary installation package of PyTorch.
|
||||
|
||||
```
|
||||
bash build.sh --python=3.7
|
||||
or
|
||||
bash build.sh --python=3.8
|
||||
```
|
||||
|
||||
Specify the Python version in the environment for build. The generated binary package is stored in the current dist directory **pytorch/pytorch/dist**.
|
||||
|
||||
5. <a name="en-us_topic_0000001152776301_li49671667141"></a>Install PyTorch.
|
||||
|
||||
Go to the **pytorch/pytorch/dist** directory and run the following command to install PyTorch:
|
||||
|
||||
```
|
||||
pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
|
||||
```
|
||||
|
||||
_\{**arch\}**_ indicates the architecture information. The value can be **aarch64** or **x86\_64**.
|
||||
|
||||
> **NOTE:**
|
||||
>To upgrade PyTorch in the environment, uninstall the PyTorch software package installed in the environment and then perform [Step 5 Install PyTorch](#en-us_topic_0000001152776301_li49671667141). Run the following command to check whether PyTorch has been installed:
|
||||
>**pip3 list | grep torch**
|
||||
|
||||
|
||||
<h2 id="configuring-environment-variables.md">Configuring Environment Variables</h2>
|
||||
|
||||
After the software packages are installed, configure environment variables to use Ascend PyTorch. For details about the environment variables, see [Table 1](#en-us_topic_0000001152616261_table42017516135).
|
||||
|
||||
1. Configure the operating environment variables by running the following command in the **root** directory of the PyTorch source code adapted to Ascend AI Processors:
|
||||
|
||||
```
|
||||
source pytorch/env.sh
|
||||
```
|
||||
|
||||
2. Select a proper HCCL initialization mode based on the actual scenario and configure the corresponding environment variables.
|
||||
|
||||
```
|
||||
# Scenario 1: Single-node scenario
|
||||
export HCCL_WHITELIST_DISABLE=1 # Disable the HCCL trustlist.
|
||||
# Scenario 2: Multi-node scenario
|
||||
export HCCL_WHITELIST_DISABLE=1 # Disable the HCCL trustlist.
|
||||
export HCCL_IF_IP="1.1.1.1" # 1.1.1.1 is the NIC IP address of the host. Change it based on the site requirements. Ensure that the NIC IP addresses in use can communicate with each other in the cluster.
|
||||
```
|
||||
|
||||
3. \(Optional\) Configure function or performance environment variables in the NPU scenario. The variables are disabled by default.
|
||||
|
||||
```
|
||||
export DYNAMIC_COMPILE_ENABLE=1 # (Optional) Dynamic shape feature, which is used when the shape changes. To enable this function, set the value to 1. (PyTorch 1.8.1 does not support this environment variable.)
|
||||
export COMBINED_ENABLE=1 # (Optional) Optimizes the scenario where two inconsecutive operators are combined. To enable this function, set the value to 1.
|
||||
export TRI_COMBINED_ENABLE=1 # (Optional) Optimizes the scenario where three inconsecutive operators are combined. To enable this function, set the value to 1.
|
||||
export ACL_DUMP_DATA=1 # (Optional) Operator data dump function, which is used for debugging. To enable this function, set the value to 1.
|
||||
export DYNAMIC_OP="ADD#MUL" # (Optional) Operator implementation. The performance of the ADD and MUL operators varies depending on the scenarios.
|
||||
```
|
||||
|
||||
4. \(Optional\) If the system is openEuler or its inherited OS, such as UOS, run the following command to cancel CPU core binding.
|
||||
|
||||
```
|
||||
# unset GOMP_CPU_AFFINITY
|
||||
```
|
||||
|
||||
|
||||
**Table 1** Description of environment variables
|
||||
|
||||
<a name="en-us_topic_0000001152616261_table42017516135"></a>
|
||||
<table><thead align="left"><tr id="en-us_topic_0000001152616261_row16198951191317"><th class="cellrowborder" valign="top" width="55.48%" id="mcps1.2.3.1.1"><p id="en-us_topic_0000001152616261_p51981251161315"><a name="en-us_topic_0000001152616261_p51981251161315"></a><a name="en-us_topic_0000001152616261_p51981251161315"></a>Environment Variable</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="44.519999999999996%" id="mcps1.2.3.1.2"><p id="en-us_topic_0000001152616261_p9198135114133"><a name="en-us_topic_0000001152616261_p9198135114133"></a><a name="en-us_topic_0000001152616261_p9198135114133"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="en-us_topic_0000001152616261_row6882121917329"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p688241953218"><a name="en-us_topic_0000001152616261_p688241953218"></a><a name="en-us_topic_0000001152616261_p688241953218"></a>LD_LIBRARY_PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p1888291915322"><a name="en-us_topic_0000001152616261_p1888291915322"></a><a name="en-us_topic_0000001152616261_p1888291915322"></a>Dynamic library search path. Set this variable based on the preceding example.</p>
|
||||
<p id="p1292181892120"><a name="p1292181892120"></a><a name="p1292181892120"></a>If you need to upgrade GCC in OSs such as CentOS, Debian, and BC-Linux, add <strong id="b6163826603"><a name="b6163826603"></a><a name="b6163826603"></a><em id="i161631926505"><a name="i161631926505"></a><a name="i161631926505"></a>${install_path}</em>/lib64</strong> to the <span class="parmname" id="parmname161637265015"><a name="parmname161637265015"></a><a name="parmname161637265015"></a><b>LD_LIBRARY_PATH</b></span> variable of the dynamic library search path. Replace <em id="i01649261704"><a name="i01649261704"></a><a name="i01649261704"></a><strong id="b1216317261109"><a name="b1216317261109"></a><a name="b1216317261109"></a>{install_path}</strong></em> with the GCC installation path. For details, see <a href="#how-do-i-install-gcc-7-3-0.md#en-us_topic_0000001135347812_en-us_topic_0000001173199577_en-us_topic_0000001172534867_en-us_topic_0276688294_li9745165315131">5</a>.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row16194175523010"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p16195185523019"><a name="en-us_topic_0000001152616261_p16195185523019"></a><a name="en-us_topic_0000001152616261_p16195185523019"></a>PYTHONPATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p19637083322"><a name="en-us_topic_0000001152616261_p19637083322"></a><a name="en-us_topic_0000001152616261_p19637083322"></a>Python search path. Set this variable based on the preceding example.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row2954102119329"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p195452113218"><a name="en-us_topic_0000001152616261_p195452113218"></a><a name="en-us_topic_0000001152616261_p195452113218"></a>PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p964914893211"><a name="en-us_topic_0000001152616261_p964914893211"></a><a name="en-us_topic_0000001152616261_p964914893211"></a>Executable program search path. Set this variable based on the preceding example.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row58592816294"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p1886016892913"><a name="en-us_topic_0000001152616261_p1886016892913"></a><a name="en-us_topic_0000001152616261_p1886016892913"></a>ASCEND_OPP_PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p28608892915"><a name="en-us_topic_0000001152616261_p28608892915"></a><a name="en-us_topic_0000001152616261_p28608892915"></a>Operator package (OPP) root directory. Set this variable based on the preceding example.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row144592037903"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p104601373014"><a name="en-us_topic_0000001152616261_p104601373014"></a><a name="en-us_topic_0000001152616261_p104601373014"></a>OPTION_EXEC_EXTERN_PLUGIN_PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p1046013716017"><a name="en-us_topic_0000001152616261_p1046013716017"></a><a name="en-us_topic_0000001152616261_p1046013716017"></a>Path of the operator information library.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row16184379493"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p131851873492"><a name="en-us_topic_0000001152616261_p131851873492"></a><a name="en-us_topic_0000001152616261_p131851873492"></a>ASCEND_AICPU_PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p181851575497"><a name="en-us_topic_0000001152616261_p181851575497"></a><a name="en-us_topic_0000001152616261_p181851575497"></a>Path of the AI CPU operator package.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row234714854615"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p2034724894619"><a name="en-us_topic_0000001152616261_p2034724894619"></a><a name="en-us_topic_0000001152616261_p2034724894619"></a>TASK_QUEUE_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p53477489462"><a name="en-us_topic_0000001152616261_p53477489462"></a><a name="en-us_topic_0000001152616261_p53477489462"></a>Whether to asynchronously deliver tasks and call the ACL APIs. You are advised to set this parameter to <strong id="en-us_topic_0000001152616261_b186701714141819"><a name="en-us_topic_0000001152616261_b186701714141819"></a><a name="en-us_topic_0000001152616261_b186701714141819"></a>1</strong> to enable this function.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row1680820246202"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p4809112415207"><a name="en-us_topic_0000001152616261_p4809112415207"></a><a name="en-us_topic_0000001152616261_p4809112415207"></a>HCCL_WHITELIST_DISABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p952814428206"><a name="en-us_topic_0000001152616261_p952814428206"></a><a name="en-us_topic_0000001152616261_p952814428206"></a>Whether to enable the communication trustlist when the HCCL is used.</p>
|
||||
<a name="ul928845132310"></a><a name="ul928845132310"></a><ul id="ul928845132310"><li><strong id="b12793231525"><a name="b12793231525"></a><a name="b12793231525"></a>0</strong>: enable the trustlist. The HCCL communication trustlist does not need to be verified.</li><li><strong id="b1146142619212"><a name="b1146142619212"></a><a name="b1146142619212"></a>1</strong>: disable the trustlist. The HCCL communication trustlist needs to be verified.</li></ul>
|
||||
<p id="en-us_topic_0000001152616261_p5809162416201"><a name="en-us_topic_0000001152616261_p5809162416201"></a><a name="en-us_topic_0000001152616261_p5809162416201"></a>The default value is <strong id="en-us_topic_0000001152616261_b1270332516435"><a name="en-us_topic_0000001152616261_b1270332516435"></a><a name="en-us_topic_0000001152616261_b1270332516435"></a>0</strong>, indicating that the trustlist is enabled by default.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row0671137162115"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p4671203792114"><a name="en-us_topic_0000001152616261_p4671203792114"></a><a name="en-us_topic_0000001152616261_p4671203792114"></a>HCCL_IF_IP</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p1822165982114"><a name="en-us_topic_0000001152616261_p1822165982114"></a><a name="en-us_topic_0000001152616261_p1822165982114"></a>IP address of the NIC for initializing communication in the HCCL.</p>
|
||||
<a name="ul2676102292415"></a><a name="ul2676102292415"></a><ul id="ul2676102292415"><li>The IP address is in dotted decimal notation.</li><li>Currently, only the host NIC is supported.</li></ul>
|
||||
<p id="en-us_topic_0000001152616261_p1167163719217"><a name="en-us_topic_0000001152616261_p1167163719217"></a><a name="en-us_topic_0000001152616261_p1167163719217"></a>By default, the host communication NICs are selected in the following sequence: NICs other than Docker/local NICs (in ascending alphabetical order of NIC names) > Docker NICs > local NICs.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row1371356152313"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p15106173103120"><a name="p15106173103120"></a><a name="p15106173103120"></a>PTCOPY_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p71055317311"><a name="p71055317311"></a><a name="p71055317311"></a>Use the PTCopy operator mode to accelerate the operation of converting non-contiguous tensors to contiguous tensors and copy process. You are advised to set the value to <strong id="b114621515513"><a name="b114621515513"></a><a name="b114621515513"></a>1</strong> to enable this function. </p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row743212132309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p17433111312307"><a name="p17433111312307"></a><a name="p17433111312307"></a>ASCEND_SLOG_PRINT_TO_STDOUT</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p6433151393018"><a name="p6433151393018"></a><a name="p6433151393018"></a>(Optional) Whether to enable the log printing function.</p>
|
||||
<a name="ul760201917473"></a><a name="ul760201917473"></a><ul id="ul760201917473"><li><strong id="b1955232216215"><a name="b1955232216215"></a><a name="b1955232216215"></a>0</strong>: uses the default log output mode.</li><li><strong id="b22913272211"><a name="b22913272211"></a><a name="b22913272211"></a>1</strong>: prints the logs to the screen.</li><li>Other values: invalid</li></ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row19237171814300"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p14238161893019"><a name="p14238161893019"></a><a name="p14238161893019"></a>ASCEND_GLOBAL_LOG_LEVEL</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p223841810303"><a name="p223841810303"></a><a name="p223841810303"></a>Sets the global log level of app logs.</p>
|
||||
<a name="ul175714586453"></a><a name="ul175714586453"></a><ul id="ul175714586453"><li><strong id="b94698561835"><a name="b94698561835"></a><a name="b94698561835"></a>0</strong>: DEBUG</li><li><strong id="b1612516597314"><a name="b1612516597314"></a><a name="b1612516597314"></a>1</strong>: INFO</li><li><strong id="b82051911547"><a name="b82051911547"></a><a name="b82051911547"></a>2</strong>: WARNING</li><li><strong id="b04351021945"><a name="b04351021945"></a><a name="b04351021945"></a>3</strong>: ERROR</li><li><strong id="b116153316418"><a name="b116153316418"></a><a name="b116153316418"></a>4</strong>: NULL (no log output)</li><li>Other values: invalid</li></ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row1348192313303"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1734815235305"><a name="p1734815235305"></a><a name="p1734815235305"></a>ASCEND_GLOBAL_EVENT_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p12348202373018"><a name="p12348202373018"></a><a name="p12348202373018"></a>Whether to enable event logging for apps.</p>
|
||||
<a name="ul416352114610"></a><a name="ul416352114610"></a><ul id="ul416352114610"><li><strong id="b425610311940"><a name="b425610311940"></a><a name="b425610311940"></a>0</strong>: disabled</li><li><strong id="b198984321741"><a name="b198984321741"></a><a name="b198984321741"></a>1</strong>: enabled</li><li>Other values: invalid</li></ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row17878184693015"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1878194683016"><a name="p1878194683016"></a><a name="p1878194683016"></a>DYNAMIC_COMPILE_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p1887894620304"><a name="p1887894620304"></a><a name="p1887894620304"></a>(Optional) Dynamic shape feature, which is used when the shape changes. To enable this function, set the value to <strong id="b11281447194117"><a name="b11281447194117"></a><a name="b11281447194117"></a>1</strong>. (PyTorch 1.8.1 does not support this environment variable.)</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row78312162301"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1832171673019"><a name="p1832171673019"></a><a name="p1832171673019"></a>COMBINED_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p583261643014"><a name="p583261643014"></a><a name="p583261643014"></a>(Optional) Optimizes the scenario where two inconsecutive operators are combined. To enable this function, set the value to <strong id="b19824817612"><a name="b19824817612"></a><a name="b19824817612"></a>1</strong>.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row17630155212342"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p66309527341"><a name="p66309527341"></a><a name="p66309527341"></a>RI_COMBINED_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p19630185220345"><a name="p19630185220345"></a><a name="p19630185220345"></a>(Optional) Optimizes the scenario where three inconsecutive operators are combined. To enable this function, set the value to <strong id="b10522121418612"><a name="b10522121418612"></a><a name="b10522121418612"></a>1</strong>.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row183041355123411"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p730435533415"><a name="p730435533415"></a><a name="p730435533415"></a>ACL_DUMP_DATA</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p16304105533412"><a name="p16304105533412"></a><a name="p16304105533412"></a>(Optional) Operator data dump function, which is used for debugging. To enable this function, set the value to <strong id="b1861154419918"><a name="b1861154419918"></a><a name="b1861154419918"></a>1</strong>.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row27481914203518"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p674813144357"><a name="p674813144357"></a><a name="p674813144357"></a>DYNAMIC_OP</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p974891414353"><a name="p974891414353"></a><a name="p974891414353"></a>(Optional) Operator implementation. The performance of the ADD and MUL operators varies depending on the scenarios. This parameter is not set by default.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row19173161510309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p16711563237"><a name="en-us_topic_0000001152616261_p16711563237"></a><a name="en-us_topic_0000001152616261_p16711563237"></a>unset GOMP_CPU_AFFINITY</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p0711356152317"><a name="en-us_topic_0000001152616261_p0711356152317"></a><a name="en-us_topic_0000001152616261_p0711356152317"></a>(Optional) If the system is openEuler or its inherited OS, such as UOS, run this command to cancel CPU core binding.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2 id="installing-the-mixed-precision-module.md">Installing the Mixed Precision Module</h2>
|
||||
|
||||
## Prerequisites<a name="en-us_topic_0000001106176190_section3225481020"></a>
|
||||
|
||||
1. Ensure that the PyTorch framework adapted to Ascend AI Processors in the operating environment can be used properly.
|
||||
2. Before building and installing Apex, you have configured the environment variables on which the build depends. See [Configuring Environment Variables](#configuring-environment-variables.md).
|
||||
|
||||
## Installation Process<a name="en-us_topic_0000001106176190_section11880164819567"></a>
|
||||
|
||||
1. Log in to the server as the **root** user or a non-root user.
|
||||
2. Obtain the Apex source code.
|
||||
|
||||
1. Run the following command to obtain the Apex source code adapted to Ascend AI Processors:
|
||||
|
||||
```
|
||||
git clone https://gitee.com/ascend/apex.git
|
||||
```
|
||||
|
||||
The directory structure of the downloaded source code is as follows:
|
||||
|
||||
```
|
||||
apex
|
||||
│ ├─patch # Directory of the patch adapted to Ascend AI Processors
|
||||
│ ├─npu.patch
|
||||
│ ├─scripts # Build and create a directory.
|
||||
│ ├─gen.sh
|
||||
│ ├─src # Source code directory
|
||||
│ ├─tests # Directory for storing test cases
|
||||
```
|
||||
|
||||
2. Run the following commands to go to the **apex** directory and obtain the native Apex source code:
|
||||
|
||||
```
|
||||
cd apex
|
||||
git clone https://github.com/NVIDIA/apex.git
|
||||
```
|
||||
|
||||
After the native Apex source code is downloaded, the main directory structure of the code is as follows:
|
||||
|
||||
```
|
||||
apex
|
||||
│ ├─apex # Directory for storing the native Apex code
|
||||
│ ├─patch # Directory of the patch adapted to Ascend AI Processors
|
||||
│ ├─npu.patch
|
||||
│ ├─scripts # Build and create a directory.
|
||||
│ ├─gen.sh
|
||||
│ ├─src # Source code directory
|
||||
│ ├─tests # Directory for storing test cases
|
||||
```
|
||||
|
||||
3. Go to the native Apex code directory, that is, **apex/apex**. Switch to the code branch whose commit ID is 4ef930c1c884fdca5f472ab2ce7cb9b505d26c1a.
|
||||
|
||||
```
|
||||
cd apex
|
||||
git checkout 4ef930c1c884fdca5f472ab2ce7cb9b505d26c1a
|
||||
```
|
||||
|
||||
> **NOTE:**
|
||||
>Due to network fluctuation, it may take a long time to obtain the source code.
|
||||
|
||||
3. Generate the Apex installation package adapted to Ascend AI Processors.
|
||||
1. Go to the **apex/scripts** directory and run the conversion script to generate full code adapted to Ascend AI Processors.
|
||||
|
||||
```
|
||||
cd ../scripts
|
||||
bash gen.sh
|
||||
```
|
||||
|
||||
The full code adapted to Ascend AI Processors is generated in the **apex/apex** directory.
|
||||
|
||||
2. Go to the full code directory **apex/apex**, and compile and generate the binary installation package of Apex.
|
||||
|
||||
```
|
||||
cd ../apex
|
||||
python3 setup.py --cpp_ext --npu_float_status bdist_wheel
|
||||
```
|
||||
|
||||
The Python version must be the same as that used by PyTorch. The generated binary package is stored in the current **dist** directory, that is, **apex/apex/dist**.
|
||||
|
||||
4. <a name="en-us_topic_0000001106176190_li425495374416"></a>Install Apex.
|
||||
|
||||
Go to the **apex/apex/dist** directory and run the following command to install Apex:
|
||||
|
||||
```
|
||||
pip3 install --upgrade apex-0.1+ascend-cp37-cp37m-linux_{arch}.whl
|
||||
```
|
||||
|
||||
_\{**arch\}**_ indicates the architecture information. The value can be **aarch64** or **x86\_64**.
|
||||
|
||||
> **NOTE:**
|
||||
>To upgrade PyTorch in the environment, uninstall the PyTorch software package installed in the environment and then perform [Step 4 Install Apex](#en-us_topic_0000001106176190_li425495374416). Run the following command to check whether PyTorch has been installed:
|
||||
>**pip3 list | grep apex**
|
||||
|
||||
|
||||
<h2 id="references.md">References</h2>
|
||||
|
||||
- **[Installing CMake](#installing-cmake.md)**
|
||||
|
||||
- **[How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0.md)**
|
||||
|
||||
- **[What Do I Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?](#what-do-i-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installed.md)**
|
||||
|
||||
|
||||
<h2 id="installing-cmake.md">Installing CMake</h2>
|
||||
|
||||
Procedure for upgrading CMake to 3.12.1
|
||||
|
||||
1. Obtain the CMake software package.
|
||||
|
||||
```
|
||||
wget https://cmake.org/files/v3.12/cmake-3.12.1.tar.gz --no-check-certificate
|
||||
```
|
||||
|
||||
2. Decompress the package and go to the software package directory.
|
||||
|
||||
```
|
||||
tar -xf cmake-3.12.1.tar.gz
|
||||
cd cmake-3.12.1/
|
||||
```
|
||||
|
||||
3. Run the configuration, build, and installation commands.
|
||||
|
||||
```
|
||||
./configure --prefix=/usr/local/cmake
|
||||
make && make install
|
||||
```
|
||||
|
||||
4. Set the soft link.
|
||||
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
|
||||
5. Run the following command to check whether CMake has been installed:
|
||||
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
If the message "cmake version 3.12.1" is displayed, the installation is successful.
|
||||
|
||||
|
||||
<h2 id="how-do-i-install-gcc-7-3-0.md">How Do I Install GCC 7.3.0?</h2>
|
||||
|
||||
Perform the following steps as the **root** user.
|
||||
|
||||
1. Download **gcc-7.3.0.tar.gz** from [https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz](https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz).
|
||||
2. GCC installation requires adequate temporary space. Run the following command to clear the **/tmp** directory in advance:
|
||||
|
||||
```
|
||||
sudo rm -rf /tmp/*
|
||||
```
|
||||
|
||||
3. Install the dependency package. \(CentOS and Ubuntu are used as examples.\)
|
||||
- For CentOS, run the following command:
|
||||
|
||||
```
|
||||
yum install bzip2
|
||||
```
|
||||
|
||||
- For Ubuntu, run the following command:
|
||||
|
||||
```
|
||||
apt-get install bzip2
|
||||
```
|
||||
|
||||
4. Build and install GCC.
|
||||
1. Go to the directory where the source package **gcc-7.3.0.tar.gz** is located and run the following command to decompress it:
|
||||
|
||||
```
|
||||
tar -zxvf gcc-7.3.0.tar.gz
|
||||
```
|
||||
|
||||
2. Go to the extracted directory and run the following command to download the GCC dependency packages:
|
||||
|
||||
```
|
||||
cd gcc-7.3.0
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
If an error is reported during the command execution, run the following commands in the **gcc-7.3.0/** directory to download the dependency packages:
|
||||
|
||||
```
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
|
||||
```
|
||||
|
||||
After the preceding dependencies are downloaded, run the following command again:
|
||||
|
||||
```
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
If the validation fails, check whether the dependency packages are repeatedly downloaded. The packages should be downloaded at a time.
|
||||
|
||||
3. <a name="en-us_topic_0000001135347812_en-us_topic_0000001173199577_en-us_topic_0000001172534867_en-us_topic_0276688294_li1649343041310"></a>Run the configuration, build, and installation commands.
|
||||
|
||||
```
|
||||
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.3.0
|
||||
make -j15 # Check the number of CPUs by running grep -w processor /proc/cpuinfo|wc -l. In this example, the number is 15.
|
||||
make install
|
||||
```
|
||||
|
||||
> **NOTICE:**
|
||||
>The **--prefix** option is used to specify the linux\_gcc7.3.0 installation path, which is configurable. Do not set it to **/usr/local** or **/usr**, which is the default installation path for the GCC installed by using the software source. Otherwise, a conflict occurs and the original GCC compilation environment of the system is damaged. In this example, the installation path is set to **/usr/local/linux\_gcc7.3.0**.
|
||||
|
||||
|
||||
5. Set the environment variable.
|
||||
|
||||
Training must be performed in the compilation environment with GCC upgraded. If you want to run training, configure the following environment variable in your training script:
|
||||
|
||||
```
|
||||
export LD_LIBRARY_PATH=${install_path}/lib64:${LD_LIBRARY_PATH}
|
||||
```
|
||||
|
||||
**$\{install\_path\}** indicates the GCC 7.3.0 installation path configured in [3](#en-us_topic_0000001135347812_en-us_topic_0000001173199577_en-us_topic_0000001172534867_en-us_topic_0276688294_li1649343041310). In this example, the GCC 7.3.0 installation path is **/usr/local/gcc7.3.0/**.
|
||||
|
||||
> **NOTE:**
|
||||
>Skip this step if you do not need to use the compilation environment with GCC upgraded.
|
||||
|
||||
|
||||
<h2 id="what-do-i-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installed.md">What Do I Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?</h2>
|
||||
|
||||
## Symptom<a name="en-us_topic_0000001105856364_en-us_topic_0175549220_section197270431505"></a>
|
||||
|
||||
During the installation of **torch-**_\*_**.whl**, the message "ERROR: torchvision 0.6.0 has requirement torch==1.5.0, but you'll have torch 1.5.0a0+1977093 which is incompatible" " is displayed.
|
||||
|
||||

|
||||
|
||||
## Possible Causes<a name="en-us_topic_0000001105856364_en-us_topic_0175549220_section169499490501"></a>
|
||||
|
||||
When the PyTorch is installed, the version check is automatically triggered. The version of the torchvision installed in the environment is 0.6.0. During the check, it is found that the version of the **torch-**_\*_**.whl** is inconsistent with the required version 1.5.0. As a result, an error message is displayed, but the installation is successful.
|
||||
|
||||
## Solution<a name="en-us_topic_0000001105856364_section108142031907"></a>
|
||||
|
||||
This problem has no impact on the actual result, and no action is required.
|
||||
|
||||
|
After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 394 B After Width: | Height: | Size: 394 B |
|
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 406 B |
|
Before Width: | Height: | Size: 253 B After Width: | Height: | Size: 253 B |
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 580 B |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 356 B |
|
After Width: | Height: | Size: 946 B |
|
After Width: | Height: | Size: 946 B |
|
After Width: | Height: | Size: 356 B |
|
After Width: | Height: | Size: 329 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 607 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 7.8 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 7.2 KiB |
|
After Width: | Height: | Size: 7.2 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 580 B |
|
After Width: | Height: | Size: 580 B |
|
After Width: | Height: | Size: 394 B |
|
After Width: | Height: | Size: 406 B |
|
After Width: | Height: | Size: 253 B |
|
After Width: | Height: | Size: 580 B |
@@ -0,0 +1,599 @@
|
||||
# PyTorch Online Inference Guide
|
||||
- [Application Scenario](#application-scenario.md)
|
||||
- [Basic Workflow](#basic-workflow.md)
|
||||
- [Prerequisites](#prerequisites.md)
|
||||
- [Online Inference Process](#online-inference-process.md)
|
||||
- [Environment Variable Configuration](#environment-variable-configuration.md)
|
||||
- [Sample Reference](#sample-reference.md)
|
||||
- [Special Topics](#special-topics.md)
|
||||
- [Mixed Precision](#mixed-precision.md)
|
||||
- [How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0.md)
|
||||
<h2 id="application-scenario.md">Application Scenario</h2>
|
||||
|
||||
Online inference, unlike offline inference, allows developers to perform inference directly with PyTorch models using the **model.eval\(\)** method.
|
||||
|
||||
In this way, PyTorch-based inference apps can be directly ported to the Ascend AI Processor, which is especially useful in the data center inference scenarios.
|
||||
|
||||
## Supported Processors<a name="section15598658104219"></a>
|
||||
|
||||
Ascend 910 AI Processor
|
||||
|
||||
Ascend 710 AI Processor
|
||||
|
||||
<h2 id="basic-workflow.md">Basic Workflow</h2>
|
||||
|
||||
- **[Prerequisites](#prerequisites.md)**
|
||||
|
||||
- **[Online Inference Process](#online-inference-process.md)**
|
||||
|
||||
- **[Environment Variable Configuration](#environment-variable-configuration.md)**
|
||||
|
||||
- **[Sample Reference](#sample-reference.md)**
|
||||
|
||||
|
||||
<h2 id="prerequisites.md">Prerequisites</h2>
|
||||
|
||||
The PyTorch framework and mixed precision module have been installed. For details, see the _PyTorch Installation Guide_.
|
||||
|
||||
<h2 id="online-inference-process.md">Online Inference Process</h2>
|
||||
|
||||
[Figure 1](#fig13802941161818) shows the online inference process.
|
||||
|
||||
**Figure 1** Online inference process<a name="fig13802941161818"></a>
|
||||

|
||||
|
||||
<h2 id="environment-variable-configuration.md">Environment Variable Configuration</h2>
|
||||
|
||||
The following are the environment variables required for starting the inference process on PyTorch:
|
||||
|
||||
```
|
||||
# Set the environment variable for the installation path of the infrastructure software on which online inference depends. The following assumes that the installation user is HwHiAiUser, and the default installation path is used.
|
||||
# Method 1: Install Ascend-CANN-Toolkit for inference on an Ascend AI device, which serves as the development environment.
|
||||
. /home/HwHiAiUser/Ascend/ascend-toolkit/set_env.sh
|
||||
# Method 2: Install Ascend-CANN-NNAE on an Ascend AI device.
|
||||
. /home/HwHiAiUser/Ascend/nnae/set_env.sh
|
||||
|
||||
# If multiple Python 3 versions exist in the operating environment, configure the installation path of Python 3.7.5 in environment variables.
|
||||
export PATH=/usr/local/python3.7.5/bin:$PATH
|
||||
export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH
|
||||
|
||||
# Sets the logical ID of a processor.
|
||||
export ASCEND_DEVICE_ID=0
|
||||
|
||||
# Outputs log information. Replace it as required.
|
||||
export ASCEND_SLOG_PRINT_TO_STDOUT=1
|
||||
export ASCEND_GLOBAL_LOG_LEVEL=0
|
||||
|
||||
# Task issued with multiple threads
|
||||
export TASK_QUEUE_ENABLE=0
|
||||
```
|
||||
|
||||
**Table 1** Description of environment variables
|
||||
|
||||
<a name="table2072027194819"></a>
|
||||
<table><thead align="left"><tr id="row1173527114812"><th class="cellrowborder" valign="top" width="46.75467546754676%" id="mcps1.2.4.1.1"><p id="p073027114816"><a name="p073027114816"></a><a name="p073027114816"></a>Environment Variable</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="43.18431843184319%" id="mcps1.2.4.1.2"><p id="p157362712480"><a name="p157362712480"></a><a name="p157362712480"></a>Description</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="10.061006100610062%" id="mcps1.2.4.1.3"><p id="p187392714485"><a name="p187392714485"></a><a name="p187392714485"></a>Required/Optional</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row2732273481"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p57382719481"><a name="p57382719481"></a><a name="p57382719481"></a>LD_LIBRARY_PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="p07319271480"><a name="p07319271480"></a><a name="p07319271480"></a>Dynamic library search path. Set this variable based on the preceding example.</p>
|
||||
<div class="note" id="note119943144912"><a name="note119943144912"></a><a name="note119943144912"></a><span class="notetitle"> NOTE: </span><div class="notebody"><p id="p49933104915"><a name="p49933104915"></a><a name="p49933104915"></a>If GCC 7.3.0 is installed in OSs such as CentOS 7.6, Debian, and BC-Linux, configure the related environment variables. For details, see <a href="#how-do-i-install-gcc-7-3-0.md#en-us_topic_0000001146754749_en-us_topic_0000001072593337_l5e5c9395407d46439788b12f0e6342bc">5</a>.</p>
|
||||
</div></div>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p187352744817"><a name="p187352744817"></a><a name="p187352744817"></a>Required</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row17342744812"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p4731227184818"><a name="p4731227184818"></a><a name="p4731227184818"></a>PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="p97310276484"><a name="p97310276484"></a><a name="p97310276484"></a>Executable program search path. Set this variable based on the preceding example.</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p1573142711483"><a name="p1573142711483"></a><a name="p1573142711483"></a>Required</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row95241840165613"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p15242404566"><a name="p15242404566"></a><a name="p15242404566"></a>ASCEND_DEVICE_ID</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="p688447526"><a name="p688447526"></a><a name="p688447526"></a>Sets the logical ID of a processor.</p>
|
||||
<p id="p178824712212"><a name="p178824712212"></a><a name="p178824712212"></a>The value range is [0, <em id="i18812110304"><a name="i18812110304"></a><a name="i18812110304"></a>N</em> – 1] and the default value is<strong id="b1381717104019"><a name="b1381717104019"></a><a name="b1381717104019"></a> 0</strong>. <em id="i1156411211703"><a name="i1156411211703"></a><a name="i1156411211703"></a>N</em> indicates the device count in the physical machine, VM, or container.</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p105245400562"><a name="p105245400562"></a><a name="p105245400562"></a>Optional</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row203705529819"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p53705522810"><a name="p53705522810"></a><a name="p53705522810"></a>ASCEND_SLOG_PRINT_TO_STDOUT</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="en-us_topic_0000001073203258_p763102116322"><a name="en-us_topic_0000001073203258_p763102116322"></a><a name="en-us_topic_0000001073203258_p763102116322"></a>Enables or disables log printing. Values:</p>
|
||||
<a name="en-us_topic_0000001073203258_ul95291245104113"></a><a name="en-us_topic_0000001073203258_ul95291245104113"></a><ul id="en-us_topic_0000001073203258_ul95291245104113"><li><strong id="b1877191971104041"><a name="b1877191971104041"></a><a name="b1877191971104041"></a>0</strong> or not configured: disabled</li><li><strong id="b737654378104041"><a name="b737654378104041"></a><a name="b737654378104041"></a>1</strong>: enabled</li></ul>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p6370125217818"><a name="p6370125217818"></a><a name="p6370125217818"></a>Optional</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row188405280914"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p5840928594"><a name="p5840928594"></a><a name="p5840928594"></a>ASCEND_GLOBAL_LOG_LEVEL</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="en-us_topic_0000001073521184_p763102116322"><a name="en-us_topic_0000001073521184_p763102116322"></a><a name="en-us_topic_0000001073521184_p763102116322"></a>Sets the global log level. Values:</p>
|
||||
<a name="en-us_topic_0000001073521184_u4d735da6e0494e55abbf5eb6aefe988d"></a><a name="en-us_topic_0000001073521184_u4d735da6e0494e55abbf5eb6aefe988d"></a><ul id="en-us_topic_0000001073521184_u4d735da6e0494e55abbf5eb6aefe988d"><li><strong id="b1731786453104041"><a name="b1731786453104041"></a><a name="b1731786453104041"></a>0</strong>: DEBUG</li><li><strong id="b758139838104041"><a name="b758139838104041"></a><a name="b758139838104041"></a>1</strong>: INFO</li><li><strong id="b539270545104041"><a name="b539270545104041"></a><a name="b539270545104041"></a>2</strong>: WARNING</li><li><strong id="b444623067104041"><a name="b444623067104041"></a><a name="b444623067104041"></a>3</strong>: ERROR</li><li><strong id="b1157662181104041"><a name="b1157662181104041"></a><a name="b1157662181104041"></a>4</strong>: NULL (no log output)</li><li>Other values: invalid</li></ul>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p6841928598"><a name="p6841928598"></a><a name="p6841928598"></a>Optional</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row17638114219104"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p20638342191018"><a name="p20638342191018"></a><a name="p20638342191018"></a>TASK_QUEUE_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="p126381842151019"><a name="p126381842151019"></a><a name="p126381842151019"></a>Enables or disables the task delivery in multi-thread mode. When this function is enabled, the training performance of the entire network is improved in most cases. Values:</p>
|
||||
<a name="ul6194152711118"></a><a name="ul6194152711118"></a><ul id="ul6194152711118"><li><strong id="b166811333191713"><a name="b166811333191713"></a><a name="b166811333191713"></a>0</strong> or not configured: disabled</li><li><strong id="b3865153321914"><a name="b3865153321914"></a><a name="b3865153321914"></a>1</strong>: enabled</li></ul>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p86386423103"><a name="p86386423103"></a><a name="p86386423103"></a>Optional</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
> **NOTE:**
|
||||
>For more log information, see the _CANN Log Reference_.
|
||||
|
||||
<h2 id="sample-reference.md">Sample Reference</h2>
|
||||
|
||||
## Sample Code<a name="section2017032418274"></a>
|
||||
|
||||
Try to minimize the initialization frequency across the app lifetime during inference. The inference mode is set using the **model.eval\(\)** method, and the inference process must run under the code branch **with torch.no\_grad\(\):**.
|
||||
|
||||
The following uses Python code of the ResNet-50 network as an example for description.
|
||||
|
||||
**resnet50\_infer\_for\_pytorch.py** sample code:
|
||||
|
||||
```
|
||||
import argparse
|
||||
import os
|
||||
import time
|
||||
import torch
|
||||
import torch.nn.parallel
|
||||
import torch.optim
|
||||
import torch.utils.data
|
||||
import torch.utils.data.distributed
|
||||
import torchvision.transforms as transforms
|
||||
import torchvision.datasets as datasets
|
||||
import torchvision.models as models
|
||||
|
||||
import torch.npu
|
||||
from apex import amp
|
||||
|
||||
model_names = sorted(name for name in models.__dict__
|
||||
if name.islower() and not name.startswith("__")
|
||||
and callable(models.__dict__[name]))
|
||||
|
||||
|
||||
def parse_args():
|
||||
""" User-defined dataset path and model path """
|
||||
parser = argparse.ArgumentParser(description='PyTorch ImageNet Training')
|
||||
parser.add_argument('--data', metavar='DIR', default="/data/imagenet",
|
||||
help='path to dataset')
|
||||
parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet50',
|
||||
choices=model_names,
|
||||
help='model architecture: ' +
|
||||
' | '.join(model_names) +
|
||||
' (default: resnet18)')
|
||||
|
||||
parser.add_argument('--epochs', default=100, type=int, metavar='N',
|
||||
help='number of total epochs to run')
|
||||
|
||||
parser.add_argument('-b', '--batch_size', default=512, type=int,
|
||||
metavar='N',
|
||||
help='mini-batch size (default: 256), this is the total '
|
||||
'batch size of all GPUs on the current node when '
|
||||
'using Data Parallel or Distributed Data Parallel')
|
||||
|
||||
parser.add_argument('--resume', default='', type=str, metavar='PATH',
|
||||
help='path to latest checkpoint (default: none)')
|
||||
|
||||
parser.add_argument('--pretrained', dest='pretrained', action='store_true',
|
||||
help='use pre-trained model')
|
||||
|
||||
parser.add_argument('--npu', default=None, type=int,
|
||||
help='NPU id to use.')
|
||||
|
||||
parser.add_argument('-j', '--workers', default=32, type=int, metavar='N',
|
||||
help='number of data loading workers (default: 8)')
|
||||
|
||||
parser.add_argument('--lr', '--learning_rate', default=0.1, type=float,
|
||||
metavar='LR', help='initial learning rate', dest='lr')
|
||||
parser.add_argument('--wd', '--weight_decay', default=1e-4, type=float,
|
||||
metavar='W', help='weight decay (default: 1e-4)',
|
||||
dest='weight_decay')
|
||||
|
||||
args, unknown_args = parser.parse_known_args()
|
||||
if len(unknown_args) > 0:
|
||||
for bad_arg in unknown_args:
|
||||
print("ERROR: Unknown command line arg: %s" % bad_arg)
|
||||
raise ValueError("Invalid command line arg(s)")
|
||||
|
||||
return args
|
||||
|
||||
|
||||
# =========================================================================
|
||||
# Main function entry
|
||||
# =========================================================================
|
||||
def main():
|
||||
args = parse_args()
|
||||
if args.npu is None:
|
||||
args.npu = 0
|
||||
global CALCULATE_DEVICE
|
||||
CALCULATE_DEVICE = "npu:{}".format(args.npu)
|
||||
torch.npu.set_device(CALCULATE_DEVICE)
|
||||
print("use ", CALCULATE_DEVICE)
|
||||
main_worker(args.npu, args)
|
||||
|
||||
|
||||
def main_worker(npu, args):
|
||||
global best_acc1
|
||||
args.npu = npu
|
||||
|
||||
# =========================================================================
|
||||
# Create a model.
|
||||
# =========================================================================
|
||||
print("=> creating model '{}'".format(args.arch))
|
||||
model = models.__dict__[args.arch](zero_init_residual=True)
|
||||
|
||||
# Copy the model data to the Ascend AI Processor.
|
||||
model = model.to(CALCULATE_DEVICE)
|
||||
|
||||
optimizer = torch.optim.SGD([
|
||||
{'params': [param for name, param in model.named_parameters() if name[-4:] == 'bias'], 'weight_decay': 0.0},
|
||||
{'params': [param for name, param in model.named_parameters() if name[-4:] != 'bias'],
|
||||
'weight_decay': args.weight_decay}],
|
||||
args.lr)
|
||||
|
||||
# =========================================================================
|
||||
# Initialize the mixed precision model. After the model is used, the calculation can be accelerated, but the accuracy may slightly decrease. Determine whether to use the model based on the actual scenario.
|
||||
# =========================================================================
|
||||
model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=1024, verbosity=1)
|
||||
|
||||
# =========================================================================
|
||||
# Load the trained model parameters.
|
||||
# =========================================================================
|
||||
# Restore model parameters from the model file.
|
||||
if os.path.isfile(args.resume):
|
||||
print("=> loading checkpoint '{}'".format(args.resume))
|
||||
checkpoint = torch.load(args.resume)
|
||||
|
||||
best_acc1 = checkpoint['best_acc1']
|
||||
best_acc1 = best_acc1.to("npu:{}".format(args.npu))
|
||||
|
||||
model.load_state_dict(checkpoint['state_dict'])
|
||||
print("=> loaded checkpoint '{}' (epoch {})".format(args.resume, checkpoint['epoch']))
|
||||
|
||||
else:
|
||||
print("=> no checkpoint found at '{}'".format(args.resume))
|
||||
|
||||
# =========================================================================
|
||||
# Initialize the database.
|
||||
# =========================================================================
|
||||
# Load and preprocess image data.
|
||||
valdir = os.path.join(args.data, 'val')
|
||||
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
|
||||
std=[0.229, 0.224, 0.225])
|
||||
|
||||
val_loader = torch.utils.data.DataLoader(
|
||||
datasets.ImageFolder(valdir, transforms.Compose([
|
||||
transforms.Resize(256),
|
||||
transforms.CenterCrop(224),
|
||||
transforms.ToTensor(),
|
||||
normalize,
|
||||
])),
|
||||
batch_size=args.batch_size, shuffle=True,
|
||||
num_workers=args.workers, pin_memory=True)
|
||||
|
||||
# =========================================================================
|
||||
# Run the validate command.
|
||||
# =========================================================================
|
||||
validate(val_loader, model, args)
|
||||
|
||||
|
||||
# =========================================================================
|
||||
# Implement the sample API for online inference.
|
||||
# =========================================================================
|
||||
def validate(val_loader, model, args):
|
||||
batch_time = AverageMeter('Time', ':6.3f')
|
||||
top1 = AverageMeter('Acc@1', ':6.2f')
|
||||
top5 = AverageMeter('Acc@5', ':6.2f')
|
||||
progress = ProgressMeter(
|
||||
len(val_loader),
|
||||
[batch_time, top1, top5],
|
||||
prefix='Test: ')
|
||||
|
||||
# =========================================================================
|
||||
# Switch to the inference mode.
|
||||
# =========================================================================
|
||||
model.eval()
|
||||
|
||||
# =========================================================================
|
||||
# Execute the model forward propagation under the torch.no_grad(): branch.
|
||||
# =========================================================================
|
||||
with torch.no_grad():
|
||||
end = time.time()
|
||||
for i, (images, target) in enumerate(val_loader):
|
||||
|
||||
# Place the image data on the NPU.
|
||||
images = images.to(CALCULATE_DEVICE, non_blocking=True)
|
||||
target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=True)
|
||||
|
||||
# Calculate the output.
|
||||
output = model(images)
|
||||
|
||||
# Collect statistics on result precisions.
|
||||
acc1, acc5 = accuracy(output, target, topk=(1, 5))
|
||||
top1.update(acc1[0], images.size(0))
|
||||
top5.update(acc5[0], images.size(0))
|
||||
|
||||
# Measure the running time.
|
||||
batch_time.update(time.time() - end)
|
||||
end = time.time()
|
||||
|
||||
# Print inference logs.
|
||||
progress.display(i)
|
||||
|
||||
print(' * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}'.format(top1=top1, top5=top5))
|
||||
|
||||
return top1.avg
|
||||
|
||||
|
||||
class AverageMeter(object):
|
||||
"""Calculate and store the average value and current value."""
|
||||
def __init__(self, name, fmt=':f'):
|
||||
self.name = name
|
||||
self.fmt = fmt
|
||||
self.reset()
|
||||
self.start_count_index = 10
|
||||
|
||||
def reset(self):
|
||||
self.val = 0
|
||||
self.avg = 0
|
||||
self.sum = 0
|
||||
self.count = 0
|
||||
|
||||
def update(self, val, n=1):
|
||||
if self.count == 0:
|
||||
self.batchsize = n
|
||||
|
||||
self.val = val
|
||||
self.count += n
|
||||
if self.count > (self.start_count_index * self.batchsize):
|
||||
self.sum += val * n
|
||||
self.avg = self.sum / (self.count - self.start_count_index * self.batchsize)
|
||||
|
||||
def __str__(self):
|
||||
fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})'
|
||||
return fmtstr.format(**self.__dict__)
|
||||
|
||||
|
||||
class ProgressMeter(object):
|
||||
"""Record model computing information."""
|
||||
def __init__(self, num_batches, meters, prefix=""):
|
||||
self.batch_fmtstr = self._get_batch_fmtstr(num_batches)
|
||||
self.meters = meters
|
||||
self.prefix = prefix
|
||||
|
||||
def display(self, batch):
|
||||
entries = [self.prefix + self.batch_fmtstr.format(batch)]
|
||||
entries += [str(meter) for meter in self.meters]
|
||||
print('\t'.join(entries))
|
||||
|
||||
def _get_batch_fmtstr(self, num_batches):
|
||||
num_digits = len(str(num_batches // 1))
|
||||
fmt = '{:' + str(num_digits) + 'd}'
|
||||
return '[' + fmt + '/' + fmt.format(num_batches) + ']'
|
||||
|
||||
|
||||
def accuracy(output, target, topk=(1,)):
|
||||
"""Calculate the precision of k top predictions based on the specified value k."""
|
||||
with torch.no_grad():
|
||||
maxk = max(topk)
|
||||
batch_size = target.size(0)
|
||||
|
||||
_, pred = output.topk(maxk, 1, True, True)
|
||||
pred = pred.t()
|
||||
correct = pred.eq(target.view(1, -1).expand_as(pred))
|
||||
|
||||
res = []
|
||||
for k in topk:
|
||||
correct_k = correct[:k].view(-1).float().sum(0, keepdim=True)
|
||||
res.append(correct_k.mul_(100.0 / batch_size))
|
||||
return res
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
```
|
||||
|
||||
## Sample Running<a name="section340764716270"></a>
|
||||
|
||||
The following uses the ResNet-50 model as an example to describe how to perform online inference.
|
||||
|
||||
1. Download a pre-trained model.
|
||||
|
||||
Visit [Ascend ModelZoo](https://www.hiascend.com/en/software/modelzoo) and click **Download Model** to download a pre-trained ResNet-50 model.
|
||||
|
||||
2. Edit the inference script.
|
||||
|
||||
Create a model script file **resnet50\_infer\_for\_pytorch.py** and write code by referring to [Sample Code]().
|
||||
|
||||
3. Run inference.
|
||||
|
||||
Set environment variables by referring to [Environment Variable Configuration](#environment-variable-configuration.md) and then run the following command:
|
||||
|
||||
```
|
||||
python3 pytorch-resnet50-apex.py --data /data/imagenet \
|
||||
--npu 7 \
|
||||
--epochs 90 \
|
||||
--resume ./checkpoint.pth.tar # ./checkpoint.pth.tar is the path of the sample pre-trained model file.
|
||||
```
|
||||
|
||||
> **NOTE:**
|
||||
>The preceding command is an example only. Modify the arguments as needed.
|
||||
|
||||
|
||||
<h2 id="special-topics.md">Special Topics</h2>
|
||||
|
||||
- **[Mixed Precision](#mixed-precision.md)**
|
||||
|
||||
|
||||
<h2 id="mixed-precision.md">Mixed Precision</h2>
|
||||
|
||||
## Overview<a name="section14734122962615"></a>
|
||||
|
||||
Based on the architecture features of the NPU, mixed precision is involved in the model computing, that is, the scenario where the float16 and float32 data types are used together. Replacing float32 with float16 has the following advantages:
|
||||
|
||||
- The memory usage of intermediate variables is reduced.
|
||||
- The data transfer time decreases because the memory usage is reduced.
|
||||
- The compute units of float16 provide better computing performance.
|
||||
|
||||
However, the mixed precision training is limited by the precision range expressed by float16. If float32 is converted into float16, the training convergence is affected. To use float16 for acceleration in some computations and ensure training convergence, the mixed precision module Apex is used. The mixed precision module Apex is a comprehensive optimization library that features high optimization performance and precision.
|
||||
|
||||
## Supported Features<a name="section175201458521"></a>
|
||||
|
||||
[Table 1](#en-us_topic_0278765773_table10717173813332) describes the functions and optimization of the mixed precision module.
|
||||
|
||||
**Table 1** Functions of the mixed precision module
|
||||
|
||||
<a name="en-us_topic_0278765773_table10717173813332"></a>
|
||||
<table><thead align="left"><tr id="en-us_topic_0278765773_row371716385333"><th class="cellrowborder" valign="top" width="32.269999999999996%" id="mcps1.2.3.1.1"><p id="en-us_topic_0278765773_p13717163815333"><a name="en-us_topic_0278765773_p13717163815333"></a><a name="en-us_topic_0278765773_p13717163815333"></a>Function</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="67.73%" id="mcps1.2.3.1.2"><p id="en-us_topic_0278765773_p14400173910345"><a name="en-us_topic_0278765773_p14400173910345"></a><a name="en-us_topic_0278765773_p14400173910345"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="en-us_topic_0278765773_row1571763813334"><td class="cellrowborder" valign="top" width="32.269999999999996%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0278765773_p4502732153412"><a name="en-us_topic_0278765773_p4502732153412"></a><a name="en-us_topic_0278765773_p4502732153412"></a>O1 configuration</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="67.73%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0278765773_p640053920348"><a name="en-us_topic_0278765773_p640053920348"></a><a name="en-us_topic_0278765773_p640053920348"></a>Conv and Matmul use float16 for computing, and Softmax and BN use float32.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0278765773_row3717173817336"><td class="cellrowborder" valign="top" width="32.269999999999996%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0278765773_p11503103210344"><a name="en-us_topic_0278765773_p11503103210344"></a><a name="en-us_topic_0278765773_p11503103210344"></a>O2 configuration</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="67.73%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0278765773_p164001639143419"><a name="en-us_topic_0278765773_p164001639143419"></a><a name="en-us_topic_0278765773_p164001639143419"></a>BN uses float32, and others use float16.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0278765773_row14717193815334"><td class="cellrowborder" valign="top" width="32.269999999999996%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0278765773_p1950318328349"><a name="en-us_topic_0278765773_p1950318328349"></a><a name="en-us_topic_0278765773_p1950318328349"></a>Static loss scale</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="67.73%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0278765773_p1440033983418"><a name="en-us_topic_0278765773_p1440033983418"></a><a name="en-us_topic_0278765773_p1440033983418"></a>Parameters are statically set to ensure the convergence of mixed precision training.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0278765773_row871733813317"><td class="cellrowborder" valign="top" width="32.269999999999996%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0278765773_p1550303243417"><a name="en-us_topic_0278765773_p1550303243417"></a><a name="en-us_topic_0278765773_p1550303243417"></a>Dynamic loss scale</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="67.73%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0278765773_p15400143963412"><a name="en-us_topic_0278765773_p15400143963412"></a><a name="en-us_topic_0278765773_p15400143963412"></a>The loss scale value is dynamically calculated to determine whether overflow occurs.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
> **NOTE:**
|
||||
>In the current version, Apex is implemented using Python and does not support AscendCL or CUDA optimization.
|
||||
|
||||
## Initializing the Mixed Precision Model<a name="section18178125518268"></a>
|
||||
|
||||
1. To use the mixed precision module Apex, you need to import the amp module from the Apex library as follows:
|
||||
|
||||
```
|
||||
from apex import amp
|
||||
```
|
||||
|
||||
2. After the amp module is imported, you need to initialize it so that it can modify the model, optimizer, and PyTorch internal functions. The initialization code is as follows:
|
||||
|
||||
```
|
||||
model, optimizer = amp.initialize(model, optimizer)
|
||||
```
|
||||
|
||||
For details, see "Initialize the mixed precision model."# in [Sample Code](#sample-reference.md).
|
||||
|
||||
```
|
||||
model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=1024, verbosity=1)
|
||||
```
|
||||
|
||||
|
||||
## Mixed Precision Inference<a name="section818071513288"></a>
|
||||
|
||||
After the mixed precision model is initialized, perform model forward propagation.
|
||||
|
||||
Sample code: For details, see the implementation of **validate\(val\_loader, model, args\)** in [Sample Code](#sample-reference.md).
|
||||
|
||||
<h2 id="how-do-i-install-gcc-7-3-0.md">How Do I Install GCC 7.3.0?</h2>
|
||||
|
||||
Perform the following steps as the **root** user.
|
||||
|
||||
1. Download **gcc-7.3.0.tar.gz** from [https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz](https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz).
|
||||
2. To install GCC, you need to reserve adequate temporary space. Run the following command to clear the **/tmp** directory before the installation:
|
||||
|
||||
```
|
||||
sudo rm -rf /tmp/*
|
||||
```
|
||||
|
||||
3. Install the dependency package. \(CentOS and Ubuntu are used as examples.\)
|
||||
- For CentOS, run the following command:
|
||||
|
||||
```
|
||||
yum install bzip2
|
||||
```
|
||||
|
||||
- For Ubuntu, run the following command:
|
||||
|
||||
```
|
||||
apt-get install bzip2
|
||||
```
|
||||
|
||||
4. Build and install GCC.
|
||||
1. Go to the directory where the source code package **gcc-7.3.0.tar.gz** is located and run the following command to extract it:
|
||||
|
||||
```
|
||||
tar -zxvf gcc-7.3.0.tar.gz
|
||||
```
|
||||
|
||||
2. Go to the extracted directory and run the following command to download the GCC dependency packages:
|
||||
|
||||
```
|
||||
cd gcc-7.3.0
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
If an error is reported during the command execution, run the following commands in the **gcc-7.3.0/** directory to download the dependency packages:
|
||||
|
||||
```
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
|
||||
```
|
||||
|
||||
After downloading the preceding dependency packages, run the following command:
|
||||
|
||||
```
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
If the verification fails, check whether the dependency package is repeatedly downloaded. The package should be downloaded at a time.
|
||||
|
||||
3. <a name="en-us_topic_0000001146754749_en-us_topic_0000001072593337_l75d31a2874534a2092e80a5f865b46f0"></a>Run the following commands for configuration, build, and installation.
|
||||
|
||||
```
|
||||
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.3.0
|
||||
make -j15 # The value 15 indicates the number of CPUs, which is configurable and can be queried by running grep -w processor /proc/cpuinfo|wc -l.
|
||||
make install
|
||||
```
|
||||
|
||||
> **NOTICE:**
|
||||
>The **--prefix** parameter is used to specify the linux\_gcc7.3.0 installation path, which is configurable. Do not set it to **/usr/local** or **/usr**, which is the default installation path for the GCC installed by using the software source. Otherwise, a conflict occurs and the original GCC compilation environment of the system is damaged. In this example, the installation path is set to **/usr/local/linux\_gcc7.3.0**.
|
||||
|
||||
|
||||
5. Set the environment variable.
|
||||
|
||||
The build environment after GCC upgrade is required for training. Therefore, you need to configure the following environment variable in the training script:
|
||||
|
||||
```
|
||||
export LD_LIBRARY_PATH=${install_path}/lib64:${LD_LIBRARY_PATH}
|
||||
```
|
||||
|
||||
**$\{install\_path\}** indicates the GCC 7.3.0 installation path configured in [3.](#en-us_topic_0000001146754749_en-us_topic_0000001072593337_l75d31a2874534a2092e80a5f865b46f0). In this example, the GCC 7.3.0 installation path is **/usr/local/linux\_gcc7.3.0/**.
|
||||
|
||||
> **NOTE:**
|
||||
>The environment variable needs to be configured only when you need to use the build environment after the GCC upgrade.
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 580 B |
|
After Width: | Height: | Size: 580 B |
|
After Width: | Height: | Size: 394 B |
|
After Width: | Height: | Size: 406 B |
|
After Width: | Height: | Size: 253 B |
|
After Width: | Height: | Size: 580 B |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 7.6 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 28 KiB |