Skip to content

Commit 4519ad6

Browse files
authored
chore: add V1 flux tests (#742)
* make linter happy * add tests for qwen-image-edit-2509 * update * update * flux schnell test runnable * update the test score * make linter happy * add fp4 results * fix the test score * add tests for flux_dev * update the test score * add flux.1-krea * fix the krea tests * update * update * add kontext * update * fix kontext * update * add flux.1-depth * add flux-tools * finish flux tools * add more flux examples * update * update3 * update * update score * update * update
1 parent 5b9af2f commit 4519ad6

31 files changed

Lines changed: 1480 additions & 248 deletions

.github/workflows/pr-test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ jobs:
9292
source $(conda info --base)/etc/profile.d/conda.sh
9393
conda activate test_env || { echo "Failed to activate conda env"; exit 1; }
9494
which python
95-
pytest -s -x tests/flux/test_flux_examples.py
96-
pytest -s -x tests/v1/test_examples.py
95+
pytest -vv -x tests/flux/test_flux_examples.py
96+
pytest -vv -x tests/v1/test_examples.py
9797
python .github/workflows/run_all_tests.py
9898
- name: clean up
9999
if: always()

.github/workflows/run_all_tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import subprocess
22
from pathlib import Path
33

4+
from tqdm import tqdm
5+
46

57
def run_all_tests():
68
test_dir = Path("tests")
@@ -21,9 +23,9 @@ def run_all_tests():
2123
print(f" {test_file}")
2224

2325
failed_tests = []
24-
for test_file in test_files:
26+
for test_file in tqdm(test_files):
2527
print(f"Running {test_file} ...")
26-
result = subprocess.run(["pytest", "--reruns", "2", "--reruns-delay", "0", "-s", "-x", test_file])
28+
result = subprocess.run(["pytest", "--reruns", "2", "--reruns-delay", "0", "-vv", "-x", test_file])
2729
if result.returncode != 0:
2830
print(f"Test failed: {test_file}")
2931
failed_tests.append(test_file)

docker/Dockerfile

Lines changed: 0 additions & 64 deletions
This file was deleted.

docker/Dockerfile.torch27

Lines changed: 0 additions & 64 deletions
This file was deleted.

docker/Dockerfile.torch28

Lines changed: 0 additions & 64 deletions
This file was deleted.

examples/flux.1-fill-dev.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from nunchaku import NunchakuFluxTransformer2dModel
66
from nunchaku.utils import get_precision
77

8-
image = load_image("https://huggingface.co/mit-han-lab/svdq-int4-flux.1-fill-dev/resolve/main/example.png")
9-
mask = load_image("https://huggingface.co/mit-han-lab/svdq-int4-flux.1-fill-dev/resolve/main/mask.png")
8+
image = load_image("https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/cup.png")
9+
mask = load_image("https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/cup_mask.png")
1010

1111
precision = get_precision() # auto-detect your precision is 'int4' or 'fp4' based on your GPU
1212
transformer = NunchakuFluxTransformer2dModel.from_pretrained(
@@ -16,7 +16,7 @@
1616
"black-forest-labs/FLUX.1-Fill-dev", transformer=transformer, torch_dtype=torch.bfloat16
1717
).to("cuda")
1818
image = pipe(
19-
prompt="A wooden basket of a cat.",
19+
prompt="a white paper cup",
2020
image=image,
2121
mask_image=mask,
2222
height=1024,

examples/v1/flux.1-canny-dev.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import torch
2+
from controlnet_aux import CannyDetector
3+
from diffusers import FluxControlPipeline
4+
from diffusers.utils import load_image
5+
6+
from nunchaku import NunchakuFluxTransformer2DModelV2
7+
from nunchaku.utils import get_precision
8+
9+
precision = get_precision() # auto-detect your precision is 'int4' or 'fp4' based on your GPU
10+
transformer = NunchakuFluxTransformer2DModelV2.from_pretrained(
11+
f"nunchaku-tech/nunchaku-flux.1-canny-dev/svdq-{precision}_r32-flux.1-canny-dev.safetensors"
12+
)
13+
pipe = FluxControlPipeline.from_pretrained(
14+
"black-forest-labs/FLUX.1-Canny-dev", transformer=transformer, torch_dtype=torch.bfloat16
15+
).to("cuda")
16+
17+
prompt = (
18+
"A robot made of exotic candies and chocolates of different kinds. "
19+
"The background is filled with confetti and celebratory gifts."
20+
)
21+
control_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png")
22+
23+
processor = CannyDetector()
24+
control_image = processor(
25+
control_image, low_threshold=50, high_threshold=200, detect_resolution=1024, image_resolution=1024
26+
)
27+
28+
image = pipe(
29+
prompt=prompt, control_image=control_image, height=1024, width=1024, num_inference_steps=20, guidance_scale=30.0
30+
).images[0]
31+
image.save(f"flux.1-canny-dev-{precision}.png")

examples/v1/flux.1-depth-dev.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import torch
2+
from diffusers import FluxControlPipeline
3+
from diffusers.utils import load_image
4+
from image_gen_aux import DepthPreprocessor
5+
6+
from nunchaku import NunchakuFluxTransformer2DModelV2
7+
from nunchaku.utils import get_precision
8+
9+
precision = get_precision() # auto-detect your precision is 'int4' or 'fp4' based on your GPU
10+
transformer = NunchakuFluxTransformer2DModelV2.from_pretrained(
11+
f"nunchaku-tech/nunchaku-flux.1-depth-dev/svdq-{precision}_r32-flux.1-depth-dev.safetensors"
12+
)
13+
14+
pipe = FluxControlPipeline.from_pretrained(
15+
"black-forest-labs/FLUX.1-Depth-dev",
16+
transformer=transformer,
17+
torch_dtype=torch.bfloat16,
18+
).to("cuda")
19+
20+
prompt = (
21+
"A robot made of exotic candies and chocolates of different kinds. "
22+
"The background is filled with confetti and celebratory gifts."
23+
)
24+
control_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png")
25+
26+
processor = DepthPreprocessor.from_pretrained("LiheYoung/depth-anything-large-hf")
27+
control_image = processor(control_image)[0].convert("RGB")
28+
29+
image = pipe(
30+
prompt=prompt, control_image=control_image, height=1024, width=1024, num_inference_steps=20, guidance_scale=10.0
31+
).images[0]
32+
image.save(f"flux.1-depth-dev-{precision}.png")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
pipeline = FluxPipeline.from_pretrained(
1212
"black-forest-labs/FLUX.1-dev", transformer=transformer, torch_dtype=torch.bfloat16
1313
).to("cuda")
14-
image = pipeline("A cat holding a sign that says hello world", num_inference_steps=50, guidance_scale=3.5).images[0]
14+
image = pipeline("A cat holding a sign that says hello world", num_inference_steps=20, guidance_scale=3.5).images[0]
1515
image.save(f"flux.1-dev-{precision}.png")

0 commit comments

Comments
 (0)