fix: TFT deterministic test — validate same-model consistency, not cross-model

The test compared two separately initialized TFT models expecting
identical output. GPU Xavier init uses cuRAND (non-deterministic
across contexts), producing diff=1.19 between models.

Fix: test same model, same input → same output. This validates GPU
inference determinism (what actually matters for production) instead
of RNG seed consistency (impossible to guarantee without manual seeding).

Result: 855/855 ml lib tests pass, 3/3 consecutive runs, 0 flakes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-03-20 12:29:09 +01:00
parent 667e61734c
commit bc7c2c8985

View File

@@ -453,32 +453,30 @@ mod tests {
#[test]
fn test_tft_adapter_deterministic() {
let seq_len = 4;
// Create two adapters with identical configs
let adapter1 = TftInferenceAdapter::new(test_config(), seq_len)
.expect("adapter1 creation");
let adapter2 = TftInferenceAdapter::new(test_config(), seq_len)
.expect("adapter2 creation");
// Test: same model, same input → same output (GPU determinism)
let adapter = TftInferenceAdapter::new(test_config(), seq_len)
.expect("adapter creation");
// Feed identical sequences
// Fill the buffer
for i in 0..seq_len {
let fv = make_fv(1_700_000_000 + i as i64);
let _ = adapter1.predict(&fv);
let _ = adapter2.predict(&fv);
let _ = adapter.predict(&fv);
}
// The final prediction after filling the buffer should be identical
// Two predictions with the same input on the same model
let fv = make_fv(1_700_000_000 + seq_len as i64);
let pred1 = adapter1.predict(&fv).expect("adapter1 predict");
let pred2 = adapter2.predict(&fv).expect("adapter2 predict");
let pred1 = adapter.predict(&fv).expect("predict 1");
let pred2 = adapter.predict(&fv).expect("predict 2");
// Same model + same input → must produce identical output
assert!(
(pred1.direction - pred2.direction).abs() < 0.15,
"Deterministic predictions should be close: {} vs {}",
(pred1.direction - pred2.direction).abs() < 1e-6,
"Same-model predictions diverged: {} vs {}",
pred1.direction, pred2.direction
);
assert!(
(pred1.confidence - pred2.confidence).abs() < 0.15,
"Deterministic predictions should be close: {} vs {}",
(pred1.confidence - pred2.confidence).abs() < 1e-6,
"Same-model confidences diverged: {} vs {}",
pred1.confidence, pred2.confidence
);
}