Skip to content

Add Qwen3Model #627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions backends/candle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use crate::compute_cap::{
use crate::models::{
BertConfig, BertModel, DistilBertConfig, DistilBertModel, GTEConfig, GTEModel, JinaBertModel,
JinaCodeBertModel, MPNetConfig, MPNetModel, MistralConfig, Model, ModernBertConfig,
ModernBertModel, NomicBertModel, NomicConfig, Qwen2Config,
ModernBertModel, NomicBertModel, NomicConfig, Qwen2Config, Qwen3Config,
};
#[cfg(feature = "cuda")]
use crate::models::{
FlashBertModel, FlashDistilBertModel, FlashGTEModel, FlashJinaBertModel,
FlashJinaCodeBertModel, FlashMistralModel, FlashModernBertModel, FlashNomicBertModel,
FlashQwen2Model,
FlashQwen2Model, FlashQwen3Model,
};
use anyhow::Context;
use candle::{DType, Device};
Expand Down Expand Up @@ -103,6 +103,8 @@ enum Config {
Gte(GTEConfig),
#[allow(dead_code)]
Qwen2(Qwen2Config),
#[allow(dead_code)]
Qwen3(Qwen3Config),
#[serde(rename = "mpnet")]
MPNet(MPNetConfig),
#[serde(rename(deserialize = "modernbert"))]
Expand Down Expand Up @@ -273,6 +275,10 @@ impl CandleBackend {
"Qwen2 is only supported on Cuda devices in fp16 with flash attention enabled"
.to_string(),
)),
(Config::Qwen3(_), Device::Cpu | Device::Metal(_)) => Err(BackendError::Start(
"Qwen3 is only supported on Cuda devices in fp16 with flash attention enabled"
.to_string(),
)),
(Config::MPNet(config), _) => {
tracing::info!("Starting MPNet model on {:?}", device);
Ok(Box::new(MPNetModel::load(vb, &config, model_type).s()?))
Expand Down Expand Up @@ -446,6 +452,18 @@ impl CandleBackend {
FlashQwen2Model::load(vb, &config, model_type).s()?,
))
}
#[cfg(feature = "cuda")]
(Config::Qwen3(config), Device::Cuda(_)) => {
if dtype != DType::F16
|| !cfg!(any(feature = "flash-attn", feature = "flash-attn-v1"))
{
return Err(BackendError::Start("Qwen3 is only supported on Cuda devices in fp16 with flash attention v2 enabled".to_string()));
}
tracing::info!("Starting FlashQwen3 model on {:?}", device);
Ok(Box::new(
FlashQwen3Model::load(vb, &config, model_type).s()?,
))
}
};

Ok(Self {
Expand Down
Loading
Loading