metrale_model_layers/quant_format/modelopt.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! 2026-09-25: The ModelOpt NVFP4 layout (`.weight`, `.weight_scale`,
4//! `.weight_scale_2`, optional `.input_scale`), mapped to
5//! [`Nvfp4Variant::Standard`].
6//!
7//! Owner: model-layers (weight loading).
8//! Invariants: none beyond the types.
9
10use crate::quant_format::{IgnoreList, QuantFormat};
11use crate::weight_map::Nvfp4Variant;
12use metrale_config::precision_plan::IgnoreDialect;
13
14/// 2026-09-25: A ModelOpt checkpoint, and the fallback of
15/// [`super::detect_quant_format`] when no quantized weights are found.
16#[derive(Debug)]
17pub struct ModeloptFormat {
18 /// 2026-09-25: The config's `quant_algo`; nothing in this module reads it,
19 /// and [`QuantFormat::base_variant`] is `Standard` whatever it says.
20 pub algo: String,
21 /// 2026-09-30: The modules that ship unquantized, matched as the format specifies.
22 pub ignore: IgnoreList,
23}
24
25impl ModeloptFormat {
26 /// 2026-09-30: A malformed ignore entry is refused.
27 pub fn new(algo: String, ignore_modules: &[String]) -> anyhow::Result<Self> {
28 Ok(Self {
29 algo,
30 ignore: IgnoreList::new(IgnoreDialect::ModelOpt, ignore_modules)?,
31 })
32 }
33}
34
35impl QuantFormat for ModeloptFormat {
36 fn name(&self) -> &'static str {
37 "modelopt"
38 }
39
40 fn base_variant(&self) -> Nvfp4Variant {
41 Nvfp4Variant::Standard
42 }
43
44 fn is_ignored(&self, module_path: &str) -> bool {
45 self.ignore.matches(module_path)
46 }
47}