Skip to content

Commit c46de05

Browse files
Unpin diffusers and pass onnx exporters tests (#2153)
* test * remove diffusers from default tests extras * add diffusers to onnx export and onnxruntime ci * raise error when incompatible diffusers andtransformers and don't test difusers with transformers 4.36 * subtle * fix * fix * fix installation * add height width to image inputs to control output image dims * fix flux test shape * use transformers main in onnx ci until new release * fix for cli as well * use a PIL image * revert main transformers and disable modernbert * comment modernbert for now * style * remove diff compatibility error * style * revert atol to 1e-4
1 parent adcae38 commit c46de05

11 files changed

+66
-56
lines changed

.github/workflows/test_export_onnx.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
python-version: ['3.9']
18+
python-version: ["3.9"]
1919
os: [ubuntu-20.04]
2020

2121
runs-on: ${{ matrix.os }}
@@ -27,13 +27,14 @@ jobs:
2727
python-version: ${{ matrix.python-version }}
2828
- name: Install dependencies for pytorch export
2929
run: |
30-
pip install .[tests,exporters]
30+
pip install .[tests,exporters,diffusers]
3131
- name: Test with unittest
3232
working-directory: tests
3333
run: |
3434
pytest exporters/onnx/test_onnx_*.py -s -n auto -m "not tensorflow_test and not timm_test" --durations=0
3535
- name: Install dependencies for tensorflow export
3636
run: |
37+
pip uninstall diffusers -y
3738
pip install .[tests,exporters-tf]
3839
- name: Test with unittest
3940
working-directory: tests

.github/workflows/test_export_onnx_cli.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
python-version: [3.9]
18+
python-version: ["3.9"]
1919
os: [ubuntu-20.04]
2020

2121
runs-on: ${{ matrix.os }}
@@ -27,7 +27,7 @@ jobs:
2727
python-version: ${{ matrix.python-version }}
2828
- name: Install dependencies for pytorch export
2929
run: |
30-
pip install .[tests,exporters]
30+
pip install .[tests,exporters,diffusers]
3131
- name: Test with unittest
3232
working-directory: tests
3333
run: |

.github/workflows/test_exporters_slow.yml

+21-20
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,27 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
python-version: ['3.9']
17+
python-version: ["3.9"]
1818

1919
runs-on: ubuntu-20.04
2020
steps:
21-
- uses: actions/checkout@v2
22-
- name: Setup Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v2
24-
with:
25-
python-version: ${{ matrix.python-version }}
26-
- name: Install dependencies for pytorch export
27-
run: |
28-
pip install .[tests,exporters]
29-
- name: Test with unittest
30-
working-directory: tests
31-
run: |
32-
RUN_SLOW=1 pytest exporters -s -m "not tensorflow_test and run_slow" --durations=0
33-
- name: Install dependencies for tensorflow export
34-
run: |
35-
pip install .[tests,exporters-tf]
36-
- name: Test with unittest
37-
working-directory: tests
38-
run: |
39-
RUN_SLOW=1 pytest exporters -s -m "tensorflow_test and run_slow" --durations=0
21+
- uses: actions/checkout@v2
22+
- name: Setup Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: Install dependencies for pytorch export
27+
run: |
28+
pip install .[tests,exporters,diffusers]
29+
- name: Test with unittest
30+
working-directory: tests
31+
run: |
32+
RUN_SLOW=1 pytest exporters -s -m "not tensorflow_test and run_slow" --durations=0
33+
- name: Install dependencies for tensorflow export
34+
run: |
35+
pip uninstall diffusers -y
36+
pip install .[tests,exporters-tf]
37+
- name: Test with unittest
38+
working-directory: tests
39+
run: |
40+
RUN_SLOW=1 pytest exporters -s -m "tensorflow_test and run_slow" --durations=0

.github/workflows/test_onnx.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
python-version: ${{ matrix.python-version }}
2828
- name: Install dependencies
2929
run: |
30-
pip install .[tests,exporters]
30+
pip install .[tests,exporters,diffusers]
3131
- name: Test with unittest
3232
working-directory: tests
3333
run: |

.github/workflows/test_onnxruntime.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,23 @@ jobs:
3838
- name: Setup Python
3939
uses: actions/setup-python@v5
4040
with:
41-
python-version: '3.9'
41+
python-version: "3.9"
4242

4343
- name: Install dependencies
4444
run: |
4545
pip install --upgrade pip
4646
pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
47-
pip install .[tests,onnxruntime]
47+
pip install .[tests,onnxruntime,diffusers]
4848
4949
- name: Install transformers ${{ matrix.transformers-version }}
5050
if: ${{ matrix.transformers-version != 'latest' }}
51-
run: pip install transformers==${{ matrix.transformers-version }}
51+
run: |
52+
pip install "transformers==${{ matrix.transformers-version }}"
53+
54+
- name: Downgrade diffusers
55+
if: matrix.transformers-version == '4.36.*'
56+
run: |
57+
pip install "diffusers<0.32.0"
5258
5359
- name: Test with pytest (in series)
5460
run: |

.github/workflows/test_onnxruntime_slow.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
python-version: ['3.9']
17+
python-version: ["3.9"]
1818
os: [ubuntu-20.04]
1919

2020
runs-on: ${{ matrix.os }}
@@ -26,7 +26,7 @@ jobs:
2626
python-version: ${{ matrix.python-version }}
2727
- name: Install dependencies for export
2828
run: |
29-
pip install .[tests,onnxruntime]
29+
pip install .[tests,onnxruntime,diffusers]
3030
- name: Test with unittest
3131
working-directory: tests
3232
run: |

optimum/exporters/onnx/model_configs.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ def inputs(self) -> Dict[str, Dict[int, str]]:
183183
return {"input_ids": dynamic_axis, "attention_mask": dynamic_axis}
184184

185185

186-
class ModernBertOnnxConfig(DistilBertOnnxConfig):
187-
pass
186+
# TODO: uncomment when transformers>=4.48.0
187+
# class ModernBertOnnxConfig(DistilBertOnnxConfig):
188+
# pass
188189

189190

190191
class MPNetOnnxConfig(DistilBertOnnxConfig):

optimum/exporters/tasks.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -893,15 +893,15 @@ class TasksManager:
893893
"image-classification",
894894
onnx="MobileNetV2OnnxConfig",
895895
),
896-
"modernbert": supported_tasks_mapping(
897-
"feature-extraction",
898-
"fill-mask",
899-
"text-classification",
900-
"multiple-choice",
901-
"token-classification",
902-
"question-answering",
903-
onnx="ModernBertOnnxConfig",
904-
),
896+
# "modernbert": supported_tasks_mapping(
897+
# "feature-extraction",
898+
# "fill-mask",
899+
# "text-classification",
900+
# "multiple-choice",
901+
# "token-classification",
902+
# "question-answering",
903+
# onnx="ModernBertOnnxConfig",
904+
# ),
905905
"mpnet": supported_tasks_mapping(
906906
"feature-extraction",
907907
"fill-mask",

setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"Pillow",
3232
"sacremoses",
3333
"torchvision",
34-
"diffusers>=0.17.0,<0.32.0",
3534
"torchaudio",
3635
"einops",
3736
"timm",
@@ -89,7 +88,7 @@
8988
"executorch>=0.4.0",
9089
"transformers>=4.46",
9190
],
92-
"diffusers": ["diffusers<0.32.0"],
91+
"diffusers": ["diffusers"],
9392
"intel": "optimum-intel>=1.18.0",
9493
"openvino": "optimum-intel[openvino]>=1.18.0",
9594
"nncf": "optimum-intel[nncf]>=1.18.0",

tests/exporters/exporters_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"mobilenet-v2": "hf-internal-testing/tiny-random-MobileNetV2Model",
126126
"mobilenet-v1": "google/mobilenet_v1_0.75_192",
127127
"mobilevit": "hf-internal-testing/tiny-random-mobilevit",
128-
"modernbert": "hf-internal-testing/tiny-random-ModernBertForMaskedLM",
128+
# "modernbert": "hf-internal-testing/tiny-random-ModernBertForMaskedLM",
129129
"mpnet": "hf-internal-testing/tiny-random-MPNetModel",
130130
"mpt": "hf-internal-testing/tiny-random-MptForCausalLM",
131131
"mt5": "lewtun/tiny-random-mt5",
@@ -269,7 +269,7 @@
269269
# "mobilenet_v1": "google/mobilenet_v1_0.75_192",
270270
# "mobilenet_v2": "google/mobilenet_v2_0.35_96",
271271
"mobilevit": "apple/mobilevit-small",
272-
"modernbert": "answerdotai/ModernBERT-base",
272+
# "modernbert": "answerdotai/ModernBERT-base",
273273
"mpt": "mosaicml/mpt-7b",
274274
"mt5": "lewtun/tiny-random-mt5", # Not using google/mt5-small because it takes too much time for testing.
275275
"musicgen": "facebook/musicgen-small",

tests/onnxruntime/test_diffusion.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def _generate_prompts(batch_size=1):
5454
"guidance_scale": 7.5,
5555
"output_type": "np",
5656
}
57+
5758
return inputs
5859

5960

@@ -105,8 +106,7 @@ class ORTPipelineForText2ImageTest(ORTModelTestMixin):
105106
def generate_inputs(self, height=128, width=128, batch_size=1):
106107
inputs = _generate_prompts(batch_size=batch_size)
107108

108-
inputs["height"] = height
109-
inputs["width"] = width
109+
inputs["height"], inputs["width"] = height, width
110110

111111
return inputs
112112

@@ -224,17 +224,19 @@ def test_shape(self, model_arch: str):
224224
elif output_type == "pt":
225225
self.assertEqual(outputs.shape, (batch_size, 3, height, width))
226226
else:
227-
expected_height = height // pipeline.vae_scale_factor
228-
expected_width = width // pipeline.vae_scale_factor
229-
230227
if model_arch == "flux":
228+
expected_height = height // (pipeline.vae_scale_factor * 2)
229+
expected_width = width // (pipeline.vae_scale_factor * 2)
231230
channels = pipeline.transformer.config.in_channels
232231
expected_shape = (batch_size, expected_height * expected_width, channels)
233-
elif model_arch == "stable-diffusion-3":
234-
out_channels = pipeline.transformer.config.out_channels
235-
expected_shape = (batch_size, out_channels, expected_height, expected_width)
236232
else:
237-
out_channels = pipeline.unet.config.out_channels
233+
expected_height = height // pipeline.vae_scale_factor
234+
expected_width = width // pipeline.vae_scale_factor
235+
out_channels = (
236+
pipeline.unet.config.out_channels
237+
if getattr(pipeline, "unet", None) is not None
238+
else pipeline.transformer.config.out_channels
239+
)
238240
expected_shape = (batch_size, out_channels, expected_height, expected_width)
239241

240242
self.assertEqual(outputs.shape, expected_shape)
@@ -363,6 +365,7 @@ def generate_inputs(self, height=128, width=128, batch_size=1, channel=3, input_
363365
height=height, width=width, batch_size=batch_size, channel=channel, input_type=input_type
364366
)
365367

368+
inputs["height"], inputs["width"] = height, width
366369
inputs["strength"] = 0.75
367370

368371
return inputs
@@ -602,9 +605,8 @@ def generate_inputs(self, height=128, width=128, batch_size=1, channel=3, input_
602605
height=height, width=width, batch_size=batch_size, channel=1, input_type=input_type
603606
)
604607

608+
inputs["height"], inputs["width"] = height, width
605609
inputs["strength"] = 0.75
606-
inputs["height"] = height
607-
inputs["width"] = width
608610

609611
return inputs
610612

0 commit comments

Comments
 (0)