Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 7.3k
Refactor Model Tests#12822
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
Uh oh!
There was an error while loading. Please reload this page.
Refactor Model Tests #12822
Changes from all commits
1f026ad1c55871bffa3a9aa29af80f1a4e0fe451c3489480b0fdd9d3c366b5ad08e0bbeae7543dcd6026d9b73ffe82001ec70de2b7b3ef42e0ab03dba475ee6caa0a95c2d30693625840a639d173342623620e4f6dfba74ce3097cda801e969f68c158f7ede6b6b8ef965272aFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -32,6 +32,22 @@ | ||
| def pytest_configure(config): | ||
| config.addinivalue_line("markers", "big_accelerator: marks tests as requiring big accelerator resources") | ||
| config.addinivalue_line("markers", "lora: marks tests for LoRA/PEFT functionality") | ||
| config.addinivalue_line("markers", "ip_adapter: marks tests for IP Adapter functionality") | ||
| config.addinivalue_line("markers", "training: marks tests for training functionality") | ||
| config.addinivalue_line("markers", "attention: marks tests for attention processor functionality") | ||
| config.addinivalue_line("markers", "memory: marks tests for memory optimization functionality") | ||
| config.addinivalue_line("markers", "cpu_offload: marks tests for CPU offloading functionality") | ||
| config.addinivalue_line("markers", "group_offload: marks tests for group offloading functionality") | ||
| config.addinivalue_line("markers", "compile: marks tests for torch.compile functionality") | ||
| config.addinivalue_line("markers", "single_file: marks tests for single file checkpoint loading") | ||
| config.addinivalue_line("markers", "quantization: marks tests for quantization functionality") | ||
| config.addinivalue_line("markers", "bitsandbytes: marks tests for BitsAndBytes quantization functionality") | ||
| config.addinivalue_line("markers", "quanto: marks tests for Quanto quantization functionality") | ||
| config.addinivalue_line("markers", "torchao: marks tests for TorchAO quantization functionality") | ||
| config.addinivalue_line("markers", "gguf: marks tests for GGUF quantization functionality") | ||
| config.addinivalue_line("markers", "modelopt: marks tests for NVIDIA ModelOpt quantization functionality") | ||
sayakpaul marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| config.addinivalue_line("markers", "context_parallel: marks tests for context parallel inference functionality") | ||
| config.addinivalue_line("markers", "slow: mark test as slow") | ||
| config.addinivalue_line("markers", "nightly: mark test as nightly") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| from .attention import AttentionTesterMixin | ||
| from .cache import ( | ||
| CacheTesterMixin, | ||
| FasterCacheConfigMixin, | ||
| FasterCacheTesterMixin, | ||
| FirstBlockCacheConfigMixin, | ||
| FirstBlockCacheTesterMixin, | ||
| PyramidAttentionBroadcastConfigMixin, | ||
| PyramidAttentionBroadcastTesterMixin, | ||
| ) | ||
| from .common import BaseModelTesterConfig, ModelTesterMixin | ||
| from .compile import TorchCompileTesterMixin | ||
| from .ip_adapter import IPAdapterTesterMixin | ||
| from .lora import LoraHotSwappingForModelTesterMixin, LoraTesterMixin | ||
| from .memory import CPUOffloadTesterMixin, GroupOffloadTesterMixin, LayerwiseCastingTesterMixin, MemoryTesterMixin | ||
| from .parallelism import ContextParallelTesterMixin | ||
| from .quantization import ( | ||
| BitsAndBytesCompileTesterMixin, | ||
| BitsAndBytesConfigMixin, | ||
| BitsAndBytesTesterMixin, | ||
| GGUFCompileTesterMixin, | ||
| GGUFConfigMixin, | ||
| GGUFTesterMixin, | ||
| ModelOptCompileTesterMixin, | ||
| ModelOptConfigMixin, | ||
| ModelOptTesterMixin, | ||
| QuantizationCompileTesterMixin, | ||
| QuantizationTesterMixin, | ||
| QuantoCompileTesterMixin, | ||
| QuantoConfigMixin, | ||
| QuantoTesterMixin, | ||
| TorchAoCompileTesterMixin, | ||
| TorchAoConfigMixin, | ||
| TorchAoTesterMixin, | ||
| ) | ||
| from .single_file import SingleFileTesterMixin | ||
| from .training import TrainingTesterMixin | ||
| __all__ = [ | ||
| "AttentionTesterMixin", | ||
| "BaseModelTesterConfig", | ||
| "BitsAndBytesCompileTesterMixin", | ||
| "BitsAndBytesConfigMixin", | ||
| "BitsAndBytesTesterMixin", | ||
| "CacheTesterMixin", | ||
| "ContextParallelTesterMixin", | ||
| "CPUOffloadTesterMixin", | ||
| "FasterCacheConfigMixin", | ||
| "FasterCacheTesterMixin", | ||
| "FirstBlockCacheConfigMixin", | ||
| "FirstBlockCacheTesterMixin", | ||
| "GGUFCompileTesterMixin", | ||
| "GGUFConfigMixin", | ||
| "GGUFTesterMixin", | ||
| "GroupOffloadTesterMixin", | ||
| "IPAdapterTesterMixin", | ||
| "LayerwiseCastingTesterMixin", | ||
| "LoraHotSwappingForModelTesterMixin", | ||
| "LoraTesterMixin", | ||
| "MemoryTesterMixin", | ||
| "ModelOptCompileTesterMixin", | ||
| "ModelOptConfigMixin", | ||
| "ModelOptTesterMixin", | ||
| "ModelTesterMixin", | ||
| "PyramidAttentionBroadcastConfigMixin", | ||
| "PyramidAttentionBroadcastTesterMixin", | ||
| "QuantizationCompileTesterMixin", | ||
| "QuantizationTesterMixin", | ||
| "QuantoCompileTesterMixin", | ||
| "QuantoConfigMixin", | ||
| "QuantoTesterMixin", | ||
| "SingleFileTesterMixin", | ||
| "TorchAoCompileTesterMixin", | ||
| "TorchAoConfigMixin", | ||
| "TorchAoTesterMixin", | ||
| "TorchCompileTesterMixin", | ||
| "TrainingTesterMixin", | ||
| ] |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,181 @@ | ||||||||||||||
| # coding=utf-8 | ||||||||||||||
| # Copyright 2025 HuggingFace Inc. | ||||||||||||||
| # | ||||||||||||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||
| # you may not use this file except in compliance with the License. | ||||||||||||||
| # You may obtain a copy of the License at | ||||||||||||||
| # | ||||||||||||||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||
| # | ||||||||||||||
| # Unless required by applicable law or agreed to in writing, software | ||||||||||||||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||
| # See the License for the specific language governing permissions and | ||||||||||||||
| # limitations under the License. | ||||||||||||||
| import gc | ||||||||||||||
| import pytest | ||||||||||||||
| import torch | ||||||||||||||
| from diffusers.models.attention import AttentionModuleMixin | ||||||||||||||
| from diffusers.models.attention_processor import ( | ||||||||||||||
| AttnProcessor, | ||||||||||||||
| ) | ||||||||||||||
| from ...testing_utils import ( | ||||||||||||||
| assert_tensors_close, | ||||||||||||||
| backend_empty_cache, | ||||||||||||||
| is_attention, | ||||||||||||||
| torch_device, | ||||||||||||||
| ) | ||||||||||||||
Comment on lines
+26
to
+31
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
| ||||||||||||||
| @is_attention | ||||||||||||||
| class AttentionTesterMixin: | ||||||||||||||
| """ | ||||||||||||||
| Mixin class for testing attention processor and module functionality on models. | ||||||||||||||
| Tests functionality from AttentionModuleMixin including: | ||||||||||||||
| - Attention processor management (set/get) | ||||||||||||||
| - QKV projection fusion/unfusion | ||||||||||||||
| - Attention backends (XFormers, NPU, etc.) | ||||||||||||||
| Expected from config mixin: | ||||||||||||||
| - model_class: The model class to test | ||||||||||||||
| Expected methods from config mixin: | ||||||||||||||
| - get_init_dict(): Returns dict of arguments to initialize the model | ||||||||||||||
| - get_dummy_inputs(): Returns dict of inputs to pass to the model forward pass | ||||||||||||||
| Pytest mark: attention | ||||||||||||||
| Use `pytest -m "not attention"` to skip these tests | ||||||||||||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we implement it in an individual model testing class? For example, say we want to skip it for model X where its attention class doesn't inherit from CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, any model using attention also uses AttentionModuleMixin. The options here
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But there are important classes like Autoencoders that don't use the Attention mixins. Let's do this?
CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
| ||||||||||||||
| ifisinstance(module, AttentionModuleMixin): |
and if that's not the case, we skip.
Otherwise, I think it could be cumbersome to check which model tests should and shouldn't use this class because attention is a common component.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.