Skip to content

Commit 50f42a5

Browse files
authored
Support new format AWQ/GPTQ MoE models (#452)
1 parent 36fe5d9 commit 50f42a5

12 files changed

Lines changed: 485 additions & 7 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ anyhow = "1.0.75"
2121
rand = "0.9.0"
2222
rayon="1.10.0"
2323
hyper = { version = "0.14", features = ["full"] }
24-
candle-core = { git = "https://github.com/guoqingbao/candle.git", version = "0.8.3", rev = "cafd231" }
25-
candle-nn = { git = "https://github.com/guoqingbao/candle.git", version = "0.8.3", rev = "cafd231" }
24+
candle-core = { git = "https://github.com/guoqingbao/candle.git", version = "0.8.3", rev = "df058d8" }
25+
candle-nn = { git = "https://github.com/guoqingbao/candle.git", version = "0.8.3", rev = "df058d8" }
2626
dyn-fmt = "0.4.0"
2727
safetensors = "0.8"
2828
serde = { version = "1.0.190", features = ["serde_derive"] }
@@ -45,7 +45,7 @@ dirs = "5.0.1"
4545
minijinja = { version = "2.10.2", features = ["builtins", "json"] }
4646
minijinja-contrib = { version = "2.10.2", features = ["pycompat"] }
4747
thiserror = "1.0.58"
48-
attention-rs = { git = "https://github.com/guoqingbao/attention.rs.git", version="0.6.5", rev = "a97f519" }
48+
attention-rs = { git = "https://github.com/guoqingbao/attention.rs.git", version="0.6.6", rev = "b35d437" }
4949
metal = { version = "0.27.0", features = ["mps"], optional = true }
5050
lazy_static = {version = "1.4.0"}
5151
interprocess = "2.2.2"

src/openai/models/gemma4.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::openai::distributed::{
77
embedding, Comm, ReplicatedLinear, VarBuilder, VocabParallelLinear,
88
};
99
use crate::openai::models::layers::moe::{
10-
FusedMoe, FusedMoeFp8, FusedMoeISQ, FusedMoeMxfp4, FusedMoeNvfp4,
10+
FusedMoe, FusedMoeFp8, FusedMoeISQ, FusedMoeMxfp4, FusedMoeNvfp4, FusedMoeWNA16,
1111
};
1212
use crate::openai::models::layers::others::{rms_norm, NormX};
1313
use crate::openai::models::mask::get_attention_causal_mask;
@@ -201,6 +201,7 @@ enum Gemma4MoE {
201201
FusedMoeFp8(FusedMoeFp8),
202202
FusedMoeMxfp4(FusedMoeMxfp4),
203203
FusedMoeNvfp4(FusedMoeNvfp4),
204+
FusedMoeWNA16(FusedMoeWNA16),
204205
}
205206

206207
impl Gemma4MoE {
@@ -211,6 +212,7 @@ impl Gemma4MoE {
211212
Self::FusedMoeFp8(m) => m.forward(xs, is_prefill),
212213
Self::FusedMoeMxfp4(m) => m.forward(xs, is_prefill),
213214
Self::FusedMoeNvfp4(m) => m.forward(xs, is_prefill),
215+
Self::FusedMoeWNA16(m) => m.forward(xs, is_prefill),
214216
}
215217
}
216218

@@ -231,6 +233,9 @@ impl Gemma4MoE {
231233
Self::FusedMoeNvfp4(m) => {
232234
m.forward_with_routing(xs, topk_weights, topk_ids, is_prefill)
233235
}
236+
Self::FusedMoeWNA16(m) => {
237+
m.forward_with_routing(xs, topk_weights, topk_ids, is_prefill)
238+
}
234239
}
235240
}
236241
}
@@ -333,6 +338,16 @@ impl Gemma4DecoderLayer {
333338
comm.clone(),
334339
dtype,
335340
)?)
341+
} else if quant_cfg.is_compressed_tensors {
342+
Gemma4MoE::FusedMoeWNA16(FusedMoeWNA16::new_with_gate(
343+
cfg,
344+
vb.pp("router").pp("proj"),
345+
vb.pp("experts"),
346+
&vb,
347+
comm.clone(),
348+
dtype,
349+
quant_cfg,
350+
)?)
336351
} else {
337352
candle::bail!(
338353
"Unsupported quantization for Gemma4 MoE: {}",

src/openai/models/layers/deltanet.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ impl GatedDeltaNet {
7272
vb.contains_tensor("weight_scale_2") || vb.contains_tensor("input_scale");
7373
has_mlx || (has_packed && has_scale) || (has_modelopt && has_scale)
7474
}
75+
"compressed-tensors" => {
76+
vb.contains_tensor("weight_packed") && vb.contains_tensor("weight_scale")
77+
}
7578
_ => true,
7679
}
7780
}

src/openai/models/layers/mla_attention.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ impl MlaAttention {
546546
block_tables,
547547
context_lens,
548548
self.sm_scale,
549+
input_metadata
550+
.max_context_len
551+
.max(input_metadata.max_seqlen_k)
552+
.max(1),
549553
)?;
550554
return self.project_mla_output(&attn_out, seq_len, xs.dtype());
551555
}

0 commit comments

Comments
 (0)