Initialize optimizer research workspace with official baselines and history-free coverage
Vendor pinned MeZO, AGZO, LOZO and LoREN sources with independent environments. Add direct in-place fix/adjust/node training, derived history-free basis gradients, development-best checkpoints and experiment tooling. Keep models, datasets, caches and credentials outside Git. Validation: 93 project tests passed; 521 vendored author files verified.
This commit is contained in:
commit
e0feabec8f
596 files changed
+87356
No files matched your search
@@ -0,0 +1,551 @@
|
||||
# Curvature-aware descent: derivation and implementation contract
|
||||
|
||||
Current engineering execution: section 8 records the user's authorization to use
|
||||
explicit local-curvature approximations and proceed with real-model experiments.
|
||||
Certified reference status: a conditional forward-query algorithm is derived in section 6 and implemented
|
||||
as OurTrainer.curvature_refresh / curvature_step, without enabling the real-model CLI. Its effective
|
||||
upper-bound certificate is not established for the real model. No production implementation
|
||||
or hyperparameter search may substitute unverified quantities for this contract.
|
||||
The earlier `descent_gradient_proxy_v1` is withdrawn and is not a test of this theory.
|
||||
|
||||
## 0. 对用户补充全文的核对(2026-11-12)
|
||||
|
||||
原文假设 1.1 将 H 定义为分析用的有效二次上界,没有要求每个 ZO 算法
|
||||
显式构建 H。不能把“未计算出完整 H”作为所有实模实验的统一禁止条件。
|
||||
只有当算法声称实际优化给定各向异性 H 下的式 (2.3) 时,才需要给出该目标
|
||||
及其梯度所需量的获取方式。分析假设与算法实际调用的量必须分别列明。
|
||||
|
||||
全文给出了比较框架,而没有给出最大化 (2.3) 的低查询选基算法。
|
||||
以下两种目标不可混称为同一算法:
|
||||
|
||||
- 采用 H=L I、固定参数子空间秩 k:式 (2.9) 的系数为正时,最大化
|
||||
D(P) 严格等价于最大化 s(P)。这是文档已证明的各向同性特例,不是
|
||||
各向异性曲率目标的代理。若采用,必须明确声明该特例、学习率条件与 k。
|
||||
- 保留各向异性 (2.3):必须推导完整的选基估计器,不能用局部三点曲率
|
||||
自动代替上界 H,也不能只实现 G'Gd 而宣称已优化全部曲率项。
|
||||
|
||||
单边误差已有原文接口,不必把理想公式硬说成精确有限差分公式。下面补出
|
||||
可直接代入 (1.9)-(1.10) 的一组充分条件,常数较松但每一步均可验证。
|
||||
|
||||
### 0.1 固定当前子空间下的单边与 batch 误差界
|
||||
|
||||
条件于选基历史及 U,要求当前训练 batch xi 与选基样本独立,方向独立于
|
||||
两者;U'U=I_k,z_i 独立同分布于 N(0,I_k)。以下期望、无偏条件
|
||||
E[g_xi]=g 及 Cov(g_xi)=Sigma 均条件于当前
|
||||
历史、theta 和 U;且各样本目标在所有查询线段上有
|
||||
统一梯度 Lipschitz 常数 L_f。对于无界高斯,该条件不能仅限于一个未控制
|
||||
逃逸概率的有限邻域。设 F 满足原文 H 的上界条件,H 在上述条件下固定且
|
||||
历史可测。
|
||||
|
||||
记 k=rank(P)、s=g'Pg、L_U=||U'HU||op、tau=tr(PH),并定义
|
||||
|
||||
B_mu = L_f^2 * mu^2/4 * k(k+2)(k+4)
|
||||
C0 = (1+1/n)*L_U + tau/n
|
||||
N_xi = (1+1/n)*tr(P H P Sigma) + tau/n * tr(P Sigma).
|
||||
|
||||
同一个 batch 用于本次 n 个方向;各方向使用同一 batch 的 clean/plus 差分。
|
||||
把估计器写成 ghat=ghat_batch_ideal+r_mu。Taylor 余项满足
|
||||
|
||||
|e_i| <= L_f*mu/2 * ||z_i||^2
|
||||
E||r_mu||^2 <= B_mu.
|
||||
|
||||
第二式用平均向量的 Jensen 不等式与高斯六阶径向矩成立,并没有假设
|
||||
e_i 条件零均值,也没有错误地将其均值按 1/n 消去。
|
||||
先对 batch 和方向精确取矩,再用 Cauchy-Schwarz/Young:
|
||||
|
||||
A >= s - sqrt(s B_mu) >= s/2 - B_mu/2
|
||||
C_batch_ideal <= C0*s + N_xi
|
||||
C <= 2*C0*s + 2*N_xi + 2*L_U*B_mu.
|
||||
|
||||
故在相应常数沿轨迹有统一上界时,主定理接口可取
|
||||
|
||||
c = 1/2, C_master = 2*C0,
|
||||
delta = B_mu/2, nu = 2*N_xi + 2*L_U*B_mu.
|
||||
|
||||
这是充分上界,不是对 OPT 的常数估计或学习率建议,也不声称该界紧。
|
||||
浮点查询误差、额外函数噪声若存在,还要进入 r_mu 并控制相应矩。
|
||||
|
||||
非二次例子 F(x)=sin(x)、theta=0、P=1 满足全局 L_f=1,且 H=1 是
|
||||
有效上界。单边估计的均值为 exp(-mu^2/2),不同于真实梯度 1,故不能
|
||||
把一般 r_mu 的均值或与理想估计的交叉项设为零。测试用高阶高斯求积
|
||||
核对该解析均值及上述误差界;它不依赖二次函数的奇偶抵消。
|
||||
|
||||
### 0.2 选择与训练 batch 的独立性
|
||||
|
||||
原文 (2.16)-(2.19) 已明确:同一当前 batch 上先选 P 再训练,会产生 h_t。
|
||||
独立的方向 seed 只能消除选基与训练方向的复用,不能消除 batch 耦合。
|
||||
因此,若要使用 0.1 的独立性结论,刷新需要独立的选基样本,不能复用训练
|
||||
batch 的 f0 来节省一次 forward。若仍复用,必须控制 h_t 以及相应的 C_t。
|
||||
此前宣称“额外 4 次前向”并不能同时作为独立 batch 方案的预算。
|
||||
|
||||
HF RandomSampler 的 epoch 内无放回采样也不能直接认作条件独立的 iid
|
||||
随机梯度 oracle。保持作者数据流时,要将随机重排分析作为额外理论任务,
|
||||
或仅报告实验协议,不宣称上述条件收敛保证已经在实模上核验。
|
||||
|
||||
### 0.3 实验推进的准确门槛
|
||||
|
||||
继续保留单边 SGD。第 6 节保留各向异性目标,给出一种有证明的 H 构造和
|
||||
对应估计器;其全局光滑常数证书仍须针对实模建立。各向同性特例仍是另一
|
||||
明确目标,不能悄然替换。不能以未知 H 为由否定所有 ZO 实验。
|
||||
现有训练入口的 fix/adjust/历史 node 不因此自动成为命题 (2.3) 的优化器。
|
||||
只有在新选基步骤明确并通过对应测试后,才继续既定的调度和刷新参数实验。
|
||||
|
||||
## 1. Given-subspace objective (Proposition 2.1)
|
||||
|
||||
At a fixed parameter point, let g be the objective gradient, H the symmetric effective
|
||||
quadratic upper-bound matrix, P an orthogonal projector, and n the number of independent
|
||||
Gaussian directions averaged in one weight update. n is not the batch size or refresh interval.
|
||||
Set s = g'Pg, t = tr(PH), alpha = eta(1+1/n)/2, beta = eta/(2n).
|
||||
|
||||
D(P) = s - alpha g'PHPg - beta s t
|
||||
M(P) = gg' - alpha(HPgg' + gg'PH) - beta(t gg' + s H)
|
||||
|
||||
M is the Euclidean projection gradient. P is constrained; M=0 is not the condition.
|
||||
For P=UU', the tangent gradient is 2(I-P) M U. g and H stay fixed during selection.
|
||||
This objective does not require third derivatives merely to differentiate P.
|
||||
|
||||
## 2. Actual Linear parameterization
|
||||
|
||||
For W with m output rows and k input columns, use row-major vectorization:
|
||||
|
||||
P(d) = I_m kron (d d'), ||d||=1, rank(P)=m, s=||Gd||^2.
|
||||
|
||||
This is not a rank-one parameter-space projector. Within a full-model block projector,
|
||||
all other parameter blocks stay present. Contract the relevant diagonal output blocks
|
||||
of M into C = sum_a M[a,:,a,:]. Then
|
||||
|
||||
grad_d D = 2 C d
|
||||
tangent_grad_d D = grad_d D - d (d' grad_d D)
|
||||
d_next = normalize(d + rho tangent_grad_d D).
|
||||
|
||||
Keep gradient magnitudes. No sign replacement, fixed-angle substitution, clipping,
|
||||
or sampling normalization without a derivation and an explicitly agreed algorithm.
|
||||
Updating d must not change W. Fresh training noise is independent of selection noise.
|
||||
|
||||
## 3. Single-sided finite differences are an additional theory obligation
|
||||
|
||||
Proposition 2.1 assumes ideal linear directional observations. Production training uses
|
||||
`(F(theta+mu*u)-F(theta))/mu`. These are not identical at nonzero mu.
|
||||
|
||||
On an exact quadratic whose Hessian equals H, write a=g'u and c=u'Hu. The observed
|
||||
response is a+mu*c/2. Gaussian symmetry gives an exact corrected objective:
|
||||
|
||||
D_mu(P) = D(P) - eta*mu^2/(8*n) T3(P)
|
||||
T3 = t^3 + 6*t*tr((PH)^2) + 8*tr((PH)^3)
|
||||
grad_P T3 = (3*t^2 + 6*tr((PH)^2))*H
|
||||
+ 12*t*HPH + 24*HPHPH.
|
||||
|
||||
If H is merely an upper bound and K is the actual quadratic Hessian, the additional
|
||||
moment is E[(u'Ku)^2 (u'Hu)], not E[(u'Hu)^3]. Do not silently identify H with K.
|
||||
For nonquadratic losses, derive/control the remaining finite-difference bias and moments.
|
||||
|
||||
Specifically, let ghat_0 denote the averaged ideal estimator and r the averaged
|
||||
observation-error contribution, so ghat_mu=ghat_0+r. The same upper-bound argument gives
|
||||
|
||||
D_bound(P) = D(P) + g' E[r] - eta E[ghat_0' H r]
|
||||
- eta/2 E[r' H r]
|
||||
E[F(theta_next)] <= F(theta) - eta D_bound(P).
|
||||
|
||||
Replacing D(P) in the original guaranteed inequality by the displayed
|
||||
expression is valid under the same upper-bound assumption; equality of this expression
|
||||
with actual descent is not claimed. These extra terms cannot simply be omitted or
|
||||
declared zero for a general neural-network loss.
|
||||
|
||||
Counterexample to ignoring this issue: F(theta)=theta^2/2, theta=0, n=1.
|
||||
Ideal D=0, but single-sided Gaussian SGD has
|
||||
E[F(theta_next)] = 15*eta^2*mu^2/8 > 0.
|
||||
|
||||
## 4. Real-model requirements for optimizing anisotropic (2.3)
|
||||
|
||||
Section 6 resolves the formal estimator under stated oracle assumptions; it does not
|
||||
establish those assumptions or a useful upper-bound certificate for OPT/SST2.
|
||||
|
||||
Before exposing a new training mode, specify all of the following:
|
||||
|
||||
1. Which objective g refers to (population/full training objective versus one batch).
|
||||
A batch-dependent squared gradient includes covariance terms and cannot silently
|
||||
replace a squared mean gradient.
|
||||
2. For this anisotropic selection objective, how the chosen effective upper-bound H,
|
||||
its required actions, and trace information are obtained within budget. H is not
|
||||
automatically a runtime requirement of every algorithm covered by the framework.
|
||||
A three-point directional curvature is
|
||||
a local Hessian measurement; it is not a verified upper bound over actual updates.
|
||||
3. A derived estimator for the complete structured basis gradient, with its sampling
|
||||
covariance, normalization, finite-mu error, finite-delta error if used, and batch noise.
|
||||
4. Actual forwards for each quantity, including any cross-moments and selection queries.
|
||||
The old claim of four extra forwards is not a budget proof for this implementation.
|
||||
|
||||
No full model snapshots, full-model stored noise, diagnostic backprop in training, or
|
||||
unbudgeted oracle calls. Dense reference matrices are permitted only in small numerical tests.
|
||||
|
||||
## 5. Acceptance tests and execution order
|
||||
|
||||
Numerical reference tests (CPU float64; no model training/evaluation queries):
|
||||
|
||||
- Evaluate Proposition 2.1 and independently differentiate with autograd in tests.
|
||||
- Check structured basis gradient against directional finite differences, including
|
||||
cross-output and fixed auxiliary blocks in the full P.
|
||||
- Check the ideal Gaussian descent moments and the finite-mu correction using exact
|
||||
Gauss-Hermite integration on small quadratic objectives.
|
||||
- Check shared-batch covariance terms and the sufficient finite-difference bounds;
|
||||
include a smooth nonquadratic example with analytically nonzero estimator bias.
|
||||
- Verify the selection–batch coupling identity and the declared isotropic special case.
|
||||
- Integrate the three-batch forward score against the complete anisotropic objective;
|
||||
verify its 13-query selection cost, joint basis gradient limit, and nonquadratic bias.
|
||||
- Verify the upper-bound inequality with a known PSD slack H-K, where applicable.
|
||||
- Check basis retraction preserves unit norm, moves uphill locally for a small step,
|
||||
and preserves the gradient's magnitude scaling.
|
||||
|
||||
For a new mode claiming to optimize anisotropic (2.3), resolve section 4 first;
|
||||
implement the complete agreed estimator in trainer.py; compare it to the reference
|
||||
under controlled known models; verify budget, restoration, tied weights, and independent
|
||||
RNG; perform a real-model short check. An explicitly chosen isotropic special case or
|
||||
another algorithm must be validated against its own stated objective and assumptions.
|
||||
After the chosen algorithm passes these checks, perform the authorized experiment
|
||||
sequence: same-LR constant controls,
|
||||
cosine starts at main query 3600/4200, matched fix control, refresh interval/basis-step
|
||||
study, and finally separately derived weight decay. Keep 6000-query budgets and choose
|
||||
hyperparameters with development data only. Do not mix historical protocols.
|
||||
|
||||
The numerical reference does not establish section 4 for OPT/SST2 and must not be
|
||||
presented as a production algorithm or a validation of real-model convergence.
|
||||
|
||||
Verified on 2026-11-12: independent autograd, exact Gaussian quadrature, structured
|
||||
directional finite differences, known-upper-bound inequality, and the single-sided
|
||||
finite-radius counterexample pass. Test code is `tests/test_curvature_theory.py`;
|
||||
the small-matrix reference is in `trainer.py`. Autograd is used only in these tests.
|
||||
|
||||
## 6. 完整条件算法:各向异性上界目标的前向选基梯度
|
||||
|
||||
本节对应当前每步一个 Gaussian 方向,即 n=1。固定刷新时刻的 theta、eta,
|
||||
令所有候选基共同使用同一个 H。目标仍为命题 (2.3),没有改成单 batch
|
||||
梯度平方、实际虚拟更新收益或局部 Hessian 目标。训练继续使用单边差分。
|
||||
|
||||
### 6.1 先把完整目标写成可估计的标量期望
|
||||
|
||||
令 u=U(d)z,z~N(0,I_k),a=g'u,h=u'Hu。高斯矩给出
|
||||
|
||||
E[a^2] = s(P)
|
||||
E[a^2 h] = 2*g'PHPg + s(P)*tr(PH).
|
||||
|
||||
因此,在 n=1 时精确有
|
||||
|
||||
D(P) = E_z[a^2*(1-eta*h/2)]. (6.1)
|
||||
|
||||
这同时保留方向曲率和曲率迹项,不需要分别存储 g、H 或 P。
|
||||
Linear 的 u_l=z_l d_l',z_l~N(0,I_out);dense 辅助参数保留完整高斯方向。
|
||||
两侧候选基必须使用同一个潜变量 z,包括所有固定基和 dense 辅助块。
|
||||
不能再将 u 归一化,否则 (6.1) 的高斯矩发生变化。
|
||||
|
||||
### 6.2 一种合法的可查询 H 构造
|
||||
|
||||
原文没有指定唯一 H。本节额外明确以下充分假设:F 二阶可微,且已知
|
||||
经过证明的全局常数 L>0,满足 ||Hess F(x)||op<=L;F 的函数值可由无偏
|
||||
独立训练 batch 查询。L 是上界证书,不是从几个观测拟合后随意调节的超参数。
|
||||
定义 K=Hess F(theta),并选择
|
||||
|
||||
H = K + 2*L*I. (6.2)
|
||||
|
||||
由于 -L I <= K <= L I,对任意 x 都有
|
||||
|
||||
Hess F(x) <= L I <= H, L I <= H <= 3 L I.
|
||||
|
||||
沿更新线段积分即得原文 (1.5),所以 H 为有效 PSD 全局上界,也适用于
|
||||
无界 Gaussian 更新。它保留 K 的各向异性,但通常保守;不宣称是最紧上界。
|
||||
这是本节新给出的充分构造,不是原文已提供的实模曲率结论。
|
||||
|
||||
只需估计 u'Ku,再加 2L||u||^2。若已有更紧且能合法查询 u'Hu 的 H,
|
||||
可直接使用 (6.1),无需上述构造。仅函数查询不能识别任意选定的上界:
|
||||
例如 F(x)=||x||^2/2 同时容许 H=I 和 H=diag(1,4),但两者给出不同 D。
|
||||
有限局部查询也不能验证未知函数在未查询区域的全局 L。
|
||||
|
||||
### 6.3 用独立 batch 的乘积估计总体目标
|
||||
|
||||
从训练分布独立抽取 A、B、C,三个 batch 的损失均满足 E[f_X(x)]=F(x)。
|
||||
独立抽样允许碰巧重叠;强制互斥抽样不自动等于独立。对固定 u 定义
|
||||
|
||||
a_A(u) = [f_A(theta+mu*u)-f_A(theta-mu*u)]/(2*mu)
|
||||
a_B(u) = [f_B(theta+mu*u)-f_B(theta-mu*u)]/(2*mu)
|
||||
c_C(u) = [f_C(theta+mu*u)-2*f_C(theta)+f_C(theta-mu*u)]/mu^2
|
||||
Y_mu(u) = a_A(u)*a_B(u)*[1-eta/2*(c_C(u)+2*L*||u||^2)]. (6.3)
|
||||
|
||||
A、B 的独立性使方向响应的乘积估计总体响应平方,而不是其二阶矩。
|
||||
C 与 A、B 独立,使曲率乘积不再包含额外的 batch 协方差。不能把它们换成
|
||||
同 batch 的 a^2*c 而仍声称估计原式。两侧基允许共享同一组 A、B、C,
|
||||
以减少差分方差;A、B、C 在组内仍独立。额外模型随机性必须纳入 oracle,
|
||||
各组保持独立,组内各扰动查询配对固定随机性。
|
||||
|
||||
设总体中心差分均值为 a+b_mu、总体三点曲率为 u'Ku+e_mu,则条件于 u:
|
||||
|
||||
E_ABC[Y_mu(u)] = (a+b_mu)^2 * [1-eta/2*(h+e_mu)]. (6.4)
|
||||
|
||||
理想导数极限下 b_mu=e_mu=0,因此 E_zABC Y_0=D(P)。在精确二次目标上,
|
||||
中心响应和曲率差分对任意非零 mu 都精确(精确算术下),故该恒等式直接成立。
|
||||
中心差分只用于选基目标的估计,不改变权重训练的单边更新。
|
||||
|
||||
### 6.4 有限 mu 的误差与所需矩条件
|
||||
|
||||
额外假设沿查询线段存在统一三、四阶导数界 M3、M4,或足够的高斯可积包络。
|
||||
仅 C4 和 L-smooth 并不自动提供有限全局 M3、M4。Taylor 展开给出
|
||||
|
||||
|b_mu| <= B(u) = M3*mu^2*||u||^3/6
|
||||
|e_mu| <= E(u) = M4*mu^2*||u||^4/12.
|
||||
|
||||
由 (6.4),相对理想标量 a^2*(1-eta*h/2) 的误差至多
|
||||
|
||||
|1-eta*h/2|*(2*|a|*B+B^2) + eta/2*E*(|a|+B)^2. (6.5)
|
||||
|
||||
对 z 积分得到 |D_mu(P)-D(P)|<=epsilon_mu,固定维度和上述常数时为 O(mu^2)。
|
||||
有限半径估计有显式可控偏差,不称作原 D 的有限半径无偏估计。
|
||||
还需 batch 方向响应及曲率的足够矩,令 Y_mu 和后续梯度估计二阶矩有限。
|
||||
总体 F 光滑并不自动保证随机 oracle 的方差有限。
|
||||
不对可能为负的随机曲率取绝对值、截断或裁剪,否则会改变期望目标。
|
||||
|
||||
### 6.5 联合切空间梯度估计
|
||||
|
||||
对所有拟更新的输入基 d_l 独立采 eps_l~N(0,I_in),投影到切空间:
|
||||
|
||||
v_l = (I-d_l d_l') eps_l
|
||||
d_l,+ = normalize(d_l+delta*v_l)
|
||||
d_l,- = normalize(d_l-delta*v_l).
|
||||
|
||||
不再归一化 v_l。用同一个内层 z 分别生成 u_+、u_-,并用同一组独立
|
||||
A、B、C 计算 (6.3)。定义
|
||||
|
||||
q = [Y_mu(u_+)-Y_mu(u_-)]/(2*delta)
|
||||
b_hat_l = q*v_l
|
||||
d_l,new = normalize(d_l+rho*b_hat_l). (6.6)
|
||||
|
||||
保留 q 的大小与符号。rho 为基的学习率,delta 为基查询半径,mu 为权重
|
||||
查询半径;三者作用不同。换基不修改 W。可联合更新全部 Linear 基;若只
|
||||
选择部分层,须声明优化的是其余基固定后的限制问题,不能冒充全基优化。
|
||||
|
||||
证明其对应梯度:在当前 d 的联合切空间取正交坐标 x,维度
|
||||
p=sum_l(in_l-1),令 R_d(x) 为逐层归一化,f_mu(x)=D_mu(P(R_d(x)))。
|
||||
在交换微分和期望合法时,Gaussian 分部积分与对称性给出
|
||||
|
||||
E[b_hat] = grad_x E_v[f_mu(x+delta*v)] at x=0. (6.7)
|
||||
|
||||
所以有限 delta 时,它对固定切空间坐标下的 Gaussian 平滑目标梯度无偏。
|
||||
不是对原始 D 的球面梯度无偏。若理想 pullback 的三阶导数范数上界为 T3,
|
||||
则平滑偏差至多 T3*delta^2*p/2;若 (6.5) 对候选基一致成立,保守的总偏差为
|
||||
|
||||
||E[b_hat]-grad_tangent D||
|
||||
<= T3*delta^2*p/2 + epsilon_mu*sqrt(p)/delta. (6.8)
|
||||
|
||||
因此取 delta->0 且 mu^2/delta->0 可消除该偏差;没有额外 C1 误差证明时,
|
||||
不能直接写 O(mu^2+delta^2)。浮点损失误差还会被 1/mu、1/mu^2、1/delta
|
||||
放大,必须实测,不能被这段精确算术推导覆盖。
|
||||
|
||||
即使没有内层噪声,线性极限的单次 Gaussian 梯度估计也满足
|
||||
E||b_hat||^2=(p+2)||b||^2。联合多层并不增加前向次数,但可能显著增加方差。
|
||||
本流程每次只有一个联合方向,不擅自增加重复试探、筛选或确认步骤。
|
||||
|
||||
### 6.6 为什么这是改进方向,保证到什么程度
|
||||
|
||||
记真实切向梯度为 b,估计偏差上界为 e,E||b_hat||^2<=V,且当前
|
||||
retraction pullback 在更新范围满足梯度 Lipschitz 常数 L_D。则一次选基满足
|
||||
|
||||
E[D(P_new)-D(P)]
|
||||
>= rho*||b||^2-rho*||b||*e-rho^2*L_D*V/2
|
||||
>= rho/2*||b||^2-rho/2*e^2-rho^2*L_D*V/2. (6.9)
|
||||
|
||||
因此在偏差和方差代价足够小时,小步可提高期望理论下降量;单次随机基
|
||||
更新不保证一定提高 D,也不保证实际训练 loss 必降或得到全局最优基。
|
||||
原文理想权重更新的下降保证仍为 -eta*D(P_new)。实际单边 batch SGD
|
||||
还包含第 0.1 节的误差与噪声,选基原 D 不等于自动优化这些附加项。
|
||||
已知 H<=3LI 时,理想条件可用 C<=3L(k+2);第 0.1 节那组保守有限差分
|
||||
常数允许 eta<=1/[12L(k+2)]。这些是充分界,不是 OPT 的学习率建议。
|
||||
|
||||
### 6.7 完整算法与查询预算
|
||||
|
||||
输入:初始化基、eta、rho、mu、delta、刷新间隔 r、主查询预算,以及已验证
|
||||
的 L/上界 oracle 条件。所有选择 batch 来自训练分布,不使用 dev/val。
|
||||
|
||||
初始化各 Linear 的单位输入基;构基前向计入主预算。
|
||||
for t = 0, 1, ...:
|
||||
若达到刷新点且剩余预算容纳 13+2 次前向:
|
||||
固定当前 theta、eta、所有原基。
|
||||
独立抽 A、B、C;采各层切向 v 和一个全模型潜变量 z。
|
||||
构造基 d_+、d_-;按相同 z 生成 u_+、u_-。
|
||||
查询 (6.3),得到 Y_+、Y_-;所有扰动均逆向恢复到 theta。
|
||||
q = (Y_+-Y_-)/(2*delta)。
|
||||
每层 d <- normalize(d+rho*q*v),权重不变。
|
||||
独立抽训练 batch 和新的 Gaussian 潜变量 z_train。
|
||||
u_train = U(d)*z_train。
|
||||
s_train = [f_train(theta+mu*u_train)-f_train(theta)]/mu。
|
||||
theta <- theta-eta*s_train*u_train。
|
||||
记录训练/选基主查询;评估查询单独记录。
|
||||
|
||||
正常权重更新为 2 次。刷新时 A、B 各查询两基的 +/- 扰动,共 8 次;
|
||||
C 查询两基的 +/- 扰动共 4 次,共享一次 f_C(theta),合计选基 13 次,
|
||||
刷新步连同正常训练合计 15 次。R 次刷新、T 次权重更新且初始化 1 次时,
|
||||
主预算为 Q=1+2T+13R。若已给出不需要 F 查询的精确 u'Hu oracle,选基
|
||||
降为 8 次 F 查询加 2 次上界 oracle 调用;不能把后者的真实成本隐去。
|
||||
确定性 F 没有 batch 乘积偏差时,两侧各三点共享 f0,只需 5 次选择查询,
|
||||
但若 F 需遍历全训练集,每次 F 的全部 batch 前向都必须计数。
|
||||
|
||||
所有权重扰动使用相同 seed 按参数再生噪声并原地逆向恢复。不保存全模型
|
||||
副本、全模型噪声或反向图。只保存小基及其切向量、标量、种子。FP32 恢复
|
||||
允许舍入误差,不能声称逐位恢复。联合探测覆盖的方向及 ||u||^2 可流式计算。
|
||||
|
||||
当前保留 HF RandomSampler 的原训练协议;它不是本节条件 iid oracle 的
|
||||
自动实现。未来落地必须显式声明采样协议,不能暗改作者数据流以声称定理成立。
|
||||
本节给出了理论上闭合的条件流程;真实模型的 L/上界证书、可接受的方差和
|
||||
有限精度误差尚未建立,因此没有启动这套流程的实模调参。
|
||||
|
||||
实现对应:`curvature_refresh` 实现 (6.3)-(6.6),流式计算 Gaussian 方向范数,
|
||||
只保存基、切向量与标量;`curvature_step` 实现刷新间隔、15 次预算预留、
|
||||
独立选择 seed 和普通单边权重更新。三个独立 batch 由调用方提供,函数无法
|
||||
仅凭张量值检查统计独立性。`certified_smoothness` 只检查数值合法性,不虚构证明。
|
||||
实际训练循环保持原协议,尚未分派到这个条件 API。
|
||||
`tests/test_curvature_steps.py` 用具有解析全局上界的二次模型验证真实函数实现,
|
||||
覆盖分数、基更新、权重更新、预算、异常恢复、RNG 隔离及无完整权重克隆;
|
||||
这些是数值验收而非 LLM 性能代理实验。
|
||||
|
||||
本轮数值验证:全套 68 项测试通过;新增三 batch 纯函数值查询与完整 D
|
||||
的高斯矩核对、13 次选择查询计数、包含跨层曲率与 dense 辅助块的联合
|
||||
双基梯度极限、非二次 sin 目标的误差界及 O(mu^2) 收缩检验。主模型查询
|
||||
与评估模型查询均为 0。证明和测试不能替代真实模型上界证书。
|
||||
|
||||
## 7. 去掉全局 L 前提:可以推到哪里,哪些量仍不可省略
|
||||
|
||||
L 是第 6 节为实现 H 而引入的充分条件,不是用户需要提供的原始输入,也不是
|
||||
所有 ZO 实验的必要条件。原文需要有效 H;具体算法是否需要查询它取决于实际
|
||||
更新公式。MeZO 的分析使用局部曲率假设,权重更新本身不调用完整曲率上界。
|
||||
本项目新选基步骤直接优化 D_H,因而必须明确 H,不能把分析量的存在当作
|
||||
对算法查询的实现。以下是新的推导,尚未替换第 6 节条件 API。
|
||||
|
||||
### 7.1 未指定的上界不能从目标中一般性消去
|
||||
|
||||
令 K 为真实二次 Hessian,H_lambda=K+lambda I,投影秩 k 固定。则
|
||||
|
||||
D_lambda(P) = [1-eta*lambda/2*(1+(k+1)/n)]*s(P)
|
||||
-eta/2*[(1+1/n)*g'PKPg+s(P)/n*tr(PK)].
|
||||
|
||||
lambda 乘的是随 P 改变的 s(P),不是可删除的常数。例:
|
||||
K=diag(100,1),g=(sqrt(1.1),1),n=k=1,eta=0.0005。
|
||||
P0=e2 e2',P1=e1 e1'。H0=K 与 H500=K+500I 都是有效全局上界。
|
||||
|
||||
lambda=0: D(P0)=0.99925, D(P1)=1.0175
|
||||
lambda=500: D(P0)=0.62425, D(P1)=0.605.
|
||||
|
||||
两种情形都满足所用投影上的保守 eta<=1/C 条件,但排序不同。即使函数值
|
||||
全部已知,也不能确定未指定的 H。改变 eta 抵消该系数同时改变权重更新,
|
||||
不能称为原学习率下同一目标。优化实际虚拟更新收益也一般不是优化 D_H。
|
||||
|
||||
### 7.2 当前 OPT 的结构性全局增长包络
|
||||
|
||||
检查本地 config 与安装的源码:OPT-1.3B 使用 ReLU,decoder 有最终 LayerNorm,
|
||||
hidden_size=word_embed_proj_dim=2048,没有 project_out。不能把 C4 全局
|
||||
光滑假设直接应用到 ReLU 参数空间。也不能仅因全局 Hessian 不有界就断言
|
||||
当前点不存在相切二次上界;以下拼接恰好可以绕开该过强要求。
|
||||
|
||||
LayerNorm 的归一化部分满足 ||q||2<=sqrt(h)。设输出头行范数最大值为 A,
|
||||
最终 LayerNorm 参数为 gamma,beta,T=sqrt(h)||gamma||inf+||beta||2,
|
||||
c=sqrt(h)+1。对唯一参数空间中任意 ||Delta||2=r(绑定权重只计一次):
|
||||
|
||||
max_j ||W_j+Delta W_j||2 <= A+r
|
||||
||LN_output||2 <= T+c*r
|
||||
||logits||inf <= (A+r)*(T+c*r).
|
||||
|
||||
token CE <= log(V)+2||logits||inf。当前 SST2 作者 wrapper 对平均 token
|
||||
log-prob 做二选项 CE;每个 option 分数在 [-log(V)-2||logits||inf,0],
|
||||
因此 loss <= log(2)+log(V)+2||logits||inf。故其总体目标有
|
||||
|
||||
0 <= F(theta+Delta) <= a0+a1*r+a2*r^2
|
||||
a0=log(2)+log(V)+2*A*T
|
||||
a1=2*(A*c+T), a2=2*c. (7.1)
|
||||
|
||||
该界不要求内部注意力/MLP 权重有界,因为最终归一化控制了输出;不能应用
|
||||
到去掉最终 LN、有额外可训练 project_out 或其他未核对的架构。
|
||||
对当前检查点的只读分块扫描得到(浮点数是分析记录,不是向上舍入证书):
|
||||
A≈3.55166360,||gamma||inf=1,||beta||2≈4.35554257,
|
||||
a0≈363.91708848,a1≈427.78397403,a2≈92.50966799。
|
||||
未执行训练/评估模型前向。这个包络不是相切上界,不能直接作为第 6 节 L。
|
||||
|
||||
### 7.3 局部证书与全局包络拼接
|
||||
|
||||
假设在当前 theta 能由模型结构验证 R>0、ell_R>=0、G>=||g||,满足
|
||||
|
||||
F(theta+Delta)<=F(theta)+g'Delta+ell_R/2*||Delta||^2
|
||||
for ||Delta||<=R.
|
||||
|
||||
令
|
||||
|
||||
q=max(ell_R, 2*a2+2*(a1+G)/R+2*a0/R^2). (7.2)
|
||||
|
||||
内球由局部证书成立。外部 r>=R,由 (7.1)、F(theta)>=0 和
|
||||
-g'Delta<=G*r 得到余项/r^2<=a2+(a1+G)/R+a0/R^2。
|
||||
因此 H_iso=q I 是当前点对所有 Delta 有效的相切 PSD 上界。
|
||||
若当前点 Hessian K 存在且已证 ||K||op<=kappa,则
|
||||
|
||||
H=K+(q+kappa)I >= q I (7.3)
|
||||
|
||||
是可用的各向异性上界。只需三点估 u'Ku 再加 (q+kappa)||u||^2,
|
||||
无需全局光滑常数 L。它定义了一个明确的合法 D_H;不保证等于先前某个
|
||||
未被指定/验证的 H 所对应的目标。实现时必须明确推广为“已认证 shift”,
|
||||
不能把 (q+kappa)/2 传作虚构的全局 L。
|
||||
|
||||
剩余证书不是从几个三点值取最大:对有限训练样本,可尝试验证所有 ReLU
|
||||
preactivation 在半径 R 内保持符号,再对 smooth DAG(attention、LN、CE)
|
||||
传播一、二阶算子界。需包括所有 token 和样本、LN epsilon、绑定权重及损失
|
||||
归一化。如果某点确在 kink,原文 g/K 或 C4 误差论证可能不成立,不能默认
|
||||
存在正半径。当前未完成这套 24 层网络的局部证书;(7.2) 中的 R、ell_R、G、
|
||||
kappa 不可用经验最大曲率代替。小 R 还可能令 1/R^2 项极大,证书即使成立
|
||||
也未必有用。尚不能据此宣布实模可运行。
|
||||
|
||||
### 7.4 选基差分不必要求全空间 C4,但需要局部/尾部误差分析
|
||||
|
||||
若当前点有上述无 kink 局部球,则在 ||u||<=R/mu 上使用局部 M3/M4 余项。
|
||||
外部用 (7.1) 控制函数值:记 A_mu=a0+a1*mu*||u||+a2*mu^2*||u||^2,
|
||||
中心响应绝对值 <=A_mu/(2mu),三点曲率绝对值 <=2*A_mu/mu^2。
|
||||
于是误差可分为局部多项式 O(mu^2) 项与 Gaussian 尾部上的多项式矩。
|
||||
固定 R>0 时,该尾项随 mu->0 比任何 mu 幂更快消失;有限 mu 时必须显式
|
||||
计入,不能声称所有 Gaussian 查询都位于局部球。该论证适用于当前有限
|
||||
样本损失的统一包络/局部界,不自动替代 batch 独立性与有限精度验收。
|
||||
|
||||
### 7.5 实验与证明的结论
|
||||
|
||||
不需要用户给 L,也不必要求训练算法都计算全局上界。需要区分:
|
||||
原文给定的 D_H 优化器需要可定义且可查询的 H;未知 H 不能保持原目标同时
|
||||
被删除。全局 L 可被 (7.1)-(7.3) 的结构证书替代,但本项目的局部证书尚未
|
||||
建立。当前已获得真实模型的增长包络,而不是完成了实模曲率认证。
|
||||
因此仍不将已有条件代码的数值验收称为正式实模实验,也不以三点局部曲率
|
||||
或实测最大值冒充原文上界。此前“实验都必须先知道全局 L”的表述撤回。
|
||||
|
||||
核对来源(只用于模型结构/现有方法事实,以上界与反例均为本项目推导):
|
||||
- MeZO 原文 Assumption 1:https://openreview.net/pdf?id=CcsdvOOzMp
|
||||
- LayerNorm 公式:https://docs.pytorch.org/docs/stable/generated/torch.nn.modules.normalization.LayerNorm.html
|
||||
- OPT 官方源码:https://github.com/huggingface/transformers/blob/main/src/transformers/models/opt/modeling_opt.py
|
||||
|
||||
## 8. 当前工程实验约定(用户澄清,2026-11-12)
|
||||
|
||||
用户明确接受理论公式与工程实现有出入,以理论解释实测现象,允许开始实模实验。
|
||||
据此启用独立命名的 local_curvature_gradient_v1,不再以全局上界证书为开跑条件。
|
||||
第 6-7 节保留为严格保证的分析,不再将其中未满足的认证条件作为该工程变体的
|
||||
启动门槛。历史 sign/固定角度结果仍不能评价当前幅值梯度方案。
|
||||
|
||||
当前工程目标明确为 n=1 下的局部二阶下降模型:
|
||||
|
||||
J_local(P)=s(P)-eta/2*[2*g'P K P g+s(P)*tr(P K)], K=Hess F(theta).
|
||||
|
||||
在理想方向观测下,它等于 E[(g'u)^2*(1-eta*u'Ku/2)];对精确二次目标
|
||||
等于理想 ZO 的期望下降/eta。对非二次模型只作为局部 Taylor 模型解释,
|
||||
不将 K 叫作 PSD 上界,也不把实训单边/batch 噪声省略后声称精确等式。
|
||||
复用第 6 节的三个独立 batch 与联合切空间估计,不添加 2L||u||^2 项。
|
||||
在ReLU场景仍采用有限查询响应,数值估计质量由真实刷新日志和开发集曲线检验。
|
||||
|
||||
实现入口为 `--trainer node --node_update local_curvature`。默认工程试验
|
||||
rho=1e-5、delta=1e-3、mu=1e-3、r=128;rho/delta 是显式工程参数,
|
||||
不是从小二次测试推断的 LLM 最优常数。保留差商的幅值,不归一化 Gaussian
|
||||
切向量,不裁剪或取绝对值处理曲率,不加入新旧基 gate。
|
||||
|
||||
数据样本、模板、损失及 HF RandomSampler 保持 MeZO 协议。独立选择 batch
|
||||
来自训练池自己的 RNG;不用 dev/val 选基。全部 144 个 Linear 输入基联合更新,
|
||||
每次刷新 13 次主前向,正常训练 2 次。评估单独计数。
|
||||
|
||||
执行顺序:300 主查询试跑验证实际刷新;3000 查询比较 eta=[1,1.5,2,3]e-6
|
||||
且固定其他参数与 constant schedule;仅按开发集末点 loss 选 eta;从原始检查点
|
||||
重新训练 6000 查询并保存标准 HF 权重。若真实试跑暴露工程问题,先记录并修正,
|
||||
不得静默改成 sign、固定角度或隐藏额外查询。旧理论未认证不等于该工程研究不可执行。
|
||||
Reference in new issue
Block a user