{"id":2553,"library":"julius","title":"Julius (PyTorch DSP Library)","description":"Julius is a Python library providing fast, differentiable Digital Signal Processing (DSP) algorithms implemented with PyTorch, offering CUDA support. It specializes in functionalities like sinc resampling, FFT-based convolutions, and FIR filter banks for audio and 1D signals. The current version is 0.2.7, with releases addressing compatibility and performance improvements.","status":"active","version":"0.2.7","language":"en","source_language":"en","source_url":"https://github.com/adefossez/julius","tags":["pytorch","dsp","audio","resampling","fft","convolution","cuda","signal-processing"],"install":[{"cmd":"pip install julius","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Julius is built on PyTorch and requires it for all operations.","package":"torch","optional":false}],"imports":[{"symbol":"julius","correct":"import julius"},{"note":"While 'resample_frac' exists in 'julius.resample', the top-level 'julius.resample_frac' is the commonly documented and used entry point for the functional API.","wrong":"from julius.resample import resample_frac","symbol":"resample_frac","correct":"import julius\nsignal = torch.randn(1000)\nresampled_signal = julius.resample_frac(signal, old_sr=44100, new_sr=16000)"},{"note":"Used for class-based resampling, e.g., in torch.nn.Module.","symbol":"ResampleFrac","correct":"from julius.resample import ResampleFrac\nresampler = ResampleFrac(old_sr=44100, new_sr=16000)"},{"note":"Functional API for FFT-based 1D convolution.","symbol":"fft_conv1d","correct":"import julius\nx = torch.randn(1, 1, 1024)\nw = torch.randn(1, 1, 256)\ny = julius.fftconv.fft_conv1d(x, w)"}],"quickstart":{"code":"import julius\nimport torch\n\n# Create a dummy audio signal (batch_size, channels, time)\nsignal = torch.randn(2, 1, 44100) # 2 batches, 1 channel, 44100 samples (1 second at 44.1kHz)\n\nold_sample_rate = 44100\nnew_sample_rate = 16000\n\n# Resample the signal\nresampled_signal = julius.resample_frac(signal, old_sr=old_sample_rate, new_sr=new_sample_rate)\n\nprint(f\"Original signal shape: {signal.shape}\")\nprint(f\"Resampled signal shape: {resampled_signal.shape}\")\n# For FFT-based convolution:\nx = torch.randn(1, 1, 2048) # Input (batch, channels, time)\nw = torch.randn(1, 1, 512) # Kernel (out_channels, in_channels, kernel_size)\ny = julius.fftconv.fft_conv1d(x, w)\nprint(f\"FFT Conv output shape: {y.shape}\")","lang":"python","description":"This quickstart demonstrates the core resampling functionality using `julius.resample_frac` and a basic FFT-based convolution with `julius.fftconv.fft_conv1d`. The resampling function is designed for efficiency when sample rates form a fraction with a small numerator and denominator after GCD reduction."},"warnings":[{"fix":"Be mindful of the ratio between `old_sr` and `new_sr`. For arbitrary ratios where performance is critical, consider pre-filtering or alternative resampling methods if `julius` is slow in specific cases.","message":"The `resample_frac` function is highly optimized for fractional changes in sample rates where the `old_sr` and `new_sr` reduce to a small irreducible fraction (e.g., 2000 to 3000 simplifies to 2:3). Performance can degrade significantly if the sample rates do not simplify to small integers (e.g., 20001 to 30001).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Benchmark both `julius.fftconv` and `torch.nn.functional.conv1d` for your specific use case to determine the faster option. Avoid `julius.fftconv` if dilation or groups are required.","message":"The `julius.fftconv` modules (e.g., `FFTConv1d`, `fft_conv1d`) are optimized for convolutions with *large kernels* (typically >= 128) and a stride of 1. For smaller kernels or different strides, `torch.nn.Conv1d` might be faster or more memory efficient. Dilation and groups are not supported by `julius.fftconv`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Evaluate `torchaudio.functional.resample` as an alternative to `julius.resample_frac` for new projects or if migrating existing `torchaudio` pipelines.","message":"As of January 2021, the `julius` implementation of resampling has been officially integrated into `torchaudio`. Users primarily focused on resampling may consider using `torchaudio.functional.resample` for potentially more robust or integrated solutions within the PyTorch ecosystem.","severity":"deprecated","affected_versions":"0.2.2+"},{"fix":"If migrating from versions prior to 0.2.2, re-evaluate output consistency, particularly for edge artifacts or filter characteristics, and adjust parameters like `rolloff` or `zeros` if necessary.","message":"Version 0.2.2 (released January 2021) introduced changes to filter normalization in `lowpass` and `resample` and switched from zero padding to replicate padding. This could subtly alter output signals, especially at the edges or for very low frequencies, compared to previous versions.","severity":"breaking","affected_versions":"Pre-0.2.2 to 0.2.2+"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}