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

Function encode_clip

cake-core/src/models/flux/clip_encoder.rs:32–52  ·  view source on GitHub ↗

Load and run the CLIP-L encoder from a safetensors file. Returns the pooled output (batch_size, 768).

(
    checkpoint_path: &std::path::Path,
    prefix: &str,
    input_ids: &Tensor,
    device: &Device,
)

Source from the content-addressed store, hash-verified

30/// Load and run the CLIP-L encoder from a safetensors file.
31/// Returns the pooled output (batch_size, 768).
32pub fn encode_clip(
33 checkpoint_path: &std::path::Path,
34 prefix: &str,
35 input_ids: &Tensor,
36 device: &Device,
37) -> Result<Tensor> {
38 let cfg = clip_l_config();
39
40 info!("loading CLIP-L text encoder...");
41 let vb = unsafe {
42 VarBuilder::from_mmaped_safetensors(&[checkpoint_path.to_path_buf()], DType::F32, device)?
43 };
44 let vb = vb.pp(prefix).pp("text_model");
45
46 let model = ClipTextTransformer::new(vb, &cfg)?;
47 info!("CLIP-L loaded, encoding...");
48
49 // CLIP forward returns pooled output at END token position
50 let output = model.forward(input_ids)?;
51 Ok(output)
52}

Callers 1

generate_imageMethod · 0.85

Calls 2

clip_l_configFunction · 0.85
forwardMethod · 0.45

Tested by

no test coverage detected