Skip to content

Modular: required=True is silently ignored when an InputParam carries a default #14388

Closed

Description

@yiyixuxu

Opened by Claude (Opus 5) on behalf of @yiyixuxu.

Describe the bug

In modular pipelines, an InputParam that is both required=True and carries a non-None default is silently not required. The default is applied before required is ever tested, at two points:

  1. ModularPipeline.__call__ writes the pipeline-level default of every input that was not passed into the state before any block runs (modular_pipeline.py#L3007-L3020). For a sequential pipeline this is the first declaring block's default, so a sub-block never sees a missing value.
  2. get_block_state reads the value from the state and, if it is None, substitutes the block's own declared default. Only then does it test required (modular_pipeline.py#L588-L600):
        # Check inputs
        for input_param in state_inputs:
            if input_param.name:
                value = state.get(input_param.name)
                if value is None:
                    ...
                    value = input_param.default
                if input_param.required and value is None:
                    raise ValueError(f"Required input '{input_param.name}' is missing")
                elif value is not None or (value is None and input_param.name not in data):
                    data[input_param.name] = value

This is easy to hit through InputParam.template, because the template supplies the default and an override only replaces the keys it names:

template_kwargs = INPUT_PARAM_TEMPLATES[template_name].copy()   # {"type_hint": int, "default": 50, ...}
template_kwargs.update(overrides)                               # {"required": True}
return cls(name=name, **template_kwargs)

So InputParam.template("num_inference_steps", required=True) reads like a decision to require the input, and produces an input that defaults to 50 instead. Nobody wrote the 50 — it arrived as a side effect of reaching for the template's type hint and description.

Reproduction

from diffusers.modular_pipelines.modular_pipeline_utils import InputParam

param = InputParam.template("num_inference_steps", required=True)
print(param.required, param.default)   # True 50

End to end, on a block that declares it that way — omitting the input runs at 50 rather than raising:

passed num_inference_steps=2 -> 1 timesteps
omitted                      -> 49 timesteps

Where it occurs

14 call sites on main, across four pipelines, where required=True cannot bite (found by matching InputParam.template(..., required=True) against the templates that carry a default, skipping the sites that pass default=None explicitly):

file line param
modular_pipelines/cosmos/before_denoise.py 953, 1224 num_inference_steps
modular_pipelines/cosmos/denoise.py 462 num_inference_steps
modular_pipelines/krea2/denoise.py 92, 259 num_inference_steps
modular_pipelines/ltx/before_denoise.py 281, 345 batch_size
modular_pipelines/ltx/decoders.py 79 dtype
modular_pipelines/ltx/denoise.py 48, 274 dtype
modular_pipelines/ltx/denoise.py 98, 210, 326 num_inference_steps
modular_pipelines/qwenimage/denoise.py 465 num_inference_steps

hunyuan_video1_5/denoise.py is the only place that noticed, and works around it by writing InputParam.template("num_inference_steps", required=True, default=None).

The templates carrying a default are batch_size, control_guidance_end, control_guidance_start, controlnet_conditioning_scale, dtype, layers, max_sequence_length, num_images_per_prompt, num_inference_steps, output_type and strength.

Why it matters beyond the flag

The contradiction also leaks into what a pipeline advertises. ModularPipeline.default_call_parameters maps every declared input to its default without filtering on required, so these inputs report a default they will not actually honour if the flag is ever made to work — and the same property is what ModularPipelineTesterMixin.optional_params is checked against, which means that assertion currently cannot distinguish an optional input from a required one.

Suggested fix

required=True and a default are contradictory: if an input is required, the default value is irrelevant and should not be there. Two ways to make that hold, both of which need a call:

  1. Reject the combination. Raise in InputParam.__post_init__ when required and default is not None. Every affected site then has to state what it means, and the mistake becomes unmakeable rather than silent.
  2. Make the flag bite. Test required before substituting the default, in both ModularPipeline.__call__ and get_block_state. Less invasive to write, but it leaves the contradictory declaration in place and merely picks a winner.

Either way the 14 sites above change behaviour — a request that omits one of those inputs starts raising where it used to fall back to the template's value — so each one needs its pipeline's author to say whether the input was meant to be required, or whether the default was meant to be real and required=True should simply go.

Happy to open a PR for whichever direction you prefer.

Activity

  1. self-assigned this
    on Aug 5, 2026
  2. Sravan1011 commented on Aug 5, 2026

    @Sravan1011

    @yiyixuxu are you working on this ?

  3. yiyixuxu commented on Aug 5, 2026

    @yiyixuxu
    CollaboratorAuthor

    @Sravan1011 not yet, let me know if you want to work on this :)

  4. Sravan1011 commented on Aug 5, 2026

    @Sravan1011

    Yup i'd like to work on this

  5. added a commit that references this issue on Aug 5, 2026
  6. added a commit that references this issue on Aug 6, 2026
  7. Sravan1011 commented on Aug 6, 2026

    @Sravan1011

    @yiyixuxu so should I try or you have fixed this ?

  8. Sravan1011 commented on Aug 6, 2026

    @Sravan1011

    @yiyixuxu can review this and create a merge

  9. Sravan1011 commented on Aug 10, 2026

    @Sravan1011

    @yiyixuxu could pls check the pr I created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugmodular-pipelinesneeds-env-info

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions