Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpin diffusers and pass onnx exporters tests #2153

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/test_export_onnx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.9']
python-version: ["3.9"]
os: [ubuntu-20.04]

runs-on: ${{ matrix.os }}
Expand All @@ -27,13 +27,14 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies for pytorch export
run: |
pip install .[tests,exporters]
pip install .[tests,exporters,diffusers]
- name: Test with unittest
working-directory: tests
run: |
pytest exporters/onnx/test_onnx_*.py -s -n auto -m "not tensorflow_test and not timm_test" --durations=0
- name: Install dependencies for tensorflow export
run: |
pip uninstall diffusers -y
pip install .[tests,exporters-tf]
- name: Test with unittest
working-directory: tests
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_export_onnx_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
python-version: ["3.9"]
os: [ubuntu-20.04]

runs-on: ${{ matrix.os }}
Expand All @@ -27,7 +27,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies for pytorch export
run: |
pip install .[tests,exporters]
pip install .[tests,exporters,diffusers]
- name: Test with unittest
working-directory: tests
run: |
Expand Down
41 changes: 21 additions & 20 deletions .github/workflows/test_exporters_slow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,27 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.9']
python-version: ["3.9"]

runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies for pytorch export
run: |
pip install .[tests,exporters]
- name: Test with unittest
working-directory: tests
run: |
RUN_SLOW=1 pytest exporters -s -m "not tensorflow_test and run_slow" --durations=0
- name: Install dependencies for tensorflow export
run: |
pip install .[tests,exporters-tf]
- name: Test with unittest
working-directory: tests
run: |
RUN_SLOW=1 pytest exporters -s -m "tensorflow_test and run_slow" --durations=0
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies for pytorch export
run: |
pip install .[tests,exporters,diffusers]
- name: Test with unittest
working-directory: tests
run: |
RUN_SLOW=1 pytest exporters -s -m "not tensorflow_test and run_slow" --durations=0
- name: Install dependencies for tensorflow export
run: |
pip uninstall diffusers -y
pip install .[tests,exporters-tf]
- name: Test with unittest
working-directory: tests
run: |
RUN_SLOW=1 pytest exporters -s -m "tensorflow_test and run_slow" --durations=0
2 changes: 1 addition & 1 deletion .github/workflows/test_onnx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install .[tests,exporters]
pip install .[tests,exporters,diffusers]
- name: Test with unittest
working-directory: tests
run: |
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/test_onnxruntime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,23 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: "3.9"

- name: Install dependencies
run: |
pip install --upgrade pip
pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
pip install .[tests,onnxruntime]
pip install .[tests,onnxruntime,diffusers]

- name: Install transformers ${{ matrix.transformers-version }}
if: ${{ matrix.transformers-version != 'latest' }}
run: pip install transformers==${{ matrix.transformers-version }}
run: |
pip install "transformers==${{ matrix.transformers-version }}"

- name: Downgrade diffusers
if: matrix.transformers-version == '4.36.*'
run: |
pip install "diffusers<0.32.0"

- name: Test with pytest (in series)
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_onnxruntime_slow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.9']
python-version: ["3.9"]
os: [ubuntu-20.04]

runs-on: ${{ matrix.os }}
Expand All @@ -26,7 +26,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies for export
run: |
pip install .[tests,onnxruntime]
pip install .[tests,onnxruntime,diffusers]
- name: Test with unittest
working-directory: tests
run: |
Expand Down
5 changes: 3 additions & 2 deletions optimum/exporters/onnx/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ def inputs(self) -> Dict[str, Dict[int, str]]:
return {"input_ids": dynamic_axis, "attention_mask": dynamic_axis}


class ModernBertOnnxConfig(DistilBertOnnxConfig):
pass
# TODO: uncomment when transformers>=4.48.0
# class ModernBertOnnxConfig(DistilBertOnnxConfig):
# pass


class MPNetOnnxConfig(DistilBertOnnxConfig):
Expand Down
18 changes: 9 additions & 9 deletions optimum/exporters/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,15 +891,15 @@ class TasksManager:
"image-classification",
onnx="MobileNetV2OnnxConfig",
),
"modernbert": supported_tasks_mapping(
"feature-extraction",
"fill-mask",
"text-classification",
"multiple-choice",
"token-classification",
"question-answering",
onnx="ModernBertOnnxConfig",
),
# "modernbert": supported_tasks_mapping(
# "feature-extraction",
# "fill-mask",
# "text-classification",
# "multiple-choice",
# "token-classification",
# "question-answering",
# onnx="ModernBertOnnxConfig",
# ),
"mpnet": supported_tasks_mapping(
"feature-extraction",
"fill-mask",
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"Pillow",
"sacremoses",
"torchvision",
"diffusers>=0.17.0,<0.32.0",
"torchaudio",
"einops",
"timm",
Expand Down Expand Up @@ -89,7 +88,7 @@
"executorch>=0.4.0",
"transformers>=4.46",
],
"diffusers": ["diffusers<0.32.0"],
"diffusers": ["diffusers"],
"intel": "optimum-intel>=1.18.0",
"openvino": "optimum-intel[openvino]>=1.18.0",
"nncf": "optimum-intel[nncf]>=1.18.0",
Expand Down
4 changes: 2 additions & 2 deletions tests/exporters/exporters_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"mobilenet-v2": "hf-internal-testing/tiny-random-MobileNetV2Model",
"mobilenet-v1": "google/mobilenet_v1_0.75_192",
"mobilevit": "hf-internal-testing/tiny-random-mobilevit",
"modernbert": "hf-internal-testing/tiny-random-ModernBertForMaskedLM",
# "modernbert": "hf-internal-testing/tiny-random-ModernBertForMaskedLM",
"mpnet": "hf-internal-testing/tiny-random-MPNetModel",
"mpt": "hf-internal-testing/tiny-random-MptForCausalLM",
"mt5": "lewtun/tiny-random-mt5",
Expand Down Expand Up @@ -267,7 +267,7 @@
# "mobilenet_v1": "google/mobilenet_v1_0.75_192",
# "mobilenet_v2": "google/mobilenet_v2_0.35_96",
"mobilevit": "apple/mobilevit-small",
"modernbert": "answerdotai/ModernBERT-base",
# "modernbert": "answerdotai/ModernBERT-base",
"mpt": "mosaicml/mpt-7b",
"mt5": "lewtun/tiny-random-mt5", # Not using google/mt5-small because it takes too much time for testing.
"musicgen": "facebook/musicgen-small",
Expand Down
24 changes: 13 additions & 11 deletions tests/onnxruntime/test_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def _generate_prompts(batch_size=1):
"guidance_scale": 7.5,
"output_type": "np",
}

return inputs


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

inputs["height"] = height
inputs["width"] = width
inputs["height"], inputs["width"] = height, width

return inputs

Expand Down Expand Up @@ -224,17 +224,19 @@ def test_shape(self, model_arch: str):
elif output_type == "pt":
self.assertEqual(outputs.shape, (batch_size, 3, height, width))
else:
expected_height = height // pipeline.vae_scale_factor
expected_width = width // pipeline.vae_scale_factor

if model_arch == "flux":
expected_height = height // (pipeline.vae_scale_factor * 2)
expected_width = width // (pipeline.vae_scale_factor * 2)
channels = pipeline.transformer.config.in_channels
expected_shape = (batch_size, expected_height * expected_width, channels)
elif model_arch == "stable-diffusion-3":
out_channels = pipeline.transformer.config.out_channels
expected_shape = (batch_size, out_channels, expected_height, expected_width)
else:
out_channels = pipeline.unet.config.out_channels
expected_height = height // pipeline.vae_scale_factor
expected_width = width // pipeline.vae_scale_factor
out_channels = (
pipeline.unet.config.out_channels
if getattr(pipeline, "unet", None) is not None
else pipeline.transformer.config.out_channels
)
expected_shape = (batch_size, out_channels, expected_height, expected_width)

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

inputs["height"], inputs["width"] = height, width
inputs["strength"] = 0.75

return inputs
Expand Down Expand Up @@ -602,9 +605,8 @@ def generate_inputs(self, height=128, width=128, batch_size=1, channel=3, input_
height=height, width=width, batch_size=batch_size, channel=1, input_type=input_type
)

inputs["height"], inputs["width"] = height, width
inputs["strength"] = 0.75
inputs["height"] = height
inputs["width"] = width

return inputs

Expand Down
Loading