Skip to content

Commit

Permalink
Add QLoRA
Browse files Browse the repository at this point in the history
  • Loading branch information
Liana64 committed Nov 22, 2024
1 parent 61bf154 commit 20bd6ae
Show file tree
Hide file tree
Showing 5 changed files with 382 additions and 0 deletions.
130 changes: 130 additions & 0 deletions .github/workflows/qlora.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Build and push QLoRA

on:
workflow_dispatch:
inputs:
image_tag:
description: "Tag for the image, e.g. qlora makes qlora-cpu, qlora-cu118, qlora-cu121, and qlora-cu124"
required: false
default: "boltz"

env:
REGISTRY: ghcr.io

jobs:
build-qlora-cpu:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Convert repository name to lowercase
run: echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: boltz/python3.11-slim
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.image_tag }}-cpu
build-args: BASE_IMAGE=python:3.11-slim
build-qlora-cuda118:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Convert repository name to lowercase
run: echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: boltz/11.8.0-cudnn8-runtime-ubuntu22.04
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.image_tag }}-cu118
build-args: BASE_IMAGE=nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
build-qlora-cuda121:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Convert repository name to lowercase
run: echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: boltz/12.1.0-cudnn8-runtime-ubuntu22.04
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.image_tag }}-cu121
build-args: BASE_IMAGE=nvidia/cuda:12.1.0-cudnn8-runtime-ubuntu22.04
build-qlora-cuda124:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Convert repository name to lowercase
run: echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: boltz/12.4.1-cudnn-runtime-ubuntu22.04
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.image_tag }}-cu124
build-args: BASE_IMAGE=nvidia/cuda:12.4.1-cudnn-runtime-ubuntu22.04
63 changes: 63 additions & 0 deletions qlora/11.8.0-cudnn8-runtime-ubuntu22.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Base image
# ----------------------
ARG PROJECT_NAME=qlora
ARG PROJECT_URL=https://github.com/artidoro/qlora
ARG BASE_IMAGE=nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
FROM ${BASE_IMAGE} AS builder

# Build
# ----------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
build-essential \
python3-venv \
&& python3 -m venv /opt/venv \
&& . /opt/venv/bin/activate \
&& git clone https://github.com/artidoro/qlora /app \
&& pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 \
&& pip install --no-cache-dir -r /app/requirements.txt \
&& apt-get purge -y git build-essential \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Metadata
# ----------------------
FROM ${BASE_IMAGE}

LABEL base_image=${BASE_IMAGE} \
software=${PROJECT_NAME} \
about.home=${PROJECT_URL} \
about.summary="QLoRA: Efficient Finetuning of Quantized LLMs" \
about.tags="Model" \
about.license="MIT" \
about.license_file="https://github.com/artidoro/qlora" \
version="1"

# Configuration
# ----------------------
ARG USERNAME=rare
ARG USER_UID=900
ARG USER_GID=900

ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=C.UTF-8
ENV PATH="/opt/venv/bin:$PATH"

# Installation
# ----------------------
RUN groupadd --gid $USER_GID $USERNAME && \
useradd --uid $USER_UID --gid $USER_GID --create-home --shell /bin/bash $USERNAME

COPY --from=builder --chown=$USER_UID:$USER_GID /opt/venv /opt/venv
COPY --from=builder --chown=$USER_UID:$USER_GID /app /app
COPY --from=builder --chown=$USER_UID:$USER_GID /app/LICENSE /app/LICENSE
COPY --from=builder --chown=$USER_UID:$USER_GID /app/README.md /app/README.md
COPY --from=builder --chown=$USER_UID:$USER_GID /app/docs /app/docs
COPY --from=builder --chown=$USER_UID:$USER_GID /app/examples /app/examples
COPY --from=builder --chown=$USER_UID:$USER_GID /app/scripts /app/scripts

WORKDIR /app
USER $USERNAME
ENTRYPOINT ["qlora"]
63 changes: 63 additions & 0 deletions qlora/12.1.0-cudnn8-runtime-ubuntu22.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Base image
# ----------------------
ARG PROJECT_NAME=qlora
ARG PROJECT_URL=https://github.com/artidoro/qlora
ARG BASE_IMAGE=nvidia/cuda:12.1.0-cudnn8-runtime-ubuntu22.04
FROM ${BASE_IMAGE} AS builder

# Build
# ----------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
build-essential \
python3-venv \
&& python3 -m venv /opt/venv \
&& . /opt/venv/bin/activate \
&& git clone https://github.com/artidoro/qlora /app \
&& pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 \
&& pip install --no-cache-dir -r /app/requirements.txt \
&& apt-get purge -y git build-essential \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Metadata
# ----------------------
FROM ${BASE_IMAGE}

LABEL base_image=${BASE_IMAGE} \
software=${PROJECT_NAME} \
about.home=${PROJECT_URL} \
about.summary="QLoRA: Efficient Finetuning of Quantized LLMs" \
about.tags="Model" \
about.license="MIT" \
about.license_file="https://github.com/artidoro/qlora" \
version="1"

# Configuration
# ----------------------
ARG USERNAME=rare
ARG USER_UID=900
ARG USER_GID=900

ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=C.UTF-8
ENV PATH="/opt/venv/bin:$PATH"

# Installation
# ----------------------
RUN groupadd --gid $USER_GID $USERNAME && \
useradd --uid $USER_UID --gid $USER_GID --create-home --shell /bin/bash $USERNAME

COPY --from=builder --chown=$USER_UID:$USER_GID /opt/venv /opt/venv
COPY --from=builder --chown=$USER_UID:$USER_GID /app /app
COPY --from=builder --chown=$USER_UID:$USER_GID /app/LICENSE /app/LICENSE
COPY --from=builder --chown=$USER_UID:$USER_GID /app/README.md /app/README.md
COPY --from=builder --chown=$USER_UID:$USER_GID /app/docs /app/docs
COPY --from=builder --chown=$USER_UID:$USER_GID /app/examples /app/examples
COPY --from=builder --chown=$USER_UID:$USER_GID /app/scripts /app/scripts

WORKDIR /app
USER $USERNAME
ENTRYPOINT ["qlora"]
63 changes: 63 additions & 0 deletions qlora/12.4.1-cudnn-runtime-ubuntu22.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Base image
# ----------------------
ARG PROJECT_NAME=qlora
ARG PROJECT_URL=https://github.com/artidoro/qlora
ARG BASE_IMAGE=nvidia/cuda:12.4.1-cudnn-runtime-ubuntu22.04
FROM ${BASE_IMAGE} AS builder

# Build
# ----------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
build-essential \
python3-venv \
&& python3 -m venv /opt/venv \
&& . /opt/venv/bin/activate \
&& git clone https://github.com/artidoro/qlora /app \
&& pip install --no-cache-dir --upgrade pip \
&& pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124 \
&& pip install --no-cache-dir -r /app/requirements.txt \
&& apt-get purge -y git build-essential \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Metadata
# ----------------------
FROM ${BASE_IMAGE}

LABEL base_image=${BASE_IMAGE} \
software=${PROJECT_NAME} \
about.home=${PROJECT_URL} \
about.summary="QLoRA: Efficient Finetuning of Quantized LLMs" \
about.tags="Model" \
about.license="MIT" \
about.license_file="https://github.com/artidoro/qlora" \
version="1"

# Configuration
# ----------------------
ARG USERNAME=rare
ARG USER_UID=900
ARG USER_GID=900

ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=C.UTF-8
ENV PATH="/opt/venv/bin:$PATH"

# Installation
# ----------------------
RUN groupadd --gid $USER_GID $USERNAME && \
useradd --uid $USER_UID --gid $USER_GID --create-home --shell /bin/bash $USERNAME

COPY --from=builder --chown=$USER_UID:$USER_GID /opt/venv /opt/venv
COPY --from=builder --chown=$USER_UID:$USER_GID /app /app
COPY --from=builder --chown=$USER_UID:$USER_GID /app/LICENSE /app/LICENSE
COPY --from=builder --chown=$USER_UID:$USER_GID /app/README.md /app/README.md
COPY --from=builder --chown=$USER_UID:$USER_GID /app/docs /app/docs
COPY --from=builder --chown=$USER_UID:$USER_GID /app/examples /app/examples
COPY --from=builder --chown=$USER_UID:$USER_GID /app/scripts /app/scripts

WORKDIR /app
USER $USERNAME
ENTRYPOINT ["qlora"]
63 changes: 63 additions & 0 deletions qlora/python3.11-slim/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Base image
# ----------------------
ARG PROJECT_NAME=qlora
ARG PROJECT_URL=https://github.com/artidoro/qlora
ARG BASE_IMAGE=python:3.11-slim
FROM ${BASE_IMAGE} AS builder

# Build
# ----------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
build-essential \
python3-venv \
&& python3 -m venv /opt/venv \
&& . /opt/venv/bin/activate \
&& git clone https://github.com/artidoro/qlora /app \
&& pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu \
&& pip install --no-cache-dir -r /app/requirements.txt \
&& apt-get purge -y git build-essential \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Metadata
# ----------------------
FROM ${BASE_IMAGE}

LABEL base_image=${BASE_IMAGE} \
software=${PROJECT_NAME} \
about.home=${PROJECT_URL} \
about.summary="QLoRA: Efficient Finetuning of Quantized LLMs" \
about.tags="Model" \
about.license="MIT" \
about.license_file="https://github.com/artidoro/qlora" \
version="1"

# Configuration
# ----------------------
ARG USERNAME=rare
ARG USER_UID=900
ARG USER_GID=900

ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=C.UTF-8
ENV PATH="/opt/venv/bin:$PATH"

# Installation
# ----------------------
RUN groupadd --gid $USER_GID $USERNAME && \
useradd --uid $USER_UID --gid $USER_GID --create-home --shell /bin/bash $USERNAME

COPY --from=builder --chown=$USER_UID:$USER_GID /opt/venv /opt/venv
COPY --from=builder --chown=$USER_UID:$USER_GID /app /app
COPY --from=builder --chown=$USER_UID:$USER_GID /app/LICENSE /app/LICENSE
COPY --from=builder --chown=$USER_UID:$USER_GID /app/README.md /app/README.md
COPY --from=builder --chown=$USER_UID:$USER_GID /app/docs /app/docs
COPY --from=builder --chown=$USER_UID:$USER_GID /app/examples /app/examples
COPY --from=builder --chown=$USER_UID:$USER_GID /app/scripts /app/scripts

WORKDIR /app
USER $USERNAME
ENTRYPOINT ["qlora"]

0 comments on commit 20bd6ae

Please sign in to comment.