geometric_bias
geometric_bias
¶
GeometricAttentionBias
¶
GeometricAttentionBias(embedding_dimension, number_of_heads, initial_decay=5.0, decay_range=3.0, base_frequency=10000.0, use_raster_positions=False)
Bases: Module
Combines spatial and depth-aware attention biases.
Generates geometry-aware attention priors that: 1. Decay with spatial distance 2. Penalize depth discontinuities 3. Allow learnable weighting between the two
Initializes geometric attention bias generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding_dimension
|
int
|
Embedding dimension. |
required |
number_of_heads
|
int
|
Number of attention heads. |
required |
initial_decay
|
float
|
Initial decay rate for spatial distance. |
5.0
|
decay_range
|
float
|
Range of decay rates across heads. |
3.0
|
base_frequency
|
float
|
Base frequency for rotary encoding. |
10000.0
|
use_raster_positions
|
bool
|
Whether to rotate by flattened raster grid positions (the DFormerv2 reference convention) instead of axis-split 2D positions. Required for pretrained DFormerv2 checkpoints. |
False
|
Source code in src/versatil/models/layers/geometric_attention/geometric_bias.py
forward
¶
Generates complete geometric attention bias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
int
|
Grid height. |
required |
width
|
int
|
Grid width. |
required |
depth_map
|
Tensor
|
Depth map of shape (B, 1, H, W). |
required |
device
|
device
|
Computation device. |
required |
decomposition_mode
|
str
|
Full or separable attention. |
value
|
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor]
|
Tuple of ((sine, cosine), bias_masks) where: |
tuple[Tensor, ...]
|
|
tuple[tuple[Tensor, Tensor], tuple[Tensor, ...]]
|
|