HeartMuLa commited on
Commit
9d0a8a5
·
verified ·
1 Parent(s): b2b7452

Document split checkpoint API and private development code

Browse files
Files changed (1) hide show
  1. README.md +71 -43
README.md CHANGED
@@ -8,60 +8,88 @@ tags:
8
 
9
  # HeartCodec OSS Encoder
10
 
11
- Encoder-only weights for HeartCodec audio encoding. This package contains the
12
- audio feature extractors and query encoder, with original `encoder.*` tensor
13
- names preserved. It does **not** include decoder or RVQ quantizer weights.
 
14
 
15
- ## Contents
 
 
 
16
 
17
- - `encoder.safetensors`: 1,006 encoder tensors (approximately 2.15 GB).
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
- ## Dependencies and loading
 
 
23
 
24
- This is a component checkpoint, not a standalone Transformers model. Do not
25
- load this repository directly with `HeartCodec.from_pretrained()`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- The encoder implementation is available in
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 json
35
- from pathlib import Path
36
- from huggingface_hub import snapshot_download
37
- from safetensors.torch import load_file
38
- from heartlib.heartcodec.models.encoder import HeartCodecEncoder
39
-
40
- root = Path(snapshot_download("HeartMuLa/HeartCodec-oss-encoder"))
41
- config = json.loads((root / "encoder_config.json").read_text())
42
- encoder = HeartCodecEncoder(config)
43
- weights = load_file(str(root / "encoder.safetensors"), device="cpu")
44
- encoder.load_state_dict(
45
- {key.removeprefix("encoder."): value for key, value in weights.items()},
46
- strict=True,
47
- )
48
- encoder.eval()
49
  ```
50
 
51
- Producing discrete tokens additionally requires the matching shared RVQ
52
- quantizer, passed to `encoder.tokenize(waveform, sample_rate, quantizer)`.
53
- Audio reconstruction also requires the decoder. The existing decoder release is
54
- [`HeartMuLa/HeartCodec-oss-20260123`](https://huggingface.co/HeartMuLa/HeartCodec-oss-20260123).
55
- No decoder or quantizer weights are duplicated here. End-to-end compatibility
56
- with that separate release has not yet been validated for this split package.
 
 
 
 
 
 
 
 
 
 
 
57
 
58
- ## Validation status
 
 
 
 
 
 
59
 
60
- The split preserves the source tensor names, dtypes, shapes, and raw tensor bytes.
61
- All 1,006 exported keys start with `encoder.`; no decoder or RVQ tensors are
62
- included. File structure and payload integrity are checked during extraction.
63
- This does not constitute an audio-inference or reconstruction-quality test.
64
 
65
  ## License
66
 
67
- The source checkpoint declares Apache-2.0; its license is retained in `LICENSE`.
 
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`.