#[allow(dead_code)]
pub struct Pretrained {
pub(super) name: &'static str,
pub(super) model: &'static str,
pub(super) tokenizer: &'static str,
}
#[cfg(feature = "pretrained")]
#[cfg_attr(docsrs, doc(cfg(feature = "pretrained")))]
mod downloader {
use super::*;
use burn::data::network::downloader;
use std::fs::{File, create_dir_all};
use std::io::Write;
use std::path::PathBuf;
impl Pretrained {
fn download(&self, url: &str) -> Result<PathBuf, std::io::Error> {
let model_dir = dirs::home_dir()
.expect("Should be able to get home directory")
.join(".cache")
.join("llama-burn")
.join(self.name);
if !model_dir.exists() {
create_dir_all(&model_dir)?;
}
let file_base_name = url
.rsplit_once('/')
.unwrap()
.1
.replace("?download=true", "");
let file_name = model_dir.join(&file_base_name);
if !file_name.exists() {
let bytes = downloader::download_file_as_bytes(url, &file_base_name);
let mut output_file = File::create(&file_name)?;
output_file.write_all(&bytes)?; }
Ok(file_name)
}
pub fn download_weights(&self) -> Result<PathBuf, std::io::Error> {
self.download(self.model)
}
pub fn download_tokenizer(&self) -> Result<PathBuf, std::io::Error> {
self.download(self.tokenizer)
}
}
}
pub trait ModelMeta {
fn pretrained(&self) -> Pretrained;
}
pub enum Llama {
Llama3,
Llama3Instruct,
Llama31Instruct,
Llama323bInstruct,
Llama321bInstruct,
TinyLlama,
}
impl ModelMeta for Llama {
fn pretrained(&self) -> Pretrained {
match self {
Self::Llama3 => Pretrained {
name: "Llama-3-8B",
model: "https://huggingface.co/tracel-ai/llama-3-8b-burn/resolve/main/model.mpk?download=true",
tokenizer: "https://huggingface.co/tracel-ai/llama-3-8b-burn/resolve/main/tokenizer.model?download=true",
},
Self::Llama3Instruct => Pretrained {
name: "Llama-3-8B-Instruct",
model: "https://huggingface.co/tracel-ai/llama-3-8b-instruct-burn/resolve/main/model.mpk?download=true",
tokenizer: "https://huggingface.co/tracel-ai/llama-3-8b-instruct-burn/resolve/main/tokenizer.model?download=true",
},
Self::Llama31Instruct => Pretrained {
name: "Llama-3.1-8B-Instruct",
model: "https://huggingface.co/tracel-ai/llama-3.1-8b-instruct-burn/resolve/main/model.mpk?download=true",
tokenizer: "https://huggingface.co/tracel-ai/llama-3.1-8b-instruct-burn/resolve/main/tokenizer.model?download=true",
},
Self::Llama323bInstruct => Pretrained {
name: "Llama-3.2-3B-Instruct",
model: "https://huggingface.co/tracel-ai/llama-3.2-3b-instruct-burn/resolve/main/model.mpk?download=true",
tokenizer: "https://huggingface.co/tracel-ai/llama-3.2-3b-instruct-burn/resolve/main/tokenizer.model?download=true",
},
Self::Llama321bInstruct => Pretrained {
name: "Llama-3.2-1B-Instruct",
model: "https://huggingface.co/tracel-ai/llama-3.2-1b-instruct-burn/resolve/main/model.mpk?download=true",
tokenizer: "https://huggingface.co/tracel-ai/llama-3.2-1b-instruct-burn/resolve/main/tokenizer.model?download=true",
},
Self::TinyLlama => Pretrained {
name: "TinyLlama-1.1B",
model: "https://huggingface.co/tracel-ai/tiny-llama-1.1b-burn/resolve/main/model.mpk?download=true",
tokenizer: "https://huggingface.co/tracel-ai/tiny-llama-1.1b-burn/resolve/main/tokenizer.json?download=true",
},
}
}
}