赞
踩
#### 自定义dockerfile
自定义安装,主要是为了在docker中使用conda虚拟环境。
FROM nvcr.io/nvidia/pytorch:23.11-py3
LABEL maintainer=“transformers”
ARG DEBIAN_FRONTEND=noninteractive
ARG PYTORCH=‘2.1.0’
cu102
, cu113
, etc.ARG CUDA=‘cu121’
RUN apt-get update &&
apt-get install -y libaio-dev wget bzip2 ca-certificates curl git git-lfs unzip mlocate usbutils
vim tmux g++ gcc build-essential cmake checkinstall lsb-release &&
rm -rf /var/lib/apt/lists/* &&
apt-get clean
RUN python3 -m pip uninstall -y torch torchvision torchaudio torch-tensorrt transformer-engine apex
SHELL [“/bin/bash”, “–login”, “-c”]
RUN cd / && wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /miniconda.sh &&
/bin/bash /miniconda.sh -b -p /opt/conda &&
ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh &&
echo “. /opt/conda/etc/profile.d/conda.sh” >> ~/.bashrc &&
/bin/bash -c “source ~/.bashrc” &&
/opt/conda/bin/conda update -n base -c defaults conda -y &&
/opt/conda/bin/conda config --set ssl_verify no &&
/opt/conda/bin/conda config --add channels conda-forge &&
/opt/conda/bin/conda create -n ai python=3.10
ENV PATH $PATH:/opt/conda/envs/ai/bin
RUN conda init bash &&
echo “conda activate ai” >> ~/.bashrc &&
conda activate ai &&
pip install --upgrade pip -i https://mirror.baidu.com/pypi/simple &&\
pip config set global.index-url https://mirror.baidu.com/pypi/simple &&\
pip install --no-cache-dir -U torch==$PYTORCH torchvision torchaudio \
--extra-index-url https://download.pytorch.org/whl/$CUDA &&\
pip install -U numpy opencv-python onnx onnxoptimizer onnxruntime -i https://mirror.baidu.com/pypi/simple
ARG REF=main
RUN conda activate ai &&
cd &&
git clone https://github.com/huggingface/transformers && cd transformers && git checkout $REF &&
cd … &&
pip install --no-cache-dir ./transformers[deepspeed-testing] &&
pip install --no-cache-dir git+https://github.com/huggingface/accelerate@main#egg=accelerate &&\
# pip uninstall -y apex &&\
MAX_JOBS=1
disables parallel building to avoid cpu memory OOM when building image on GitHub Action (standard) runnerspip uninstall -y deepspeed
RUN DS_BUILD_CPU_ADAM=1 DS_BUILD_FUSED_ADAM=1
RUN conda activate ai &&
pip install deepspeed --global-option=“build_ext”
–global-option=“-j8” --no-cache -v --disable-pip-version-check 2>&1
transformers
is not recognized as a package.RUN conda activate ai &&
cd &&
cd transformers && python3 setup.py develop
pydantic==1.8.2
which is not working - i.e. the next command failsRUN conda activate ai &&
pip install -U --no-cache-dir “pydantic<2”
RUN conda activate ai &&
python3 -c “from deepspeed.launcher.runner import main”
RUN apt-get update &&
rm -rf /var/lib/apt/lists/* &&
apt-get clean
### 缓存设置
预训练模型会被下载并本地缓存到 `~/.cache/huggingface/hub`。这是由环境变量 `TRANSFORMERS_CACHE` 指定的默认目录。在 Windows 上,默认目录为 `C:\Users\username\.cache\huggingface\hub`。你可以按照不同优先级改变下述环境变量,以指定不同的缓存目录。
1. 环境变量(默认): `HUGGINGFACE_HUB_CACHE` 或 `TRANSFORMERS_CACHE`。
2. 环境变量 `HF_HOME`。
3. 环境变量 `XDG_CACHE_HOME` + `/huggingface`。
除非你明确指定了环境变量 `TRANSFORMERS_CACHE`,声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/654844
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。