Attention & Transformer¶
Three hyperbolic attention variants from the Hypformer paper (Yang et al. 2025,
Section 4.3). All operate on hyperboloid points and support independent curvatures for
input (c_in), attention computation (c_attn), and output (c_out), plus causal
(autoregressive) masking via causal=True. c_attn and c_out default to c_in, so
a call that passes only c_in keeps all three curvatures equal. For complexity/use-case trade-offs see
the NN Layers guide.
The supporting utilities (spatial_to_hyperboloid, lorentz_midpoint,
focus_transform) are documented under Primitives. The Hypformer
transformation component HTCLinear (used for MLP sublayers) is on the
Linear page; HRC normalization is on the
Normalization page.
Attention modules¶
hyperbolix.nn_layers.HyperbolicLinearAttention ¶
HyperbolicLinearAttention(
in_features: int,
out_features: int,
*,
num_heads: int = 1,
power: float = 2.0,
init_bound: float | None = None,
eps: float = 1e-07,
param_dtype: DTypeLike = jnp.float32,
rngs: Rngs,
)
Bases: _HyperbolicAttentionBase
Hyperbolic linear attention with focus function (Eq 14-19).
The paper's main contribution: O(N) attention using the kernel trick in the spatial domain of the hyperboloid. Focus function φ sharpens query and key.
Differences from Hypformer
- No focus temperature. Hypformer learns a temperature
tinside the focus function. :func:focus_transformis homogeneous of degree 1 in1/(|t| + eps), soφ(Q)andφ(K)both scale by it, and the outputφ(Q)(φ(K)^T V) / φ(Q)(φ(K)^T 1)seestonly through theepsfloors inside :func:focus_transform, in the bidirectional and the causal form alike. Its gradient measured 5 to 7 orders of magnitude below the other parameters', so it stays near its init; the parameter is omitted and the layer usest = 1, the old init, which leaves the output at init unchanged. - No additive
epson the kernel-ratio denominator. Hypformer divides byden + 1e-6.φis strictly positive, soden > 0, but a query whose spatial part is≤ 0on a head hasφ(Q) ≈ eps^powerandden ~ 1e-13at the defaultpower = 2, where+ epsreturns≈ 0for that head instead of its attention average. The layer divides bydenfloored at the smallest normal number of the working dtype promoted to at least float32, a floor that acts only on an underflowedden.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_features
|
int
|
Ambient input dimension ( |
required |
out_features
|
int
|
Spatial output dimension per head. |
required |
num_heads
|
int
|
Number of attention heads (default: 1). |
1
|
power
|
float
|
Focus function sharpening exponent (default: 2.0). |
2.0
|
init_bound
|
float or None
|
Uniform init bound forwarded to the HTCLinear projections; |
None
|
eps
|
float
|
Numerical stability floor (default: 1e-7). |
1e-07
|
param_dtype
|
DTypeLike
|
Storage dtype of the trainable parameters (default: jnp.float32).
This layer takes no |
float32
|
rngs
|
Rngs
|
Random number generators. |
required |
Source code in hyperbolix/nn_layers/hyperboloid_attention.py
hyperbolix.nn_layers.HyperbolicSoftmaxAttention ¶
HyperbolicSoftmaxAttention(
in_features: int,
out_features: int,
*,
num_heads: int = 1,
init_bound: float | None = None,
eps: float = 1e-07,
param_dtype: DTypeLike = jnp.float32,
rngs: Rngs,
)
Bases: _HyperbolicAttentionBase
Hyperbolic softmax attention in the spatial domain.
Standard scaled dot-product attention applied to spatial components of query, key, value, followed by the same HRC pipeline (residual + time calibration) as the linear variant.
The scores are scaled, masked and softmaxed in at least float32, and the weights are cast back to the working dtype, so bfloat16/float16 inputs get a float32 softmax; float32 and float64 inputs are unaffected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_features
|
int
|
Ambient input dimension ( |
required |
out_features
|
int
|
Spatial output dimension per head. |
required |
num_heads
|
int
|
Number of attention heads (default: 1). |
1
|
init_bound
|
float or None
|
Uniform init bound forwarded to the HTCLinear projections; |
None
|
eps
|
float
|
Numerical stability floor (default: 1e-7). |
1e-07
|
param_dtype
|
DTypeLike
|
Storage dtype of the trainable parameters (default: jnp.float32).
This layer takes no |
float32
|
rngs
|
Rngs
|
Random number generators. |
required |
Source code in hyperbolix/nn_layers/hyperboloid_attention.py
hyperbolix.nn_layers.HyperbolicFullAttention ¶
HyperbolicFullAttention(
in_features: int,
out_features: int,
*,
num_heads: int = 1,
init_bound: float | None = None,
eps: float = 1e-07,
param_dtype: DTypeLike = jnp.float32,
score_dtype: DTypeLike | None = None,
centroid_form: Literal["variance", "gemm"] = "variance",
init_tau: float | None = None,
rngs: Rngs,
)
Bases: _HyperbolicAttentionBase
Full Lorentzian attention with midpoint aggregation.
Uses the Lorentzian inner product for similarity and weighted Lorentzian midpoint for aggregation — operating on full hyperboloid points throughout.
The score of query Q and key K is (2/c + 2<Q,K>_L) / tau, which is
-d_L^2(Q, K) / tau with d_L^2 = -2/c - 2<Q,K>_L the squared Lorentzian
distance. tau = exp(log_tau) is one learnable temperature shared by all heads.
The scores are masked and softmaxed in at least float32, and the weights are cast
back to the working dtype.
Differences from Hypformer
- Temperature parameterization. Hypformer divides by a raw learnable
scale. Nothing keeps it positive: an optimizer step can drive it to 0 or below, and a negative value flips the softmax so each query attends to its farthest keys. Here the parameter islog_tauandtau = exp(log_tau)is positive for any parameter value. The init is Hypformer's,tau = sqrt(out_features)(the per-head spatial width), unlessinit_tauis given. - No score bias. Hypformer adds one learnable scalar to every score. A constant shared by all keys of a row cancels in the softmax, so that parameter changes nothing and its gradient is exactly zero; it is omitted.
- Curvature constant. Hypformer writes
2 + 2<Q,K>_L, thec = 1form; here it is2/c. The constant cancels in the softmax as well, so the weights are the same, but the score is the scaled negative squared distance for anyc.
Float32 score floor
The score contains <Q,K>_L = -Q_0 K_0 + <Q_s, K_s>, a difference of two
Minkowski terms each of size cosh(a_q) cosh(a_k) / c — writing
a = sqrt(c) d for the geodesic radius of a point in nats — whose O(1)
difference is the only part the softmax sees. Unlike the other cancellations in
the library this one has no GEMM-compatible cancellation-free spelling: any
matrix product of the ambient coordinates returns the Gram matrix to absolute
eps, so the angular term alone already carries an error of
eps sinh(a_q) sinh(a_k) / c, the same order as the literal form. The absolute
error on one score is therefore
eps * cosh(a_q) * cosh(a_k) / (c * tau)
which with float32's eps ≈ 1.19e-7 (c = 1, tau = 1) is about 4.8e-3
at a = 6, 0.26 at a = 8 and 2.0 at a = 9. The default
tau = sqrt(out_features) divides these numbers by tau, but it divides the
score spread by the same factor, so the radius where the error overtakes the
spread does not move: from a ≈ 8 the error exceeds the score spread the
softmax is meant to resolve, and the weights are wrong while staying perfectly
finite. Three remedies, cheapest first: keep the
radius down (a :class:HyperboloidGyroRMSNorm in front of the layer), use a
smaller c, or pass score_dtype=jnp.float64 to run the score computation as
a float64 island. The island casts only the spatial parts of the queries and keys
and rebuilds both time coordinates from them in float64, so its scores are those of
a float64 layer fed the same float32 spatial coordinates; what is left is the cost
of storing the spatial part in float32, far below the cancellation. Measured
against a float64 layer on the unrounded points (c = 1, tau = 1, 16
spatial dimensions, 12 tokens, query and key clouds at scaled radius a whose
directions lie within about 8/sinh(a) of each other, worst of three draws),
the largest score error at a = 4 / 8 / 12 is 3.8e-4 / 1.1 / 4.2e3 by default
and 1.1e-5 / 4.9e-4 / 2.7e-2 with the island, and the largest attention-weight
error 7.5e-5 / 0.21 / 1.0 against 9.4e-7 / 3.4e-5 / 1.7e-3; other draws move
these maxima by up to a factor of 2. The value aggregation stays in the working
dtype: in self-attention at a = 8 and a = 12 the island's float32 output
lies 1.2e-4 and 7.7e-3 nats from the float64 output, against 6e-4 to 1e-2
(depending on the draw) and 4.2 by default. The exact pairwise polar-frame
evaluation, which would remove the cancellation in float32, is O(N·M·D) in memory
and is not implemented here.
Centroid form
Each head aggregates its values with :func:lorentz_midpoint in
form=centroid_form. "variance" (the default) is the cancellation-free direct
variance, accurate to the storage floor. It is the default because this layer is the
library's geometrically faithful O(N²) attention, and its accuracy on far-out values
is pinned by tests (test_full_attention_aggregates_far_values_accurately and its
per-head-ray sibling). Its cost is an elementwise (B, H, N, M, D) intermediate:
O(N M D) work outside the GEMMs, materialized in memory where XLA does not fuse
it away.
"gemm" is for long sequences. It normalizes h = sum_m w_m v_m by the literal
c (h_0^2 - ||h_s||^2): one GEMM plus O(N) work per head. Measured on an A100,
float32 forward+backward, B = 2, H = 4, D = 32, causal, variance against
gemm: compile 15.9 s against 4.0 s and step 2.44 ms against 1.93 ms at N = 512;
compile 17.2 s against 4.8 s and step 16.5 ms against 9.5 ms at N = 2048
(logs/2026-09-30_helm-decisions/full_attention_centroid_probe_gpu*.out). The
normalizer cancels, with relative error up to eps cosh^2(a) at value radius
a (float32: 9e-5 at a = 4, 0.27 at a = 8). This depends on the values
alone: with queries and keys near the origin, where the scores are float32-accurate,
and values at a = 9, the float32 output of "gemm" lies 5.7 to 11 nats from
the float64 run, against 5e-7 to 4.5e-4 for "variance"
(logs/2026-09-30_helm-decisions/far_values_gemm_probe.out). Use "gemm" only
when the values stay well inside a ≈ 6 or run in float64.
The average over heads (a midpoint of the H head aggregates of each token) always
uses the variance form: its intermediate is (B, N, H, D), the size of the layer's
input, so the GEMM form would save next to nothing (measured: 0.7 s of compile, under
2 % of the step) and would cancel when the head aggregates lie close together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_features
|
int
|
Ambient input dimension ( |
required |
out_features
|
int
|
Spatial output dimension per head. |
required |
num_heads
|
int
|
Number of attention heads (default: 1). |
1
|
init_bound
|
float or None
|
Uniform init bound forwarded to the HTCLinear projections; |
None
|
eps
|
float
|
Numerical stability floor (default: 1e-7). |
1e-07
|
param_dtype
|
DTypeLike
|
Storage dtype of the trainable parameters (default: jnp.float32).
This layer takes no |
float32
|
score_dtype
|
DTypeLike or None
|
When set, the spatial parts of the queries and keys are cast to this dtype, both
time coordinates are rebuilt from them in this dtype at the attention curvature,
and the Lorentzian similarity and the |
None
|
centroid_form
|
(variance, gemm)
|
|
"variance"
|
init_tau
|
float or None
|
Initial score temperature |
None
|
rngs
|
Rngs
|
Random number generators. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
log_tau |
Param
|
Scalar log temperature, init |
Source code in hyperbolix/nn_layers/hyperboloid_attention.py
Latent attention (HELM)¶
LorentzMLA is the attention block of HELM (He et al. 2025): DeepSeek-style
multi-head latent attention on the hyperboloid. Keys and values are decompressed from
one low-rank latent point per token, queries and keys carry a decoupled
HOPE-rotated slice, and each head averages its values with
the weighted Lorentzian centroid. It takes one model curvature c and supports
causal, packed-sequence (segment_ids) and padding (attention_mask) masks. The
mixture-of-curvature feed-forward block that pairs with it is on the
Mixture of Curvature Experts page.
hyperbolix.nn_layers.LorentzMLA ¶
LorentzMLA(
dim: int,
num_heads: int,
kv_lora_rank: int,
qk_nope_head_dim: int,
qk_rope_head_dim: int,
v_head_dim: int,
*,
rngs: Rngs,
rope_base: float = 10000.0,
rms_epsilon: float = 1e-08,
init_tau: float | None = None,
init_bound: float | None = None,
param_dtype: DTypeLike = jnp.float32,
eps: float = 1e-07,
centroid_form: Literal["gemm", "variance"] = "gemm",
score_precision: PrecisionLike = MATMUL_PRECISION,
)
Bases: Module
Hyperbolic multi-head latent attention (HMLA, HELM's LorentzMLA).
Forward pass, for input points x on the hyperboloid <x, x>_L = -1/c:
q = wq(x)(spatial,H * Kwide), split per head intoq_nope(N) andq_pe(P);q_peis HOPE-rotated.wkv_a(x)(spatial,R + Pwide) is split into the latent(R,)and onek_pe(P,)per token, shared by all heads and HOPE-rotated.- The latent is RMS-normalized and given a time coordinate (
HRCRMSNorm, spatial input), thenwkv_bdecompresses it intok_nope(N) and the value space (V) per head. q = [q_nope, q_pe],k = [k_nope, k_pe]andvget their time coordinates rebuilt from the hyperboloid constraint (HELM's "Lorentz concatenation").- Scores
(2/c + 2 <q, k>_L) / tau-- the negative squared Lorentzian distance divided by one learnable temperaturetau = exp(log_tau)shared by all heads; masked, softmaxed in at least float32. - Each head takes the weighted Lorentzian centroid of its values (:func:
lorentz_midpointwithform=centroid_form; the default"gemm"is HELM'slorentzian_centroid, one GEMM plusO(S)work per head), the per-head ambient points (time included) are flattened to(H * W,), andwomaps them to the output point.
Only HELM's q_lora_rank = 0 path (a direct query projection) is implemented; HELM's
YaRN mscale adjustment of tau for extended contexts and its (commented-out) KV cache
are not.
Differences from the HELM code
- Temperature init. HELM initializes
tau = sqrt(H * L)(Lthe ambient query/key head width),sqrt(H)larger than the per-headsqrt(L)of standard scaled dot-product attention, so its initial softmax issqrt(H)times flatter. That is the default here too;init_tau=math.sqrt(qk_nope_head_dim + qk_rope_head_dim)gives the per-head scaling. - Temperature parameterization. HELM learns
tauitself (self.softmax_scale, a raw parameter that its training script weight-decays toward 0). Nothing keeps thattaupositive: an optimizer step can drive it to 0 or below, and a negativetauflips the softmax so each query attends to its farthest keys. Here the parameter islog_tauandtau = exp(log_tau), positive for any parameter value, with the sametauat init. The gradient step is then relative totau, and weight decay onlog_taupullstautoward 1 rather than 0. - No score bias. HELM adds one learnable scalar to every score
(
scores / self.softmax_scale + self.bias). A constant shared by all keys of a row cancels in the softmax, so that parameter changes nothing and its gradient is exactly zero; it is omitted. - Library forms replace HELM's clamps: the centroid is :func:
lorentz_midpoint, whoseepsfloor sits onc |<h, h>_L|rather than HELM's1e-8on|<h, h>_L|and whose time coordinate is rebuilt from the spatial part; the other time coordinates come from :func:spatial_to_hyperboloid. - Score and centroid GEMMs. The two score GEMMs default to HIGHEST and can be lowered
with
score_precision. The centroid GEMM is always HIGHEST. HELM's code runs both at the framework default.
Conventions
- Head dimensions follow HELM:
qk_nope_head_dimcounts spatial coordinates, whileqk_rope_head_dimandv_head_dimcount ambient coordinates (their spatial widths areqk_rope_head_dim - 1andv_head_dim - 1). A query/key head is therefore a point withqk_nope_head_dim + qk_rope_head_dimambient coordinates and a value head one withv_head_dim.dimis ambient. - Curvature: HELM's manifold parameter
khas<x, x>_L = -k; hyperbolix'schas<x, x>_L = -1/c, soc = 1/kand HELM's score2k + 2<q, k>_Lis2/c + 2<q, k>_Lhere.
Float32 score floor
The score is formed from GEMMs of the ambient coordinates, so it inherits the floor of
:class:HyperbolicFullAttention (docs: numerical-stability.md#attention-score-floor):
<q, k>_L = -q_0 k_0 + <q_s, k_s> subtracts two terms of size
cosh(a_q) cosh(a_k) / c (a = sqrt(c) d the scaled radius) to reach an O(1)
difference, and the absolute score error is about 2 eps cosh(a_q) cosh(a_k) / (c tau).
In float32 (c = 1, tau = 1) it reaches O(1) near a ~ 8. A bfloat16 input runs
these GEMMs in bfloat16, whose eps is 2^16 times float32's; since the error grows as
e^(2a), that moves the same error down by ln(2^16) / 2 ~ 5.5 nats of radius. The
weights stay finite either way, just wrong. Keep the radius down, or run the layer in
float32/float64. The two score GEMMs are pinned to HIGHEST by default; a lower
score_precision (DEFAULT, which is TF32 on Ampere/Hopper) adds its own rounding on top
of the cancellation described here. The measured trade-off is under score_precision.
Centroid form
centroid_form="gemm" (the default) normalizes h = sum_t w_t v_t by the literal
c (h_0^2 - ||h_s||^2): one GEMM and O(S T) memory per head, like the scores. This
is the HELM paper form of the centroid, the one HELM uses. It is the default because at LLM
context lengths the alternative is impractical on GPU: centroid_form="variance", the cancellation-free direct variance
of :func:lorentz_midpoint, forms an elementwise (B, H, S, T, v_head_dim - 1)
intermediate, O(S T D) work outside the GEMMs and as much memory where XLA
materializes it (XLA:CPU does in the backward, about 100 GB in float32 at B = 8,
H = 12, S = T = 2048, v_head_dim = 64). XLA:GPU fuses it away, but that fused kernel
took about 55 s to compile against 9 s for "gemm" at S = 512 (forward plus
backward, A100, jax 0.9.1; a forward-only jit took about 9 min against 3 s), and ptxas had
not finished it after 10 min at S = 2048.
The price of "gemm" is cancellation in the normalizer, with relative error up to
eps cosh^2(a) at value radius a (float32: 9e-5 at a = 4, 0.27 at a = 8).
This depends on the values alone, not on the score floor above: in float32 "gemm"
loses the centroid once the values lie beyond scaled radius a ≈ 6, even when the
queries and keys sit near the origin and the scores are accurate (measured on this layer,
values at a ≈ 9: 11.4 nats from the float64 centroid, against at most 6.4e-4 for
"variance"; logs/2026-09-30_helm-decisions/mla_far_values_probe.out, pinned by
test_variance_centroid_aggregates_far_values_accurately). For short sequences, or
whenever the values can lie far out, use centroid_form="variance", which is accurate
to the storage floor. The centroid GEMM h = sum_t w_t v_t is always HIGHEST, whatever
score_precision says.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
int
|
Model ambient dimension |
required |
num_heads
|
int
|
Number of attention heads |
required |
kv_lora_rank
|
int
|
Spatial width |
required |
qk_nope_head_dim
|
int
|
Spatial width |
required |
qk_rope_head_dim
|
int
|
Ambient width of the rotated slice; its spatial width |
required |
v_head_dim
|
int
|
Ambient width |
required |
rngs
|
Rngs
|
Random number generators for parameter initialization. |
required |
rope_base
|
float
|
HOPE frequency base (default: 10000.0, HELM's). |
10000.0
|
rms_epsilon
|
float
|
Epsilon of the latent RMSNorm (default: 1e-8, HELM's |
1e-08
|
init_tau
|
float or None
|
Initial temperature |
None
|
init_bound
|
float or None
|
Uniform init bound shared by all four projections. |
None
|
param_dtype
|
DTypeLike
|
Storage dtype of the parameters (default: jnp.float32). Compute follows the input dtype. |
float32
|
eps
|
float
|
Numerical floor for the time rebuilds and the centroid (default: 1e-7). |
1e-07
|
centroid_form
|
(gemm, variance)
|
|
"gemm"
|
score_precision
|
PrecisionLike
|
Precision of the two attention-score einsums only (default: In the trained HELM-MiCE 120M model (queries and keys below scaled radius |
MATMUL_PRECISION
|
Attributes:
| Name | Type | Description |
|---|---|---|
wq |
HTCLinear
|
|
wkv_a |
HTCLinear
|
|
kv_norm |
HRCRMSNorm
|
RMSNorm of the |
wkv_b |
HTCLinear
|
|
wo |
HTCLinear
|
|
log_tau |
Param
|
Scalar log temperature, init |
References
He et al., "HELM: Hyperbolic Large Language Models via Mixture-of-Curvature Experts", 2025 (arXiv:2505.24722).
Source code in hyperbolix/nn_layers/hyperboloid_mla.py
__call__ ¶
__call__(
x_BSA: Float[Array, "B S A"],
c: float = 1.0,
*,
positions: Int[Array, S]
| Int[Array, "B S"]
| None = None,
causal: bool = True,
segment_ids: Int[Array, "B S"] | None = None,
attention_mask: Bool[Array, "B S"] | None = None,
) -> Float[Array, "B S A"]
Attend over a sequence of hyperboloid points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_BSA
|
(Array, shape(B, S, A))
|
Input points on the hyperboloid with curvature |
required |
c
|
float
|
Curvature ( |
1.0
|
positions
|
int Array of shape (S,) or (B, S)
|
HOPE positions of the tokens; |
None
|
causal
|
bool
|
If True, query |
True
|
segment_ids
|
int Array of shape (B, S)
|
Document ids of packed sequences; a query attends only to keys with the same id (HELM's block-diagonal document mask) (default: None). |
None
|
attention_mask
|
bool Array of shape (B, S)
|
|
None
|
Returns:
| Type | Description |
|---|---|
(Array, shape(B, S, A))
|
Output points on the hyperboloid with curvature |
Notes
The masks are combined with a logical AND and applied as HELM does, by filling the
masked scores with -1e18: a query row with no valid key gets a uniform (finite)
softmax over all keys rather than NaN.
Source code in hyperbolix/nn_layers/hyperboloid_mla.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
Causal (autoregressive) masking¶
All three variants support causal=True: position n attends only to positions
m ≤ n, required for autoregressive tasks. Masking is JIT-compatible.
How causal masking is implemented
HyperbolicSoftmaxAttention/HyperbolicFullAttention: lower-triangular mask on the score matrix before softmax, which sets the masked scores to the finite value-1e18— O(N²) in both modes.HyperbolicLinearAttention: a cumulative-sum recurrence (jax.lax.scan, Katharopoulos et al. 2020):S_i = Σ_{j≤i} φ(K_j) V_jᵀ, O(1) per step → O(N) total, well-suited to long autoregressive sequences.
Example¶
import jax, jax.numpy as jnp
from flax import nnx
from hyperbolix.manifolds import Hyperboloid
from hyperbolix.nn_layers import HyperbolicLinearAttention
hyperboloid = Hyperboloid()
B, N, A_in, D_out = 4, 8, 9, 8 # 8-dim spatial + 1 time
spatial = jax.random.normal(jax.random.PRNGKey(0), (B, N, A_in - 1)) * 0.1
time = jnp.sqrt(jnp.sum(spatial**2, axis=-1, keepdims=True) + 1.0)
x = jnp.concatenate([time, spatial], axis=-1) # (B, N, A_in) on the hyperboloid
attn = HyperbolicLinearAttention(in_features=A_in, out_features=D_out, num_heads=2, power=2.0, rngs=nnx.Rngs(0))
y = attn(x, c_in=1.0, c_attn=1.0, c_out=1.0) # bidirectional
y_causal = attn(x, c_in=1.0, c_attn=1.0, c_out=1.0, causal=True)
print(y.shape) # (4, 8, 9) — D_out spatial + 1 time
See the NN Layers guide (Pattern 3) for a full hyperbolic transformer block.