Skip to content
Open
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
13 changes: 12 additions & 1 deletion crates/larql-inference/src/vindex/walk_ffn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ fn walk_trace_env_enabled() -> bool {

impl<'a> WalkFfn<'a> {
fn top_k_for(&self, layer: usize) -> usize {
self.config.k_for(layer).unwrap_or(usize::MAX)
self.config
.k_for(layer)
.unwrap_or_else(|| self.index.num_features(layer))
}

// ── Legacy constructors (stable public API) ──
Expand Down Expand Up @@ -786,6 +788,15 @@ mod dispatch_tests {
assert_eq!(out.shape(), &[1, weights.hidden_size]);
}

#[test]
fn dense_top_k_for_clamps_to_layer_feature_count() {
let weights = shared_weights();
let idx = mock_index(weights);
let ffn = WalkFfn::new_unlimited(weights, &idx);

assert_eq!(ffn.top_k_for(0), weights.intermediate_size);
}

/// Variant of `MockGateIndex` that yields a `FeatureMeta` for every
/// `(layer, feature)` query. This is what `take_trace` needs to
/// promote a residual into a populated `WalkHit` — without it, the
Expand Down