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,
)
| 30 | /// Load and run the CLIP-L encoder from a safetensors file. |
| 31 | /// Returns the pooled output (batch_size, 768). |
| 32 | pub 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 | } |
no test coverage detected