Skip to content

[Modular] Fast Tests #11937

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

[Modular] Fast Tests #11937

wants to merge 17 commits into from

Conversation

yiyixuxu
Copy link
Collaborator

@yiyixuxu yiyixuxu commented Jul 16, 2025

I added a fast test for modular sdxl so we have something

feel free to refactor them!

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@@ -20,12 +20,6 @@
]
)

TEXT_TO_IMAGE_BATCH_PARAMS = frozenset(["prompt", "negative_prompt"])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just rearranged a bit, i.e. put all the batch inputs together, image inputs together
did not delete or add anything

@yiyixuxu yiyixuxu requested review from DN6 and sayakpaul July 16, 2025 10:12
@DN6
Copy link
Collaborator

DN6 commented Jul 21, 2025

Will take care of the code scanning warnings.

Changes introduced

  1. Dedicated workflow for modular that runs only when there are changes to core modules or modular pipelines. This is so that the PR CI doesn't slow down
  2. Dedicated test module for modular. Easier to isolate running modular tests
  3. Miscellaneous changes to common tests that I've been meaning to get to.

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice start! My comments are mostly minor.

Apart from the common tests in the mixin, can we think of any other tests that should check for the core features of a modular pipeline? For example, for a given pipeline, does load_default_components() work as expected?

Then, do properties such as input_names work as expected?

We can do that in follow-ups but I thought the PR that is adding the first modular test suite should cover the rudimentary elements.

Comment on lines +6 to +18
paths:
- "src/diffusers/modular_pipelines/**.py"
- "src/diffusers/models/modeling_utils.py"
- "src/diffusers/models/model_loading_utils.py"
- "src/diffusers/pipelines/pipeline_utils.py"
- "src/diffusers/pipeline_loading_utils.py"
- "src/diffusers/loaders/lora_base.py"
- "src/diffusers/loaders/lora_pipeline.py"
- "src/diffusers/loaders/peft.py"
- "tests/modular_pipelines/**.py"
- ".github/**.yml"
- "utils/**.py"
- "setup.py"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see filtered invokations. Do we know if changing anything in the repsective modeling or pipeline implementations (SDXL, for instance) would impact modular? If so, should we consider that somehow?

Comment on lines +82 to +88
matrix:
config:
- name: Fast PyTorch Modular Pipeline CPU tests
framework: pytorch_pipelines
runner: aws-highmemory-32-plus
image: diffusers/diffusers-pytorch-cpu
report: torch_cpu_modular_pipelines
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need a matrix here, I believe?

if: ${{ matrix.config.framework == 'pytorch_pipelines' }}
run: |
python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH"
python -m pytest -n 8 --max-worker-restart=0 --dist=loadfile \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can potentially increase the number of workers here.

Comment on lines -747 to -748
return_noise=False,
return_image_latents=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason behind this change?

Comment on lines +20 to +24
def to_np(tensor):
if isinstance(tensor, torch.Tensor):
tensor = tensor.detach().cpu().numpy()

return tensor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer this to be in testing_utils.py.

Comment on lines +52 to +56
intermediate_params = frozenset(
[
"generator",
]
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
intermediate_params = frozenset(
[
"generator",
]
)
intermediate_params = frozenset(["generator"])

@@ -0,0 +1,320 @@
import gc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit): license header missing.

Comment on lines 386 to 404
@require_torch_accelerator
def test_stable_diffusion_xl_offloads(self):
pipes = []
sd_pipe = self.get_pipeline().to(torch_device)
pipes.append(sd_pipe)

cm = ComponentsManager()
cm.enable_auto_cpu_offload(device=torch_device)
sd_pipe = self.get_pipeline(components_manager=cm)
pipes.append(sd_pipe)

image_slices = []
for pipe in pipes:
inputs = self.get_dummy_inputs(torch_device)
image = pipe(**inputs, output="images")

image_slices.append(image[0, -3:, -3:, -1].flatten())

assert np.abs(image_slices[0] - image_slices[1]).max() < 1e-3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would consider moving this to mixin.


assert np.abs(image_slices[0] - image_slices[1]).max() < 1e-3

def test_stable_diffusion_xl_save_from_pretrained(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would consider moving this to mixin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants