Files
facok-ComfyUI-LCS/core/lcs_data.py
T
facok 534bc19033 Implement LCS plugin for training-free color control in FLUX
Implements "The Latent Color Subspace" (arXiv:2603.12261v1, ICML 2026)
as a ComfyUI plugin with V3 API + V2 backward compatibility.

6 nodes across 3 categories:
- LCS/calibration: LCSCalibrate (PCA from VAE), LCSLoadData (cache load)
- LCS/intervention: LCSColorIntervene (single color), LCSColorBatch (multi)
- LCS/observe: LCSPreviewColors (latent color map), LCSStepObserver

Core modules: patchify (16ch->64d patches), bicone HSL<->LCS mapping,
alpha_t/beta_t tables (51 entries from Appendix F), PCA calibration,
and timestep normalization with residual preservation.
2026-03-17 01:43:26 +08:00

23 lines
778 B
Python

from dataclasses import dataclass
import torch
@dataclass
class LCSData:
basis: torch.Tensor # [64, 3] PCA basis B (orthonormal columns)
mean: torch.Tensor # [64] PCA mean mu
anchor_lcs: torch.Tensor # [8, 3] LCS coords of 8 anchor colors [R,B,G,M,C,Y,Black,White]
anchor_angles: torch.Tensor # [6] hue angles (radians) of the 6 chromatic anchors
def to(self, device, dtype=None):
"""Move all tensors to device/dtype."""
kw = {"device": device}
if dtype is not None:
kw["dtype"] = dtype
return LCSData(
basis=self.basis.to(**kw),
mean=self.mean.to(**kw),
anchor_lcs=self.anchor_lcs.to(**kw),
anchor_angles=self.anchor_angles.to(**kw),
)