Skip to content

Commit 2a7bb53

Browse files
authored
Revert "[tests] Changes to the torch.compile() CI and tests (#11508)"
This reverts commit 4af76d0.
1 parent 826f435 commit 2a7bb53

17 files changed

+498
-41
lines changed

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
runs-on:
2424
group: aws-g6-4xlarge-plus
2525
container:
26-
image: diffusers/diffusers-pytorch-cuda
26+
image: diffusers/diffusers-pytorch-compile-cuda
2727
options: --shm-size "16gb" --ipc host --gpus 0
2828
steps:
2929
- name: Checkout diffusers

.github/workflows/build_docker_images.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ jobs:
4141
run: |
4242
CHANGED_FILES="${{ steps.file_changes.outputs.all }}"
4343
for FILE in $CHANGED_FILES; do
44-
# skip anything that isn’t still on disk
45-
if [[ ! -f "$FILE" ]]; then
46-
echo "Skipping removed file $FILE"
47-
continue
48-
fi
49-
5044
if [[ "$FILE" == docker/*Dockerfile ]]; then
5145
DOCKER_PATH="${FILE%/Dockerfile}"
5246
DOCKER_TAG=$(basename "$DOCKER_PATH")
@@ -71,7 +65,7 @@ jobs:
7165
image-name:
7266
- diffusers-pytorch-cpu
7367
- diffusers-pytorch-cuda
74-
- diffusers-pytorch-cuda
68+
- diffusers-pytorch-compile-cuda
7569
- diffusers-pytorch-xformers-cuda
7670
- diffusers-pytorch-minimum-cuda
7771
- diffusers-flax-cpu

.github/workflows/nightly_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ jobs:
188188
group: aws-g4dn-2xlarge
189189

190190
container:
191-
image: diffusers/diffusers-pytorch-cuda
191+
image: diffusers/diffusers-pytorch-compile-cuda
192192
options: --gpus 0 --shm-size "16gb" --ipc host
193193

194194
steps:

.github/workflows/push_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ jobs:
262262
group: aws-g4dn-2xlarge
263263

264264
container:
265-
image: diffusers/diffusers-pytorch-cuda
265+
image: diffusers/diffusers-pytorch-compile-cuda
266266
options: --gpus 0 --shm-size "16gb" --ipc host
267267

268268
steps:

.github/workflows/release_tests_fast.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ jobs:
316316
group: aws-g4dn-2xlarge
317317

318318
container:
319-
image: diffusers/diffusers-pytorch-cuda
319+
image: diffusers/diffusers-pytorch-compile-cuda
320320
options: --gpus 0 --shm-size "16gb" --ipc host
321321

322322
steps:
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
FROM nvidia/cuda:12.1.0-runtime-ubuntu20.04
2+
LABEL maintainer="Hugging Face"
3+
LABEL repository="diffusers"
4+
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
RUN apt-get -y update \
8+
&& apt-get install -y software-properties-common \
9+
&& add-apt-repository ppa:deadsnakes/ppa
10+
11+
RUN apt install -y bash \
12+
build-essential \
13+
git \
14+
git-lfs \
15+
curl \
16+
ca-certificates \
17+
libsndfile1-dev \
18+
libgl1 \
19+
python3.10 \
20+
python3.10-dev \
21+
python3-pip \
22+
python3.10-venv && \
23+
rm -rf /var/lib/apt/lists
24+
25+
# make sure to use venv
26+
RUN python3.10 -m venv /opt/venv
27+
ENV PATH="/opt/venv/bin:$PATH"
28+
29+
# pre-install the heavy dependencies (these can later be overridden by the deps from setup.py)
30+
RUN python3.10 -m pip install --no-cache-dir --upgrade pip uv==0.1.11 && \
31+
python3.10 -m uv pip install --no-cache-dir \
32+
torch \
33+
torchvision \
34+
torchaudio \
35+
invisible_watermark && \
36+
python3.10 -m pip install --no-cache-dir \
37+
accelerate \
38+
datasets \
39+
hf-doc-builder \
40+
huggingface-hub \
41+
hf_transfer \
42+
Jinja2 \
43+
librosa \
44+
numpy==1.26.4 \
45+
scipy \
46+
tensorboard \
47+
transformers \
48+
hf_transfer
49+
50+
CMD ["/bin/bash"]

tests/models/test_modeling_common.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,14 +1748,14 @@ class TorchCompileTesterMixin:
17481748
def setUp(self):
17491749
# clean up the VRAM before each test
17501750
super().setUp()
1751-
torch.compiler.reset()
1751+
torch._dynamo.reset()
17521752
gc.collect()
17531753
backend_empty_cache(torch_device)
17541754

17551755
def tearDown(self):
17561756
# clean up the VRAM after each test in case of CUDA runtime errors
17571757
super().tearDown()
1758-
torch.compiler.reset()
1758+
torch._dynamo.reset()
17591759
gc.collect()
17601760
backend_empty_cache(torch_device)
17611761

@@ -1764,17 +1764,13 @@ def tearDown(self):
17641764
@is_torch_compile
17651765
@slow
17661766
def test_torch_compile_recompilation_and_graph_break(self):
1767-
torch.compiler.reset()
1767+
torch._dynamo.reset()
17681768
init_dict, inputs_dict = self.prepare_init_args_and_inputs_for_common()
17691769

17701770
model = self.model_class(**init_dict).to(torch_device)
17711771
model = torch.compile(model, fullgraph=True)
17721772

1773-
with (
1774-
torch._inductor.utils.fresh_inductor_cache(),
1775-
torch._dynamo.config.patch(error_on_recompile=True),
1776-
torch.no_grad(),
1777-
):
1773+
with torch._dynamo.config.patch(error_on_recompile=True), torch.no_grad():
17781774
_ = model(**inputs_dict)
17791775
_ = model(**inputs_dict)
17801776

@@ -1802,7 +1798,7 @@ def tearDown(self):
18021798
# It is critical that the dynamo cache is reset for each test. Otherwise, if the test re-uses the same model,
18031799
# there will be recompilation errors, as torch caches the model when run in the same process.
18041800
super().tearDown()
1805-
torch.compiler.reset()
1801+
torch._dynamo.reset()
18061802
gc.collect()
18071803
backend_empty_cache(torch_device)
18081804

@@ -1919,7 +1915,7 @@ def test_hotswapping_model(self, rank0, rank1):
19191915
def test_hotswapping_compiled_model_linear(self, rank0, rank1):
19201916
# It's important to add this context to raise an error on recompilation
19211917
target_modules = ["to_q", "to_k", "to_v", "to_out.0"]
1922-
with torch._dynamo.config.patch(error_on_recompile=True), torch._inductor.utils.fresh_inductor_cache():
1918+
with torch._dynamo.config.patch(error_on_recompile=True):
19231919
self.check_model_hotswap(do_compile=True, rank0=rank0, rank1=rank1, target_modules0=target_modules)
19241920

19251921
@parameterized.expand([(11, 11), (7, 13), (13, 7)]) # important to test small to large and vice versa
@@ -1929,7 +1925,7 @@ def test_hotswapping_compiled_model_conv2d(self, rank0, rank1):
19291925

19301926
# It's important to add this context to raise an error on recompilation
19311927
target_modules = ["conv", "conv1", "conv2"]
1932-
with torch._dynamo.config.patch(error_on_recompile=True), torch._inductor.utils.fresh_inductor_cache():
1928+
with torch._dynamo.config.patch(error_on_recompile=True):
19331929
self.check_model_hotswap(do_compile=True, rank0=rank0, rank1=rank1, target_modules0=target_modules)
19341930

19351931
@parameterized.expand([(11, 11), (7, 13), (13, 7)]) # important to test small to large and vice versa
@@ -1939,7 +1935,7 @@ def test_hotswapping_compiled_model_both_linear_and_conv2d(self, rank0, rank1):
19391935

19401936
# It's important to add this context to raise an error on recompilation
19411937
target_modules = ["to_q", "conv"]
1942-
with torch._dynamo.config.patch(error_on_recompile=True), torch._inductor.utils.fresh_inductor_cache():
1938+
with torch._dynamo.config.patch(error_on_recompile=True):
19431939
self.check_model_hotswap(do_compile=True, rank0=rank0, rank1=rank1, target_modules0=target_modules)
19441940

19451941
@parameterized.expand([(11, 11), (7, 13), (13, 7)]) # important to test small to large and vice versa

tests/models/transformers/test_models_transformer_hunyuan_video.py

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@
1919
from diffusers import HunyuanVideoTransformer3DModel
2020
from diffusers.utils.testing_utils import (
2121
enable_full_determinism,
22+
is_torch_compile,
23+
require_torch_2,
24+
require_torch_gpu,
25+
slow,
2226
torch_device,
2327
)
2428

25-
from ..test_modeling_common import ModelTesterMixin, TorchCompileTesterMixin
29+
from ..test_modeling_common import ModelTesterMixin
2630

2731

2832
enable_full_determinism()
2933

3034

31-
class HunyuanVideoTransformer3DTests(ModelTesterMixin, TorchCompileTesterMixin, unittest.TestCase):
35+
class HunyuanVideoTransformer3DTests(ModelTesterMixin, unittest.TestCase):
3236
model_class = HunyuanVideoTransformer3DModel
3337
main_input_name = "hidden_states"
3438
uses_custom_attn_processor = True
@@ -92,8 +96,23 @@ def test_gradient_checkpointing_is_applied(self):
9296
expected_set = {"HunyuanVideoTransformer3DModel"}
9397
super().test_gradient_checkpointing_is_applied(expected_set=expected_set)
9498

99+
@require_torch_gpu
100+
@require_torch_2
101+
@is_torch_compile
102+
@slow
103+
def test_torch_compile_recompilation_and_graph_break(self):
104+
torch._dynamo.reset()
105+
init_dict, inputs_dict = self.prepare_init_args_and_inputs_for_common()
95106

96-
class HunyuanSkyreelsImageToVideoTransformer3DTests(ModelTesterMixin, TorchCompileTesterMixin, unittest.TestCase):
107+
model = self.model_class(**init_dict).to(torch_device)
108+
model = torch.compile(model, fullgraph=True)
109+
110+
with torch._dynamo.config.patch(error_on_recompile=True), torch.no_grad():
111+
_ = model(**inputs_dict)
112+
_ = model(**inputs_dict)
113+
114+
115+
class HunyuanSkyreelsImageToVideoTransformer3DTests(ModelTesterMixin, unittest.TestCase):
97116
model_class = HunyuanVideoTransformer3DModel
98117
main_input_name = "hidden_states"
99118
uses_custom_attn_processor = True
@@ -160,8 +179,23 @@ def test_gradient_checkpointing_is_applied(self):
160179
expected_set = {"HunyuanVideoTransformer3DModel"}
161180
super().test_gradient_checkpointing_is_applied(expected_set=expected_set)
162181

182+
@require_torch_gpu
183+
@require_torch_2
184+
@is_torch_compile
185+
@slow
186+
def test_torch_compile_recompilation_and_graph_break(self):
187+
torch._dynamo.reset()
188+
init_dict, inputs_dict = self.prepare_init_args_and_inputs_for_common()
189+
190+
model = self.model_class(**init_dict).to(torch_device)
191+
model = torch.compile(model, fullgraph=True)
192+
193+
with torch._dynamo.config.patch(error_on_recompile=True), torch.no_grad():
194+
_ = model(**inputs_dict)
195+
_ = model(**inputs_dict)
196+
163197

164-
class HunyuanVideoImageToVideoTransformer3DTests(ModelTesterMixin, TorchCompileTesterMixin, unittest.TestCase):
198+
class HunyuanVideoImageToVideoTransformer3DTests(ModelTesterMixin, unittest.TestCase):
165199
model_class = HunyuanVideoTransformer3DModel
166200
main_input_name = "hidden_states"
167201
uses_custom_attn_processor = True
@@ -226,10 +260,23 @@ def test_gradient_checkpointing_is_applied(self):
226260
expected_set = {"HunyuanVideoTransformer3DModel"}
227261
super().test_gradient_checkpointing_is_applied(expected_set=expected_set)
228262

263+
@require_torch_gpu
264+
@require_torch_2
265+
@is_torch_compile
266+
@slow
267+
def test_torch_compile_recompilation_and_graph_break(self):
268+
torch._dynamo.reset()
269+
init_dict, inputs_dict = self.prepare_init_args_and_inputs_for_common()
229270

230-
class HunyuanVideoTokenReplaceImageToVideoTransformer3DTests(
231-
ModelTesterMixin, TorchCompileTesterMixin, unittest.TestCase
232-
):
271+
model = self.model_class(**init_dict).to(torch_device)
272+
model = torch.compile(model, fullgraph=True)
273+
274+
with torch._dynamo.config.patch(error_on_recompile=True), torch.no_grad():
275+
_ = model(**inputs_dict)
276+
_ = model(**inputs_dict)
277+
278+
279+
class HunyuanVideoTokenReplaceImageToVideoTransformer3DTests(ModelTesterMixin, unittest.TestCase):
233280
model_class = HunyuanVideoTransformer3DModel
234281
main_input_name = "hidden_states"
235282
uses_custom_attn_processor = True
@@ -295,3 +342,18 @@ def test_output(self):
295342
def test_gradient_checkpointing_is_applied(self):
296343
expected_set = {"HunyuanVideoTransformer3DModel"}
297344
super().test_gradient_checkpointing_is_applied(expected_set=expected_set)
345+
346+
@require_torch_gpu
347+
@require_torch_2
348+
@is_torch_compile
349+
@slow
350+
def test_torch_compile_recompilation_and_graph_break(self):
351+
torch._dynamo.reset()
352+
init_dict, inputs_dict = self.prepare_init_args_and_inputs_for_common()
353+
354+
model = self.model_class(**init_dict).to(torch_device)
355+
model = torch.compile(model, fullgraph=True)
356+
357+
with torch._dynamo.config.patch(error_on_recompile=True), torch.no_grad():
358+
_ = model(**inputs_dict)
359+
_ = model(**inputs_dict)

tests/models/transformers/test_models_transformer_wan.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@
1919
from diffusers import WanTransformer3DModel
2020
from diffusers.utils.testing_utils import (
2121
enable_full_determinism,
22+
is_torch_compile,
23+
require_torch_2,
24+
require_torch_gpu,
25+
slow,
2226
torch_device,
2327
)
2428

25-
from ..test_modeling_common import ModelTesterMixin, TorchCompileTesterMixin
29+
from ..test_modeling_common import ModelTesterMixin
2630

2731

2832
enable_full_determinism()
2933

3034

31-
class WanTransformer3DTests(ModelTesterMixin, TorchCompileTesterMixin, unittest.TestCase):
35+
class WanTransformer3DTests(ModelTesterMixin, unittest.TestCase):
3236
model_class = WanTransformer3DModel
3337
main_input_name = "hidden_states"
3438
uses_custom_attn_processor = True
@@ -82,3 +86,18 @@ def prepare_init_args_and_inputs_for_common(self):
8286
def test_gradient_checkpointing_is_applied(self):
8387
expected_set = {"WanTransformer3DModel"}
8488
super().test_gradient_checkpointing_is_applied(expected_set=expected_set)
89+
90+
@require_torch_gpu
91+
@require_torch_2
92+
@is_torch_compile
93+
@slow
94+
def test_torch_compile_recompilation_and_graph_break(self):
95+
torch._dynamo.reset()
96+
init_dict, inputs_dict = self.prepare_init_args_and_inputs_for_common()
97+
98+
model = self.model_class(**init_dict).to(torch_device)
99+
model = torch.compile(model, fullgraph=True)
100+
101+
with torch._dynamo.config.patch(error_on_recompile=True), torch.no_grad():
102+
_ = model(**inputs_dict)
103+
_ = model(**inputs_dict)

0 commit comments

Comments
 (0)