mirror of
https://github.com/huggingface/text-generation-inference.git
synced 2025-09-11 12:24:53 +00:00
Trying to fix that flaky test.
This commit is contained in:
parent
16958fe312
commit
29fa60ec3e
@ -548,26 +548,12 @@ pub(crate) struct ErrorResponse {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::io::Write;
|
|
||||||
use tokenizers::Tokenizer;
|
use tokenizers::Tokenizer;
|
||||||
|
|
||||||
pub(crate) async fn get_tokenizer() -> Tokenizer {
|
pub(crate) async fn get_tokenizer() -> Tokenizer {
|
||||||
let filename = std::path::Path::new("tokenizer.json");
|
let api = hf_hub::api::sync::Api::new().unwrap();
|
||||||
if !filename.exists() {
|
let repo = api.model("gpt2".to_string());
|
||||||
let content = reqwest::get("https://huggingface.co/gpt2/raw/main/tokenizer.json")
|
let filename = repo.get("tokenizer.json").unwrap();
|
||||||
.await
|
Tokenizer::from_file(filename).unwrap()
|
||||||
.unwrap()
|
|
||||||
.bytes()
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let tmp_filename = "tokenizer.json.temp";
|
|
||||||
let mut file = std::fs::File::create(tmp_filename).unwrap();
|
|
||||||
file.write_all(&content).unwrap();
|
|
||||||
// Re-check if another process has written this file maybe.
|
|
||||||
if !filename.exists() {
|
|
||||||
std::fs::rename(tmp_filename, filename).unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Tokenizer::from_file("tokenizer.json").unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user