Repository navigation
fix(skippy): make local proposal handoff deadline-safe #1193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
e762e78
512b725
b54f3d7
52b077e
50ad3c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ use crate::frontend::generation::{ | |
| LocalGeneration, OpenAiBackendMode, OpenAiCacheHints, OpenAiGenerationIds, StageOpenAiBackend, | ||
| TokenControl, | ||
| }; | ||
| use crate::frontend::local_generation::token_generation::commit_local_generation_token; | ||
| use crate::frontend::local_generation::{ | ||
| native_mtp_dispatch_counts_for_test, prompt_fits_single_prefill_sample, | ||
| }; | ||
|
|
@@ -30,6 +31,7 @@ use crate::telemetry::{Telemetry, TelemetryLevel}; | |
| #[derive(Default)] | ||
| struct RecordingReceiptSink { | ||
| receipts: Mutex<Vec<GenerationReceipt>>, | ||
| commits: Mutex<Vec<GenerationCommit>>, | ||
| fail: AtomicBool, | ||
| } | ||
|
|
||
|
|
@@ -38,7 +40,8 @@ impl GenerationReceiptSink for RecordingReceiptSink { | |
| Ok(()) | ||
| } | ||
|
|
||
| fn committed(&self, _commit: &GenerationCommit) -> Result<()> { | ||
| fn committed(&self, commit: &GenerationCommit) -> Result<()> { | ||
| self.commits.lock().unwrap().push(commit.clone()); | ||
| Ok(()) | ||
| } | ||
|
|
||
|
|
@@ -65,6 +68,16 @@ fn wait_for_receipts(sink: &RecordingReceiptSink, expected: usize) { | |
| panic!("timed out waiting for {expected} generation receipts"); | ||
| } | ||
|
|
||
| fn wait_for_commits(sink: &RecordingReceiptSink, expected: usize) { | ||
| for _ in 0..100 { | ||
| if sink.commits.lock().unwrap().len() >= expected { | ||
| return; | ||
| } | ||
| thread::sleep(Duration::from_millis(1)); | ||
| } | ||
| panic!("timed out waiting for {expected} generation commits"); | ||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @coderabbitai does rust have a stronger pattern for this instead of busy-wait looping?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This avoids the 1 ms polling interval and reduces test scheduler sensitivity. A channel with You are interacting with an AI system. |
||
| #[test] | ||
| fn single_prefill_sample_requires_prompt_to_fit_session_batch() { | ||
| assert!(!prompt_fits_single_prefill_sample(0, 2048)); | ||
|
|
@@ -73,6 +86,27 @@ fn single_prefill_sample_requires_prompt_to_fit_session_batch() { | |
| assert!(!prompt_fits_single_prefill_sample(2049, 2048)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn local_generation_commit_helper_preserves_ordered_counts() { | ||
| let sink = Arc::new(RecordingReceiptSink::default()); | ||
| let config = GenerationReceiptConfig::new(sink.clone()); | ||
| let mut generated_token_count = 0; | ||
|
|
||
| commit_local_generation_token(Some(&config), 11, 22, &mut generated_token_count, 33); | ||
| commit_local_generation_token(Some(&config), 11, 22, &mut generated_token_count, 44); | ||
|
|
||
| let commits = sink.commits.lock().unwrap(); | ||
| assert_eq!(commits.len(), 2); | ||
| assert_eq!(commits[0].request_id, 11); | ||
| assert_eq!(commits[0].session_id, 22); | ||
| assert_eq!(commits[0].generated_token_count, 1); | ||
| assert_eq!(commits[0].token_ids.as_ref(), [33]); | ||
| assert_eq!(commits[1].request_id, 11); | ||
| assert_eq!(commits[1].session_id, 22); | ||
| assert_eq!(commits[1].generated_token_count, 2); | ||
| assert_eq!(commits[1].token_ids.as_ref(), [44]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn local_native_mtp_decode_uses_non_frame_runtime_api() { | ||
| let (sampled_calls, frame_calls) = native_mtp_dispatch_counts_for_test(); | ||
|
|
@@ -188,7 +222,17 @@ fn local_generation_eventually_delivers_receipts_and_cleanup_survives_sink_error | |
| }, | ||
| )?; | ||
|
|
||
| wait_for_commits(&sink, emitted.len()); | ||
| wait_for_receipts(&sink, 1); | ||
| let commits = sink.commits.lock().unwrap(); | ||
| assert_eq!(commits.len(), emitted.len()); | ||
| for (index, (commit, token_id)) in commits.iter().zip(&emitted).enumerate() { | ||
| assert_eq!(commit.request_id, ids.request_id); | ||
| assert_eq!(commit.session_id, ids.session_id); | ||
| assert_eq!(commit.generated_token_count, index + 1); | ||
| assert_eq!(commit.token_ids.as_ref(), [*token_id]); | ||
| } | ||
| drop(commits); | ||
| let receipts = sink.receipts.lock().unwrap(); | ||
| assert_eq!(receipts.len(), 1); | ||
| assert_eq!(receipts[0].request_id, ids.request_id); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.