invoke-ai/InvokeAI · error · ValueError

shift must be finite.

Error message

shift must be finite.

What it means

A pydantic field_validator on the optional 'shift' field of the Krea2 denoise invocation rejects NaN/±Infinity. 'shift' controls the flow-matching timestep shift for Krea2 models; a non-finite shift is invalid, so the model refuses construction with 'shift must be finite.'

Source

Thrown at invokeai/app/invocations/krea2_denoise.py:113

    shift: Optional[float] = InputField(
        default=None,
        description="Override the resolution-aware timestep shift (mu). Leave unset to use the model default "
        "(mu=1.15 for the distilled Turbo checkpoint).",
    )

    @field_validator("cfg_scale")
    @classmethod
    def validate_cfg_scale_is_finite(cls, value: float | list[float]) -> float | list[float]:
        values = value if isinstance(value, list) else [value]
        if not all(math.isfinite(item) for item in values):
            raise ValueError("cfg_scale values must be finite.")
        return value

    @field_validator("shift")
    @classmethod
    def validate_shift_is_finite(cls, value: float | None) -> float | None:
        if value is not None and not math.isfinite(value):
            raise ValueError("shift must be finite.")
        return value

    @torch.no_grad()
    def invoke(self, context: InvocationContext) -> LatentsOutput:
        latents = self._run_diffusion(context)
        latents = latents.detach().to("cpu")
        name = context.tensors.save(tensor=latents)
        return LatentsOutput.build(latents_name=name, latents=latents, seed=None)

    def _prep_inpaint_mask(self, context: InvocationContext, latents: torch.Tensor) -> torch.Tensor | None:
        if self.denoise_mask is None:
            return None
        mask = context.tensors.load(self.denoise_mask.mask_name)
        mask = 1.0 - mask
        _, _, latent_height, latent_width = latents.shape
        mask = tv_resize(
            img=mask,
            size=[latent_height, latent_width],

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Pass a finite float (or omit/None to use the default shift), e.g. shift=3.0.
  2. Coerce bad computed values to None instead of NaN when the shift is unknown.
  3. Guard with math.isfinite(value) before assigning shift.

Example fix

// before
shift=float("nan")  # raises
// after
shift=None  # use default, or e.g. shift=3.0
Defensive patterns

Strategy: validation

Validate before calling

import math
def shift_ok(v) -> bool:
    return v is None or (isinstance(v, (int, float)) and math.isfinite(v))

Type guard

def is_finite_shift(v: object) -> bool:
    return v is None or (isinstance(v, (int, float)) and math.isfinite(v))

Try / catch

try:
    node = Krea2DenoiseInvocation(**params)
except ValueError as e:
    if "shift must be finite" in str(e):
        params["shift"] = None  # fall back to default
        node = Krea2DenoiseInvocation(**params)

Prevention

When it happens

Trigger: Constructing/deserializing the Krea2 denoise invocation with shift=nan, shift=float('inf'), or equivalent JSON 'NaN'/'Infinity' literals; leaving a computed shift of None is fine, only explicit non-finite floats fail.

Common situations: Computing shift from model metadata where a missing value became NaN instead of None; hand-written API payloads containing Infinity; interpolation code dividing by zero.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/de653df30aa7249b. Report an issue: GitHub.