dockerfile

vim Dockerfile

FROM ubuntu:jammy

RUN /usr/bin/apt-get clean && \
/usr/bin/apt update -y && \
/usr/bin/apt-get install -y python3 curl build-essential python3.10-dev git vim && \
curl -sSL https://bootstrap.pypa.io/get-pip.py | python3.10 - && \
python3 -m pip install torch==2.4.0 transformers==4.45.2 datasets==3.2.0 accelerate==1.2.1 peft==0.12.0 trl==0.9.6 && \
curl -o cuda-keyring_1.1-1_all.deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb && \
/usr/bin/dpkg -i cuda-keyring_1.1-1_all.deb && \
/usr/bin/apt update -y && /usr/bin/apt install -y cuda-toolkit-12-1 libcudnn9-cuda-12 libcudnn9-dev-cuda-12 && \
rm -rf cuda-keyring_1.1-1_all.deb && \
python3 -m pip install deepspeed==0.14.4 bitsandbytes==0.43.1 vllm==0.6.6 flash-attn==2.7.3 && \
cd /root/ && \
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git && \
cd LLaMA-Factory && \
pip install -e ".[torch,metrics]" && \
pip install --upgrade huggingface_hub && \
pip cache purge && \
/usr/bin/apt-get clean && \
/usr/bin/apt-get autoclean && \
/usr/bin/apt-get autoremove

构建镜像

docker build -t ubuntu:llama-factory-v1.0.0 .

运行镜像

docker run --shm-size 8g --name ubuntu -itd --gpus all ubuntu:llama-factory-v1.0.0 

注意

宿主机要安装 英伟达驱动和cuda。

参考链接