Skip to content

Commit

Permalink
Add build files
Browse files Browse the repository at this point in the history
  • Loading branch information
robballantyne committed Mar 7, 2024
1 parent 2b1518f commit bafcdba
Show file tree
Hide file tree
Showing 30 changed files with 748 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: [ai-dock, robballantyne]
Binary file added .github/images/api-schema-image2image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/api-schema-rawworkflow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/api-schema-text2image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/api1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/runpod-template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/serviceportal-links.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/serviceportal-logs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/serviceportal-processes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions .github/workflows/clear-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# https://stackoverflow.com/a/73556714
name: Clear Cache

on:
workflow_dispatch:

permissions:
actions: write

jobs:
clear-cache:
runs-on: ubuntu-latest
steps:
- name: Clear cache
uses: actions/github-script@v6
with:
script: |
console.log("About to clear")
const response = await github.rest.actions.getActionsCacheList({
owner: context.repo.owner,
repo: context.repo.repo,
page: 1,
per_page: 100
});
const pages = (function() {
if (typeof response.headers.link !== 'undefined') {
return response.headers.link.split(">").slice(-2)[0].split('=').slice(-1)[0]
}
return 1;
})();
console.log("Total pages: " + pages);
for (let page = pages; page >= 1; page--) {
console.log("Processing page " + page)
const response = await github.rest.actions.getActionsCacheList({
owner: context.repo.owner,
repo: context.repo.repo,
page: page,
per_page: 100
});
for (const cache of response.data.actions_caches) {
console.log(cache)
github.rest.actions.deleteActionsCacheById({
owner: context.repo.owner,
repo: context.repo.repo,
cache_id: cache.id,
})
}
}
console.log("Clear completed")
110 changes: 110 additions & 0 deletions .github/workflows/delete-old-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Delete Old Packages

env:
PER_PAGE: 100

on:
workflow_dispatch:
inputs:
age:
type: choice
required: true
description: Delete older than
options:
- 1 Hour
- 12 Hours
- 1 Day
- 1 Week
- 2 Weeks
- 1 Month
- 6 Months
- 1 Year
- 2 Years
- 3 Years
- 4 Years
- 5 Years
- All Packages

jobs:
delete-old-packages:
runs-on: ubuntu-latest
steps:
-
run: |
echo "PACKAGE_NAME=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
echo "OWNER=orgs/${GITHUB_REPOSITORY_OWNER,,}" >> ${GITHUB_ENV}
-
uses: actions/github-script@v6
with:
github-token: ${{ secrets.DELETE_PACKAGES_TOKEN }}
script: |
const delete_age = (function() {
switch ("${{ github.event.inputs.age }}") {
case "All Packages":
return 0;
case "1 Hour":
return 60;
case "12 Hours":
return 720;
case "1 Day":
return 1440;
case "1 Week":
return 10080;
case "2 Weeks":
return 20160;
case "1 Month":
return 43800;
case "6 Months":
return 262800;
case "1 Year":
return 525600;
case "2 Years":
return 525600 * 2;
case "3 Years":
return 525600 * 3;
case "4 Years":
return 525600 * 4;
case "5 Years":
return 525600 * 5;
default:
return 157680000;
}
})();
const now = new Date();
const epoch_minutes = Math.round(now.getTime() / 1000 / 60);
const response = await github.request("GET /${{ env.OWNER }}/packages/container/${{ github.event.repository.name }}/versions",
{ per_page: ${{ env.PER_PAGE }}
});
const pages = (function() {
if (typeof response.headers.link !== 'undefined') {
return response.headers.link.split(">").slice(-2)[0].split('=').slice(-1)[0]
}
return 1;
})();
console.log("Total pages: " + pages);
for (let page = pages; page >= 1; page--) {
console.log("Processing page " + page)
const response = await github.request("GET /${{ env.OWNER }}/packages/container/${{ github.event.repository.name }}/versions",
{
per_page: ${{ env.PER_PAGE }},
page: page
});
console.log("Deleting packages updated more than " + delete_age + " minutes ago...")
for (version of response.data) {
let updated_at = new Date(version.updated_at)
let minutes_old = epoch_minutes - Math.round(updated_at.getTime() / 1000 / 60);
console.log("Package is " + minutes_old + " minutes old")
if (minutes_old > delete_age) {
console.log("delete " + version.id)
const deleteResponse = await github.request("DELETE /${{ env.OWNER }}/packages/container/${{ github.event.repository.name }}/versions/" + version.id, { });
console.log("status " + deleteResponse.status)
}
}
}
56 changes: 56 additions & 0 deletions .github/workflows/delete-untagged-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Delete Untagged Packages

env:
PER_PAGE: 100

on:
workflow_dispatch:
workflow_run:
workflows: ["Docker Build"]
types:
- completed

jobs:
delete-untagged:
runs-on: ubuntu-latest
steps:
-
run: |
echo "PACKAGE_NAME=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
echo "OWNER=orgs/${GITHUB_REPOSITORY_OWNER,,}" >> ${GITHUB_ENV}
-
uses: actions/github-script@v6
with:
github-token: ${{ secrets.DELETE_PACKAGES_TOKEN }}
script: |
const response = await github.request("GET /${{ env.OWNER }}/packages/container/${{ github.event.repository.name }}/versions",
{ per_page: ${{ env.PER_PAGE }}
});
const pages = (function() {
if (typeof response.headers.link !== 'undefined') {
return response.headers.link.split(">").slice(-2)[0].split('=').slice(-1)[0]
}
return 1;
})();
console.log("Total pages: " + pages);
for (let page = pages; page >= 1; page--) {
console.log("Processing page " + page)
const response = await github.request("GET /${{ env.OWNER }}/packages/container/${{ github.event.repository.name }}/versions",
{
per_page: ${{ env.PER_PAGE }},
page: page
});
for (version of response.data) {
if (version.metadata.container.tags.length == 0) {
console.log("delete " + version.id)
const deleteResponse = await github.request("DELETE /${{ env.OWNER }}/packages/container/${{ github.event.repository.name }}/versions/" + version.id, { });
console.log("status " + deleteResponse.status)
}
}
}
86 changes: 86 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Docker Build

on:
workflow_dispatch:
push:
branches: [ "main" ]

env:
UBUNTU_VERSION: 22.04
BUILDX_NO_DEFAULT_ATTESTATIONS: 1
# Conservative defaults for cloud providers
LATEST_CUDA: "pytorch-2.1.2-py3.10-cuda-11.8.0-runtime-22.04"

jobs:
nvidia-base:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
base:
- "linux-desktop"
python:
- "3.10"
pytorch:
- "2.1.2"
- "2.2.0"
cuda:
- "11.8.0"
- "12.1.0"
level:
- "runtime"
steps:
-
name: Free Space
run: |
df -h
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/.ghcup
sudo rm -rf /usr/local/share/boost
sudo rm -rf /usr/local/lib/android
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
df -h
-
name: Env Setter
run: |
echo "PACKAGE_NAME=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
-
name: Checkout
uses: actions/checkout@v3
-
name: Permissions fixes
run: |
reponame="$(basename ${GITHUB_REPOSITORY})"
target="${HOME}/work/${reponame}/${reponame}/build/COPY*"
chmod -R ug+rwX ${target}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Set tags
run: |
img_path="ghcr.io/${{ env.PACKAGE_NAME }}"
ver_tag="${{ matrix.base }}-${{ matrix.pytorch }}-py${{ matrix.python }}-cuda-${{ matrix.cuda }}-${{ matrix.level }}-${{ env.UBUNTU_VERSION }}"
if [[ $ver_tag == ${{ env.LATEST_CUDA }} ]]; then
TAGS="${img_path}:latest, ${img_path}:latest-cuda, ${img_path}:$ver_tag"
else
TAGS="${img_path}:$ver_tag"
fi
echo "TAGS=${TAGS}" >> ${GITHUB_ENV}
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: build
build-args: |
IMAGE_BASE=ghcr.io/ai-dock/linux-desktop:jupyter-pytorch-${{ matrix.pytorch }}-py${{ matrix.python }}-cuda-${{ matrix.cuda }}-${{ matrix.level }}-${{ env.UBUNTU_VERSION }}
PYTORCH_VERSION=${{ matrix.pytorch }}
push: true
provenance: false
tags: ${{ env.TAGS }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
workspace
*__pycache__
build/COPY_ROOT_EXTRA/
config/authorized_keys
config/rclone
tpdocs/
.env
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,38 @@ OneTrainer is described as a one-stop solution for all your stable diffusion tra
Some features:

**Supported models**: Stable Diffusion 1.5, 2.0, 2.1, SDXL, Würstchen-v2, Stable Cascade, PixArt-Alpha and inpainting models

**Model formats**: diffusers and ckpt models

**Training methods**: Full fine-tuning, LoRA, embeddings

**Masked Training**: Let the training focus on just certain parts of the samples.

**Automatic backups**: Fully back up your training progress regularly during training. This includes all information to seamlessly continue training.

**Image augmentation**: Apply random transforms such as rotation, brightness, contrast or saturation to each image sample to quickly create a more diverse dataset.

**Tensorboard**: A simple tensorboard integration to track the training progress.

**Multiple prompts per image**: Train the model on multiple different prompts per image sample.

**Noise Scheduler Rescaling:** From the paper Common Diffusion Noise Schedules and Sample Steps are Flawed

**EMA**: Train you own EMA model. Optionally keep EMA weights in CPU memory to reduce VRAM usage.

**Aspect Ratio Bucketing**: Automatically train on multiple aspect ratios at a time. Just select the target resolutions, buckets are created automatically.

**Multi Resolution Training**: Train multiple resolutions at the same time.

**Dataset Tooling**: Automatically caption your dataset using BLIP, BLIP2 and WD-1.4, or create masks for masked training using ClipSeg or Rembg.

**Model Tooling**: Convert between different model formats from a simple UI.

**Sampling UI**: Sample the model during training without switching to a different application.

**AlignProp**: A Reinforcement Learning method for diffusion networks from the paper


## Pre-built Images

Docker images are built automatically through a GitHub Actions workflow and hosted at the GitHub Container Registry.
Expand All @@ -58,17 +74,17 @@ Tags follow these patterns:
##### _CUDA_
- `:pytorch-[pytorch-version]-py[python-version]-cuda-[x.x.x]-base-[ubuntu-version]`

- `:latest-cuda` → `:pytorch-2.2.0-py3.10-cuda-11.8.0-base-22.04`
- `:latest-cuda` → `:pytorch-2.1.2-py3.10-cuda-11.8.0-base-22.04`

- `:latest-cuda-jupyter` → `:jupyter-pytorch-2.2.0-py3.10-cuda-11.8.0-base-22.04`
- `:latest-cuda-jupyter` → `:jupyter-pytorch-2.1.2-py3.10-cuda-11.8.0-base-22.04`

Browse [here](https://github.com/ai-dock/onetrainer/pkgs/container/onetrainer) for an image suitable for your target environment.

You can also [build from source](#building-images) by editing `.env` and running `docker compose build`.

Supported Python versions: `3.10`

Supported Pytorch versions: `2.1.2`
Supported Pytorch versions: `2.1.2`, `2.2.0`

Supported Platforms: `NVIDIA CUDA`

Expand Down
12 changes: 12 additions & 0 deletions build/COPY_ROOT/opt/ai-dock/bin/build/layer0/amd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/false

build_amd_main() {
build_amd_install_onetrainer
}

build_amd_install_onetrainer() {
# AMD not yet supported
exit 0
}

build_amd_main "$@"
Loading

0 comments on commit bafcdba

Please sign in to comment.