Skip to content

Make sliding_window for Qwen2 optional #546

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 3 commits into from
Apr 2, 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
12 changes: 10 additions & 2 deletions backends/candle/src/models/flash_qwen2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct Qwen2Attention {
impl Qwen2Attention {
pub fn load(vb: VarBuilder, config: &Qwen2Config) -> Result<Self> {
if config.use_sliding_window {
candle::bail!("Sliding window is not supported");
candle::bail!("Sliding window is not supported for Qwen2",);
}

let num_attention_heads = config.num_attention_heads;
Expand Down Expand Up @@ -264,7 +264,15 @@ impl FlashQwen2Model {
ModelType::Embedding(pool) => pool,
};

let vb = vb.pp("model");
// Pushing the prefix for `model` is apparently only required if the model architecture is
// ForCausalLM as it contains the `lm_head`, other than that, the `model` key won't be
// present e.g. a model without the `model` key as it's a `Qwen2Model` instance not a
// `Qwen2ModelForCausalLM` is https://huggingface.co/mims-harvard/ToolRAG-T1-GTE-Qwen2-1.5B
let vb = if vb.contains_tensor("model.embed_tokens.weight") {
vb.pp("model")
} else {
vb
};

let embeddings = Embedding::new(
vb.pp("embed_tokens")
Expand Down
2 changes: 1 addition & 1 deletion backends/candle/src/models/qwen2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ pub struct Qwen2Config {
pub max_position_embeddings: usize,
pub rms_norm_eps: f32,
pub rope_theta: f32,
pub sliding_window: usize,
pub sliding_window: Option<usize>,
pub use_sliding_window: bool,
}
Loading