Skip to content

moss_image: the schedule from scheduler_config.json natively, bit for bit MOSSImageScheduler's - #1670

Open
BobClawblaw wants to merge 2 commits into
ashhart:mainfrom
BobClawblaw:moss-schedule
Open

BobClawblaw wants to merge 2 commits into
ashhart:mainfrom
BobClawblaw:moss-schedule

Conversation

@BobClawblaw

Copy link
Copy Markdown
Contributor

Part of #1529. Builds on #1668: its first commit is #1668's.

moss_image.schedule computes the timesteps and noise levels that the pipeline's MOSSImageScheduler sets:

  • a float32 grid shifted by shift;
  • snapped to the nearest of the num_train_timesteps training levels, which are shifted by training_shift;
  • repeats dropped, and sigmas ending at 0.

torch's CPU linspace fuses its multiply-add, and so does this; unfused, 850 of 897 test grids differ from torch.

Config: it reads the three settings above. It refuses a config that turns on Karras, exponential or beta sigmas, dynamic shifting, shift_terminal, inverted sigmas or stochastic sampling. diffusers warns that MOSSImageScheduler ignores those keys, but I checked and its base scheduler applies them.

Checks

  • moss_image_case.py schedule records sha256s of the scheduler's own timesteps and sigmas: 21 step counts from 1 to 2000, times 5 configs (the released one, shift 3.0 and 7.5, training_shift 2.0, num_train_timesteps 500).
  • zig build test checks all 105, on aarch64 and on x86.
  • An unfused linspace fails the test.
  • torch gives the same bits on x86, a GB10 and a Mac, and on torch 2.11, 2.13 and 2.14. The image size doesn't enter, because the released config has no dynamic shifting.

Not in this PR

The issue's third item, gating tf-moss-image's teacher check per step against float32. It builds on #1512's gate code and needs a Mac run with float32 references for every step, so it follows once #1512 lands. Switching tf-moss-image from the case's schedule to this one belongs with #1531.

Host code only, with no kernels and no shared code. lean shows 0 new problems.

…orch.randn's on any CPU

The pipeline starts from torch.randn on a CPU generator seeded with manual_seed. moss_image.noise computes those
latents in the family's host code: torch's mt19937 and its float uniforms, then the Box-Muller pass over 16 values
that x86 torch takes, with avx_mathfun.h's log and sincos and their multiply-adds fused as GCC fuses them in torch's
build. ARM torch takes a libm path, so its bits differ from x86 torch's in the last places (for seed 42 at 1024x1024,
200,873 of 524,288 values on a Mac, by at most 2.2e-6). The native generator gives x86 torch's bits on every CPU.

moss_image_case.py noise records sha256s of x86 torch's latents (torch 2.13.0, AVX512) for 24 seeds and 9 sizes,
69 cases, in the case's rows x columns x 128 layout; zig build test checks every one. Host code only: no kernels and
no shared code.
… bit MOSSImageScheduler's

moss_image.schedule computes the timesteps and noise levels the pipeline's MOSSImageScheduler sets: a float32 grid
shifted by `shift`, snapped to the nearest of the `num_train_timesteps` training levels (shifted by `training_shift`),
repeats dropped, sigmas ending at 0. torch.linspace's CPU kernel fuses its multiply-add, and so does this. A config
turning on Karras, exponential or beta sigmas, dynamic shifting, shift_terminal, inverted sigmas or stochastic
sampling is refused: diffusers warns it ignores them, but its base scheduler applies them.

moss_image_case.py schedule records sha256s of the scheduler's own timesteps and sigmas for 21 step counts (1 to
2000) and 5 configs; zig build test checks all 105. torch gives the same bits on x86, a GB10 and a Mac.
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.

1 participant