LSCodec-25 Hz β packed int8 weights
Int8 post-training quantization of cantabile-kwok/lscodec_25hz
(encoder + vocoder + VQ codebook, 49.3 MB instead of 196.0 MB fp32), produced with the
same quantizer the quantization lab Space
uses for its lscodec-int8 row.
| File | Contents | Size |
|---|---|---|
encoder.safetensors |
LSCodec encoder (conv frontend, conformer, quantizer) | 17.6 MB |
vocoder.safetensors |
CTXVEC2WAV vocoder | 31.6 MB |
codebook.safetensors |
1024-entry, 64-dim VQ codebook | 0.07 MB |
Method: per-output-channel absmax scale (per-tensor for 1-D params), round-to-nearest
into signed int8, stored as int8 levels plus an fp32 _scale/<name> tensor per parameter.
Dequantizing reproduces the lab's lscodec-int8 model bit-for-bit; integer buffers
(num_batches_tracked) are stored unchanged.
Unchanged: the token stream is still 25 tokens/s Γ 10 bits = 0.25 kbps, and the
WavLM-Large prompt encoder (microsoft/wavlm-large,
first 6 layers) is neither included here nor quantized β it only embeds the prompt.
Measured on a 3 s LibriSpeech clip: STOI 0.694 / LSD 11.10 dB at int8 versus 0.725 / 11.18 dB at fp32 (fetched by the lab Space).
Native int8 β no dequantization
int8nn.py (shipped in this repo) swaps every Linear/Conv1d/ConvTranspose1d/Embedding for
an int8 twin: weights stay int8 in memory, each GEMM quantizes its activations per row and
computes int8 x int8 -> int32 via torch._int_mm (W8A8 dynamic). Measured natively:
STOI 0.704 versus 0.694 through the dequantized fake-quant path (0.725 at fp32).
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
import int8nn # from this repo
for module, name in ((encoder, "encoder"), (vocoder, "vocoder"), (codebook, "codebook")):
packed = load_file(hf_hub_download("ALWOAL/lscodec_25hz_int8", f"{name}.safetensors", repo_type="model"))
int8nn.apply_int8(module, packed)
Load
Requires the LSCodec-Inference repo to build the modules:
from huggingface_hub import hf_hub_download
from lscodec.utils import load_model, load_vocoder # X-LANCE/LSCodec-Inference
from safetensors.torch import load_file
def dequantize(path: str) -> dict:
raw = load_file(path)
return {
k: (v.float() if (s := raw.get("_scale/" + k)) is None else v.float() * s)
for k, v in raw.items() if not k.startswith("_scale/")
}
encoder = load_model(encoder_config, encoder_ckpt)
vocoder = load_vocoder(vocoder_config, vocoder_ckpt)
for module, name in ((encoder, "encoder"), (vocoder, "vocoder"), (codebook, "codebook")):
path = hf_hub_download("ALWOAL/lscodec_25hz_int8", f"{name}.safetensors", repo_type="model")
module.load_state_dict(dequantize(path))
Credits
LSCodec by Yiwei Guo et al. β MIT, X-LANCE/LSCodec-Inference. Quantization method and numbers from the FocalCodec quantization lab.
Model tree for ALWOAL/lscodec_25hz_int8
Base model
cantabile-kwok/lscodec_25hz