Neural Amp Modeler (NAM)

repository·main·Indexed 25 days ago

https://github.com/sdatkinson/neural-amp-modeler

A framework for training neural network models of audio amplifiers and exporting them to the specialized .nam file format. It includes tools for local training via the nam-full command, cloud training via Google Colab, and a detailed .nam file specification for storing model architecture, weights, and hardware calibration metadata.

Tokens
5.4K
Snippets
10
Records
33
Agent score
84%

What's inside neural-amp-modeler

  1. Overview of Neural Amp Modeler (NAM)

    main

    Neural Amp Modeler (NAM) is a toolset used for training neural network models of amplifiers and exporting them into the .nam file format.

    Note that this repository is specifically for the training and exporting workflow. If you want to play trained models in real time via a standalone application or plugin, you should use the NeuralAmpModelerPlugin repository instead.

  2. Update calibration metadata in .nam files

    main

    Since .nam files are JSON-formatted, you can manually add or update calibration metadata using a text editor.

    To update an existing model:

    1. Create a new model that already has calibration data to use as a reference.
    2. Open your old .nam file in a text editor.
    3. Locate or add the following keys in the metadata section:
      • "input_level_dbu"
      • "output_level_dbu"
    4. Enter the calculated dBu values. If you only know one value, you can set the other to null.

    Warning: Always create a backup of your .nam file before editing.

  3. Use Slimmable WaveNet models for dynamic scaling

    main

    The nam/models/wavenet module implements a slimmable class hierarchy that allows for dynamic adjustment of model size during inference or training. The top-level _WaveNet model manages an adjustment ratio (between 0 and 1) and propagates this scaling to its child modules using adjust_to() and adjust_to_random() methods.

    Key scaling methods available via the _Slimmable mixin:

    • adjust_to(ratio): Sets the model to a specific size ratio.
    • adjust_to_random(): Sets the model to a random size ratio.
    • context_adjust_to_random(): Adjusts size within a specific context.
  4. Prepare reamping data for NAM training

    main

    To train a model, you need an input file (the standardized test signal) and an output file (the reamped signal from your gear).

    Requirements

    • The exported output file must be the exact same length as the input file.
    • Using standardized input files (which are an exact number of seconds long) and a DAW session at 120 BPM can help ensure correct length by snapping guides to the beat.

    Quickstart Data (Optional)

    If you want to skip reamping for your first model, you can use these pre-made files:

    Uploading to Colab

    1. Click the Folder icon in the Colab sidebar.
    2. Drag and drop your files or use the upload button.
    3. CRITICAL: Wait for the files to finish uploading completely before proceeding to training to avoid errors.
  5. Measure the analog send level (dBu)

    main

    To find the analog voltage of your reamping send:

    1. Set up your reamping gear and ensure the interface output is at its maximum value.
    2. Play a 1kHz sine wave at 0dBFS peak amplitude.
    3. Unplug the cable from the gear being reamped.
    4. Use a multimeter to measure the RMS voltage across the jack's tip and sleeve.
    5. Convert the measured RMS voltage to dBu using the formula:

    $$\text{dBu} = 20 \times \log_{10}\left(\frac{V_{\text{RMS}}}{0.7746}\right)$$

    Example: 6.40 V RMS $\approx$ 18.3 dBu.

  6. Configure Packed WaveNet training

    main

    Packed training allows training multiple compatible WaveNet submodels within a single larger masked WaveNet. This is useful for creating a single .nam file containing several WaveNet sizes that share the same temporal architecture but use different channel counts.

    To use packed training, set the name in your model configuration to "PackedWaveNet" and run the nam-full command. No special CLI flags are required; the trainer automatically selects the PackedLightningModule based on the config.

    Configuration Requirements:

    • The submodels list contains individual WaveNet configurations.
    • Temporal settings (e.g., kernel_size, dilations, activation) must match across all submodels.
    • Channel counts (e.g., channels) can differ between submodels.
    • Use export.container_max_values to control the max_value thresholds in the exported SlimmableContainer. Options include "uniform" or a sorted list of values (one per submodel).
    {
      "net": {
        "name": "PackedWaveNet",
        "config": {
          "submodels": [
            {
              "name": "small",
              "config": {
                "layers_configs": [
                  {
                    "input_size": 1,
                    "condition_size": 1,
                    "channels": 3,
                    "head": {"out_channels": 1, "kernel_size": 1, "bias": true},
                    "kernel_size": 6,
                    "dilations": [1, 5, 29, 97, 227],
                    "activation": "LeakyReLU"
                  }
                ],
                "head": null,
                "head_scale": 0.01
              }
            },
            {
              "name": "large",
              "config": {
                "layers_configs": [
                  {
                    "input_size": 1,
                    "condition_size": 1,
                    "channels": 8,
                    "head": {"out_channels": 1, "kernel_size": 1, "bias": true},
                    "kernel_size": 6,
                    "dilations": [1, 5, 29, 97, 227],
                    "activation": "LeakyReLU"
                  }
                ],
                "head": null,
                "head_scale": 0.01
              }
            }
          ],
          "export": {
            "container_max_values": "uniform"
          }
        }
      }
    }
  7. Determine calibration levels for NAM models

    main

    To ensure accurate gain staging between digital models and analog source gear, you can define calibration levels in the NAM metadata. This involves measuring the relationship between the digital signal strength (dBFS) and the analog signal strength (dBu).

    As of version 0.10.0, the NAM file specification supports two metadata fields:

    • input_level_dbu: The analog signal strength (in dBu) that corresponds to the loudest digital signal.
    • output_level_dbu: The analog signal strength (in dBu) that corresponds to the loudest digital output.

    Providing these levels is optional. If omitted, models will still function, but gain staging may not accurately reflect the original analog hardware behavior.

  8. Configure model architecture and learning parameters

    main

    Training requires two additional configuration files:

    1. Model Architecture: Define the model structure (e.g., WaveNet) by copying a file from nam_full_configs/models/ (e.g., wavenet.json or wavenet_packed.json) to your desired filename (e.g., model.json).
    2. Learning Algorithm: Define the training details by copying a file from nam_full_configs/learning/ to your desired filename (e.g., learning.json).
      • Use demo.json for a quick test run.
      • Use default.json for standard use cases.
      • Note: Many PyTorch Lightning configuration options can be controlled via the default.json file.
  9. Set up a local development environment for NAM

    main
    If you intend to contribute to or develop the neural-amp-modeler package, use the Anaconda environment definitions located in the environments/ directory. For testing parity with GitHub Actions, refer to .github/workflows/python-pckage.yml to ensure your local environment matches the automated testing configuration.