已合并
optimize docker to build torch_npu #37602
SCh_zx创建于 6月4日
optimize docker to build torch_npu #37602
已合并
SCh_zx创建于 6月4日
8 个文件变更+222-25
@@ -1,4 +1,4 @@
1-FROM pytorch/manylinux2_28_aarch64-builder:cpu-aarch64-v2.10.0-rc71+FROM quay.io/pypa/manylinux_2_28_aarch64:2025.04.26-0
2 2 
3ENV PATH /usr/local/bin:$PATH3ENV PATH /usr/local/bin:$PATH
4 4 
@@ -6,14 +6,15 @@ RUN echo "alias ll='ls -l --color=auto'" >> /root/.bashrc
6 6 
7# Set pip&python7# Set pip&python
8RUN cd /usr/local/bin \8RUN cd /usr/local/bin \
9- && ln -sf /opt/_internal/cpython-3.10.19/bin/pip3.10 pip3.10 \9+ && ln -sf /opt/python/cp310-cp310/bin/pip3.10 pip3.10 \
10- && ln -sf /opt/_internal/cpython-3.11.14/bin/pip3.11 pip3.11 \10+ && ln -sf /opt/python/cp311-cp311/bin/pip3.11 pip3.11 \
11- && ln -sf /opt/_internal/cpython-3.12.12/bin/pip3.12 pip3.12 \11+ && ln -sf /opt/python/cp312-cp312/bin/pip3.12 pip3.12 \
12- && ln -sf /opt/_internal/cpython-3.10.19/bin/pip3.10 pip3 \12+ && ln -sf /opt/python/cp310-cp310/bin/pip3.10 pip3 \
13- && ln -sf /opt/_internal/cpython-3.10.19/bin/python3.10 python3.10 \13+ && ln -sf /opt/python/cp310-cp310/bin/python3.10 python3.10 \
14- && ln -sf /opt/_internal/cpython-3.11.14/bin/python3.11 python3.11 \14+ && ln -sf /opt/python/cp311-cp311/bin/python3.11 python3.11 \
15- && ln -sf /opt/_internal/cpython-3.12.12/bin/python3.12 python3.12 \15+ && ln -sf /opt/python/cp311-cp311/bin/python3.12 python3.12 \
16- && ln -sf /opt/_internal/cpython-3.10.19/bin/python3.10 python316+ && ln -sf /opt/python/cp310-cp310/bin/python3.10 python3 \
17+ && ln -sf /opt/python/cp310-cp310/bin/python3.10 python
17 18 
18# Set pip source19# Set pip source
19RUN mkdir /root/.pip \20RUN mkdir /root/.pip \
@@ -39,17 +40,26 @@ RUN if [ "$CONFIG_FOR_LCOV" = "1" ]; then \
39 yum install -y perl-CPAN*; \40 yum install -y perl-CPAN*; \
40 fi41 fi
41 42 
43+RUN yum install -y vim-common\
44+ && yum install -y ninja-build \
45+ && yum install -y dos2unix \
46+ && yum install -y gcc-toolset-14 \
47+ && echo "source /opt/rh/gcc-toolset-14/enable" >> /root/.bashrc
48+ 
42# Install pip package(build)49# Install pip package(build)
43RUN pip3.10 install pyyaml \50RUN pip3.10 install pyyaml \
44- && pip3.10 install torch==2.10.0 \51+ && pip3.10 install setuptools \
52+ && pip3.10 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \
45 && pip3.10 install numpy==1.25.253 && pip3.10 install numpy==1.25.2
46 54 
47RUN pip3.11 install pyyaml \55RUN pip3.11 install pyyaml \
48- && pip3.11 install torch==2.10.0 \56+ && pip3.11 install setuptools \
57+ && pip3.11 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \
49 && pip3.11 install numpy==1.25.258 && pip3.11 install numpy==1.25.2
50 59 
51RUN pip3.12 install pyyaml \60RUN pip3.12 install pyyaml \
52- && pip3.12 install torch==2.10.0 \61+ && pip3.12 install setuptools \
62+ && pip3.12 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \
53 && pip3.12 install numpy==1.25.263 && pip3.12 install numpy==1.25.2
54 64 
55WORKDIR /home65WORKDIR /home
@@ -1,8 +1,8 @@
1-## Ascend Pytorch Dockerfile Repository1+# Ascend Pytorch Dockerfile Repository
2 2 
3This folder hosts the `Dockerfile` to build docker images with various platforms.3This folder hosts the `Dockerfile` to build docker images with various platforms.
4 4 
5-### Build torch_npu from Docker container5+## Build torch_npu from Docker container
6 6 
7**Clone torch-npu**7**Clone torch-npu**
8 8 
@@ -16,7 +16,9 @@ git clone https://gitcode.com/ascend/pytorch.git --depth 1
16cd pytorch/ci/docker/{arch} # {arch} for X86 or ARM16cd pytorch/ci/docker/{arch} # {arch} for X86 or ARM
17docker build -t manylinux-builder:v1 .17docker build -t manylinux-builder:v1 .
18```18```
19+ 
19If you want to configure the environment of LCOV, please build docker image like this:20If you want to configure the environment of LCOV, please build docker image like this:
21+ 
20```Shell22```Shell
21cd pytorch/ci/docker/{arch} # {arch} for X86 or ARM23cd pytorch/ci/docker/{arch} # {arch} for X86 or ARM
22docker build -t manylinux-builder:v1 --build-arg CONFIG_FOR_LCOV=1 .24docker build -t manylinux-builder:v1 --build-arg CONFIG_FOR_LCOV=1 .
@@ -28,10 +30,12 @@ docker build -t manylinux-builder:v1 --build-arg CONFIG_FOR_LCOV=1 .
28docker run -it -v /{code_path}/pytorch:/home/pytorch manylinux-builder:v1 bash30docker run -it -v /{code_path}/pytorch:/home/pytorch manylinux-builder:v1 bash
29# {code_path} is the torch_npu source code path31# {code_path} is the torch_npu source code path
30```32```
33+ 
31**Compile torch_npu**34**Compile torch_npu**
32 35 
33-Take Python 3.9 as an example36+Take Python 3.10 as an example
37+ 
34```Shell38```Shell
35cd /home/pytorch39cd /home/pytorch
36-bash ci/build.sh --python=3.940+bash ci/build.sh --python=3.10
37```41```
@@ -1,4 +1,4 @@
1- FROM pytorch/manylinux2_28-builder:cpu-v2.10.0-rc71+FROM quay.io/pypa/manylinux_2_28_x86_64:2025.04.26-0
2 2 
3ENV PATH /usr/local/bin:$PATH3ENV PATH /usr/local/bin:$PATH
4 4 
@@ -6,14 +6,15 @@ RUN echo "alias ll='ls -l --color=auto'" >> /root/.bashrc
6 6 
7# Set pip&python7# Set pip&python
8RUN cd /usr/local/bin \8RUN cd /usr/local/bin \
9- && ln -sf /opt/_internal/cpython-3.10.19/bin/pip3.10 pip3.10 \9+ && ln -sf /opt/python/cp310-cp310/bin/pip3.10 pip3.10 \
10- && ln -sf /opt/_internal/cpython-3.11.14/bin/pip3.11 pip3.11 \10+ && ln -sf /opt/python/cp311-cp311/bin/pip3.11 pip3.11 \
11- && ln -sf /opt/_internal/cpython-3.12.12/bin/pip3.12 pip3.12 \11+ && ln -sf /opt/python/cp312-cp312/bin/pip3.12 pip3.12 \
12- && ln -sf /opt/_internal/cpython-3.10.19/bin/pip3.10 pip3 \12+ && ln -sf /opt/python/cp310-cp310/bin/pip3.10 pip3 \
13- && ln -sf /opt/_internal/cpython-3.10.19/bin/python3.10 python3.10 \13+ && ln -sf /opt/python/cp310-cp310/bin/python3.10 python3.10 \
14- && ln -sf /opt/_internal/cpython-3.11.14/bin/python3.11 python3.11 \14+ && ln -sf /opt/python/cp311-cp311/bin/python3.11 python3.11 \
15- && ln -sf /opt/_internal/cpython-3.12.12/bin/python3.12 python3.12 \15+ && ln -sf /opt/python/cp311-cp311/bin/python3.12 python3.12 \
16- && ln -sf /opt/_internal/cpython-3.10.19/bin/python3.10 python316+ && ln -sf /opt/python/cp310-cp310/bin/python3.10 python3 \
17+ && ln -sf /opt/python/cp310-cp310/bin/python3.10 python
17 18 
18# Set pip source19# Set pip source
19RUN mkdir /root/.pip \20RUN mkdir /root/.pip \
@@ -39,16 +40,25 @@ RUN if [ "$CONFIG_FOR_LCOV" = "1" ]; then \
39 yum install -y perl-CPAN*; \40 yum install -y perl-CPAN*; \
40 fi41 fi
41 42 
43+RUN yum install -y vim-common\
44+ && yum install -y ninja-build \
45+ && yum install -y dos2unix \
46+ && yum install -y gcc-toolset-14 \
47+ && echo "source /opt/rh/gcc-toolset-14/enable" >> /root/.bashrc
48+ 
42# Install pip package(build)49# Install pip package(build)
43RUN pip3.10 install pyyaml \50RUN pip3.10 install pyyaml \
51+ && pip3.10 install setuptools \
44 && pip3.10 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \52 && pip3.10 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \
45 && pip3.10 install numpy==1.25.253 && pip3.10 install numpy==1.25.2
46 54 
47RUN pip3.11 install pyyaml \55RUN pip3.11 install pyyaml \
56+ && pip3.11 install setuptools \
48 && pip3.11 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \57 && pip3.11 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \
49 && pip3.11 install numpy==1.25.258 && pip3.11 install numpy==1.25.2
50 59 
51RUN pip3.12 install pyyaml \60RUN pip3.12 install pyyaml \
61+ && pip3.12 install setuptools \
52 && pip3.12 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \62 && pip3.12 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \
53 && pip3.12 install numpy==1.25.263 && pip3.12 install numpy==1.25.2
54 64 
@@ -0,0 +1,65 @@
1+FROM quay.io/pypa/manylinux_2_28_aarch64:2025.04.26-0
2+ 
3+ENV PATH /usr/local/bin:$PATH
4+ 
5+RUN echo "alias ll='ls -l --color=auto'" >> /root/.bashrc
6+ 
7+# Set pip&python
8+RUN cd /usr/local/bin \
9+ && ln -sf /opt/python/cp310-cp310/bin/pip3.10 pip3.10 \
10+ && ln -sf /opt/python/cp311-cp311/bin/pip3.11 pip3.11 \
11+ && ln -sf /opt/python/cp312-cp312/bin/pip3.12 pip3.12 \
12+ && ln -sf /opt/python/cp310-cp310/bin/pip3.10 pip3 \
13+ && ln -sf /opt/python/cp310-cp310/bin/python3.10 python3.10 \
14+ && ln -sf /opt/python/cp311-cp311/bin/python3.11 python3.11 \
15+ && ln -sf /opt/python/cp311-cp311/bin/python3.12 python3.12 \
16+ && ln -sf /opt/python/cp310-cp310/bin/python3.10 python3 \
17+ && ln -sf /opt/python/cp310-cp310/bin/python3.10 python
18+ 
19+# Set pip source
20+RUN mkdir /root/.pip \
21+ && echo "[global]" > /root/.pip/pip.conf \
22+ && echo "index-url=https://mirrors.huaweicloud.com/repository/pypi/simple" >> /root/.pip/pip.conf \
23+ && echo "trusted-host=repo.huaweicloud.com" >> /root/.pip/pip.conf \
24+ && echo "timeout=120" >> /root/.pip/pip.conf
25+ 
26+ARG CONFIG_FOR_LCOV=0
27+ 
28+RUN if [ "$CONFIG_FOR_LCOV" = "1" ]; then \
29+ mkdir -p /etc/yum.repos.d/backup && \
30+ mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/ && \
31+ curl -o /etc/yum.repos.d/Centos7-aliyun.repo https://mirrors.wlnmp.com/centos/Centos7-aliyun-altarch.repo -k && \
32+ yum clean all && \
33+ yum makecache; \
34+ fi
35+ 
36+RUN if [ "$CONFIG_FOR_LCOV" = "1" ]; then \
37+ yum install -y perl-Module-Load-Conditional && \
38+ yum install -y perl-Digest-MD5 && \
39+ yum install -y "perl(DateTime)" && \
40+ yum install -y perl-CPAN*; \
41+ fi
42+ 
43+RUN yum install -y vim-common\
44+ && yum install -y ninja-build \
45+ && yum install -y dos2unix \
46+ && yum install -y gcc-toolset-14 \
47+ && echo "source /opt/rh/gcc-toolset-14/enable" >> /root/.bashrc
48+ 
49+# Install pip package(build)
50+RUN pip3.10 install pyyaml \
51+ && pip3.10 install setuptools \
52+ && pip3.10 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \
53+ && pip3.10 install numpy==1.25.2
54+ 
55+RUN pip3.11 install pyyaml \
56+ && pip3.11 install setuptools \
57+ && pip3.11 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \
58+ && pip3.11 install numpy==1.25.2
59+ 
60+RUN pip3.12 install pyyaml \
61+ && pip3.12 install setuptools \
62+ && pip3.12 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \
63+ && pip3.12 install numpy==1.25.2
64+ 
65+WORKDIR /home
@@ -0,0 +1,41 @@
1+# Ascend Pytorch Dockerfile Repository
2+ 
3+This folder hosts the `Dockerfile` to build docker images with various platforms.
4+ 
5+## Build torch_npu from Docker container
6+ 
7+**Clone torch-npu**
8+ 
9+```Shell
10+git clone https://gitcode.com/ascend/pytorch.git --depth 1
11+```
12+ 
13+**Build docker image**
14+ 
15+```Shell
16+cd pytorch/docker/builder/{arch} # {arch} for X86 or ARM
17+docker build -t manylinux-builder:v1 .
18+```
19+ 
20+If you want to configure the environment of LCOV, please build docker image like this:
21+ 
22+```Shell
23+cd pytorch/docker/builder/{arch} # {arch} for X86 or ARM
24+docker build -t manylinux-builder:v1 --build-arg CONFIG_FOR_LCOV=1 .
25+```
26+ 
27+**Enter docker Container**
28+ 
29+```Shell
30+docker run -it -v /{code_path}/pytorch:/home/pytorch manylinux-builder:v1 bash
31+# {code_path} is the torch_npu source code path
32+```
33+ 
34+**Compile torch_npu**
35+ 
36+Take Python 3.10 as an example
37+ 
38+```Shell
39+cd /home/pytorch
40+bash ci/build.sh --python=3.10
41+```
@@ -0,0 +1,65 @@
1+FROM quay.io/pypa/manylinux_2_28_x86_64:2025.04.26-0
2+ 
3+ENV PATH /usr/local/bin:$PATH
4+ 
5+RUN echo "alias ll='ls -l --color=auto'" >> /root/.bashrc
6+ 
7+# Set pip&python
8+RUN cd /usr/local/bin \
9+ && ln -sf /opt/python/cp310-cp310/bin/pip3.10 pip3.10 \
10+ && ln -sf /opt/python/cp311-cp311/bin/pip3.11 pip3.11 \
11+ && ln -sf /opt/python/cp312-cp312/bin/pip3.12 pip3.12 \
12+ && ln -sf /opt/python/cp310-cp310/bin/pip3.10 pip3 \
13+ && ln -sf /opt/python/cp310-cp310/bin/python3.10 python3.10 \
14+ && ln -sf /opt/python/cp311-cp311/bin/python3.11 python3.11 \
15+ && ln -sf /opt/python/cp311-cp311/bin/python3.12 python3.12 \
16+ && ln -sf /opt/python/cp310-cp310/bin/python3.10 python3 \
17+ && ln -sf /opt/python/cp310-cp310/bin/python3.10 python
18+ 
19+# Set pip source
20+RUN mkdir /root/.pip \
21+ && echo "[global]" > /root/.pip/pip.conf \
22+ && echo "index-url=https://mirrors.huaweicloud.com/repository/pypi/simple" >> /root/.pip/pip.conf \
23+ && echo "trusted-host=repo.huaweicloud.com" >> /root/.pip/pip.conf \
24+ && echo "timeout=120" >> /root/.pip/pip.conf
25+ 
26+ARG CONFIG_FOR_LCOV=0
27+ 
28+RUN if [ "$CONFIG_FOR_LCOV" = "1" ]; then \
29+ mkdir -p /etc/yum.repos.d/backup && \
30+ mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/ && \
31+ curl -o /etc/yum.repos.d/Centos7-aliyun.repo https://mirrors.wlnmp.com/centos/Centos7-aliyun-altarch.repo -k && \
32+ yum clean all && \
33+ yum makecache; \
34+ fi
35+ 
36+RUN if [ "$CONFIG_FOR_LCOV" = "1" ]; then \
37+ yum install -y perl-Module-Load-Conditional && \
38+ yum install -y perl-Digest-MD5 && \
39+ yum install -y "perl(DateTime)" && \
40+ yum install -y perl-CPAN*; \
41+ fi
42+ 
43+RUN yum install -y vim-common\
44+ && yum install -y ninja-build \
45+ && yum install -y dos2unix \
46+ && yum install -y gcc-toolset-14 \
47+ && echo "source /opt/rh/gcc-toolset-14/enable" >> /root/.bashrc
48+ 
49+# Install pip package(build)
50+RUN pip3.10 install pyyaml \
51+ && pip3.10 install setuptools \
52+ && pip3.10 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \
53+ && pip3.10 install numpy==1.25.2
54+ 
55+RUN pip3.11 install pyyaml \
56+ && pip3.11 install setuptools \
57+ && pip3.11 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \
58+ && pip3.11 install numpy==1.25.2
59+ 
60+RUN pip3.12 install pyyaml \
61+ && pip3.12 install setuptools \
62+ && pip3.12 install torch==2.10.0+cpu --index-url https://download.pytorch.org/whl/cpu \
63+ && pip3.12 install numpy==1.25.2
64+ 
65+WORKDIR /home
@@ -1,4 +1,5 @@
1#pragma once1#pragma once
2+#include <algorithm>
2#include <c10/core/Device.h>3#include <c10/core/Device.h>
3#include <torch_npu/csrc/core/npu/GetAffinityCPUInfo.h>4#include <torch_npu/csrc/core/npu/GetAffinityCPUInfo.h>
4#include <set>5#include <set>
@@ -7,6 +7,7 @@
7#include <libgen.h>7#include <libgen.h>
8#include <fcntl.h>8#include <fcntl.h>
9#include <sys/syscall.h>9#include <sys/syscall.h>
10+#include <time.h>
10 11 
11#include <stdint.h>12#include <stdint.h>
12 13