Skip to content

Commit b635e65

Browse files
authored
Merge branch 'main' into qwen-image-batch-size-mismatch
2 parents 3bae648 + a2583e5 commit b635e65

7 files changed

Lines changed: 501 additions & 1 deletion

File tree

.github/labeler.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# https://github.com/actions/labeler
2+
pipelines:
3+
- changed-files:
4+
- any-glob-to-any-file:
5+
- src/diffusers/pipelines/**
6+
7+
models:
8+
- changed-files:
9+
- any-glob-to-any-file:
10+
- src/diffusers/models/**
11+
12+
schedulers:
13+
- changed-files:
14+
- any-glob-to-any-file:
15+
- src/diffusers/schedulers/**
16+
17+
single-file:
18+
- changed-files:
19+
- any-glob-to-any-file:
20+
- src/diffusers/loaders/single_file.py
21+
- src/diffusers/loaders/single_file_model.py
22+
- src/diffusers/loaders/single_file_utils.py
23+
24+
ip-adapter:
25+
- changed-files:
26+
- any-glob-to-any-file:
27+
- src/diffusers/loaders/ip_adapter.py
28+
29+
lora:
30+
- changed-files:
31+
- any-glob-to-any-file:
32+
- src/diffusers/loaders/lora_base.py
33+
- src/diffusers/loaders/lora_conversion_utils.py
34+
- src/diffusers/loaders/lora_pipeline.py
35+
- src/diffusers/loaders/peft.py
36+
37+
loaders:
38+
- changed-files:
39+
- any-glob-to-any-file:
40+
- src/diffusers/loaders/textual_inversion.py
41+
- src/diffusers/loaders/transformer_flux.py
42+
- src/diffusers/loaders/transformer_sd3.py
43+
- src/diffusers/loaders/unet.py
44+
- src/diffusers/loaders/unet_loader_utils.py
45+
- src/diffusers/loaders/utils.py
46+
- src/diffusers/loaders/__init__.py
47+
48+
quantization:
49+
- changed-files:
50+
- any-glob-to-any-file:
51+
- src/diffusers/quantizers/**
52+
53+
hooks:
54+
- changed-files:
55+
- any-glob-to-any-file:
56+
- src/diffusers/hooks/**
57+
58+
guiders:
59+
- changed-files:
60+
- any-glob-to-any-file:
61+
- src/diffusers/guiders/**
62+
63+
modular-pipelines:
64+
- changed-files:
65+
- any-glob-to-any-file:
66+
- src/diffusers/modular_pipelines/**
67+
68+
experimental:
69+
- changed-files:
70+
- any-glob-to-any-file:
71+
- src/diffusers/experimental/**
72+
73+
documentation:
74+
- changed-files:
75+
- any-glob-to-any-file:
76+
- docs/**
77+
78+
tests:
79+
- changed-files:
80+
- any-glob-to-any-file:
81+
- tests/**
82+
83+
examples:
84+
- changed-files:
85+
- any-glob-to-any-file:
86+
- examples/**
87+
88+
CI:
89+
- changed-files:
90+
- any-glob-to-any-file:
91+
- .github/**
92+
93+
utils:
94+
- changed-files:
95+
- any-glob-to-any-file:
96+
- src/diffusers/utils/**
97+
- src/diffusers/commands/**
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Issue Labeler
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
permissions:
8+
contents: read
9+
issues: write
10+
11+
jobs:
12+
label:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
16+
- name: Install dependencies
17+
run: pip install huggingface_hub
18+
- name: Get labels from LLM
19+
id: get-labels
20+
env:
21+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
22+
ISSUE_TITLE: ${{ github.event.issue.title }}
23+
ISSUE_BODY: ${{ github.event.issue.body }}
24+
run: |
25+
LABELS=$(python utils/label_issues.py)
26+
echo "labels=$LABELS" >> "$GITHUB_OUTPUT"
27+
- name: Apply labels
28+
if: steps.get-labels.outputs.labels != ''
29+
env:
30+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
ISSUE_NUMBER: ${{ github.event.issue.number }}
32+
LABELS: ${{ steps.get-labels.outputs.labels }}
33+
run: |
34+
for label in $(echo "$LABELS" | python -c "import json,sys; print('\n'.join(json.load(sys.stdin)))"); do
35+
gh issue edit "$ISSUE_NUMBER" --add-label "$label"
36+
done

.github/workflows/pr_labeler.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: PR Labeler
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, synchronize, reopened]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
11+
jobs:
12+
label:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5
16+
with:
17+
sync-labels: true
18+
19+
missing-tests:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
23+
- name: Check for missing tests
24+
id: check
25+
env:
26+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
PR_NUMBER: ${{ github.event.pull_request.number }}
28+
REPO: ${{ github.repository }}
29+
run: |
30+
gh api --paginate "repos/${REPO}/pulls/${PR_NUMBER}/files" \
31+
| python utils/check_test_missing.py
32+
- name: Add or remove missing-tests label
33+
if: always()
34+
env:
35+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
PR_NUMBER: ${{ github.event.pull_request.number }}
37+
run: |
38+
if [ "${{ steps.check.outcome }}" = "failure" ]; then
39+
gh pr edit "$PR_NUMBER" --add-label "missing-tests"
40+
else
41+
gh pr edit "$PR_NUMBER" --remove-label "missing-tests" 2>/dev/null || true
42+
fi
43+
44+
size-label:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Label PR by diff size
48+
env:
49+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
PR_NUMBER: ${{ github.event.pull_request.number }}
51+
REPO: ${{ github.repository }}
52+
run: |
53+
DIFF_SIZE=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}" --jq '.additions + .deletions')
54+
for label in size/S size/M size/L; do
55+
gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "$label" 2>/dev/null || true
56+
done
57+
if [ "$DIFF_SIZE" -lt 50 ]; then
58+
gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "size/S"
59+
elif [ "$DIFF_SIZE" -lt 200 ]; then
60+
gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "size/M"
61+
else
62+
gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "size/L"
63+
fi

src/diffusers/models/transformers/transformer_glm_image.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,11 @@ class GlmImageTransformer2DModel(ModelMixin, ConfigMixin, PeftAdapterMixin, Cach
533533
"""
534534

535535
_supports_gradient_checkpointing = True
536+
_repeated_blocks = ["GlmImageTransformerBlock"]
536537
_no_split_modules = [
537538
"GlmImageTransformerBlock",
538539
"GlmImageImageProjector",
539-
"GlmImageImageProjector",
540+
"GlmImageCombinedTimestepSizeEmbeddings",
540541
]
541542
_skip_layerwise_casting_patterns = ["patch_embed", "norm", "proj_out"]
542543
_skip_keys = ["kv_caches"]
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# coding=utf-8
2+
# Copyright 2025 HuggingFace Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import torch
17+
18+
from diffusers import GlmImageTransformer2DModel
19+
from diffusers.utils.torch_utils import randn_tensor
20+
21+
from ...testing_utils import enable_full_determinism, torch_device
22+
from ..testing_utils import (
23+
BaseModelTesterConfig,
24+
ModelTesterMixin,
25+
TrainingTesterMixin,
26+
)
27+
28+
29+
enable_full_determinism()
30+
31+
32+
class GlmImageTransformerTesterConfig(BaseModelTesterConfig):
33+
@property
34+
def model_class(self):
35+
return GlmImageTransformer2DModel
36+
37+
@property
38+
def main_input_name(self) -> str:
39+
return "hidden_states"
40+
41+
@property
42+
def output_shape(self) -> tuple:
43+
return (4, 8, 8)
44+
45+
@property
46+
def input_shape(self) -> tuple:
47+
return (4, 8, 8)
48+
49+
@property
50+
def generator(self):
51+
return torch.Generator("cpu").manual_seed(0)
52+
53+
def get_init_dict(self) -> dict:
54+
return {
55+
"patch_size": 2,
56+
"in_channels": 4,
57+
"out_channels": 4,
58+
"num_layers": 1,
59+
"attention_head_dim": 8,
60+
"num_attention_heads": 2,
61+
"text_embed_dim": 32,
62+
"time_embed_dim": 16,
63+
"condition_dim": 8,
64+
"prior_vq_quantizer_codebook_size": 64,
65+
}
66+
67+
def get_dummy_inputs(self, batch_size: int = 1) -> dict[str, torch.Tensor]:
68+
num_channels = 4
69+
height = width = 8
70+
sequence_length = 12
71+
72+
return {
73+
"hidden_states": randn_tensor(
74+
(batch_size, num_channels, height, width), generator=self.generator, device=torch_device
75+
),
76+
"encoder_hidden_states": randn_tensor(
77+
(batch_size, sequence_length, 32), generator=self.generator, device=torch_device
78+
),
79+
"prior_token_id": torch.randint(0, 64, size=(batch_size,), generator=self.generator).to(torch_device),
80+
"prior_token_drop": torch.zeros(batch_size, dtype=torch.bool, device=torch_device),
81+
"timestep": torch.randint(0, 1000, size=(batch_size,), generator=self.generator).to(torch_device),
82+
"target_size": torch.tensor([[height, width]] * batch_size, dtype=torch.float32).to(torch_device),
83+
"crop_coords": torch.tensor([[0, 0]] * batch_size, dtype=torch.float32).to(torch_device),
84+
}
85+
86+
87+
class TestGlmImageTransformer(GlmImageTransformerTesterConfig, ModelTesterMixin):
88+
pass
89+
90+
91+
class TestGlmImageTransformerTraining(GlmImageTransformerTesterConfig, TrainingTesterMixin):
92+
def test_gradient_checkpointing_is_applied(self):
93+
expected_set = {"GlmImageTransformer2DModel"}
94+
super().test_gradient_checkpointing_is_applied(expected_set=expected_set)

utils/check_test_missing.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import ast
2+
import json
3+
import sys
4+
5+
6+
SRC_DIRS = ["src/diffusers/pipelines/", "src/diffusers/models/", "src/diffusers/schedulers/"]
7+
MIXIN_BASES = {"ModelMixin", "SchedulerMixin", "DiffusionPipeline"}
8+
9+
10+
def extract_classes_from_file(filepath: str) -> list[str]:
11+
with open(filepath) as f:
12+
tree = ast.parse(f.read())
13+
14+
classes = []
15+
for node in ast.walk(tree):
16+
if not isinstance(node, ast.ClassDef):
17+
continue
18+
base_names = set()
19+
for base in node.bases:
20+
if isinstance(base, ast.Name):
21+
base_names.add(base.id)
22+
elif isinstance(base, ast.Attribute):
23+
base_names.add(base.attr)
24+
if base_names & MIXIN_BASES:
25+
classes.append(node.name)
26+
27+
return classes
28+
29+
30+
def extract_imports_from_file(filepath: str) -> set[str]:
31+
with open(filepath) as f:
32+
tree = ast.parse(f.read())
33+
34+
names = set()
35+
for node in ast.walk(tree):
36+
if isinstance(node, ast.ImportFrom):
37+
for alias in node.names:
38+
names.add(alias.name)
39+
elif isinstance(node, ast.Import):
40+
for alias in node.names:
41+
names.add(alias.name.split(".")[-1])
42+
43+
return names
44+
45+
46+
def main():
47+
pr_files = json.load(sys.stdin)
48+
49+
new_classes = []
50+
for f in pr_files:
51+
if f["status"] != "added" or not f["filename"].endswith(".py"):
52+
continue
53+
if not any(f["filename"].startswith(d) for d in SRC_DIRS):
54+
continue
55+
try:
56+
new_classes.extend(extract_classes_from_file(f["filename"]))
57+
except (FileNotFoundError, SyntaxError):
58+
continue
59+
60+
if not new_classes:
61+
sys.exit(0)
62+
63+
new_test_files = [
64+
f["filename"]
65+
for f in pr_files
66+
if f["status"] == "added" and f["filename"].startswith("tests/") and f["filename"].endswith(".py")
67+
]
68+
69+
imported_names = set()
70+
for filepath in new_test_files:
71+
try:
72+
imported_names |= extract_imports_from_file(filepath)
73+
except (FileNotFoundError, SyntaxError):
74+
continue
75+
76+
untested = [cls for cls in new_classes if cls not in imported_names]
77+
78+
if untested:
79+
print(f"missing-tests: {', '.join(untested)}")
80+
sys.exit(1)
81+
else:
82+
sys.exit(0)
83+
84+
85+
if __name__ == "__main__":
86+
main()

0 commit comments

Comments
 (0)