junhyeok lee commited on
Commit
24910ef
·
0 Parent(s):

JHCodec-1.4M checkpoint and model card

Browse files
Files changed (4) hide show
  1. .gitattributes +35 -0
  2. README.md +147 -0
  3. config.json +139 -0
  4. jhcodec_mimi_1400000.pt +3 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ pipeline_tag: audio-to-audio
4
+ tags:
5
+ - audio
6
+ - audio-codec
7
+ - speech
8
+ - representation-learning
9
+ ---
10
+
11
+ # Model Card for JHCodec
12
+
13
+ JHCodec is a pure Transformer decoder-based neural audio codec with residual vector quantization (RVQ). It achieves state-of-the-art performance with minimal latency and high intelligibility through self-supervised representation reconstruction (SSRR) loss.
14
+
15
+ - **Paper:** [Reconstruct! Don't Encode: Self-Supervised Representation Reconstruction Loss for High-Intelligibility and Low-Latency Streaming Neural Audio Codec](https://huggingface.co/papers/2603.05887)
16
+ - **GitHub Repository:** [https://github.com/jhcodec843/jhcodec](https://github.com/jhcodec843/jhcodec)
17
+ - **Demo:** [https://jhcodec843.github.io/jhcodec/](https://jhcodec843.github.io/jhcodec/)
18
+ - **License:** MIT
19
+
20
+ ## Model Details
21
+
22
+ This checkpoint corresponds to the **JHCodec-1.4M** model variant (`jhcodec_mimi_1400000.pt`). JHCodec uses a self-supervised representation reconstruction loss to improve codec training, enhancing intelligibility by reconstructing distilled self-supervised representations from codec outputs. It features a zero-lookahead architecture designed for real-time streaming deployment.
23
+
24
+ The model operates on 16 kHz mono audio in frames of `FRAME_SIZE = 320` samples (20 ms), so the input length must be a multiple of 320.
25
+
26
+ ### Requirements
27
+
28
+ - Python >= 3.10
29
+ - PyTorch/TorchAudio with CUDA support (tested with `torch==2.6.0+cu124` and `torch==2.9.1+cu128`)
30
+ - [omegaconf==2.3.0](https://omegaconf.readthedocs.io/en/2.3_branch/)
31
+ - [Flash-Attention](https://github.com/Dao-AILab/flash-attention) (required for the reported performance; tested with `flash-attn==2.7.4.post1` and `flash-attn==2.8.3`)
32
+ - [huggingface_hub](https://huggingface.co/docs/huggingface_hub/index) — only if you auto-download the official checkpoint
33
+
34
+ **Note: Running on CPU currently leads to degraded reconstruction quality.**
35
+
36
+ ## Usage
37
+
38
+ ### Inference via CLI
39
+
40
+ Download this checkpoint and point `--checkpoint` at it (`--from_hf` fetches the 1M
41
+ variant from `jhcodec/jhcodec`):
42
+
43
+ ```bash
44
+ python jhcodec/inference.py \
45
+ --config config/config_mimi_recon.json \
46
+ --checkpoint jhcodec_mimi_1400000.pt \
47
+ --input_file /path/to/input.wav \
48
+ --output_file /path/to/output.wav \
49
+ --num_codebooks 8 \
50
+ --device 'cuda'
51
+ ```
52
+
53
+ ### Use in Python (offline, whole utterance at once)
54
+
55
+ ```python
56
+ import torch
57
+ import torch.nn.functional as F
58
+ import torchaudio
59
+ from jhcodec.utils import load_pretrained_jhcodec
60
+
61
+ DEVICE = 'cuda'
62
+ SAMPLE_RATE = 16000
63
+ FRAME_SIZE = 320 # 20 ms hop; input length must be a multiple of this
64
+ NUM_CODEBOOKS = 8 # <= config.model.rvq.num_codebooks
65
+
66
+ codec = load_pretrained_jhcodec(repo_id='jhcodec/jhcodec_1.4m').to(DEVICE).eval()
67
+
68
+ x, sr = torchaudio.load('input.wav')
69
+ if sr != SAMPLE_RATE:
70
+ x = torchaudio.transforms.Resample(sr, SAMPLE_RATE)(x)
71
+ x = x[0, :].view(1, -1).to(DEVICE) # [1, T], mono
72
+ if x.shape[1] % FRAME_SIZE != 0:
73
+ x = F.pad(x, (0, FRAME_SIZE - x.shape[1] % FRAME_SIZE))
74
+
75
+ # encode/decode are already decorated with @torch.no_grad()
76
+ n_codebooks = torch.tensor([NUM_CODEBOOKS], device=DEVICE)
77
+ indices, _ = codec.encode(x, n_codebooks, inference_cache=None) # [1, T//320, NUM_CODEBOOKS]
78
+ decoded, _ = codec.decode(indices, n_codebooks, inference_cache=None) # [1, T]
79
+
80
+ torchaudio.save('output.wav', decoded.detach().cpu(), SAMPLE_RATE)
81
+ ```
82
+
83
+ ### Use in Python (streaming, frame by frame)
84
+
85
+ Pass the returned `inference_cache` back in on every call. The encoder and the decoder each keep their own cache, so use two separate variables and start both at `None`.
86
+
87
+ ```python
88
+ encoder_cache = None
89
+ indices = []
90
+ for i in range(0, x.shape[1], FRAME_SIZE):
91
+ frame_indices, encoder_cache = codec.encode(
92
+ x[:, i:i + FRAME_SIZE], n_codebooks, inference_cache=encoder_cache)
93
+ indices.append(frame_indices) # each [1, 1, NUM_CODEBOOKS]
94
+
95
+ decoder_cache = None
96
+ chunks = []
97
+ for frame_indices in indices:
98
+ audio_chunk, decoder_cache = codec.decode(
99
+ frame_indices, n_codebooks, inference_cache=decoder_cache)
100
+ chunks.append(audio_chunk) # each [1, 320]
101
+ decoded = torch.cat(chunks, dim=1) # [1, T]
102
+ ```
103
+
104
+ To load a local checkpoint instead of the Hugging Face one:
105
+
106
+ ```python
107
+ import omegaconf
108
+ import jhcodec.utils as utils
109
+ from jhcodec.model.codec import JHCodecMimi
110
+
111
+ config = omegaconf.OmegaConf.load('config/config_mimi_recon.json')
112
+ codec = JHCodecMimi(config.model, training=False)
113
+ utils.load_checkpoint(codec, None, None, 'jhcodec_mimi_1400000.pt', strict_model=True)
114
+ codec = codec.to(DEVICE).eval()
115
+ ```
116
+
117
+ For CUDA-graph per-frame streaming (`JHCodecMimiCudaGraph`, whose `state_dict` is identical to `JHCodecMimi`), see the [GitHub repository README](https://github.com/jhcodec843/jhcodec).
118
+
119
+ ## Intended Use
120
+
121
+ - Real-time low-latency audio codecs for speech-to-speech models
122
+ - Research into neural codecs and generative modeling
123
+ - Serving as a neural front-end for speech recognition or synthesis pipelines
124
+ - Compressing large audio datasets
125
+
126
+ ### Out-of-Scope Use
127
+
128
+ - Any malicious, deceptive, or privacy-violating applications
129
+
130
+ ## Training Details
131
+
132
+ Please refer to the GitHub repository README.
133
+
134
+ ## Citation
135
+
136
+ ```bibtex
137
+ @article{jhcodec2026,
138
+ title={Reconstruct! Don't Encode: Self-Supervised Representation Reconstruction Loss for High-Intelligibility and Low-Latency Streaming Neural Audio Codec},
139
+ author={Anonymous},
140
+ journal={arXiv preprint arXiv:2603.05887},
141
+ year={2026}
142
+ }
143
+ ```
144
+
145
+ ## Authors
146
+
147
+ Anonymous, Submitted to Interspeech 2026
config.json ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model": {
3
+ "mlp_in":{
4
+ "in_features": 320,
5
+ "hidden_features": 768,
6
+ "out_features": 1024,
7
+ "compute_dtype": "float32"
8
+ },
9
+ "mlp_out":{
10
+ "in_features": 1024,
11
+ "hidden_features": 768,
12
+ "out_features": 320,
13
+ "compute_dtype": "float32"
14
+ },
15
+ "decoder": {
16
+ "n_layers": 8,
17
+ "n_embd": 1024,
18
+ "n_hidden": 4096,
19
+ "n_heads": 16,
20
+ "head_dim": 64,
21
+ "compute_dtype": "float32",
22
+ "window_size": 15,
23
+ "dropout_rate": 0.1,
24
+ "drop_path_rate": 0.1
25
+ },
26
+ "encoder": {
27
+ "n_layers": 8,
28
+ "n_embd": 1024,
29
+ "n_hidden": 4096,
30
+ "n_heads": 16,
31
+ "head_dim": 64,
32
+ "compute_dtype": "float32",
33
+ "window_size": 15,
34
+ "dropout_rate": 0.1,
35
+ "drop_path_rate": 0.1
36
+ },
37
+ "rvq": {
38
+ "type": "mimi",
39
+ "num_codebooks": 8,
40
+ "codebook_size": 1024,
41
+ "embedding_dim": 1024,
42
+ "latent_dim": 16,
43
+ "updown_linears": true,
44
+ "codebook_weight_dtype": "float32"
45
+ },
46
+ "training": {
47
+ "quantizer_dropout": 0.5,
48
+ "encoder_mask_rate": 0.1,
49
+ "decoder_mask_rate": 0.1,
50
+ "noise_augmentation": 0.1
51
+ }
52
+ },
53
+ "w2v":{
54
+ "mlp_in":{
55
+ "in_features": 320,
56
+ "hidden_features": 768,
57
+ "out_features": 1024,
58
+ "compute_dtype": "float32"
59
+ },
60
+ "encoder": {
61
+ "n_layers": 8,
62
+ "n_embd": 1024,
63
+ "n_hidden": 4096,
64
+ "n_heads": 16,
65
+ "head_dim": 64,
66
+ "compute_dtype": "float32",
67
+ "window_size": 15,
68
+ "dropout_rate": 0.1
69
+ },
70
+ "rvq": {
71
+ "num_codebooks": 8,
72
+ "codebook_size": 1024,
73
+ "embedding_dim": 1024,
74
+ "latent_dim": 1024,
75
+ "updown_linears": false,
76
+ "codebook_weight_dtype": "float32"
77
+ },
78
+ "training": {
79
+ "noise_masking": 0.1
80
+ }
81
+ },
82
+ "training":{
83
+ "resume": false,
84
+ "loss_type": "l1",
85
+ "strict_model": false,
86
+ "load_discriminator": true,
87
+ "learning_rate": 1e-4,
88
+ "weight_decay": 1e-2,
89
+ "discriminator_start_steps": 10000,
90
+ "discriminator_segment_duration": 2.56,
91
+ "masking_stop_steps": 100000,
92
+ "apply_apa": false,
93
+ "warmup_steps": 1000,
94
+ "min_lr": 1e-6,
95
+ "num_epochs": 100,
96
+ "use_continuous": 0.1,
97
+ "max_grad_norm": 1000.0,
98
+ "batch_size": 42,
99
+ "gradient_accumulation_steps": 1,
100
+ "num_workers": 4,
101
+ "use_phaseaug": true,
102
+ "init_dataset": false,
103
+ "profile": false,
104
+ "verbose_grad_norm": false,
105
+ "verbose_norm_threshold_max": 5.0,
106
+ "verbose_norm_threshold_min": 0.001,
107
+ "verbose_paramter_norm": false,
108
+ "use_discriminator": true,
109
+ "encoder_checkpoint": null,
110
+ "rect_checkpoint": null,
111
+ "decoder_checkpoint": null,
112
+ "codec_checkpoint": null,
113
+ "sw2v_checkpoint": "/data/jhcodec/sw2v/cossim/checkpoints/checkpoint_60000.pt"
114
+ },
115
+ "loss":{
116
+ "recon_loss_weight": 0.1,
117
+ "vq_loss_weight": 1.0,
118
+ "commit_loss_weight": 0.1,
119
+ "fm_loss_weight": 1.0,
120
+ "adv_loss_weight": 1.0,
121
+ "w2v_loss_weight": 1.0,
122
+ "semantic_loss_weight": 1.0
123
+ },
124
+ "data": {
125
+ "audio_dir": "/data",
126
+ "sample_rate": 16000,
127
+ "segment_duration": 10.24,
128
+ "cache_dir": "/data/dataloader/v9"
129
+ },
130
+ "logging": {
131
+ "log_interval": 100,
132
+ "save_interval": 500,
133
+ "eval_interval": 3000,
134
+ "experiment_dir": "/data/jhcodec/{experiment_name}",
135
+ "checkpoint_dir": "/data/jhcodec/{experiment_name}/checkpoints",
136
+ "tensorboard_dir": "/data/jhcodec/{experiment_name}/tensorboard",
137
+ "n_samples": 3
138
+ }
139
+ }
jhcodec_mimi_1400000.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4a175d41869775ad6df5124b9dfd470b6b04e9b33ac480d43e01e22dad0cd61e
3
+ size 1085065112