SoftJAX & SoftTorch: Empowering Automatic Differentiation Libraries with Informative Gradients

Anselm Paulus, Andreas René Geist, Vit Musil, Sebastian Hoffmann, Georg Martius

International Conference on Machine Learning 2026 · Oral

Overview

Throughout machine learning and scientific computing, workflows frequently encounter discrete decision-making operations—such as sorting, ranking, spatial projections, and conditional branching. However, standard discrete operators are non-differentiable, completely blocking gradient-based optimization. This talk introduces SoftJAX and SoftTorch, two companion libraries built for JAX and PyTorch that inject informative, continuous approximations into discrete operators. By providing smooth surrogates for functions like Heaviside thresholds, argmax, sorting, and top-$k$ selections, these frameworks enable gradient flow through otherwise opaque discrete code paths.

Watch on SlidesLive

Visual summary for SoftJAX & SoftTorch: Empowering Automatic Differentiation Libraries with Informative Gradients by Anselm Paulus, Andreas René Geist, Vit Musil, Sebastian Hoffmann, Georg Martius
Visual summary for SoftJAX & SoftTorch: Empowering Automatic Differentiation Libraries with Informative Gradients by Anselm Paulus, Andreas René Geist, Vit Musil, Sebastian Hoffmann, Georg Martius

Key moments

  1. 0:00 Introduction and motivation for soft differentiable programming
  2. 2:00 Continuous approximations and fuzzy logic comparison operators
  3. 3:52 Axis-wise operators: Argmax and SoftSort
  4. 6:14 Addressing gradient biases with the straight-through trick
  5. 7:55 The straight-through pitfall in higher dimensions
  6. 9:51 Connection between ReLU and axis-wise operators
  7. 12:00 Audience Q&A and choosing default hyper-parameter tau

SoftJAX & SoftTorch: Empowering Automatic Differentiation Libraries with Informative Gradients

Speakers: Anselm Paulus; Andreas René Geist; Vit Musil; Sebastian Hoffmann; Georg Martius

Conference: ICML

YouTube: https://slideslive.com/39083762

Overview

Throughout machine learning and scientific computing, workflows frequently encounter discrete decision-making operations—such as sorting, ranking, spatial projections, and conditional branching. However, standard discrete operators are non-differentiable, completely blocking gradient-based optimization. This talk introduces SoftJAX and SoftTorch, two companion libraries built for JAX and PyTorch that inject informative, continuous approximations into discrete operators. By providing smooth surrogates for functions like Heaviside thresholds, argmax, sorting, and top-$k$ selections, these frameworks enable gradient flow through otherwise opaque discrete code paths.

The importance of this work lies in bridging the gap between discrete algorithmic logic and continuous optimization frameworks like deep learning. Whether applied to differentiable rendering (e.g., determining whether a 2D pixel falls inside a 3D projected triangle), combinatorial optimization, or reinforcement learning, practitioners often struggle to obtain useful gradients. SoftJAX and SoftTorch systematically address this by implementing families of smooth approximations with adjustable continuity properties, multiple algorithmic backends for axis-wise operations, and robust handling of automatic differentiation (autodiff) mechanics.

Background

▶ Watch: Introduction and motivation for soft differentiable programming (0:00)

In the machine learning and systems space, a fundamental friction exists between continuous optimization algorithms (which rely on gradients computed via automatic differentiation) and discrete structures (such as sorting networks, argmax indices, and conditional statements). Discrete operations yield zero gradients almost everywhere, rendering standard backpropagation ineffective.

Prior work has attempted to tackle this problem in isolated domains. For instance, researchers have proposed continuous relaxations for sorting (such as NeuralSort, FastSoftSort, and SmoothSort) or entropy-regularized optimal transport for ranking. Similarly, custom sigmoid surrogates have been used ad-hoc to approximate step functions.

However, these solutions have historically been fragmented, ad-hoc, and scattered across disparate repositories without unified API designs or integration with modern tensor compilation frameworks like JAX and PyTorch. Furthermore, practitioners adopting soft relaxations face severe mathematical hurdles—such as gradient bias, hyperparameter sensitivity, and subtle autodiff failures in higher dimensions when combining relaxed operators. SoftJAX and SoftTorch unify these techniques into cohesive, drop-in libraries that span both element-wise and axis-wise discrete operations.

Key Findings

▶ Watch: Axis-wise operators: Argmax and SoftSort (3:52)

The development and formalization of SoftJAX and SoftTorch yield several key conceptual and practical discoveries:

  • Unified Element-Wise Surrogates: The libraries generalize element-wise discontinuous functions (Heaviside, sign, round, abs) using configurable sigmoidal approximations with adjustable softness ($\tau$). These include $C^0$, $C^1$, and $C^2$ continuous variants.
  • Fuzzy Logic Integration: Comparison operators (greater, less, equal, is close) are systematically formulated via fuzzy logic using the underlying Heaviside cumulative distribution functions, enabling smooth evaluations of logical conjunctions (AND, OR, XOR, NOT).
  • Axis-Wise Operator Backends: For complex axis-wise operations (Argmax, ArgSort, TopK, Quantile), the libraries provide multiple interchangeable algorithmic backends, including entropy-regularized optimal transport, SoftSort, NeuralSort, FastSoftSort, and SmoothSort.
  • The Straight-Through Pitfall: The authors identify and analyze a critical mathematical trap when applying the straight-through trick to composite functions. Naively wrapping multiple interacting functions in independent straight-through wrappers can violate the product rule and yield zero or incorrect gradients in multi-dimensional spaces.
  • Macro-Level Straight-Through Wrapping: To resolve this pitfall, the framework demonstrates that the straight-through wrapper must be applied at the macro (outermost) level of composite expressions, ensuring that forward passes utilize hard discrete evaluations while backward passes correctly propagate global soft Jacobians.

Technical Deep Dive

▶ Watch: Addressing gradient biases with the straight-through trick (6:14)

The architectural and mathematical foundation of SoftJAX and SoftTorch rests on two primary categories of operators: element-wise and axis-wise.

Element-Wise Operators

The cornerstone of element-wise soft differentiation is the Heaviside step function $H(x)$, which outputs $0$ for negative inputs and $1$ for positive inputs. In SoftJAX and SoftTorch, $H(x)$ is replaced by a parametrized sigmoidal surrogate $H_\tau(x)$, where $\tau$ controls the softness. As $\tau \to 0$, $H_\tau(x)$ approaches the hard Heaviside function.

Using $H_\tau(x)$, the libraries derive continuous approximations for:

  • Sign, Round, and Absolute Value (abs): Standard linear algebra primitives mapped through smooth conditionals.
  • Relational Operators: Greater-than and less-than operators are interpreted as cumulative distribution functions representing the probability that a Boolean proposition evaluates to true.
  • Logical Operations: Operations such as all and not are computed via joint probabilities (assuming independence) and complement rules ($1 - p$), allowing complex Boolean logic graphs to remain fully differentiable.
  • Selections: Discrete indexing and selection are executed via expectation computations using the derived probability distributions (e.g., computing a dot product between a probability vector and a tensor).

Axis-Wise Operators

Axis-wise operators extend soft differentiation across entire tensor dimensions. The standard Argmax operation, for instance, normally returns a discrete index. In SoftJAX/SoftTorch, hard mode utilizes a one-hot encoding combined with a dot product to preserve expectation mechanics, while soft mode substitutes this with a Softmax distribution over the axis.

For sorting operations like SoftSort, the pipeline proceeds as follows:

  1. Compute the hard sorted array.
  2. Calculate pairwise distances between original array elements and sorted array elements.
  3. Apply an axis-wise unit simplex projection (such as Softmax or a soft-plus transformation) to yield a row-wise probability matrix, designated as $P$ or $P^*$.
  4. Perform a dot-product computation between the input tensor and the probability matrix $P$ to produce the soft-sorted output.

Autodiff and the Straight-Through Pitfall

A major technical contribution of the libraries is navigating the tension between gradient bias and exactness. While soft surrogates yield informative gradients, they introduce approximation bias. To mitigate this, developers frequently employ the straight-through trick (famously used in straight-through estimators for quantization or hard activations like ReLU).

The standard straight-through estimator defines a composite function where the forward pass uses the hard function $F(x)$, and the backward pass substitutes the soft surrogate $F_\tau(x)$. However, the speakers highlight a dangerous pitfall in 2D and higher dimensions when evaluating products of functions (e.g., $y \cdot \text{ReLU}(x)$). If independent straight-through wrappers are applied to each sub-expression, the product rule breaks down because the forward pass inappropriately freezes terms at zero (inherited from the hard function's zero-gradient regions), neutralizing cross-terms in the Jacobian.

The Solution: SoftJAX and SoftTorch structure computations such that the entire expression is written using soft surrogates, and the stop-gradient/straight-through wrapper is applied exclusively at the outermost level. In the case of axis-wise operations like SoftSort, the forward pass executes the hard sorting operator while the Jacobian is explicitly overridden to be the probability matrix $P$ via a stop-gradient wrapper around the sorting index computation.

Experimental Setup & Results

▶ Watch: Connection between ReLU and axis-wise operators (9:51)

Note: As this talk focuses on software library design, API architecture, and mathematical formulations rather than presenting a standalone benchmark study for a new deep learning model, extensive multi-dataset evaluations are not the primary focus.

However, the authors provide computational benchmarks for axis-wise operators within the library's ecosystem, comparing the runtime and memory scaling of different sorting and optimal transport backends. Furthermore, the mathematical soundness of these implementations is supported by formal proofs provided in the paper's appendix, which establishes the smoothness characteristics of $p$-norm regularized projections.

Regarding hyperparameter tuning, the authors address the practical challenge of selecting the softness parameter $\tau$. For element-wise operators, setting $\tau$ such that the surrogate operates comfortably within a $[-1, 1]$ range is straightforward and mirrors standard practices in linear algebra frameworks. For axis-wise operations, however, automatic scaling remains an open research problem; while the appendix outlines experimental normalization schemes, the current libraries leave axis-wise scaling configurable by the user depending on the downstream application.

Practical Implications

▶ Watch: Audience Q&A and choosing default hyper-parameter tau (12:00)

For machine learning engineers, infrastructure teams, and model builders, SoftJAX and SoftTorch lower the barrier to integrating non-differentiable algorithms directly into deep learning pipelines.

  • Model Builders: Tasks that previously required heuristics, REINFORCE-style policy gradient approximations, or straight-through hacks plagued by gradient vanishing can now leverage principled, continuous relaxations. Differentiable rendering, combinatorial graph algorithms, and structured prediction tasks benefit immediately.
  • Infra and Systems Teams: Because the libraries are native to JAX and PyTorch, they integrate seamlessly with hardware acceleration (GPUs and TPUs) and support automatic vectorization and compilation.
  • Tradeoffs and Limitations: Practitioners must be mindful of two primary limitations. First, soft approximations introduce gradient bias—optimizing through a smoothed surrogate does not optimize the exact discrete objective. Second, improper usage of straight-through wrappers in multi-dimensional product expressions can lead to dead gradients, a pitfall that SoftJAX and SoftTorch explicitly help diagnose and structure around.

Key Takeaways

  • Bridging Discrete and Continuous: SoftJAX and SoftTorch provide drop-in soft differentiable approximations for discrete operators in JAX and PyTorch, enabling gradient-based optimization through sorting, ranking, argmax, and logical operations.
  • Comprehensive Operator Coverage: The libraries support both element-wise operations (Heaviside, sign, round, abs, fuzzy logic) and axis-wise operations (Argmax, ArgSort, TopK, Quantile) with multiple algorithmic backends.
  • Algorithmic Flexibility for Sorting: Axis-wise sorting operations leverage diverse mathematical backends including entropy-regularized optimal transport, NeuralSort, FastSoftSort, and SmoothSort.
  • The Straight-Through Pitfall: Applying straight-through wrappers independently to sub-expressions in multi-dimensional product rules causes silent gradient failures; wrapping must occur at the macro/outermost level.
  • Seamless Autodiff Integration: By leveraging stop-gradient operators and probability matrices (such as matrix $P$ in SoftSort), the libraries ensure forward passes execute hard operations while backward passes inherit clean, continuous Jacobians.

About the Speaker(s)

  • Andreas René Geist: Presenter of SoftJAX and SoftTorch, libraries for differentiable soft approximations to discrete operators in automatic differentiation.

Co-authors: Anselm Paulus, Vit Musil, Sebastian Hoffmann, Georg Martius.

Reviews

→ Top-rated talks at International Conference on Machine Learning 2026

All talks from International Conference on Machine Learning 2026