ComfyUI Node

Flux2TTRTrainer

Phase-1: distill Flux TTR linear attention modules from native attention.

By ttulttul·Created 6 months ago·Updated 6 months ago· 1
Flux2TTRTrainer
  • model
  • latents
  • conditioning
  • training_config
  • MODEL
  • loss_value
steps512
trainingtrue
training_preview_ttrtrue
checkpoint_path/tmp/ComfyUI/models/approximate_attention/flux2_ttr.pt
feature_dim256
query_chunk_size256
key_chunk_size1024
landmark_fraction0.080
landmark_min64
landmark_max0
text_tokens_guess77
alpha_init0.100
training_query_token_cap128
replay_buffer_size8
replay_offload_cputrue
replay_max_mb768
train_steps_per_call1
readiness_threshold0.1200
readiness_min_updates24
enable_memory_reservefalse
layer_start-1
layer_end-1
cfg_scale1.000
min_swap_layers1
max_swap_layers-1
inference_mixed_precisiontrue
controller_checkpoint_path
Categoryadvanced/attention

Inputs (31)

NameTypeDefaultDescription
modelMODEL
latentsLATENT
conditioningCONDITIONING
stepsINT5120–200000
trainingBOOLEANtrueTrain TTR layers by distillation when enabled.
training_preview_ttrBOOLEANtrueWhen training, output TTR student attention for visual preview instead of teacher passthrough.
checkpoint_pathSTRING/tmp/ComfyUI/models/approximate_attention/flux2_ttr.ptCheckpoint file to load/save TTR layer weights (defaults to ComfyUI/models/approximate_attention/flux2_ttr.pt).
feature_dimINT256128–8192Kernel feature dimension (must be a multiple of 256).
query_chunk_sizeINT2561–4096Query chunk size for kernel attention evaluation.
key_chunk_sizeINT10241–8192Key chunk size for kernel KV/Ksum accumulation.
landmark_fractionFLOAT0.0800.01–0.5Fraction of image tokens used as landmarks for exact softmax residual.
landmark_minINT641–1024Minimum landmark count used at low resolution.
landmark_maxINT00–2048Maximum landmark count used at high resolution (0 means unlimited).
text_tokens_guessINT770–1024Assumed number of text tokens at the start of sequence for landmark selection.
alpha_initFLOAT0.1000–10Initial residual gate for landmark softmax branch.
training_query_token_capINT1281–4096Max number of query tokens per replay sample; keys/values always stay full length.
replay_buffer_sizeINT81–4096Replay buffer capacity per layer for distillation samples.
replay_offload_cpuBOOLEANtrueStore replay samples on CPU (reduced precision) to reduce VRAM pressure.
replay_max_mbINT76864–65536Global replay memory budget in MB across all layers.
train_steps_per_callINT11–32Number of replay optimization steps run per attention call.
readiness_thresholdFLOAT0.12000–10Enable student inference for a layer only when EMA loss is below this threshold.
readiness_min_updatesINT240–100000Minimum replay updates before a layer can be marked ready.
enable_memory_reserveBOOLEANfalseCall ComfyUI free_memory before HKR attention allocations (can offload aggressively).
layer_startINT-1-1–512Only apply TTR to single blocks with index >= layer_start (-1 disables).
layer_endINT-1-1–512Only apply TTR to single blocks with index <= layer_end (-1 disables).
cfg_scaleFLOAT1.0000–100Default CFG scale used when transformer_options does not provide guidance scale.
min_swap_layersINT10–512Training mode: minimum number of eligible single layers to swap to TTR per diffusion step.
max_swap_layersINT-1-1–512Training mode: maximum swapped layers per diffusion step (-1 means all eligible layers).
inference_mixed_precisionBOOLEANtrueUse input dtype (bf16/fp16) for TTR inference on CUDA for speed.
controller_checkpoint_pathSTRINGOptional Phase-2 controller checkpoint used for inference-time layer routing.
training_configoptTTR_TRAINING_CONFIG

Outputs (2)

NameTypeDescription
MODELMODEL
loss_valueFLOAT