diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85e7c1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8e40cc9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +# ROCm-enabled PyTorch base image from AMD +# Pick a tag that matches your installed ROCm driver best; this one is a good default. +FROM rocm/pytorch:rocm7.1.1_ubuntu22.04_py3.10_pytorch_release_2.9.1 + +# OCI metadata for discoverability +LABEL org.opencontainers.image.source="https://github.com/zuzupebbles/unsloth-rocm" +LABEL org.opencontainers.image.url="https://hub.docker.com/r/zuzupebbles/unsloth-rocm" +LABEL org.opencontainers.image.title="Unsloth ROCm image" +LABEL org.opencontainers.image.description="Unsloth + ROCm PyTorch for AMD GPUs (e.g. 7900 XTX)" +LABEL org.opencontainers.image.licenses="Apache-2.0" + +# Basic utilities +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + git wget curl vim nano && \ + rm -rf /var/lib/apt/lists/* + +# Upgrade pip and install Unsloth (AMD is supported via regular pip install) +# Unsloth itself is Apache-2.0 licensed. +RUN pip install --upgrade pip && \ + pip install --no-cache-dir unsloth + +# Optional: tools you’ll almost certainly want when experimenting +RUN pip install --no-cache-dir \ + "transformers>=4.45.0" \ + datasets \ + accelerate \ + peft \ + safetensors \ + bitsandbytes || true +# ^ bitsandbytes may be CUDA-only; failing here is fine, Unsloth on ROCm does not strictly need it. + +# Create a non-root user that matches your host UID/GID at runtime (set via docker-compose) +ARG USERNAME=unsloth +ARG UID=1000 +ARG GID=1000 +RUN groupadd -g ${GID} ${USERNAME} && \ + useradd -m -u ${UID} -g ${GID} -s /bin/bash ${USERNAME} + +USER ${USERNAME} +WORKDIR /workspace + +# Keep the container alive by default; you’ll exec into it +CMD ["bash"] diff --git a/README.md b/README.md index e69de29..1cf295c 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,100 @@ +# unsloth-rocm 🦥🔥 + +Unsloth + PyTorch-on-ROCm in a ready-to-use Docker image for AMD GPUs +(Navi / RDNA2 / RDNA3 – e.g. 7900 XTX). + +- Base image: [`rocm/pytorch`](https://hub.docker.com/r/rocm/pytorch) (PyTorch with ROCm backend) +- Fine-tuning framework: [Unsloth](https://github.com/unslothai/unsloth) (Apache-2.0). + +This repo contains: + +- `Dockerfile` – how the image is built +- `docker-compose.build.yml` – a sample compose file for local build + dev use + +The idea is to give ROCm users a “batteries-included” Unsloth container and a clean example of how to wire up devices / groups / HF cache. + +--- + +## Requirements + +On the host (e.g. Arch, Ubuntu, etc.): + +- AMD GPU supported by ROCm / `rocm/pytorch` (MI* or newer Navi, see AMD’s support matrix) +- ROCm stack installed and working (`rocminfo` sees your GPU) +- Docker or compatible container runtime +- User is in the appropriate groups, e.g.: + +```bash + sudo usermod -aG video,docker $USER + # log out & back in afterwards +``` + +You should also see `/dev/kfd` and `/dev/dri` on the host: + +```bash +ls /dev/kfd +ls /dev/dri +``` + +--- + +## Build locally + +Clone the repo (whichever remote you like – GitHub or your local Forgejo): + +```bash +git clone https://github.com/zuzupebbles/unsloth-rocm.git +cd unsloth-rocm +``` + +Build the image: + +```bash +# ensure UID/GID match your host user (especially on Arch) +export UID +export GID + +docker compose -f docker-compose.build.yml build +``` + +This will produce a local image named: + +```text +zuzupebbles/unsloth-rocm:local +``` + +You can confirm with: + +```bash +docker images | grep unsloth-rocm +``` + +--- + +## Run for local dev + +Bring up a dev container: + +```bash +docker compose -f docker-compose.build.yml up -d +docker compose -f docker-compose.build.yml exec unsloth-rocm bash +``` + +Inside the container you’ll have: + +* user: `unsloth` +* working dir: `/workspace` +* volumes mounted: + + * `./workspace` → `/workspace` + * `~/.cache/huggingface` → `/data/hf-cache` + * `./repos-clone` → `/repos-clone` + +Quick sanity check in the container: + +```bash +python -c "import torch; print(torch.cuda.is_available(), torch.version.cuda, torch.version.hip, torch.version.git_version)" +python -c "import unsloth; print(unsloth.__version__)" +``` + +(ROCm builds often report HIP instead of CUDA, that’s expected.) diff --git a/docker-compose.build.yml b/docker-compose.build.yml new file mode 100644 index 0000000..374de58 --- /dev/null +++ b/docker-compose.build.yml @@ -0,0 +1,52 @@ +services: + unsloth-rocm: + build: + context: . + dockerfile: Dockerfile + args: + UID: ${UID:-1000} + GID: ${GID:-1000} + + # Image name for local use; you can retag this for Docker Hub. + image: zuzupebbles/unsloth-rocm:local + + container_name: unsloth-rocm + restart: unless-stopped + + # ROCm device plumbing – basically AMD's recommended set. + devices: + - /dev/kfd + - /dev/dri + group_add: + - "video" # host group that has access to /dev/kfd and /dev/dri + # - "render" # optional, if your distro uses it + + cap_add: + - SYS_PTRACE + security_opt: + - seccomp=unconfined + ipc: host + shm_size: "16g" + + environment: + # If you only want GPU 0, set explicitly: + - ROCM_VISIBLE_DEVICES=0 + + # HF cache so you don't redownload models all the time + - HF_HOME=/data/hf-cache + - HUGGINGFACE_HUB_CACHE=/data/hf-cache + - TRANSFORMERS_CACHE=/data/hf-cache + + volumes: + # Workspace for notebooks / scripts + - ./workspace:/workspace + + # Hugging Face cache on host + - ~/.cache/huggingface:/data/hf-cache + + # Optional: local repo clones or model sources + - ./repos-clone:/repos-clone + + working_dir: /workspace + stdin_open: true + tty: true