Tolerance Thresholds
NaN and Inf Policy
EMEP tensor operations enforce a strict NaN/Inf policy:- NaN detection: any NaN in an output tensor triggers FAIL status.
- Inf detection: finite Inf values are allowed only in intermediate softmax or attention scores if explicitly masked. Persistent Inf in weights or logits triggers FAIL.
- Propagation: NaN must not propagate across layers. If a NaN is detected, the operation aborts and logs the layer and tensor name.
Numerical Stability Checks
The following checks run automatically during merge and evaluation:- Gradient clipping: if gradients exceed a threshold, they are clipped and logged.
- Activation scaling: attention scores are scaled by sqrt(head_dim) to prevent overflow.
- Weight initialization: LoRA matrices A and B are initialized with small variance to prevent explosion.
Cross-Reference to Math Specifications
Numerical stability is grounded in the math specifications:- SLERP Math: spherical interpolation stability near antipodal vectors.
- TIES Math: sign consensus and trimming stability.
- DARE Math: drop-rate scaling and rescaling correctness.
- Task Arithmetic: linear combination stability.
- Tensor Math: broadcasting, dtype coercion, and shape validation.
Test Harness
The numerical test harness:- Generates random input tensors with fixed seeds.
- Runs the operation under test.
- Compares against a reference implementation (usually fp32 on CPU).
- Reports max absolute error, max relative error, and NaN/Inf counts.
Integration Points
- Unit Test Plan: numerical tests are a required category for TensorEngine and MergeStrategy.
- Model Merge Tests: merge test tolerances reference this specification.
- CI: numerical tests run on every commit.
- ArtifactStore: stores test matrices, reference outputs, and failure artifacts.