Skip to main content

DebugScanner

Struct DebugScanner 

Source
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; abortAbort; anything else truthy ⇒ Warn.

Fields§

§mode: DebugMode

Implementations§

Source§

impl DebugScanner

Source

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.

Source

pub fn from_env(backend: &'static str) -> Self

Build from RLX_DEBUG_NANS, tagging messages with backend.

Source

pub fn enabled(&self) -> bool

True when scanning is active — gate the (possibly expensive) readback and gather on this so production pays nothing.

Source

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.

Source

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

Source§

fn clone(&self) -> DebugScanner

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DebugScanner

Source§

impl Debug for DebugScanner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.