# Repository Briefing: Nynxz/ComfyUI-PlatoKeys
> Source: https://repoforai.com/repo/Nynxz/ComfyUI-PlatoKeys (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/Nynxz/ComfyUI-PlatoKeys
- **Category**: Voice, Vision & Video (语音 / 视觉 / 视频生成)
- **Primary Language**: Python
- **License**: Apache-2.0
- **Engineering Health**: A (76/100 · Maintenance 35/35 · Adoption 10/25 · Releases 11/20 · License 20/20)
- **Review Snapshot**: 2026-12-04
- **Deployment / Stack Signals**: Local AI, CLI, GPU
- **Momentum**: 38 ★ total (+0 24h / +33 7d) · 4 forks
- **When to Use**: Best for: Local ComfyUI teams that want to reuse a smaller or vision-capable encoder, have a matching key or can calibrate one, and can compare outputs against the native path. Skip if: You need native conditioning fidelity, cannot maintain checkpoint-to-key compatibility, or need proven image-quality and speed gains without running your own evaluation.

## Overview
```text
### Architecture & Core Mechanics
PlatoKeys is a Python custom-node extension for ComfyUI V3 that separates encoder calibration from inference. The calibration CLI loads the source and target encoders sequentially and accumulates weighted first- and second-order statistics in float64. Memory for those statistics does not grow with the number of token pairs, but the matrices still grow with feature width. A thin SVD yields the semi-orthogonal Procrustes map; closed-form Ridge provides a regularized fit that can adjust individual channel scales.

At inference, Load Plato Key supplies a safetensors projection and metadata to the graph. Plato Key Encode handles prompt encoding directly, while Patch CLIP clones the CLIP object and wraps tokenization and encoding for downstream consumers. Both use the key’s layer, normalization, chat-template, and prefix-strip settings; temporary overrides of SDClipModel defaults are restored in a finally block without modifying ComfyUI core. The manifest declares safetensors as its only direct dependency; node execution relies on the ComfyUI host.

### Key Capabilities & Differentiators
The extension handles both single-layer targets and stacked hidden states. For Krea 2, it aligns calibration pairs across different tokenizers using UTF-8 byte spans, projects into the 12 Qwen3-VL-4B layer taps, then flattens [B, 12, seq, 2560] into [B, seq, 30720]. Patch CLIP can also project visual tokens from a compatible source encoder, as in the Qwen3-VL-4B → Z-Image route.

The MOSS-Image Qwen3.5-2B → Qwen3.5-9B Ridge key is 16.8 MB, with held-out token cosine of 0.8978 and R² of 0.7486. The Krea 2 Qwen3.5-2B and 9B routes use 121 MB and 241 MB keys, with R² values of 0.7412 and 0.7723, respectively. Compare Conditioning can check mapped tensors against native ones; Compose Plato Keys can combine compatible routes through a hub into a single inference projection.

### Trade-offs & Limitations
The native encoder is the baseline when conditioning fidelity and minimal integration work take priority. PlatoKeys is useful when a different source encoder is worth the extra compatibility checks: the target encoder can stay out of the mapped inference branch, but the source checkpoint, extraction layer, normalization, template, and prefix handling must match the key. A smaller source can reduce encoder cost; a larger source or a wide multi-layer projection can instead add overhead. Key file size is not a measurement of runtime VRAM.

Compared with training a learned adapter, a closed-form fit removes the gradient-training loop but limits the mapping to what can be recovered linearly from the source representations. Calibration fit scores characterize hidden states, not image quality, prompt adherence, or end-to-end speed. Before replacing the native path, run an A/B comparison on representative prompts and any visual inputs, and measure memory and runtime on the full graph.

### Hardware & Deployment Guide
Install the source checkout under ComfyUI/custom_nodes and restart ComfyUI. Put a matching pre-calibrated key in ComfyUI/models/plato_keys/ or register an alternate location through extra_model_paths.yaml. Once the models and key are local, inference does not require a hosted API. The manifest identifies package version 0.1.0, but no GitHub release is listed, so record the working plugin and ComfyUI revisions alongside the encoder checkpoints and key file.

For a custom route, scripts/calibrate_comfy.py consumes local ComfyUI checkpoints and supports quantized int8/fp8 inputs and multi-layer extraction. scripts/calibrate.py provides the Hugging Face path and has a companion Colab notebook. Its --target-8bit and --target-4bit flags are options for fitting Qwen3.5-9B calibration on a 16 GB GPU. Use --save-stats and --from-stats to refit on CPU without rerunning the encoder passes.
```

## Key Capabilities
```text
- Calibration: Streaming float64 statistics support semi-orthogonal Procrustes via thin SVD and closed-form Ridge without storing every token pair.
- Tokenizer alignment: UTF-8 byte-span pairing calibrates routes across Qwen3.5 and Qwen3-VL tokenizers.
- Multi-layer output: Krea 2 keys project 12 layers and flatten the 12 × 2,560 stack into 30,720 channels per token.
- Graph integration: Patch CLIP preserves the CLIP-facing interface for downstream text and visual nodes; Apply Plato Key handles existing single-layer conditioning.
- Key composition: The Hub node folds compatible A → Hub → B maps into one projection and supports documented 2D and stacked key forms.
- Validation: Compare Conditioning exposes per-token cosine, RMS ratio, and relative L2 against native target conditioning.
```

## Quick Start / Clone
```bash
cd ComfyUI/custom_nodes
git clone https://github.com/Nynxz/ComfyUI-PlatoKeys
```
