mlex 0.1.2

Safe, idiomatic Rust runtime for Apple MLX: quantized LLM inference (Qwen, Gemma4, NemotronH, DharaAR, ...) with multi-modal support
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
//! Qwen3.5 / Qwen3.6 hybrid architecture: most decoder layers use the
//! linear-time `GatedDeltaNet` recurrence (see `gated_delta.rs`), with a
//! plain GQA self-attention layer every `full_attention_interval` layers.
//! Also covers the MoE variant (Qwen3.6-A3B) via `SparseMoeBlock`.
//!
//! Checkpoints whose `config.json` carries a `vision_config` sub-dict (and
//! ship the matching `vision_tower.*` weights - see [`vision`]) additionally
//! accept image input: [`Qwen35Model::forward_with_media`] splices the
//! vision tower's projected patch features into the text embedding stream
//! at `image_token_id` placeholder positions before the decoder stack runs
//! (video frames arrive as ordinary entries of `images`, one vision-tower
//! pass per frame). Text-only checkpoints are unaffected: the tower stays
//! `None` and `forward` behaves exactly as before.

pub mod vision;

use serde_json::Value;

use crate::array::Array;
use crate::error::{Error, Result};
use crate::media::image::ProcessedImage;
use crate::nn::{Embedding, Linear, RmsNorm, WeightMap};
use crate::ops::{self, AttentionMask};
use crate::quant::Quantization;

use super::base::{attention_mask_for, merge_heads, splice_media_features, RopeConfig};
use super::cache::{GatedDeltaCache, LayerCache};
use super::config::{get_bool, get_f32, get_i32, require_i32, text_config};
use super::gated_delta::{GatedDeltaConfig, GatedDeltaNet};
use super::moe::SparseMoeBlock;
use vision::{Qwen35VisionConfig, Qwen35VisionTower};

#[derive(Debug, Clone)]
pub struct Qwen35Config {
    pub hidden_size: i32,
    pub num_hidden_layers: i32,
    pub intermediate_size: i32,
    pub num_attention_heads: i32,
    pub num_key_value_heads: i32,
    pub head_dim: i32,
    pub rms_norm_eps: f32,
    pub vocab_size: i32,
    pub tie_word_embeddings: bool,
    pub attention_bias: bool,
    pub rope_theta: f32,
    pub partial_rotary_factor: f32,
    pub full_attention_interval: i32,

    pub linear_num_value_heads: i32,
    pub linear_num_key_heads: i32,
    pub linear_key_head_dim: i32,
    pub linear_value_head_dim: i32,
    pub linear_conv_kernel_dim: i32,

    pub num_experts: i32,
    pub num_experts_per_tok: i32,
    pub decoder_sparse_step: i32,
    pub moe_intermediate_size: i32,
    pub shared_expert_intermediate_size: i32,
    pub norm_topk_prob: bool,
}

impl Qwen35Config {
    pub fn from_json(cfg: &Value) -> Result<Self> {
        let cfg = text_config(cfg);
        let hidden_size = require_i32(cfg, "hidden_size")?;
        let num_attention_heads = require_i32(cfg, "num_attention_heads")?;
        let head_dim = get_i32(cfg, "head_dim", hidden_size / num_attention_heads);
        let rope = cfg.get("rope_parameters");
        let rope_theta = rope
            .and_then(|r| r.get("rope_theta"))
            .and_then(|v| v.as_f64())
            .map(|v| v as f32)
            .unwrap_or(100_000.0);
        let partial_rotary_factor = rope
            .and_then(|r| r.get("partial_rotary_factor"))
            .and_then(|v| v.as_f64())
            .map(|v| v as f32)
            .unwrap_or(0.25);

        Ok(Qwen35Config {
            hidden_size,
            num_hidden_layers: require_i32(cfg, "num_hidden_layers")?,
            // Absent on checkpoints where every layer is MoE (e.g. Qwen3.6-A3B),
            // since `Mlp::load` (the dense fallback) is then never reached.
            intermediate_size: get_i32(cfg, "intermediate_size", 0),
            num_attention_heads,
            num_key_value_heads: get_i32(cfg, "num_key_value_heads", num_attention_heads),
            head_dim,
            rms_norm_eps: get_f32(cfg, "rms_norm_eps", 1e-6),
            vocab_size: require_i32(cfg, "vocab_size")?,
            tie_word_embeddings: get_bool(cfg, "tie_word_embeddings", false),
            attention_bias: get_bool(cfg, "attention_bias", false),
            rope_theta,
            partial_rotary_factor,
            full_attention_interval: get_i32(cfg, "full_attention_interval", 4),
            linear_num_value_heads: get_i32(cfg, "linear_num_value_heads", 64),
            linear_num_key_heads: get_i32(cfg, "linear_num_key_heads", 16),
            linear_key_head_dim: get_i32(cfg, "linear_key_head_dim", 192),
            linear_value_head_dim: get_i32(cfg, "linear_value_head_dim", 128),
            linear_conv_kernel_dim: get_i32(cfg, "linear_conv_kernel_dim", 4),
            num_experts: get_i32(cfg, "num_experts", 0),
            num_experts_per_tok: get_i32(cfg, "num_experts_per_tok", 0),
            decoder_sparse_step: get_i32(cfg, "decoder_sparse_step", 1),
            moe_intermediate_size: get_i32(cfg, "moe_intermediate_size", 0),
            shared_expert_intermediate_size: get_i32(cfg, "shared_expert_intermediate_size", 0),
            norm_topk_prob: get_bool(cfg, "norm_topk_prob", true),
        })
    }

    fn is_linear_layer(&self, layer_idx: i32) -> bool {
        (layer_idx + 1) % self.full_attention_interval != 0
    }
}

struct Attention {
    q_proj: Linear,
    k_proj: Linear,
    v_proj: Linear,
    o_proj: Linear,
    q_norm: RmsNorm,
    k_norm: RmsNorm,
    rope: RopeConfig,
    n_heads: i32,
    n_kv_heads: i32,
    head_dim: i32,
    scale: f32,
}

impl Attention {
    fn load(w: &mut WeightMap, prefix: &str, cfg: &Qwen35Config) -> Result<Self> {
        let attn = format!("{prefix}.self_attn");
        let rope_dims = ((cfg.head_dim as f32) * cfg.partial_rotary_factor) as i32;
        Ok(Attention {
            q_proj: w.linear(&format!("{attn}.q_proj"))?,
            k_proj: w.linear(&format!("{attn}.k_proj"))?,
            v_proj: w.linear(&format!("{attn}.v_proj"))?,
            o_proj: w.linear(&format!("{attn}.o_proj"))?,
            q_norm: w.rms_norm(&format!("{attn}.q_norm"), cfg.rms_norm_eps)?,
            k_norm: w.rms_norm(&format!("{attn}.k_norm"), cfg.rms_norm_eps)?,
            rope: RopeConfig::new(rope_dims, cfg.rope_theta),
            n_heads: cfg.num_attention_heads,
            n_kv_heads: cfg.num_key_value_heads,
            head_dim: cfg.head_dim,
            scale: (cfg.head_dim as f32).powf(-0.5),
        })
    }

    fn forward(
        &self,
        x: &Array,
        mask: AttentionMask,
        cache: &mut super::cache::KvCache,
    ) -> Result<Array> {
        let shape = x.shape();
        let (b, l) = (shape[0], shape[1]);

        let q_out = self.q_proj.forward(x)?;
        let q_out = ops::reshape(&q_out, &[b, l, self.n_heads, 2 * self.head_dim])?;
        let parts = ops::split(&q_out, 2, -1)?;
        let (queries, gate) = (&parts[0], &parts[1]);
        let gate = ops::reshape(gate, &[b, l, self.n_heads * self.head_dim])?;

        let k = self.k_proj.forward(x)?;
        let v = self.v_proj.forward(x)?;
        let k = ops::reshape(&k, &[b, l, self.n_kv_heads, self.head_dim])?;
        let v = ops::reshape(&v, &[b, l, self.n_kv_heads, self.head_dim])?;

        let queries = self.q_norm.forward(queries)?;
        let queries = ops::transpose_axes(&queries, &[0, 2, 1, 3])?;
        let k = self.k_norm.forward(&k)?;
        let k = ops::transpose_axes(&k, &[0, 2, 1, 3])?;
        let v = ops::transpose_axes(&v, &[0, 2, 1, 3])?;

        let offset = cache.offset();
        let queries = self.rope.apply(&queries, offset)?;
        let k = self.rope.apply(&k, offset)?;
        let (k, v) = cache.update_and_fetch(k, v)?;

        let out = ops::scaled_dot_product_attention(&queries, &k, &v, self.scale, mask)?;
        let out = merge_heads(&out, b, l)?;
        let gated = ops::multiply(&out, &ops::sigmoid(&gate)?)?;
        self.o_proj.forward(&gated)
    }
}

struct Mlp {
    gate_proj: Linear,
    up_proj: Linear,
    down_proj: Linear,
}

impl Mlp {
    fn load(w: &mut WeightMap, prefix: &str, hidden: i32, intermediate: i32) -> Result<Self> {
        let _ = (hidden, intermediate);
        Ok(Mlp {
            gate_proj: w.linear(&format!("{prefix}.gate_proj"))?,
            up_proj: w.linear(&format!("{prefix}.up_proj"))?,
            down_proj: w.linear(&format!("{prefix}.down_proj"))?,
        })
    }

    fn forward(&self, x: &Array) -> Result<Array> {
        let gate = ops::silu(&self.gate_proj.forward(x)?)?;
        let up = self.up_proj.forward(x)?;
        self.down_proj.forward(&ops::multiply(&gate, &up)?)
    }
}

enum Mixer {
    Linear(GatedDeltaNet),
    Attention(Attention),
}

enum FeedForward {
    Dense(Mlp),
    Moe(SparseMoeBlock),
}

struct Block {
    mixer: Mixer,
    ff: FeedForward,
    input_layernorm: RmsNorm,
    post_attention_layernorm: RmsNorm,
}

impl Block {
    fn load(w: &mut WeightMap, prefix: &str, cfg: &Qwen35Config, layer_idx: i32) -> Result<Self> {
        let is_linear = cfg.is_linear_layer(layer_idx);
        let mixer = if is_linear {
            let gd_cfg = GatedDeltaConfig {
                num_v_heads: cfg.linear_num_value_heads,
                num_k_heads: cfg.linear_num_key_heads,
                head_k_dim: cfg.linear_key_head_dim,
                head_v_dim: cfg.linear_value_head_dim,
                conv_kernel_size: cfg.linear_conv_kernel_dim,
                rms_norm_eps: cfg.rms_norm_eps,
            };
            Mixer::Linear(GatedDeltaNet::load(
                w,
                &format!("{prefix}.linear_attn"),
                &gd_cfg,
            )?)
        } else {
            Mixer::Attention(Attention::load(w, prefix, cfg)?)
        };

        let use_moe = cfg.num_experts > 0 && (layer_idx + 1) % cfg.decoder_sparse_step == 0;
        let ff = if use_moe {
            FeedForward::Moe(SparseMoeBlock::load(w, &format!("{prefix}.mlp"), cfg)?)
        } else {
            FeedForward::Dense(Mlp::load(
                w,
                &format!("{prefix}.mlp"),
                cfg.hidden_size,
                cfg.intermediate_size,
            )?)
        };

        Ok(Block {
            mixer,
            ff,
            input_layernorm: w.rms_norm(&format!("{prefix}.input_layernorm"), cfg.rms_norm_eps)?,
            post_attention_layernorm: w.rms_norm(
                &format!("{prefix}.post_attention_layernorm"),
                cfg.rms_norm_eps,
            )?,
        })
    }

    fn forward(&self, x: &Array, mask: AttentionMask, cache: &mut LayerCache) -> Result<Array> {
        let normed = self.input_layernorm.forward(x)?;
        let r = match &self.mixer {
            Mixer::Linear(m) => m.forward(&normed, cache.as_gated_delta()?)?,
            Mixer::Attention(m) => m.forward(&normed, mask, cache.as_attention()?)?,
        };
        let h = ops::add(x, &r)?;
        let ff_in = self.post_attention_layernorm.forward(&h)?;
        let ff_out = match &self.ff {
            FeedForward::Dense(m) => m.forward(&ff_in)?,
            FeedForward::Moe(m) => m.forward(&ff_in)?,
        };
        ops::add(&h, &ff_out)
    }

    fn is_linear(&self) -> bool {
        matches!(self.mixer, Mixer::Linear(_))
    }
}

/// Optional image support (`Some` only on checkpoints whose `config.json`
/// carries a `vision_config` sub-dict with a matching `vision_tower.*`
/// weight set).
struct VisionSupport {
    tower: Qwen35VisionTower,
    image_token_id: i32,
    vision_start_token_id: i32,
    vision_end_token_id: i32,
    video_token_id: i32,
}

pub struct Qwen35Model {
    pub config: Qwen35Config,
    embed_tokens: Embedding,
    layers: Vec<Block>,
    norm: RmsNorm,
    lm_head: Option<Linear>,
    vision: Option<VisionSupport>,
}

impl Qwen35Model {
    pub fn load(mut weights: WeightMap, config_json: &Value) -> Result<Self> {
        let cfg = Qwen35Config::from_json(config_json)?;

        let embed_tokens = weights.embedding("language_model.model.embed_tokens")?;
        let mut layers = Vec::with_capacity(cfg.num_hidden_layers as usize);
        for i in 0..cfg.num_hidden_layers {
            layers.push(Block::load(
                &mut weights,
                &format!("language_model.model.layers.{i}"),
                &cfg,
                i,
            )?);
        }
        let norm = weights.rms_norm("language_model.model.norm", cfg.rms_norm_eps)?;
        let lm_head = if cfg.tie_word_embeddings {
            None
        } else {
            Some(weights.linear("language_model.lm_head")?)
        };

        let vision = Self::load_vision(&mut weights, config_json)?;

        Ok(Qwen35Model {
            config: cfg,
            embed_tokens,
            layers,
            norm,
            lm_head,
            vision,
        })
    }

    /// Build the vision tower iff `config.json` carries a `vision_config`
    /// sub-dict AND the checkpoint actually shipped the matching
    /// `vision_tower.*` weights (a checkpoint could declare `vision_config`
    /// while being distributed text-only); returns `None` otherwise so
    /// text-only checkpoints load exactly as before.
    fn load_vision(weights: &mut WeightMap, config_json: &Value) -> Result<Option<VisionSupport>> {
        let Some(vision_cfg_json) = config_json.get("vision_config") else {
            return Ok(None);
        };
        if !vision::has_vision_weights(weights) {
            return Ok(None);
        }

        let vision_cfg = Qwen35VisionConfig::from_json(vision_cfg_json);
        let tower = Qwen35VisionTower::load(weights, vision_cfg)?;

        Ok(Some(VisionSupport {
            tower,
            image_token_id: get_i32(config_json, "image_token_id", 151655),
            vision_start_token_id: get_i32(config_json, "vision_start_token_id", 151652),
            vision_end_token_id: get_i32(config_json, "vision_end_token_id", 151653),
            video_token_id: get_i32(config_json, "video_token_id", 151656),
        }))
    }

    /// Whether this checkpoint's vision tower was loaded (i.e. it can
    /// accept image input via [`Qwen35Model::forward_with_media`]).
    pub fn supports_images(&self) -> bool {
        self.vision.is_some()
    }

    /// `(patch_size, max_soft_tokens, spatial_merge_size)` for
    /// [`crate::media::image::preprocess_image_bytes`], or `None` if this
    /// checkpoint has no vision support.
    pub fn image_processing_params(&self) -> Option<(i32, i32, i32)> {
        self.vision.as_ref().map(|v| {
            let cfg = v.tower.config();
            (cfg.patch_size, 1280, cfg.spatial_merge_size)
        })
    }

    /// `(image_token_id, vision_start_token_id, vision_end_token_id)`, or
    /// `None` if this checkpoint has no vision support. Reuses the
    /// `(image_token_id, boi_token_id, eoi_token_id)` shape every
    /// multimodal architecture in this crate exposes: Qwen3.5's
    /// `vision_start`/`vision_end` tokens play the same "wrap the expanded
    /// placeholder span" role as Gemma4's `boi`/`eoi`.
    pub fn image_token_ids(&self) -> Option<(u32, u32, u32)> {
        self.vision.as_ref().map(|v| {
            (
                v.image_token_id as u32,
                v.vision_start_token_id as u32,
                v.vision_end_token_id as u32,
            )
        })
    }

    /// `video_token_id` from `config.json`, or `None` when the checkpoint
    /// has no vision tower (video reuses the vision path per frame).
    pub fn video_token_id(&self) -> Option<u32> {
        self.vision.as_ref().map(|v| v.video_token_id as u32)
    }

    pub fn new_caches(&self) -> Vec<LayerCache> {
        self.layers
            .iter()
            .map(|l| {
                if l.is_linear() {
                    LayerCache::GatedDelta(GatedDeltaCache::new())
                } else {
                    LayerCache::new_attention()
                }
            })
            .collect()
    }

    pub fn num_layers(&self) -> usize {
        self.layers.len()
    }

    pub fn forward(&self, input_ids: &Array, caches: &mut [LayerCache]) -> Result<Array> {
        let h = self.embed_tokens.forward(input_ids)?;
        self.forward_from_embeds(input_ids, h, caches)
    }

    /// Same as [`Qwen35Model::forward`], but splices `images`' projected
    /// vision-tower features into the text embedding stream at
    /// `image_token_id` placeholder positions before running the decoder
    /// stack (order preserving across multiple images; each image's
    /// soft-token count must exactly match the number of `image_token_id`
    /// placeholders `input_ids` holds for it, produced by expanding the
    /// chat template's single-placeholder-per-image convention beforehand -
    /// see `crate::generate::Session::encode_chat_with_media`).
    pub fn forward_with_images(
        &self,
        input_ids: &Array,
        images: &[ProcessedImage],
        caches: &mut [LayerCache],
    ) -> Result<Array> {
        self.forward_with_media(input_ids, images, caches)
    }

    /// Same as [`Qwen35Model::forward_with_images`]; Qwen3.5-VL has no
    /// audio tower, so this simply ignores audio (kept as a distinct name
    /// to mirror the generic [`crate::models::Model::forward_with_media`]
    /// dispatch signature other multimodal architectures use).
    pub fn forward_with_media(
        &self,
        input_ids: &Array,
        images: &[ProcessedImage],
        caches: &mut [LayerCache],
    ) -> Result<Array> {
        let mut h = self.embed_tokens.forward(input_ids)?;

        if !images.is_empty() {
            let vision = self.vision.as_ref().ok_or_else(|| {
                Error::Model("qwen3.5: model has no vision support (no vision_config)".into())
            })?;
            let mut all_features = Vec::with_capacity(images.len());
            for image in images {
                let features =
                    vision
                        .tower
                        .forward(&image.pixel_values, image.patch_h, image.patch_w)?;
                all_features.push(features);
            }
            h = splice_media_features(&h, input_ids, all_features, vision.image_token_id, "image")?;
        }

        self.forward_from_embeds(input_ids, h, caches)
    }

    fn forward_from_embeds(
        &self,
        input_ids: &Array,
        mut h: Array,
        caches: &mut [LayerCache],
    ) -> Result<Array> {
        let seq_len = input_ids.dim(1);
        let mask = attention_mask_for(seq_len);

        for (layer, cache) in self.layers.iter().zip(caches.iter_mut()) {
            h = layer.forward(&h, mask, cache)?;
        }
        h = self.norm.forward(&h)?;

        match &self.lm_head {
            Some(head) => head.forward(&h),
            None => self.embed_tokens.as_linear(&h),
        }
    }
}

/// Normalize checkpoint weight keys. Qwen3.5/3.6 checkpoints (dense or MoE,
/// with or without a vision tower) always ship the language model under a
/// `language_model.*` prefix and, when present, the vision tower under a
/// bare `vision_tower.*` prefix (an `optiq_vision.safetensors` sidecar on
/// OptiQ checkpoints); keep both, drop everything else (MTP
/// speculative-decoding heads), and fold fused MoE expert weights into the
/// `switch_mlp.*` layout `SparseMoeBlock` expects.
pub fn sanitize(weights: &mut WeightMap, num_hidden_layers: i32, num_experts: i32) {
    weights.rename_keys(|k| {
        if k.starts_with("vision_tower.") {
            Some(k.to_string())
        } else if k.starts_with("language_model.") && !k.contains("mtp.") {
            Some(k.to_string())
        } else {
            None
        }
    });

    if num_experts <= 0 {
        return;
    }

    for l in 0..num_hidden_layers {
        let prefix = format!("language_model.model.layers.{l}.mlp");
        // Fused gate_up_proj (stacked experts): [E, 2*I, H] -> split in half.
        if let Some(gate_up) = weights.take_optional(&format!("{prefix}.experts.gate_up_proj")) {
            let mid = gate_up.dim(-2) / 2;
            let shape = gate_up.shape();
            if let Ok(gate) = ops::slice(&gate_up, &[0, 0, 0], &[shape[0], mid, shape[2]]) {
                weights.insert(format!("{prefix}.switch_mlp.gate_proj.weight"), gate);
            }
            if let Ok(up) = ops::slice(&gate_up, &[0, mid, 0], &[shape[0], shape[1], shape[2]]) {
                weights.insert(format!("{prefix}.switch_mlp.up_proj.weight"), up);
            }
        }
        if let Some(down) = weights.take_optional(&format!("{prefix}.experts.down_proj")) {
            weights.insert(format!("{prefix}.switch_mlp.down_proj.weight"), down);
        }
        // Per-expert separate weights: stack into [E, out, in].
        for name in ["gate_proj", "up_proj", "down_proj"] {
            if weights.contains(&format!("{prefix}.experts.0.{name}.weight")) {
                let mut expert_weights = Vec::new();
                let mut e = 0;
                while let Some(w) =
                    weights.take_optional(&format!("{prefix}.experts.{e}.{name}.weight"))
                {
                    expert_weights.push(w);
                    e += 1;
                }
                let refs: Vec<&Array> = expert_weights.iter().collect();
                if let Ok(stacked) = ops::stack_axis(&refs, 0) {
                    weights.insert(format!("{prefix}.switch_mlp.{name}.weight"), stacked);
                }
            }
        }
    }
}

pub fn parse_quantization(config_json: &Value) -> Result<Quantization> {
    Quantization::from_config(config_json)
}

pub fn model_error(model_type: &str) -> Error {
    Error::Model(format!("unsupported qwen3.5 variant '{model_type}'"))
}