MCPcopy Create free account
hub / github.com/evilsocket/cake / mask

Method mask

cake-core/src/models/common/cache.rs:150–160  ·  view source on GitHub ↗

Get the attention mask for the given sequence length.

(&mut self, seq_len: usize, device: &Device)

Source from the content-addressed store, hash-verified

148
149 /// Get the attention mask for the given sequence length.
150 pub fn mask(&mut self, seq_len: usize, device: &Device) -> Result<Tensor> {
151 // Always create/cache on self.device, then copy to target if needed
152 if !self.masks.contains_key(&seq_len) {
153 let mask: Vec<_> = (0..seq_len)
154 .flat_map(|i| (0..seq_len).map(move |j| u8::from(j > i)))
155 .collect();
156 let mask = Tensor::from_slice(&mask, (seq_len, seq_len), &self.device)?;
157 self.masks.insert(seq_len, mask);
158 }
159 self.masks.get(&seq_len).unwrap().clone().to_device(device)
160 }
161
162 /// Process the input k and v by either generating their cache entry or applying a previously cached one.
163 pub fn process_kv(

Callers 6

cache_maskFunction · 0.80
forwardMethod · 0.80
forwardMethod · 0.80
test_mask_causal_shapeFunction · 0.80

Calls 2

cloneMethod · 0.45
getMethod · 0.45