Skip to main content
QUICK REVIEW

[Paper Review] Differentiable Knapsack and Top-k Operators via Dynamic Programming

Germain Vivier--Ardisson, Michael E. Sander|arXiv (Cornell University)|Jan 29, 2026
Stochastic Gradient Optimization TechniquesComputer Science0 citations
TL;DR

The paper presents a unified differentiable framework for Knapsack and Top-k operators by casting them as dynamic programs and smoothing the recursions, enabling both deterministic and stochastic layers in neural networks. It also characterizes regularizers that ensure permutation-equivariance and sparsity, and demonstrates applications in decision-focused learning, constrained dynamic assortment RL, and discrete VAEs.

ABSTRACT

Knapsack and Top-k operators are useful for selecting discrete subsets of variables. However, their integration into neural networks is challenging as they are piecewise constant, yielding gradients that are zero almost everywhere. In this paper, we propose a unified framework casting these operators as dynamic programs, and derive differentiable relaxations by smoothing the underlying recursions. On the algorithmic side, we develop efficient parallel algorithms supporting both deterministic and stochastic forward passes, and vector-Jacobian products for the backward pass. On the theoretical side, we prove that Shannon entropy is the unique regularization choice yielding permutation-equivariant operators, and characterize regularizers inducing sparse selections. Finally, on the experimental side, we demonstrate our framework on a decision-focused learning benchmark, a constrained dynamic assortment RL problem, and an extension of discrete VAEs.

Motivation & Objective

  • Cast Knapsack and Top-k as dynamic programs and derive differentiable relaxations by smoothing max recursions.
  • Develop efficient parallel algorithms for forward and backward passes and enable vector-Jacobian products.
  • Characterize regularizers that yield permutation-equivariant operators and sparsity in selections.
  • Provide stochastic forward passes and Fenchel-Young losses for end-to-end learning.
  • Demonstrate the framework on decision-focused learning, constrained dynamic assortment RL, and discrete VAEs.

Proposed method

  • Regularize the DP Bellman recursions by replacing max with max_Ω to obtain differentiable relaxations.
  • Define smoothed DP values and their gradients to produce differentiable operators in conv(Y^C_w).
  • Establish permutation-equivariance and sparsity properties and identify Shannon entropy as the unique regularizer yielding equivariance.
  • Provide forward and backward algorithms (Algorithms 1-4) for deterministic and stochastic integration, including VJPs and sampling schemes.
  • Link the operators to Fenchel-Young losses for principled supervised learning.
  • Demonstrate efficiency via wavefront parallelism and a NumPy/Numba implementation.
Figure 1: Illustration of our relaxed Top- $k$ and Knapsack operators. We plot the sum of the first two coordinates of the relaxed operator for ${\bm{\theta}}=(\theta_{1},\theta_{2},\frac{1}{2},1)^{\top}$ . In the first row, we use $\bm{y}^{k}_{\bm{1},\Omega}$ with $k=2$ and ${\bm{w}}=\bm{1}$ . In t
Figure 1: Illustration of our relaxed Top- $k$ and Knapsack operators. We plot the sum of the first two coordinates of the relaxed operator for ${\bm{\theta}}=(\theta_{1},\theta_{2},\frac{1}{2},1)^{\top}$ . In the first row, we use $\bm{y}^{k}_{\bm{1},\Omega}$ with $k=2$ and ${\bm{w}}=\bm{1}$ . In t

Experimental results

Research questions

  • RQ1Can Knapsack and Top-k be reformulated as DP problems with differentiable relaxations?
  • RQ2What regularization enforces permutation-equivariance and when do we obtain sparse selections?
  • RQ3How can these differentiable operators be integrated into end-to-end learning with both deterministic and stochastic forward passes?
  • RQ4Do the proposed operators improve decision-focused learning, dynamic assortment RL, and DVAE tasks compared to baselines?

Key findings

  • A differentiable Knapsack and Top-k operator is derived by smoothing the DP max recursions with a regularizer Ω.
  • Shannon entropy is the unique separable regularization yielding permutation-equivariant relaxed operators and sparsity can be induced by other regularizers.
  • Efficient vector-Jacobian products and an ancestral sampling-based stochastic forward pass enable end-to-end training.
  • The framework supports both deterministic layers and stochastic forward passes with Fenchel-Young losses for supervision.
  • Experiments show DP-based losses outperform baselines on decision-focused learning, dynamic assortment RL, and discrete VAE tasks.
  • The approach enables sampling from an underlying distribution π^{w,C}_{θ,Ω} and provides tractable forward/backward passes without excessive solver calls.
Figure 2: Scaling and performance of $\bm{y}^{C}_{\bm{w},\Omega}$ as an output layer. Lower computational time and test relative regret are better.
Figure 2: Scaling and performance of $\bm{y}^{C}_{\bm{w},\Omega}$ as an output layer. Lower computational time and test relative regret are better.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.