Views
No views yet
Input (16kHz) → ConvPre → Interpolate (3x) → AMPBlock0 → ConvPost → Tanh → Output (48kHz)x + (1 - cos(2 * α * x)) / (2 * β + ε)1# Clone the repository
2git clone <repo-url>
3cd novasr-candle
4
5
6# Build the library and CLI
7cargo build --release
8
9# The binary will be at target/release/novasr-cli1uv run --project NovaSR python scripts/convert_weights.py \
2 --input novasr_model.pth \
3 --output models/novasr_v1.safetensors
41# Upsample an audio file using a local model
2./target/release/novasr-cli input.wav output.wav models/novasr_v1.safetensors
3
4# Upsample using a model from Hugging Face Hub
5./target/release/novasr-cli input.wav output.wav babybirdprd/novasr-candle
61use candle_core::{Device, DType};
2use candle_nn::VarBuilder;
3use novasr_candle::{load_model, upsample_audio};
4
5fn main() -> anyhow::Result<()> {
6 let device = Device::Cpu;
7
8 // Load from HF Hub
9 let model = novasr_candle::from_hf("babybirdprd/novasr-candle", "main", &device)?;
10
11 // OR load local
12 // let vb = unsafe { VarBuilder::from_mmaped_safetensors("model.safetensors", DType::F32, &device)? };
13 // let model = load_model(vb)?;
14
15
16 // Process audio
17 let input = candle_core::Tensor::from_vec(
18 audio_samples,
19 (1, 1, sample_count),
20 &device,
21 )?;
22
23 let output = upsample_audio(&model, &input)?;
24
25 Ok(())
26}1pub fn forward(&self, x: &Tensor) -> Result<Tensor> {
2 let a = self.alpha.exp()?;
3 let b = self.beta.exp()?;
4
5 // x + (1 - cos(2 * alpha * x)) / (2 * beta + epsilon)
6 let two_a_x = (x.broadcast_mul(&a)? * 2.0)?;
7 let cos_term = two_a_x.cos()?;
8 let one_minus_cos = (Tensor::ones_like(&cos_term)? - cos_term)?;
9 let inv_2b = ((b * 2.0)? + 1e-9)?.recip()?;
10
11 x.add(&one_minus_cos.broadcast_mul(&inv_2b)?)
12}
13| Property | Value |
|---|---|
| Total Parameters | ~13,000 |
| Model Size | 52 KB |
| Input Sample Rate | 16 kHz |
| Output Sample Rate | 48 kHz |
| Upsampling Factor | 3x |
| Inference Speed | 3600x realtime (A100) |
| Feature | PyTorch (Original) | Candle (This Port) |
|---|---|---|
| Language | Python | Rust |
| Framework | PyTorch | Candle |
| Dependencies | Heavy | Minimal |
| WASM Support | No | Yes |
| Performance | Fast | Comparable |