style: cargo fmt --workspace (whitespace/wrapping only, no semantic change)
Whole-workspace rustfmt pass picked up while iterating on Mamba GPU backward work. Verified formatting-only via diff sampling; no logic changed. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
@@ -128,8 +128,7 @@ impl DynamicDraftTree {
|
||||
if self.config.max_depth == 0 {
|
||||
return false;
|
||||
}
|
||||
node.probability > self.config.expansion_threshold
|
||||
&& node.depth < self.config.max_depth - 1
|
||||
node.probability > self.config.expansion_threshold && node.depth < self.config.max_depth - 1
|
||||
}
|
||||
|
||||
/// Remove all leaf nodes whose cumulative path probability (root→leaf
|
||||
@@ -237,9 +236,10 @@ impl DynamicDraftTree {
|
||||
if let Some(parent_idx) = self.inner.nodes[idx].parent {
|
||||
let siblings: Vec<usize> =
|
||||
self.inner.nodes[parent_idx].children.clone();
|
||||
if let Some(sibling_idx) = siblings.into_iter().find(|&s| {
|
||||
self.inner.nodes[s].token_id == actual_next_token
|
||||
}) {
|
||||
if let Some(sibling_idx) = siblings
|
||||
.into_iter()
|
||||
.find(|&s| self.inner.nodes[s].token_id == actual_next_token)
|
||||
{
|
||||
self.inner.nodes[sibling_idx].accepted = true;
|
||||
accepted += 1;
|
||||
}
|
||||
@@ -332,10 +332,8 @@ impl Eagle3Decoder {
|
||||
.draft_from_hidden(hidden_states, context, &eagle_cfg)
|
||||
.await?;
|
||||
|
||||
let root_candidates: Vec<(u32, f32)> = root_tokens
|
||||
.iter()
|
||||
.map(|t| (t.id, t.probability))
|
||||
.collect();
|
||||
let root_candidates: Vec<(u32, f32)> =
|
||||
root_tokens.iter().map(|t| (t.id, t.probability)).collect();
|
||||
|
||||
let root_indices = tree.add_roots(&root_candidates);
|
||||
|
||||
@@ -369,22 +367,17 @@ impl Eagle3Decoder {
|
||||
} {
|
||||
let node_depth = tree.inner.nodes[parent_idx].depth;
|
||||
// Force expansion until each path is at least min_depth tokens.
|
||||
let must_expand = self.config.min_depth > 0
|
||||
&& node_depth < self.config.min_depth - 1;
|
||||
let must_expand = self.config.min_depth > 0 && node_depth < self.config.min_depth - 1;
|
||||
let may_expand = tree.should_expand(parent_idx);
|
||||
|
||||
if !must_expand && !may_expand {
|
||||
continue;
|
||||
}
|
||||
|
||||
let child_tokens = draft_model
|
||||
.draft_from_hidden(&hs, &ctx, &eagle_cfg)
|
||||
.await?;
|
||||
let child_tokens = draft_model.draft_from_hidden(&hs, &ctx, &eagle_cfg).await?;
|
||||
|
||||
let child_candidates: Vec<(u32, f32)> = child_tokens
|
||||
.iter()
|
||||
.map(|t| (t.id, t.probability))
|
||||
.collect();
|
||||
let child_candidates: Vec<(u32, f32)> =
|
||||
child_tokens.iter().map(|t| (t.id, t.probability)).collect();
|
||||
|
||||
let child_indices = tree.expand_node(parent_idx, &child_candidates);
|
||||
|
||||
@@ -414,9 +407,9 @@ impl Eagle3Decoder {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::InferenceResult;
|
||||
use crate::speculative::eagle::{EagleConfig, EagleDraftModel};
|
||||
use crate::speculative::types::Token;
|
||||
use crate::InferenceResult;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Mock EagleDraftModel
|
||||
@@ -638,10 +631,7 @@ mod tests {
|
||||
|
||||
let prob = tree.path_probability(gc);
|
||||
// 0.8 * 0.5 * 0.25 = 0.1
|
||||
assert!(
|
||||
(prob - 0.1_f32).abs() < 1e-6,
|
||||
"expected 0.1, got {prob}"
|
||||
);
|
||||
assert!((prob - 0.1_f32).abs() < 1e-6, "expected 0.1, got {prob}");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@@ -103,10 +103,7 @@ impl WindowedAcceptanceTracker {
|
||||
if self.buffer.is_empty() {
|
||||
return 0.0;
|
||||
}
|
||||
self.buffer
|
||||
.iter()
|
||||
.copied()
|
||||
.fold(f32::INFINITY, f32::min)
|
||||
self.buffer.iter().copied().fold(f32::INFINITY, f32::min)
|
||||
}
|
||||
|
||||
/// Maximum value in the current window, or `0.0` if empty.
|
||||
@@ -266,8 +263,7 @@ impl PerformanceMetrics {
|
||||
};
|
||||
|
||||
// Push per-step acceptance rate into the sliding window.
|
||||
let step_rate =
|
||||
step_result.accepted_tokens as f32 / step_result.draft_tokens.max(1) as f32;
|
||||
let step_rate = step_result.accepted_tokens as f32 / step_result.draft_tokens.max(1) as f32;
|
||||
self.windowed.push(step_rate);
|
||||
|
||||
// Estimate speedup ratio
|
||||
@@ -338,10 +334,7 @@ mod tests {
|
||||
assert!(tracker.is_full());
|
||||
// Sum should be 0.2 + 0.3 + 0.4 = 0.9 → mean ≈ 0.3
|
||||
let rate = tracker.windowed_rate();
|
||||
assert!(
|
||||
(rate - 0.3).abs() < 1e-5,
|
||||
"expected ~0.3, got {rate}"
|
||||
);
|
||||
assert!((rate - 0.3).abs() < 1e-5, "expected ~0.3, got {rate}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -438,8 +431,16 @@ mod tests {
|
||||
tracker.push(0.3);
|
||||
tracker.push(0.7);
|
||||
tracker.push(0.9);
|
||||
assert!((tracker.min() - 0.3).abs() < 1e-5, "min got {}", tracker.min());
|
||||
assert!((tracker.max() - 0.9).abs() < 1e-5, "max got {}", tracker.max());
|
||||
assert!(
|
||||
(tracker.min() - 0.3).abs() < 1e-5,
|
||||
"min got {}",
|
||||
tracker.min()
|
||||
);
|
||||
assert!(
|
||||
(tracker.max() - 0.9).abs() < 1e-5,
|
||||
"max got {}",
|
||||
tracker.max()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -455,7 +456,7 @@ mod tests {
|
||||
fn test_clamp_out_of_range() {
|
||||
let mut tracker = WindowedAcceptanceTracker::new(5);
|
||||
tracker.push(-0.5); // clamped to 0.0
|
||||
tracker.push(1.5); // clamped to 1.0
|
||||
tracker.push(1.5); // clamped to 1.0
|
||||
assert!((tracker.windowed_rate() - 0.5).abs() < 1e-5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ pub use medusa::*;
|
||||
pub use metrics::*;
|
||||
pub use self_spec::*;
|
||||
pub use streaming::{
|
||||
collect_stream, SpeculativeStreamConfig, SpeculativeStreamer, StreamStats, StreamedToken,
|
||||
SpeculativeStreamConfig, SpeculativeStreamer, StreamStats, StreamedToken, collect_stream,
|
||||
};
|
||||
pub use traits::*;
|
||||
pub use tree::*;
|
||||
|
||||
Reference in New Issue
Block a user