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
//! Topology fingerprint.
//!
//! Computes a stable SHA-256 hash of the topology (depth, width,
//! expert count, top-k, per-expert MLP shape). The fingerprint
//! is independent of the parameter values; it is the "what
//! model is this" identifier.
//!
// Stable short hash of a `ModelArch`, intended for cache keys, model
// registry lookups, and the patent disclosure's reproducibility
// appendix. NOT a cryptographic commitment — just a deterministic
// 16-hex-char (64-bit) digest of the canonical arch JSON.
//
// We hash the canonical JSON (sorted keys, compact form) so the
// fingerprint is stable across:
// - pretty-printed vs. compact JSON,
// - Rust struct field reordering in future versions of `ModelArch`,
// - the choice of `MoESize` representation (`"Tiny"` vs. `0`).
//
// Only fields that affect what `build` produces are part of the
// hash. We re-serialize the arch through serde_json (which is
// deterministic for our flat struct) and then SHA-256 it.
use ;
use ModelArch;
/// Return a 16-hex-char (64-bit) fingerprint of `arch`. Two arches
/// that would build to structurally identical models (same size,
/// dims, expert count, top_k, depth, and seed) hash to the same
/// string, even if the originating `ModelArch` instances are
/// distinct.