Creating new sync Api for candle-hub.

- `api::Api` -> `api::tokio::api` (And created new `api::sync::Api`).
- Remove `tokio` from all our examples.
- Using similar codebase for now instead of ureq (for simplicity).
This commit is contained in:
Nicolas Patry
2023-07-06 15:15:25 +02:00
parent dd60bd84bb
commit 115629fe08
9 changed files with 719 additions and 29 deletions

View File

@ -5,7 +5,7 @@ extern crate intel_mkl_src;
use anyhow::{anyhow, Error as E, Result};
use candle::{safetensors::SafeTensors, DType, Device, Shape, Tensor};
use candle_hub::{api::Api, Cache, Repo, RepoType};
use candle_hub::{api::sync::Api, Cache, Repo, RepoType};
use clap::Parser;
use serde::Deserialize;
use std::collections::HashMap;
@ -645,7 +645,7 @@ struct Args {
}
impl Args {
async fn build_model_and_tokenizer(&self) -> Result<(BertModel, Tokenizer)> {
fn build_model_and_tokenizer(&self) -> Result<(BertModel, Tokenizer)> {
let device = if self.cpu {
Device::Cpu
} else {
@ -677,9 +677,9 @@ impl Args {
} else {
let api = Api::new()?;
(
api.get(&repo, "config.json").await?,
api.get(&repo, "tokenizer.json").await?,
api.get(&repo, "model.safetensors").await?,
api.get(&repo, "config.json")?,
api.get(&repo, "tokenizer.json")?,
api.get(&repo, "model.safetensors")?,
)
};
let config = std::fs::read_to_string(config_filename)?;
@ -694,12 +694,11 @@ impl Args {
}
}
#[tokio::main]
async fn main() -> Result<()> {
fn main() -> Result<()> {
let start = std::time::Instant::now();
let args = Args::parse();
let (model, mut tokenizer) = args.build_model_and_tokenizer().await?;
let (model, mut tokenizer) = args.build_model_and_tokenizer()?;
let device = &model.device;
if let Some(prompt) = args.prompt {