-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: kandrio <[email protected]>
- Loading branch information
Showing
72 changed files
with
4,282 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Extened/build an image for CANN support | ||
# Ascend-cann-toolkit_<VERSION>.run is expected to exist in <project_root>/ascend_install_files | ||
|
||
# preferably arm64 | ||
FROM ubuntu:20.04 | ||
|
||
RUN DEBIAN_FRONTEND="noninteractive" apt update && \ | ||
apt install --no-install-recommends net-tools -y && \ | ||
apt install --no-install-recommends libsqlite3-dev -y && \ | ||
apt install --no-install-recommends zlib1g -y && \ | ||
apt install --no-install-recommends openssl -y | ||
|
||
RUN DEBIAN_FRONTEND="noninteractive" apt update && \ | ||
apt install --no-install-recommends ca-certificates -y && \ | ||
apt install --no-install-recommends bc wget -y && \ | ||
apt install --no-install-recommends curl gdb cmake gcc make g++ pkg-config unzip -y && \ | ||
apt install --no-install-recommends libblas3 liblapack3 gfortran vim -y && \ | ||
apt install --no-install-recommends liblapack-dev libblas-dev libhdf5-dev libffi-dev -y && \ | ||
apt install --no-install-recommends libssl-dev zlib1g-dev xz-utils cython3 python3-h5py -y && \ | ||
apt install --no-install-recommends libopenblas-dev libgmpxx4ldbl liblzma-dev -y && \ | ||
apt install --no-install-recommends pciutils -y | ||
|
||
|
||
RUN DEBIAN_FRONTEND="noninteractive" apt update && \ | ||
apt-get install -y --no-install-recommends \ | ||
python3-dev \ | ||
python3-pip \ | ||
wget | ||
|
||
RUN python3 -m pip --no-cache-dir install numpy && \ | ||
python3 -m pip --no-cache-dir install decorator && \ | ||
python3 -m pip --no-cache-dir install sympy && \ | ||
python3 -m pip --no-cache-dir install cffi && \ | ||
python3 -m pip --no-cache-dir install pyyaml && \ | ||
python3 -m pip --no-cache-dir install pathlib2 && \ | ||
python3 -m pip --no-cache-dir install protobuf && \ | ||
python3 -m pip --no-cache-dir install scipy | ||
|
||
RUN python3 -m pip --no-cache-dir install psutil && \ | ||
python3 -m pip --no-cache-dir install requests absl-py | ||
|
||
RUN python3 -m pip --no-cache-dir install attrs | ||
|
||
# cleanup actions | ||
RUN rm -rf /root/.cache/pip | ||
RUN DEBIAN_FRONTEND="noninteractive" apt clean && rm -rf /var/lib/apt/lists/* | ||
RUN DEBIAN_FRONTEND="noninteractive" apt autoremove && apt autoclean | ||
|
||
# Install Ascend toolkit | ||
COPY ascend_install_files ascend_install_files | ||
RUN chmod +x ascend_install_files/Ascend-cann-toolkit_7.0.RC1.alpha001_linux-aarch64.run && \ | ||
ascend_install_files/Ascend-cann-toolkit_7.0.RC1.alpha001_linux-aarch64.run --install && \ | ||
rm -f ascend_install_files/Ascend-cann-toolkit_7.0.RC1.alpha001_linux-aarch64.run | ||
|
||
# Add usergroup & user | ||
RUN groupadd HwHiAiUser && useradd -g HwHiAiUser -m -d /home/HwHiAiUser HwHiAiUser | ||
|
||
# This is copied from /usr/local/Ascend/ascend-toolkit/set_env.sh of the respective ascend-toolkit version | ||
ENV LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/common:/usr/local/Ascend/driver/lib64/driver:$LD_LIBRARY_PATH | ||
ENV ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest | ||
ENV LD_LIBRARY_PATH=${ASCEND_TOOLKIT_HOME}/lib64:${ASCEND_TOOLKIT_HOME}/lib64/plugin/opskernel:${ASCEND_TOOLKIT_HOME}/lib64/plugin/nnengine:$LD_LIBRARY_PATH | ||
ENV PYTHONPATH=${ASCEND_TOOLKIT_HOME}/python/site-packages:${ASCEND_TOOLKIT_HOME}/opp/built-in/op_impl/ai_core/tbe:$PYTHONPATH | ||
ENV PATH=${ASCEND_TOOLKIT_HOME}/bin:${ASCEND_TOOLKIT_HOME}/compiler/ccec_compiler/bin:$PATH | ||
ENV ASCEND_AICPU_PATH=${ASCEND_TOOLKIT_HOME} | ||
ENV ASCEND_OPP_PATH=${ASCEND_TOOLKIT_HOME}/opp | ||
ENV TOOLCHAIN_HOME=${ASCEND_TOOLKIT_HOME}/toolkit | ||
ENV ASCEND_HOME_PATH=${ASCEND_TOOLKIT_HOME} | ||
|
||
# ENV LD_LIBRARY_PATH=/usr/lib/aarch64-linux-gnu/hdf5/serial:$LD_LIBRARY_PATH | ||
# ENV HCCL_CONNECT_TIMEOUT=7200 | ||
# ENV HCCL_WHITELIST_DISABLE=1 | ||
# ENV HCCL_SECURITY_MODE=1 | ||
|
||
ENV ASCEND_GLOBAL_LOG_LEVEL=3 | ||
|
||
# Set env vars again in case of interactive ssh connection (ascend-toolkit assumed to be already installed) | ||
RUN cp /usr/local/Ascend/ascend-toolkit/set_env.sh /etc/profile.d/ | ||
RUN chmod 644 /etc/profile.d/set_env.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
# build image that will host CANN environment | ||
cd ../../ | ||
docker build -t ctranslate2-aarch64 -f docker/cann/Dockerfile_cann --platform linux/arm64 . | ||
|
||
# run the respective container | ||
docker run \ | ||
-d --cap-add sys_ptrace \ | ||
--pids-limit 409600 \ | ||
--privileged --shm-size=128G \ | ||
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ | ||
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \ | ||
-v /usr/local/dcmi:/usr/local/dcmi \ | ||
--name ctranslate2-aarch64 <container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cmake_minimum_required(VERSION 3.7) | ||
project(cann) | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_BUILD_TYPE Release) | ||
find_package(Threads) | ||
add_executable(cann_run main.cc) | ||
target_link_libraries(cann_run PRIVATE | ||
${CMAKE_THREAD_LIBS_INIT} | ||
ctranslate2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# CANN example query | ||
This example demonstrates a translation query employing `CANN` using the English-German Transformer model trained with OpenNMT-py as in [CTranslate2 documentation](https://opennmt.net/CTranslate2/quickstart.html). | ||
|
||
## Environment setup | ||
- Create environment:`docker/cann/Dockerfile_cann` | ||
- Run the container: `docker/cann/run_container_cann.sh` | ||
|
||
## Download model | ||
```bash | ||
wget https://s3.amazonaws.com/opennmt-models/transformer-ende-wmt-pyOnmt.tar.gz | ||
tar xf transformer-ende-wmt-pyOnmt.tar.gz | ||
``` | ||
|
||
## Build executable | ||
Run `examples/cann/build_run.sh` | ||
|
||
### Expected output | ||
|
||
``` | ||
current path: "<current path>" | ||
input data path: "<input data path>" | ||
[<timestamp>] [ctranslate2] [thread 49835] [info] CPU: ARM (NEON=true) | ||
[<timestamp>] [ctranslate2] [thread 49835] [info] - Selected ISA: NEON | ||
[<timestamp>] [ctranslate2] [thread 49835] [info] - Use Intel MKL: false | ||
[<timestamp>] [ctranslate2] [thread 49835] [info] - SGEMM backend: OpenBLAS (packed: false) | ||
[<timestamp>] [ctranslate2] [thread 49835] [info] - GEMM_S16 backend: none (packed: false) | ||
[<timestamp>] [ctranslate2] [thread 49835] [info] - GEMM_S8 backend: Ruy (packed: false, u8s8 preferred: false) | ||
[<timestamp>] [ctranslate2] [thread 49835] [info] NPU: | ||
[<timestamp>] [ctranslate2] [thread 49835] [info] - Number of NPU cores: 8 | ||
[<timestamp>] [ctranslate2] [thread 49835] [info] - aclrtRunMode: ACL_HOST | ||
[<timestamp>] [ctranslate2] [thread 49835] [info] Loaded model <path> on device cann:0 | ||
[<timestamp>] [ctranslate2] [thread 49835] [info] - Binary version: 6 | ||
[<timestamp>] [ctranslate2] [thread 49835] [info] - Model specification revision: 7 | ||
[<timestamp>] [ctranslate2] [thread 49835] [info] - Selected compute type: float32 | ||
input data: | ||
▁H ello ▁world ! | ||
Start: Warmup examples | ||
output: | ||
▁Hallo ▁Welt ! | ||
input data: | ||
▁H ello ▁world ! | ||
Start: Query examples | ||
output: | ||
▁Hallo ▁Welt ! | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# execute from project root | ||
|
||
# first build ct2lib | ||
rm -rf build-release/ | ||
mkdir build-release && cd build-release || exit | ||
|
||
cmake -DWITH_CANN=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_CLI=OFF -DWITH_MKL=OFF -DOPENMP_RUNTIME=COMP -DCMAKE_PREFIX_PATH="/opt/OpenBLAS" -DWITH_OPENBLAS=ON -DWITH_RUY=ON .. | ||
|
||
make -j"$(nproc)" | ||
|
||
rm CMakeCache.txt | ||
|
||
# then build cann_run | ||
cmake -DCMAKE_BUILD_TYPE=Release ../examples/cann/ | ||
|
||
make -j"$(nproc)" | ||
# ./cann_run <ende_ctranslate2_path> |
Oops, something went wrong.