Skip to main content

qualify_checkpoints/
qualify_checkpoints.rs

1//! Verify the pinned generative qualification fixtures without initializing a GPU.
2//! Offline by default; `--fetch` also downloads missing files into the Hub cache.
3use hrx::artifacts::{hf, safetensors::FileView};
4use serde::Deserialize;
5
6#[derive(Deserialize)]
7struct Repository {
8    owner: String,
9    repository: String,
10    revision: String,
11    files: Vec<File>,
12}
13
14#[derive(Deserialize)]
15struct File {
16    name: String,
17    sha256: String,
18}
19
20fn main() -> Result<(), Box<dyn std::error::Error>> {
21    let args: Vec<_> = std::env::args().skip(1).collect();
22    let fetch = match args.as_slice() {
23        [] => false,
24        [argument] if argument == "--fetch" => true,
25        _ => return Err("usage: qualify_checkpoints [--fetch]".into()),
26    };
27    let repositories: Vec<Repository> =
28        serde_json::from_str(include_str!("../native/qualification/checkpoints.json"))?;
29    let mut failures = 0;
30    for repository in repositories {
31        let resolver = hf::Resolver::new(
32            hf::Repository::new(&repository.owner, &repository.repository).at(&repository.revision),
33        )
34        .offline(!fetch);
35        for file in repository.files {
36            eprintln!(
37                "Checking {}/{} at {}: {}",
38                repository.owner, repository.repository, repository.revision, file.name
39            );
40            let result = (|| -> hrx::Result<()> {
41                let path = resolver.resolve(&hf::HubFile::new(file.name).sha256(file.sha256))?;
42                // SAFETY: qualification requires completed, immutable cache files.
43                // The Hub publishes downloads atomically; do not mutate these files
44                // while this command is running.
45                let view = unsafe { FileView::map(&path)? };
46                println!("OK: {} tensors, {}", view.entries().len(), path.display());
47                Ok(())
48            })();
49            if let Err(error) = result {
50                failures += 1;
51                eprintln!("FAILED: {error}");
52            }
53        }
54    }
55    if failures != 0 {
56        return Err(format!("{failures} checkpoint(s) failed qualification").into());
57    }
58    Ok(())
59}