gensbi.models.tarflow.pe#
Rotary positional embedding for the transformer flow.
Adapted from apple/ml-starflow (STARFlow); see
models/tarflow/LICENSE.starflow. Faithful JAX port of the reference
misc/pe.py, restricted to the paths GenSBI uses.
Deliberately omitted relative to the reference: the is_1d branch (used
only for the pretrained-LM top block), freqs_for='pixel'/'constant' and
custom_freqs, the latent_len head-dim split (STARFlow’s text-prefix
“3D” axis — GenSBI positions prefix tokens at the identity rotation
instead; see docs/superpowers/specs/2026-07-11-tarflow-rope-kvcache-design.md),
video duplicate handling, and the deprecated checkpoint-compat buffers.
Classes#
2D vision RoPE with the |
Functions#
|
Apply a rotary embedding: |
|
2D patch positions in raster order (reference |
|
Rotate adjacent channel pairs: |
Module Contents#
- class gensbi.models.tarflow.pe.VisionRotaryEmbedding(dim, pt_seq_len=16, theta=10000)[source]#
Bases:
flax.nnx.Module2D vision RoPE with the
'lang'frequency schedule.Port of the reference
VisionRotaryEmbeddingFastwithout thelatent_lensplit: each of the two position axes is rotated with the same1 / theta**(2i/dim)frequency table, and the concatenated per-axis angles are repeated pairwise to cover2*dimchannels (= the full head dimension whendim = head_dim // 2).- Parameters:
dim (int) – Half the attention head dimension. Must be even.
pt_seq_len (int, optional) – Pre-training sequence length recorded for position building. Default is 16.
theta (int, optional) – Frequency base. Default is 10000.
- gensbi.models.tarflow.pe.apply_rope(t, freqs)[source]#
Apply a rotary embedding:
t*cos(freqs) + rotate_half(t)*sin(freqs).- Parameters:
t (Array) – Tensor to rotate; last dimension even.
freqs (Array) – Rotation angles, broadcastable to
t’s shape.
- Returns:
Rotated tensor, same shape as
t.- Return type:
Array
- gensbi.models.tarflow.pe.get_positions(h, w, pt_seq_len=None)[source]#
2D patch positions in raster order (reference
'2d'mode).Coordinates are normalized by
sqrt(h*w)and rescaled topt_seq_len(the reference’s resolution-transfer schedule). For a square grid withpt_seq_len == h == wthis reduces to plain integer coordinates.- Parameters:
h (int) – Patch-grid height and width.
w (int) – Patch-grid height and width.
pt_seq_len (int or None, optional) – Pre-training sequence length; defaults to
sqrt(h*w).
- Returns:
Positions of shape
(h*w, 2).- Return type:
Array