Skip to content

Optimization problem set, part b: constrained optimization, duality, and DPO

ModuleS-M10b · solve · none · Pass 10 · 3 to 4 h
You buildanswers in solve/S-M10b.toml for 18 SymPy-checked problems and four rubric derivations
Contractnone: a pen and paper set
Testscourse/solve/S-M10b/key.toml (hidden): typed answers, reject canaries, and proof rubrics
NeedsM04.2 constrained optimization, M11.1 KL; reading: Optimization
Used byno call site; optional analysis behind L12.2 DPO
MilestoneMS-P10 includes this optional solve set only when selected
Optional depthBoyd and Vandenberghe, Convex Optimization, ch. 5; DPO derivation in Rafailov et al.
  • KKT multipliers pair with the chosen inequality sign convention.
  • Strong duality equates primal and dual optima under suitable convexity and feasibility assumptions.
  • A KL-regularized policy optimum is proportional to the reference policy times exponentiated reward.
  • The DPO log-ratio subtracts away the unknown normalization constant.
Terminal window
ol start S-M10b
ol check S-M10b

The optional post-training sequence uses a KL penalty to keep an updated model near its SFT reference. These problems derive the optimization constraints and the closed-form policy that motivates DPO. They follow the earlier gradient and KL material and are not required for the core agent pass.

For a minimization problem with inequality g_i(x) <= 0, KKT multipliers satisfy lambda_i >= 0, stationarity, primal feasibility, and complementary slackness lambda_i g_i(x)=0. The Lagrangian is L(x,lambda)=f(x)+Σ lambda_i g_i(x). For a KL-regularized reward objective, maximizing E_pi[r] - beta D_KL(pi || pi_ref) gives pi*(y|x) = pi_ref(y|x) exp(r(x,y)/beta) / Z(x).

SymbolMeaning
g_i(x)inequality constraint, nonpositive when feasible
lambda_inonnegative KKT multiplier
pi_reffixed reference policy
betaKL strength, positive
Z(x)normalizer over candidate completions

Minimize x² subject to x >= 1, written 1-x <= 0. At x=1, stationarity gives 2x-lambda=0, hence lambda=2. The primal value is 1. For two outcomes with equal reference probability, rewards [1,0], and beta=1, the optimal policy has probabilities [e/(1+e), 1/(1+e)] and log odds 1. These values appear in q3-6 and q11-17.

Enter exact fractions, intervals, vectors, booleans, or symbolic expressions in solve/S-M10b.toml. The checker evaluates typed expressions using SymPy. Four derivations are self-graded against the rubric. The problem set includes reject canaries for sign errors, infeasible multipliers, reversed odds, and a missing normalizer cancellation.

TestWhy it existsExpected result
KKT stationarity and feasibilityFinds sign convention mistakesFeasible solution with zero residual
Dual valueChecks infimum over the primal variableGap zero in the convex fixture
DPO oddsConnects reward differences to policy/reference ratiosDifference equals reward gap over beta
PitfallCaught by
Using a negative multiplier for g<=0q4 and q6
Forgetting feasibility along with stationarityq10 canary
Maximizing over x when forming the dualq12
Keeping the unknown Z(x) in log oddsq18 rubric
DirectionModuleHow it uses this
BackM04.2, M11.1constraints, gradients, and KL
ForwardL12.2DPO uses the optimal policy’s reference-adjusted odds
ForwardC2optional post-training applies the preference objective

Strong duality needs assumptions such as convex objectives, convex constraints, and a strict feasible point. Real preference learning also has noisy labels and finite data, so a closed-form derivation is a guide to the objective rather than a guarantee of learned behavior.