Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

Move trace_validator.rs to tests (#423)

Aleksandr Golokoz4ae4c933f4c1
diff --git a/crates/backend-uzu/src/encodable_block/short_conv_mixer.rs b/crates/backend-uzu/src/encodable_block/short_conv_mixer.rs
index 6fcb3fec9..6545e6050 100644
--- a/crates/backend-uzu/src/encodable_block/short_conv_mixer.rs
+++ b/crates/backend-uzu/src/encodable_block/short_conv_mixer.rs
@@ -39,7 +39,7 @@ pub struct ShortConvMixer<B: Backend> {
data_type: DataType,
}
-pub(crate) struct ShortConvArguments<'a, B: Backend> {
+pub struct ShortConvArguments<'a, B: Backend> {
pub active_row_count: usize,
pub sampling_start: usize,
pub sampling_length: usize,
diff --git a/crates/backend-uzu/src/language_model/mod.rs b/crates/backend-uzu/src/language_model/mod.rs
index 14a07af90..881a2d811 100644
--- a/crates/backend-uzu/src/language_model/mod.rs
+++ b/crates/backend-uzu/src/language_model/mod.rs
@@ -7,7 +7,7 @@ pub mod result;
pub mod rng;
#[cfg(feature = "tracing")]
-pub(crate) mod sampler;
+pub mod sampler;
// Re-export main types
pub use language_model_generator::{LanguageModelGenerator, LanguageModelGeneratorTrait};
diff --git a/crates/backend-uzu/src/lib.rs b/crates/backend-uzu/src/lib.rs
index bbfa77026..afc80e7d5 100644
--- a/crates/backend-uzu/src/lib.rs
+++ b/crates/backend-uzu/src/lib.rs
@@ -4,21 +4,13 @@ extern crate self as backend_uzu;
mod array;
mod audio;
-mod classifier;
-mod config;
mod data_type;
-mod encodable_block;
-mod forward_pass;
-pub mod inference;
-mod language_model;
-mod parameters;
mod speculators;
-#[cfg(feature = "tracing")]
-mod tracer;
mod trie;
mod utils;
pub mod backends;
+pub mod inference;
pub mod prelude;
pub mod session;
@@ -30,6 +22,27 @@ pub use config::ConfigDataType;
pub use data_type::{ArrayElement, DataType};
pub use language_model::gumbel::{gumbel_float, revidx};
pub use parameters::{ParameterLoader, read_safetensors_metadata};
-#[cfg(feature = "tracing")]
-pub use tracer::TraceValidator;
pub use utils::{TOOLCHAIN_VERSION, VERSION};
+
+// The following modules are private in production builds, but exposed publicly
+// when the `tracing` feature is enabled so the trace-validation integration
+// test (`tests/integration/tracer/trace_validator.rs`) can reach internal types.
+macro_rules! tracing_visible_mod {
+ ($($name:ident),* $(,)?) => {
+ $(
+ #[cfg(feature = "tracing")]
+ pub mod $name;
+ #[cfg(not(feature = "tracing"))]
+ mod $name;
+ )*
+ };
+}
+
+tracing_visible_mod! {
+ classifier,
+ config,
+ encodable_block,
+ forward_pass,
+ language_model,
+ parameters,
+}
diff --git a/crates/backend-uzu/src/tracer/mod.rs b/crates/backend-uzu/src/tracer/mod.rs
deleted file mode 100644
index 7a85593be..000000000
--- a/crates/backend-uzu/src/tracer/mod.rs
+++ /dev/null
@@ -1,9 +0,0 @@
-//! Unified trace validation for all model types.
-//!
-//! This module provides `TraceValidator` which can validate activation traces
-//! for any model type (LLM or classifier). The model type is automatically
-//! detected from the config.
-
-mod trace_validator;
-
-pub use trace_validator::TraceValidator;
diff --git a/crates/backend-uzu/tests/integration/tracer/mod.rs b/crates/backend-uzu/tests/integration/tracer/mod.rs
index a2ccc7ca3..4db832b5d 100644
--- a/crates/backend-uzu/tests/integration/tracer/mod.rs
+++ b/crates/backend-uzu/tests/integration/tracer/mod.rs
@@ -1 +1,4 @@
+#![cfg(feature = "tracing")]
+
+mod trace_validator;
mod trace_validator_test;
diff --git a/crates/backend-uzu/src/tracer/trace_validator.rs b/crates/backend-uzu/tests/integration/tracer/trace_validator.rs
similarity index 99%
rename from crates/backend-uzu/src/tracer/trace_validator.rs
rename to crates/backend-uzu/tests/integration/tracer/trace_validator.rs
index 1c2755b0e..db5a3341e 100644
--- a/crates/backend-uzu/src/tracer/trace_validator.rs
+++ b/crates/backend-uzu/tests/integration/tracer/trace_validator.rs
@@ -11,13 +11,8 @@ use std::{
rc::Rc,
};
-use half::{bf16, f16};
-use ndarray::{IxDyn, s};
-use num_traits::NumCast;
-
-use crate::{
- ArrayElement, DataType, allocation_to_vec,
- array::Array,
+use backend_uzu::{
+ Array, ArrayElement, DataType, allocation_to_vec,
backends::common::{Allocation, Backend, Encoder, kernel::kv_cache_update::KVCacheUpdate},
classifier::Classifier,
config::{ClassifierModelConfig, LanguageModelConfig, ModelMetadata, ModelType},
@@ -34,6 +29,9 @@ use crate::{
types::Error,
},
};
+use half::{bf16, f16};
+use ndarray::{IxDyn, s};
+use num_traits::NumCast;
// ============================================================================
// Validation Types
@@ -43,6 +41,7 @@ use crate::{
pub struct TracerValidationMetrics {
pub atol: f32,
pub rtol: f32,
+ #[allow(unused)]
pub fraction_of_allowed_violations: f32,
pub reference_shape: Vec<usize>,
pub result_shape: Vec<usize>,
@@ -129,10 +128,6 @@ impl TracerValidationResults {
let threshold: f64 = 0.01;
(self.suffix_length as f64 * threshold).ceil() as usize
}
-
- pub fn is_valid(&self) -> bool {
- self.number_of_tokens_violations() <= self.number_of_allowed_tokens_violations()
- }
}
/// Transform to apply to produced arrays before comparison.
diff --git a/crates/backend-uzu/tests/integration/tracer/trace_validator_test.rs b/crates/backend-uzu/tests/integration/tracer/trace_validator_test.rs
index c3b31a8ad..6983c8d2e 100644
--- a/crates/backend-uzu/tests/integration/tracer/trace_validator_test.rs
+++ b/crates/backend-uzu/tests/integration/tracer/trace_validator_test.rs
@@ -1,10 +1,11 @@
-#![cfg(all(feature = "tracing"))]
+use backend_uzu::backends::common::Backend;
-use backend_uzu::{TraceValidator, backends::common::Backend};
-
-use crate::common::{
- for_each_non_cpu_backend,
- path::{get_test_model_path, get_traces_path},
+use crate::{
+ common::{
+ for_each_non_cpu_backend,
+ path::{get_test_model_path, get_traces_path},
+ },
+ tracer::trace_validator::TraceValidator,
};
fn test_tracer_internal<B: Backend>() {