fix(gaps): G4 — re-enable all rtx-transformers Phase 2/3 modules (222 compile errors fixed)
Uncommented all deferred modules in lib.rs and fixed API drift across ~60 files in 9 module groups: continual, curriculum, meta, modular, neural_ode, graph, kan, perceiver, distributed/pipeline_parallelism. Common patterns fixed across modules: - Tensor::randn/zeros/ones([a,b]) → (&[a,b], device)? (slice + Result) - Result<T, TensorError> → .map_err(Into::into)? in TransformerError contexts - Device by value → &device references - &Tensor where Tensor expected → .clone() - tensor.relu()/tanh()/sigmoid() as methods not ops functions - Tensor arithmetic returning Result: (a + b)? → (a.clone() + b)? - shape literals → shape.dims() for Shape type - sum(n) → sum(Some(n)), mean(None) → mean(&[], false) - i64 indices → usize where required - backward(x) → backward(x, None) - Borrow conflicts on self.field resolved by extracting to locals before mut borrow - BatchingStats private fields → pub(crate) - TransformerError::Serialization → ::SerializationError - Add scalar to tensor: (t + 0.1)? → t.add_scalar(0.1)? Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
448c0a0be5
commit
a08adfbf57
@@ -104,6 +104,12 @@ pub enum KANError {
|
||||
|
||||
#[error("Autograd integration error: {msg}")]
|
||||
AutogradIntegration { msg: String },
|
||||
|
||||
#[error("Invalid input: {0}")]
|
||||
InvalidInput(String),
|
||||
|
||||
#[error("Tensor error: {0}")]
|
||||
TensorError(#[from] rtx_tensor::TensorError),
|
||||
}
|
||||
|
||||
impl From<KANError> for TransformerError {
|
||||
@@ -125,30 +131,35 @@ pub mod utils {
|
||||
"Grid size must be at least 2".to_string()
|
||||
));
|
||||
}
|
||||
|
||||
Tensor::linspace(min, max, size, device)
|
||||
.map_err(|e| TransformerError::TensorError(e))
|
||||
|
||||
let values: Vec<f32> = (0..size)
|
||||
.map(|i| (min + (max - min) * i as f64 / (size - 1) as f64) as f32)
|
||||
.collect();
|
||||
Tensor::from_slice(&values, &[size], device)
|
||||
.map_err(TransformerError::TensorError)
|
||||
}
|
||||
|
||||
/// Compute complexity measure for grid adaptation
|
||||
pub fn compute_complexity_measure(values: &Tensor) -> Result<f64> {
|
||||
// Use second derivative as complexity measure
|
||||
if values.dim() < 1 {
|
||||
let ndim = values.dims().len();
|
||||
if ndim < 1 {
|
||||
return Ok(0.0);
|
||||
}
|
||||
|
||||
let n = values.shape().dims()[values.dim() - 1];
|
||||
|
||||
let last_dim = ndim - 1;
|
||||
let n = values.dims()[last_dim];
|
||||
if n < 3 {
|
||||
return Ok(0.0);
|
||||
}
|
||||
|
||||
|
||||
// Approximate second derivative using finite differences
|
||||
let second_deriv = values.narrow(values.dim() - 1, 2, n - 2)?
|
||||
.sub(&values.narrow(values.dim() - 1, 1, n - 2)?.mul_scalar(2.0)?)?
|
||||
.add(&values.narrow(values.dim() - 1, 0, n - 2)?)?;
|
||||
|
||||
let complexity = second_deriv.abs()?.mean(None, false)?;
|
||||
Ok(complexity.get_item([])?)
|
||||
let second_deriv = values.narrow(last_dim, 2, n - 2)?
|
||||
.sub(&values.narrow(last_dim, 1, n - 2)?.mul_scalar(2.0)?)?
|
||||
.add(&values.narrow(last_dim, 0, n - 2)?)?;
|
||||
|
||||
let complexity = second_deriv.abs()?.mean(&[0i32], false)?.to_scalar::<f32>()?;
|
||||
Ok(complexity as f64)
|
||||
}
|
||||
|
||||
/// Check if a function is approximately linear
|
||||
|
||||
Reference in New Issue
Block a user