[tests] A tester mixin for running modular blocks on their own

Offen
#15,267 6 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python, pytorch
Bereich
testing

Rechercherichtung

Read the existing mixins in tests/modular_pipelines/testing_utils/ and the standalone block tests under tests/modular_pipelines/, including the MiniMax H3 Image example in the issue. Compare how those tests initialize blocks, load components, and check inputs and outputs; define what the shared checks should cover across workflows. Done means the proposed mixin can run those checks for each top-level block, while model-specific assertions remain in each pipeline's test class.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

idea-contribution-welcome

A modular pipeline is meant to be used in pieces: you can take the text encoder block, turn it into its own pipeline, and run it separately from the rest. We want that to keep working for every pipeline, and we want it to be intuitive to use that way. Today each test file checks the first by hand, if at all, and nothing checks the second.

What we want to test

For each top-level block of a pipeline (text encoder, VAE encoder, denoise, decode, ...):

  • it builds into its own pipeline with init_pipeline()
  • that pipeline loads only the components the block declares, e.g. just vae for a VAE encoder
  • it runs on the inputs it declares and returns the outputs it declares
  • running the blocks one after another, each fed the outputs of the ones before it, gives the same result as the assembled pipeline
  • it is intuitive to use on its own: what you pass in and what you get back make sense without knowing the rest of the pipeline
Is it intuitive to use this way?

Running image -> encoder -> denoise -> decoder by hand shows interface problems that the assembled pipeline hides. Patterns we have run into so far:

  • Components it does not own. It would be weird for a VAE encoder block to require the transformer just because it reads a value from its config. A block run on its own should load only what it actually runs.
  • Too much crossing a boundary. A decoder that takes packed latents also needs latent_height and latent_width to unpack them, so the user has to carry those over from the denoise step. We fixed this for flux, krea2 and ltx by making unpack part of the denoise group (#14730, #14737). What one block hands to the next should be a short, canonical list (prompt_embeds, image_latents, latents).
  • Optional in, something out. A text encoder block should not require the guider: the user should not have to configure guidance in two separate places, once for the text encoder and once for the denoiser. Run on its own, it gives back negative embeddings when you pass a negative_prompt and none when you don't. Getting a negative_prompt=None encoded anyway is unintuitive (#14469).
  • Redundant inputs. A denoise block that takes image_latents should not also need height and width, unless the pipeline supports an output size different from the reference's.

In this test we want to check for these specific patterns. We catch new ones over time during reviews, so the mixin should make adding one cheap.

What it looks like today

Fifteen test files under tests/modular_pipelines/ build a one-block pipeline by hand, each with its own setup. For example, from the MiniMax H3 Image tests:

class TestMiniMaxH3ImageModularBlocks(MiniMaxH3ImageModularPipelineTesterConfig):
    def test_vae_encoder_block_standalone(self):
        pipe = MiniMaxH3ImageEditVaeEncoderStep().init_pipeline(self.pretrained_model_name_or_path)
        pipe.load_components(dtype=torch.float32)

        reference_latents = pipe(
            reference_images=[Image.new("RGB", (64, 32))],
            generator=self.get_generator(0),
            output="reference_latents",
        )

        assert set(pipe.components) == {"vae"}
        assert len(reference_latents) == 1
        assert reference_latents[0].shape == (1, 4, 8, 16)

The build, the load, the component check and the "does it return its output" check are the same for every block in every pipeline. Only the last assertion is specific to this model.

Proposal

A tester mixin next to the existing ones in tests/modular_pipelines/testing_utils/, composed with the same config class as the others. It walks the top-level blocks of each workflow and runs the checks above, so a new pipeline gets them without writing anything. Model-specific assertions stay as methods on the pipeline's own test class.

How to contribute

This issue carries the idea-contribution-welcome label. We are not currently looking for a PR here, we are looking for your feedback, especially if you use modular blocks on their own:

  • other patterns you think this test should check for
  • places where running a block standalone is unintuitive today: an input you did not expect to need, an output you did not expect to get, a value you had to carry from one block to the next

we may invite you to work with us on this once we agree on the implementation. If we decide to write the PR ourselves, anyone whose feedback shaped it will be added as a co-author.


Posted by Claude on behalf of @yiyixuxu. The text was drafted together and approved by yiyixuxu.

Vorherrschende Sprache
Python
Sterne
35k
Forks
7.5k
Ø Merge
2 T. 22 Std.
Gemergte PRs (30 T.)
58

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus huggingface/diffusers

Alle Issues in huggingface/diffusers

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.