Skip to content

Riemannian Optimizers User Guide

Almost no Hyperbolix user needs a Riemannian optimizer. This page exists to tell you when you're in the rare case that does.

For per-optimizer signatures, see the Optimizers API reference.

TL;DR

Use optax.adam (or any Euclidean Optax optimizer). That includes:

  • All modern NN layers — HTCLinear, FGGLinear, HypConv2DHyperboloid*, HypLinearHyperboloidPLFC, HypLinearPoincarePP, HypLinearPV, all attention / normalization / regression heads.
  • Learnable curvature (via the LearnableCurvature module).

The exceptions are the layers that store a parameter on the manifold. They need riemannian_adam (or riemannian_sgd):

  • The legacy Ganea-style Poincaré layers (HypLinearPoincare, HypRegressionPoincare) parameterize their bias directly on the Poincaré ball (the kernel stays Euclidean). You can usually just migrate to the PP equivalents and stay with optax.adam.
  • LorentzEmbedding with its default parameterization="manifold" stores its table as points on the hyperboloid. One optax.adam step moves the rows off the hyperboloid. parameterization="spatial" stores a Euclidean table and works with optax.adam.

When to Use What

Setup Optimizer
Any modern hyperbolic NN (HTC, FGG, HCat, PP, HRC, PV) optax.adam
Learnable curvature (any manifold) optax.adam
Mixed Euclidean / hyperbolic networks optax.adam
Legacy HypLinearPoincare / HypRegressionPoincare riemannian_adam
LorentzEmbedding (default parameterization="manifold") riemannian_adam

That's the whole decision.

Why Modern Layers Don't Need Riemannian Optimization

Modern hyperbolic layers (HTC, FGG, HNN++, HCat, PV) store their weights as Euclidean tensors and apply the hyperbolic transformation inside the forward pass. The weights themselves never live on a manifold — they're just flat parameter tensors with Euclidean gradients. Standard Adam handles them correctly.

import optax
from flax import nnx

# Standard setup — works for every modern layer family
model = HTCClassifier(...)
optimizer = nnx.Optimizer(model, optax.adam(1e-3), wrt=nnx.Param)

Learnable Curvature Is Also Euclidean

A common confusion: surely learnable curvature needs Riemannian optimization? No. The LearnableCurvature module stores a plain Euclidean nnx.Param that is reparameterized at call time — via "log" (default, c = exp(raw), scale-invariant gradient), "softplus" (c = softplus(raw), bounded gradient near zero), or "identity" (c = raw, an unconstrained signed curvature for the Stereographic manifold) — to produce the curvature value. It gets a normal Euclidean gradient and a normal Adam update — there's nothing to project, nothing on a manifold.

from hyperbolix import LearnableCurvature

class Model(nnx.Module):
    def __init__(self, *, rngs: nnx.Rngs):
        self.curvature = LearnableCurvature(init_c=1.0)  # raw is a plain nnx.Param
        ...

optimizer = nnx.Optimizer(model, optax.adam(1e-3), wrt=nnx.Param)
# Curvature is updated by Adam alongside all other parameters.

The Legacy Ganea Exception

HypLinearPoincare and HypRegressionPoincare (Ganea et al. 2018) store their bias as a point on the Poincaré ball (the kernel stays a plain Euclidean nnx.Param). Each gradient step on that bias needs to respect the ball constraint, which is exactly what riemannian_adam provides. The constructors already tag the bias with ManifoldParam internally, so using them is just:

from hyperbolix.optim import riemannian_adam
from hyperbolix.nn_layers import HypLinearPoincare

model = HypLinearPoincare(manifold_module=poincare, in_dim=32, out_dim=16, rngs=rngs)
optimizer = nnx.Optimizer(model, riemannian_adam(1e-3), wrt=nnx.Param)

Pass the curvature you call the layer with to the constructor too (curvature=0.1, or a callable such as lambda: self.curvature() for learnable curvature). The optimizer's bias update uses it, not the call-time c.

No manual tagging step is required for these built-in layers. The same holds for LorentzEmbedding: its default table is a ManifoldParam on the hyperboloid at the c given to its constructor. If you're writing your own manifold-valued parameter instead — e.g. a hyperbolic embedding table — that's when you reach for ManifoldParam (or the mark_manifold_param convenience wrapper around an existing nnx.Param) yourself:

from hyperbolix.optim import ManifoldParam

# Tag your own manifold-valued parameter during model init
self.embedding = ManifoldParam(
    init_value, manifold=poincare, curvature=0.1,
)

The optimizer walks the model state, applies Riemannian updates wherever it finds a ManifoldParam tag, and falls back to standard Adam everywhere else. You don't need separate optimizers for the Euclidean and manifold parts.

Storage vs. compute dtype

The Riemannian update math (egrad2rgrad, expmap, ptransp) runs in the manifold's dtype, but the returned parameter updates and the momentum buffers are cast back to the parameter's storage dtype. A float32 ManifoldParam paired with a Poincare(dtype=jnp.float64) manifold therefore gets float64-precision geometry while its weights and optimizer state stay float32. See Numerical Stability.

Prefer the PP migration

If you're picking the legacy Ganea layer for new work, almost always swap it for HypLinearPoincarePP / HypRegressionPoincarePP instead. The PP variants compute the same operation with Euclidean weights, removing the need for Riemannian optimization entirely. The numerics are typically cleaner and the optimizer setup is simpler.

Learning-Rate Schedules

Both optimizers accept an optax.Schedule (any count -> lr callable) in place of a float, and re-read it on every update():

import optax
from hyperbolix.optim import riemannian_adam

schedule = optax.warmup_cosine_decay_schedule(
    init_value=0.0, peak_value=1e-3, warmup_steps=100, decay_steps=10_000
)
optimizer = nnx.Optimizer(model, riemannian_adam(schedule), wrt=nnx.Param)

The schedule is resolved at the pre-increment step count, matching optax's scale_by_schedule: the k-th update() reads schedule(k - 1), so the very first update uses schedule(0). Adam-style bias correction deliberately keeps the post-increment count (1 - beta**k), which is also what optax's scale_by_adam does — the two are different counters by design. Constant learning rates are unaffected by this distinction.

Behavior change after v1.0.0

Through v1.0.0 the schedule was resolved at the post-increment count, so a warmup ran one step ahead of the equivalent optax setup and schedule(0) was never used. Runs that pinned a schedule against an optax baseline will shift by one step.

Common Pitfalls

  1. Using riemannian_adam for HTC / FGG / PP / PV layers. Adds compute for no benefit (and occasionally slightly worse numerics). Use optax.adam.
  2. Forgetting to tag a hand-rolled manifold-valued parameter. The built-in legacy layers (HypLinearPoincare, HypRegressionPoincare) already self-tag their bias with ManifoldParam in __init__ — there's nothing to do for them. The tag matters only when you add your own manifold-valued parameter (e.g. a hyperbolic embedding table stored as a plain nnx.Param): without ManifoldParam / mark_manifold_param, riemannian_adam falls back to Euclidean Adam on it: the update ignores the ball's metric and can step the values off the ball.
  3. Expecting riemannian_adam to need a separate optimizer for the Euclidean parts. It doesn't. One optimizer with wrt=nnx.Param handles everything; dispatch is via the ManifoldParam tag.

See Also