-
Notifications
You must be signed in to change notification settings - Fork 39
feat(libsy): expose algorithm metrics through driver #307
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
Open
nachiketb-nvidia
wants to merge
3
commits into
main
Choose a base branch
from
nachiketb/switch-1227-driver-algorithm-metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ use serde::Deserialize; | |
| use super::prompts; | ||
| use super::tool_signals::ToolSignals; | ||
| use crate::Result; | ||
| use crate::core::algorithm::Driver; | ||
| use crate::core::algorithm::{Driver, MetricAttribute}; | ||
| use crate::core::classifier::{Classification, Classifier, Score}; | ||
| use crate::core::state::{State, StateValue}; | ||
| use switchyard_protocol::Request; | ||
|
|
@@ -43,6 +43,9 @@ const HARD_SEVERITY: f64 = 0.7; | |
| const SIGNAL_UNIT: f64 = 0.10; | ||
| /// Critical severity forces the capable tier regardless of the scorer. | ||
| const SEVERITY_CRITICAL: f32 = 1.0; | ||
| const SCORE_METRIC: &str = "switchyard.stage_router.score"; | ||
| const CONFIDENCE_METRIC: &str = "switchyard.stage_router.confidence"; | ||
| const DIMENSION_METRIC: &str = "switchyard.stage_router.dimension"; | ||
|
|
||
| /// The two tiers a turn can route to. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
|
|
@@ -340,6 +343,37 @@ pub fn pick_tier(signal: &ToolSignals, mode: PickerMode, confidence_threshold: f | |
| } | ||
| } | ||
|
|
||
| /// Records the router's scorer output and four bounded input dimensions. | ||
| fn record_metrics(driver: Option<&Driver>, signal: &ToolSignals, outcome: &PickOutcome) { | ||
| let Some(driver) = driver else { | ||
| return; | ||
| }; | ||
| let (score, confidence) = match outcome { | ||
| PickOutcome::Resolved { | ||
| score, confidence, .. | ||
| } => (*score, confidence.unwrap_or(score.abs())), | ||
| PickOutcome::ConsultClassifier { | ||
| score, confidence, .. | ||
| } => (*score, *confidence), | ||
| }; | ||
| driver.record_histogram(SCORE_METRIC, score, []); | ||
| driver.record_histogram(CONFIDENCE_METRIC, confidence, []); | ||
|
|
||
| let dimensions = dimensions_from_signal(signal); | ||
| for (name, value) in [ | ||
| ("severity", dimensions.severity), | ||
| ("spinning", dimensions.spinning), | ||
| ("exploring", dimensions.exploring), | ||
| ("production_intensity", dimensions.production_intensity), | ||
| ] { | ||
| driver.record_histogram( | ||
|
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 is great! We can stick to reporting raw scores. can you update the routing algorithms page for stage router where Im talking about decision sources ? |
||
| DIMENSION_METRIC, | ||
| value, | ||
| [MetricAttribute::new("dimension", name)], | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// Build a resolved outcome (a decision made without the classifier). | ||
| fn resolved( | ||
| tier: Tier, | ||
|
|
@@ -484,7 +518,7 @@ impl Classifier<State> for StageClassifier { | |
| &self, | ||
| state: &mut State, | ||
| request: &mut Request, | ||
| _driver: Option<&Driver>, | ||
| driver: Option<&Driver>, | ||
| ) -> Result<(Classification, Option<switchyard_protocol::Response>)> { | ||
| let tool_signals = &state.tool_signals; | ||
| let Some(signal) = tool_signals else { | ||
|
|
@@ -494,6 +528,7 @@ impl Classifier<State> for StageClassifier { | |
| }; | ||
|
|
||
| let outcome = pick_tier(signal, self.mode, self.confidence_threshold); | ||
| record_metrics(driver, signal, &outcome); | ||
| match outcome { | ||
| PickOutcome::Resolved { | ||
| tier, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we generalize this a bit? if we add a new signal, Ill have to manually update the strings here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's probably best practice since that would be a meaningful update, can probably pull this up to a const variable would that be preferable?