Skip to content
Merged
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
14 changes: 10 additions & 4 deletions src/gpu_model/prefill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,21 @@ impl GpuModel<'_> {
pub(super) fn prefill_image_rows(&mut self, embs: &[Vec<f32>], pos: &[[i32; 4]], ids: &[u32]) -> anyhow::Result<usize> {
let c = &self.m.cfg;
let Some(chunk) = self.pf.as_ref().map(|p| p.chunk) else { return Ok(0) };
if c.mrope_sections.is_none() || self.qsa.is_some() || self.ple_ring.is_some() { return Ok(0); }
if c.mrope_sections.is_none() { return Ok(0); }
let n = embs.len().min(chunk).min(pos.len().saturating_sub(1));
if n < 2 { return Ok(0); }
let segs = crate::backend::mrope_segments(&pos[..n]);
let first = segs.iter().flat_map(|&(a, ..)| pos[a].map(|p| [p, 0]).concat()).collect();
anyhow::ensure!(self.pos + n <= self.ctx, "context full ({} tokens; raise --ctx)", self.ctx);
self.kv_need(self.cur, self.pos + n)?;
let emb: Vec<f32> = embs[..n].iter().flat_map(|x| x.repeat(c.hc_n.max(1))).collect();
let pe: Vec<f32> = if self.ple_ring.is_some() {
ids[..n].iter().flat_map(|&tk| self.m.ple_embed(&mut self.ple_prev, tk)).collect()
} else {
vec![]
};
self.pf_mrope = Some((segs, first));
let r = self.prefill_chunk(&ids[..n], Some((&emb, &[])), None);
let r = self.prefill_chunk(&ids[..n], Some((&emb, &pe)), None);
self.pf_mrope = None;
r?;
crate::term::prefilled(n);
Expand Down Expand Up @@ -501,7 +506,8 @@ impl GpuModel<'_> {
let (hd, nh, nkv) = (c.head_dim, c.n_head, c.n_head_kv);
let kv = nkv * hd;
// The draft head runs as one more layer on the chunk while it is in step with the main model.
let fill = self.mtp_synced();
// Skip during M-RoPE image chunks (matching `step_embed`, which does not feed placeholder tokens to MTP).
let fill = self.mtp_synced() && self.pf_mrope.is_none();
let is_eagle = self.mtp.as_ref().is_some_and(|mh| mh.eagle.is_some());
// STRATA_MTP_FILL_STEP=1: fill a hyper-connection head after the chunk, TMAX rows a time (the old way; to compare).
let hc_step = c.hc_n > 0 && std::env::var("STRATA_MTP_FILL_STEP").is_ok_and(|v| v == "1");
Expand Down Expand Up @@ -764,7 +770,7 @@ impl GpuModel<'_> {
// Rows with at most `top` complete blocks attend densely: no mask while all of them do.
if self.pos + t >= super::QSA_POOL * (b.top + 1) {
g.rms_norm(iq, dq, a.qn.ptr, iqn, dq, dq, t * super::QSA_H, eps)?;
g.rope_neox(iqn, dq, t * super::QSA_H, super::QSA_H, c.n_rot, rope, c.rope_base)?;
self.rope_chunk(iqn, dq, t, super::QSA_H, rope)?;
for r0 in (0..t).step_by(super::QSA_ROWS) {
g.qsa_select(iqn + (4 * r0 * nq) as u64, a.pool[self.cur].addr(), b.score.addr(), 0, b.mask.addr() + (4 * r0 * b.mw) as u64,
step, r0, super::QSA_ROWS.min(t - r0), b.nbs, b.top, 0, b.mw)?;
Expand Down