Mass cleanup of crates/ml/: - Delete 121 dead/broken/superseded example files (-44,098 lines) - Delete 6 QAT test files (-4,201 lines) — QAT is disabled at runtime (trainer.rs falls back to FP32 with warning) - Delete 2 stale markdown files in examples/ - Delete orphaned src/bin/train_tft.rs (unimplemented stub) - Clean up Cargo.toml: remove stale [[example]] entries, add missing ones - Fix stale binary references in log_size_test.rs - Add infra consistency test (35 checks across Dockerfile/train.sh/Cargo.toml) Remaining examples (7): train_baseline_rl, train_baseline_supervised, evaluate_baseline, hyperopt_baseline_rl, hyperopt_baseline_supervised, download_baseline, cuda_test All 2390 lib tests pass. All examples compile. 35/35 infra checks pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
131 lines
4.0 KiB
Rust
131 lines
4.0 KiB
Rust
/// Wave 16M: Test log size reduction from 2.8MB → <1MB
|
|
///
|
|
/// Validates that 1-epoch training produces <100KB of INFO-level logs
|
|
/// (scaling to <1MB for 10 epochs).
|
|
///
|
|
/// **Test Strategy**:
|
|
/// 1. Run 1-epoch training with RUST_LOG=info
|
|
/// 2. Capture log output to file
|
|
/// 3. Verify file size <100KB (10x scaling → <1MB for 10 epochs)
|
|
/// 4. Verify essential metrics still visible (epoch summary, trading stats)
|
|
|
|
use std::fs::File;
|
|
use std::io::Write;
|
|
use std::process::Command;
|
|
|
|
#[test]
|
|
fn test_log_size_under_1mb() {
|
|
// Create temp log file
|
|
let log_file = "/tmp/test_log_size.log";
|
|
|
|
// Run 1-epoch training with INFO-level logging
|
|
let output = Command::new("cargo")
|
|
.args(&[
|
|
"run",
|
|
"-p",
|
|
"ml",
|
|
"--example",
|
|
"train_baseline_rl",
|
|
"--release",
|
|
"--features",
|
|
"cuda",
|
|
"--",
|
|
"--model",
|
|
"dqn",
|
|
"--epochs",
|
|
"1",
|
|
])
|
|
.env("RUST_LOG", "info")
|
|
.output()
|
|
.expect("Failed to run training");
|
|
|
|
// Write output to file
|
|
let mut file = File::create(log_file).expect("Failed to create log file");
|
|
file.write_all(&output.stdout).expect("Failed to write stdout");
|
|
file.write_all(&output.stderr).expect("Failed to write stderr");
|
|
|
|
// Check log size
|
|
let metadata = std::fs::metadata(log_file).expect("Failed to read log file");
|
|
let size_bytes = metadata.len();
|
|
let size_kb = size_bytes as f64 / 1_024.0;
|
|
let size_mb = size_bytes as f64 / 1_048_576.0;
|
|
|
|
println!("Log size: {:.2} KB ({:.3} MB)", size_kb, size_mb);
|
|
|
|
// 1 epoch should produce <100KB (10 epochs → <1MB)
|
|
assert!(
|
|
size_kb < 100.0,
|
|
"1-epoch log should be <100KB, got {:.2}KB ({:.3}MB). 10-epoch projection: {:.2}MB",
|
|
size_kb,
|
|
size_mb,
|
|
size_mb * 10.0
|
|
);
|
|
|
|
// Verify essential metrics are still present (INFO level)
|
|
let log_content = std::fs::read_to_string(log_file).expect("Failed to read log file");
|
|
|
|
// Essential metrics that MUST be visible at INFO level
|
|
assert!(
|
|
log_content.contains("Epoch 1/1"),
|
|
"Missing epoch summary in INFO logs"
|
|
);
|
|
assert!(
|
|
log_content.contains("train_loss=") || log_content.contains("Training Stats"),
|
|
"Missing training loss in INFO logs"
|
|
);
|
|
assert!(
|
|
log_content.contains("Trading Stats") || log_content.contains("P&L"),
|
|
"Missing trading stats in INFO logs"
|
|
);
|
|
assert!(
|
|
log_content.contains("Action diversity") || log_content.contains("diversity="),
|
|
"Missing action diversity in INFO logs"
|
|
);
|
|
|
|
println!("✅ Test passed: Log size {:.2}KB < 100KB target", size_kb);
|
|
println!("✅ Projected 10-epoch log size: {:.2}MB < 1MB target", size_mb * 10.0);
|
|
}
|
|
|
|
#[test]
|
|
fn test_debug_logs_available() {
|
|
// Create temp log file
|
|
let log_file = "/tmp/test_log_debug.log";
|
|
|
|
// Run 1-epoch training with DEBUG-level logging
|
|
let output = Command::new("cargo")
|
|
.args(&[
|
|
"run",
|
|
"-p",
|
|
"ml",
|
|
"--example",
|
|
"train_baseline_rl",
|
|
"--release",
|
|
"--features",
|
|
"cuda",
|
|
"--",
|
|
"--model",
|
|
"dqn",
|
|
"--epochs",
|
|
"1",
|
|
])
|
|
.env("RUST_LOG", "debug")
|
|
.output()
|
|
.expect("Failed to run training");
|
|
|
|
// Write output to file
|
|
let mut file = File::create(log_file).expect("Failed to create log file");
|
|
file.write_all(&output.stdout).expect("Failed to write stdout");
|
|
file.write_all(&output.stderr).expect("Failed to write stderr");
|
|
|
|
// Verify DEBUG logs contain step-level details
|
|
let log_content = std::fs::read_to_string(log_file).expect("Failed to read log file");
|
|
|
|
// DEBUG-level details should be present
|
|
assert!(
|
|
log_content.contains("Q-values:") || log_content.contains("Diagnostics:"),
|
|
"Missing step-level diagnostics in DEBUG logs"
|
|
);
|
|
|
|
println!("✅ DEBUG logs contain step-level details");
|
|
}
|