Nodes/Deforum Nodes/(deforum) Shuffle Tokenizer
ComfyUI Node

(deforum) Shuffle Tokenizer

The weirdest way to remix a CLIP's vocabulary

By XmYx·Created 3 years ago·Updated 3 months ago· 198
(deforum) Shuffle Tokenizer
  • clip
  • CLIP
seed0

This is the strangest node in the pack, and I mean that as a compliment. Take a CLIP, hand it a seed, and the node shuffles the tokenizer's entire vocabulary - the mapping of words to token IDs - then hands the same CLIP back. Every word now encodes to a different token, so every prompt you write with that CLIP means something semantically scrambled but reproducibly scrambled. Same seed, same shuffle, same weirdness.

Why would anyone want that? Two honest reasons. First, it's an exploration tool: prompt "a red cat" and get whatever the shuffled vocabulary maps those tokens to - a way to stumble into visual ideas a sane vocabulary would never produce. Second, it's a reproducibility trick for prompt-engineering experiments: instead of editing your prompt, you can sweep seeds and get systematically different semantic mappings. That's the theory, anyway.

The one-liner caveat: the source itself is openly hacky. It copies the vocab, shuffles with a seeded RNG, and writes it straight back onto the tokenizer object with a comment admitting this "is highly dependent on the tokenizer's implementation." It may work beautifully on one CLIP and do nothing (or worse, nothing visible) on another. Treat it as a toy with sharp edges.

Inputs and output

  • clip - a CLIP object (from Load CLIP / CLIPLoader). The node mutates its tokenizer in place.
  • seed - the shuffle seed. Same seed → same vocabulary → same results.
  • Output: CLIP - the same object, now with the shuffled vocab. Wire it into a CLIPTextEncode and the scrambling takes effect.

How it works

It copies clip.tokenizer.vocab, builds a seeded random.Random(seed), shuffles the items into a new dict, and assigns it back as tokenizer.vocab. There's no model retraining, no checkpoint, no file written. The original vocabulary is only preserved in memory as a copy - meaning a new shuffle overwrites the previous one, and the "restoration" path mentioned in comments isn't actually implemented. Reload the CLIP node to get the original vocab back.

Installation

Part of Deforum Nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/XmYx/deforum-comfy-nodes.git

Restart ComfyUI, or install "Deforum Nodes" by XmYx via ComfyUI Manager. No extra dependencies beyond the pack and a loaded CLIP.

Practical warnings

  • The shuffle is global to the CLIP object. If you shuffle and then try to run a normal workflow with that same CLIP in the same session, your "normal" prompts come out scrambled too. Reload the model (or restart) to clear it.
  • Results vary by tokenizer. The CLIP implementations differ under the hood, and the node's own comments admit the mutation is implementation-dependent. If a workflow using this node seems to ignore the shuffle, that's the likely reason.
  • Don't build a production pipeline on it. This is an experimental conditioning hack in the spirit of the pack's _for_testing energy. Fun to explore, fragile to depend on.
Categorydeforum/conditioning

Inputs (2)

NameTypeDefaultDescription
clipCLIP
seedINT00–18446744073709550000

Outputs (1)

NameTypeDescription
CLIPCLIP