STRA-338 size-fn: experimental-ref: second pass over the new helpers and plan_open, dispatch, resolve
This commit is contained in:
@@ -225,6 +225,19 @@ fn append_int8_pair(
|
||||
append_q8_half(&mut pools.v_q, &mut pools.v_scale, hv, table, pos, v, s)
|
||||
}
|
||||
|
||||
/// Q4_0 K and V of one cell, each into its own pool (and the host mirror's, when streaming).
|
||||
fn append_q4_pair(
|
||||
pools: &mut PoolSet,
|
||||
mut host: Option<&mut PoolSet>,
|
||||
table: &[i32],
|
||||
pos: i64,
|
||||
(k, v): (&[f32], &[f32]),
|
||||
(s, c): (&QsaShapes, Contraction),
|
||||
) -> Result<(), CacheError> {
|
||||
append_q4_half(&mut pools.k_q4, host.as_deref_mut().map(|h| &mut h.k_q4[..]), table, pos, k, s, c)?;
|
||||
append_q4_half(&mut pools.v_q4, host.as_deref_mut().map(|h| &mut h.v_q4[..]), table, pos, v, s, c)
|
||||
}
|
||||
|
||||
/// The whole cell append of `layer.cpp` for `format`: rotation is the caller's (`fwht256` of K and/or V as
|
||||
/// [`KvFormat::rotates_k`] / [`KvFormat::rotates_v`] say); this writes the already-rotated `k` and `v`.
|
||||
/// K8V4 is the composed call (INT8 K, Q4_0 V); a value-only cache ignores `k`.
|
||||
@@ -242,10 +255,7 @@ pub fn append_cell(
|
||||
) -> Result<(), CacheError> {
|
||||
check_geometry(format, s)?;
|
||||
match format {
|
||||
KvFormat::Q4_0 => {
|
||||
append_q4_half(&mut pools.k_q4, host.as_deref_mut().map(|h| &mut h.k_q4[..]), table, pos, k, s, c)?;
|
||||
append_q4_half(&mut pools.v_q4, host.as_deref_mut().map(|h| &mut h.v_q4[..]), table, pos, v, s, c)
|
||||
}
|
||||
KvFormat::Q4_0 => append_q4_pair(pools, host, table, pos, (k, v), (s, c)),
|
||||
KvFormat::Int8 | KvFormat::Int8Rotated => append_int8_pair(pools, host, table, pos, (k, v), s),
|
||||
KvFormat::Int8Keyless => {
|
||||
let hv = host.as_deref_mut().map(|h| (&mut h.v_q[..], &mut h.v_scale[..]));
|
||||
|
||||
@@ -80,6 +80,15 @@ fn read_array(c: &mut Cursor<'_>, depth: u32) -> Result<Meta, CvecError> {
|
||||
Ok(Meta::Other)
|
||||
}
|
||||
|
||||
/// Bytes of the metadata value types that are skipped (float32 and float64).
|
||||
fn skipped_width(t: u32) -> Option<usize> {
|
||||
match t {
|
||||
6 => Some(4),
|
||||
12 => Some(8),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn read_value(c: &mut Cursor<'_>, t: u32, depth: u32) -> Result<Meta, CvecError> {
|
||||
if depth > 2 {
|
||||
return Err(CvecError::Gguf("GGUF: array nesting too deep".into()));
|
||||
@@ -87,19 +96,15 @@ pub(super) fn read_value(c: &mut Cursor<'_>, t: u32, depth: u32) -> Result<Meta,
|
||||
if let Some(value) = read_uint(c, t)? {
|
||||
return Ok(value);
|
||||
}
|
||||
Ok(match t {
|
||||
6 => {
|
||||
c.take(4)?;
|
||||
Meta::Other
|
||||
}
|
||||
8 => Meta::Str(c.string()?),
|
||||
12 => {
|
||||
c.take(8)?;
|
||||
Meta::Other
|
||||
}
|
||||
9 => read_array(c, depth)?,
|
||||
_ => return Err(CvecError::Gguf("GGUF: unknown metadata value type".into())),
|
||||
})
|
||||
if let Some(width) = skipped_width(t) {
|
||||
c.take(width)?;
|
||||
return Ok(Meta::Other);
|
||||
}
|
||||
match t {
|
||||
8 => Ok(Meta::Str(c.string()?)),
|
||||
9 => read_array(c, depth),
|
||||
_ => Err(CvecError::Gguf("GGUF: unknown metadata value type".into())),
|
||||
}
|
||||
}
|
||||
|
||||
/// The magic, version and counts of a GGUF v3 header: (tensor count, key/value count).
|
||||
@@ -116,9 +121,30 @@ fn read_header(c: &mut Cursor<'_>) -> Result<(u64, u64), CvecError> {
|
||||
Ok((n_tensors, n_kv))
|
||||
}
|
||||
|
||||
/// The metadata the loader uses: architecture, model hint and alignment.
|
||||
struct Wanted {
|
||||
architecture: Option<String>,
|
||||
model_hint: Option<String>,
|
||||
alignment: u64,
|
||||
}
|
||||
|
||||
impl Wanted {
|
||||
/// Note one key/value pair if it is one of the wanted keys.
|
||||
fn note(&mut self, key: &str, v: Meta) {
|
||||
match (key, v) {
|
||||
("general.architecture", Meta::Str(s)) => self.architecture = Some(s),
|
||||
("general.architecture", _) => self.architecture = Some(String::new()),
|
||||
("controlvector.model_hint", Meta::Str(s)) => self.model_hint = Some(s),
|
||||
("controlvector.model_hint", _) => self.model_hint = Some(String::new()),
|
||||
("general.alignment", Meta::Uint(a)) if a != 0 => self.alignment = a,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The metadata the loader uses: architecture, model hint and alignment (the first of a repeated key wins).
|
||||
fn read_metadata(c: &mut Cursor<'_>, n_kv: u64) -> Result<(Option<String>, Option<String>, u64), CvecError> {
|
||||
let (mut architecture, mut model_hint, mut alignment) = (None, None, 32u64);
|
||||
let mut wanted = Wanted { architecture: None, model_hint: None, alignment: 32 };
|
||||
let mut seen_keys = std::collections::BTreeSet::new();
|
||||
for _ in 0..n_kv {
|
||||
let key = c.string()?;
|
||||
@@ -127,21 +153,27 @@ fn read_metadata(c: &mut Cursor<'_>, n_kv: u64) -> Result<(Option<String>, Optio
|
||||
if !seen_keys.insert(key.clone()) {
|
||||
continue; // emplace keeps the first
|
||||
}
|
||||
match (key.as_str(), v) {
|
||||
("general.architecture", Meta::Str(s)) => architecture = Some(s),
|
||||
("general.architecture", _) => architecture = Some(String::new()),
|
||||
("controlvector.model_hint", Meta::Str(s)) => model_hint = Some(s),
|
||||
("controlvector.model_hint", _) => model_hint = Some(String::new()),
|
||||
("general.alignment", Meta::Uint(a)) if a != 0 => alignment = a,
|
||||
_ => {}
|
||||
}
|
||||
wanted.note(&key, v);
|
||||
}
|
||||
Ok((architecture, model_hint, alignment))
|
||||
Ok((wanted.architecture, wanted.model_hint, wanted.alignment))
|
||||
}
|
||||
|
||||
/// A tensor info as stored: name, shape, ggml type and offset into the data section.
|
||||
type TensorInfo = (String, Vec<u64>, u32, u64);
|
||||
|
||||
/// The dimension count and sizes of a tensor.
|
||||
fn read_shape(c: &mut Cursor<'_>, name: &str) -> Result<Vec<u64>, CvecError> {
|
||||
let nd = c.u32()?;
|
||||
if nd == 0 || nd > 4 {
|
||||
return Err(CvecError::Gguf(format!("GGUF: bad n_dims for {name}")));
|
||||
}
|
||||
let mut shape = Vec::new();
|
||||
for _ in 0..nd {
|
||||
shape.push(c.u64()?);
|
||||
}
|
||||
Ok(shape)
|
||||
}
|
||||
|
||||
fn read_tensor_infos(c: &mut Cursor<'_>, n_tensors: u64) -> Result<Vec<TensorInfo>, CvecError> {
|
||||
let mut names = std::collections::BTreeSet::new();
|
||||
let mut infos = Vec::new();
|
||||
@@ -150,14 +182,7 @@ fn read_tensor_infos(c: &mut Cursor<'_>, n_tensors: u64) -> Result<Vec<TensorInf
|
||||
if !names.insert(name.clone()) {
|
||||
return Err(CvecError::Gguf(format!("GGUF: duplicate tensor name '{name}'")));
|
||||
}
|
||||
let nd = c.u32()?;
|
||||
if nd == 0 || nd > 4 {
|
||||
return Err(CvecError::Gguf(format!("GGUF: bad n_dims for {name}")));
|
||||
}
|
||||
let mut shape = Vec::new();
|
||||
for _ in 0..nd {
|
||||
shape.push(c.u64()?);
|
||||
}
|
||||
let shape = read_shape(c, &name)?;
|
||||
let ggml_type = c.u32()?;
|
||||
let offset = c.u64()?;
|
||||
infos.push((name, shape, ggml_type, offset));
|
||||
|
||||
@@ -75,6 +75,50 @@ fn steer_row(mode: CvecMode, d: &[f32], dir_row: &mut [f32], scale: &mut f32) ->
|
||||
true
|
||||
}
|
||||
|
||||
/// The first and last steered layer and the single source layer (-1: each layer is its own source).
|
||||
fn layer_range(o: &CvecOptions, n_layers: i64) -> (i64, i64, i64) {
|
||||
let first = if o.first <= 0 { 1 } else { o.first };
|
||||
let last = if o.last <= 0 || o.last >= n_layers { n_layers - 1 } else { o.last };
|
||||
let single = if o.mode == CvecMode::Project { o.single } else { -1 };
|
||||
(first, last, single)
|
||||
}
|
||||
|
||||
/// The direction and scale tables of the layers `first..=last` and how many layers they steer.
|
||||
fn steer_layers(
|
||||
(data, have): (&[f32], &[bool]),
|
||||
(first, last, single): (i64, i64, i64),
|
||||
(mode, n_layers, n): (CvecMode, i64, usize),
|
||||
) -> (Vec<f32>, Vec<f32>, usize) {
|
||||
let l_n = n_layers as usize;
|
||||
let mut dir = vec![0.0f32; l_n * n];
|
||||
let mut s = vec![0.0f32; l_n];
|
||||
let mut steered = 0;
|
||||
for l in first..=last {
|
||||
let src = if single >= 0 { single } else { l };
|
||||
if src < 0 || src >= n_layers || !have[src as usize] {
|
||||
continue;
|
||||
}
|
||||
let d = &data[src as usize * n..(src as usize + 1) * n];
|
||||
let row = l as usize * n..(l as usize + 1) * n;
|
||||
if !steer_row(mode, d, &mut dir[row], &mut s[l as usize]) {
|
||||
continue;
|
||||
}
|
||||
steered += 1;
|
||||
}
|
||||
(dir, s, steered)
|
||||
}
|
||||
|
||||
/// The one-line description of the loaded vector, e.g. `project:1-23:single7`.
|
||||
fn summary_of(mode: CvecMode, (first, last, single): (i64, i64, i64)) -> String {
|
||||
format!(
|
||||
"{}:{}-{}{}",
|
||||
if mode == CvecMode::Project { "project" } else { "add" },
|
||||
first,
|
||||
last,
|
||||
if single >= 0 { format!(":single{single}") } else { String::new() }
|
||||
)
|
||||
}
|
||||
|
||||
/// `load_control_vectors`: every file's `direction.<l>` times its scale, summed (f32 multiply then add), then the
|
||||
/// project/add tables. `files` are `(label, bytes, scale)`. A `direction.<l>` with `l < 1` or `l >= n_layers` is
|
||||
/// ignored (layer 0 has no vector; past the model is ignored, as in llama.cpp).
|
||||
@@ -91,38 +135,17 @@ pub fn load_control_vectors(
|
||||
for file in files {
|
||||
add_file((&mut data, &mut have), file, (n_layers, n_embd))?;
|
||||
}
|
||||
let first = if o.first <= 0 { 1 } else { o.first };
|
||||
let last = if o.last <= 0 || o.last >= n_layers { n_layers - 1 } else { o.last };
|
||||
let single = if o.mode == CvecMode::Project { o.single } else { -1 };
|
||||
let range = layer_range(o, n_layers);
|
||||
let (first, last, single) = range;
|
||||
if single >= 0 && (single >= n_layers || !have[single as usize]) {
|
||||
return Err(CvecError::NoSingleDirection(single));
|
||||
}
|
||||
let mut dir = vec![0.0f32; l_n * n];
|
||||
let mut s = vec![0.0f32; l_n];
|
||||
let mut steered = 0;
|
||||
for l in first..=last {
|
||||
let src = if single >= 0 { single } else { l };
|
||||
if src < 0 || src >= n_layers || !have[src as usize] {
|
||||
continue;
|
||||
}
|
||||
let d = &data[src as usize * n..(src as usize + 1) * n];
|
||||
let row = l as usize * n..(l as usize + 1) * n;
|
||||
if !steer_row(o.mode, d, &mut dir[row], &mut s[l as usize]) {
|
||||
continue;
|
||||
}
|
||||
steered += 1;
|
||||
}
|
||||
let (dir, s, steered) = steer_layers((&data, &have), range, (o.mode, n_layers, n));
|
||||
if steered == 0 {
|
||||
return Err(CvecError::NothingSteered { first, last });
|
||||
}
|
||||
check_tables(&dir, &s, n_embd)?;
|
||||
let summary = format!(
|
||||
"{}:{}-{}{}",
|
||||
if o.mode == CvecMode::Project { "project" } else { "add" },
|
||||
first,
|
||||
last,
|
||||
if single >= 0 { format!(":single{single}") } else { String::new() }
|
||||
);
|
||||
let summary = summary_of(o.mode, range);
|
||||
let steered_flags = s.iter().map(|v| *v != 0.0).collect();
|
||||
Ok(CvecTables { dir, s, mode: o.mode, first, last, n_embd, hc, steered: steered_flags, summary })
|
||||
}
|
||||
@@ -160,6 +183,11 @@ pub fn warp_xor_sum(mut lanes: [f32; 32]) -> f32 {
|
||||
lanes[0]
|
||||
}
|
||||
|
||||
/// A register after steering: projected off the direction (by `dot`) or shifted by it.
|
||||
fn steered_value(xv: f32, v: f32, (project, dot): (bool, f32)) -> f32 {
|
||||
if project { (-dot).mul_add(v, xv) } else { xv + v }
|
||||
}
|
||||
|
||||
/// Store the stream back: the registers, steered by `(project, dot)` when steering is on.
|
||||
#[allow(clippy::needless_range_loop)] // thread/k indices mirror the CUDA text
|
||||
fn write_back(stream: &mut [f32], x: &[[f32; MAXK]], v: &[f32], steering: Option<(bool, f32)>) {
|
||||
@@ -168,11 +196,8 @@ fn write_back(stream: &mut [f32], x: &[[f32; MAXK]], v: &[f32], steering: Option
|
||||
for k in 0..MAXK {
|
||||
let d = tid + k * THREADS;
|
||||
if d < n {
|
||||
let mut xv = x[tid][k];
|
||||
if let Some((project, dot)) = steering {
|
||||
xv = if project { (-dot).mul_add(v[d], xv) } else { xv + v[d] };
|
||||
}
|
||||
stream[d] = xv;
|
||||
let xv = x[tid][k];
|
||||
stream[d] = steering.map_or(xv, |st| steered_value(xv, v[d], st));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,22 +221,26 @@ impl Reader<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the header fields name this model: version, layer count, heads and head dimension.
|
||||
fn header_matches(g: &KeylessGeometry, (version, layers, heads, dim): (u32, u32, u32, u32)) -> bool {
|
||||
version == VERSION
|
||||
&& layers as usize == g.qsa_layers.len()
|
||||
&& heads == g.n_head
|
||||
&& dim == g.head_dim
|
||||
&& dim as usize == DIM
|
||||
}
|
||||
|
||||
/// The magic and header of an artifact checked against the model: (layer count, head count).
|
||||
fn read_artifact_header(r: &mut Reader<'_>, g: &KeylessGeometry) -> Result<(u32, u32), KeylessError> {
|
||||
let magic = r.take(8)?;
|
||||
if magic != MAGIC {
|
||||
return Err(KeylessError::Header);
|
||||
}
|
||||
let (version, layers, heads, dim) = (r.u32()?, r.u32()?, r.u32()?, r.u32()?);
|
||||
if version != VERSION
|
||||
|| layers as usize != g.qsa_layers.len()
|
||||
|| heads != g.n_head
|
||||
|| dim != g.head_dim
|
||||
|| dim as usize != DIM
|
||||
{
|
||||
let fields = (r.u32()?, r.u32()?, r.u32()?, r.u32()?);
|
||||
if !header_matches(g, fields) {
|
||||
return Err(KeylessError::Header);
|
||||
}
|
||||
Ok((layers, heads))
|
||||
Ok((fields.1, fields.2))
|
||||
}
|
||||
|
||||
/// The elements the source projection of `role` must have.
|
||||
@@ -291,6 +295,15 @@ fn read_matrices(r: &mut Reader<'_>, layer: u32, heads: u32) -> Result<Vec<f32>,
|
||||
Ok(matrices)
|
||||
}
|
||||
|
||||
/// The next layer id, which must be a layer with quantized-score attention that was not seen before.
|
||||
fn admit_layer(r: &mut Reader<'_>, g: &KeylessGeometry, seen: &mut BTreeSet<u32>) -> Result<u32, KeylessError> {
|
||||
let layer = r.u32()?;
|
||||
if layer >= g.n_layers || !g.qsa_layers.contains(&layer) || !seen.insert(layer) {
|
||||
return Err(KeylessError::InvalidLayer(layer));
|
||||
}
|
||||
Ok(layer)
|
||||
}
|
||||
|
||||
/// `keyless_load` minus the CUDA allocations: parse and fully admit a `SKLROUT1` artifact against the model's
|
||||
/// geometry and its source projections. Every check happens before any matrix would reach a device.
|
||||
pub fn parse_artifact<'a>(
|
||||
@@ -303,10 +316,7 @@ pub fn parse_artifact<'a>(
|
||||
let mut seen = BTreeSet::new();
|
||||
let mut out = Vec::new();
|
||||
for _ in 0..layers {
|
||||
let layer = r.u32()?;
|
||||
if layer >= g.n_layers || !g.qsa_layers.contains(&layer) || !seen.insert(layer) {
|
||||
return Err(KeylessError::InvalidLayer(layer));
|
||||
}
|
||||
let layer = admit_layer(&mut r, g, &mut seen)?;
|
||||
for role in ["q", "k", "v"] {
|
||||
check_role(&mut r, g, source, (layer, role))?;
|
||||
}
|
||||
|
||||
@@ -66,6 +66,13 @@ impl StreamMap {
|
||||
let (hand, got) = self.sweep_victims(need, epoch);
|
||||
let placed = got.min(need);
|
||||
self.place_misses(need, placed, epoch);
|
||||
self.record_call(epoch, hand, (placed, need), lookups);
|
||||
Ok(ResolveReport { epoch, hand: hand as i32, misses: need, placed, lookups })
|
||||
}
|
||||
|
||||
/// Store the call's epoch, hand and placement count (the overflow flag when not every miss found a slot)
|
||||
/// and add to the lookup, miss and call counters.
|
||||
fn record_call(&mut self, epoch: i32, hand: usize, (placed, need): (usize, usize), lookups: usize) {
|
||||
self.ctl[0] = epoch;
|
||||
self.ctl[1] = hand as i32;
|
||||
self.ctl[2] = placed as i32;
|
||||
@@ -75,7 +82,6 @@ impl StreamMap {
|
||||
self.add_u64(4, placed as u64);
|
||||
self.add_u64(6, lookups as u64);
|
||||
self.add_u64(8, 1);
|
||||
Ok(ResolveReport { epoch, hand: hand as i32, misses: need, placed, lookups })
|
||||
}
|
||||
|
||||
/// 1. hits take this epoch and their reference bit; a missing block is claimed exactly once (-1 -> -2).
|
||||
|
||||
@@ -143,17 +143,39 @@ pub fn plan_open(
|
||||
claimed: &mut [u8],
|
||||
sizes: &ExpertSizes,
|
||||
) -> Result<RemotePlan, RemoteError> {
|
||||
let sane_device = device >= 1 && device < device_count;
|
||||
if !sane_device || slots <= 0 || ranked.is_empty() || layers <= 0 || experts <= 0 {
|
||||
return Err(RemoteError::BadArguments);
|
||||
}
|
||||
if claimed.len() != layers as usize * experts as usize {
|
||||
if !valid_open_arguments((device, device_count), (slots, layers, experts), ranked.len(), claimed.len()) {
|
||||
return Err(RemoteError::BadArguments);
|
||||
}
|
||||
let selected = pick_unclaimed(ranked, (slots, layers, experts), primary_has, claimed);
|
||||
if selected.is_empty() {
|
||||
return Err(RemoteError::NoUnclaimedExperts);
|
||||
}
|
||||
let (slot_sizes, needed) = slot_budget(&selected, sizes, free_bytes)?;
|
||||
let mut layers_present = vec![0u8; layers as usize];
|
||||
for &(l, e) in &selected {
|
||||
layers_present[l as usize] = 1;
|
||||
claimed[l as usize * experts as usize + e as usize] = 1;
|
||||
}
|
||||
Ok(RemotePlan { device, n_expert: experts, selected, slot_sizes, layers_present, needed_bytes: needed })
|
||||
}
|
||||
|
||||
/// Whether the arguments of `plan_open` describe a helper device and a claim table of the right size.
|
||||
fn valid_open_arguments(
|
||||
(device, device_count): (i32, i32),
|
||||
(slots, layers, experts): (i32, i64, i64),
|
||||
ranked: usize,
|
||||
claimed: usize,
|
||||
) -> bool {
|
||||
let sane_device = device >= 1 && device < device_count;
|
||||
if !sane_device || slots <= 0 || ranked == 0 || layers <= 0 || experts <= 0 {
|
||||
return false;
|
||||
}
|
||||
claimed == layers as usize * experts as usize
|
||||
}
|
||||
|
||||
/// The blob size of every selected expert's slot (native packs only) and the bytes the slots need, which must
|
||||
/// leave the reserve free.
|
||||
fn slot_budget(selected: &[(i32, i32)], sizes: &ExpertSizes, free_bytes: u64) -> Result<(Vec<u64>, u64), RemoteError> {
|
||||
let slot_sizes: Vec<u64> =
|
||||
if sizes.native { selected.iter().map(|&(l, _)| sizes.blob(l as usize)).collect() } else { Vec::new() };
|
||||
let needed: u64 = selected.iter().map(|&(l, _)| sizes.slot_cost(l as usize)).sum();
|
||||
@@ -161,12 +183,7 @@ pub fn plan_open(
|
||||
if needed + RESERVE_BYTES > free_bytes {
|
||||
return Err(RemoteError::SlotsLeaveLessThanReserve { needed, free: free_bytes });
|
||||
}
|
||||
let mut layers_present = vec![0u8; layers as usize];
|
||||
for &(l, e) in &selected {
|
||||
layers_present[l as usize] = 1;
|
||||
claimed[l as usize * experts as usize + e as usize] = 1;
|
||||
}
|
||||
Ok(RemotePlan { device, n_expert: experts, selected, slot_sizes, layers_present, needed_bytes: needed })
|
||||
Ok((slot_sizes, needed))
|
||||
}
|
||||
|
||||
fn align16(n: u64) -> u64 {
|
||||
@@ -247,6 +264,33 @@ impl Dispatch {
|
||||
}
|
||||
}
|
||||
|
||||
/// The number of routed entries (`n_tok * k`) of a legal dispatch for `layer`.
|
||||
fn dispatch_entries(plan: &RemotePlan, layer: i64, (n_tok, k): (i64, i64)) -> Result<usize, RemoteError> {
|
||||
let n = n_tok * k;
|
||||
if n <= 0 || n > CAP as i64 || n_tok > MAXT as i64 || k != ROUTES as i64 || layer < 0 {
|
||||
return Err(RemoteError::InvalidDispatch);
|
||||
}
|
||||
if layer as usize >= plan.layers_present.len() {
|
||||
return Err(RemoteError::InvalidDispatch);
|
||||
}
|
||||
Ok(n as usize)
|
||||
}
|
||||
|
||||
impl Dispatch {
|
||||
/// A dispatch of `n` entries, none owned.
|
||||
fn empty(n: usize) -> Self {
|
||||
Self {
|
||||
owned: vec![0; n],
|
||||
groups: Vec::new(),
|
||||
start: Vec::new(),
|
||||
dst: Vec::new(),
|
||||
tok: Vec::new(),
|
||||
original_row: Vec::new(),
|
||||
computed: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `RemoteExperts::begin` minus staging and launches. `ids` is `[n_tok][k]`, `kind` the primary verifier's
|
||||
/// classification (-1 = CPU candidate, null on the one-token path), `primary_res` the primary's
|
||||
/// `layer x expert -> slot` table.
|
||||
@@ -259,23 +303,8 @@ pub fn dispatch(
|
||||
kind: Option<&[i32]>,
|
||||
primary_res: Option<&[i32]>,
|
||||
) -> Result<Dispatch, RemoteError> {
|
||||
let n = n_tok * k;
|
||||
if n <= 0 || n > CAP as i64 || n_tok > MAXT as i64 || k != ROUTES as i64 || layer < 0 {
|
||||
return Err(RemoteError::InvalidDispatch);
|
||||
}
|
||||
if layer as usize >= plan.layers_present.len() {
|
||||
return Err(RemoteError::InvalidDispatch);
|
||||
}
|
||||
let n = n as usize;
|
||||
let mut d = Dispatch {
|
||||
owned: vec![0; n],
|
||||
groups: Vec::new(),
|
||||
start: Vec::new(),
|
||||
dst: Vec::new(),
|
||||
tok: Vec::new(),
|
||||
original_row: Vec::new(),
|
||||
computed: 0,
|
||||
};
|
||||
let n = dispatch_entries(plan, layer, (n_tok, k))?;
|
||||
let mut d = Dispatch::empty(n);
|
||||
if plan.layers_present[layer as usize] == 0 {
|
||||
return Ok(d);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user