Skip to content

Commit

Permalink
Allow specifying multiple mirrors for partitioned models
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam committed Mar 28, 2024
1 parent 9978225 commit 848b28e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/tabby-common/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct ModelInfo {
#[serde(skip_serializing_if = "Option::is_none")]
pub urls: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub partition_urls: Option<Vec<String>>,
pub partition_urls: Option<Vec<Vec<String>>>,
pub sha256: String,
}

Expand Down
21 changes: 19 additions & 2 deletions crates/tabby-download/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ use tokio_retry::{
};
use tracing::{info, warn};

fn download_host() -> String {
std::env::var("TABBY_DOWNLOAD_HOST").unwrap_or("huggingface.co".to_owned())
}

Check warning on line 19 in crates/tabby-download/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-download/src/lib.rs#L17-L19

Added lines #L17 - L19 were not covered by tests

async fn download_model_impl(
registry: &ModelRegistry,
name: &str,
Expand Down Expand Up @@ -45,7 +49,7 @@ async fn download_model_impl(
return download_split_model(&model_info, &model_path).await;
}

let registry = std::env::var("TABBY_DOWNLOAD_HOST").unwrap_or("huggingface.co".to_owned());
let registry = download_host();
let Some(model_url) = model_info
.urls
.iter()
Expand Down Expand Up @@ -74,7 +78,20 @@ async fn download_split_model(model_info: &ModelInfo, model_path: &Path) -> Resu
}
let mut paths = vec![];
let partition_urls = model_info.partition_urls.clone().unwrap_or_default();
for (index, url) in partition_urls.iter().enumerate() {
let mirror = download_host();

Check warning on line 81 in crates/tabby-download/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-download/src/lib.rs#L72-L81

Added lines #L72 - L81 were not covered by tests

let Some(urls) = partition_urls
.iter()
.find(|urls| urls.iter().all(|url| url.contains(&mirror)))

Check warning on line 85 in crates/tabby-download/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-download/src/lib.rs#L83-L85

Added lines #L83 - L85 were not covered by tests
else {
return Err(anyhow!(
"Invalid mirror <{}> for model urls: {:?}",
mirror,
partition_urls
));

Check warning on line 91 in crates/tabby-download/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-download/src/lib.rs#L87-L91

Added lines #L87 - L91 were not covered by tests
};

for (index, url) in urls.iter().enumerate() {
let ext = format!(
"{}.{}",
model_path.extension().unwrap_or_default().to_string_lossy(),
Expand Down

0 comments on commit 848b28e

Please sign in to comment.