Skip to content

Commit 9306f8d

Browse files
[Diffusion] Add support for diffusion models (flagos-ai#767)
1) Implement DiffusionEngine, Adapter, Hook and Transform 2) Add a simple LogIOTransform 3) Add example openjourney --------- Co-authored-by: Yupu Feng <ypfeng@baai.ac.cn> Co-authored-by: you-and-you <1823382186@qq.com>
1 parent 59e6b40 commit 9306f8d

21 files changed

Lines changed: 1255 additions & 52 deletions

.github/workflows/all-tests-nvidia.yml

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
run: |
2626
echo "ci_image=localhost:5000/flagscale:cuda12.8.1-cudnn9.7.1-python3.12-torch2.7.0-time2507111538" >> $GITHUB_OUTPUT # Set output variable
2727
28-
# Megatron Unit Tests with Matrix
29-
megatron-unit-tests:
28+
# Train Megatron Unit Tests with Matrix
29+
unit_tests_train_megatron:
3030
needs:
3131
- set-env
3232
uses: ./.github/workflows/unit-tests-nvidia.yml
@@ -47,34 +47,51 @@ jobs:
4747
- transformer/moe
4848
- transformer
4949
- ./
50-
name: "megatron-${{ matrix.subset == './' && 'root' || matrix.subset }}"
50+
name: "train_megatron-${{ matrix.subset == './' && 'root' || matrix.subset }}"
5151
with:
52-
backend: megatron
52+
backend: train_megatron
5353
subset: ${{ matrix.subset }}
5454
image: ${{ needs.set-env.outputs.ci_image }}
5555

56-
# Flagscale Unit Tests with Matrix
57-
flagscale-unit-tests:
56+
# Train Flagscale Unit Tests with Matrix
57+
unit_tests_train_flagscale:
5858
needs:
5959
- set-env
60-
- megatron-unit-tests
60+
- unit_tests_train_megatron
6161
uses: ./.github/workflows/unit-tests-nvidia.yml
6262
strategy:
6363
matrix:
6464
subset:
6565
- runner
6666
- ./
67-
name: "flagscale-${{ matrix.subset == './' && 'root' || matrix.subset }}"
67+
name: "train_flagscale-${{ matrix.subset == './' && 'root' || matrix.subset }}"
6868
with:
69-
backend: flagscale
69+
backend: train_flagscale
70+
subset: ${{ matrix.subset }}
71+
image: ${{ needs.set-env.outputs.ci_image }}
72+
73+
# Inference Flagscale Unit Tests with Matrix
74+
unit_tests_inference_flagscale:
75+
needs:
76+
- set-env
77+
- unit_tests_train_flagscale
78+
uses: ./.github/workflows/unit-tests-nvidia.yml
79+
strategy:
80+
matrix:
81+
subset:
82+
- inference
83+
- transforms
84+
name: "inference_flagscale-${{ matrix.subset == './' && 'root' || matrix.subset }}"
85+
with:
86+
backend: inference_flagscale
7087
subset: ${{ matrix.subset }}
7188
image: ${{ needs.set-env.outputs.ci_image }}
7289

7390
# Functional Tests with Mision and Type Matrix
74-
functional-tests-train:
91+
functional_tests_train:
7592
needs:
7693
- set-env
77-
- flagscale-unit-tests
94+
- unit_tests_inference_flagscale
7895
uses: ./.github/workflows/functional-tests-nvidia.yml
7996
strategy:
8097
matrix:
@@ -89,10 +106,10 @@ jobs:
89106
type: train
90107
image: ${{ needs.set-env.outputs.ci_image }}
91108

92-
functional-tests-hetero:
109+
functional_tests_hetero:
93110
needs:
94111
- set-env
95-
- functional-tests-train
112+
- functional_tests_train
96113
# TODO: test need fix
97114
uses: ./.github/workflows/functional-tests-nvidia.yml
98115
strategy:
@@ -105,10 +122,10 @@ jobs:
105122
type: hetero_train
106123
image: ${{ needs.set-env.outputs.ci_image }}
107124

108-
functional-tests-inference:
125+
functional_tests_inference:
109126
needs:
110127
- set-env
111-
- functional-tests-hetero
128+
- functional_tests_hetero
112129
uses: ./.github/workflows/functional-tests-nvidia.yml
113130
strategy:
114131
matrix:
@@ -123,10 +140,10 @@ jobs:
123140
type: inference
124141
image: ${{ needs.set-env.outputs.ci_image }}
125142

126-
functional-tests-serve:
143+
functional_tests_serve:
127144
needs:
128145
- set-env
129-
- functional-tests-inference
146+
- functional_tests_inference
130147
uses: ./.github/workflows/functional-tests-nvidia.yml
131148
strategy:
132149
matrix:
@@ -139,10 +156,10 @@ jobs:
139156
type: serve
140157
image: ${{ needs.set-env.outputs.ci_image }}
141158

142-
functional-tests-rl:
159+
functional_tests_rl:
143160
needs:
144161
- set-env
145-
- functional-tests-serve
162+
- functional_tests_serve
146163
uses: ./.github/workflows/functional-tests-nvidia.yml
147164
strategy:
148165
matrix:
@@ -157,11 +174,12 @@ jobs:
157174
# Check All Tests
158175
all-tests:
159176
needs:
160-
- megatron-unit-tests
161-
- flagscale-unit-tests
162-
- functional-tests-train
163-
- functional-tests-hetero
164-
- functional-tests-inference
177+
- unit_tests_train_megatron
178+
- unit_tests_train_flagscale
179+
- unit_tests_inference_flagscale
180+
- functional_tests_train
181+
- functional_tests_hetero
182+
- functional_tests_inference
165183
- functional-tests-serve
166184
- functional-tests-rl
167185
runs-on: ubuntu-latest

.github/workflows/unit-tests-nvidia.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ jobs:
5353
pip install gitpython # TODO: Remove after updating the image
5454
5555
git config --global --add safe.directory /__w/FlagScale/FlagScale
56-
if [ "${{ inputs.backend }}" = "megatron" ] || [ "${{ inputs.backend }}" = "flagscale" ]; then
56+
if [ "${{ inputs.backend }}" = "train_megatron" ] || [ "${{ inputs.backend }}" = "train_flagscale" ]; then
5757
echo ""
5858
# PYTHONPATH=./:$PYTHONPATH pip install . --config-settings=backend="Megatron-LM" --verbose --no-build-isolation
59-
elif [ "${{ inputs.backend }}" = "vllm" ]; then
59+
elif [ "${{ inputs.backend }}" = "vllm" ] || [ "${{ inputs.backend }}" = "inference_flagscale" ]; then
6060
source /root/miniconda3/bin/activate flagscale-inference
6161
pip install scikit-build scikit-build-core
6262
pip install --no-build-isolation git+https://github.com/FlagOpen/FlagGems.git@release_v1.0.0
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
defaults:
2+
- _self_
3+
- inference: t2i
4+
5+
experiment:
6+
exp_name: openjourney
7+
exp_dir: outputs/${experiment.exp_name}
8+
model: prompthero/openjourney
9+
task:
10+
type: inference
11+
backend: vllm # TODO(yupu): Remove this restriction
12+
entrypoint: flagscale/inference/diffusion_entrypoint.py
13+
runner:
14+
hostfile: null
15+
cmds:
16+
before_start: source /root/miniconda3/bin/activate flagscale-inference
17+
envs:
18+
CUDA_VISIBLE_DEVICES: 0
19+
CUDA_DEVICE_MAX_CONNECTIONS: 1
20+
# Optionally, set HF_HOME and HF_ENDPOINT
21+
22+
action: run
23+
24+
hydra:
25+
run:
26+
dir: ${experiment.exp_dir}/hydra
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
engine:
2+
model_config:
3+
model: ${experiment.model}
4+
loader: diffusers
5+
engine_config:
6+
results_path: ${experiment.exp_dir}/results
7+
transformations:
8+
LogIOTransformation:
9+
log_level: "info"
10+
StateScopeTransformation:
11+
{}
12+
13+
generate:
14+
prompt: "retro serie of different cars with different colors and shapes, mdjrny-v4 style"
15+
width: 512
16+
height: 512
17+
num_inference_steps: 50
18+
guidance_scale: 7.0
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import argparse
2+
3+
from typing import Union
4+
5+
from omegaconf import DictConfig, ListConfig, OmegaConf
6+
7+
from flagscale.inference.inference_engine import InferenceEngine
8+
from flagscale.runner.utils import logger
9+
10+
11+
def parse_config() -> Union[DictConfig, ListConfig]:
12+
"""Parse the configuration file"""
13+
14+
parser = argparse.ArgumentParser()
15+
parser.add_argument(
16+
"--config-path", type=str, required=True, help="Path to the configuration YAML file"
17+
)
18+
args = parser.parse_args()
19+
20+
config = OmegaConf.load(args.config_path)
21+
22+
# TODO(yupu): Any checks?
23+
24+
return config
25+
26+
27+
def inference(cfg: DictConfig) -> None:
28+
"""Run the model inference
29+
30+
Args:
31+
cfg: The parsed configuration
32+
"""
33+
34+
engine = InferenceEngine(cfg.get("engine", {}))
35+
36+
generate_cfg = cfg.get("generate", {})
37+
outputs = engine.generate(**generate_cfg)
38+
39+
engine.save(outputs)
40+
41+
42+
if __name__ == "__main__":
43+
parsed_cfg = parse_config()
44+
assert isinstance(parsed_cfg, DictConfig) # To make pyright happy
45+
inference(parsed_cfg)
46+
logger.info("Inference model inference completed")

0 commit comments

Comments
 (0)