skills/skillxiv-v0.0.2-claude-opus-4.6/alf-load-balancing-theory/SKILL.md
Rigorous theoretical framework reformulating DeepSeek's ALF-LB as single-step primal-dual method for assignment problem, proving monotonic Lagrangian improvement, approximate balancing guarantees, and logarithmic expected regret in stochastic settings.
npx skillsauth add ADu2021/skillXiv alf-load-balancing-theoryInstall 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.
Theoretical Framework for Auxiliary-Loss-Free Load Balancing establishes a rigorous mathematical foundation for DeepSeek's ALF-LB algorithm. The analysis reformulates the algorithm as a single-step primal-dual method for an assignment problem, proves monotonic Lagrangian improvement in deterministic case, extends to stochastic training with logarithmic regret bounds, and provides theoretical justification for practical effectiveness.
Primal-Dual Formulation: Reformulate expert load balancing as a constrained optimization problem:
Minimize: loss(weights)
Subject to: all experts equally loaded
Single-Step Update: ALF-LB performs one update step of the primal-dual method:
w_t+1 = w_t - α ∇_w loss(w_t) - β ∇_dual (loading_constraint)
Where the dual term encourages load balance.
Monotonic Improvement: Prove that each step monotonically improves the Lagrangian:
L(w_t+1, λ_t) <= L(w_t, λ_t)
This guarantees convergence toward balanced loading.
Assignment problem formulation:
# Expert assignment can be viewed as solving:
# min ||routing_scores - average_score||²
# subject to: each token assigned to exactly one expert
def compute_optimal_assignment(routing_scores):
"""
Optimal assignment minimizes deviation from average routing.
ALF-LB approximately solves this via gradient descent on load variance.
"""
avg_score = routing_scores.mean()
load_variance = ((routing_scores - avg_score) ** 2).sum()
return load_variance
Primal-dual update rule:
def alf_lb_update(routing_logits, expert_capacity, lambda_dual, learning_rate):
# Primal: gradient on loss (LLM token prediction)
loss = cross_entropy(routing_logits, target_tokens)
grad_primal = torch.autograd.grad(loss, routing_logits)[0]
# Dual: gradient on load balance constraint
routing = softmax(routing_logits)
loads = routing.sum(dim=0) # per-expert loads
load_imbalance = ((loads - expert_capacity) ** 2).sum()
grad_dual = torch.autograd.grad(load_imbalance, routing_logits)[0]
# Combined update
update = grad_primal + lambda_dual * grad_dual
routing_logits = routing_logits - learning_rate * update
return routing_logits
Monotonic Lagrangian improvement proof sketch:
def verify_monotonic_improvement(w_t, loss, constraint, alpha, beta):
"""
Verify that L(w_{t+1}) <= L(w_t) where:
L = loss(w) + lambda * constraint(w)
"""
L_t = loss(w_t) + beta * constraint(w_t)
# Update step
w_t1 = w_t - alpha * (grad_loss(w_t) + beta * grad_constraint(w_t))
# Lagrangian at t+1
L_t1 = loss(w_t1) + beta * constraint(w_t1)
# Verify improvement
assert L_t1 <= L_t, "No monotonic improvement!"
return L_t1 <= L_t
Stochastic analysis:
def expected_regret_bound(num_steps, variance):
"""
In stochastic setting (noisy routing), expected regret:
E[Regret] = O(log T) where T = num_steps
This logarithmic bound justifies effectiveness even with
training noise and dynamic expert assignments.
"""
regret = torch.log(torch.tensor(num_steps)) * torch.sqrt(variance)
return regret
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.