Document split checkpoint API and private development code
Browse files
README.md
CHANGED
|
@@ -8,60 +8,88 @@ tags:
|
|
| 8 |
|
| 9 |
# HeartCodec OSS Encoder
|
| 10 |
|
| 11 |
-
Encoder-only weights for HeartCodec audio
|
| 12 |
-
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
- `encoder_config.json`: configuration for the encoder module.
|
| 19 |
-
- `SHA256SUMS`: SHA-256 checksum of the weight file.
|
| 20 |
-
- `LICENSE`: license supplied with the source checkpoint.
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
[`mula-labs/heartlib_codec`](https://github.com/mula-labs/heartlib_codec),
|
| 29 |
-
at revision `306b163fe2ab777fb16ba973fe2c25f39cb428f5` (access may be required).
|
| 30 |
-
The main `HeartMuLa/heartlib` implementation may not contain these encoder
|
| 31 |
-
classes. With the encoder-enabled implementation installed, load the component:
|
| 32 |
|
| 33 |
```python
|
| 34 |
-
import
|
| 35 |
-
from
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
)
|
| 48 |
-
encoder.eval()
|
| 49 |
```
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
This does not constitute an audio-inference or reconstruction-quality test.
|
| 64 |
|
| 65 |
## License
|
| 66 |
|
| 67 |
-
|
|
|
|
| 8 |
|
| 9 |
# HeartCodec OSS Encoder
|
| 10 |
|
| 11 |
+
Encoder-only weights for HeartCodec audio tokenization. Pair this checkpoint
|
| 12 |
+
with [HeartCodec-oss-20260123](https://huggingface.co/HeartMuLa/HeartCodec-oss-20260123),
|
| 13 |
+
which supplies the shared RVQ quantizer and audio decoder. Together they support
|
| 14 |
+
audio → eight token streams at 12.5 Hz → 48 kHz stereo reconstruction.
|
| 15 |
|
| 16 |
+
This repository is a private development preview. The matching code is in
|
| 17 |
+
[HeartMuLa/heartlib-codec-dev](https://github.com/HeartMuLa/heartlib-codec-dev);
|
| 18 |
+
access to both repositories is required. The encoder loading API has not yet
|
| 19 |
+
been merged into the public `HeartMuLa/heartlib` repository.
|
| 20 |
|
| 21 |
+
## Installation and reconstruction
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
Use Python 3.10, a CUDA-compatible PyTorch installation, and `ffmpeg` for MP3
|
| 24 |
+
output. Install this development copy of `heartlib` in a separate environment;
|
| 25 |
+
do not install both the public and development copies into one environment.
|
| 26 |
|
| 27 |
+
```bash
|
| 28 |
+
git clone https://github.com/HeartMuLa/heartlib-codec-dev.git
|
| 29 |
+
cd heartlib-codec-dev
|
| 30 |
+
pip install -e .
|
| 31 |
+
hf auth login
|
| 32 |
+
hf download HeartMuLa/HeartCodec-oss-encoder --local-dir ./ckpt/HeartCodec-oss-encoder
|
| 33 |
+
hf download HeartMuLa/HeartCodec-oss-20260123 --local-dir ./ckpt/HeartCodec-oss-20260123
|
| 34 |
+
python examples/run_music_reconstruction.py \
|
| 35 |
+
--encoder_path ./ckpt/HeartCodec-oss-encoder \
|
| 36 |
+
--decoder_path ./ckpt/HeartCodec-oss-20260123 \
|
| 37 |
+
--input_path /path/to/your/audio.mp3 \
|
| 38 |
+
--save_path ./reconstructed.mp3
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
Use authorized input audio. MP3 is encoded directly from float32 output at
|
| 42 |
+
320 kbps, without an intermediate PCM WAV. WAV output is available by selecting
|
| 43 |
+
a `.wav` output path. Output is trimmed to the input duration.
|
| 44 |
|
| 45 |
+
## Python API
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
```python
|
| 48 |
+
import torch
|
| 49 |
+
from heartlib.heartcodec.modeling_heartcodec import HeartCodec
|
| 50 |
+
|
| 51 |
+
codec = HeartCodec.from_encoder_decoder_pretrained(
|
| 52 |
+
"HeartMuLa/HeartCodec-oss-20260123",
|
| 53 |
+
"HeartMuLa/HeartCodec-oss-encoder",
|
| 54 |
+
dtype=torch.float32,
|
| 55 |
+
).to("cuda").eval()
|
| 56 |
+
|
| 57 |
+
# waveform: float32 tensor [samples], [1, samples], or [2, samples]
|
| 58 |
+
# sample_rate: positive integer sampling rate of the input waveform
|
| 59 |
+
# tokens = codec.tokenize(waveform, sample_rate, batch_size=1)
|
| 60 |
+
# reconstructed = codec.detokenize(tokens, num_steps=10, guidance_scale=1.25)
|
|
|
|
|
|
|
| 61 |
```
|
| 62 |
|
| 63 |
+
Do not pass this encoder-only repository to `HeartCodec.from_pretrained()`.
|
| 64 |
+
The existing decoder-only loading API remains supported. Encoder and decoder
|
| 65 |
+
weights are strictly checked by the split-checkpoint loader.
|
| 66 |
+
|
| 67 |
+
## Files
|
| 68 |
+
|
| 69 |
+
- `encoder.safetensors`: 1,006 encoder tensors, approximately 2.15 GB;
|
| 70 |
+
original `encoder.*` names, shapes, dtypes and values are preserved.
|
| 71 |
+
- `encoder_config.json`: feature extractor and query encoder configuration.
|
| 72 |
+
- `SHA256SUMS`: weight-file SHA-256 checksum.
|
| 73 |
+
- `LICENSE`: the source checkpoint's Apache-2.0 license.
|
| 74 |
+
|
| 75 |
+
No decoder or RVQ weights are included here. The shared quantizer belongs to
|
| 76 |
+
the paired decoder checkpoint; loading two independently trained quantizers
|
| 77 |
+
is not supported.
|
| 78 |
+
|
| 79 |
+
## Validation
|
| 80 |
|
| 81 |
+
On an NVIDIA B300, the split encoder and published decoder completed a
|
| 82 |
+
239.293-second stereo audio round trip using FP32, batch size 1, seed 42,
|
| 83 |
+
10 decoder steps and guidance scale 1.25. Tokens had shape `[8, 2992]`.
|
| 84 |
+
Output was finite, non-silent, 48 kHz stereo and matched the input duration.
|
| 85 |
+
PyTorch peak allocated memory was approximately 12.65 GiB; peak reserved
|
| 86 |
+
memory was approximately 15.41 GiB. These are measurements for one input and
|
| 87 |
+
configuration, not minimum-memory requirements or an audio-quality benchmark.
|
| 88 |
|
| 89 |
+
All exported encoder tensor bytes match the source checkpoint. The paired
|
| 90 |
+
decoder's 818 tensors match the source decoder numerically; eight RVQ
|
| 91 |
+
initialization flags differ only in stored shape (scalar versus `[1]`).
|
|
|
|
| 92 |
|
| 93 |
## License
|
| 94 |
|
| 95 |
+
Apache-2.0, as declared by the source checkpoint. See `LICENSE`.
|