pub enum StoredDtype {
Bf16,
F32,
Q8,
Q4,
}Expand description
How a tensor’s elements are stored in the container.
Narrow on purpose, and unknown values are refused. The high-precision variants exist because the quant recipe protects norms, codebooks, and the speaker path — an artifact that claims a dtype we have never conformed is a refusal, not a best-effort read.
Variants§
Bf16
bfloat16, kept verbatim from the checkpoint.
F32
32-bit float.
Q8
int8 with separate per-group scales.
Q4
int4, two elements per byte, with separate per-group scales.
Implementations§
Source§impl StoredDtype
impl StoredDtype
Sourcepub const fn as_str(self) -> &'static str
pub const fn as_str(self) -> &'static str
The stable wire string.
Examples found in repository?
examples/fttsq_census.rs (line 85)
41fn main() {
42 let path = std::env::args().nth(1).unwrap_or_else(|| {
43 eprintln!("usage: fttsq_census <artifact.fttsq>");
44 std::process::exit(2);
45 });
46 let mapped = match MappedFttsq::open(&path) {
47 Ok(mapped) => mapped,
48 Err(error) => {
49 eprintln!("refusing census: {error}");
50 std::process::exit(1);
51 }
52 };
53 let reader = mapped.reader();
54 let file_bytes = mapped.len() as u64;
55
56 let mut class_bytes: BTreeMap<&str, u64> = BTreeMap::new();
57 let mut sections_total = 0_u64;
58 for section in reader.sections() {
59 sections_total += section.length;
60 *class_bytes
61 .entry(section.access_class.as_str())
62 .or_default() += section.length;
63 row(
64 "section",
65 &[
66 ("name", quoted(§ion.name)),
67 ("access_class", quoted(section.access_class.as_str())),
68 ("bytes", section.length.to_string()),
69 ("share_of_file", share(section.length, file_bytes)),
70 ],
71 );
72 }
73
74 // Dtype split inside each section: separates payload from quantization-scale overhead and
75 // shows how much of a "quantized" section is still wide.
76 let mut dtype_bytes: BTreeMap<(String, &str), u64> = BTreeMap::new();
77 let mut scale_bytes: BTreeMap<String, u64> = BTreeMap::new();
78 let scale_names: std::collections::BTreeSet<&str> = reader
79 .tensors()
80 .iter()
81 .filter_map(|tensor| tensor.scales.as_deref())
82 .collect();
83 for tensor in reader.tensors() {
84 *dtype_bytes
85 .entry((tensor.section.clone(), tensor.dtype.as_str()))
86 .or_default() += tensor.length;
87 if scale_names.contains(tensor.name.as_str()) {
88 *scale_bytes.entry(tensor.section.clone()).or_default() += tensor.length;
89 }
90 }
91 for ((section, dtype), bytes) in &dtype_bytes {
92 row(
93 "section_dtype",
94 &[
95 ("section", quoted(section)),
96 ("dtype", quoted(dtype)),
97 ("bytes", bytes.to_string()),
98 ("share_of_file", share(*bytes, file_bytes)),
99 ],
100 );
101 }
102 for (section, bytes) in &scale_bytes {
103 row(
104 "scale_overhead",
105 &[
106 ("section", quoted(section)),
107 ("bytes", bytes.to_string()),
108 ("share_of_file", share(*bytes, file_bytes)),
109 ],
110 );
111 }
112
113 for (class, bytes) in &class_bytes {
114 row(
115 "access_class",
116 &[
117 ("access_class", quoted(class)),
118 ("bytes", bytes.to_string()),
119 ("share_of_file", share(*bytes, file_bytes)),
120 ],
121 );
122 }
123 row(
124 "total",
125 &[
126 ("file_bytes", file_bytes.to_string()),
127 ("section_bytes", sections_total.to_string()),
128 (
129 "header_directory_bytes",
130 (file_bytes - sections_total).to_string(),
131 ),
132 ("model_family", quoted(reader.model_family())),
133 ],
134 );
135}Sourcepub const fn storage_bytes(self, elements: u64) -> Option<u64>
pub const fn storage_bytes(self, elements: u64) -> Option<u64>
Storage bytes for elements values, or None on overflow.
Q4 packs two elements per byte and rounds up, so an odd element count still occupies a whole trailing byte.
Trait Implementations§
Source§impl Clone for StoredDtype
impl Clone for StoredDtype
Source§fn clone(&self) -> StoredDtype
fn clone(&self) -> StoredDtype
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for StoredDtype
Source§impl Debug for StoredDtype
impl Debug for StoredDtype
Source§impl Display for StoredDtype
impl Display for StoredDtype
impl Eq for StoredDtype
Source§impl Ord for StoredDtype
impl Ord for StoredDtype
Source§fn cmp(&self, other: &StoredDtype) -> Ordering
fn cmp(&self, other: &StoredDtype) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for StoredDtype
impl PartialEq for StoredDtype
Source§impl PartialOrd for StoredDtype
impl PartialOrd for StoredDtype
impl StructuralPartialEq for StoredDtype
Auto Trait Implementations§
impl Freeze for StoredDtype
impl RefUnwindSafe for StoredDtype
impl Send for StoredDtype
impl Sync for StoredDtype
impl Unpin for StoredDtype
impl UnsafeUnpin for StoredDtype
impl UnwindSafe for StoredDtype
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more