Liquid-Codec / README.md
paulpak58's picture orech's picture
Initial commit
1150afc
|
Raw History Blame Contribute Delete
1.44 kB
metadata
library_name: transformers
license: other
tags:
  - audio
  - audio-codec
  - pytorch
  - bfloat16

Liquid Codec BF16

Remote-code loading

The repository includes the codec configuration and model implementation, so it can be loaded with AutoModel:

import torch
from transformers import AutoModel

codec = AutoModel.from_pretrained(
    "LiquidAI/Liquid-Codec",
    trust_remote_code=True,
    dtype=torch.bfloat16,
    device_map="cuda",
)
waveform = torch.randn(1, 24_000 * 3, device="cuda")  # 24 kHz
codes = codec.encode(waveform).audio_codes
reconstructed = codec.decode(codes).audio_values

Native loading and streaming

import torch
from transformers import LiquidCodecModel, LiquidCodecStreamingCache

codec = LiquidCodecModel.from_pretrained("LiquidAI/Liquid-Codec", dtype=torch.bfloat16, device_map="cuda")

waveform = torch.randn(1, 24_000 * 3, device="cuda")  # 24 kHz
codes = codec.encode(waveform).audio_codes  # (1, 12, 38)
reconstructed = codec.decode(codes).audio_values  # (1, 38 * 1920), float32

# streaming synthesis: every chunk returns the samples that no later frame changes any more
cache = LiquidCodecStreamingCache(codec.config)
chunks = [codec.decode(codes[..., i : i + 1], cache, finalize=False).audio_values for i in range(codes.shape[-1])]
chunks.append(codec.decode(codes[..., :0], cache, finalize=True).audio_values)
streamed = torch.cat(chunks, dim=-1)