Nodes/ComfyUI-sonar/SonarLatentOperationSetSeed
ComfyUI Node

SonarLatentOperationSetSeed

Give one latent operation its own seed, mid-pipeline

By blepping·Created 3 years ago·Updated 15 days ago· 49
SonarLatentOperationSetSeed
  • operation
  • LATENT_OPERATION
seed0
restore_rng_statefalse

SonarLatentOperationSetSeed is a small utility and it knows it: it wraps another LATENT_OPERATION and sets the seed right before that operation runs. The use case in the node description is the sharp one - latent operations that generate noise outside a normal sampling context, like running noise-generating operations on the initial latent before sampling even starts. In those contexts nothing is managing the RNG the way a sampler would, so your noise isn't reproducible. This node makes it reproducible.

How it works

  • operation - the LATENT_OPERATION you want to seed.
  • seed - the seed to set. The tooltip spells out the catch: it's called every time before the operation, not once.
  • restore_rng_state - default false. When enabled, the current RNG state is saved before the operation runs and restored after, so the seed you set only affects the operation itself and nothing downstream. The tooltip notes this only covers the PyTorch and Python random module states.

Output is a LATENT_OPERATION, so it wraps transparently - whatever the inner operation did, you get it back with deterministic noise.

Why you'd bother

Noise-generating latent operations are non-deterministic by default: every queue run draws fresh random values. That's fine for exploration and maddening when you've finally tuned something and want it to stay put. Wrapping the operation in this node pins its noise to a seed - and with restore_rng_state on, the rest of your pipeline keeps behaving as if the seed were never touched. It's the reproducibility tool for the SonarLatentOperationNoise-style nodes, and it becomes essential the moment you build a workflow around operations on the pre-sampling latent.

The trap

Because the seed is set on every call, this node interacts badly with anything that calls the operation repeatedly and expects progression. If you're feeding it an operation that runs once per step, you've pinned all steps to the same draw. That's usually exactly what you want for a stable starting noise - but if you notice a repeating pattern or identical noise at every stage, this is why, and the fix is to restructure so the seeding wraps a one-shot operation.

Install

ComfyUI Manager → search "ComfyUI-sonar" → Install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/blepping/ComfyUI-sonar

No models, no extra deps. This is the rare pack node with zero GPU/CPU seed weirdness of its own - it's all about taming the seed weirdness of the operations around it.

Categorylatent/advanced/operations

Inputs (3)

NameTypeDefaultDescription
operationLATENT_OPERATION
seedINT00–18446744073709550000Seed to set. Note that this is called _every time_ before the operation.
restore_rng_stateBOOLEANfalseWhen enabled, the current RNG state is saved just before calling the operation and restored afterwards. In other words, only the latent operation will see the seed you set. Note: This only handles the PyTorch and Python random module states.

Outputs (1)

NameTypeDescription
LATENT_OPERATIONLATENT_OPERATION