pub struct DebugScanner {
pub mode: DebugMode,
/* private fields */
}Expand description
Shared NaN/Inf debug epilogue for every backend run loop.
Centralizes the RLX_DEBUG_NANS policy so each backend adds only a few
lines: build one with DebugScanner::from_env before the loop, gate on
enabled, and hand each computed node’s output + operand
slices to check. The env var is read once (constructing
the scanner), never per-node.
RLX_DEBUG_NANS values: unset / 0 / empty ⇒ Off;
abort ⇒ Abort; anything else truthy ⇒
Warn.
Fields§
§mode: DebugModeImplementations§
Source§impl DebugScanner
impl DebugScanner
Sourcepub fn with_mode(mode: DebugMode, backend: &'static str) -> Self
pub fn with_mode(mode: DebugMode, backend: &'static str) -> Self
Construct with an explicit mode (bypassing the env), tagging messages
with backend. Useful in tests and when a caller drives the mode.
Sourcepub fn from_env(backend: &'static str) -> Self
pub fn from_env(backend: &'static str) -> Self
Build from RLX_DEBUG_NANS, tagging messages with backend.
Sourcepub fn enabled(&self) -> bool
pub fn enabled(&self) -> bool
True when scanning is active — gate the (possibly expensive) readback and gather on this so production pays nothing.
Sourcepub fn check_outputs(&self, graph: &Graph, outputs: &[Vec<f32>])
pub fn check_outputs(&self, graph: &Graph, outputs: &[Vec<f32>])
Scan a whole-graph run’s outputs — the universal fallback for backends
that execute opaquely (MPSGraph, MLX, CoreML MIL, PJRT/HLO) and can’t
hook per-op. Reports which graph output first went non-finite, with its
provenance. outputs is zipped against graph.outputs positionally, as
every backend returns them in that order. No-op when scanning is off.
For internal localization on those backends, run the identical graph
on the CPU backend with RLX_DEBUG_NANS — provenance is backend-neutral.
Sourcepub fn check(
&self,
graph: &Graph,
node: NodeId,
output: &[f32],
inputs: &[(NodeId, &[f32])],
) -> Option<NanReport>
pub fn check( &self, graph: &Graph, node: NodeId, output: &[f32], inputs: &[(NodeId, &[f32])], ) -> Option<NanReport>
Scan one node’s output; on the first bad value, print a localized
diagnostic and (in Abort mode) panic. Returns the
report so callers may also collect/stop. No-op when the output is clean
or scanning is off.
Trait Implementations§
Source§impl Clone for DebugScanner
impl Clone for DebugScanner
Source§fn clone(&self) -> DebugScanner
fn clone(&self) -> DebugScanner
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more