Skip to content

Instantly share code, notes, and snippets.

@a-agmon
Last active July 8, 2024 18:26
Show Gist options
  • Save a-agmon/7cedd4979038b11f83e404ceb8f1b978 to your computer and use it in GitHub Desktop.
Save a-agmon/7cedd4979038b11f83e404ceb8f1b978 to your computer and use it in GitHub Desktop.
const EMB_MODEL_ID: &str = "sentence-transformers/all-MiniLM-L6-v2";
const EMB_MODEL_REV: &str = "refs/pr/21";
thread_local! {
static BERT_MODEL: Rc<BertModelWrapper> = {
info!("Loading a model on thread: {:?}", std::thread::current().id());
let model = BertModelWrapper::new(candle::Device::Cpu, EMB_MODEL_ID, EMB_MODEL_REV);
match model {
Ok(model) => Rc::new(model),
Err(e) => {
panic!("Failed to load the model: {}", e);
}
}
}
}
pub fn get_model_reference() -> anyhow::Result<Rc<BertModelWrapper>> {
BERT_MODEL.with(|model| Ok(model.clone()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment