engine: the bring-up, driver-error and serve-profile switches are the driver's, the spec trace and stats are controller configuration (STRA-338)
The engine kept a second copy of three switches the CUDA driver already owns (LELEKA_BRINGUP_TRACE, LELEKA_SERVE_PROFILE, LELEKA_PREFILL_PROFILE_SYNC with the bring-up trace); bringup_trace_enabled, serve_profile::enabled and the prefill profile sync now ask the driver's switch, which reads the same variable with the same rule. LELEKA_TRACE_DRIVER_ERRORS joins the bring-up switch in cuda-model (driver_errors_traced, bring-up trace or the variable set). Both were free functions behind about 80 trace call sites that carry no context. LELEKA_SPEC_TRACE and LELEKA_SPEC_STATS are fields of SpecConfig (OriginalServeSettings.trace_rounds/trace_stats, set by with_trace) instead of two functions on the process settings.
This commit is contained in:
@@ -30,7 +30,7 @@ use std::{
|
||||
// STRA-338 S24: the pure host-side models live in `leleka-cuda-model`; they keep their paths in this crate.
|
||||
// Pure halves: command timing (bring-up profiling), host spans, prompt-attention selection and geometry, the
|
||||
// Original `Prefill::run` schedule, `prefill/moe_mmq.cu` and `core/device.cu` helpers, `native_flash_attn.cu`.
|
||||
pub(crate) use leleka_cuda_model::bringup_trace_enabled;
|
||||
pub use leleka_cuda_model::{bringup_trace_enabled, driver_errors_traced};
|
||||
pub use leleka_cuda_model::{
|
||||
command_profile, device_arena, host_profile, mmq_original_prefill_misc, native_flash_attn,
|
||||
original_prefill_schedule, qsa_prompt_attention_select, ring_prefetch, s_gemv_legacy,
|
||||
|
||||
@@ -9,3 +9,10 @@ pub fn bringup_trace_enabled() -> bool {
|
||||
static BRINGUP_TRACE: EnvSwitch = EnvSwitch::new("LELEKA_BRINGUP_TRACE", rules::is_set);
|
||||
BRINGUP_TRACE.get()
|
||||
}
|
||||
|
||||
/// A driver error is printed when `LELEKA_BRINGUP_TRACE` or `LELEKA_TRACE_DRIVER_ERRORS` is set (to anything).
|
||||
#[inline]
|
||||
pub fn driver_errors_traced() -> bool {
|
||||
static TRACE_DRIVER_ERRORS: EnvSwitch = EnvSwitch::new("LELEKA_TRACE_DRIVER_ERRORS", rules::is_set);
|
||||
bringup_trace_enabled() || TRACE_DRIVER_ERRORS.get()
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ pub mod s_gemv_legacy;
|
||||
pub mod serving_context;
|
||||
mod shapes;
|
||||
|
||||
pub use bringup_trace::bringup_trace_enabled;
|
||||
pub use bringup_trace::{bringup_trace_enabled, driver_errors_traced};
|
||||
pub use error::{Error, Result};
|
||||
pub use projection::{DenseFormat, ProjectionKind, ProjectionSpec, RoutedFormat};
|
||||
pub use shapes::{Bf16ProjectionShape, Q5KProjectionShape, Q6KProjectionShape};
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
/// Bring-up tracing: `LELEKA_BRINGUP_TRACE` set (any value) enables the `DBG`/`PROBE` diagnostics on stderr.
|
||||
/// Off by default so production serving prints nothing extra.
|
||||
pub(crate) fn bringup_trace_enabled() -> bool {
|
||||
settings::process().diagnostics.bringup_trace
|
||||
leleka_cuda_driver::bringup_trace_enabled()
|
||||
}
|
||||
/// A driver error is printed when `LELEKA_BRINGUP_TRACE` or `LELEKA_TRACE_DRIVER_ERRORS` is set.
|
||||
pub(crate) fn driver_errors_traced() -> bool {
|
||||
settings::process().diagnostics.traces_driver_errors()
|
||||
leleka_cuda_driver::driver_errors_traced()
|
||||
}
|
||||
macro_rules! bringup_trace {
|
||||
($($arg:tt)*) => {
|
||||
|
||||
@@ -173,6 +173,9 @@ pub(crate) struct OriginalServeSettings {
|
||||
pub(crate) adaptive: Option<AdaptiveConfig>,
|
||||
/// Re-run a verify window with non-finite output from its round's checkpoint (`NanGuard`); off in mode17 itself.
|
||||
pub(crate) nan_guard: NanGuard,
|
||||
/// `LELEKA_SPEC_TRACE` and `LELEKA_SPEC_STATS`: the operator lines of the controller (round trace, request stats).
|
||||
pub(crate) trace_rounds: bool,
|
||||
pub(crate) trace_stats: bool,
|
||||
/// An arm's own `spec_min_p` for the requests it serves (`fixed4@0`), overriding the harness default; `None` = the
|
||||
/// harness's.
|
||||
pub(crate) request_min_p: Option<f32>,
|
||||
|
||||
+6
-1
@@ -22,6 +22,8 @@ impl OriginalServeSettings {
|
||||
coupled,
|
||||
adaptive: None,
|
||||
nan_guard: NanGuard::off(),
|
||||
trace_rounds: false,
|
||||
trace_stats: false,
|
||||
request_min_p: None,
|
||||
}
|
||||
}
|
||||
@@ -35,6 +37,8 @@ impl OriginalServeSettings {
|
||||
let num = |name: &str| env.get(name).and_then(|v| v.trim().parse::<usize>().ok());
|
||||
let mut s = Self::mode17(context, vocabulary, coupled);
|
||||
s.nan_guard = NanGuard::from_environment(env);
|
||||
let decode = crate::settings::DecodeSettings::from_source(env);
|
||||
(s.trace_rounds, s.trace_stats) = (decode.spec_trace, decode.spec_stats);
|
||||
if let Some(spec) = num("LELEKA_SPEC") {
|
||||
let spec = spec.clamp(2, MAX_T);
|
||||
s.max_t = (spec + 2).min(MAX_T);
|
||||
@@ -174,7 +178,8 @@ impl OriginalServeSettings {
|
||||
self.coupled,
|
||||
)?
|
||||
.with_adaptive(self.adaptive)
|
||||
.with_nan_guard(self.nan_guard),
|
||||
.with_nan_guard(self.nan_guard)
|
||||
.with_trace(self.trace_rounds, self.trace_stats),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,6 +340,8 @@ fn serve_settings(max_context: i64) -> OriginalServeSettings {
|
||||
coupled: false,
|
||||
adaptive: None,
|
||||
nan_guard: NanGuard::off(),
|
||||
trace_rounds: false,
|
||||
trace_stats: false,
|
||||
request_min_p: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,10 @@
|
||||
use std::cell::RefCell;
|
||||
use std::time::Instant;
|
||||
|
||||
/// `LELEKA_SERVE_PROFILE` set to anything but `0`, read once.
|
||||
/// `LELEKA_SERVE_PROFILE` set to anything but `0`: the one switch of the driver's host spans, which this profile
|
||||
/// prints next to its own.
|
||||
pub(crate) fn enabled() -> bool {
|
||||
crate::settings::process().diagnostics.serve_profile
|
||||
leleka_cuda_driver::host_profile::enabled()
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ fn note_request_end(
|
||||
result: &std::result::Result<ServeOutcome, SpecError>,
|
||||
) {
|
||||
let stats = controller.take_stats();
|
||||
if super::super::super::original_spec_controller::stats_enabled() {
|
||||
if controller.stats_traced() {
|
||||
eprintln!("DBG spec-stats arm={} {}", arm_label, stats.line());
|
||||
}
|
||||
if let Err(e) = result {
|
||||
|
||||
@@ -108,6 +108,9 @@ pub(crate) struct SpecConfig {
|
||||
adaptive: Option<AdaptiveConfig>,
|
||||
/// See [`NanGuard`]; off unless the caller asks (the controller's own tests rely on the first failure aborting).
|
||||
nan_guard: NanGuard,
|
||||
/// `LELEKA_SPEC_TRACE`: the round trace lines; `LELEKA_SPEC_STATS`: the request stats line.
|
||||
trace_rounds: bool,
|
||||
trace_stats: bool,
|
||||
}
|
||||
struct Request {
|
||||
consumed: Vec<i32>,
|
||||
@@ -173,8 +176,6 @@ mod tests;
|
||||
|
||||
mod finish_round_steps;
|
||||
use finish_round_steps::{RoundFacts, combine_round};
|
||||
mod trace_enabled;
|
||||
pub(crate) use trace_enabled::stats_enabled;
|
||||
pub(crate) use trace_enabled::trace_enabled;
|
||||
mod original_spec_controller_finish;
|
||||
mod round_steps;
|
||||
mod trace_enabled;
|
||||
|
||||
+2
-9
@@ -4,7 +4,6 @@
|
||||
use super::{
|
||||
AdaptivePolicy, Choice, CommittedRound, DraftBatch, DraftPlan, DraftPreparation, DraftSampling, Error,
|
||||
OriginalSpecController, OriginalSpecEngine, Rc, Request, Result, SpecConfig, SpecError, SpecResult, VerifiedWindow,
|
||||
trace_enabled,
|
||||
};
|
||||
use crate::qwen_forward::original_spec_adaptive::RoundFlags;
|
||||
use crate::qwen_forward::original_spec_policy::RoundOutcome;
|
||||
@@ -73,9 +72,6 @@ fn round_chain(plan: Option<DraftPlan>, config: &SpecConfig, min_p: f32, at: (i6
|
||||
|
||||
/// The adaptive policy's trace line of a round (only when the spec trace is on).
|
||||
fn trace_adaptive(round: &RoundFacts, c: &Choice, ms: f64, drafts_after: usize, pol: &AdaptivePolicy) {
|
||||
if !trace_enabled() {
|
||||
return;
|
||||
}
|
||||
let plan = pol.draft_plan();
|
||||
eprintln!(
|
||||
"DBG spec-trace r={} t={} src={:?} acc={} ms={:.2} E={:.2} rate={:.4} explored={} drafts={} \
|
||||
@@ -98,9 +94,6 @@ fn trace_adaptive(round: &RoundFacts, c: &Choice, ms: f64, drafts_after: usize,
|
||||
|
||||
/// The fixed-width policy's trace line of a round (only when the spec trace is on).
|
||||
fn trace_fixed(round: &RoundFacts, ms: f64, drafts_after: usize) {
|
||||
if !trace_enabled() {
|
||||
return;
|
||||
}
|
||||
eprintln!(
|
||||
"DBG spec-trace r={} t={} src={} acc={} ms={:.2} drafts={}",
|
||||
round.round_number,
|
||||
@@ -243,7 +236,7 @@ impl OriginalSpecController {
|
||||
(Some(pol), Some(c)) => {
|
||||
pol.observe(c, round.accepted, ms, drafts_after);
|
||||
self.plan = Some(pol.draft_plan());
|
||||
if trace_enabled() {
|
||||
if self.config.trace_rounds {
|
||||
trace_adaptive(round, c, ms, drafts_after, pol);
|
||||
}
|
||||
}
|
||||
@@ -251,7 +244,7 @@ impl OriginalSpecController {
|
||||
if self.adaptive.is_none() {
|
||||
self.observe_fixed(round, ms)?;
|
||||
}
|
||||
if trace_enabled() {
|
||||
if self.config.trace_rounds {
|
||||
trace_fixed(round, ms, drafts_after);
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -157,6 +157,10 @@ impl OriginalSpecController {
|
||||
pub(crate) fn take_stats(&mut self) -> SpecStats {
|
||||
std::mem::take(&mut self.stats)
|
||||
}
|
||||
/// Whether the operator asked for the request stats line (`LELEKA_SPEC_STATS`).
|
||||
pub(crate) fn stats_traced(&self) -> bool {
|
||||
self.config.trace_stats
|
||||
}
|
||||
pub(crate) fn is_failed(&self) -> bool {
|
||||
self.failed
|
||||
}
|
||||
|
||||
+12
-11
@@ -1,20 +1,11 @@
|
||||
//! Settings of the speculative controller: NanGuard (non-finite window retry policy and its injection), SpecConfig
|
||||
//! (window, context, suffix and adaptive options), the round accessors, and the `LELEKA_SPEC_TRACE/STATS` switches.
|
||||
//! (window, context, suffix and adaptive options), the round accessors, and the `LELEKA_SPEC_TRACE/STATS` switches
|
||||
//! (`with_trace`).
|
||||
|
||||
use super::{
|
||||
AdaptiveConfig, CommittedRound, Error, MAX_T, NanGuard, Result, SpecConfig, SpecContext, SpecError, SpecWindow,
|
||||
};
|
||||
|
||||
/// `LELEKA_SPEC_TRACE`: one `DBG spec-trace` line per timed round (width, source, accepted, round ms, the policy's
|
||||
/// expectation).
|
||||
pub(crate) fn trace_enabled() -> bool {
|
||||
crate::settings::process().decode.spec_trace
|
||||
}
|
||||
/// `LELEKA_SPEC_STATS`: one `DBG spec-stats` line per request (rounds, tokens per round, T and accepted histograms,
|
||||
/// ms per T).
|
||||
pub(crate) fn stats_enabled() -> bool {
|
||||
crate::settings::process().decode.spec_stats
|
||||
}
|
||||
impl From<Error> for SpecError {
|
||||
fn from(e: Error) -> Self {
|
||||
Self::Forward(e)
|
||||
@@ -124,6 +115,8 @@ impl SpecConfig {
|
||||
coupled,
|
||||
adaptive: None,
|
||||
nan_guard: NanGuard::off(),
|
||||
trace_rounds: false,
|
||||
trace_stats: false,
|
||||
})
|
||||
}
|
||||
/// `new` for the context of an unconfigured process (262144 serving cells).
|
||||
@@ -137,6 +130,14 @@ impl SpecConfig {
|
||||
) -> Result<Self> {
|
||||
Self::new(window, SpecContext::trained(max_context), vocabulary, suffix_min_match, coupled)
|
||||
}
|
||||
/// `LELEKA_SPEC_TRACE` (one `DBG spec-trace` line per timed round: width, source, accepted, round ms, the policy's
|
||||
/// expectation) and `LELEKA_SPEC_STATS` (one `DBG spec-stats` line per request: rounds, tokens per round, T and
|
||||
/// accepted histograms, ms per T).
|
||||
pub(crate) fn with_trace(mut self, rounds: bool, stats: bool) -> Self {
|
||||
self.trace_rounds = rounds;
|
||||
self.trace_stats = stats;
|
||||
self
|
||||
}
|
||||
pub(crate) fn with_nan_guard(mut self, guard: NanGuard) -> Self {
|
||||
self.nan_guard = guard;
|
||||
self
|
||||
|
||||
@@ -139,7 +139,7 @@ pub(crate) fn enabled() -> bool {
|
||||
crate::bringup_trace_enabled()
|
||||
}
|
||||
fn sync_enabled() -> bool {
|
||||
enabled() && crate::settings::process().diagnostics.prefill_profile_sync
|
||||
leleka_cuda_driver::command_profile::enabled()
|
||||
}
|
||||
|
||||
/// One timed stage; the elapsed time is added when it drops.
|
||||
|
||||
@@ -47,7 +47,7 @@ pub(crate) struct DecodeSettings {
|
||||
}
|
||||
|
||||
impl DecodeSettings {
|
||||
pub(super) fn from_source(env: &impl EnvSource) -> Self {
|
||||
pub(crate) fn from_source(env: &impl EnvSource) -> Self {
|
||||
Self {
|
||||
coupled: set_and_not_zero(env, "STRATA_SPEC_COUPLED"),
|
||||
overlap: on_unless_off(env, "LELEKA_SERVE_OVERLAP"),
|
||||
|
||||
@@ -6,10 +6,6 @@ use super::source::EnvSource;
|
||||
/// What the operator asked to see.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) struct DiagnosticsSettings {
|
||||
/// `LELEKA_BRINGUP_TRACE` is set (to anything): the `DBG`/`PROBE` lines on stderr.
|
||||
pub(crate) bringup_trace: bool,
|
||||
/// `LELEKA_TRACE_DRIVER_ERRORS` is set (to anything).
|
||||
pub(crate) trace_driver_errors: bool,
|
||||
/// `LELEKA_TRACE_PLE` is set (to anything).
|
||||
pub(crate) trace_ple: bool,
|
||||
/// `LELEKA_TRACE_PREFILL_R` is set (to anything): the hash of every prefill chunk's final residual.
|
||||
@@ -18,32 +14,19 @@ pub(crate) struct DiagnosticsSettings {
|
||||
pub(crate) seed_trace: bool,
|
||||
/// `LELEKA_PREFIX_TRACE` is set (to anything).
|
||||
pub(crate) prefix_trace: bool,
|
||||
/// `LELEKA_SERVE_PROFILE`: set, non-empty and not `0`.
|
||||
pub(crate) serve_profile: bool,
|
||||
/// `LELEKA_SERVE_PROFILE_TIER_CROSS`: set, non-empty and not `0`; the cross-layer swap estimate of the profile.
|
||||
/// It sorts the usage of all 24,576 experts at every adaptation: about 0.6 ms of host time in the draft's shadow.
|
||||
pub(crate) profile_tier_cross: bool,
|
||||
/// `LELEKA_PREFILL_PROFILE_SYNC` is set (to anything); it only matters while the bring-up trace is on.
|
||||
pub(crate) prefill_profile_sync: bool,
|
||||
}
|
||||
|
||||
impl DiagnosticsSettings {
|
||||
pub(super) fn from_source(env: &impl EnvSource) -> Self {
|
||||
Self {
|
||||
bringup_trace: env.is_set("LELEKA_BRINGUP_TRACE"),
|
||||
trace_driver_errors: env.is_set("LELEKA_TRACE_DRIVER_ERRORS"),
|
||||
trace_ple: env.is_set("LELEKA_TRACE_PLE"),
|
||||
trace_prefill_r: env.is_set("LELEKA_TRACE_PREFILL_R"),
|
||||
seed_trace: env.is_set("LELEKA_SEED_TRACE"),
|
||||
prefix_trace: env.is_set("LELEKA_PREFIX_TRACE"),
|
||||
serve_profile: set_and_not_zero(env, "LELEKA_SERVE_PROFILE"),
|
||||
profile_tier_cross: set_and_not_zero(env, "LELEKA_SERVE_PROFILE_TIER_CROSS"),
|
||||
prefill_profile_sync: env.is_set("LELEKA_PREFILL_PROFILE_SYNC"),
|
||||
}
|
||||
}
|
||||
|
||||
/// A driver error is printed when either the bring-up trace or the driver-error trace is on.
|
||||
pub(crate) fn traces_driver_errors(&self) -> bool {
|
||||
self.bringup_trace || self.trace_driver_errors
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,10 @@ fn set_ness(key: &str, field: fn(&DiagnosticsSettings) -> bool) {
|
||||
|
||||
#[test]
|
||||
fn the_trace_switches_are_on_when_set_to_anything() {
|
||||
set_ness("LELEKA_BRINGUP_TRACE", |d| d.bringup_trace);
|
||||
set_ness("LELEKA_TRACE_DRIVER_ERRORS", |d| d.trace_driver_errors);
|
||||
set_ness("LELEKA_TRACE_PLE", |d| d.trace_ple);
|
||||
set_ness("LELEKA_TRACE_PREFILL_R", |d| d.trace_prefill_r);
|
||||
set_ness("LELEKA_SEED_TRACE", |d| d.seed_trace);
|
||||
set_ness("LELEKA_PREFIX_TRACE", |d| d.prefix_trace);
|
||||
set_ness("LELEKA_PREFILL_PROFILE_SYNC", |d| d.prefill_profile_sync);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -31,22 +28,6 @@ fn a_raw_os_value_counts_as_set() {
|
||||
assert!(settings.trace_ple);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_serve_profile_is_set_non_empty_and_not_zero() {
|
||||
assert!(!diag(&[]).serve_profile);
|
||||
for (value, want) in [("1", true), ("on", true), ("00", true), ("0", false), ("", false)] {
|
||||
assert_eq!(diag(&[("LELEKA_SERVE_PROFILE", value)]).serve_profile, want, "{value:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn driver_errors_print_under_either_trace() {
|
||||
assert!(!diag(&[]).traces_driver_errors());
|
||||
assert!(diag(&[("LELEKA_BRINGUP_TRACE", "")]).traces_driver_errors());
|
||||
assert!(diag(&[("LELEKA_TRACE_DRIVER_ERRORS", "")]).traces_driver_errors());
|
||||
assert!(!diag(&[("LELEKA_TRACE_PLE", "1")]).traces_driver_errors());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_tier_cross_estimate_is_set_non_empty_and_not_zero() {
|
||||
assert!(!diag(&[]).profile_tier_cross);
|
||||
|
||||
Reference in New Issue
Block a user