Skip to content

Loading a local model using candle #423

Answered by manifest
manifest asked this question in Q&A
Discussion options

You must be logged in to vote

The working example

let device = Device::Cpu;

let config_filename = "path/to/checkpoint/config.json";
let config_filename = std::fs::read_to_string(config_filename)?;
let config: Config = serde_json::from_str(&config_filename)?;

let tokenizer_filename = "path/to/checkpoint/tokenizer.json";
let tokenizer = Tokenizer::from_file(tokenizer_filename).map_err(anyhow::Error::msg)?;

let parameters_filename = "path/to/checkpoint/model.safetensors";
let params = unsafe { VarBuilder::from_mmaped_safetensors(&[parameters_filename], DTYPE, &device)? };

let model = DistilBertModel::load(params, &config)?;

Replies: 5 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@manifest
Comment options

@manifest
Comment options

Answer selected by manifest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants