pub struct TwoWayAttentionBlock { /* private fields */ }Expand description
A two-way attention block: tokens attend to themselves and to the image, then the image attends back to the tokens — so both representations are updated in a single block.
Implementations§
Source§impl TwoWayAttentionBlock
impl TwoWayAttentionBlock
Sourcepub fn new(
embed_dim: usize,
n_heads: usize,
mlp_dim: usize,
rng: &mut LcgRng,
) -> VisionResult<Self>
pub fn new( embed_dim: usize, n_heads: usize, mlp_dim: usize, rng: &mut LcgRng, ) -> VisionResult<Self>
Sourcepub fn forward(
&self,
tokens: &[f32],
image: &[f32],
query_pe: &[f32],
key_pe: &[f32],
) -> VisionResult<TwoWayBlockOutput>
pub fn forward( &self, tokens: &[f32], image: &[f32], query_pe: &[f32], key_pe: &[f32], ) -> VisionResult<TwoWayBlockOutput>
Forward pass.
tokens/query_pe are [n_t · e]; image/key_pe are [n_i · e].
The positional encodings are added to queries and keys only (never to
the values), exactly as in SAM.
§Errors
VisionError::DimensionMismatchon inconsistent lengths.- Propagates attention errors.
Auto Trait Implementations§
impl Freeze for TwoWayAttentionBlock
impl RefUnwindSafe for TwoWayAttentionBlock
impl Send for TwoWayAttentionBlock
impl Sync for TwoWayAttentionBlock
impl Unpin for TwoWayAttentionBlock
impl UnsafeUnpin for TwoWayAttentionBlock
impl UnwindSafe for TwoWayAttentionBlock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more