Last active
July 8, 2024 18:26
-
-
Save a-agmon/7cedd4979038b11f83e404ceb8f1b978 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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