Skip to content

Commit f1cd1ae

Browse files
committed
add flux docker build
1 parent 722a3fd commit f1cd1ae

File tree

8 files changed

+97
-2
lines changed

8 files changed

+97
-2
lines changed

.ci/docker/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,14 @@ It also uses the same directory structure as PyTorch.
2020
# Build a specific image
2121
./build.sh torchtitan-ubuntu-20.04-clang12 -t myimage:latest
2222
```
23+
24+
### Flux Docker Image
25+
26+
For flux model development, a dedicated Docker image is available that includes the necessary dependencies (transformers, einops, sentencepiece). This image is built automatically when changes are made to the flux code.
27+
28+
To build the flux Docker image manually:
29+
30+
```bash
31+
cd .ci/docker
32+
docker build -f ubuntu/Dockerfile.flux -t torchtitan-flux-ubuntu-20.04-clang12 .
33+
```

.ci/docker/build.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ docker build \
3636
--build-arg "MINICONDA_VERSION=${MINICONDA_VERSION}" \
3737
--shm-size=1g \
3838
-f "${OS}"/Dockerfile \
39-
"$@" \
4039
.
File renamed without changes.

.ci/docker/ubuntu/Dockerfile.flux

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM 308535385114.dkr.ecr.us-east-1.amazonaws.com/torchtitan/torchtitan-ubuntu-20.04-clang12:latest
2+
3+
# Install flux dependencies
4+
COPY flux-requirements.txt /opt/conda/
5+
RUN . /opt/conda/bin/activate py_${PYTHON_VERSION} && \
6+
pip install -r /opt/conda/flux-requirements.txt && \
7+
rm /opt/conda/flux-requirements.txt
8+
9+
USER ci-user
10+
CMD ["bash"]
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: flux-docker-builds
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
paths:
7+
- .ci/docker/**
8+
- .github/workflows/flux-docker-builds.yml
9+
push:
10+
branches:
11+
- main
12+
- release/*
13+
paths:
14+
- - .ci/docker/**
15+
- .github/workflows/flux-docker-builds.yml
16+
schedule:
17+
- cron: 1 4 * * 3 # Run at 4:01 AM UTC on Wednesdays
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
flux-docker-build:
25+
runs-on: [self-hosted, linux.2xlarge]
26+
timeout-minutes: 240
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
include:
31+
- docker-image-name: torchtitan-flux-ubuntu-20.04-clang12
32+
base-image-name: torchtitan-ubuntu-20.04-clang12
33+
env:
34+
DOCKER_IMAGE: 308535385114.dkr.ecr.us-east-1.amazonaws.com/torchtitan/${{ matrix.docker-image-name }}
35+
steps:
36+
- name: Clean workspace
37+
shell: bash
38+
run: |
39+
echo "${GITHUB_WORKSPACE}"
40+
sudo rm -rf "${GITHUB_WORKSPACE}"
41+
mkdir "${GITHUB_WORKSPACE}"
42+
43+
- name: Setup SSH (Click me for login details)
44+
uses: pytorch/test-infra/.github/actions/setup-ssh@main
45+
with:
46+
github-secret: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Checkout the repo
49+
uses: actions/checkout@v3
50+
51+
- name: Setup Linux
52+
uses: pytorch/test-infra/.github/actions/setup-linux@main
53+
54+
- name: Build flux docker image
55+
id: build-docker-image
56+
run: |
57+
cd .ci/docker
58+
docker build \
59+
--no-cache \
60+
--progress=plain \
61+
-f ubuntu/Dockerfile.flux \
62+
-t 308535385114.dkr.ecr.us-east-1.amazonaws.com/torchtitan/${{ matrix.docker-image-name }}:latest \
63+
.
64+
docker push 308535385114.dkr.ecr.us-east-1.amazonaws.com/torchtitan/${{ matrix.docker-image-name }}:latest
65+
66+
- name: Teardown Linux
67+
uses: pytorch/test-infra/.github/actions/teardown-linux@main
68+
if: always()

torchtitan/experiments/flux/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
## Overview
44
This directory contains the implementation of the [FLUX](https://github.com/black-forest-labs/flux/tree/main) model in torchtitan. In torchtitan, we showcase the pre-training process of text-to-image part of the FLUX model.
55

6+
## Prerequisites
7+
Install the required dependencies:
8+
```bash
9+
pip install -r flux-requirements.txt
10+
```
11+
612
## Usage
713
First, download the autoencoder model from HuggingFace with your own access token:
814
```bash

torchtitan/experiments/flux/dataset/flux_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _process_cc12m_image(
6060
resized_img = resized_img.convert("RGB")
6161

6262
np_img = np.array(resized_img).transpose((2, 0, 1))
63-
tensor_img = torch.tensor(np_img).float() / 255.0
63+
tensor_img = torch.tensor(np_img).float() / 255.0 * 2.0 - 1.0
6464

6565
# NOTE: The following commented code is an alternative way
6666
# img_transform = transforms.Compose(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.ci/docker/flux-requirements.txt

0 commit comments

Comments
 (0)