### Install SNAC-Go Package Source: https://github.com/tcpipuk/snac-go/blob/main/README.md Use 'go get' to install the SNAC-Go library. This command fetches and installs the package and its dependencies. ```bash go get github.com/tcpipuk/snac-go ``` -------------------------------- ### Install Dependencies and Run Conversion Inside Docker Source: https://github.com/tcpipuk/snac-go/blob/main/scripts/README.md Set up a Python 3.13 Docker container, install necessary packages including the SNAC library, and then run the weight conversion script. ```bash docker run --rm -it -v $(pwd):/workspace -w /workspace python:3.13 bash # Inside container: pip install torch numpy git clone https://github.com/hubertsiuzdak/snac tmp/snac cd tmp/snac && pip install -e . && cd ../.. # Run conversion python scripts/convert_weights.py hubertsiuzdak/snac_24khz -o weights/snac_24khz.npz ``` -------------------------------- ### Install Local Python Dependencies Source: https://github.com/tcpipuk/snac-go/blob/main/scripts/README.md Install project dependencies from requirements.txt and set up the local SNAC package for use with the conversion script. ```bash pip install -r scripts/requirements.txt git clone https://github.com/hubertsiuzdak/snac tmp/snac cd tmp/snac && pip install -e . && cd ../.. ``` -------------------------------- ### Install PyTorch and NumPy Source: https://github.com/tcpipuk/snac-go/blob/main/scripts/README.md Install PyTorch and NumPy if they are missing. This addresses the 'No module named 'torch'' error. ```bash pip install torch numpy ``` -------------------------------- ### Install SNAC Package Source: https://github.com/tcpipuk/snac-go/blob/main/scripts/README.md Clone the SNAC repository and install it locally. This is a solution for when the SNAC package is not found. ```bash git clone https://github.com/hubertsiuzdak/snac tmp/snac cd tmp/snac && pip install -e . && cd ../.. ``` -------------------------------- ### Quick Start: Decode SNAC Tokens to Audio Source: https://github.com/tcpipuk/snac-go/blob/main/README.md This Go snippet demonstrates loading the SNAC decoder and decoding tokens into an audio waveform. Ensure 'tokens' is correctly formatted and 'writeWAV' function is available. ```go package main import ( "github.com/tcpipuk/snac-go/snac" "log" ) func main() { // Load SNAC decoder with 24kHz model decoder, err := snac.NewDecoder("hubertsiuzdak/snac_24khz") if err != nil { log.Fatal(err) } // Decode SNAC tokens to audio // tokens is [3][]int representing 3 hierarchical codebook levels audio, err := decoder.Decode(tokens) if err != nil { log.Fatal(err) } // Write to WAV file if err := writeWAV("output.wav", audio, 24000); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Test Mode Validation Output Source: https://github.com/tcpipuk/snac-go/blob/main/scripts/README.md This example shows the expected output when running the conversion script in test mode, demonstrating successful validation without saving. ```bash python scripts/convert_weights.py hubertsiuzdak/snac_24khz --test # Expected output: # Loading model from: hubertsiuzdak/snac_24khz # Extracted 135 parameters: # - Quantizer: 20 # - Decoder: 115 # Validating weights... # ✓ Found 67 weight_g parameters # ✓ All quantizer codebooks present # ✓ Decoder structure valid # ✓ All dtypes are float32 # ✓ Weight normalisation pairs complete # ✓ Test mode: Validation passed, no file saved ``` -------------------------------- ### Run Weight Conversion in Docker (Custom) Source: https://github.com/tcpipuk/snac-go/blob/main/scripts/README.md Execute the Docker wrapper script with custom model and output path arguments. This allows conversion of different models and saving to specified locations. ```bash ./scripts/convert_in_docker.sh hubertsiuzdak/snac_32khz weights/snac_32khz.npz ``` -------------------------------- ### Convert Weights with Verbose Output Source: https://github.com/tcpipuk/snac-go/blob/main/scripts/README.md Execute the weight conversion script with verbose output enabled to see detailed progress and information during the process. Use -o for output path. ```bash python scripts/convert_weights.py hubertsiuzdak/snac_24khz -o weights/snac_24khz.npz --verbose ``` -------------------------------- ### Convert Weights from Local Path Source: https://github.com/tcpipuk/snac-go/blob/main/scripts/README.md Convert model weights from a local directory to a .npz file. Specify the source directory and the desired output file name. ```bash python scripts/convert_weights.py /path/to/local/model -o model.npz ``` -------------------------------- ### Run Conversion Script in Docker Source: https://github.com/tcpipuk/snac-go/blob/main/scripts/README.md Execute the weight conversion script within a Docker container. This is the recommended method on TrueNAS systems. ```bash ./scripts/convert_in_docker.sh ``` -------------------------------- ### Weight Normalization Logic in Go Source: https://github.com/tcpipuk/snac-go/blob/main/scripts/README.md This Go code snippet demonstrates how weight normalization parameters (g and v) are handled. It shows the L2 norm calculation per output channel and the subsequent folding of normalized weights. This approach aids in verifying Python reference logic and debugging numerical differences. ```go // Folded in Go: // w = g * (v / ||v||) v_norm := computeL2Norm(v, axis=0) // Per output channel w := g * (v / (v_norm + 1e-9)) // Broadcast g appropriately ``` -------------------------------- ### Load SNAC Decoder in Go Source: https://github.com/tcpipuk/snac-go/blob/main/scripts/README.md Load a pre-converted SNAC decoder using its weights file in Go. Handles potential errors during loading. ```go import "github.com/tcpipuk/snac-go/snac" // Load decoder with converted weights decoder, err := snac.NewDecoder("weights/snac_24khz.npz") if err != nil { log.Fatal(err) } // Decode tokens to audio audio, err := decoder.Decode(tokens) ``` -------------------------------- ### Regenerate SNAC Test Data with Docker Source: https://github.com/tcpipuk/snac-go/blob/main/snac/testdata/README.md Use this command to regenerate all test data using Docker. Ensure you are in the project root directory. ```bash docker run --rm -v $(pwd):/workspace -w /workspace \ python:3.13 bash -c \ "pip install torch numpy huggingface_hub && \ cd tmp/snac && pip install -e . && cd ../.. && \ python scripts/generate_ground_truth.py" ``` -------------------------------- ### Convert SNAC PyTorch Model to NumPy Source: https://github.com/tcpipuk/snac-go/blob/main/scripts/README.md Convert a SNAC PyTorch model from HuggingFace to a compressed NumPy .npz file. Specify the model name and output file path. ```python python scripts/convert_weights.py hubertsiuzdak/snac_24khz -o weights/snac_24khz.npz ``` -------------------------------- ### Test SNAC Model Conversion Source: https://github.com/tcpipuk/snac-go/blob/main/scripts/README.md Run the weight conversion script in test mode to validate the output structure and completeness without saving the .npz file. ```python python scripts/convert_weights.py hubertsiuzdak/snac_24khz --test ``` -------------------------------- ### Regenerate SNAC Test Data Directly Source: https://github.com/tcpipuk/snac-go/blob/main/snac/testdata/README.md Run this command directly if you have a Python environment available to regenerate test data. ```bash python scripts/generate_ground_truth.py ``` -------------------------------- ### SNAC 24kHz Model Configuration Source: https://github.com/tcpipuk/snac-go/blob/main/docs/architecture.md Configuration parameters for the 24kHz speech-optimised SNAC model. These settings define the model's architecture and capacity. ```json { "sampling_rate": 24000, "encoder_dim": 64, "encoder_rates": [3, 3, 5, 5], "latent_dim": 64, "decoder_dim": 1536, "decoder_rates": [5, 5, 3, 3], "attn_window_size": 32, "codebook_size": 4096, "codebook_dim": 8, "vq_strides": [8, 4, 2, 1] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.