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

Method embedding

cake-core/src/backends/mod.rs:513–528  ·  view source on GitHub ↗

Embedding lookup: select rows from weight matrix by token IDs.

(&self, ids: &Tensor, weight: &Tensor)

Source from the content-addressed store, hash-verified

511
512 /// Embedding lookup: select rows from weight matrix by token IDs.
513 fn embedding(&self, ids: &Tensor, weight: &Tensor) -> Result<Tensor> {
514 let hidden_size = weight.dim(1)?;
515 let dims = ids.dims();
516 // Fast path: 1D input — no reshape needed
517 if dims.len() == 1 {
518 let selected = weight.index_select(ids, 0)?;
519 return Ok(selected);
520 }
521 // General path: flatten, select, reshape
522 let elem_count: usize = dims.iter().product();
523 let flat_ids = ids.reshape(elem_count)?;
524 let selected = weight.index_select(&flat_ids, 0)?;
525 let mut out_shape = dims.to_vec();
526 out_shape.push(hidden_size);
527 selected.reshape(out_shape.as_slice())
528 }
529
530 /// Create a causal attention mask. Returns a U8 tensor of shape `(seq_len, kv_len)`
531 /// where 1 = masked (future position), 0 = attend.

Callers 11

embedding_lookupFunction · 0.80
encodeMethod · 0.80
forwardMethod · 0.80
generateMethod · 0.80
loadMethod · 0.80
generateMethod · 0.80
forwardMethod · 0.80
test_embedding_lookupFunction · 0.80
test_embedding_2d_idsFunction · 0.80

Implementers 5

mod.rscake-core/src/backends/rocm/mod.rs
mod.rscake-core/src/backends/cpu/mod.rs
mod.rscake-core/src/backends/metal/mod.rs
mod.rscake-core/src/backends/vulkan/mod.rs
mod.rscake-core/src/backends/cuda/mod.rs

Calls 3

to_vecMethod · 0.80
as_sliceMethod · 0.80
pushMethod · 0.45

Tested by 4

test_embedding_lookupFunction · 0.64
test_embedding_2d_idsFunction · 0.64