mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
Add devcontainer support to PyTorch Project (#98252)
# Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 293ded1</samp> This pull request adds support for using Visual Studio Code Remote - Containers extension with the pytorch project. It adds a `.devcontainer` folder with a `devcontainer.json` file, a `Dockerfile`, and a `noop.txt` file that configure and create a dev container with Anaconda and Python 3. <!-- copilot:poem --> ### <samp>🤖 Generated by Copilot at d6b9cd7</samp> > _`devcontainer.json`_ > _Configures PyTorch containers_ > _For CPU or GPU_ ## Related to: https://github.com/pytorch/pytorch/issues/92838 Pull Request resolved: https://github.com/pytorch/pytorch/pull/98252 Approved by: https://github.com/ZainRizvi
This commit is contained in:
committed by
PyTorch MergeBot
parent
4d89489df5
commit
7378b6b9e3
34
.devcontainer/Dockerfile
Normal file
34
.devcontainer/Dockerfile
Normal file
@ -0,0 +1,34 @@
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/miniconda:0-3
|
||||
|
||||
# I am suprised this is needed
|
||||
RUN conda init
|
||||
|
||||
# Copy environment.yml (if found) to a temp location so we update the environment. Also
|
||||
# copy "noop.txt" so the COPY instruction does not fail if no environment.yml exists.
|
||||
COPY .devcontainer/cuda/environment.yml .devcontainer/noop.txt /tmp/conda-tmp/
|
||||
RUN if [ -f "/tmp/conda-tmp/environment.yml" ]; then umask 0002 && /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi \
|
||||
&& sudo rm -rf /tmp/conda-tmp
|
||||
|
||||
# Tools needed for llvm
|
||||
RUN sudo apt-get -y update
|
||||
RUN sudo apt install -y lsb-release wget software-properties-common gnupg
|
||||
|
||||
# Install CLANG if version is specified
|
||||
ARG CLANG_VERSION
|
||||
RUN if [ -n "$CLANG_VERSION" ]; then \
|
||||
sudo wget https://apt.llvm.org/llvm.sh; \
|
||||
chmod +x llvm.sh; \
|
||||
sudo ./llvm.sh "${CLANG_VERSION}"; \
|
||||
echo 'export CC=clang' >> ~/.bashrc; \
|
||||
echo 'export CXX=clang++' >> ~/.bashrc; \
|
||||
sudo apt update; \
|
||||
sudo apt install -y clang; \
|
||||
sudo apt install -y libomp-dev; \
|
||||
fi
|
||||
|
||||
|
||||
# Install cuda if version is specified
|
||||
ARG CUDA_VERSION
|
||||
RUN if [ -n "$CUDA_VERSION" ]; then \
|
||||
conda install cuda -c "nvidia/label/cuda-${CUDA_VERSION}"; \
|
||||
fi
|
37
.devcontainer/cpu/devcontainer.json
Normal file
37
.devcontainer/cpu/devcontainer.json
Normal file
@ -0,0 +1,37 @@
|
||||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||
// README at: https://github.com/devcontainers/templates/tree/main/src/anaconda
|
||||
{
|
||||
"name": "PyTorch - CPU",
|
||||
"build": {
|
||||
"context": "../..",
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"USERNAME": "vscode",
|
||||
"BUILDKIT_INLINE_CACHE": "0",
|
||||
"CLANG_VERSION": ""
|
||||
}
|
||||
},
|
||||
|
||||
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||
"features": {
|
||||
// This is needed for lintrunner
|
||||
"ghcr.io/devcontainers/features/rust:1" : {}
|
||||
},
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
"postCreateCommand": "bash .devcontainer/scripts/install-dev-tools.sh",
|
||||
|
||||
// Configure tool-specific properties.
|
||||
// "customizations": {},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": ["streetsidesoftware.code-spell-checker"]
|
||||
}
|
||||
}
|
||||
|
||||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||
// "remoteUser": "root"
|
||||
}
|
6
.devcontainer/cpu/environment.yml
Normal file
6
.devcontainer/cpu/environment.yml
Normal file
@ -0,0 +1,6 @@
|
||||
# This environment is specific to Debian
|
||||
name: PyTorch
|
||||
dependencies:
|
||||
- cmake
|
||||
- ninja
|
||||
- libopenblas
|
37
.devcontainer/cuda/devcontainer.json
Normal file
37
.devcontainer/cuda/devcontainer.json
Normal file
@ -0,0 +1,37 @@
|
||||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||
// README at: https://github.com/devcontainers/templates/tree/main/src/anaconda
|
||||
{
|
||||
"name": "PyTorch - CUDA",
|
||||
"build": {
|
||||
"context": "../..",
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"USERNAME": "vscode",
|
||||
"BUILDKIT_INLINE_CACHE": "0",
|
||||
"CUDA_VERSION": "11.8.0",
|
||||
"CLANG_VERSION": ""
|
||||
}
|
||||
},
|
||||
"runArgs": ["--gpus", "all"],
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
"postCreateCommand": "bash .devcontainer/scripts/install-dev-tools.sh",
|
||||
|
||||
// Configure tool-specific properties.
|
||||
// "customizations": {},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": ["streetsidesoftware.code-spell-checker"]
|
||||
}
|
||||
},
|
||||
|
||||
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||
"features": {
|
||||
// This is needed for lintrunner
|
||||
"ghcr.io/devcontainers/features/rust:1" : {}
|
||||
}
|
||||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||
// "remoteUser": "root"
|
||||
}
|
6
.devcontainer/cuda/environment.yml
Normal file
6
.devcontainer/cuda/environment.yml
Normal file
@ -0,0 +1,6 @@
|
||||
# This environment is specific to Debian
|
||||
name: PyTorch
|
||||
dependencies:
|
||||
- cmake
|
||||
- ninja
|
||||
- libopenblas
|
3
.devcontainer/noop.txt
Normal file
3
.devcontainer/noop.txt
Normal file
@ -0,0 +1,3 @@
|
||||
This file copied into the container along with environment.yml* from the parent
|
||||
folder. This file is included to prevents the Dockerfile COPY instruction from
|
||||
failing if no environment.yml is found.
|
11
.devcontainer/scripts/install-dev-tools.sh
Normal file
11
.devcontainer/scripts/install-dev-tools.sh
Normal file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
# Run this command from the PyTorch directory after cloning the source code using the “Get the PyTorch Source“ section below
|
||||
pip install -r requirements.txt
|
||||
git submodule sync
|
||||
git submodule update --init --recursive
|
||||
|
||||
# This takes some time
|
||||
make setup_lint
|
||||
|
||||
# Add CMAKE_PREFIX_PATH to bashrc
|
||||
echo 'export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}' >> ~/.bashrc
|
38
.devcontainer/scripts/update_alternatives_clang.sh
Executable file
38
.devcontainer/scripts/update_alternatives_clang.sh
Executable file
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
# update_alternatives_clang.sh
|
||||
# chmod u+x update_alternatives_clang.sh
|
||||
#
|
||||
|
||||
update_alternatives() {
|
||||
local version=${1}
|
||||
local priority=${2}
|
||||
local z=${3}
|
||||
local slaves=${4}
|
||||
local path=${5}
|
||||
local cmdln
|
||||
|
||||
cmdln="--verbose --install ${path}${master} ${master} ${path}${master}-${version} ${priority}"
|
||||
for slave in ${slaves}; do
|
||||
cmdln="${cmdln} --slave ${path}${slave} ${slave} ${path}${slave}-${version}"
|
||||
done
|
||||
sudo update-alternatives ${cmdln}
|
||||
}
|
||||
|
||||
if [[ ${#} -ne 2 ]]; then
|
||||
echo usage: "${0}" clang_version priority
|
||||
exit 1
|
||||
fi
|
||||
|
||||
version=${1}
|
||||
priority=${2}
|
||||
path="/usr/bin/"
|
||||
|
||||
master="llvm-config"
|
||||
slaves="llvm-addr2line llvm-ar llvm-as llvm-bcanalyzer llvm-bitcode-strip llvm-cat llvm-cfi-verify llvm-cov llvm-c-test llvm-cvtres llvm-cxxdump llvm-cxxfilt llvm-cxxmap llvm-debuginfod llvm-debuginfod-find llvm-diff llvm-dis llvm-dlltool llvm-dwarfdump llvm-dwarfutil llvm-dwp llvm-exegesis llvm-extract llvm-gsymutil llvm-ifs llvm-install-name-tool llvm-jitlink llvm-jitlink-executor llvm-lib llvm-libtool-darwin llvm-link llvm-lipo llvm-lto llvm-lto2 llvm-mc llvm-mca llvm-ml llvm-modextract llvm-mt llvm-nm llvm-objcopy llvm-objdump llvm-omp-device-info llvm-opt-report llvm-otool llvm-pdbutil llvm-PerfectShuffle llvm-profdata llvm-profgen llvm-ranlib llvm-rc llvm-readelf llvm-readobj llvm-reduce llvm-remark-size-diff llvm-rtdyld llvm-sim llvm-size llvm-split llvm-stress llvm-strings llvm-strip llvm-symbolizer llvm-tapi-diff llvm-tblgen llvm-tli-checker llvm-undname llvm-windres llvm-xray"
|
||||
|
||||
update_alternatives "${version}" "${priority}" "${master}" "${slaves}" "${path}"
|
||||
|
||||
master="clang"
|
||||
slaves="analyze-build asan_symbolize bugpoint c-index-test clang++ clang-apply-replacements clang-change-namespace clang-check clang-cl clang-cpp clangd clang-doc clang-extdef-mapping clang-format clang-format-diff clang-include-fixer clang-linker-wrapper clang-move clang-nvlink-wrapper clang-offload-bundler clang-offload-packager clang-offload-wrapper clang-pseudo clang-query clang-refactor clang-rename clang-reorder-fields clang-repl clang-scan-deps clang-tidy count diagtool dsymutil FileCheck find-all-symbols git-clang-format hmaptool hwasan_symbolize intercept-build ld64.lld ld.lld llc lld lldb lldb-argdumper lldb-instr lldb-server lldb-vscode lld-link lli lli-child-target modularize not obj2yaml opt pp-trace run-clang-tidy sancov sanstats scan-build scan-build-py scan-view split-file UnicodeNameMappingGenerator verify-uselistorder wasm-ld yaml2obj yaml-bench"
|
||||
|
||||
update_alternatives "${version}" "${priority}" "${master}" "${slaves}" "${path}"
|
Reference in New Issue
Block a user