STRA-338 size: engine produce_rows, retry settle trimmed
This commit is contained in:
@@ -115,8 +115,6 @@ mod generate_fn;
|
||||
pub(in super::super) use generate_fn::generate;
|
||||
#[path = "runner/run_parts.rs"]
|
||||
mod run_parts;
|
||||
#[cfg(target_os = "linux")]
|
||||
use run_parts::drop_model_page_cache;
|
||||
#[allow(unused_imports)]
|
||||
use run_parts::{
|
||||
GenerateEnv, abandon_stack, close_context, close_stack, open_run_stack, publish_open, serve_generate, sweep_idle,
|
||||
|
||||
@@ -144,10 +144,8 @@ pub(super) fn open_with_retry<'ctx>(
|
||||
if !retry.auto || attempt - failed >= 6 {
|
||||
return Ok(Some(keep(cache, retry)));
|
||||
}
|
||||
match squeeze(context, retry, &mut plan, cache, &mut zero_reads)? {
|
||||
Settled::Keep(cache) => return Ok(Some(keep(cache, retry))),
|
||||
Settled::Retry => {}
|
||||
Settled::Nothing => return Ok(None),
|
||||
if let Some(done) = squeeze(context, retry, &mut plan, cache, &mut zero_reads)?.finish(retry) {
|
||||
return Ok(done);
|
||||
}
|
||||
}
|
||||
unreachable!()
|
||||
@@ -175,6 +173,17 @@ fn shrink_after_refusal(retry: &Retry, plan: &mut Plan, failed: usize) -> Result
|
||||
Ok(retry.auto && failed < 8 && plan.shrink_to(plan.bytes()? / 4 * 3)?)
|
||||
}
|
||||
|
||||
impl<'ctx> Settled<'ctx> {
|
||||
/// `Some(result)` ends the retry; `None` goes round again with the shrunk plan.
|
||||
fn finish(self, retry: &Retry) -> Option<Option<OriginalExpertCache<'ctx>>> {
|
||||
match self {
|
||||
Settled::Keep(cache) => Some(Some(keep(cache, retry))),
|
||||
Settled::Retry => None,
|
||||
Settled::Nothing => Some(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn keep<'ctx>(mut cache: OriginalExpertCache<'ctx>, retry: &Retry) -> OriginalExpertCache<'ctx> {
|
||||
cache.set_per_layer_admission(retry.per_layer);
|
||||
cache
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
use crate::qwen_forward::chunk_modules::ChunkModules;
|
||||
|
||||
/// The rows of one projection: everything but the source and the values.
|
||||
struct RowFactory<'b, 'ctx> {
|
||||
@@ -201,12 +202,24 @@ pub(super) fn project_impl<'source, 'ctx>(
|
||||
let origin = chunk.original_session()?.target_origin()?;
|
||||
check_inputs(binding, chunk, layer, inputs)?;
|
||||
let (matrix, provider) = project_matrix(cache, binding, layer, role)?;
|
||||
let (columns, tokens) = (host_columns(inputs)?, inputs.len());
|
||||
let columns = host_columns(inputs)?;
|
||||
let factory = RowFactory { binding, origin, context, layer, role, provider };
|
||||
let modules = cache.chunk_modules(binding, context)?;
|
||||
produce_rows(&factory, (matrix, &columns, modules), inputs, retain)
|
||||
}
|
||||
|
||||
/// Run the Q6_K projection of the host columns and wrap its output in rows: left on the device, or copied to the host.
|
||||
fn produce_rows<'source, 'ctx>(
|
||||
factory: &RowFactory<'_, 'ctx>,
|
||||
work: (&DeviceBuffer<'_>, &[f32], &ChunkModules<'ctx>),
|
||||
inputs: &[&'source ResidualReady],
|
||||
retain: bool,
|
||||
) -> Result<Vec<ProjectionRow<'source, 'ctx>>> {
|
||||
let (matrix, columns, modules) = work;
|
||||
let (context, rows, tokens) = (factory.context, factory.role.rows(), inputs.len());
|
||||
if retain {
|
||||
let output = numeric_retained(context, matrix, &columns, role.rows(), tokens, modules)?;
|
||||
return retained_rows(&factory, inputs, (modules.failure_flag().clone(), output));
|
||||
let output = numeric_retained(context, matrix, columns, rows, tokens, modules)?;
|
||||
return retained_rows(factory, inputs, (modules.failure_flag().clone(), output));
|
||||
}
|
||||
host_rows(&factory, inputs, &numeric(context, matrix, &columns, role.rows(), tokens, modules)?)
|
||||
host_rows(factory, inputs, &numeric(context, matrix, columns, rows, tokens, modules)?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user