1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Pure-Rust checkpoint and tensor inspection for GGUF and Safetensors.
//!
//! The primary contract is the format-independent
//! [`checkpoint`] module: [`open_checkpoint`] detects the container
//! format and returns a [`Checkpoint`] handle that inventories tensors
//! ([`TensorInfo`], [`TensorShape`], [`TensorDType`],
//! [`TensorLocation`]), reads metadata, and fetches raw payload bytes
//! without the caller branching on GGUF vs. Safetensors.
//!
//! Beneath that contract, [`gguf`] and (feature-gated) `safetensors`
//! are format-specific backends: each exposes its own full parsing
//! surface for callers that need format semantics — GGML wire types,
//! K-quant dequant, Safetensors manifests and MoE candidate discovery.
//!
//! Model-analysis specializations live under [`analysis`]. Today that
//! is [`analysis::moe`]: per-expert raw-weight extraction over a parsed
//! [`GgufLayout`]. MoE is one analysis specialization built above the
//! parsers, not the identity of the crate.
//!
//! # Features
//!
//! - **No dependencies enabled by default**: the default path is pure Rust.
//! The optional `mmap` feature adds `memmap2`; `safetensors` adds the
//! upstream `safetensors` crate.
//! - **Parse limits**: [`ParseLimits`] is a documented budget for KV/tensor
//! counts, string sizes, array work, tensor rank, and metadata bytes.
//! File-declared `u64` sizes convert with [`HostSizeField`] errors.
//! Defaults stay generous; trusted callers override explicitly.
//! - **GGUF v3 support**: Full parsing of headers, metadata, and tensor directories
//! - **GGUF wire-type metadata**: labels + packed `byte_len` for known quant
//! codes (F32/F16/BF16, Q*/IQ*, integers, historical wire 31 = `Q4_0_4_4`).
//! Packed dequant is implemented for Q8_0, Q5_K, Q6_K, and the internal
//! IQ3_M block layout. No GGML kernels, no ggml runtime, no CUDA.
//! - **Type labels**: Human-readable names via [`ggml_type_label`] (maps the
//! on-wire `ggml_type` integer used by GGUF)
//! - **MoE analysis**: Extract expert **raw** weights (byte buffers + shape)
//! via [`analysis::moe`]; GGUF-specific.
//! - **Metadata helpers**: Architecture-aware convenience methods for common fields
//! - **Optional Safetensors**: enable `--features safetensors` for
//! inspection, deterministic manifests, MoE candidate discovery, and raw
//! tensor payload access via the upstream `safetensors` crate. Combine
//! with `--features mmap` for borrowed mmap-backed payload slices. No
//! Hugging Face `config.json` policy.
//! - **Format-independent access**: [`Checkpoint`] + [`open_checkpoint`]
//! inventory tensors, read metadata, and fetch raw payloads from GGUF
//! or Safetensors without branching on format. See [`checkpoint`].
//!
//! # Example
//!
//! Format-agnostic inventory:
//!
//! ```no_run
//! use engram_parser::{Checkpoint, open_checkpoint};
//!
//! let ckpt = open_checkpoint("model.gguf").unwrap();
//! for t in ckpt.tensors() {
//! println!("{} {} {:?} {}B", t.name, t.dtype, t.shape.dims(), t.byte_len);
//! }
//! ```
//!
//! MoE expert analysis (GGUF-specific) uses the canonical
//! [`analysis::moe`] path:
//!
//! ```no_run
//! use engram_parser::analysis::moe::{extract_expert, list_experts};
//! use engram_parser::load_gguf;
//!
//! let layout = load_gguf("moe-model.gguf").unwrap();
//! for (block, expert) in list_experts(&layout) {
//! let weights = extract_expert(&layout, block, expert).unwrap();
//! println!("blk.{block} expert {expert}: complete={}", weights.is_complete());
//! }
//! ```
//!
//! # Compatibility
//!
//! The legacy `engram_parser::moe` module and the crate-root MoE
//! symbols ([`extract_expert`], [`list_experts`], [`MoeExpertWeights`],
//! [`RawTensor`]) remain as re-exports of [`analysis::moe`] and keep
//! compiling unchanged.
// Re-export commonly used types at the crate root for convenience.
pub use SafetensorsBackend;
pub use SafetensorsMmapBackend;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
// MoE analysis result types and extractors, re-exported for
// compatibility; the canonical path is `analysis::moe`.
pub use ;