Download klein9/docs/FLUX2_KLEIN9_REFMODS_GUIDE.md from malcolmrey/various: direct link, hf CLI and curl.
- Browser
- Download file 24.6 kB
-
https://huggingface.co/datasets/malcolmrey/various/resolve/main/klein9/docs/FLUX2_KLEIN9_REFMODS_GUIDE.md
- Command line
-
hf download hf://datasets/malcolmrey/various/klein9/docs/FLUX2_KLEIN9_REFMODS_GUIDE.md
-
curl -L -o FLUX2_KLEIN9_REFMODS_GUIDE.md https://huggingface.co/datasets/malcolmrey/various/resolve/main/klein9/docs/FLUX2_KLEIN9_REFMODS_GUIDE.md
FLUX.2 & Klein 9B RefMods: Comprehensive Architecture, Extraction, and Usage Guide
Version: 1.0.0
Last Updated: September 2026
Target Architecture: FLUX.2 / Klein 4B / Klein 8B / Klein 9B + ComfyUI-Flux2Klein9Mod
Open Weight Repository: huggingface.co/malcolmrey/klein9
Custom Node Repository: github.com/malcolmamal/ComfyUI-Flux2Klein9Mod
1. Executive Summary: What Are RefMods?
RefMods (Reference Latent Adapters) are compact, pre-encoded .safetensors files (~1.2 MB – 6.0 MB) containing compressed conditioning latents extracted through the FLUX.2 / Klein VAE.
In modern flow-matching architectures (FLUX.2, Klein 4B, Klein 8B, Klein 9B), reference imagery is injected directly into the joint sequence via 2D Rotary Position Embedding (RoPE) coordinates alongside text tokens and noisy latents. Standard reference workflows resize and VAE-encode raw uncompressed images on every single generation run, which introduces substantial latency, explodes token budgets (e.g. 4,096+ tokens per 1024px reference image), and spikes VRAM consumption.
A RefMod pre-encodes reference imagery once from a dataset and stores the spatial latent representation on disk. At inference time, the pre-computed latents are loaded directly into GPU memory in milliseconds and injected into standard ComfyUI CONDITIONING (reference_latents) with zero live VAE latency, configurable token budgets, and seamless multi-character scaling.
┌───────────────────────────────────────────────────────────────────────────────┐
│ TRADITIONAL REFERENCE IMAGES │
│ │
│ [Raw 4K/1024px Images] ──► [Live VAE Encode] ──► [4,096+ Tokens/Img] ──► DiT │
│ (1.2s - 2.5s lag) (Heavy Attention) │
└───────────────────────────────────────────────────────────────────────────────┘
VS
┌───────────────────────────────────────────────────────────────────────────────┐
│ KLEIN9 / FLUX.2 REFMODS │
│ │
│ [Pre-encoded .safetensors] ──► [Instant Load] ──► [512-1024 Tokens] ──► DiT │
│ (models/refmods-klein9/) (<5ms latency) (Lightweight & Fast) │
└───────────────────────────────────────────────────────────────────────────────┘
2. Architectural Comparison: RefMods vs Legacy Reference Images vs LoRAs
| Dimension | Legacy Raw Reference Images | Pure Trained LoRA | Klein9 / FLUX.2 RefMod | Hybrid RefMod + LoRA Stack |
|---|---|---|---|---|
| Training Requirement | None (Zero training) | Requires 500–2,000 training steps (10–30 min GPU time) | Zero training (Instant 1-pass VAE extraction) | Trained LoRA + 1-pass RefMod extraction |
| Generation Latency | High (Encodes images on every generation run) | Zero overhead (Pre-baked model weights) | Zero overhead (Pre-computed latents loaded in <5ms) | Zero overhead |
| Token & Attention Load | Extreme (4,096+ tokens per 1024px image; ~8,192 for 8 images) | 0 extra tokens | 512 – 1,024 tokens (adaptive spatial pooling) | 512 – 1,024 tokens |
| VRAM Spike Risk | High (Risk of OOM during multi-image live VAE encoding) | Low | Low & Flat | Low & Flat |
| Multi-Subject Scaling | Cluttered graph with multiple image and VAE nodes | Single LoRA or complex multi-LoRA stacking | Up to 8 RefMods in one node (mod_1..mod_8) |
Up to 8 RefMods + LoRAs |
| Strength Modulation | Pixel-space opacity fading (causes washed-out ghosting) | Weight scaling (0.0 – 1.5) |
Manifold Low-Pass Blurring (preserves latent coherence) | Independent LoRA and RefMod dials |
| File Format & Size | Multiple raw PNG/JPG files (10 MB – 50 MB) | Single .safetensors (20 MB – 300 MB) |
Single .safetensors (~1.2 MB – 6.0 MB) |
Combined ecosystem |
3. Where to Download RefMods
Over 1,400+ pre-extracted RefMods for celebrities, characters, and concepts are hosted and maintained on the Hugging Face Hub:
- Interactive Visual Model Browser: https://huggingface.co/spaces/malcolmrey/browser
Easily search, preview, filter, and find any celebrity, persona, character, or concept RefMod with live visual previews. - Hugging Face Model Repository: https://huggingface.co/malcolmrey/klein9
- Model Storage Directory in ComfyUI:
ComfyUI/models/refmods-klein9/
File Naming Convention
- RefMod Files:
fk9_<character_name>_v1_refmod.safetensors(e.g.fk9_alisonbrie_v1_refmod.safetensors,fk9_brettcooper_v1_refmod.safetensors) - Paired Prodigy LoRAs (Optional):
fk9_<character_name>_v1_prodigy.safetensors
Download Methods
Method A: Interactive Visual Search & Download
- Open the Malcolmrey Browser Space.
- Search for the desired character/subject (e.g. "Alison Brie", "Whoopi Goldberg", "Brett Cooper").
- Download the
.safetensorsRefMod and place it intoComfyUI/models/refmods-klein9/.
Method B: Hugging Face CLI (hf)
# Download a specific RefMod directly into your ComfyUI models folder
hf hub download malcolmrey/klein9 fk9_alisonbrie_v1_refmod.safetensors --local-dir C:/Development/ComfyUI/models/refmods-klein9
# Download all RefMods matching a pattern
hf hub download malcolmrey/klein9 --include "fk9_*_refmod.safetensors" --local-dir C:/Development/ComfyUI/models/refmods-klein9
Method C: Git LFS Clone
cd C:/Development/projects/huggingface
git clone git@hf.co:malcolmrey/klein9
4. Where to Put RefMods & Directory Layout
All FLUX.2 and Klein9 RefMod .safetensors files must be placed inside the dedicated models/refmods-klein9/ folder:
ComfyUI/
├── custom_nodes/
│ └── ComfyUI-Flux2Klein9Mod/
├── models/
│ ├── checkpoints/
│ ├── loras/
│ ├── vae/
│ │ └── flux2_vae.safetensors
│ ├── refmods/ <── MiniMax-H3 Video RefMods
│ └── refmods-klein9/ <── FLUX.2 / Klein9 RefMods (.safetensors)
│ ├── fk9_aaliyah_v1_refmod.safetensors
│ ├── fk9_alisonbrie_v1_refmod.safetensors
│ ├── fk9_brettcooper_v1_refmod.safetensors
│ ├── fk9_jodiefoster_v1_refmod.safetensors
│ ├── fk9_oliviawilde_v1_refmod.safetensors
│ ├── fk9_rebeccaferguson_v1_refmod.safetensors
│ ├── fk9_sydneysweeney_v1_refmod.safetensors
│ └── ...
Note: If
ComfyUI/models/refmods-klein9/does not exist, create it manually or let the custom node / generator script create it automatically.
5. ComfyUI Custom Node Installation
The node package powering the RefMod workflow is ComfyUI-Flux2Klein9Mod.
Installation Steps
Open a terminal in your ComfyUI
custom_nodesfolder:cd ComfyUI/custom_nodesClone the repository:
git clone https://github.com/malcolmamal/ComfyUI-Flux2Klein9Mod.git(Optional) Install dependencies:
pip install -r ComfyUI-Flux2Klein9Mod/requirements.txtRestart ComfyUI.
6. ComfyUI Node Specifications & Workflow Wiring
ComfyUI-Flux2Klein9Mod provides four specialized nodes categorized under model/conditioning/klein9:
1. Load Klein9 RefMods (FLUX.2) (Klein9RefModsLoader)
Loads 1 to 8 RefMods simultaneously from models/refmods-klein9/ with independent strength dials and copy multipliers.
- Inputs:
mod_1..mod_8: Dropdowns listing all.safetensorsinmodels/refmods-klein9/.strength_1..strength_8: Strength multiplier (0.0to3.0, default1.0).copies_1..copies_8: Integer token repeat count (1to8, default1).
- Outputs:
klein9_refmods: Packed mod bundle forKlein9RefModApply.prompt_hint: Informational string summarizing loaded concepts and token counts.
2. Apply Klein9 RefMods (FLUX.2) (Klein9RefModApply)
Injects the loaded RefMod bundle into standard ComfyUI CONDITIONING under the model's native reference_latents key.
- Inputs:
conditioning: Standard ComfyUICONDITIONING(e.g. fromCLIPTextEncode).klein9_refmods: Mod bundle fromKlein9RefModsLoader.retention: Master retention preset:fully_preserved (1.0): 100% likeness retention for strict portrait fidelity.partially_preserved (0.7): Optimal balance allowing extensive prompt styling, clothing changes, and scene variation.attribute_transfer (0.4): Subtle biometric/facial feature transfer without dominating clothing or lighting.weak_reference (0.2): Soft style/mood reference.custom_multiplier: Uses thecustom_retentionnumeric float input.
custom_retention: Float multiplier (0.0–2.0) when custom retention is selected.ref_method: RoPE sequence positioning (default,index,uxo,index_timestep_zero).blend_mode:manifold_blur(Recommended): Weakens latents by blending toward a low-pass spatial blur on the latent manifold, preserving smooth neural correlations without pixel noise.direct_scale: Linear magnitude scaling.
- Outputs:
conditioning: Updated conditioning graph ready for sampling.
3. Extract Klein9 RefMod (FLUX.2) (Klein9RefModExtract)
Performs in-graph VAE encoding and token compression on input images directly to a saved .safetensors file in models/refmods-klein9/.
4. Load RefMod Folder (Images) (Klein9RefModFolderLoader)
Batch loads an entire disk directory of reference stills for in-graph extraction pipelines.
7. Ready-to-Use ComfyUI Workflows & Graph Diagrams
Two production-ready, drag-and-drop ComfyUI JSON workflows are provided in the repository under workflows/:
workflow_klein9_refmod.json: Pure RefMod Text-to-Image workflow for FLUX.2 / Klein 9B.workflow_klein9_refmod_lora.json: Hybrid RefMod + LoRA Power Stack workflow for FLUX.2 / Klein 9B.
Both workflows can be dragged directly onto the ComfyUI canvas or loaded via Load Workflow -> JSON.
Workflow A: Pure RefMod Generation (workflow_klein9_refmod.json)
File location: klein9/workflows/workflow_klein9_refmod.json
Best for: Zero-training instant character and concept likeness with zero VAE latency and compact 1,024-token footprint.
┌──────────────────────────┐
│ UNETLoader │ ──► MODEL ───────────────────────────────────┐
│ (flux-2-klein-9b-fp8) │ │
└──────────────────────────┘ │
┌──────────────────────────┐ │
│ CLIPLoader │ ──► CLIP ──► [ CLIPTextEncode (Prompt) ] │
│ (flux2 clip/t5xxl) │ │ │
└──────────────────────────┘ ▼ (conditioning) ▼
┌──────────────────────────┐ [ Apply Klein9 RefMods ] ──► [ KSampler ]
│ Klein9RefModsLoader │ ────────► (retention: 1.0 / 0.7) (er_sde / simple)
│ (mod_1..mod_8 @ 0.0-3.0) │ (manifold_blur) │
└──────────────────────────┘ ▼
┌──────────────────────────┐ [ VAEDecode ]
│ VAELoader │ ─────────────────────────────────────► (flux2_vae)
│ (flux2_vae.safetensors) │ │
└──────────────────────────┘ ▼
[ SaveImage ]
Key Node Configurations in workflow_klein9_refmod.json:
UNETLoader(Node 1): LoadsFLUX2\flux-2-klein-9b-fp8.safetensors.Klein9RefModsLoader(Node 48): Selects any RefMod frommodels/refmods-klein9/with independent strength (1.0) and copies (1).Klein9RefModApply(Node 49 & Node 50): Injects latents into positive and negative conditioning streams withmanifold_blurmode.KSampler(Node 3): Standard 8-steper_sde/simplesampler at CFG1.0.
Workflow B: Hybrid RefMod + LoRA Stack (workflow_klein9_refmod_lora.json)
File location: klein9/workflows/workflow_klein9_refmod_lora.json
Best for: Maximum possible likeness fidelity and texture rendering by stacking a macro-geometry RefMod with a trained micro-texture LoRA.
┌──────────────────────────┐
│ UNETLoader │ ──► MODEL ──► [ LoraLoaderModelOnly ] ───────┐
│ (flux-2-klein-9b-fp8) │ (fk9_persona_v1_prodigy @ 0.6) │
└──────────────────────────┘ │
┌──────────────────────────┐ │
│ CLIPLoader │ ──► CLIP ──► [ CLIPTextEncode (Prompt) ] │
│ (flux2 clip/t5xxl) │ │ │
└──────────────────────────┘ ▼ (conditioning) ▼
┌──────────────────────────┐ [ Apply Klein9 RefMods ] ──► [ KSampler ]
│ Klein9RefModsLoader │ ────────► (RefMod strength @ 0.85x) (er_sde / simple)
│ (mod_1..mod_8 @ 0.85) │ (retention: 0.70) │
└──────────────────────────┘ ▼
┌──────────────────────────┐ [ VAEDecode ]
│ VAELoader │ ─────────────────────────────────────► (flux2_vae)
│ (flux2_vae.safetensors) │ │
└──────────────────────────┘ ▼
[ SaveImage ]
Recommended Dial Presets:
- RefMod Strength (
Klein9RefModsLoader):0.80–0.90(locks facial geometry, eye alignment, and bone structure). - Master Retention (
Klein9RefModApply):partially_preserved (0.7)(ensures high flexibility for outfit and background changes). - LoRA Strength (
LoraLoaderModelOnly):0.50–0.70(injects realistic skin pores, lighting gradients, and fine details).
8. How to Create / Extract RefMods
You can extract custom RefMods from any image dataset using the automated CLI script or the batch mass extractor.
Dataset Preparation Best Practices
- Image Count: 8 to 24 high-resolution stills.
- Framing & Angles:
- 40% Front portraits: Neutral and smiling expressions, clean eye contact.
- 30% 3/4 angle views: Left and right turns.
- 20% Profile shots: Crisp facial silhouette.
- 10% Upper torso / waist-up: Capturing natural posture and hair volume.
- Lighting & Variety: Use diverse real-world lighting (daylight, warm tungsten, soft diffused) and varied backgrounds so the latent representation isolates invariant facial geometry.
- Resolution: Native high-resolution (1024x1024 or higher). The extractor handles downscaling and 32-pixel alignment automatically.
Method 1: The Standalone CLI Generator (generate_flux2_klein9_refmod.py)
The script is located in various/klein9/generate_flux2_klein9_refmod.py.
# 1. Extract by dataset folder name under C:\Development\ai-toolkit\datasets\
python generate_flux2_klein9_refmod.py brettcooper
# 2. Extract by explicit dataset folder path
python generate_flux2_klein9_refmod.py C:/Development/ai-toolkit/datasets/brettcooper --token-budget 1024
# 3. Dry-run to inspect discovered media and execution plan without encoding
python generate_flux2_klein9_refmod.py brettcooper --dry-run
# 4. Custom RefMod name, concept type, and token budget
python generate_flux2_klein9_refmod.py C:/Development/ai-toolkit/datasets/brettcooper \
--name fk9_brettcooper_v2_refmod \
--concept-type identity \
--token-budget 1024 \
--max-images 20 \
--resolution 1024
CLI Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
target |
Positional | None |
Dataset folder path or name under datasets root |
--all |
Flag | False |
Batch extract all datasets found in --datasets-root |
--datasets-root |
Path | C:/Development/ai-toolkit/datasets |
Directory containing dataset subfolders |
--name |
String | fk9_<folder>_v1_refmod |
Output .safetensors filename |
--vae |
Path | Auto-detected | Path to flux2_vae.safetensors |
--concept-type |
Choice | identity |
identity, style, character, clothing, background, generic |
--token-budget |
Choice | 1024 |
native, 4096, 2048, 1024, 512, 256 |
--resolution |
Int | 1024 |
Maximum image edge resolution in pixels |
--max-images |
Int | 16 |
Maximum reference images to encode per RefMod |
--output-dir |
Path | ComfyUI/models/refmods-klein9/ |
Destination folder |
--dry-run |
Flag | False |
Preview extraction plan without writing files |
--force |
Flag | False |
Overwrite existing .safetensors files |
Method 2: Mass Batch Extraction Across All Datasets
To extract hundreds of RefMods in a single continuous high-speed session with the VAE loaded once into GPU VRAM:
python generate_flux2_klein9_refmod.py --all --datasets-root C:/Development/ai-toolkit/datasets --token-budget 1024
The script automatically skips already generated .safetensors files and processes each dataset sequentially in ~0.8s to 1.5s per subject on modern GPUs.
9. Empirical Benchmarks & 5-Column Visual Studies
Extensive empirical evaluations were conducted comparing five distinct generation paradigms across multiple subjects (Brett Cooper, Alison Brie, Olivia Wilde, Jodie Foster, Rebecca Ferguson, and Sydney Sweeney).
Detailed visual grids, single run links, and direct model downloads are documented in VISUAL_BENCHMARKS_AND_COMPARISONS.md.
Column 1: Pure LoRA @ 1.0 (Trained Prodigy LoRA only)
Column 2: 8-Raw-Reference Images (Live VAE encode, ~8,192 tokens)
Column 3: 8-Raw-Reference Images + LoRA Stack
Column 4: Pure RefMod @ 1.0 (Pre-encoded .safetensors, 1,024 tokens, Zero Training)
Column 5: RefMod + LoRA Hybrid Stack (RefMod @ 0.85x + LoRA @ 0.70x)
Visual Benchmark Grids (docs/examples/)
- Brett Cooper 5-Col Comparison (
examples/Flux2-Klein9-BrettCooper-5Col-Comparison-Grid.png) - Alison Brie 5-Col Comparison (
examples/Flux2-Klein9-AlisonBrie-5Col-Comparison-Grid.png) - Olivia Wilde 5-Col Comparison (
examples/Flux2-Klein9-OliviaWilde-5Col-Comparison-Grid.png) - Jodie Foster 5-Col Comparison (
examples/Flux2-Klein9-JodieFoster-5Col-Comparison-Grid.png) - Rebecca Ferguson 5-Col Comparison (
examples/Flux2-Klein9-RebeccaFerguson-5Col-Comparison-Grid.png) - Sydney Sweeney 5-Col Comparison (
examples/Flux2-Klein9-SydneySweeney-5Col-Comparison-Grid.png)
Key Empirical Findings
Pure RefMod (Col 4) vs Pure LoRA (Col 1):
- Pure RefMod achieves 90–95% likeness accuracy with ZERO training compared to a dedicated 1,500-step Prodigy LoRA.
- Facial bone structure, eye shape, and distinct likeness markers transfer immediately without dataset overcooking.
Pure RefMod (Col 4) vs 8-Raw-Reference Images (Col 2):
- RefMod produces identical or sharper facial fidelity while consuming 87% fewer attention tokens (1,024 vs 8,192 tokens).
- RefMod eliminates the 2.0s live VAE encoding bottleneck per render.
Hybrid RefMod + LoRA (Col 5):
- The combination of a RefMod (governing macro geometry and facial likeness) and a moderate LoRA (governing micro-skin texture and lighting response) yields the highest benchmark scores across all tested subjects.
10. Recommended Settings & Pro Tips
- Recommended Master Retention: Use
partially_preserved (0.7)for creative prompts (fantasy, action, cyberpunk, costume changes) to avoid clothing and background bleed from reference images. - High-Fidelity Portraits: Use
fully_preserved (1.0)with RefMod strength1.0and samplerer_sde/simpleat 8–12 steps. - Multi-Character Scenes: Load Character A in
mod_1(strength_1: 0.90) and Character B inmod_2(strength_2: 0.90). In your text prompt, describe spatial positions explicitly (e.g. "Character A on the left, Character B on the right"). - Token Budget Sweet Spot:
1024tokens provides the optimal tradeoff between spatial resolution and DiT compute throughput. Use512for ultra-fast generation batches.
11. Links & Resources
- Interactive Model Browser Space: https://huggingface.co/spaces/malcolmrey/browser
- Hugging Face Model Hub (1,400+ models): huggingface.co/malcolmrey/klein9
- Ready-to-Use Workflows:
workflows/(workflow_klein9_refmod.json&workflow_klein9_refmod_lora.json) - Visual Studies & Single Runs:
VISUAL_BENCHMARKS_AND_COMPARISONS.md - ComfyUI Custom Node: github.com/malcolmamal/ComfyUI-Flux2Klein9Mod
- Extractor Script:
../generate_flux2_klein9_refmod.py - Visual Comparison Grids:
examples/