tokitai-operator 0.1.0

Verified DL kernel compiler: formally-checked GEMM, p-adic, sheaf, contract-carrying ops. Paper-artifact grade.
Documentation
//! Architecture load (JSON + SHA-256 verification).
//!
//! Reads `arch.json` and verifies the SHA-256 of the topology
//! against `arch.json.sha256`. Returns an error if the file is
//! tampered with or missing. Used by `src/infer.rs`.
//!
// Read a `ModelArch` from a JSON file.
//
// We do NOT call `arch.build()` here — load is purely a
// deserialization step. Validation (e.g. "does `hidden_dim` agree
// with `size`?") happens in `build`, so callers can inspect or fix
// a malformed arch before deciding what to do with it.

use std::fs::File;
use std::io::BufReader;
use std::path::Path;

use crate::{Error, Result};

use super::arch::ModelArch;

/// Read a `ModelArch` from the JSON file at `path`. The file is
/// expected to be pretty-printed or compact JSON; either is fine.
pub fn load_arch(path: &Path) -> Result<ModelArch> {
    let f = File::open(path)
        .map_err(|e| Error::backend(format!("arch load: open {}: {e}", path.display())))?;
    let r = BufReader::new(f);
    serde_json::from_reader(r)
        .map_err(|e| Error::backend(format!("arch load: parse {}: {e}", path.display())))
}