against_reality/
against_reality.rs1use hearth_resolve::plan::RepoFile;
4use hearth_resolve::{
5 pick_gguf, plan_from_hf_files, plan_from_ollama_manifest, HfSource, QuantChoice, Reference,
6};
7
8fn gib(b: u64) -> f64 {
9 b as f64 / (1024.0 * 1024.0 * 1024.0)
10}
11
12fn main() {
13 let manifest: serde_json::Value =
15 serde_json::from_str(&std::fs::read_to_string("/tmp/ollama_manifest.json").unwrap())
16 .unwrap();
17 let r = Reference::parse("llama3").unwrap();
18 let (ns, nm) = match &r {
19 Reference::Ollama {
20 namespace, name, ..
21 } => (namespace.clone(), name.clone()),
22 _ => unreachable!(),
23 };
24 let p = plan_from_ollama_manifest(
25 &manifest,
26 "https://registry.ollama.ai",
27 &ns,
28 &nm,
29 r.key(),
30 r.display_name(),
31 )
32 .unwrap();
33 println!("OLLAMA {}", p.display_name);
34 println!(" key {}", p.key);
35 println!(" blobs {} (filtered from 4 layers)", p.blobs.len());
36 println!(" size {:.2} GiB", gib(p.total_bytes().unwrap()));
37 println!(" digest {}", p.blobs[0].digest.as_deref().unwrap());
38 println!(" url {}", p.blobs[0].url);
39
40 let hf: serde_json::Value =
42 serde_json::from_str(&std::fs::read_to_string("/tmp/hf.json").unwrap()).unwrap();
43 let files: Vec<RepoFile> = hf["siblings"]
44 .as_array()
45 .unwrap()
46 .iter()
47 .map(|s| RepoFile {
48 path: s["rfilename"].as_str().unwrap().to_string(),
49 size_bytes: s.get("size").and_then(|v| v.as_u64()),
50 })
51 .filter(|f| f.path.ends_with(".gguf"))
52 .collect();
53 println!("\nHUGGINGFACE {} gguf files in the repo", files.len());
54
55 let hr = Reference::parse("hf:TheBloke/Llama-2-7B-GGUF").unwrap();
56 let (picked, quant, chose) = pick_gguf(&files, None).unwrap();
57 let plan = plan_from_hf_files(
58 HfSource {
59 owner: "TheBloke",
60 repo: "Llama-2-7B-GGUF",
61 revision: "main",
62 },
63 picked,
64 QuantChoice {
65 quant: quant.clone(),
66 chosen_for_you: chose,
67 },
68 hr.key(),
69 hr.display_name(),
70 );
71 println!(
72 " auto {} ({:.2} GiB){}",
73 quant,
74 gib(plan.total_bytes().unwrap()),
75 if chose { " <- we chose this" } else { "" }
76 );
77 println!(" url {}", plan.blobs[0].url);
78
79 let (pinned, q2, chose2) = pick_gguf(&files, Some("Q8_0")).unwrap();
80 println!(
81 " pinned {} ({:.2} GiB){}",
82 q2,
83 gib(pinned.iter().filter_map(|f| f.size_bytes).sum::<u64>()),
84 if chose2 {
85 " <- we chose"
86 } else {
87 " <- caller chose"
88 }
89 );
90
91 match pick_gguf(&files, Some("Q9_MEGA")) {
92 Ok(_) => println!(" BAD: accepted a quant that does not exist"),
93 Err(e) => println!(" bogus quant -> {}", &e.0[..e.0.len().min(96)]),
94 }
95}