olm.nn.embeddings.positional.base¶
Classes¶
PositionalEmbeddingBase(*args, **kwargs) |
Abstract base class for all positional embedding implementations. |
|---|---|
class olm.nn.embeddings.positional.base.ABC¶
Bases: object
Helper class that provides a standard way to create an ABC using inheritance.
class olm.nn.embeddings.positional.base.PositionalEmbeddingBase(*args: Any, **kwargs: Any)¶
Bases: Module, ABC
Abstract base class for all positional embedding implementations.
Positional embeddings add information about token positions in a sequence to help the model understand order and relative positions. Different positional embedding strategies have different properties:
- Learned (Absolute): Simple, effective, but limited to max_seq_len
- Sinusoidal: Deterministic, can extrapolate to longer sequences
- RoPE: Applied to Q/K directly, enables relative position modeling
- ALiBi: Adds bias to attention scores, excellent extrapolation
All positional embedding implementations should inherit from this base class and implement the forward method.
extra_repr() → str¶
String representation of the module for debugging.
Override this in subclasses to provide useful information.
abstractmethod forward(*args, **kwargs) → torch.Tensor¶
Apply positional information to input tensor(s).
The signature and behavior of this method varies by implementation: - Some add to embeddings (Absolute, Sinusoidal) - Some rotate representations (RoPE) - Some return bias to add to attention scores (ALiBi)
- Returns: Transformed tensor(s) with positional information applied
olm.nn.embeddings.positional.base.abstractmethod(funcobj)¶
A decorator indicating abstract methods.
Requires that the metaclass is ABCMeta or derived from it. A class that has a metaclass derived from ABCMeta cannot be instantiated unless all of its abstract methods are overridden. The abstract methods can be called using any of the normal ‘super’ call mechanisms. abstractmethod() may be used to declare abstract methods for properties and descriptors.
Usage:
class C(metaclass=ABCMeta): : @abstractmethod def my_abstract_method(self, arg1, arg2, argN):
…