Skip to main content

AprV2Metadata

Struct AprV2Metadata 

Source
pub struct AprV2Metadata {
Show 36 fields pub model_type: String, pub name: Option<String>, pub description: Option<String>, pub author: Option<String>, pub license: Option<String>, pub data_source: Option<String>, pub data_license: Option<String>, pub version: Option<String>, pub source: Option<String>, pub original_format: Option<String>, pub created_at: Option<String>, pub total_size: u64, pub param_count: u64, pub quantization: Option<QuantizationMetadata>, pub sharding: Option<ShardingMetadata>, pub chat_template: Option<String>, pub chat_format: Option<String>, pub special_tokens: Option<ChatSpecialTokens>, pub architecture: Option<String>, pub hf_architecture: Option<String>, pub hf_model_type: Option<String>, pub hidden_size: Option<usize>, pub num_layers: Option<usize>, pub num_heads: Option<usize>, pub num_kv_heads: Option<usize>, pub vocab_size: Option<usize>, pub intermediate_size: Option<usize>, pub max_position_embeddings: Option<usize>, pub rope_theta: Option<f32>, pub rope_type: Option<u32>, pub rms_norm_eps: Option<f32>, pub head_dim: Option<usize>, pub num_experts: Option<usize>, pub num_experts_per_tok: Option<usize>, pub moe_intermediate_size: Option<usize>, pub custom: HashMap<String, Value>,
}
Expand description

APR v2 JSON metadata section

Fields§

§model_type: String

Model type identifier

§name: Option<String>

Model name

§description: Option<String>

Model description

§author: Option<String>

Model author/organization

§license: Option<String>

Model license (SPDX identifier; governed by C-APR-PROVENANCE). NO skip_serializing_if here: FALSIFY-SHIP-022 requires provenance keys to serialize as explicit null (FM-APR-PROV-SILENT-SKIP) — and license is not a realizar alias-group member, so the null cannot trigger the duplicate-field poison (C-APR-MERGE-RUNNABLE).

§data_source: Option<String>

Training-data source (dataset identifier or “teacher-only”; governed by C-APR-PROVENANCE / AC-SHIP2-012 / FALSIFY-SHIP-022). Explicit-null serialization required — see license.

§data_license: Option<String>

SPDX license for data_source (governed by C-APR-PROVENANCE / AC-SHIP2-012 / FALSIFY-SHIP-022). Explicit-null serialization required — see license.

§version: Option<String>

Model version string

§source: Option<String>

Source/provenance URI (DD6: Model provenance tracking) Examples: “hf://openai/whisper-tiny”, “local://path/to/model.safetensors

§original_format: Option<String>

Original format before conversion Examples: “safetensors”, “gguf”, “pytorch”

§created_at: Option<String>

Creation timestamp (ISO 8601)

§total_size: u64

Total model size in bytes

§param_count: u64

Parameter count

§quantization: Option<QuantizationMetadata>

Quantization info

§sharding: Option<ShardingMetadata>

Shard info (for multi-file models)

§chat_template: Option<String>

Chat template (Jinja2 format, from tokenizer_config.json) Per spec: chat-template-improvement-spec.md CTA-01

§chat_format: Option<String>

Detected chat template format Per spec: chat-template-improvement-spec.md CTA-03 Values: “chatml”, “llama2”, “mistral”, “phi”, “alpaca”, “custom”, “raw”

§special_tokens: Option<ChatSpecialTokens>

Special tokens for chat templates Per spec: chat-template-improvement-spec.md CTA-04

§architecture: Option<String>

Model architecture family (e.g., “llama”, “qwen2”, “phi”)

§hf_architecture: Option<String>

HuggingFace class name from config.json::architectures[0] (e.g., “Qwen2ForCausalLM”, “LlamaForCausalLM”). Distinct from architecture (family) and model_type. PMAT-690 P0-K stamps this so downstream apr pretrain --init can propagate it into the trained checkpoint’s metadata.

§hf_model_type: Option<String>

HuggingFace config.json::model_type (e.g., “qwen2”, “llama”). PMAT-690 P0-K stamps this alongside hf_architecture so the import→pretrain→export chain has a single source of truth.

§hidden_size: Option<usize>

Hidden dimension size

§num_layers: Option<usize>

Number of transformer layers

§num_heads: Option<usize>

Number of attention heads

§num_kv_heads: Option<usize>

Number of key-value heads (for GQA, defaults to num_heads)

§vocab_size: Option<usize>

Vocabulary size

§intermediate_size: Option<usize>

FFN intermediate dimension

§max_position_embeddings: Option<usize>

Maximum context/sequence length

§rope_theta: Option<f32>

RoPE theta for position encoding

§rope_type: Option<u32>

RoPE type: 0=NORM (adjacent pairs), 2=NEOX (split halves) CORRECTNESS-011: Qwen2.5 models require rope_type=2 (NEOX style)

§rms_norm_eps: Option<f32>

Layer norm epsilon

§head_dim: Option<usize>

Explicit head dimension (overrides hidden_size / num_heads for Qwen3+)

§num_experts: Option<usize>

Number of MoE experts

§num_experts_per_tok: Option<usize>

Number of experts selected per token

§moe_intermediate_size: Option<usize>

MoE expert intermediate/FFN dimension

§custom: HashMap<String, Value>

Custom key-value pairs

Implementations§

Source§

impl AprV2Metadata

Source

pub fn new(model_type: impl Into<String>) -> Self

Create new empty metadata

Source

pub fn to_json(&self) -> Result<Vec<u8>, V2FormatError>

Serialize to JSON bytes

§Errors

Returns error if serialization fails.

Source

pub fn to_json_pretty(&self) -> Result<String, V2FormatError>

Serialize to pretty JSON string

§Errors

Returns error if serialization fails.

Source

pub fn canonicalize_hf_aliases(&mut self)

Canonicalize HF/GGUF-style alias keys into typed struct fields (C-APR-MERGE-RUNNABLE / FALSIFY-APR-MERGE-RUNNABLE-001).

Import-produced APR files carry HuggingFace-style dimension keys (num_hidden_layers, num_attention_heads, num_key_value_heads, …) which land in custom because this struct has no serde aliases. Realizar’s AprMetadata deserializer DOES alias them — so a file containing BOTH the canonical field (even as an explicit null) AND an alias key makes serde fail with “duplicate field”, which realizar’s mmap loader swallows via unwrap_or_default() — silently dropping ALL metadata (architecture, dims, embedded tokenizer) and producing C-01 / “no tokenizer in APR metadata” failures on a file that physically contains everything.

This method promotes alias values into the typed fields (when the field is unset) and REMOVES the alias keys from custom, so a re-serialized container has exactly one spelling per dimension.

Source

pub fn from_json(data: &[u8]) -> Result<Self, V2FormatError>

Deserialize from JSON bytes

§Errors

Returns error if deserialization fails.

Trait Implementations§

Source§

impl Clone for AprV2Metadata

Source§

fn clone(&self) -> AprV2Metadata

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AprV2Metadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AprV2Metadata

Source§

fn default() -> AprV2Metadata

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for AprV2Metadata

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for AprV2Metadata

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.