skills/skillxiv-v0.0.2-claude-opus-4.6/dcm-dual-expert-consistency/SKILL.md
Accelerate video generation through dual-expert consistency distillation, using separate denoisers for semantic layout/motion and detail refinement to resolve conflicting optimization gradients.
npx skillsauth add ADu2021/skillXiv dcm-dual-expert-consistencyInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Consistency distillation for video synthesis faces a fundamental optimization conflict: early diffusion steps require rapid semantic changes (layout, motion) while later steps need gradual detail refinement. A single student model cannot simultaneously optimize for both dynamics, creating conflicting gradients. DCM solves this by employing two specialized expert denoisers—one for semantic/motion reasoning, one for detail synthesis—enabling efficient 4-step video generation while maintaining quality near 50-step original models.
The approach maintains parameter efficiency through LoRA adapters and frozen semantic experts, achieving VBench scores of 83.83 (vs. 80.33 baseline) with 92% latency reduction.
# Expert training specification
def create_dual_expert_curriculum(diffusion_model, train_data):
"""
Partition training into high-noise (semantic) and low-noise (detail) phases.
Each expert specializes in different denoising dynamics.
"""
semantic_expert = copy_model(diffusion_model) # Will be frozen
detail_expert = copy_model(diffusion_model) # Will be adapted with LoRA
# High-noise timesteps for semantic learning (t: 1-25, high sigma)
semantic_batch = filter_timesteps(train_data, timestep_range=(1, 25))
# Low-noise timesteps for detail learning (t: 26-50, low sigma)
detail_batch = filter_timesteps(train_data, timestep_range=(26, 50))
return {
'semantic_expert': semantic_expert,
'detail_expert': detail_expert,
'semantic_data': semantic_batch,
'detail_data': detail_batch
}
def temporal_coherence_loss(semantic_expert, batch_frames, target_frames):
"""
Loss for semantic expert to maintain consistent motion across frames.
Ensures optical flow consistency and frame alignment.
"""
# Predict denoised output
denoised = semantic_expert(batch_frames, timestep=high_noise)
# Compute optical flow between consecutive frames
flow_target = compute_optical_flow(target_frames)
flow_denoised = compute_optical_flow(denoised)
# L2 loss on flow consistency
flow_loss = torch.nn.functional.mse_loss(flow_denoised, flow_target)
# Frame alignment loss for temporal coherence
alignment_loss = 0.0
for i in range(len(denoised) - 1):
# Warp frame[i+1] using flow[i] and compare to frame[i]
warped = warp_frame(denoised[i+1], flow_denoised[i])
alignment_loss += torch.nn.functional.mse_loss(warped, denoised[i])
total_coherence_loss = 0.7 * flow_loss + 0.3 * alignment_loss
return total_coherence_loss
def detail_expert_loss(detail_expert, detail_discriminator, batch_frames, target_frames):
"""
Adversarial loss for detail expert to synthesize high-frequency details.
Combines reconstruction fidelity with feature matching.
"""
# Forward through detail expert
denoised = detail_expert(batch_frames, timestep=low_noise)
# Reconstruction loss: match target quality
recon_loss = torch.nn.functional.mse_loss(denoised, target_frames)
# Adversarial loss: fool discriminator
fake_logits = detail_discriminator(denoised)
adversarial_loss = -torch.log(fake_logits + 1e-8).mean()
# Feature matching: align intermediate representations with target
# Extract features from intermediate layers of discriminator
fake_features = extract_features(detail_discriminator, denoised)
real_features = extract_features(detail_discriminator, target_frames)
feature_loss = 0.0
for fake_feat, real_feat in zip(fake_features, real_features):
feature_loss += torch.nn.functional.l1_loss(fake_feat, real_feat)
# Combined objective: reconstruction + adversarial + features
total_loss = 0.5 * recon_loss + 0.3 * adversarial_loss + 0.2 * feature_loss
return total_loss
def apply_lora_to_detail_expert(detail_expert, lora_rank=8):
"""
Add LoRA adapters to detail expert while keeping semantic expert frozen.
Maintains parameter efficiency—only ~1-5% additional parameters.
"""
for name, module in detail_expert.named_modules():
if isinstance(module, torch.nn.Linear) and 'attn' in name:
# Add LoRA matrices to attention layers
module.lora_A = torch.nn.Linear(module.in_features, lora_rank, bias=False)
module.lora_B = torch.nn.Linear(lora_rank, module.out_features, bias=False)
# Original forward: out = W @ x
# LoRA forward: out = W @ x + (B @ A @ x) * scale
original_forward = module.forward
def forward_with_lora(x):
out = original_forward(x)
lora_out = module.lora_B(module.lora_A(x))
return out + lora_out * (2.0 / lora_rank) # Scaling factor
module.forward = forward_with_lora
# Freeze semantic expert parameters
for param in detail_expert.parameters():
if 'lora' not in param.__dict__:
param.requires_grad = False
def dual_expert_denoising_step(semantic_expert, detail_expert,
noisy_frames, timestep, context):
"""
Route denoising to appropriate expert based on noise level.
Semantic expert: high noise (early steps)
Detail expert: low noise (late steps)
"""
sigma = get_sigma_from_timestep(timestep)
if sigma > threshold_sigma: # High noise → semantic expert
denoised = semantic_expert(noisy_frames, timestep, context)
else: # Low noise → detail expert
denoised = detail_expert(noisy_frames, timestep, context)
return denoised
When to Apply:
Setup Requirements:
Performance Expectations:
Key Tuning Parameters:
Training Strategy:
Common Pitfalls:
Implemented on HunyuanVideo base model. Achieves VBench 83.83 with 4-step inference. Training uses 8 A100 GPUs with mixed precision. Validated through human evaluation (82.67% preference) and automated metrics (PSNR, temporal consistency scores).
testing
Uses flow maps as look-ahead operators to enable principled reward-guided diffusion by predicting trajectory endpoints at any denoising step. Deploy when applying rewards or preferences to diffusion trajectories with meaningful gradients throughout generation.
testing
Train language models where each expert learns independently on closed datasets, enabling flexible inference with selective data inclusion or exclusion. 41% performance improvement while allowing users to opt out of specific data sources without retraining.
data-ai
Understand how token generation flexibility in diffusion LMs paradoxically constrains reasoning, as models exploit ordering flexibility to avoid uncertain tokens, and apply simplified approaches that preserve parallel decoding benefits. Use when optimizing diffusion-based language models for reasoning tasks.
devops
Enable LLM agents to improve continuously during deployment by constructing structured experience libraries through self-reflection on successes and failures—achieving 23% improvement on reasoning without gradient-based parameter updates or external training.