Skip to content
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
5 changes: 4 additions & 1 deletion crates/dluth-model/src/inkling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ pub mod model;
pub mod prompt;

pub use config::{load_config, model_kind, validate_weights, Checked, ExpertFormat, InklingConfig, ModelKind};
pub use model::{CpuProducts, ExpertLayer, ExpertMatrices, InklingCpu, Products};
pub use model::{
CpuBlend, CpuOps, CpuProducts, ExpertLayer, ExpertMatrices, Gate, Inkling, InklingCpu, KvConv, Layer, Ops,
PassState, Products,
};
506 changes: 347 additions & 159 deletions crates/dluth-model/src/inkling/model.rs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions tools/mutants/40-inkling-shared-history.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# weights-env: DLUTH_INKLING2_MINI
# Bug: every pass of a looped layer shares one attention history.
diff --git a/crates/dluth-model/src/inkling/model.rs b/crates/dluth-model/src/inkling/model.rs
index 8693fee..a6be3d7 100644
index 306a8fc..dcaaf9f 100644
--- a/crates/dluth-model/src/inkling/model.rs
+++ b/crates/dluth-model/src/inkling/model.rs
@@ -569,7 +569,8 @@ impl<'w> InklingCpu<'w> {
@@ -798,7 +798,8 @@ impl<'w, O: Ops> Inkling<'w, O> {
_ => None,
};
let p = self.products.as_mut();
let at = Arrival { pos, messages: messages.as_deref() };
- x = apply_layer(cfg, p, layer, &mut self.states[index], &x, &mut blocks, at)?;
- x = apply_layer(cfg, ops, layer, &mut self.passes[index], &x, &mut blocks, at)?;
+ let shared = self.steps.iter().position(|s| s.layer == step.layer).unwrap_or(index);
+ x = apply_layer(cfg, p, layer, &mut self.states[shared], &x, &mut blocks, at)?;
+ x = apply_layer(cfg, ops, layer, &mut self.passes[shared], &x, &mut blocks, at)?;
}

self.last = x;
self.last = Some((x, blocks));
18 changes: 9 additions & 9 deletions tools/mutants/41-inkling-value-message.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# weights-env: DLUTH_INKLING2_MINI
# Bug: the message for the value input is dropped.
diff --git a/crates/dluth-model/src/inkling/model.rs b/crates/dluth-model/src/inkling/model.rs
index 8693fee..c856a7f 100644
index 306a8fc..1ab29ae 100644
--- a/crates/dluth-model/src/inkling/model.rs
+++ b/crates/dluth-model/src/inkling/model.rs
@@ -878,7 +878,7 @@ fn apply_layer(
}
};
// 2. From the second pass on, merge in the previous pass's messages, then normalize.
- for (input, port) in inputs.iter_mut().zip([Port::Query, Port::Key, Port::Value]) {
+ for (input, port) in inputs.iter_mut().zip([Port::Query, Port::Key]) {
*input = merged(p, port, std::mem::take(input))?;
@@ -1083,7 +1083,7 @@ fn apply_layer<O: Ops>(
for ((input, port), weights) in
[q, k, v].into_iter().zip([Port::Query, Port::Key, Port::Value]).zip(&layer.input_norms)
{
- let input = merged(ops, port, input)?;
+ let input = if matches!(port, Port::Value) { input } else { merged(ops, port, input)? };
normed.push(ops.rmsnorm(&input, weights, cfg.eps)?);
}
let mut normed = [vec![0.0f32; h], vec![0.0f32; h], vec![0.0f32; h]];

8 changes: 4 additions & 4 deletions tools/mutants/42-inkling-pass-restart.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# weights-env: DLUTH_INKLING2_MINI
# Bug: a later pass continues from the previous pass instead of starting again from the loop entry.
diff --git a/crates/dluth-model/src/inkling/model.rs b/crates/dluth-model/src/inkling/model.rs
index 899fc4b..b70fa48 100644
index 306a8fc..1570241 100644
--- a/crates/dluth-model/src/inkling/model.rs
+++ b/crates/dluth-model/src/inkling/model.rs
@@ -464,7 +464,6 @@ impl<'w> InklingCpu<'w> {
blocks[start_blocks.len() + 1..].iter().map(Vec::as_slice).collect();
@@ -780,7 +780,6 @@ impl<'w, O: Ops> Inkling<'w, O> {
let mut source: Vec<&O::V> = blocks[start_blocks.len() + 1..].iter().collect();
source.push(&x);
message_source = Some(depthmix::normalize(&source, BLEND_EPS));
message_source = Some(ops.normalize(&source)?);
- x = start_x.clone();
blocks = start_blocks.clone();
}
Expand Down
20 changes: 10 additions & 10 deletions tools/mutants/43-inkling-no-window.patch
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# test: cargo test -p dluth-model --test tiny_inkling_golden
# Bug: local layers see the whole sequence.
diff --git a/crates/dluth-model/src/inkling/model.rs b/crates/dluth-model/src/inkling/model.rs
index 899fc4b..4caa761 100644
index 306a8fc..c4c9d7b 100644
--- a/crates/dluth-model/src/inkling/model.rs
+++ b/crates/dluth-model/src/inkling/model.rs
@@ -375,7 +375,7 @@ impl<'w> InklingCpu<'w> {
let recent = cfg.conv_taps - 1;
let mut states = Vec::with_capacity(steps.len());
for step in &steps {
- let window = cfg.is_local(step.layer).then_some(cfg.window);
+ let window: Option<usize> = None;
states.push(PassState {
keys: History::new(kv_width, window, max_seq)?,
values: History::new(kv_width, window, max_seq)?,
@@ -366,7 +366,7 @@ impl Ops for CpuOps<'_> {

fn new_pass(&mut self, cfg: &InklingConfig, local: bool, max_seq: usize) -> Result<PassState, ModelError> {
let (h, kv_width, recent) = (cfg.hidden, cfg.kv_heads * cfg.head_dim, cfg.conv_taps - 1);
- let window = local.then_some(cfg.window);
+ let window: Option<usize> = None.filter(|_: &usize| local);
Ok(PassState {
keys: History::new(kv_width, window, max_seq)?,
values: History::new(kv_width, window, max_seq)?,
12 changes: 6 additions & 6 deletions tools/mutants/48-inkling-message-source.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# weights-env: DLUTH_INKLING2_MINI
# Bug: messages are blended from the wrong blocks of the previous pass.
diff --git a/crates/dluth-model/src/inkling/model.rs b/crates/dluth-model/src/inkling/model.rs
index deeb305..0a5621f 100644
index 306a8fc..335010b 100644
--- a/crates/dluth-model/src/inkling/model.rs
+++ b/crates/dluth-model/src/inkling/model.rs
@@ -464,7 +464,7 @@ impl<'w> InklingCpu<'w> {
@@ -777,7 +777,7 @@ impl<'w, O: Ops> Inkling<'w, O> {
// this pass's messages. Then start again from the loop's entry.
// The configuration check guarantees the loop starts on a block
// boundary and is not empty, so that block exists.
let mut source: Vec<&[f32]> =
- blocks[start_blocks.len() + 1..].iter().map(Vec::as_slice).collect();
+ blocks[start_blocks.len()..].iter().map(Vec::as_slice).collect();
- let mut source: Vec<&O::V> = blocks[start_blocks.len() + 1..].iter().collect();
+ let mut source: Vec<&O::V> = blocks[start_blocks.len()..].iter().collect();
source.push(&x);
message_source = Some(depthmix::normalize(&source, BLEND_EPS));
message_source = Some(ops.normalize(&source)?);
x = start_x.clone();
17 changes: 9 additions & 8 deletions tools/mutants/49-inkling-block-boundary.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
# weights-env: DLUTH_INKLING2_MINI
# Bug: a layer that starts a block still adds the previous running sum.
diff --git a/crates/dluth-model/src/inkling/model.rs b/crates/dluth-model/src/inkling/model.rs
index 899fc4b..96d6cce 100644
index 306a8fc..6b94aec 100644
--- a/crates/dluth-model/src/inkling/model.rs
+++ b/crates/dluth-model/src/inkling/model.rs
@@ -770,6 +770,7 @@ fn apply_layer(
let mut sum = a;
if layer.starts_block {
blocks.push(x.to_vec());
+ add_into(&mut sum, x);
@@ -1095,7 +1095,7 @@ fn apply_layer<O: Ops>(
// list and a new sum starts from this layer's attention output.
let sum = if layer.starts_block {
blocks.push(x.clone());
- a
+ ops.add(&a, x)?
} else {
add_into(&mut sum, x);
}
ops.add(&a, x)?
};
6 changes: 3 additions & 3 deletions tools/mutants/51-inkling-output-cap.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# weights-env: DLUTH_INKLING2_MINI
# Bug: the output scores are not capped.
diff --git a/crates/dluth-model/src/inkling/model.rs b/crates/dluth-model/src/inkling/model.rs
index 8693fee..0a783b0 100644
index 306a8fc..cd48873 100644
--- a/crates/dluth-model/src/inkling/model.rs
+++ b/crates/dluth-model/src/inkling/model.rs
@@ -592,7 +592,7 @@ impl<'w> InklingCpu<'w> {
@@ -464,7 +464,7 @@ impl Ops for CpuOps<'_> {
let mut logits = vec![0.0f32; cfg.vocab_out];
self.products.bf16(&self.unembed[..cfg.vocab_out * h * 2], cfg.vocab_out, h, &normed, &mut logits)?;
self.products.bf16(&unembed[..cfg.vocab_out * h * 2], cfg.vocab_out, h, x, &mut logits)?;
for l in logits.iter_mut() {
- *l = cpu::softcap(*l, cfg.logit_cap);
+ *l = l.clamp(-1e30, 1e30);
Expand Down
Loading