AlignedHPO: Automatic Tuning of Loss Function Hyperparameters with 12x Speedup

AlignedHPO efficiently tunes loss function hyperparameters with gradient alignment and JVP, achieving nearly 12x speedup.
AlignedHPO is a lightweight framework for automatic tuning of loss function hyperparameters. It addresses the high cost and randomness sensitivity of implicit differentiation by using Jacobian-vector products to estimate hypergradients (nearly 12x speedup), normalizing gradients before alignment, and introducing gradient smoothing. It also uses differentiable metric surrogates to replace non-differentiable evaluation metrics, aligning hyperparameters directly with task metrics. On generalized Focal Loss long-tail classification and ArcFace open-set face recognition, it performs comparably to or better than implicit differentiation.
Deep learning loss functions often contain multiple hyperparameters—weights, scales, margins, etc. Although these parameters are differentiable, in practice they are still mainly tuned manually or via expensive black-box optimization. A new paper proposes the AlignedHPO framework, which attempts to solve this problem efficiently using gradient alignment and surrogate validation objectives. It achieves results comparable to or better than implicit differentiation on long-tail classification and open-set face recognition tasks, while speeding up hypergradient computation by nearly 12x.

Why Loss Function Hyperparameters Are Hard to Tune
Modern loss functions are increasingly sophisticated. Take generalized Focal Loss and ArcFace as examples: the former requires tuning class weights and focusing parameters to handle long-tail distributions, while the latter relies on scale factors and angular margins to enhance the discriminativeness of face features. These parameters directly affect the optimization landscape and the quality of final representations, but their optimal values often vary with dataset, model architecture, and training stage.
Manual tuning relies on experience and is hard to reproduce; black-box optimization (such as Bayesian optimization) requires repeated full training runs and is extremely computationally expensive. A natural idea: since the loss function is differentiable with respect to hyperparameters, can we directly compute hypergradients to update them? Implicit differentiation provides a theoretical path, but it incurs high computational and memory overhead and is sensitive to randomness. AlignedHPO is a lightweight solution proposed to address these pain points.
Hypergradient refers to the derivative of the validation loss (or surrogate metric) with respect to hyperparameters. Unlike ordinary gradients, hyperparameters indirectly affect the final model parameters by influencing the model training process (i.e., the inner optimization), so hypergradients need to be backpropagated along the entire training trajectory. There are two paths to compute exact hypergradients: one is to unroll the entire training process and backpropagate (unrolled differentiation), with memory growing linearly with the number of training steps; the other is implicit differentiation, which uses the optimality conditions at training convergence to compute derivatives, requiring less memory but needing to solve linear systems or approximate inverse matrices. The common difficulty of both is that the training process itself contains randomness (mini-batch sampling, data augmentation), leading to biased and high-variance hypergradient estimates.
Three Key Techniques of AlignedHPO
The core idea of the paper is to estimate the hypergradient direction using gradient alignment and to guide optimization with a differentiable metric surrogate. Specifically, it includes three designs:
Jacobian-vector product reduces overhead. By computing hypergradients via JVP, it avoids explicitly constructing and inverting large matrices, significantly reducing computation time and memory usage. This is the main source of the "nearly 12x speedup."
Normalized alignment resolves gradient magnitude ambiguity. Different hyperparameters have vastly different sensitivities to the loss, and raw gradient magnitudes may mislead the update direction. AlignedHPO normalizes gradients before alignment, making optimization more stable.
Gradient smoothing handles stochastic instability. Mini-batch training introduces noise, causing hypergradient estimates to fluctuate. The paper introduces a gradient smoothing mechanism to make update directions more reliable in stochastic environments.
In addition, the method uses differentiable metric surrogates to replace non-differentiable evaluation metrics (such as F1, accuracy), directly steering the optimization objective toward the evaluation criteria that the task truly cares about, rather than merely minimizing training loss.
Jacobian-vector product (JVP) is a forward-mode operation in automatic differentiation: given a function $f$ and a vector $v$, it directly computes $J_f \cdot v$ without explicitly constructing the Jacobian matrix $J_f$. In many hypergradient estimations, what is actually needed is only the product of the Jacobian matrix with some vector, not the matrix itself. Using JVP can reduce time and memory from overhead quadratic in the parameter dimension to linear scale, and can be combined with reverse-mode automatic differentiation (i.e., forward-reverse hybrid mode). This is the underlying mechanism that enables AlignedHPO to bypass explicit matrix construction and inversion and achieve substantial speedup; understanding this also explains that the "nearly 12x speedup" is not an engineering trick but an algorithmic-level benefit from the choice of automatic differentiation mode.
Experimental Results: Effectiveness Verified on Two Types of Tasks
The paper validates on two markedly different tasks. Long-tail classification uses generalized Focal Loss, and open-set face recognition uses ArcFace. The commonality of these two scenarios is that loss function hyperparameters greatly affect performance, and data distributions are complex.
Results show that AlignedHPO achieves performance comparable to or better than implicit differentiation methods, while speeding up hypergradient computation by nearly 12x. This means that under the same computational budget, hyperparameters can be updated more frequently, or the saved computation can be used for larger-scale experiments. The paper also emphasizes that the method can adaptively adjust hyperparameters rather than relying on fixed heuristics.
Differentiable metric surrogate is a substitute function designed to address the issue that "task metrics are non-differentiable." Evaluation metrics such as F1, accuracy, and AUC typically involve argmax, threshold comparisons, or discrete counting, with gradients almost everywhere zero, making them unsuitable for direct gradient-based hyperparameter optimization. A common approach is to construct a smooth surrogate, such as soft-F1 (using probabilities instead of hard predictions), differentiable ranking approximations, or temperature-scaled softmax to approximate the original metric. The key to surrogate design is maintaining sufficiently high correlation with the original metric; otherwise, the optimization direction will deviate from the true objective. This also explains the limitation mentioned in the original text: surrogates need to be customized for specific tasks, and their quality directly affects the practical effectiveness of AlignedHPO.
Implications for Practitioners
The value of this work lies in moving "automatic tuning of loss function hyperparameters" from theoretical feasibility to engineering usability. JVP and gradient smoothing are both mature tools, and their combination yields significant efficiency gains. For scenarios requiring fine-tuning of loss functions—long-tail learning, face recognition, metric learning—AlignedHPO provides a path that is more computationally efficient than black-box search and lighter than implicit differentiation.
However, the paper currently validates only on two tasks, and the design of surrogate metrics also needs to be customized for specific tasks. Whether it can be generalized to a broader range of loss functions and training pipelines remains to be seen. But the idea of "replacing expensive hypergradient computation with gradient alignment" is worth attention.
One-line Summary
AlignedHPO efficiently tunes loss function hyperparameters using gradient alignment and JVP, achieving nearly 12x speedup.
Paragraph Summary
AlignedHPO is a lightweight framework for automatic tuning of loss function hyperparameters. The article points out that although hyperparameters such as weights, scales, and margins are differentiable, in practice they still rely on manual tuning or expensive black-box optimization, while implicit differentiation, though providing a theoretical path, incurs high computational and memory overhead and is sensitive to randomness. AlignedHPO addresses these pain points through three designs: using Jacobian-vector products to estimate hypergradients, avoiding explicit matrix construction and inversion, yielding nearly 12x speedup; normalizing gradients before alignment to eliminate magnitude ambiguity caused by differing sensitivities of hyperparameters; and introducing gradient smoothing to suppress estimation fluctuations caused by mini-batch noise. The method also uses differentiable metric surrogates to replace non-differentiable evaluation metrics, enabling hyperparameters to be adjusted directly toward task evaluation criteria. On generalized Focal Loss long-tail classification and ArcFace open-set face recognition tasks, its performance is comparable to or better than implicit differentiation.
Related articles

Pure-Code Video Generation Tested: Which AI Model Actually Follows Instructions?
A Bilibili creator tested three AI models' pure-code video generation with unified prompts and three revisions each: Xiaonaomao has a high ceiling but lacks stability, GPT 6.2 Extra models well but only follows half the instructions, and OPAS 5.5 remains the benchmark.

GPT-6 Six-Tier Hands-On Test: Astra Ultra Dominates but Bills Double
GPT-6 six-tier test: Astra Ultra sweeps 3:0 in 3D tasks thanks to sub-agents and runs 14% faster, but hidden backend bills make its real cost 2.6x single-threaded.

GPT-6.2 Astra vs Fable 5.2: Huge Cost-Efficiency Gap Across 12 Real-World Tests
Bilibili creator tests GPT-6.2 Astra vs Fable 5.2 across 12 real tasks: Fable wins 7-5 but costs 7.2x more and takes nearly 5x longer. Token efficiency emerges as the key selection metric.