diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

Per-token FlowMatch Euler sign differs from scalar path; model parity unverified

Open davrens101 opened this issue 3 weeks ago • 2 comments

Describe the bug

FlowMatchEulerDiscreteScheduler.step reverses the deterministic velocity sign when per_token_timesteps is supplied. A zero sample with unit velocity and sigma changing from 1 to 0.5 should advance to -0.5, regardless of whether timesteps are scalar or per-token.

The shipped LTXCondition and SanaWM pipelines compensate by negating the model prediction. That preserves their deterministic updates, but supplies the wrong velocity to the stochastic clean-sample estimate x0 = sample - sigma * velocity.

PR #15177 corrects the scheduler sign and removes both caller compensations. External per-token callers using the old negation must remove it too.

Reproduction

import torch
from diffusers import FlowMatchEulerDiscreteScheduler

sample = torch.zeros(1, 2, 3)
velocity = torch.ones_like(sample)
for per_token in (False, True):
    scheduler = FlowMatchEulerDiscreteScheduler(shift=1)
    scheduler.set_timesteps(sigmas=[1.0, 0.5])
    kwargs = {"per_token_timesteps": torch.full((1, 2), 1000.0)} if per_token else {}
    result = scheduler.step(velocity, scheduler.timesteps[0], sample, **kwargs).prev_sample
    print("per_token =", per_token, ":", result.flatten().tolist())

Observed output

per_token = False : [-0.5, -0.5, -0.5, -0.5, -0.5, -0.5]
per_token = True : [0.5, 0.5, 0.5, 0.5, 0.5, 0.5]

Expected: both paths return six -0.5 values. The fixed code in #15177 does so.

System Info

Reproduced on CPU, Windows, Python 3.12.6, PyTorch 2.15.0+cpu, Diffusers 0.42.0.dev0. The failing run used the scheduler source from the parent of PR commit f7ccd237da58da699001678f1a9c35bd0dee4651; the passing run used that PR commit. No GPU or generation-quality claim.

Assistance

Filed by an AI coding agent at the contributor's request, following the maintainer permission reported by the contributor. I supervised and checked the AI-assisted work as it progressed. No independent maintainer approval of the fix is claimed.

davrens101 avatar Nov 05 '26 07:11 davrens101

Thanks for reporting this issue but note that changes in https://github.com/huggingface/diffusers/pull/15177 seem incomplete without visual validation. Our integrations follow parity checking so the bug you're describing doesn't sound appropriate from that perspective. Also, what is more interesting is that SanaWM pipeline was contributed by the actual team (cc: @lawrence-cj).

sayakpaul avatar Nov 09 '26 07:11 sayakpaul

The scalar/per-token sign comparison is not enough to establish a pipeline bug. I have not provided visual parity against the reference implementation or shown that the SanaWM callers should change. I moved #15177 back to draft; the earlier local-check statement should not have implied that this was validated end to end.

davrens101 avatar Nov 12 '26 04:11 davrens101