hf2q 0.1.30

Pure Rust CLI for converting HuggingFace models to hardware-optimized formats and serving them over an OpenAI-compatible API on Apple Silicon
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
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
//! Validated DFlash2 checkpoint descriptors (ADR-067 D0).

use serde::Deserialize;
use std::path::Path;

pub const MAX_DFLASH2_BLOCK_ROWS: usize = 16;
pub const DFLASH2_CONVOLUTION_STAGES: usize = 2;
pub const DFLASH2_SELECTOR_RANK: usize = 256;
pub const DFLASH2_SELECTOR_TOP_K: usize = 16;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DFlash2LayerType {
    FullAttention,
    SlidingAttention,
}

#[derive(Debug, Clone, Deserialize)]
struct RawDFlash2SpecificConfig {
    block_size: usize,
    conv_group_size: usize,
    conv_kernel_size: usize,
    mask_token_id: i64,
    selector_rank: usize,
    selector_top_k: usize,
    target_layer_ids: Vec<usize>,
    #[serde(default)]
    final_logit_softcapping: Option<f32>,
    #[serde(default)]
    output_multiplier: Option<f32>,
}

#[derive(Debug, Clone, Deserialize)]
struct RawRopeParameters {
    rope_theta: f64,
    rope_type: String,
}

#[derive(Debug, Clone, Deserialize)]
struct RawDFlash2Config {
    architectures: Vec<String>,
    attention_bias: bool,
    is_causal: bool,
    dtype: String,
    dflash_config: RawDFlash2SpecificConfig,
    head_dim: usize,
    hidden_act: String,
    hidden_size: usize,
    intermediate_size: usize,
    layer_types: Vec<DFlash2LayerType>,
    max_position_embeddings: usize,
    max_window_layers: usize,
    model_type: String,
    num_attention_heads: usize,
    num_hidden_layers: usize,
    num_key_value_heads: usize,
    num_target_layers: usize,
    rms_norm_eps: f32,
    rope_parameters: RawRopeParameters,
    sliding_window: usize,
    tie_word_embeddings: bool,
    use_sliding_window: bool,
    vocab_size: usize,
}

#[derive(Debug, Clone, Deserialize)]
struct RawSpeculatorsVerifier {
    architectures: Vec<String>,
    name_or_path: String,
}

#[derive(Debug, Clone, Deserialize)]
struct RawSpeculatorsConfig {
    algorithm: String,
    verifier: RawSpeculatorsVerifier,
}

#[derive(Debug, Clone, Deserialize)]
struct RawNestedTransformerConfig {
    attention_bias: bool,
    #[serde(default)]
    dtype: Option<String>,
    head_dim: usize,
    hidden_act: String,
    hidden_size: usize,
    intermediate_size: usize,
    layer_types: Vec<DFlash2LayerType>,
    max_position_embeddings: usize,
    #[serde(rename = "max_window_layers")]
    _target_max_window_layers: usize,
    model_type: String,
    num_attention_heads: usize,
    num_hidden_layers: usize,
    num_key_value_heads: usize,
    rms_norm_eps: f32,
    rope_parameters: RawRopeParameters,
    sliding_window: usize,
    tie_word_embeddings: bool,
    use_sliding_window: bool,
    vocab_size: usize,
}

#[derive(Debug, Clone, Deserialize)]
struct RawNestedDFlash2Config {
    architectures: Vec<String>,
    aux_hidden_state_layer_ids: Vec<usize>,
    block_size: usize,
    conv_group_size: usize,
    conv_kernel_size: usize,
    draft_vocab_size: usize,
    dtype: String,
    mask_token_id: i64,
    sample_from_anchor: bool,
    selector_rank: usize,
    selector_top_k: usize,
    sliding_window_non_causal: bool,
    speculators_config: RawSpeculatorsConfig,
    speculators_model_type: String,
    tie_word_embeddings: bool,
    transformer_layer_config: RawNestedTransformerConfig,
}

impl RawNestedDFlash2Config {
    fn normalize(self) -> Result<RawDFlash2Config, DFlash2ConfigError> {
        let target_layers = match self.speculators_config.verifier.name_or_path.as_str() {
            "google/gemma-4-E2B-it" => 35,
            "google/gemma-4-31B-it" => 60,
            target => {
                return Err(DFlash2ConfigError::Invalid(format!(
                    "nested speculators schema has unsupported target identity {target}"
                )));
            }
        };
        if self.speculators_config.algorithm != "dflash2"
            || self.speculators_model_type != "dflash2"
            || self.speculators_config.verifier.architectures.as_slice()
                != ["Gemma4ForConditionalGeneration"]
            || self.sample_from_anchor
            || !self.sliding_window_non_causal
            || self.draft_vocab_size != self.transformer_layer_config.vocab_size
            || self
                .transformer_layer_config
                .dtype
                .as_deref()
                .is_some_and(|dtype| dtype != self.dtype.as_str())
            || self.tie_word_embeddings
            || self.transformer_layer_config.tie_word_embeddings
        {
            return Err(DFlash2ConfigError::Invalid(
                "nested speculators DFlash2 envelope is incompatible".into(),
            ));
        }
        let transformer = self.transformer_layer_config;
        Ok(RawDFlash2Config {
            architectures: self.architectures,
            attention_bias: transformer.attention_bias,
            is_causal: false,
            dtype: self.dtype,
            dflash_config: RawDFlash2SpecificConfig {
                block_size: self.block_size,
                conv_group_size: self.conv_group_size,
                conv_kernel_size: self.conv_kernel_size,
                mask_token_id: self.mask_token_id,
                selector_rank: self.selector_rank,
                selector_top_k: self.selector_top_k,
                target_layer_ids: self.aux_hidden_state_layer_ids,
                final_logit_softcapping: None,
                output_multiplier: None,
            },
            head_dim: transformer.head_dim,
            hidden_act: transformer.hidden_act,
            hidden_size: transformer.hidden_size,
            intermediate_size: transformer.intermediate_size,
            layer_types: transformer.layer_types,
            max_position_embeddings: transformer.max_position_embeddings,
            max_window_layers: transformer.num_hidden_layers,
            model_type: transformer.model_type,
            num_attention_heads: transformer.num_attention_heads,
            num_hidden_layers: transformer.num_hidden_layers,
            num_key_value_heads: transformer.num_key_value_heads,
            num_target_layers: target_layers,
            rms_norm_eps: transformer.rms_norm_eps,
            rope_parameters: transformer.rope_parameters,
            sliding_window: transformer.sliding_window,
            tie_word_embeddings: false,
            use_sliding_window: transformer.use_sliding_window,
            vocab_size: transformer.vocab_size,
        })
    }
}

/// Runtime descriptor shared by every family adapter.
#[derive(Debug, Clone, PartialEq)]
pub struct DFlash2Config {
    pub draft_model_type: String,
    pub hidden_size: usize,
    pub intermediate_size: usize,
    pub num_hidden_layers: usize,
    pub num_attention_heads: usize,
    pub num_key_value_heads: usize,
    pub head_dim: usize,
    pub vocab_size: usize,
    pub num_target_layers: usize,
    pub target_layer_ids: Vec<usize>,
    pub layer_types: Vec<DFlash2LayerType>,
    pub max_position_embeddings: usize,
    pub sliding_window: usize,
    pub rms_norm_eps: f32,
    pub rope_theta: f64,
    pub block_size: usize,
    pub conv_group_size: usize,
    pub conv_kernel_size: usize,
    pub selector_rank: usize,
    pub selector_top_k: usize,
    pub mask_token_id: u32,
    pub final_logit_softcapping: Option<f32>,
    pub output_multiplier: Option<f32>,
}

/// Target metadata supplied by a family adapter. Checkpoint identity is bound
/// separately because the Hugging Face config does not name the target revision.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DFlash2TargetShape<'a> {
    pub architecture: &'a str,
    pub hidden_size: usize,
    pub vocab_size: usize,
    pub num_hidden_layers: usize,
}

#[derive(Debug, thiserror::Error)]
pub enum DFlash2ConfigError {
    #[error("DFlash2 config IO error: {0}")]
    Io(#[from] std::io::Error),
    #[error("DFlash2 config JSON error: {0}")]
    Json(#[from] serde_json::Error),
    #[error("DFlash2 config validation: {0}")]
    Invalid(String),
    #[error("DFlash2 target {architecture} is incompatible: {reason}")]
    Target {
        architecture: String,
        reason: String,
    },
}

impl DFlash2Config {
    pub fn from_json_path(path: impl AsRef<Path>) -> Result<Self, DFlash2ConfigError> {
        Self::from_json_str(&std::fs::read_to_string(path)?)
    }

    pub fn from_json_str(json: &str) -> Result<Self, DFlash2ConfigError> {
        let value: serde_json::Value = serde_json::from_str(json)?;
        let raw = if value.get("transformer_layer_config").is_some() {
            serde_json::from_value::<RawNestedDFlash2Config>(value)?.normalize()?
        } else {
            serde_json::from_value::<RawDFlash2Config>(value)?
        };
        let specific = &raw.dflash_config;
        let invalid = |message: String| DFlash2ConfigError::Invalid(message);

        if raw.architectures.as_slice() != ["DFlash2DraftModel"] {
            return Err(invalid(format!(
                "architectures must be [\"DFlash2DraftModel\"], got {:?}",
                raw.architectures
            )));
        }
        if raw.dtype != "bfloat16" {
            return Err(invalid(format!(
                "dtype must be bfloat16, got {}",
                raw.dtype
            )));
        }
        if raw.attention_bias || raw.is_causal || raw.tie_word_embeddings {
            return Err(invalid(
                "attention_bias, is_causal and tie_word_embeddings must be false".into(),
            ));
        }
        if raw.hidden_act != "silu" {
            return Err(invalid(format!(
                "hidden_act must be silu, got {}",
                raw.hidden_act
            )));
        }
        for (name, value) in [
            ("hidden_size", raw.hidden_size),
            ("intermediate_size", raw.intermediate_size),
            ("num_hidden_layers", raw.num_hidden_layers),
            ("num_attention_heads", raw.num_attention_heads),
            ("num_key_value_heads", raw.num_key_value_heads),
            ("head_dim", raw.head_dim),
            ("vocab_size", raw.vocab_size),
            ("num_target_layers", raw.num_target_layers),
            ("max_position_embeddings", raw.max_position_embeddings),
            ("sliding_window", raw.sliding_window),
        ] {
            if value == 0 {
                return Err(invalid(format!("{name} must be nonzero")));
            }
        }
        if raw.num_attention_heads % raw.num_key_value_heads != 0 {
            return Err(invalid(format!(
                "num_attention_heads {} must be divisible by num_key_value_heads {}",
                raw.num_attention_heads, raw.num_key_value_heads
            )));
        }
        if raw.layer_types.len() != raw.num_hidden_layers {
            return Err(invalid(format!(
                "layer_types length {} != num_hidden_layers {}",
                raw.layer_types.len(),
                raw.num_hidden_layers
            )));
        }
        if raw.max_window_layers > raw.num_hidden_layers {
            return Err(invalid(format!(
                "max_window_layers {} exceeds num_hidden_layers {}",
                raw.max_window_layers, raw.num_hidden_layers
            )));
        }
        if !raw.use_sliding_window
            || !raw
                .layer_types
                .iter()
                .any(|layer| *layer == DFlash2LayerType::SlidingAttention)
        {
            return Err(invalid(
                "DFlash2 requires use_sliding_window and at least one sliding_attention layer"
                    .into(),
            ));
        }
        if raw.rms_norm_eps <= 0.0 || !raw.rms_norm_eps.is_finite() {
            return Err(invalid("rms_norm_eps must be finite and positive".into()));
        }
        if raw.rope_parameters.rope_type != "default"
            || raw.rope_parameters.rope_theta <= 0.0
            || !raw.rope_parameters.rope_theta.is_finite()
        {
            return Err(invalid(
                "rope_parameters must have rope_type=default and finite positive rope_theta".into(),
            ));
        }
        if !(2..=MAX_DFLASH2_BLOCK_ROWS).contains(&specific.block_size) {
            return Err(invalid(format!(
                "block_size must be in 2..={MAX_DFLASH2_BLOCK_ROWS}, got {}",
                specific.block_size
            )));
        }
        if specific.conv_group_size == 0 || raw.hidden_size % specific.conv_group_size != 0 {
            return Err(invalid(format!(
                "conv_group_size {} must divide hidden_size {}",
                specific.conv_group_size, raw.hidden_size
            )));
        }
        if specific.conv_kernel_size != 2 {
            return Err(invalid(format!(
                "conv_kernel_size must be 2, got {}",
                specific.conv_kernel_size
            )));
        }
        if specific.selector_rank != DFLASH2_SELECTOR_RANK
            || specific.selector_top_k != DFLASH2_SELECTOR_TOP_K
        {
            return Err(invalid(format!(
                "selector must be rank {DFLASH2_SELECTOR_RANK}, top-k {DFLASH2_SELECTOR_TOP_K}; got rank {}, top-k {}",
                specific.selector_rank, specific.selector_top_k
            )));
        }
        if specific.target_layer_ids.is_empty() {
            return Err(invalid("target_layer_ids must be non-empty".into()));
        }
        for pair in specific.target_layer_ids.windows(2) {
            if pair[0] >= pair[1] {
                return Err(invalid(format!(
                    "target_layer_ids must be strictly increasing, got {:?}",
                    specific.target_layer_ids
                )));
            }
        }
        if let Some(layer) = specific.target_layer_ids.last() {
            if *layer >= raw.num_target_layers {
                return Err(invalid(format!(
                    "target layer {layer} is outside num_target_layers {}",
                    raw.num_target_layers
                )));
            }
        }
        if specific.mask_token_id < 0 || specific.mask_token_id as usize >= raw.vocab_size {
            return Err(invalid(format!(
                "mask_token_id {} is outside vocabulary {}",
                specific.mask_token_id, raw.vocab_size
            )));
        }
        for (name, value) in [
            ("final_logit_softcapping", specific.final_logit_softcapping),
            ("output_multiplier", specific.output_multiplier),
        ] {
            if let Some(value) = value {
                if value <= 0.0 || !value.is_finite() {
                    return Err(invalid(format!("{name} must be finite and positive")));
                }
            }
        }

        raw.hidden_size
            .checked_mul(specific.target_layer_ids.len())
            .ok_or_else(|| invalid("fc input dimension overflows usize".into()))?;
        raw.num_attention_heads
            .checked_mul(raw.head_dim)
            .ok_or_else(|| invalid("query projection dimension overflows usize".into()))?;
        raw.num_key_value_heads
            .checked_mul(raw.head_dim)
            .ok_or_else(|| invalid("KV projection dimension overflows usize".into()))?;

        Ok(Self {
            draft_model_type: raw.model_type,
            hidden_size: raw.hidden_size,
            intermediate_size: raw.intermediate_size,
            num_hidden_layers: raw.num_hidden_layers,
            num_attention_heads: raw.num_attention_heads,
            num_key_value_heads: raw.num_key_value_heads,
            head_dim: raw.head_dim,
            vocab_size: raw.vocab_size,
            num_target_layers: raw.num_target_layers,
            target_layer_ids: specific.target_layer_ids.clone(),
            layer_types: raw.layer_types,
            max_position_embeddings: raw.max_position_embeddings,
            sliding_window: raw.sliding_window,
            rms_norm_eps: raw.rms_norm_eps,
            rope_theta: raw.rope_parameters.rope_theta,
            block_size: specific.block_size,
            conv_group_size: specific.conv_group_size,
            conv_kernel_size: specific.conv_kernel_size,
            selector_rank: specific.selector_rank,
            selector_top_k: specific.selector_top_k,
            mask_token_id: specific.mask_token_id as u32,
            final_logit_softcapping: specific.final_logit_softcapping,
            output_multiplier: specific.output_multiplier,
        })
    }

    pub fn proposal_tokens(&self) -> usize {
        self.block_size - 1
    }

    pub fn fc_input_dim(&self) -> usize {
        self.hidden_size * self.target_layer_ids.len()
    }

    pub fn convolution_groups(&self) -> usize {
        self.hidden_size / self.conv_group_size
    }

    pub fn dynamic_projection_width(&self) -> usize {
        DFLASH2_CONVOLUTION_STAGES * self.conv_kernel_size * self.convolution_groups()
    }

    pub fn validate_target(
        &self,
        target: DFlash2TargetShape<'_>,
    ) -> Result<(), DFlash2ConfigError> {
        let mismatch = if target.hidden_size != self.hidden_size {
            Some(format!(
                "hidden_size {} != draft {}",
                target.hidden_size, self.hidden_size
            ))
        } else if target.vocab_size != self.vocab_size {
            Some(format!(
                "vocab_size {} != draft {}",
                target.vocab_size, self.vocab_size
            ))
        } else if target.num_hidden_layers != self.num_target_layers {
            Some(format!(
                "num_hidden_layers {} != draft num_target_layers {}",
                target.num_hidden_layers, self.num_target_layers
            ))
        } else {
            None
        };
        if let Some(reason) = mismatch {
            return Err(DFlash2ConfigError::Target {
                architecture: target.architecture.into(),
                reason,
            });
        }
        Ok(())
    }
}

#[cfg(test)]
pub(crate) mod tests {
    use super::*;

    pub const QWEN38_CONFIG: &str = r#"{
      "architectures":["DFlash2DraftModel"], "attention_bias":false,
      "is_causal":false, "dtype":"bfloat16", "head_dim":128,
      "hidden_act":"silu", "hidden_size":5120, "intermediate_size":17408,
      "layer_types":["sliding_attention","sliding_attention","sliding_attention","sliding_attention","sliding_attention"],
      "max_position_embeddings":262144, "max_window_layers":5,
      "model_type":"qwen3", "num_attention_heads":32, "num_hidden_layers":5,
      "num_key_value_heads":8, "num_target_layers":64, "rms_norm_eps":0.000001,
      "rope_parameters":{"rope_theta":10000000.0,"rope_type":"default"},
      "sliding_window":2048, "tie_word_embeddings":false,
      "use_sliding_window":true, "vocab_size":248320,
      "dflash_config":{"block_size":8,"conv_group_size":16,"conv_kernel_size":2,
        "mask_token_id":248070,"selector_rank":256,"selector_top_k":16,
        "target_layer_ids":[5,19,33,47,61]}
    }"#;

    const GEMMA4_E2B_CONFIG: &str = r#"{
      "architectures":["DFlash2DraftModel"],
      "aux_hidden_state_layer_ids":[3,13,23,33],
      "block_size":8,"conv_group_size":16,"conv_kernel_size":2,
      "draft_vocab_size":262144,"dtype":"bfloat16","mask_token_id":4,
      "sample_from_anchor":false,"selector_rank":256,"selector_top_k":16,
      "sliding_window_non_causal":true,"speculators_model_type":"dflash2",
      "tie_word_embeddings":false,
      "speculators_config":{"algorithm":"dflash2","verifier":{
        "architectures":["Gemma4ForConditionalGeneration"],
        "name_or_path":"google/gemma-4-E2B-it"}},
      "transformer_layer_config":{"attention_bias":false,
        "head_dim":128,"hidden_act":"silu","hidden_size":1536,
        "intermediate_size":6144,
        "layer_types":["sliding_attention","sliding_attention","sliding_attention",
          "sliding_attention","full_attention"],
        "max_position_embeddings":131072,"max_window_layers":28,
        "model_type":"qwen3","num_attention_heads":12,"num_hidden_layers":5,
        "num_key_value_heads":4,"rms_norm_eps":0.000001,
        "rope_parameters":{"rope_theta":10000.0,"rope_type":"default"},
        "sliding_window":2048,"tie_word_embeddings":false,
        "use_sliding_window":true,"vocab_size":262144}
    }"#;

    #[test]
    fn parses_pinned_qwen38_contract() {
        let cfg = DFlash2Config::from_json_str(QWEN38_CONFIG).unwrap();
        assert_eq!(cfg.proposal_tokens(), 7);
        assert_eq!(cfg.fc_input_dim(), 25_600);
        assert_eq!(cfg.convolution_groups(), 320);
        assert_eq!(cfg.dynamic_projection_width(), 1_280);
        assert_eq!(cfg.target_layer_ids, [5, 19, 33, 47, 61]);
        cfg.validate_target(DFlash2TargetShape {
            architecture: "qwen35",
            hidden_size: 5_120,
            vocab_size: 248_320,
            num_hidden_layers: 64,
        })
        .unwrap();
    }

    #[test]
    fn parses_nested_gemma4_speculators_contract() {
        let cfg = DFlash2Config::from_json_str(GEMMA4_E2B_CONFIG).unwrap();
        assert_eq!(cfg.hidden_size, 1_536);
        assert_eq!(cfg.num_target_layers, 35);
        assert_eq!(cfg.target_layer_ids, [3, 13, 23, 33]);
        assert_eq!(cfg.fc_input_dim(), 6_144);
        assert_eq!(cfg.dynamic_projection_width(), 384);
        assert_eq!(
            cfg.layer_types.last(),
            Some(&DFlash2LayerType::FullAttention)
        );
        cfg.validate_target(DFlash2TargetShape {
            architecture: "gemma4",
            hidden_size: 1_536,
            vocab_size: 262_144,
            num_hidden_layers: 35,
        })
        .unwrap();
    }

    #[test]
    fn rejects_cross_family_shape_instead_of_approximating() {
        let cfg = DFlash2Config::from_json_str(QWEN38_CONFIG).unwrap();
        let error = cfg
            .validate_target(DFlash2TargetShape {
                architecture: "gemma4",
                hidden_size: 5_120,
                vocab_size: 262_144,
                num_hidden_layers: 64,
            })
            .unwrap_err();
        assert!(error
            .to_string()
            .contains("vocab_size 262144 != draft 248320"));
    }

    #[test]
    fn rejects_invalid_dynamic_convolution_shape() {
        let json = QWEN38_CONFIG.replace("\"conv_group_size\":16", "\"conv_group_size\":17");
        let error = DFlash2Config::from_json_str(&json).unwrap_err();
        assert!(error.to_string().contains("must divide hidden_size"));
    }
}