Plato's Key Use any text encoder with any models - details and setup guide | comfyui

Plato's Key starts with a practical question for anyone running AI models locally: even when two neural networks are trained separately with different sizes, architectures, or tokenizers, do their internal representations line up closely enough that a simple mathematical map can translate between them without retraining? Instead of fine-tuning heavy checkpoints or running gradient descent, a closed-form linear projection—using a rotation, scaling, or ridge fit—can translate hidden states from one encoder into the representation space another model expects.

Following Stanford Hazy Research's November 25, 2026 blog post on Plato's Key (hazyresearch.stanford.edu), the open-source ComfyUI-PlatoKeys node pack (github.com/Nynxz/ComfyUI-PlatoKeys) brings cross-encoder conditioning alignment into ComfyUI. In practice, that lets you encode prompts (and even visual inputs via patched CLIP) with a smaller, faster encoder to save memory—or route a stronger encoder into a model without retraining the diffusion checkpoint.

Animated Graph 1: Closed-Form Representation Mapping in ComfyUI
1. Source Encoder Qwen3.5-2B / Qwen3.5-9B or Gemma 4 (E2B / E4B) Extracts hidden states 2. Plato's Key (.safetensors) Closed-Form Linear Map Procrustes / Ridge + Scale Layer & template parity Zero Model Retraining 3. Target Conditioning MOSS-Image (Qwen3.5-9B) Krea 2 (12-layer) / Z-Image Feeds KSampler / UNet

What Is Plato's Key?

In Stanford Hazy Research's study, researchers examined the Platonic Representation Hypothesis across 12 base language models spanning eight model families (from 1.5B to 27B parameters). Rather than only measuring geometric similarity, they tested whether one model's hidden states could functionally serve inside another model without gradient descent.

Key takeaways from the research and its ComfyUI adaptation include:

  • Closed-Form Alignment Without Retraining: A lightweight linear mapping—such as an orthogonal Procrustes rotation and global scale, or ridge regression—can project source representations into a target space using paired calibration examples.
  • Chaining & Lower-Dimensional Structure: Rotations can chain across intermediate spaces (such as A -> B -> C) while retaining high transfer accuracy, and lower-rank projections still capture a large share of transfer performance.
  • Cross-Tokenizer & Multi-Layer Support in ComfyUI: ComfyUI-PlatoKeys supports single-layer targets (like MOSS-Image's Qwen3.5-9B space) as well as multi-layer stacks (like Krea 2's 12-layer Qwen3-VL-4B conditioning) using UTF-8 byte-span alignment when tokenizers differ.
  • Automatic Metadata Parity: Each .safetensors key stores header metadata for target layer selection, normalization, chat templates, and prefix stripping so nodes apply the matching behavior automatically.
ComfyUI workflow showing CLIPLoader, Load Plato Key, and Plato Key Encode connected to a sampler
a screenshot of your complete ComfyUI graph showing Load Plato Key and Plato Key Encode (or Patch CLIP) connected to your diffusion model.

Hugging Face Download Links & Pre-Calibrated Keys

Pre-calibrated .safetensors keys are hosted on Hugging Face under nynxz/PlatoKeys and organized into folders including moss_image/, krea2/, z_image/, cross_modal/, and ablations/.

Hugging Face Key Collection: nynxz/PlatoKeys
Browse all folders (moss_image/, krea2/, z_image/, cross_modal/, ablations/) and download individual .safetensors files.
Open nynxz/PlatoKeys on Hugging Face
Target / Folder Key File & Route Approx. Size Direct Hugging Face Link
MOSS-Image
moss_image/
qwen35_2b_to_qwen35_9b_moss_image_ridge.safetensors
(Qwen3.5-2B -> Qwen3.5-9B)
~16.8 MB View on HF / Direct .safetensors
MOSS-Image
moss_image/
qwen35_2b_comfy_to_qwen35_9b_moss_ridge.safetensors
(Qwen3.5-2B stock ComfyUI -> Qwen3.5-9B)
~16.8 MB View on HF / Direct .safetensors
MOSS-Image
moss_image/
gemma4_e4b_4layer_to_qwen35_9b_moss_image_ridge.safetensors
(Gemma 4 E4B 4-layer -> Qwen3.5-9B)
~83.9 MB View on HF / Direct .safetensors
MOSS-Image
moss_image/
gemma4_e2b_4layer_to_qwen35_9b_moss_image_ridge.safetensors
(Gemma 4 E2B 4-layer -> Qwen3.5-9B)
~50.5 MB View on HF / Direct .safetensors
MOSS-Image
moss_image/
qwen35_9b_to_qwen35_2b_moss_image_ridge.safetensors
(Qwen3.5-9B -> Qwen3.5-2B reverse)
~16.8 MB View on HF / Direct .safetensors
Krea 2
krea2/
qwen35_9b_to_qwen3vl_4b_krea2_ridge.safetensors
(Qwen3.5-9B -> Krea 2 12-layer)
~241 MB View on HF / Direct .safetensors
Krea 2
krea2/
qwen35_2b_to_qwen3vl_4b_krea2_ridge.safetensors
(Qwen3.5-2B -> Krea 2 12-layer)
~121 MB View on HF / Direct .safetensors
Krea 2
krea2/
gemma4_e4b_12layer_to_qwen3vl_4b_krea2_ridge.safetensors
(Gemma 4 E4B -> Krea 2)
~157.5 MB View on HF / Direct .safetensors
Krea 2
krea2/
gemma4_e2b_12layer_to_qwen3vl_4b_krea2_ridge.safetensors
(Gemma 4 E2B -> Krea 2)
~94.6 MB View on HF / Direct .safetensors
Z-Image
z_image/
qwen3vl_4b_to_zimage_qwen3_4b_ridge.safetensors
(Qwen3-VL-4B -> Z-Image Qwen3-4B)
~13.1 MB View on HF / Direct .safetensors
Z-Image
z_image/
gemma4_e4b_4layer_to_zimage_qwen3_4b_ridge.safetensors
(Gemma 4 E4B 4-layer -> Z-Image)
~52.5 MB View on HF / Direct .safetensors
Z-Image
z_image/
gemma4_e2b_4layer_to_zimage_qwen3_4b_ridge.safetensors
(Gemma 4 E2B 4-layer -> Z-Image)
~31.5 MB View on HF / Direct .safetensors
10s Action Test: 6-Way Model Comparison (Tokyo Neon Rain Alley & Medieval Blacksmith Forge)

Beginner Step-by-Step Guide: Using Plato's Key in ComfyUI

Follow these steps carefully to install the custom node pack, place your downloaded keys, and wire up a working workflow without altering ComfyUI's core files.

Step 1: Clone ComfyUI-PlatoKeys into custom_nodes

Open a terminal inside your ComfyUI custom_nodes directory, clone the repository, and restart ComfyUI:

cd ComfyUI/custom_nodes
git clone https://github.com/Nynxz/ComfyUI-PlatoKeys

Step 2: Save .safetensors Keys in ComfyUI/models/plato_keys/

Place your downloaded .safetensors keys into ComfyUI/models/plato_keys/. You can preserve subfolders such as moss_image/, krea2/, or z_image/—ComfyUI registers and scans them automatically.

ComfyUI/
  models/
    plato_keys/
      moss_image/
        qwen35_2b_to_qwen35_9b_moss_image_ridge.safetensors
      krea2/
        qwen35_2b_to_qwen3vl_4b_krea2_ridge.safetensors

Step 3: Understand the Available Nodes

In ComfyUI, find the nodes under conditioning/plato keys:

  • Load Plato Key: Loads a .safetensors key file and outputs PLATO_KEY along with metadata and held-out calibration metrics.
  • Plato Key Encode: A drop-in alternative to CLIPTextEncode that takes clip, plato_key, and text, applies the key's calibrated layer, chat template, and prefix settings automatically, and outputs CONDITIONING.
  • Patch CLIP (Plato Key): Clones and wraps a CLIP object with a PLATO_KEY so downstream nodes—including CLIPTextEncode, Visual Fusion, Layout/Regions, or image-edit encoders—receive target-space conditioning seamlessly.
  • Apply Plato Key: Projects an existing single-layer CONDITIONING wire directly when your upstream encoder already matches the key's layer and template (for multi-layer targets like Krea 2, use Patch CLIP (Plato Key) or Plato Key Encode).
  • Compose Plato Keys (Hub): Analytically combines two keys (A -> Hub and Hub -> B) into a single A -> B key.
  • Compare Conditioning (Plato Key): Diagnostic node comparing mapped conditioning against native target conditioning (shapes, RMS ratio, per-token cosine similarity, and relative L2).
Animated Graph 2: Two Beginner Wiring Patterns in ComfyUI
Pattern 1: Plato Key Encode (Single-Layer Targets like MOSS-Image / Z-Image) CLIPLoader Source Encoder (e.g. 2B) Load Plato Key Select .safetensors key Plato Key Encode Prompt + Key -> Cond KSampler Positive Cond Pattern 2: Patch CLIP (Plato Key) (Multi-Layer Krea 2 & Downstream CLIP Nodes) CLIPLoader Qwen3.5-9B or 2B Patch CLIP (Plato Key) Wraps CLIP + PLATO_KEY CLIPTextEncode or Fusion / Edit Node KSampler Multi-Layer Cond

Step 4: Practical Tips for Distilled Models & Samplers

  • Distilled Models (cfg = 1): For distilled workflows such as Krea 2 Turbo or MOSS DMD2, wire ConditioningZeroOut into the negative conditioning input of your sampler.
  • Match Source Encoder to Key: Make sure the text encoder loaded in CLIPLoader matches the source side of the .safetensors key you selected in Load Plato Key.

Calibrating Custom Keys (Optional)

If you want to fit your own key using local ComfyUI checkpoints (including quantized weights or custom prompt sets) or Hugging Face models / Colab notebooks, the repository provides scripts/calibrate_comfy.py and scripts/calibrate.py (along with colab/calibrate_qwen35_moss.ipynb).

python scripts/calibrate_comfy.py \
  --comfy-dir /path/to/ComfyUI \
  --preset krea2 \
  --source-ckpt /path/to/qwen3.5_9b_int8_convrot.safetensors \
  --source-clip-type qwen_image \
  --target-ckpt /path/to/qwen3vl_4b_bf16.safetensors \
  --target-clip-type krea2 \
  --num-prompts 2000 \
  --out-dir keys \
  --file-prefix qwen35_9b_to_qwen3vl_4b_krea2
Comparison of images generated using a Plato's Key mapped encoder versus a native encoder
a side-by-side output comparison showing visual results, prompt detail, and VRAM/speed notes from your own test run.

Join JOTE SOFT & Community: Have you tried ComfyUI-PlatoKeys with MOSS-Image, Krea 2, or Z-Image? Share your tests, workflow notes, and questions with the community on jote.top and Telegram (t.me/emubros / t.me/switchbro).

Disclaimer: This guide is provided by JOTE SOFT for educational and informational purposes. All referenced research papers, open-source tools, and model weights belong to their respective creators and remain governed by their original licenses. If you notice any outdated link or need help with a workflow, leave a message through jote.top.

No comments:

Post a Comment

// SYSTEM_STATUS