blazingbhavneek commited on
Commit
a44a58e
·
verified ·
1 Parent(s): c858206

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* 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
 
 
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
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - text-to-speech
5
+ - gptq
6
+ - quantized
7
+ language:
8
+ - zh
9
+ - en
10
+ - de
11
+ - es
12
+ - fr
13
+ - ja
14
+ - it
15
+ - he
16
+ - ko
17
+ - ru
18
+ - fa
19
+ - ar
20
+ - pl
21
+ - pt
22
+ - cs
23
+ - da
24
+ - sv
25
+ - hu
26
+ - el
27
+ - tr
28
+ base_model: OpenMOSS-Team/MOSS-TTS
29
+ ---
30
+
31
+ # MOSS-TTS-GPTQ
32
+
33
+ This is a **GPTQ 4-bit quantized** version of [MOSS-TTS (MossTTSDelay 8B)](https://huggingface.co/OpenMOSS-Team/MOSS-TTS) by the OpenMOSS Team, quantized using [GPTQModel](https://github.com/ModelCloud/GPTQModel). The quantization targets the LLM backbone only; the non-backbone weights (`emb_ext`, `lm_heads`, `language_model.norm`) are preserved in their original precision and merged back into a single self-contained repo.
34
+
35
+ This repo is intended to be used together with the float16 audio tokenizer: 🤗 [blazingbhavneek/MOSS-Audio-Tokenizer-FP16](https://huggingface.co/blazingbhavneek/MOSS-Audio-Tokenizer-FP16).
36
+
37
+ **VRAM usage: ~9 GB** (vs. ~23 GB for the original bf16 model + tokenizer), making this accessible on a single consumer GPU.
38
+
39
+ The quantization scripts and a working environment `requirements.txt` are available in the [fork used to produce this model](https://github.com/blazingbhavneek/MOSS-TTS/tree/feature/gptq-quant-model-support).
40
+
41
+ **Original model resources:**
42
+ - 🤗 [OpenMOSS-Team/MOSS-TTS](https://huggingface.co/OpenMOSS-Team/MOSS-TTS)
43
+ - 💻 [OpenMOSS/MOSS-TTS (GitHub)](https://github.com/OpenMOSS/MOSS-TTS)
44
+
45
+ ---
46
+
47
+ ## Model Description
48
+
49
+ MOSS-TTS is a production-grade TTS foundation model focused on **zero-shot voice cloning**, **ultra-long stable speech generation** (up to 1 hour), **token-level duration control**, **phoneme-level pronunciation control** (Pinyin / IPA), and **multilingual & code-switched synthesis**. It is built on a clean autoregressive discrete-token recipe with a large-scale Transformer backbone (MossTTSDelay architecture).
50
+
51
+ ### Supported Languages
52
+
53
+ 20 languages are supported:
54
+
55
+ | Language | Code | | Language | Code | | Language | Code |
56
+ |---|---|---|---|---|---|---|---|
57
+ | Chinese | zh | 🇨🇳 | English | en | 🇺🇸 | German | de | 🇩🇪 |
58
+ | Spanish | es | 🇪🇸 | French | fr | 🇫🇷 | Japanese | ja | 🇯🇵 |
59
+ | Italian | it | 🇮🇹 | Hebrew | he | 🇮🇱 | Korean | ko | 🇰🇷 |
60
+ | Russian | ru | 🇷🇺 | Persian (Farsi) | fa | 🇮🇷 | Arabic | ar | 🇸🇦 |
61
+ | Polish | pl | 🇵🇱 | Portuguese | pt | 🇵🇹 | Czech | cs | 🇨🇿 |
62
+ | Danish | da | 🇩🇰 | Swedish | sv | 🇸🇪 | Hungarian | hu | 🇭🇺 |
63
+ | Greek | el | 🇬🇷 | Turkish | tr | 🇹🇷 | | | |
64
+
65
+ ---
66
+
67
+ ## Quantization Details
68
+
69
+ | Property | Value |
70
+ |---|---|
71
+ | Base model | MossTTSDelay-8B |
72
+ | Quantization method | GPTQ |
73
+ | Bits | 4 |
74
+ | Group size | 128 |
75
+ | Calibration dataset | wikitext2 |
76
+ | Quantization library | [GPTQModel](https://github.com/ModelCloud/GPTQModel) |
77
+ | VRAM (this model + FP16 tokenizer) | ~9 GB |
78
+ | VRAM (original bf16 model + tokenizer) | ~23 GB |
79
+
80
+ ---
81
+
82
+ ## Evaluation — Quality Degradation
83
+
84
+ Benchmarks on [seed-tts-eval](https://github.com/BytedanceSpeech/seed-tts-eval). Lower WER is better.
85
+
86
+ | Model | EN WER (%) ↓ |
87
+ |---|---:|
88
+ | MossTTSDelay-8B (original fp32/bf16) | 1.79 |
89
+ | **MossTTSDelay-8B (this GPTQ 4-bit)** | 2.585 |
90
+
91
+ ---
92
+
93
+ ## Installation
94
+
95
+ Install [GPTQModel](https://github.com/ModelCloud/GPTQModel) in addition to the standard MOSS-TTS dependencies — it is required to load the quantized backbone at inference time:
96
+
97
+ ```bash
98
+ pip install gptqmodel
99
+ ```
100
+
101
+ Then install MOSS-TTS from the fork that added GPTQ support:
102
+
103
+ ```bash
104
+ git clone -b feature/gptq-quant-model-support https://github.com/blazingbhavneek/MOSS-TTS.git
105
+ cd MOSS-TTS
106
+ pip install --extra-index-url https://download.pytorch.org/whl/cu128 -e .
107
+ ```
108
+
109
+ > **Note:** When loading this model you will see warnings about unexpected keys (e.g. `model.layers.X.mlp.gate_proj.qweight`). These are normal — they come from the GPTQModel library's quantized layer format and do not affect inference.
110
+
111
+ ---
112
+
113
+ ## Inference
114
+
115
+ ```python
116
+ from pathlib import Path
117
+ import torch
118
+ import torchaudio
119
+ from moss_tts_delay.modeling_moss_tts import MossTTSDelayModel
120
+ from moss_tts_delay.processing_moss_tts import MossTTSDelayProcessor
121
+
122
+ # Disable problematic SDP backends
123
+ torch.backends.cuda.enable_cudnn_sdp(False)
124
+ torch.backends.cuda.enable_flash_sdp(False)
125
+ torch.backends.cuda.enable_mem_efficient_sdp(False)
126
+ torch.backends.cuda.enable_math_sdp(True)
127
+
128
+ MERGED_PATH = "blazingbhavneek/MOSS-TTS-GPTQ"
129
+ AUDIO_TOK_PATH = "blazingbhavneek/MOSS-Audio-Tokenizer-FP16"
130
+
131
+ device = "cuda" if torch.cuda.is_available() else "cpu"
132
+
133
+ model = MossTTSDelayModel.from_pretrained(
134
+ MERGED_PATH,
135
+ gptq_device=device,
136
+ trust_remote_code=True,
137
+ ).eval()
138
+
139
+ processor = MossTTSDelayProcessor.from_pretrained(
140
+ MERGED_PATH,
141
+ codec_path=AUDIO_TOK_PATH,
142
+ trust_remote_code=True,
143
+ )
144
+
145
+ # --- Example texts ---
146
+ text_en = "We stand on the threshold of the AI era. Artificial intelligence is no longer just a concept in laboratories, but is entering every industry, every creative endeavor, and every decision."
147
+ text_zh = "亲爱的你,你好呀。今天,我想用最认真、最温柔的声音,对你说一些重要的话。"
148
+ text_pinyin = "nin2 hao3,qing3 wen4 nin2 lai2 zi4 na3 zuo4 cheng2 shi4?"
149
+ text_ipa = "/həloʊ, meɪ aɪ æsk wɪtʃ sɪti juː ɑːr frʌm?/"
150
+
151
+ # Reference audio for voice cloning (URLs or local paths)
152
+ ref_audio_zh = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_zh.wav"
153
+ ref_audio_en = "https://speech-demo.oss-cn-shanghai.aliyuncs.com/moss_tts_demo/tts_readme_demo/reference_en.m4a"
154
+
155
+ conversations = [
156
+ # Direct TTS (no reference)
157
+ [processor.build_user_message(text=text_zh)],
158
+ [processor.build_user_message(text=text_en)],
159
+ # Pronunciation control
160
+ [processor.build_user_message(text=text_pinyin)],
161
+ [processor.build_user_message(text=text_ipa)],
162
+ # Voice cloning
163
+ [processor.build_user_message(text=text_zh, reference=[ref_audio_zh])],
164
+ [processor.build_user_message(text=text_en, reference=[ref_audio_en])],
165
+ # Duration control (1s ≈ 12.5 tokens)
166
+ [processor.build_user_message(text=text_en, tokens=325)],
167
+ [processor.build_user_message(text=text_en, tokens=600)],
168
+ ]
169
+
170
+ save_dir = Path("inference_root")
171
+ save_dir.mkdir(exist_ok=True, parents=True)
172
+
173
+ with torch.no_grad():
174
+ for idx, conversation in enumerate(conversations):
175
+ batch = processor([conversation], mode="generation")
176
+ outputs = model.generate(
177
+ input_ids=batch["input_ids"].to(device),
178
+ attention_mask=batch["attention_mask"].to(device),
179
+ max_new_tokens=4096,
180
+ )
181
+ for message in processor.decode([(sl, ids.long()) for sl, ids in outputs]):
182
+ audio = message.audio_codes_list[0]
183
+ out_path = save_dir / f"sample{idx}.wav"
184
+ torchaudio.save(out_path, audio.unsqueeze(0), processor.model_config.sampling_rate)
185
+ print(f"Saved {out_path}")
186
+ ```
187
+
188
+ ### Input reference
189
+
190
+ **UserMessage fields**
191
+
192
+ | Field | Type | Required | Description |
193
+ |---|---|:---:|---|
194
+ | `text` | `str` | ✅ | Text to synthesize. Supports all 20 languages, raw text, Pinyin, IPA, or any mix. |
195
+ | `reference` | `List[str]` | ❌ | Reference audio path(s) or URL(s) for zero-shot voice cloning. One audio expected. |
196
+ | `tokens` | `int` | ❌ | Target audio token count for duration control. **1 second ≈ 12.5 tokens.** |
197
+
198
+ ### Generation hyperparameters
199
+
200
+ | Parameter | Default | Description |
201
+ |---|---|---|
202
+ | `max_new_tokens` | — | Total audio tokens to generate. Use the 1s ≈ 12.5 tokens rule. |
203
+ | `audio_temperature` | 1.7 | Higher = more variation; lower = more stable prosody. |
204
+ | `audio_top_p` | 0.8 | Nucleus sampling cutoff. |
205
+ | `audio_top_k` | 25 | Top-K sampling. |
206
+ | `audio_repetition_penalty` | 1.0 | Values > 1.0 discourage repeating patterns. |
207
+
208
+ ---
209
+
210
+ ## License
211
+
212
+ Apache 2.0, consistent with the original [MOSS-TTS](https://huggingface.co/OpenMOSS-Team/MOSS-TTS) release.
chat_template.jinja ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {% for message in messages %}<|im_start|>{{ message['role'] }}
2
+ {% if message['content'] is string %}{{ message['content'] }}{% else %}{% for content in message['content'] %}{% if content.get('type') == 'text' %}{{ content['text'] }}{% endif %}{% endfor %}{% endif %}<|im_end|>
3
+ {% endfor %}{% if add_generation_prompt %}<|im_start|>assistant
4
+ {% endif %}
config.json ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "moss_tts_delay",
3
+ "architectures": [
4
+ "MossTTSDelayModel"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_moss_tts.MossTTSDelayConfig",
8
+ "AutoModel": "modeling_moss_tts.MossTTSDelayModel"
9
+ },
10
+ "dtype": "bfloat16",
11
+ "initializer_range": 0.02,
12
+ "language_config": {
13
+ "_name_or_path": "Qwen/Qwen3-8B",
14
+ "architectures": [
15
+ "Qwen3ForCausalLM"
16
+ ],
17
+ "attention_bias": false,
18
+ "attention_dropout": 0.0,
19
+ "bos_token_id": 151643,
20
+ "eos_token_id": 151645,
21
+ "pad_token_id": 151643,
22
+ "head_dim": 128,
23
+ "hidden_act": "silu",
24
+ "hidden_size": 4096,
25
+ "initializer_range": 0.02,
26
+ "intermediate_size": 12288,
27
+ "layer_types": [
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention",
42
+ "full_attention",
43
+ "full_attention",
44
+ "full_attention",
45
+ "full_attention",
46
+ "full_attention",
47
+ "full_attention",
48
+ "full_attention",
49
+ "full_attention",
50
+ "full_attention",
51
+ "full_attention",
52
+ "full_attention",
53
+ "full_attention",
54
+ "full_attention",
55
+ "full_attention",
56
+ "full_attention",
57
+ "full_attention",
58
+ "full_attention",
59
+ "full_attention",
60
+ "full_attention",
61
+ "full_attention",
62
+ "full_attention",
63
+ "full_attention"
64
+ ],
65
+ "max_position_embeddings": 40960,
66
+ "max_window_layers": 36,
67
+ "model_type": "qwen3",
68
+ "num_attention_heads": 32,
69
+ "num_hidden_layers": 36,
70
+ "num_key_value_heads": 8,
71
+ "rms_norm_eps": 1e-06,
72
+ "rope_scaling": null,
73
+ "rope_theta": 1000000,
74
+ "sliding_window": null,
75
+ "use_cache": true,
76
+ "use_sliding_window": false,
77
+ "vocab_size": 155648
78
+ },
79
+ "n_vq": 32,
80
+ "audio_vocab_size": 1024,
81
+ "audio_user_slot_token_id": 151654,
82
+ "audio_assistant_gen_slot_token_id": 151656,
83
+ "audio_assistant_delay_slot_token_id": 151662,
84
+ "audio_start_token_id": 151652,
85
+ "audio_end_token_id": 151653,
86
+ "audio_pad_code": 1024,
87
+ "sampling_rate": 24000,
88
+ "transformers_version": "4.57.1"
89
+ }
configuration_moss_tts.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2026 OpenMOSS and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """ MossTTSDelay model configuration """
16
+
17
+ from typing import Optional, Union
18
+ from transformers.configuration_utils import PretrainedConfig
19
+ from transformers.utils import logging
20
+ from transformers.models.qwen3 import Qwen3Config
21
+
22
+ logger = logging.get_logger(__name__)
23
+
24
+
25
+ class MossTTSDelayConfig(PretrainedConfig):
26
+ r"""
27
+ This is the configuration class to store the configuration of a [`MossTTSDelayModel`]. It is used to instantiate an
28
+ MossTTSDelay model according to the specified arguments, defining the model architecture. Instantiating a configuration
29
+ with the defaults will yield a similar configuration to that of the MossTTSDelay [MossTTSDelay-8B](https://huggingface.co/OpenMOSS/mosstts-8b) architecture.
30
+
31
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
32
+ documentation from [`PretrainedConfig`] for more information.
33
+
34
+ Args:
35
+ language_config (`Union[Qwen3Config, dict]`, *optional*):
36
+ Configuration for the backbone language model (Qwen3).
37
+ initializer_range (`float`, *optional*, defaults to 0.02):
38
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
39
+ n_vq (`int`, *optional*, defaults to 32):
40
+ Number of additional VQ (Vector Quantization) heads/channels for audio.
41
+ Determines the number of codebooks used in the audio representation.
42
+ audio_vocab_size (`int`, *optional*, defaults to 1024):
43
+ Vocabulary size for the audio tokens (codebooks 1 to N).
44
+ audio_user_slot_token_id (`int`, *optional*, defaults to 151654):
45
+ The specific token ID used as a placeholder/slot for user-side audio inputs in the prompt.
46
+ audio_assistant_gen_slot_token_id (`int`, *optional*, defaults to 151656):
47
+ The specific token ID representing the generation slot for the assistant's audio output.
48
+ Acting as the trigger for the TTS generation process.
49
+ audio_assistant_delay_slot_token_id (`int`, *optional*, defaults to 151662):
50
+ The token ID used in the 'Delay Pattern' paradigm to represent the delayed/offset positions
51
+ between different VQ channels.
52
+ audio_start_token_id (`int`, *optional*, defaults to 151652):
53
+ Special token ID used to denote the start of an audio sequence in the stream.
54
+ audio_end_token_id (`int`, *optional*, defaults to 151653):
55
+ Special token ID used to denote the end of an audio sequence (EOS for audio).
56
+ audio_pad_code (`int`, *optional*, defaults to 1024):
57
+ The padding value used within the audio VQ codebooks. Typically equals `audio_vocab_size`.
58
+ """
59
+ model_type = "moss_tts_delay"
60
+ keys_to_ignore_at_inference = ["past_key_values"]
61
+
62
+ def __init__(
63
+ self,
64
+ language_config: Optional[Union[Qwen3Config, dict]] = None,
65
+ initializer_range: float = 0.02,
66
+ n_vq: int = 32,
67
+ pad_token_id: int = 151643,
68
+ im_start_token_id: int = 151644,
69
+ im_end_token_id: int = 151645,
70
+ audio_vocab_size: int = 1024,
71
+ audio_user_slot_token_id: int = 151654,
72
+ audio_assistant_gen_slot_token_id: int = 151656,
73
+ audio_assistant_delay_slot_token_id: int = 151662,
74
+ audio_start_token_id: int = 151652,
75
+ audio_end_token_id: int = 151653,
76
+ audio_pad_code: int = 1024,
77
+ sampling_rate: int = 24000,
78
+ **kwargs,
79
+ ):
80
+ if isinstance(language_config, dict):
81
+ self.language_config = Qwen3Config(**language_config)
82
+ elif language_config is None:
83
+ self.language_config = Qwen3Config()
84
+ else:
85
+ self.language_config = language_config
86
+
87
+ self.initializer_range = initializer_range
88
+ self.n_vq = n_vq
89
+ self.audio_vocab_size = audio_vocab_size
90
+ self.audio_user_slot_token_id = audio_user_slot_token_id
91
+ self.audio_assistant_gen_slot_token_id = audio_assistant_gen_slot_token_id
92
+ self.audio_assistant_delay_slot_token_id = audio_assistant_delay_slot_token_id
93
+ self.audio_start_token_id = audio_start_token_id
94
+ self.audio_end_token_id = audio_end_token_id
95
+ self.audio_pad_code = audio_pad_code
96
+ self.sampling_rate = sampling_rate
97
+
98
+ self.hidden_size = self.language_config.hidden_size
99
+ self.vocab_size = self.language_config.vocab_size
100
+ self.im_start_token_id = self.language_config
101
+ self.pad_token_id = pad_token_id
102
+ self.im_start_token_id = im_start_token_id
103
+ self.im_end_token_id = im_end_token_id
104
+
105
+
106
+ super().__init__(**kwargs)
107
+
108
+ def to_dict(self):
109
+ output = super().to_dict()
110
+ if hasattr(self.language_config, "to_dict"):
111
+ output["language_config"] = self.language_config.to_dict()
112
+ else:
113
+ output["language_config"] = self.language_config
114
+ return output
generation_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 151643,
4
+ "do_sample": true,
5
+ "eos_token_id": 151645,
6
+ "output_attentions": false,
7
+ "output_hidden_states": false,
8
+ "pad_token_id": 151643,
9
+ "transformers_version": "5.2.0",
10
+ "use_cache": true
11
+ }
inference_utils.py ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torchaudio
3
+ import torch.nn.functional as F
4
+ from typing import Optional, List, Tuple
5
+ from tqdm import tqdm
6
+
7
+
8
+ def apply_top_k(logits, top_k):
9
+ batch_size, vocab_size = logits.shape
10
+ top_k = min(top_k, vocab_size)
11
+ top_k_values, top_k_indices = torch.topk(logits, top_k, dim=-1)
12
+ filtered_logits = torch.full_like(logits, float("-inf"))
13
+ batch_indices = torch.arange(batch_size).unsqueeze(-1)
14
+ filtered_logits[batch_indices, top_k_indices] = top_k_values
15
+ return filtered_logits
16
+
17
+
18
+ def apply_top_p(logits, top_p):
19
+ probs = F.softmax(logits, dim=-1)
20
+ sorted_probs, sorted_indices = torch.sort(probs, descending=True, dim=-1)
21
+ cumulative_probs = torch.cumsum(sorted_probs, dim=-1)
22
+ sorted_indices_to_remove = cumulative_probs > top_p
23
+ sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[..., :-1].clone()
24
+ sorted_indices_to_remove[..., 0] = False
25
+ batch_size = logits.shape[0]
26
+ filtered_logits = logits.clone()
27
+ for i in range(batch_size):
28
+ indices_to_remove = sorted_indices[i][sorted_indices_to_remove[i]]
29
+ filtered_logits[i, indices_to_remove] = float("-inf")
30
+ return filtered_logits
31
+
32
+
33
+ def apply_top_p_optimized(logits, top_p):
34
+ probs = F.softmax(logits, dim=-1)
35
+ sorted_probs, sorted_indices = torch.sort(probs, descending=True, dim=-1)
36
+
37
+ cumulative_probs = torch.cumsum(sorted_probs, dim=-1)
38
+
39
+ sorted_indices_to_remove = cumulative_probs > top_p
40
+ sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[..., :-1].clone()
41
+ sorted_indices_to_remove[..., 0] = False
42
+
43
+ indices_to_remove = torch.zeros_like(logits, dtype=torch.bool).scatter_(
44
+ dim=-1, index=sorted_indices, src=sorted_indices_to_remove
45
+ )
46
+
47
+ logits[indices_to_remove] = float("-inf")
48
+ return logits
49
+
50
+
51
+ def apply_repetition_penalty_delay_pattern(
52
+ logits: torch.Tensor,
53
+ prev_tokens: torch.LongTensor,
54
+ penalty: float,
55
+ ):
56
+ """
57
+ logits: [B, H, V] or [N, V]
58
+ prev_tokens: [B, T, H] or [N, T] or [B, H]
59
+
60
+ Apply the repetition penalty independently for each H (VQ head).
61
+ """
62
+ if penalty == 1.0 or prev_tokens is None:
63
+ return logits
64
+
65
+ vocab_size = logits.size(-1)
66
+
67
+ # Case 1: regular [N, V] (text layer)
68
+ if logits.dim() == 2:
69
+ prev_tokens_flat = prev_tokens.reshape(-1)
70
+ unique_tokens = torch.unique(prev_tokens_flat)
71
+
72
+ token_logits = logits[:, unique_tokens]
73
+ pos_mask = token_logits > 0
74
+ token_logits[pos_mask] /= penalty
75
+ token_logits[~pos_mask] *= penalty
76
+ logits[:, unique_tokens] = token_logits
77
+ return logits
78
+
79
+ # Case 2: Delay Pattern audio [B, H, V]
80
+ assert logits.dim() == 3, "Delay Pattern audio logits must be [B, H, V]"
81
+ B, H, V = logits.shape
82
+
83
+ for h in range(H):
84
+ # prev_tokens_h: [B, T] or [B]
85
+ prev_tokens_h = prev_tokens[..., h].reshape(-1)
86
+ unique_tokens = torch.unique(prev_tokens_h)
87
+
88
+ if unique_tokens.numel() == 0:
89
+ continue
90
+
91
+ token_logits = logits[:, h, unique_tokens]
92
+ pos_mask = token_logits > 0
93
+ token_logits[pos_mask] /= penalty
94
+ token_logits[~pos_mask] *= penalty
95
+ logits[:, h, unique_tokens] = token_logits
96
+
97
+ return logits
98
+
99
+
100
+ def sample_token(
101
+ logits,
102
+ prev_tokens: Optional[torch.LongTensor] = None,
103
+ repetition_penalty: float = 1.0,
104
+ top_p=None,
105
+ top_k=None,
106
+ do_sample=True,
107
+ ):
108
+ vocab_size = logits.size(-1)
109
+
110
+ # ===== Repetition Penalty (before reshaping!) =====
111
+ if prev_tokens is not None and repetition_penalty != 1.0:
112
+ logits = apply_repetition_penalty_delay_pattern(
113
+ logits,
114
+ prev_tokens,
115
+ repetition_penalty,
116
+ )
117
+
118
+ if not do_sample:
119
+ return torch.argmax(logits, dim=-1)
120
+
121
+ # ===== Only flatten after this, for top-k / top-p / multinomial =====
122
+ original_shape = logits.shape
123
+ reshaped_logits = logits.view(-1, vocab_size)
124
+
125
+ if top_k is not None and top_k > 0:
126
+ reshaped_logits = apply_top_k(reshaped_logits, top_k)
127
+
128
+ if top_p is not None and top_p < 1.0:
129
+ reshaped_logits = apply_top_p_optimized(reshaped_logits, top_p)
130
+
131
+ probs = F.softmax(reshaped_logits, dim=-1)
132
+ next_tokens = torch.multinomial(probs, num_samples=1)
133
+
134
+ return next_tokens.view(original_shape[:-1])
135
+
136
+
137
+ def find_last_equal_C(tensor, C):
138
+ """
139
+ tensor: torch.Tensor of shape [batch_size, seq_len]
140
+ C: scalar value to match
141
+ Returns: torch.Tensor of shape [batch_size] with last indices
142
+ """
143
+ mask = (tensor == C).int() # Shape: [batch_size, seq_len], bool tensor
144
+ flipped_mask = mask.flip(dims=[1]) # Flip along sequence dimension
145
+ flipped_indices = flipped_mask.argmax(dim=1) # First True in flipped
146
+ seq_len = tensor.shape[1]
147
+ last_indices = (seq_len - 1) - flipped_indices # Convert to original indices
148
+
149
+ # Optional: Handle cases with no C (set to -1), though problem assumes existence
150
+ actual_values = tensor[torch.arange(tensor.shape[0]), last_indices]
151
+ no_match = actual_values != C
152
+ last_indices[no_match] = -1
153
+
154
+ return last_indices
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9222e89d77190ebdd240765bca8d4613764fd66ff7910738d3acc0419f6eb96c
3
+ size 4280025536
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8a5e8085dcdd2af233517535cb697fa37b530a7e39bfef2ab520468e98655190
3
+ size 1884708993
model.safetensors.index.json ADDED
@@ -0,0 +1,1228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 7977212609
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "model-00001-of-00002.safetensors",
7
+ "model.embed_tokens.weight": "model-00001-of-00002.safetensors",
8
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
9
+ "model.layers.0.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
10
+ "model.layers.0.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
11
+ "model.layers.0.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
12
+ "model.layers.0.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
13
+ "model.layers.0.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
14
+ "model.layers.0.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
15
+ "model.layers.0.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
16
+ "model.layers.0.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
17
+ "model.layers.0.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
18
+ "model.layers.0.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
19
+ "model.layers.0.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
20
+ "model.layers.0.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
21
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
22
+ "model.layers.0.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
23
+ "model.layers.0.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
24
+ "model.layers.0.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
25
+ "model.layers.0.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
26
+ "model.layers.0.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
27
+ "model.layers.0.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
28
+ "model.layers.0.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
29
+ "model.layers.0.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
30
+ "model.layers.0.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
31
+ "model.layers.0.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
32
+ "model.layers.0.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
33
+ "model.layers.0.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
34
+ "model.layers.0.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
35
+ "model.layers.0.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
36
+ "model.layers.0.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
37
+ "model.layers.0.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
38
+ "model.layers.0.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
39
+ "model.layers.0.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
40
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
41
+ "model.layers.1.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
42
+ "model.layers.1.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
43
+ "model.layers.1.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
44
+ "model.layers.1.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
45
+ "model.layers.1.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
46
+ "model.layers.1.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
47
+ "model.layers.1.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
48
+ "model.layers.1.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
49
+ "model.layers.1.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
50
+ "model.layers.1.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
51
+ "model.layers.1.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
52
+ "model.layers.1.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
53
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
54
+ "model.layers.1.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
55
+ "model.layers.1.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
56
+ "model.layers.1.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
57
+ "model.layers.1.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
58
+ "model.layers.1.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
59
+ "model.layers.1.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
60
+ "model.layers.1.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
61
+ "model.layers.1.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
62
+ "model.layers.1.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
63
+ "model.layers.1.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
64
+ "model.layers.1.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
65
+ "model.layers.1.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
66
+ "model.layers.1.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
67
+ "model.layers.1.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
68
+ "model.layers.1.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
69
+ "model.layers.1.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
70
+ "model.layers.1.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
71
+ "model.layers.1.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
72
+ "model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
73
+ "model.layers.10.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
74
+ "model.layers.10.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
75
+ "model.layers.10.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
76
+ "model.layers.10.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
77
+ "model.layers.10.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
78
+ "model.layers.10.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
79
+ "model.layers.10.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
80
+ "model.layers.10.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
81
+ "model.layers.10.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
82
+ "model.layers.10.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
83
+ "model.layers.10.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
84
+ "model.layers.10.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
85
+ "model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
86
+ "model.layers.10.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
87
+ "model.layers.10.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
88
+ "model.layers.10.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
89
+ "model.layers.10.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
90
+ "model.layers.10.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
91
+ "model.layers.10.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
92
+ "model.layers.10.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
93
+ "model.layers.10.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
94
+ "model.layers.10.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
95
+ "model.layers.10.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
96
+ "model.layers.10.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
97
+ "model.layers.10.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
98
+ "model.layers.10.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
99
+ "model.layers.10.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
100
+ "model.layers.10.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
101
+ "model.layers.10.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
102
+ "model.layers.10.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
103
+ "model.layers.10.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
104
+ "model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
105
+ "model.layers.11.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
106
+ "model.layers.11.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
107
+ "model.layers.11.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
108
+ "model.layers.11.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
109
+ "model.layers.11.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
110
+ "model.layers.11.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
111
+ "model.layers.11.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
112
+ "model.layers.11.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
113
+ "model.layers.11.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
114
+ "model.layers.11.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
115
+ "model.layers.11.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
116
+ "model.layers.11.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
117
+ "model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
118
+ "model.layers.11.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
119
+ "model.layers.11.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
120
+ "model.layers.11.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
121
+ "model.layers.11.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
122
+ "model.layers.11.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
123
+ "model.layers.11.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
124
+ "model.layers.11.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
125
+ "model.layers.11.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
126
+ "model.layers.11.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
127
+ "model.layers.11.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
128
+ "model.layers.11.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
129
+ "model.layers.11.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
130
+ "model.layers.11.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
131
+ "model.layers.11.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
132
+ "model.layers.11.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
133
+ "model.layers.11.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
134
+ "model.layers.11.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
135
+ "model.layers.11.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
136
+ "model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
137
+ "model.layers.12.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
138
+ "model.layers.12.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
139
+ "model.layers.12.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
140
+ "model.layers.12.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
141
+ "model.layers.12.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
142
+ "model.layers.12.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
143
+ "model.layers.12.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
144
+ "model.layers.12.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
145
+ "model.layers.12.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
146
+ "model.layers.12.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
147
+ "model.layers.12.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
148
+ "model.layers.12.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
149
+ "model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
150
+ "model.layers.12.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
151
+ "model.layers.12.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
152
+ "model.layers.12.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
153
+ "model.layers.12.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
154
+ "model.layers.12.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
155
+ "model.layers.12.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
156
+ "model.layers.12.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
157
+ "model.layers.12.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
158
+ "model.layers.12.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
159
+ "model.layers.12.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
160
+ "model.layers.12.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
161
+ "model.layers.12.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
162
+ "model.layers.12.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
163
+ "model.layers.12.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
164
+ "model.layers.12.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
165
+ "model.layers.12.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
166
+ "model.layers.12.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
167
+ "model.layers.12.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
168
+ "model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
169
+ "model.layers.13.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
170
+ "model.layers.13.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
171
+ "model.layers.13.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
172
+ "model.layers.13.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
173
+ "model.layers.13.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
174
+ "model.layers.13.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
175
+ "model.layers.13.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
176
+ "model.layers.13.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
177
+ "model.layers.13.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
178
+ "model.layers.13.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
179
+ "model.layers.13.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
180
+ "model.layers.13.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
181
+ "model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
182
+ "model.layers.13.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
183
+ "model.layers.13.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
184
+ "model.layers.13.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
185
+ "model.layers.13.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
186
+ "model.layers.13.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
187
+ "model.layers.13.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
188
+ "model.layers.13.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
189
+ "model.layers.13.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
190
+ "model.layers.13.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
191
+ "model.layers.13.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
192
+ "model.layers.13.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
193
+ "model.layers.13.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
194
+ "model.layers.13.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
195
+ "model.layers.13.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
196
+ "model.layers.13.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
197
+ "model.layers.13.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
198
+ "model.layers.13.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
199
+ "model.layers.13.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
200
+ "model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
201
+ "model.layers.14.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
202
+ "model.layers.14.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
203
+ "model.layers.14.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
204
+ "model.layers.14.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
205
+ "model.layers.14.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
206
+ "model.layers.14.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
207
+ "model.layers.14.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
208
+ "model.layers.14.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
209
+ "model.layers.14.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
210
+ "model.layers.14.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
211
+ "model.layers.14.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
212
+ "model.layers.14.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
213
+ "model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
214
+ "model.layers.14.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
215
+ "model.layers.14.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
216
+ "model.layers.14.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
217
+ "model.layers.14.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
218
+ "model.layers.14.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
219
+ "model.layers.14.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
220
+ "model.layers.14.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
221
+ "model.layers.14.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
222
+ "model.layers.14.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
223
+ "model.layers.14.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
224
+ "model.layers.14.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
225
+ "model.layers.14.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
226
+ "model.layers.14.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
227
+ "model.layers.14.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
228
+ "model.layers.14.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
229
+ "model.layers.14.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
230
+ "model.layers.14.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
231
+ "model.layers.14.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
232
+ "model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
233
+ "model.layers.15.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
234
+ "model.layers.15.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
235
+ "model.layers.15.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
236
+ "model.layers.15.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
237
+ "model.layers.15.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
238
+ "model.layers.15.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
239
+ "model.layers.15.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
240
+ "model.layers.15.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
241
+ "model.layers.15.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
242
+ "model.layers.15.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
243
+ "model.layers.15.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
244
+ "model.layers.15.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
245
+ "model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
246
+ "model.layers.15.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
247
+ "model.layers.15.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
248
+ "model.layers.15.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
249
+ "model.layers.15.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
250
+ "model.layers.15.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
251
+ "model.layers.15.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
252
+ "model.layers.15.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
253
+ "model.layers.15.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
254
+ "model.layers.15.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
255
+ "model.layers.15.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
256
+ "model.layers.15.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
257
+ "model.layers.15.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
258
+ "model.layers.15.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
259
+ "model.layers.15.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
260
+ "model.layers.15.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
261
+ "model.layers.15.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
262
+ "model.layers.15.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
263
+ "model.layers.15.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
264
+ "model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
265
+ "model.layers.16.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
266
+ "model.layers.16.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
267
+ "model.layers.16.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
268
+ "model.layers.16.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
269
+ "model.layers.16.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
270
+ "model.layers.16.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
271
+ "model.layers.16.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
272
+ "model.layers.16.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
273
+ "model.layers.16.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
274
+ "model.layers.16.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
275
+ "model.layers.16.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
276
+ "model.layers.16.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
277
+ "model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
278
+ "model.layers.16.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
279
+ "model.layers.16.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
280
+ "model.layers.16.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
281
+ "model.layers.16.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
282
+ "model.layers.16.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
283
+ "model.layers.16.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
284
+ "model.layers.16.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
285
+ "model.layers.16.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
286
+ "model.layers.16.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
287
+ "model.layers.16.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
288
+ "model.layers.16.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
289
+ "model.layers.16.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
290
+ "model.layers.16.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
291
+ "model.layers.16.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
292
+ "model.layers.16.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
293
+ "model.layers.16.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
294
+ "model.layers.16.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
295
+ "model.layers.16.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
296
+ "model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
297
+ "model.layers.17.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
298
+ "model.layers.17.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
299
+ "model.layers.17.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
300
+ "model.layers.17.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
301
+ "model.layers.17.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
302
+ "model.layers.17.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
303
+ "model.layers.17.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
304
+ "model.layers.17.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
305
+ "model.layers.17.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
306
+ "model.layers.17.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
307
+ "model.layers.17.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
308
+ "model.layers.17.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
309
+ "model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
310
+ "model.layers.17.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
311
+ "model.layers.17.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
312
+ "model.layers.17.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
313
+ "model.layers.17.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
314
+ "model.layers.17.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
315
+ "model.layers.17.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
316
+ "model.layers.17.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
317
+ "model.layers.17.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
318
+ "model.layers.17.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
319
+ "model.layers.17.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
320
+ "model.layers.17.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
321
+ "model.layers.17.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
322
+ "model.layers.17.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
323
+ "model.layers.17.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
324
+ "model.layers.17.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
325
+ "model.layers.17.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
326
+ "model.layers.17.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
327
+ "model.layers.17.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
328
+ "model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
329
+ "model.layers.18.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
330
+ "model.layers.18.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
331
+ "model.layers.18.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
332
+ "model.layers.18.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
333
+ "model.layers.18.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
334
+ "model.layers.18.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
335
+ "model.layers.18.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
336
+ "model.layers.18.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
337
+ "model.layers.18.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
338
+ "model.layers.18.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
339
+ "model.layers.18.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
340
+ "model.layers.18.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
341
+ "model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
342
+ "model.layers.18.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
343
+ "model.layers.18.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
344
+ "model.layers.18.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
345
+ "model.layers.18.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
346
+ "model.layers.18.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
347
+ "model.layers.18.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
348
+ "model.layers.18.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
349
+ "model.layers.18.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
350
+ "model.layers.18.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
351
+ "model.layers.18.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
352
+ "model.layers.18.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
353
+ "model.layers.18.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
354
+ "model.layers.18.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
355
+ "model.layers.18.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
356
+ "model.layers.18.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
357
+ "model.layers.18.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
358
+ "model.layers.18.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
359
+ "model.layers.18.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
360
+ "model.layers.19.input_layernorm.weight": "model-00001-of-00002.safetensors",
361
+ "model.layers.19.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
362
+ "model.layers.19.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
363
+ "model.layers.19.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
364
+ "model.layers.19.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
365
+ "model.layers.19.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
366
+ "model.layers.19.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
367
+ "model.layers.19.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
368
+ "model.layers.19.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
369
+ "model.layers.19.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
370
+ "model.layers.19.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
371
+ "model.layers.19.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
372
+ "model.layers.19.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
373
+ "model.layers.19.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
374
+ "model.layers.19.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
375
+ "model.layers.19.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
376
+ "model.layers.19.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
377
+ "model.layers.19.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
378
+ "model.layers.19.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
379
+ "model.layers.19.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
380
+ "model.layers.19.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
381
+ "model.layers.19.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
382
+ "model.layers.19.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
383
+ "model.layers.19.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
384
+ "model.layers.19.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
385
+ "model.layers.19.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
386
+ "model.layers.19.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
387
+ "model.layers.19.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
388
+ "model.layers.19.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
389
+ "model.layers.19.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
390
+ "model.layers.19.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
391
+ "model.layers.19.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
392
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
393
+ "model.layers.2.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
394
+ "model.layers.2.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
395
+ "model.layers.2.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
396
+ "model.layers.2.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
397
+ "model.layers.2.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
398
+ "model.layers.2.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
399
+ "model.layers.2.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
400
+ "model.layers.2.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
401
+ "model.layers.2.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
402
+ "model.layers.2.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
403
+ "model.layers.2.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
404
+ "model.layers.2.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
405
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
406
+ "model.layers.2.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
407
+ "model.layers.2.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
408
+ "model.layers.2.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
409
+ "model.layers.2.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
410
+ "model.layers.2.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
411
+ "model.layers.2.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
412
+ "model.layers.2.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
413
+ "model.layers.2.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
414
+ "model.layers.2.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
415
+ "model.layers.2.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
416
+ "model.layers.2.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
417
+ "model.layers.2.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
418
+ "model.layers.2.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
419
+ "model.layers.2.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
420
+ "model.layers.2.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
421
+ "model.layers.2.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
422
+ "model.layers.2.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
423
+ "model.layers.2.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
424
+ "model.layers.20.input_layernorm.weight": "model-00001-of-00002.safetensors",
425
+ "model.layers.20.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
426
+ "model.layers.20.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
427
+ "model.layers.20.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
428
+ "model.layers.20.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
429
+ "model.layers.20.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
430
+ "model.layers.20.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
431
+ "model.layers.20.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
432
+ "model.layers.20.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
433
+ "model.layers.20.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
434
+ "model.layers.20.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
435
+ "model.layers.20.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
436
+ "model.layers.20.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
437
+ "model.layers.20.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
438
+ "model.layers.20.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
439
+ "model.layers.20.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
440
+ "model.layers.20.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
441
+ "model.layers.20.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
442
+ "model.layers.20.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
443
+ "model.layers.20.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
444
+ "model.layers.20.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
445
+ "model.layers.20.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
446
+ "model.layers.20.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
447
+ "model.layers.20.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
448
+ "model.layers.20.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
449
+ "model.layers.20.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
450
+ "model.layers.20.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
451
+ "model.layers.20.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
452
+ "model.layers.20.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
453
+ "model.layers.20.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
454
+ "model.layers.20.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
455
+ "model.layers.20.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
456
+ "model.layers.21.input_layernorm.weight": "model-00001-of-00002.safetensors",
457
+ "model.layers.21.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
458
+ "model.layers.21.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
459
+ "model.layers.21.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
460
+ "model.layers.21.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
461
+ "model.layers.21.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
462
+ "model.layers.21.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
463
+ "model.layers.21.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
464
+ "model.layers.21.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
465
+ "model.layers.21.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
466
+ "model.layers.21.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
467
+ "model.layers.21.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
468
+ "model.layers.21.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
469
+ "model.layers.21.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
470
+ "model.layers.21.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
471
+ "model.layers.21.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
472
+ "model.layers.21.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
473
+ "model.layers.21.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
474
+ "model.layers.21.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
475
+ "model.layers.21.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
476
+ "model.layers.21.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
477
+ "model.layers.21.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
478
+ "model.layers.21.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
479
+ "model.layers.21.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
480
+ "model.layers.21.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
481
+ "model.layers.21.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
482
+ "model.layers.21.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
483
+ "model.layers.21.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
484
+ "model.layers.21.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
485
+ "model.layers.21.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
486
+ "model.layers.21.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
487
+ "model.layers.21.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
488
+ "model.layers.22.input_layernorm.weight": "model-00001-of-00002.safetensors",
489
+ "model.layers.22.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
490
+ "model.layers.22.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
491
+ "model.layers.22.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
492
+ "model.layers.22.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
493
+ "model.layers.22.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
494
+ "model.layers.22.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
495
+ "model.layers.22.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
496
+ "model.layers.22.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
497
+ "model.layers.22.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
498
+ "model.layers.22.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
499
+ "model.layers.22.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
500
+ "model.layers.22.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
501
+ "model.layers.22.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
502
+ "model.layers.22.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
503
+ "model.layers.22.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
504
+ "model.layers.22.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
505
+ "model.layers.22.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
506
+ "model.layers.22.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
507
+ "model.layers.22.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
508
+ "model.layers.22.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
509
+ "model.layers.22.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
510
+ "model.layers.22.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
511
+ "model.layers.22.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
512
+ "model.layers.22.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
513
+ "model.layers.22.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
514
+ "model.layers.22.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
515
+ "model.layers.22.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
516
+ "model.layers.22.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
517
+ "model.layers.22.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
518
+ "model.layers.22.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
519
+ "model.layers.22.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
520
+ "model.layers.23.input_layernorm.weight": "model-00001-of-00002.safetensors",
521
+ "model.layers.23.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
522
+ "model.layers.23.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
523
+ "model.layers.23.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
524
+ "model.layers.23.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
525
+ "model.layers.23.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
526
+ "model.layers.23.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
527
+ "model.layers.23.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
528
+ "model.layers.23.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
529
+ "model.layers.23.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
530
+ "model.layers.23.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
531
+ "model.layers.23.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
532
+ "model.layers.23.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
533
+ "model.layers.23.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
534
+ "model.layers.23.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
535
+ "model.layers.23.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
536
+ "model.layers.23.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
537
+ "model.layers.23.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
538
+ "model.layers.23.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
539
+ "model.layers.23.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
540
+ "model.layers.23.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
541
+ "model.layers.23.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
542
+ "model.layers.23.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
543
+ "model.layers.23.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
544
+ "model.layers.23.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
545
+ "model.layers.23.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
546
+ "model.layers.23.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
547
+ "model.layers.23.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
548
+ "model.layers.23.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
549
+ "model.layers.23.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
550
+ "model.layers.23.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
551
+ "model.layers.23.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
552
+ "model.layers.24.input_layernorm.weight": "model-00001-of-00002.safetensors",
553
+ "model.layers.24.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
554
+ "model.layers.24.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
555
+ "model.layers.24.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
556
+ "model.layers.24.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
557
+ "model.layers.24.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
558
+ "model.layers.24.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
559
+ "model.layers.24.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
560
+ "model.layers.24.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
561
+ "model.layers.24.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
562
+ "model.layers.24.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
563
+ "model.layers.24.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
564
+ "model.layers.24.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
565
+ "model.layers.24.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
566
+ "model.layers.24.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
567
+ "model.layers.24.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
568
+ "model.layers.24.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
569
+ "model.layers.24.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
570
+ "model.layers.24.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
571
+ "model.layers.24.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
572
+ "model.layers.24.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
573
+ "model.layers.24.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
574
+ "model.layers.24.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
575
+ "model.layers.24.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
576
+ "model.layers.24.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
577
+ "model.layers.24.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
578
+ "model.layers.24.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
579
+ "model.layers.24.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
580
+ "model.layers.24.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
581
+ "model.layers.24.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
582
+ "model.layers.24.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
583
+ "model.layers.24.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
584
+ "model.layers.25.input_layernorm.weight": "model-00001-of-00002.safetensors",
585
+ "model.layers.25.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
586
+ "model.layers.25.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
587
+ "model.layers.25.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
588
+ "model.layers.25.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
589
+ "model.layers.25.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
590
+ "model.layers.25.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
591
+ "model.layers.25.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
592
+ "model.layers.25.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
593
+ "model.layers.25.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
594
+ "model.layers.25.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
595
+ "model.layers.25.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
596
+ "model.layers.25.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
597
+ "model.layers.25.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
598
+ "model.layers.25.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
599
+ "model.layers.25.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
600
+ "model.layers.25.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
601
+ "model.layers.25.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
602
+ "model.layers.25.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
603
+ "model.layers.25.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
604
+ "model.layers.25.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
605
+ "model.layers.25.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
606
+ "model.layers.25.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
607
+ "model.layers.25.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
608
+ "model.layers.25.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
609
+ "model.layers.25.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
610
+ "model.layers.25.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
611
+ "model.layers.25.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
612
+ "model.layers.25.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
613
+ "model.layers.25.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
614
+ "model.layers.25.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
615
+ "model.layers.25.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
616
+ "model.layers.26.input_layernorm.weight": "model-00001-of-00002.safetensors",
617
+ "model.layers.26.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
618
+ "model.layers.26.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
619
+ "model.layers.26.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
620
+ "model.layers.26.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
621
+ "model.layers.26.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
622
+ "model.layers.26.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
623
+ "model.layers.26.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
624
+ "model.layers.26.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
625
+ "model.layers.26.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
626
+ "model.layers.26.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
627
+ "model.layers.26.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
628
+ "model.layers.26.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
629
+ "model.layers.26.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
630
+ "model.layers.26.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
631
+ "model.layers.26.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
632
+ "model.layers.26.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
633
+ "model.layers.26.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
634
+ "model.layers.26.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
635
+ "model.layers.26.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
636
+ "model.layers.26.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
637
+ "model.layers.26.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
638
+ "model.layers.26.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
639
+ "model.layers.26.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
640
+ "model.layers.26.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
641
+ "model.layers.26.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
642
+ "model.layers.26.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
643
+ "model.layers.26.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
644
+ "model.layers.26.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
645
+ "model.layers.26.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
646
+ "model.layers.26.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
647
+ "model.layers.26.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
648
+ "model.layers.27.input_layernorm.weight": "model-00001-of-00002.safetensors",
649
+ "model.layers.27.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
650
+ "model.layers.27.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
651
+ "model.layers.27.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
652
+ "model.layers.27.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
653
+ "model.layers.27.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
654
+ "model.layers.27.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
655
+ "model.layers.27.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
656
+ "model.layers.27.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
657
+ "model.layers.27.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
658
+ "model.layers.27.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
659
+ "model.layers.27.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
660
+ "model.layers.27.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
661
+ "model.layers.27.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
662
+ "model.layers.27.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
663
+ "model.layers.27.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
664
+ "model.layers.27.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
665
+ "model.layers.27.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
666
+ "model.layers.27.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
667
+ "model.layers.27.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
668
+ "model.layers.27.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
669
+ "model.layers.27.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
670
+ "model.layers.27.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
671
+ "model.layers.27.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
672
+ "model.layers.27.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
673
+ "model.layers.27.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
674
+ "model.layers.27.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
675
+ "model.layers.27.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
676
+ "model.layers.27.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
677
+ "model.layers.27.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
678
+ "model.layers.27.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
679
+ "model.layers.27.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
680
+ "model.layers.28.input_layernorm.weight": "model-00001-of-00002.safetensors",
681
+ "model.layers.28.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
682
+ "model.layers.28.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
683
+ "model.layers.28.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
684
+ "model.layers.28.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
685
+ "model.layers.28.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
686
+ "model.layers.28.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
687
+ "model.layers.28.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
688
+ "model.layers.28.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
689
+ "model.layers.28.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
690
+ "model.layers.28.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
691
+ "model.layers.28.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
692
+ "model.layers.28.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
693
+ "model.layers.28.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
694
+ "model.layers.28.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
695
+ "model.layers.28.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
696
+ "model.layers.28.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
697
+ "model.layers.28.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
698
+ "model.layers.28.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
699
+ "model.layers.28.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
700
+ "model.layers.28.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
701
+ "model.layers.28.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
702
+ "model.layers.28.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
703
+ "model.layers.28.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
704
+ "model.layers.28.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
705
+ "model.layers.28.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
706
+ "model.layers.28.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
707
+ "model.layers.28.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
708
+ "model.layers.28.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
709
+ "model.layers.28.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
710
+ "model.layers.28.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
711
+ "model.layers.28.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
712
+ "model.layers.29.input_layernorm.weight": "model-00001-of-00002.safetensors",
713
+ "model.layers.29.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
714
+ "model.layers.29.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
715
+ "model.layers.29.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
716
+ "model.layers.29.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
717
+ "model.layers.29.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
718
+ "model.layers.29.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
719
+ "model.layers.29.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
720
+ "model.layers.29.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
721
+ "model.layers.29.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
722
+ "model.layers.29.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
723
+ "model.layers.29.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
724
+ "model.layers.29.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
725
+ "model.layers.29.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
726
+ "model.layers.29.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
727
+ "model.layers.29.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
728
+ "model.layers.29.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
729
+ "model.layers.29.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
730
+ "model.layers.29.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
731
+ "model.layers.29.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
732
+ "model.layers.29.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
733
+ "model.layers.29.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
734
+ "model.layers.29.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
735
+ "model.layers.29.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
736
+ "model.layers.29.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
737
+ "model.layers.29.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
738
+ "model.layers.29.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
739
+ "model.layers.29.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
740
+ "model.layers.29.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
741
+ "model.layers.29.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
742
+ "model.layers.29.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
743
+ "model.layers.29.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
744
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
745
+ "model.layers.3.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
746
+ "model.layers.3.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
747
+ "model.layers.3.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
748
+ "model.layers.3.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
749
+ "model.layers.3.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
750
+ "model.layers.3.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
751
+ "model.layers.3.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
752
+ "model.layers.3.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
753
+ "model.layers.3.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
754
+ "model.layers.3.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
755
+ "model.layers.3.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
756
+ "model.layers.3.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
757
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
758
+ "model.layers.3.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
759
+ "model.layers.3.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
760
+ "model.layers.3.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
761
+ "model.layers.3.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
762
+ "model.layers.3.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
763
+ "model.layers.3.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
764
+ "model.layers.3.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
765
+ "model.layers.3.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
766
+ "model.layers.3.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
767
+ "model.layers.3.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
768
+ "model.layers.3.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
769
+ "model.layers.3.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
770
+ "model.layers.3.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
771
+ "model.layers.3.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
772
+ "model.layers.3.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
773
+ "model.layers.3.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
774
+ "model.layers.3.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
775
+ "model.layers.3.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
776
+ "model.layers.30.input_layernorm.weight": "model-00001-of-00002.safetensors",
777
+ "model.layers.30.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
778
+ "model.layers.30.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
779
+ "model.layers.30.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
780
+ "model.layers.30.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
781
+ "model.layers.30.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
782
+ "model.layers.30.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
783
+ "model.layers.30.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
784
+ "model.layers.30.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
785
+ "model.layers.30.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
786
+ "model.layers.30.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
787
+ "model.layers.30.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
788
+ "model.layers.30.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
789
+ "model.layers.30.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
790
+ "model.layers.30.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
791
+ "model.layers.30.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
792
+ "model.layers.30.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
793
+ "model.layers.30.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
794
+ "model.layers.30.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
795
+ "model.layers.30.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
796
+ "model.layers.30.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
797
+ "model.layers.30.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
798
+ "model.layers.30.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
799
+ "model.layers.30.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
800
+ "model.layers.30.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
801
+ "model.layers.30.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
802
+ "model.layers.30.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
803
+ "model.layers.30.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
804
+ "model.layers.30.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
805
+ "model.layers.30.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
806
+ "model.layers.30.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
807
+ "model.layers.30.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
808
+ "model.layers.31.input_layernorm.weight": "model-00001-of-00002.safetensors",
809
+ "model.layers.31.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
810
+ "model.layers.31.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
811
+ "model.layers.31.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
812
+ "model.layers.31.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
813
+ "model.layers.31.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
814
+ "model.layers.31.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
815
+ "model.layers.31.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
816
+ "model.layers.31.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
817
+ "model.layers.31.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
818
+ "model.layers.31.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
819
+ "model.layers.31.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
820
+ "model.layers.31.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
821
+ "model.layers.31.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
822
+ "model.layers.31.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
823
+ "model.layers.31.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
824
+ "model.layers.31.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
825
+ "model.layers.31.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
826
+ "model.layers.31.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
827
+ "model.layers.31.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
828
+ "model.layers.31.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
829
+ "model.layers.31.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
830
+ "model.layers.31.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
831
+ "model.layers.31.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
832
+ "model.layers.31.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
833
+ "model.layers.31.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
834
+ "model.layers.31.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
835
+ "model.layers.31.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
836
+ "model.layers.31.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
837
+ "model.layers.31.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
838
+ "model.layers.31.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
839
+ "model.layers.31.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
840
+ "model.layers.32.input_layernorm.weight": "model-00001-of-00002.safetensors",
841
+ "model.layers.32.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
842
+ "model.layers.32.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
843
+ "model.layers.32.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
844
+ "model.layers.32.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
845
+ "model.layers.32.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
846
+ "model.layers.32.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
847
+ "model.layers.32.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
848
+ "model.layers.32.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
849
+ "model.layers.32.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
850
+ "model.layers.32.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
851
+ "model.layers.32.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
852
+ "model.layers.32.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
853
+ "model.layers.32.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
854
+ "model.layers.32.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
855
+ "model.layers.32.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
856
+ "model.layers.32.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
857
+ "model.layers.32.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
858
+ "model.layers.32.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
859
+ "model.layers.32.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
860
+ "model.layers.32.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
861
+ "model.layers.32.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
862
+ "model.layers.32.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
863
+ "model.layers.32.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
864
+ "model.layers.32.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
865
+ "model.layers.32.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
866
+ "model.layers.32.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
867
+ "model.layers.32.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
868
+ "model.layers.32.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
869
+ "model.layers.32.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
870
+ "model.layers.32.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
871
+ "model.layers.32.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
872
+ "model.layers.33.input_layernorm.weight": "model-00001-of-00002.safetensors",
873
+ "model.layers.33.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
874
+ "model.layers.33.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
875
+ "model.layers.33.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
876
+ "model.layers.33.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
877
+ "model.layers.33.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
878
+ "model.layers.33.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
879
+ "model.layers.33.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
880
+ "model.layers.33.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
881
+ "model.layers.33.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
882
+ "model.layers.33.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
883
+ "model.layers.33.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
884
+ "model.layers.33.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
885
+ "model.layers.33.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
886
+ "model.layers.33.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
887
+ "model.layers.33.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
888
+ "model.layers.33.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
889
+ "model.layers.33.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
890
+ "model.layers.33.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
891
+ "model.layers.33.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
892
+ "model.layers.33.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
893
+ "model.layers.33.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
894
+ "model.layers.33.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
895
+ "model.layers.33.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
896
+ "model.layers.33.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
897
+ "model.layers.33.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
898
+ "model.layers.33.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
899
+ "model.layers.33.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
900
+ "model.layers.33.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
901
+ "model.layers.33.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
902
+ "model.layers.33.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
903
+ "model.layers.33.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
904
+ "model.layers.34.input_layernorm.weight": "model-00001-of-00002.safetensors",
905
+ "model.layers.34.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
906
+ "model.layers.34.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
907
+ "model.layers.34.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
908
+ "model.layers.34.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
909
+ "model.layers.34.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
910
+ "model.layers.34.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
911
+ "model.layers.34.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
912
+ "model.layers.34.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
913
+ "model.layers.34.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
914
+ "model.layers.34.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
915
+ "model.layers.34.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
916
+ "model.layers.34.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
917
+ "model.layers.34.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
918
+ "model.layers.34.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
919
+ "model.layers.34.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
920
+ "model.layers.34.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
921
+ "model.layers.34.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
922
+ "model.layers.34.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
923
+ "model.layers.34.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
924
+ "model.layers.34.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
925
+ "model.layers.34.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
926
+ "model.layers.34.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
927
+ "model.layers.34.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
928
+ "model.layers.34.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
929
+ "model.layers.34.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
930
+ "model.layers.34.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
931
+ "model.layers.34.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
932
+ "model.layers.34.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
933
+ "model.layers.34.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
934
+ "model.layers.34.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
935
+ "model.layers.34.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
936
+ "model.layers.35.input_layernorm.weight": "model-00001-of-00002.safetensors",
937
+ "model.layers.35.mlp.down_proj.g_idx": "model-00002-of-00002.safetensors",
938
+ "model.layers.35.mlp.down_proj.qweight": "model-00002-of-00002.safetensors",
939
+ "model.layers.35.mlp.down_proj.qzeros": "model-00002-of-00002.safetensors",
940
+ "model.layers.35.mlp.down_proj.scales": "model-00002-of-00002.safetensors",
941
+ "model.layers.35.mlp.gate_proj.g_idx": "model-00002-of-00002.safetensors",
942
+ "model.layers.35.mlp.gate_proj.qweight": "model-00002-of-00002.safetensors",
943
+ "model.layers.35.mlp.gate_proj.qzeros": "model-00002-of-00002.safetensors",
944
+ "model.layers.35.mlp.gate_proj.scales": "model-00002-of-00002.safetensors",
945
+ "model.layers.35.mlp.up_proj.g_idx": "model-00002-of-00002.safetensors",
946
+ "model.layers.35.mlp.up_proj.qweight": "model-00002-of-00002.safetensors",
947
+ "model.layers.35.mlp.up_proj.qzeros": "model-00002-of-00002.safetensors",
948
+ "model.layers.35.mlp.up_proj.scales": "model-00002-of-00002.safetensors",
949
+ "model.layers.35.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
950
+ "model.layers.35.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
951
+ "model.layers.35.self_attn.k_proj.g_idx": "model-00002-of-00002.safetensors",
952
+ "model.layers.35.self_attn.k_proj.qweight": "model-00002-of-00002.safetensors",
953
+ "model.layers.35.self_attn.k_proj.qzeros": "model-00002-of-00002.safetensors",
954
+ "model.layers.35.self_attn.k_proj.scales": "model-00002-of-00002.safetensors",
955
+ "model.layers.35.self_attn.o_proj.g_idx": "model-00002-of-00002.safetensors",
956
+ "model.layers.35.self_attn.o_proj.qweight": "model-00002-of-00002.safetensors",
957
+ "model.layers.35.self_attn.o_proj.qzeros": "model-00002-of-00002.safetensors",
958
+ "model.layers.35.self_attn.o_proj.scales": "model-00002-of-00002.safetensors",
959
+ "model.layers.35.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
960
+ "model.layers.35.self_attn.q_proj.g_idx": "model-00002-of-00002.safetensors",
961
+ "model.layers.35.self_attn.q_proj.qweight": "model-00002-of-00002.safetensors",
962
+ "model.layers.35.self_attn.q_proj.qzeros": "model-00002-of-00002.safetensors",
963
+ "model.layers.35.self_attn.q_proj.scales": "model-00002-of-00002.safetensors",
964
+ "model.layers.35.self_attn.v_proj.g_idx": "model-00002-of-00002.safetensors",
965
+ "model.layers.35.self_attn.v_proj.qweight": "model-00002-of-00002.safetensors",
966
+ "model.layers.35.self_attn.v_proj.qzeros": "model-00002-of-00002.safetensors",
967
+ "model.layers.35.self_attn.v_proj.scales": "model-00002-of-00002.safetensors",
968
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
969
+ "model.layers.4.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
970
+ "model.layers.4.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
971
+ "model.layers.4.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
972
+ "model.layers.4.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
973
+ "model.layers.4.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
974
+ "model.layers.4.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
975
+ "model.layers.4.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
976
+ "model.layers.4.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
977
+ "model.layers.4.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
978
+ "model.layers.4.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
979
+ "model.layers.4.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
980
+ "model.layers.4.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
981
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
982
+ "model.layers.4.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
983
+ "model.layers.4.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
984
+ "model.layers.4.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
985
+ "model.layers.4.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
986
+ "model.layers.4.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
987
+ "model.layers.4.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
988
+ "model.layers.4.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
989
+ "model.layers.4.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
990
+ "model.layers.4.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
991
+ "model.layers.4.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
992
+ "model.layers.4.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
993
+ "model.layers.4.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
994
+ "model.layers.4.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
995
+ "model.layers.4.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
996
+ "model.layers.4.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
997
+ "model.layers.4.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
998
+ "model.layers.4.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
999
+ "model.layers.4.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
1000
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
1001
+ "model.layers.5.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
1002
+ "model.layers.5.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
1003
+ "model.layers.5.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
1004
+ "model.layers.5.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
1005
+ "model.layers.5.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
1006
+ "model.layers.5.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
1007
+ "model.layers.5.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
1008
+ "model.layers.5.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
1009
+ "model.layers.5.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
1010
+ "model.layers.5.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
1011
+ "model.layers.5.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
1012
+ "model.layers.5.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
1013
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
1014
+ "model.layers.5.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
1015
+ "model.layers.5.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
1016
+ "model.layers.5.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
1017
+ "model.layers.5.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
1018
+ "model.layers.5.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
1019
+ "model.layers.5.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
1020
+ "model.layers.5.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
1021
+ "model.layers.5.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
1022
+ "model.layers.5.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
1023
+ "model.layers.5.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
1024
+ "model.layers.5.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
1025
+ "model.layers.5.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
1026
+ "model.layers.5.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
1027
+ "model.layers.5.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
1028
+ "model.layers.5.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
1029
+ "model.layers.5.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
1030
+ "model.layers.5.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
1031
+ "model.layers.5.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
1032
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
1033
+ "model.layers.6.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
1034
+ "model.layers.6.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
1035
+ "model.layers.6.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
1036
+ "model.layers.6.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
1037
+ "model.layers.6.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
1038
+ "model.layers.6.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
1039
+ "model.layers.6.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
1040
+ "model.layers.6.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
1041
+ "model.layers.6.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
1042
+ "model.layers.6.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
1043
+ "model.layers.6.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
1044
+ "model.layers.6.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
1045
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
1046
+ "model.layers.6.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
1047
+ "model.layers.6.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
1048
+ "model.layers.6.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
1049
+ "model.layers.6.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
1050
+ "model.layers.6.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
1051
+ "model.layers.6.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
1052
+ "model.layers.6.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
1053
+ "model.layers.6.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
1054
+ "model.layers.6.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
1055
+ "model.layers.6.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
1056
+ "model.layers.6.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
1057
+ "model.layers.6.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
1058
+ "model.layers.6.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
1059
+ "model.layers.6.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
1060
+ "model.layers.6.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
1061
+ "model.layers.6.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
1062
+ "model.layers.6.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
1063
+ "model.layers.6.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
1064
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
1065
+ "model.layers.7.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
1066
+ "model.layers.7.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
1067
+ "model.layers.7.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
1068
+ "model.layers.7.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
1069
+ "model.layers.7.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
1070
+ "model.layers.7.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
1071
+ "model.layers.7.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
1072
+ "model.layers.7.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
1073
+ "model.layers.7.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
1074
+ "model.layers.7.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
1075
+ "model.layers.7.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
1076
+ "model.layers.7.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
1077
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
1078
+ "model.layers.7.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
1079
+ "model.layers.7.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
1080
+ "model.layers.7.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
1081
+ "model.layers.7.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
1082
+ "model.layers.7.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
1083
+ "model.layers.7.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
1084
+ "model.layers.7.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
1085
+ "model.layers.7.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
1086
+ "model.layers.7.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
1087
+ "model.layers.7.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
1088
+ "model.layers.7.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
1089
+ "model.layers.7.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
1090
+ "model.layers.7.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
1091
+ "model.layers.7.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
1092
+ "model.layers.7.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
1093
+ "model.layers.7.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
1094
+ "model.layers.7.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
1095
+ "model.layers.7.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
1096
+ "model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
1097
+ "model.layers.8.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
1098
+ "model.layers.8.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
1099
+ "model.layers.8.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
1100
+ "model.layers.8.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
1101
+ "model.layers.8.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
1102
+ "model.layers.8.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
1103
+ "model.layers.8.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
1104
+ "model.layers.8.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
1105
+ "model.layers.8.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
1106
+ "model.layers.8.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
1107
+ "model.layers.8.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
1108
+ "model.layers.8.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
1109
+ "model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
1110
+ "model.layers.8.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
1111
+ "model.layers.8.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
1112
+ "model.layers.8.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
1113
+ "model.layers.8.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
1114
+ "model.layers.8.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
1115
+ "model.layers.8.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
1116
+ "model.layers.8.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
1117
+ "model.layers.8.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
1118
+ "model.layers.8.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
1119
+ "model.layers.8.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
1120
+ "model.layers.8.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
1121
+ "model.layers.8.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
1122
+ "model.layers.8.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
1123
+ "model.layers.8.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
1124
+ "model.layers.8.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
1125
+ "model.layers.8.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
1126
+ "model.layers.8.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
1127
+ "model.layers.8.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
1128
+ "model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
1129
+ "model.layers.9.mlp.down_proj.g_idx": "model-00001-of-00002.safetensors",
1130
+ "model.layers.9.mlp.down_proj.qweight": "model-00001-of-00002.safetensors",
1131
+ "model.layers.9.mlp.down_proj.qzeros": "model-00001-of-00002.safetensors",
1132
+ "model.layers.9.mlp.down_proj.scales": "model-00001-of-00002.safetensors",
1133
+ "model.layers.9.mlp.gate_proj.g_idx": "model-00001-of-00002.safetensors",
1134
+ "model.layers.9.mlp.gate_proj.qweight": "model-00001-of-00002.safetensors",
1135
+ "model.layers.9.mlp.gate_proj.qzeros": "model-00001-of-00002.safetensors",
1136
+ "model.layers.9.mlp.gate_proj.scales": "model-00001-of-00002.safetensors",
1137
+ "model.layers.9.mlp.up_proj.g_idx": "model-00001-of-00002.safetensors",
1138
+ "model.layers.9.mlp.up_proj.qweight": "model-00001-of-00002.safetensors",
1139
+ "model.layers.9.mlp.up_proj.qzeros": "model-00001-of-00002.safetensors",
1140
+ "model.layers.9.mlp.up_proj.scales": "model-00001-of-00002.safetensors",
1141
+ "model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
1142
+ "model.layers.9.self_attn.k_norm.weight": "model-00001-of-00002.safetensors",
1143
+ "model.layers.9.self_attn.k_proj.g_idx": "model-00001-of-00002.safetensors",
1144
+ "model.layers.9.self_attn.k_proj.qweight": "model-00001-of-00002.safetensors",
1145
+ "model.layers.9.self_attn.k_proj.qzeros": "model-00001-of-00002.safetensors",
1146
+ "model.layers.9.self_attn.k_proj.scales": "model-00001-of-00002.safetensors",
1147
+ "model.layers.9.self_attn.o_proj.g_idx": "model-00001-of-00002.safetensors",
1148
+ "model.layers.9.self_attn.o_proj.qweight": "model-00001-of-00002.safetensors",
1149
+ "model.layers.9.self_attn.o_proj.qzeros": "model-00001-of-00002.safetensors",
1150
+ "model.layers.9.self_attn.o_proj.scales": "model-00001-of-00002.safetensors",
1151
+ "model.layers.9.self_attn.q_norm.weight": "model-00001-of-00002.safetensors",
1152
+ "model.layers.9.self_attn.q_proj.g_idx": "model-00001-of-00002.safetensors",
1153
+ "model.layers.9.self_attn.q_proj.qweight": "model-00001-of-00002.safetensors",
1154
+ "model.layers.9.self_attn.q_proj.qzeros": "model-00001-of-00002.safetensors",
1155
+ "model.layers.9.self_attn.q_proj.scales": "model-00001-of-00002.safetensors",
1156
+ "model.layers.9.self_attn.v_proj.g_idx": "model-00001-of-00002.safetensors",
1157
+ "model.layers.9.self_attn.v_proj.qweight": "model-00001-of-00002.safetensors",
1158
+ "model.layers.9.self_attn.v_proj.qzeros": "model-00001-of-00002.safetensors",
1159
+ "model.layers.9.self_attn.v_proj.scales": "model-00001-of-00002.safetensors",
1160
+ "model.norm.weight": "model-00001-of-00002.safetensors",
1161
+ "emb_ext.0.weight": "moss_extras.safetensors",
1162
+ "emb_ext.1.weight": "moss_extras.safetensors",
1163
+ "emb_ext.10.weight": "moss_extras.safetensors",
1164
+ "emb_ext.11.weight": "moss_extras.safetensors",
1165
+ "emb_ext.12.weight": "moss_extras.safetensors",
1166
+ "emb_ext.13.weight": "moss_extras.safetensors",
1167
+ "emb_ext.14.weight": "moss_extras.safetensors",
1168
+ "emb_ext.15.weight": "moss_extras.safetensors",
1169
+ "emb_ext.16.weight": "moss_extras.safetensors",
1170
+ "emb_ext.17.weight": "moss_extras.safetensors",
1171
+ "emb_ext.18.weight": "moss_extras.safetensors",
1172
+ "emb_ext.19.weight": "moss_extras.safetensors",
1173
+ "emb_ext.2.weight": "moss_extras.safetensors",
1174
+ "emb_ext.20.weight": "moss_extras.safetensors",
1175
+ "emb_ext.21.weight": "moss_extras.safetensors",
1176
+ "emb_ext.22.weight": "moss_extras.safetensors",
1177
+ "emb_ext.23.weight": "moss_extras.safetensors",
1178
+ "emb_ext.24.weight": "moss_extras.safetensors",
1179
+ "emb_ext.25.weight": "moss_extras.safetensors",
1180
+ "emb_ext.26.weight": "moss_extras.safetensors",
1181
+ "emb_ext.27.weight": "moss_extras.safetensors",
1182
+ "emb_ext.28.weight": "moss_extras.safetensors",
1183
+ "emb_ext.29.weight": "moss_extras.safetensors",
1184
+ "emb_ext.3.weight": "moss_extras.safetensors",
1185
+ "emb_ext.30.weight": "moss_extras.safetensors",
1186
+ "emb_ext.31.weight": "moss_extras.safetensors",
1187
+ "emb_ext.4.weight": "moss_extras.safetensors",
1188
+ "emb_ext.5.weight": "moss_extras.safetensors",
1189
+ "emb_ext.6.weight": "moss_extras.safetensors",
1190
+ "emb_ext.7.weight": "moss_extras.safetensors",
1191
+ "emb_ext.8.weight": "moss_extras.safetensors",
1192
+ "emb_ext.9.weight": "moss_extras.safetensors",
1193
+ "language_model.norm.weight": "moss_extras.safetensors",
1194
+ "lm_heads.0.weight": "moss_extras.safetensors",
1195
+ "lm_heads.1.weight": "moss_extras.safetensors",
1196
+ "lm_heads.10.weight": "moss_extras.safetensors",
1197
+ "lm_heads.11.weight": "moss_extras.safetensors",
1198
+ "lm_heads.12.weight": "moss_extras.safetensors",
1199
+ "lm_heads.13.weight": "moss_extras.safetensors",
1200
+ "lm_heads.14.weight": "moss_extras.safetensors",
1201
+ "lm_heads.15.weight": "moss_extras.safetensors",
1202
+ "lm_heads.16.weight": "moss_extras.safetensors",
1203
+ "lm_heads.17.weight": "moss_extras.safetensors",
1204
+ "lm_heads.18.weight": "moss_extras.safetensors",
1205
+ "lm_heads.19.weight": "moss_extras.safetensors",
1206
+ "lm_heads.2.weight": "moss_extras.safetensors",
1207
+ "lm_heads.20.weight": "moss_extras.safetensors",
1208
+ "lm_heads.21.weight": "moss_extras.safetensors",
1209
+ "lm_heads.22.weight": "moss_extras.safetensors",
1210
+ "lm_heads.23.weight": "moss_extras.safetensors",
1211
+ "lm_heads.24.weight": "moss_extras.safetensors",
1212
+ "lm_heads.25.weight": "moss_extras.safetensors",
1213
+ "lm_heads.26.weight": "moss_extras.safetensors",
1214
+ "lm_heads.27.weight": "moss_extras.safetensors",
1215
+ "lm_heads.28.weight": "moss_extras.safetensors",
1216
+ "lm_heads.29.weight": "moss_extras.safetensors",
1217
+ "lm_heads.3.weight": "moss_extras.safetensors",
1218
+ "lm_heads.30.weight": "moss_extras.safetensors",
1219
+ "lm_heads.31.weight": "moss_extras.safetensors",
1220
+ "lm_heads.32.weight": "moss_extras.safetensors",
1221
+ "lm_heads.4.weight": "moss_extras.safetensors",
1222
+ "lm_heads.5.weight": "moss_extras.safetensors",
1223
+ "lm_heads.6.weight": "moss_extras.safetensors",
1224
+ "lm_heads.7.weight": "moss_extras.safetensors",
1225
+ "lm_heads.8.weight": "moss_extras.safetensors",
1226
+ "lm_heads.9.weight": "moss_extras.safetensors"
1227
+ }
1228
+ }
modeling_moss_tts.py ADDED
@@ -0,0 +1,512 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2026 OpenMOSS and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """ Modeling classes for MossTTSDelay. """
16
+
17
+ from dataclasses import dataclass
18
+ from typing import List, Optional, Tuple, Union
19
+ from tqdm import tqdm
20
+
21
+ import torch
22
+ import torch.nn as nn
23
+ from torch.nn import CrossEntropyLoss
24
+
25
+ from transformers.modeling_utils import PreTrainedModel
26
+ from transformers.modeling_outputs import ModelOutput
27
+ from transformers.utils import (
28
+ add_start_docstrings,
29
+ add_start_docstrings_to_model_forward,
30
+ logging,
31
+ replace_return_docstrings,
32
+ )
33
+ from transformers.cache_utils import Cache
34
+ from transformers.models.qwen3 import Qwen3Model
35
+ from transformers import initialization as init
36
+
37
+ from .configuration_moss_tts import MossTTSDelayConfig
38
+ from .inference_utils import sample_token, find_last_equal_C
39
+
40
+ try:
41
+ from .processing_moss_tts import UserMessage, AssistantMessage, MossTTSDelayProcessor
42
+ except Exception:
43
+ UserMessage = None
44
+ AssistantMessage = None
45
+ MossTTSDelayProcessor = None
46
+
47
+ logger = logging.get_logger(__name__)
48
+
49
+ _CONFIG_FOR_DOC = "MossTTSDelayConfig"
50
+
51
+
52
+ @dataclass
53
+ class MossTTSDelayOutputWithPast(ModelOutput):
54
+ """
55
+ Base class for model's outputs that may also contain a past key/values (to speed up sequential decoding).
56
+
57
+ Args:
58
+ loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
59
+ Weighted sum of channel losses.
60
+ all_sum_losses (`torch.FloatTensor` of shape `(batch_size, n_vq + 1)`, *optional*):
61
+ Sum of losses for each sample and each channel before averaging.
62
+ all_token_nums (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
63
+ Number of non-masked tokens per sample.
64
+ sample_losses (`torch.FloatTensor` of shape `(batch_size,)`, *optional*):
65
+ Loss per sample.
66
+ channel_losses (`torch.FloatTensor` of shape `(n_vq + 1,)`, *optional*):
67
+ Loss per channel (text head + vq heads).
68
+ logits (`List[torch.FloatTensor]`, *optional*):
69
+ List of prediction scores from each head.
70
+ past_key_values (`Cache`, *optional*):
71
+ Pre-computed hidden-states (key and values in the self-attention blocks).
72
+ hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed):
73
+ Tuple of torch.FloatTensor (one for the output of the embeddings, if the model has an embedding layer, +
74
+ one for the output of each layer).
75
+ attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed):
76
+ Tuple of torch.FloatTensor (one for each layer) of the attention weights.
77
+ """
78
+ loss: Optional[torch.FloatTensor] = None
79
+ all_sum_losses: Optional[torch.FloatTensor] = None
80
+ all_token_nums: Optional[torch.LongTensor] = None
81
+ sample_losses: Optional[torch.FloatTensor] = None
82
+ channel_losses: Optional[torch.FloatTensor] = None
83
+ logits: Optional[List[torch.FloatTensor]] = None
84
+ past_key_values: Optional[Cache] = None
85
+ hidden_states: Optional[Tuple[torch.FloatTensor]] = None
86
+ attentions: Optional[Tuple[torch.FloatTensor]] = None
87
+
88
+
89
+
90
+
91
+ class MossTTSDelayPreTrainedModel(PreTrainedModel):
92
+ config_class = MossTTSDelayConfig
93
+ base_model_prefix = "model"
94
+ supports_gradient_checkpointing = True
95
+ _no_split_modules = ["Qwen3DecoderLayer"]
96
+ _skip_keys_device_placement = "past_key_values"
97
+ _supports_flash_attn = True
98
+ _supports_flash_attn_2 = True
99
+ _supports_sdpa = True
100
+ _supports_flex_attn = True
101
+
102
+ def _init_weights(self, module):
103
+ """
104
+ Transformers 5.0+ safe init:
105
+ - MUST use transformers.initialization helpers
106
+ - MUST respect param._is_hf_initialized to avoid overwriting ckpt-loaded params
107
+ """
108
+ # Let HF handle its standard modules first (LayerNorm, Linear, Embedding, etc.)
109
+ super()._init_weights(module)
110
+
111
+ # Pick a std consistent with HF conventions
112
+ # Prefer model/text config initializer_range if present.
113
+ std = None
114
+ if hasattr(self.config, "initializer_range"):
115
+ std = self.config.initializer_range
116
+ elif hasattr(self.config, "language_config") and hasattr(self.config.language_config, "initializer_range"):
117
+ std = self.config.language_config.initializer_range
118
+ else:
119
+ std = 0.02
120
+
121
+ # Initialize extra audio embeddings
122
+ if isinstance(module, nn.Embedding):
123
+ # Only touch our extra embeddings (avoid double touching LM's embeddings if not desired)
124
+ # If you prefer, you can skip this check and rely on super()._init_weights for all embeddings.
125
+ if getattr(module, "num_embeddings", None) == self.config.audio_vocab_size + 1:
126
+ init.normal_(module.weight, mean=0.0, std=std)
127
+ # If you later set padding_idx, you must explicitly zero it (and respect _is_hf_initialized!)
128
+ # init.zeros_ will internally check param flags, but slicing needs manual care.
129
+
130
+ # Initialize multi-head projections you added
131
+ if isinstance(module, nn.Linear):
132
+ # For your lm_heads, super()._init_weights already covers typical Linear.
133
+ # This block is only needed if you have custom Linear variants later.
134
+ pass
135
+
136
+
137
+
138
+ MOSSTTS_START_DOCSTRING = r"""
139
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
140
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
141
+ etc.)
142
+
143
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
144
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
145
+ and behavior.
146
+
147
+ Parameters:
148
+ config ([`MossTTSDelayConfig`]):
149
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
150
+ load the weights associated with the model, only the configuration. Check out the
151
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
152
+ """
153
+
154
+
155
+ @add_start_docstrings(
156
+ "The MossTTSDelay Model architecture tailored for Text-to-Speech generation with multi-head VQ prediction.",
157
+ MOSSTTS_START_DOCSTRING,
158
+ )
159
+ class MossTTSDelayModel(MossTTSDelayPreTrainedModel):
160
+ UserMessage = UserMessage
161
+ AssistantMessage = AssistantMessage
162
+ Processor = MossTTSDelayProcessor
163
+
164
+ def __init__(self, config: MossTTSDelayConfig):
165
+ super().__init__(config)
166
+ self.config = config
167
+
168
+ config.language_config.torch_dtype = config.torch_dtype
169
+
170
+ self.language_model = Qwen3Model(config.language_config)
171
+
172
+ # Audio VQ Embeddings (Extra channels)
173
+ # Note: input_ids[..., 0] uses Qwen's embedding.
174
+ # input_ids[..., 1:] use these extensions.
175
+ self.emb_ext = nn.ModuleList()
176
+ for vq_idx in range(self.config.n_vq):
177
+ # Add +1 for potential padding/special tokens logic if strictly required by upstream data prep
178
+ self.emb_ext.append(
179
+ nn.Embedding(self.config.audio_vocab_size + 1, config.language_config.hidden_size, padding_idx=None)
180
+ )
181
+
182
+ # Multi-Head Prediction Layers
183
+ # Head 0: Main language head
184
+ # Head 1..N: Audio VQ heads
185
+ self.lm_heads = nn.ModuleList([
186
+ nn.Linear(config.language_config.hidden_size, config.language_config.vocab_size, bias=False)
187
+ ])
188
+ for vq_idx in range(self.config.n_vq):
189
+ self.lm_heads.append(
190
+ nn.Linear(config.language_config.hidden_size, self.config.audio_vocab_size + 1, bias=False)
191
+ )
192
+
193
+ # Initialize weights and apply final processing
194
+ self.post_init()
195
+
196
+ def get_input_embeddings(self, input_ids: torch.LongTensor) -> torch.Tensor:
197
+ inputs_embeds = self.language_model.get_input_embeddings()(input_ids[..., 0])
198
+ for i, embed_layer in enumerate(self.emb_ext):
199
+ inputs_embeds = inputs_embeds + embed_layer(input_ids[..., i + 1])
200
+ return inputs_embeds.to(torch.float16) # ← force fp16
201
+
202
+ def set_input_embeddings(self, value):
203
+ self.language_model.embed_tokens = value
204
+
205
+ def get_output_embeddings(self):
206
+ # Returning a list of heads might break some HF utilities expecting a single head.
207
+ # However, for custom models, this is acceptable.
208
+ return self.lm_heads
209
+
210
+ @add_start_docstrings_to_model_forward(MOSSTTS_START_DOCSTRING)
211
+ @replace_return_docstrings(output_type=MossTTSDelayOutputWithPast, config_class=_CONFIG_FOR_DOC)
212
+ def forward(
213
+ self,
214
+ input_ids: Optional[torch.LongTensor] = None,
215
+ attention_mask: Optional[torch.Tensor] = None,
216
+ position_ids: Optional[torch.LongTensor] = None,
217
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
218
+ inputs_embeds: Optional[torch.FloatTensor] = None,
219
+ labels: Optional[torch.LongTensor] = None,
220
+ use_cache: Optional[bool] = None,
221
+ output_attentions: Optional[bool] = None,
222
+ cache_position: Optional[torch.LongTensor] = None,
223
+ hidden_out_layers: Optional[List[int]] = None,
224
+ channelwise_loss_weight: Optional[List[float]] = None,
225
+ **kwargs,
226
+ ) -> Union[Tuple, MossTTSDelayOutputWithPast]:
227
+ r"""
228
+ Args:
229
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length, 1 + n_vq)`):
230
+ Indices of input sequence tokens in the vocabulary.
231
+ Dimension 2 contains: [Text/Semantics, VQ_0, VQ_1, ..., VQ_N].
232
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length, 1 + n_vq)`, *optional*):
233
+ Labels for computing the masked language modeling loss.
234
+ channelwise_loss_weight (`List[float]`, *optional*):
235
+ Manual weights for summing losses across different heads (Text vs Audio channels).
236
+
237
+ Returns:
238
+ """
239
+
240
+ if len(input_ids.shape) != 3 or input_ids.shape[-1] != self.config.n_vq + 1:
241
+ raise ValueError("`Input_ids`'s shape should be exactly (batch_size, sequence_length, 1 + n_vq).")
242
+
243
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
244
+
245
+ # 1. Prepare Embeddings
246
+ if inputs_embeds is None:
247
+ inputs_embeds = self.get_input_embeddings(input_ids)
248
+
249
+ # 2. Backbone Forward
250
+ # Qwen3Model outputs standard CausalLMOutputWithPast or similar
251
+ outputs = self.language_model(
252
+ input_ids=None, # Passed via inputs_embeds
253
+ position_ids=position_ids,
254
+ attention_mask=attention_mask,
255
+ past_key_values=past_key_values,
256
+ inputs_embeds=inputs_embeds,
257
+ use_cache=use_cache,
258
+ output_attentions=output_attentions,
259
+ output_hidden_states=True, # Always need hidden states for multi-head projection
260
+ return_dict=True,
261
+ cache_position=cache_position,
262
+ **kwargs,
263
+ )
264
+
265
+ # 3. Handle specific layer outputs if requested (Delay Pattern often requires features from specific layers)
266
+ last_hidden_state = outputs.last_hidden_state
267
+ if hidden_out_layers is None:
268
+ # Default to using the last layer for all heads
269
+ # In some architectures (like MusicGen), different codebooks come from different transformer layers.
270
+ # Here we default to the final layer as per original code behavior [-1] * (n + 1).
271
+ hidden_states_for_heads = [last_hidden_state] * (len(self.lm_heads))
272
+ else:
273
+ # If hidden_out_layers is provided (e.g. [-1, -2, -3...]), fetch them from all_hidden_states
274
+ # Note: outputs.hidden_states includes embedding output at index 0 usually.
275
+ all_hs = outputs.hidden_states
276
+ hidden_states_for_heads = [all_hs[idx] for idx in hidden_out_layers]
277
+
278
+ # 4. Project to Logits (Multi-Head)
279
+ layer_logits = []
280
+ for i, (hs, head) in enumerate(zip(hidden_states_for_heads, self.lm_heads)):
281
+ logits = head(hs)
282
+ # Original code logic: Mask the last token index for audio heads (indices > 0)
283
+ # This implies the vocab size is (N+1) but the model shouldn't predict the (N+1)-th token
284
+ # (perhaps reserved for padding in the input but invalid for prediction).
285
+ if i > 0:
286
+ logits[..., -1] = float("-inf")
287
+ layer_logits.append(logits)
288
+
289
+ # 5. Loss Calculation
290
+ loss = None
291
+ all_sum_losses = None
292
+ all_token_nums = None
293
+ sample_losses = None
294
+ channel_losses = None
295
+
296
+ if labels is not None:
297
+ # Ensure labels match input shape rank (B, S, C)
298
+ if labels.dim() != 3:
299
+ raise ValueError(f"Labels must have rank 3 (B, S, C), got {labels.shape}")
300
+
301
+ batch_size = labels.size(0)
302
+ n_heads = len(layer_logits)
303
+
304
+ # Container for per-sample, per-channel losses
305
+ # Shape: [Batch, n_heads]
306
+ all_sum_losses_list = []
307
+
308
+ # Count valid tokens (not -100) per sample.
309
+ # Note: Assuming mask is consistent across channels or we take sum over dim 1 (seq)
310
+ # Usually strict masking means checking one channel or all.
311
+ # Original code: torch.sum(labels != -100, dim=1) -> [B, C]
312
+ all_token_nums = torch.sum(labels != -100, dim=1)
313
+
314
+ for i, logits in enumerate(layer_logits):
315
+ # logits: [B, S, V]
316
+ # cur_labels: [B, S]
317
+ cur_labels = labels[..., i]
318
+
319
+ # Flatten for CrossEntropy
320
+ # logits: [B*S, V], labels: [B*S]
321
+ loss_fct = CrossEntropyLoss(reduction='none')
322
+ vocab_size = logits.size(-1)
323
+
324
+ reshaped_logits = logits.view(-1, vocab_size)
325
+ reshaped_labels = cur_labels.contiguous().view(-1)
326
+
327
+ # Calculate loss per token
328
+ per_token_loss = loss_fct(reshaped_logits, reshaped_labels)
329
+
330
+ # Reshape back to [B, S] and sum over Sequence dimension to get per-sample loss
331
+ per_token_loss = per_token_loss.view(batch_size, -1)
332
+ per_sample_loss = torch.sum(per_token_loss, dim=-1) # [B]
333
+
334
+ all_sum_losses_list.append(per_sample_loss)
335
+
336
+ # Stack to [B, n_heads]
337
+ all_sum_losses = torch.stack(all_sum_losses_list, dim=1)
338
+
339
+ # Weighted Loss Aggregation
340
+ if channelwise_loss_weight is not None:
341
+ if len(channelwise_loss_weight) != n_heads:
342
+ raise ValueError(f"channelwise_loss_weight length {len(channelwise_loss_weight)} != {n_heads}")
343
+
344
+ w_tensor = torch.tensor(channelwise_loss_weight, device=all_sum_losses.device, dtype=all_sum_losses.dtype)
345
+
346
+ # Sample losses: Weighted sum over channels per sample / Total weight
347
+ # Normalize by token count per channel
348
+ # Avoid division by zero with epsilon or mask
349
+ token_counts_safe = all_token_nums.float().clamp(min=1.0)
350
+
351
+ normalized_losses = all_sum_losses / token_counts_safe
352
+ sample_losses = (normalized_losses * w_tensor).sum(dim=1) / w_tensor.sum()
353
+
354
+ # Channel losses: Sum over batch / Sum tokens over batch
355
+ total_loss_per_channel = all_sum_losses.sum(dim=0)
356
+ total_tokens_per_channel = all_token_nums.sum(dim=0).float().clamp(min=1.0)
357
+ channel_losses = total_loss_per_channel / total_tokens_per_channel
358
+
359
+ # Final scalar loss
360
+ loss = (channel_losses * w_tensor).sum() / w_tensor.sum()
361
+ else:
362
+ # Default average if no weights provided
363
+ total_tokens = all_token_nums.sum().float().clamp(min=1.0)
364
+ loss = all_sum_losses.sum() / total_tokens
365
+ channel_losses = all_sum_losses.sum(dim=0) / all_token_nums.sum(dim=0).clamp(min=1.0)
366
+
367
+ return MossTTSDelayOutputWithPast(
368
+ loss=loss,
369
+ all_sum_losses=all_sum_losses,
370
+ all_token_nums=all_token_nums,
371
+ sample_losses=sample_losses,
372
+ channel_losses=channel_losses,
373
+ logits=layer_logits,
374
+ past_key_values=outputs.past_key_values,
375
+ hidden_states=outputs.hidden_states,
376
+ attentions=outputs.attentions,
377
+ )
378
+
379
+ @torch.inference_mode()
380
+ def generate(
381
+ self,
382
+ input_ids: torch.LongTensor,
383
+ attention_mask: Optional[torch.Tensor] = None,
384
+ max_new_tokens: int = 1000,
385
+ text_temperature: float = 1.5,
386
+ text_top_p: float = 1.0,
387
+ text_top_k: int = 50,
388
+ audio_temperature: float = 1.7,
389
+ audio_top_p: float = 0.8,
390
+ audio_top_k: int = 25,
391
+ audio_repetition_penalty: float = 1.0,
392
+ ):
393
+ if text_temperature > 0:
394
+ text_do_sample = True
395
+ else:
396
+ text_temperature = 1
397
+ text_do_sample = False
398
+ if audio_temperature > 0:
399
+ audio_do_sample = True
400
+ else:
401
+ audio_temperature = 1
402
+ audio_do_sample = False
403
+
404
+ past_key_values = None
405
+ device = input_ids.device
406
+ current_input_ids = input_ids
407
+ current_attention_mask = attention_mask
408
+ batch_size, seq_len, n_vq = input_ids.shape
409
+ n_vq -= 1
410
+
411
+ generation_ids = input_ids[:]
412
+ is_stopping = torch.zeros(batch_size, dtype=torch.bool, device=device)
413
+
414
+ audio_lengths = torch.zeros(batch_size, dtype=torch.int64, device=device)
415
+ torch_int64_max = torch.iinfo(torch.int64).max
416
+ delayed_lengths = torch.full((batch_size,), torch_int64_max, dtype=torch.int64, device=device)
417
+
418
+ is_continuation = (input_ids[:, -1, 0] == self.config.audio_start_token_id) | (input_ids[:, -1, 0] == self.config.audio_assistant_gen_slot_token_id)
419
+ audio_start_indices = find_last_equal_C(input_ids[..., 0], self.config.audio_start_token_id)
420
+ audio_start_mask = is_continuation & (audio_start_indices != -1)
421
+ audio_lengths[audio_start_mask] = seq_len - audio_start_indices[audio_start_mask]
422
+
423
+ is_audio = audio_start_mask.clone()
424
+
425
+ pre_exclude_mask0 = torch.tensor([self.config.pad_token_id, self.config.audio_assistant_gen_slot_token_id, self.config.audio_assistant_delay_slot_token_id, self.config.audio_end_token_id], device=device)
426
+ pre_exclude_mask1 = torch.ones(self.config.language_config.vocab_size, device=device).bool()
427
+ pre_exclude_mask1[[self.config.audio_assistant_gen_slot_token_id, self.config.audio_assistant_delay_slot_token_id]] = False
428
+
429
+ for time_step in tqdm(range(max_new_tokens), desc=f"Generating bs{batch_size} ..."):
430
+ outputs = self(
431
+ input_ids=current_input_ids,
432
+ attention_mask=current_attention_mask,
433
+ past_key_values=past_key_values,
434
+ use_cache=True,
435
+ )
436
+ past_key_values = outputs.past_key_values
437
+
438
+ next_token_logits = [logit[:, -1, :] / text_temperature if logit_idx == 0 else logit[:, -1, :] / audio_temperature for logit_idx, logit in enumerate(outputs.logits)] # List, len=n_vq+1, [batch_size, 1, vocab_size];
439
+ next_token_logits[0] = next_token_logits[0].clone()
440
+ next_text_token = torch.full((batch_size,), self.config.pad_token_id, device=device)
441
+ next_text_token[~is_stopping & (delayed_lengths < n_vq)] = self.config.audio_assistant_delay_slot_token_id
442
+ is_audio_eos = ~is_stopping & (delayed_lengths == n_vq)
443
+ next_text_token[is_audio_eos] = self.config.audio_end_token_id
444
+ is_audio[is_audio_eos] = False
445
+ sampling_text_mask = ~is_stopping & (delayed_lengths > n_vq)
446
+ next_token_logits[0][~is_audio] = next_token_logits[0][~is_audio].index_fill(-1, pre_exclude_mask0, float('-inf'))
447
+ next_token_logits[0][is_audio] = next_token_logits[0][is_audio].masked_fill(pre_exclude_mask1, float('-inf'))
448
+ if time_step == 0:
449
+ next_token_logits[0][..., 151662] = float('-inf')
450
+ if time_step <= n_vq:
451
+ next_token_logits[0][..., self.config.im_end_token_id] = float('-inf')
452
+
453
+ next_text_token[sampling_text_mask] = sample_token(
454
+ logits=next_token_logits[0][sampling_text_mask],
455
+ top_p=text_top_p,
456
+ top_k=text_top_k,
457
+ do_sample=text_do_sample
458
+ )
459
+ is_audio[next_text_token == self.config.audio_start_token_id] = True
460
+ is_stopping[next_text_token == self.config.im_end_token_id] = True
461
+
462
+ next_audio_tokens = torch.full((batch_size, n_vq), self.config.audio_pad_code, device=device)
463
+
464
+ pre_audio_mask = audio_lengths.unsqueeze(1) > torch.arange(n_vq, dtype=int, device=device).expand(batch_size, n_vq)
465
+ post_audio_mask = torch.arange(n_vq, dtype=int, device=device).expand(batch_size, n_vq) > delayed_lengths.unsqueeze(1) - 1
466
+ post_audio_mask[delayed_lengths == torch_int64_max] = True
467
+ sampling_audio_mask = pre_audio_mask & post_audio_mask
468
+ next_audio_tokens[~sampling_audio_mask] = self.config.audio_pad_code
469
+
470
+ if sampling_audio_mask.sum() > 0:
471
+ audio_ch0_logits = next_token_logits[1][sampling_audio_mask[:, 0]]
472
+ audio_logits = torch.stack(next_token_logits[2:], dim=1)[sampling_audio_mask[:, 1:]]
473
+ audio_ch0_logits[..., self.config.audio_pad_code] = float('-inf')
474
+ audio_logits[..., self.config.audio_pad_code] = float('-inf')
475
+ next_audio_tokens[:, 0][sampling_audio_mask[:, 0]] = sample_token(
476
+ logits=audio_ch0_logits,
477
+ prev_tokens=generation_ids[:, :, 1],
478
+ repetition_penalty=audio_repetition_penalty,
479
+ top_p=audio_top_p,
480
+ top_k=audio_top_k,
481
+ do_sample=audio_do_sample
482
+ )
483
+ next_audio_tokens[:, 1:][sampling_audio_mask[:, 1:]] = sample_token(
484
+ logits=audio_logits,
485
+ prev_tokens=generation_ids[:, :, 2:],
486
+ repetition_penalty=audio_repetition_penalty,
487
+ top_p=audio_top_p,
488
+ top_k=audio_top_k,
489
+ do_sample=audio_do_sample
490
+ )
491
+
492
+ audio_lengths[(next_text_token == self.config.audio_start_token_id) | (next_text_token == self.config.audio_assistant_gen_slot_token_id) | (next_text_token == self.config.audio_assistant_delay_slot_token_id)] += 1
493
+ audio_lengths[next_text_token == self.config.audio_end_token_id] = 0
494
+ delayed_lengths[(delayed_lengths == torch_int64_max) & (next_text_token == self.config.audio_assistant_delay_slot_token_id)] = 0
495
+ delayed_lengths[delayed_lengths != torch_int64_max] += 1
496
+ delayed_lengths[delayed_lengths > n_vq] = torch_int64_max
497
+
498
+ current_input_ids = torch.cat([next_text_token[:, None, None], next_audio_tokens[:, None, :]], dim=2)
499
+ current_attention_mask = torch.cat([current_attention_mask, (~is_stopping).unsqueeze(-1)], dim=-1)
500
+ generation_ids = torch.cat([generation_ids, current_input_ids], dim=1)
501
+
502
+ if is_stopping.sum() == batch_size:
503
+ break
504
+
505
+ start_indices = find_last_equal_C(input_ids[..., 0], self.config.im_start_token_id) + 3
506
+ start_lengths = seq_len - start_indices
507
+
508
+ output = []
509
+ for start_idx, start_length, cur_generation_ids in zip(start_indices, start_lengths, generation_ids):
510
+ output.append((start_length, cur_generation_ids[start_idx:]))
511
+
512
+ return output
moss_config.json ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "moss_tts_delay",
3
+ "architectures": [
4
+ "MossTTSDelayModel"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_moss_tts.MossTTSDelayConfig",
8
+ "AutoModel": "modeling_moss_tts.MossTTSDelayModel"
9
+ },
10
+ "dtype": "bfloat16",
11
+ "initializer_range": 0.02,
12
+ "language_config": {
13
+ "_name_or_path": "Qwen/Qwen3-8B",
14
+ "architectures": [
15
+ "Qwen3ForCausalLM"
16
+ ],
17
+ "attention_bias": false,
18
+ "attention_dropout": 0.0,
19
+ "bos_token_id": 151643,
20
+ "eos_token_id": 151645,
21
+ "pad_token_id": 151643,
22
+ "head_dim": 128,
23
+ "hidden_act": "silu",
24
+ "hidden_size": 4096,
25
+ "initializer_range": 0.02,
26
+ "intermediate_size": 12288,
27
+ "layer_types": [
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention",
42
+ "full_attention",
43
+ "full_attention",
44
+ "full_attention",
45
+ "full_attention",
46
+ "full_attention",
47
+ "full_attention",
48
+ "full_attention",
49
+ "full_attention",
50
+ "full_attention",
51
+ "full_attention",
52
+ "full_attention",
53
+ "full_attention",
54
+ "full_attention",
55
+ "full_attention",
56
+ "full_attention",
57
+ "full_attention",
58
+ "full_attention",
59
+ "full_attention",
60
+ "full_attention",
61
+ "full_attention",
62
+ "full_attention",
63
+ "full_attention"
64
+ ],
65
+ "max_position_embeddings": 40960,
66
+ "max_window_layers": 36,
67
+ "model_type": "qwen3",
68
+ "num_attention_heads": 32,
69
+ "num_hidden_layers": 36,
70
+ "num_key_value_heads": 8,
71
+ "rms_norm_eps": 1e-06,
72
+ "rope_scaling": null,
73
+ "rope_theta": 1000000,
74
+ "sliding_window": null,
75
+ "use_cache": true,
76
+ "use_sliding_window": false,
77
+ "vocab_size": 155648
78
+ },
79
+ "n_vq": 32,
80
+ "audio_vocab_size": 1024,
81
+ "audio_user_slot_token_id": 151654,
82
+ "audio_assistant_gen_slot_token_id": 151656,
83
+ "audio_assistant_delay_slot_token_id": 151662,
84
+ "audio_start_token_id": 151652,
85
+ "audio_end_token_id": 151653,
86
+ "audio_pad_code": 1024,
87
+ "sampling_rate": 24000,
88
+ "transformers_version": "4.57.1"
89
+ }
moss_configuration_moss_tts.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2026 OpenMOSS and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """ MossTTSDelay model configuration """
16
+
17
+ from typing import Optional, Union
18
+ from transformers.configuration_utils import PretrainedConfig
19
+ from transformers.utils import logging
20
+ from transformers.models.qwen3 import Qwen3Config
21
+
22
+ logger = logging.get_logger(__name__)
23
+
24
+
25
+ class MossTTSDelayConfig(PretrainedConfig):
26
+ r"""
27
+ This is the configuration class to store the configuration of a [`MossTTSDelayModel`]. It is used to instantiate an
28
+ MossTTSDelay model according to the specified arguments, defining the model architecture. Instantiating a configuration
29
+ with the defaults will yield a similar configuration to that of the MossTTSDelay [MossTTSDelay-8B](https://huggingface.co/OpenMOSS/mosstts-8b) architecture.
30
+
31
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
32
+ documentation from [`PretrainedConfig`] for more information.
33
+
34
+ Args:
35
+ language_config (`Union[Qwen3Config, dict]`, *optional*):
36
+ Configuration for the backbone language model (Qwen3).
37
+ initializer_range (`float`, *optional*, defaults to 0.02):
38
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
39
+ n_vq (`int`, *optional*, defaults to 32):
40
+ Number of additional VQ (Vector Quantization) heads/channels for audio.
41
+ Determines the number of codebooks used in the audio representation.
42
+ audio_vocab_size (`int`, *optional*, defaults to 1024):
43
+ Vocabulary size for the audio tokens (codebooks 1 to N).
44
+ audio_user_slot_token_id (`int`, *optional*, defaults to 151654):
45
+ The specific token ID used as a placeholder/slot for user-side audio inputs in the prompt.
46
+ audio_assistant_gen_slot_token_id (`int`, *optional*, defaults to 151656):
47
+ The specific token ID representing the generation slot for the assistant's audio output.
48
+ Acting as the trigger for the TTS generation process.
49
+ audio_assistant_delay_slot_token_id (`int`, *optional*, defaults to 151662):
50
+ The token ID used in the 'Delay Pattern' paradigm to represent the delayed/offset positions
51
+ between different VQ channels.
52
+ audio_start_token_id (`int`, *optional*, defaults to 151652):
53
+ Special token ID used to denote the start of an audio sequence in the stream.
54
+ audio_end_token_id (`int`, *optional*, defaults to 151653):
55
+ Special token ID used to denote the end of an audio sequence (EOS for audio).
56
+ audio_pad_code (`int`, *optional*, defaults to 1024):
57
+ The padding value used within the audio VQ codebooks. Typically equals `audio_vocab_size`.
58
+ """
59
+ model_type = "moss_tts_delay"
60
+ keys_to_ignore_at_inference = ["past_key_values"]
61
+
62
+ def __init__(
63
+ self,
64
+ language_config: Optional[Union[Qwen3Config, dict]] = None,
65
+ initializer_range: float = 0.02,
66
+ n_vq: int = 32,
67
+ pad_token_id: int = 151643,
68
+ im_start_token_id: int = 151644,
69
+ im_end_token_id: int = 151645,
70
+ audio_vocab_size: int = 1024,
71
+ audio_user_slot_token_id: int = 151654,
72
+ audio_assistant_gen_slot_token_id: int = 151656,
73
+ audio_assistant_delay_slot_token_id: int = 151662,
74
+ audio_start_token_id: int = 151652,
75
+ audio_end_token_id: int = 151653,
76
+ audio_pad_code: int = 1024,
77
+ sampling_rate: int = 24000,
78
+ **kwargs,
79
+ ):
80
+ if isinstance(language_config, dict):
81
+ self.language_config = Qwen3Config(**language_config)
82
+ elif language_config is None:
83
+ self.language_config = Qwen3Config()
84
+ else:
85
+ self.language_config = language_config
86
+
87
+ self.initializer_range = initializer_range
88
+ self.n_vq = n_vq
89
+ self.audio_vocab_size = audio_vocab_size
90
+ self.audio_user_slot_token_id = audio_user_slot_token_id
91
+ self.audio_assistant_gen_slot_token_id = audio_assistant_gen_slot_token_id
92
+ self.audio_assistant_delay_slot_token_id = audio_assistant_delay_slot_token_id
93
+ self.audio_start_token_id = audio_start_token_id
94
+ self.audio_end_token_id = audio_end_token_id
95
+ self.audio_pad_code = audio_pad_code
96
+ self.sampling_rate = sampling_rate
97
+
98
+ self.hidden_size = self.language_config.hidden_size
99
+ self.vocab_size = self.language_config.vocab_size
100
+ self.im_start_token_id = self.language_config
101
+ self.pad_token_id = pad_token_id
102
+ self.im_start_token_id = im_start_token_id
103
+ self.im_end_token_id = im_end_token_id
104
+
105
+
106
+ super().__init__(**kwargs)
107
+
108
+ def to_dict(self):
109
+ output = super().to_dict()
110
+ if hasattr(self.language_config, "to_dict"):
111
+ output["language_config"] = self.language_config.to_dict()
112
+ else:
113
+ output["language_config"] = self.language_config
114
+ return output
moss_extras.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:973a6249da64484a44ef934da7958e15fc3014b0db218f9ea3312a1d79cdbbd4
3
+ size 1812478080
moss_inference_utils.py ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torchaudio
3
+ import torch.nn.functional as F
4
+ from typing import Optional, List, Tuple
5
+ from tqdm import tqdm
6
+
7
+
8
+ def apply_top_k(logits, top_k):
9
+ batch_size, vocab_size = logits.shape
10
+ top_k = min(top_k, vocab_size)
11
+ top_k_values, top_k_indices = torch.topk(logits, top_k, dim=-1)
12
+ filtered_logits = torch.full_like(logits, float("-inf"))
13
+ batch_indices = torch.arange(batch_size).unsqueeze(-1)
14
+ filtered_logits[batch_indices, top_k_indices] = top_k_values
15
+ return filtered_logits
16
+
17
+
18
+ def apply_top_p(logits, top_p):
19
+ probs = F.softmax(logits, dim=-1)
20
+ sorted_probs, sorted_indices = torch.sort(probs, descending=True, dim=-1)
21
+ cumulative_probs = torch.cumsum(sorted_probs, dim=-1)
22
+ sorted_indices_to_remove = cumulative_probs > top_p
23
+ sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[..., :-1].clone()
24
+ sorted_indices_to_remove[..., 0] = False
25
+ batch_size = logits.shape[0]
26
+ filtered_logits = logits.clone()
27
+ for i in range(batch_size):
28
+ indices_to_remove = sorted_indices[i][sorted_indices_to_remove[i]]
29
+ filtered_logits[i, indices_to_remove] = float("-inf")
30
+ return filtered_logits
31
+
32
+
33
+ def apply_top_p_optimized(logits, top_p):
34
+ probs = F.softmax(logits, dim=-1)
35
+ sorted_probs, sorted_indices = torch.sort(probs, descending=True, dim=-1)
36
+
37
+ cumulative_probs = torch.cumsum(sorted_probs, dim=-1)
38
+
39
+ sorted_indices_to_remove = cumulative_probs > top_p
40
+ sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[..., :-1].clone()
41
+ sorted_indices_to_remove[..., 0] = False
42
+
43
+ indices_to_remove = torch.zeros_like(logits, dtype=torch.bool).scatter_(
44
+ dim=-1, index=sorted_indices, src=sorted_indices_to_remove
45
+ )
46
+
47
+ logits[indices_to_remove] = float("-inf")
48
+ return logits
49
+
50
+
51
+ def apply_repetition_penalty_delay_pattern(
52
+ logits: torch.Tensor,
53
+ prev_tokens: torch.LongTensor,
54
+ penalty: float,
55
+ ):
56
+ """
57
+ logits: [B, H, V] or [N, V]
58
+ prev_tokens: [B, T, H] or [N, T] or [B, H]
59
+
60
+ Apply the repetition penalty independently for each H (VQ head).
61
+ """
62
+ if penalty == 1.0 or prev_tokens is None:
63
+ return logits
64
+
65
+ vocab_size = logits.size(-1)
66
+
67
+ # Case 1: regular [N, V] (text layer)
68
+ if logits.dim() == 2:
69
+ prev_tokens_flat = prev_tokens.reshape(-1)
70
+ unique_tokens = torch.unique(prev_tokens_flat)
71
+
72
+ token_logits = logits[:, unique_tokens]
73
+ pos_mask = token_logits > 0
74
+ token_logits[pos_mask] /= penalty
75
+ token_logits[~pos_mask] *= penalty
76
+ logits[:, unique_tokens] = token_logits
77
+ return logits
78
+
79
+ # Case 2: Delay Pattern audio [B, H, V]
80
+ assert logits.dim() == 3, "Delay Pattern audio logits must be [B, H, V]"
81
+ B, H, V = logits.shape
82
+
83
+ for h in range(H):
84
+ # prev_tokens_h: [B, T] or [B]
85
+ prev_tokens_h = prev_tokens[..., h].reshape(-1)
86
+ unique_tokens = torch.unique(prev_tokens_h)
87
+
88
+ if unique_tokens.numel() == 0:
89
+ continue
90
+
91
+ token_logits = logits[:, h, unique_tokens]
92
+ pos_mask = token_logits > 0
93
+ token_logits[pos_mask] /= penalty
94
+ token_logits[~pos_mask] *= penalty
95
+ logits[:, h, unique_tokens] = token_logits
96
+
97
+ return logits
98
+
99
+
100
+ def sample_token(
101
+ logits,
102
+ prev_tokens: Optional[torch.LongTensor] = None,
103
+ repetition_penalty: float = 1.0,
104
+ top_p=None,
105
+ top_k=None,
106
+ do_sample=True,
107
+ ):
108
+ vocab_size = logits.size(-1)
109
+
110
+ # ===== Repetition Penalty (before reshaping!) =====
111
+ if prev_tokens is not None and repetition_penalty != 1.0:
112
+ logits = apply_repetition_penalty_delay_pattern(
113
+ logits,
114
+ prev_tokens,
115
+ repetition_penalty,
116
+ )
117
+
118
+ if not do_sample:
119
+ return torch.argmax(logits, dim=-1)
120
+
121
+ # ===== Only flatten after this, for top-k / top-p / multinomial =====
122
+ original_shape = logits.shape
123
+ reshaped_logits = logits.view(-1, vocab_size)
124
+
125
+ if top_k is not None and top_k > 0:
126
+ reshaped_logits = apply_top_k(reshaped_logits, top_k)
127
+
128
+ if top_p is not None and top_p < 1.0:
129
+ reshaped_logits = apply_top_p_optimized(reshaped_logits, top_p)
130
+
131
+ probs = F.softmax(reshaped_logits, dim=-1)
132
+ next_tokens = torch.multinomial(probs, num_samples=1)
133
+
134
+ return next_tokens.view(original_shape[:-1])
135
+
136
+
137
+ def find_last_equal_C(tensor, C):
138
+ """
139
+ tensor: torch.Tensor of shape [batch_size, seq_len]
140
+ C: scalar value to match
141
+ Returns: torch.Tensor of shape [batch_size] with last indices
142
+ """
143
+ mask = (tensor == C).int() # Shape: [batch_size, seq_len], bool tensor
144
+ flipped_mask = mask.flip(dims=[1]) # Flip along sequence dimension
145
+ flipped_indices = flipped_mask.argmax(dim=1) # First True in flipped
146
+ seq_len = tensor.shape[1]
147
+ last_indices = (seq_len - 1) - flipped_indices # Convert to original indices
148
+
149
+ # Optional: Handle cases with no C (set to -1), though problem assumes existence
150
+ actual_values = tensor[torch.arange(tensor.shape[0]), last_indices]
151
+ no_match = actual_values != C
152
+ last_indices[no_match] = -1
153
+
154
+ return last_indices
moss_modeling_moss_tts.py ADDED
@@ -0,0 +1,512 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2026 OpenMOSS and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """ Modeling classes for MossTTSDelay. """
16
+
17
+ from dataclasses import dataclass
18
+ from typing import List, Optional, Tuple, Union
19
+ from tqdm import tqdm
20
+
21
+ import torch
22
+ import torch.nn as nn
23
+ from torch.nn import CrossEntropyLoss
24
+
25
+ from transformers.modeling_utils import PreTrainedModel
26
+ from transformers.modeling_outputs import ModelOutput
27
+ from transformers.utils import (
28
+ add_start_docstrings,
29
+ add_start_docstrings_to_model_forward,
30
+ logging,
31
+ replace_return_docstrings,
32
+ )
33
+ from transformers.cache_utils import Cache
34
+ from transformers.models.qwen3 import Qwen3Model
35
+ from transformers import initialization as init
36
+
37
+ from .configuration_moss_tts import MossTTSDelayConfig
38
+ from .inference_utils import sample_token, find_last_equal_C
39
+
40
+ try:
41
+ from .processing_moss_tts import UserMessage, AssistantMessage, MossTTSDelayProcessor
42
+ except Exception:
43
+ UserMessage = None
44
+ AssistantMessage = None
45
+ MossTTSDelayProcessor = None
46
+
47
+ logger = logging.get_logger(__name__)
48
+
49
+ _CONFIG_FOR_DOC = "MossTTSDelayConfig"
50
+
51
+
52
+ @dataclass
53
+ class MossTTSDelayOutputWithPast(ModelOutput):
54
+ """
55
+ Base class for model's outputs that may also contain a past key/values (to speed up sequential decoding).
56
+
57
+ Args:
58
+ loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
59
+ Weighted sum of channel losses.
60
+ all_sum_losses (`torch.FloatTensor` of shape `(batch_size, n_vq + 1)`, *optional*):
61
+ Sum of losses for each sample and each channel before averaging.
62
+ all_token_nums (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
63
+ Number of non-masked tokens per sample.
64
+ sample_losses (`torch.FloatTensor` of shape `(batch_size,)`, *optional*):
65
+ Loss per sample.
66
+ channel_losses (`torch.FloatTensor` of shape `(n_vq + 1,)`, *optional*):
67
+ Loss per channel (text head + vq heads).
68
+ logits (`List[torch.FloatTensor]`, *optional*):
69
+ List of prediction scores from each head.
70
+ past_key_values (`Cache`, *optional*):
71
+ Pre-computed hidden-states (key and values in the self-attention blocks).
72
+ hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed):
73
+ Tuple of torch.FloatTensor (one for the output of the embeddings, if the model has an embedding layer, +
74
+ one for the output of each layer).
75
+ attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed):
76
+ Tuple of torch.FloatTensor (one for each layer) of the attention weights.
77
+ """
78
+ loss: Optional[torch.FloatTensor] = None
79
+ all_sum_losses: Optional[torch.FloatTensor] = None
80
+ all_token_nums: Optional[torch.LongTensor] = None
81
+ sample_losses: Optional[torch.FloatTensor] = None
82
+ channel_losses: Optional[torch.FloatTensor] = None
83
+ logits: Optional[List[torch.FloatTensor]] = None
84
+ past_key_values: Optional[Cache] = None
85
+ hidden_states: Optional[Tuple[torch.FloatTensor]] = None
86
+ attentions: Optional[Tuple[torch.FloatTensor]] = None
87
+
88
+
89
+
90
+
91
+ class MossTTSDelayPreTrainedModel(PreTrainedModel):
92
+ config_class = MossTTSDelayConfig
93
+ base_model_prefix = "model"
94
+ supports_gradient_checkpointing = True
95
+ _no_split_modules = ["Qwen3DecoderLayer"]
96
+ _skip_keys_device_placement = "past_key_values"
97
+ _supports_flash_attn = True
98
+ _supports_flash_attn_2 = True
99
+ _supports_sdpa = True
100
+ _supports_flex_attn = True
101
+
102
+ def _init_weights(self, module):
103
+ """
104
+ Transformers 5.0+ safe init:
105
+ - MUST use transformers.initialization helpers
106
+ - MUST respect param._is_hf_initialized to avoid overwriting ckpt-loaded params
107
+ """
108
+ # Let HF handle its standard modules first (LayerNorm, Linear, Embedding, etc.)
109
+ super()._init_weights(module)
110
+
111
+ # Pick a std consistent with HF conventions
112
+ # Prefer model/text config initializer_range if present.
113
+ std = None
114
+ if hasattr(self.config, "initializer_range"):
115
+ std = self.config.initializer_range
116
+ elif hasattr(self.config, "language_config") and hasattr(self.config.language_config, "initializer_range"):
117
+ std = self.config.language_config.initializer_range
118
+ else:
119
+ std = 0.02
120
+
121
+ # Initialize extra audio embeddings
122
+ if isinstance(module, nn.Embedding):
123
+ # Only touch our extra embeddings (avoid double touching LM's embeddings if not desired)
124
+ # If you prefer, you can skip this check and rely on super()._init_weights for all embeddings.
125
+ if getattr(module, "num_embeddings", None) == self.config.audio_vocab_size + 1:
126
+ init.normal_(module.weight, mean=0.0, std=std)
127
+ # If you later set padding_idx, you must explicitly zero it (and respect _is_hf_initialized!)
128
+ # init.zeros_ will internally check param flags, but slicing needs manual care.
129
+
130
+ # Initialize multi-head projections you added
131
+ if isinstance(module, nn.Linear):
132
+ # For your lm_heads, super()._init_weights already covers typical Linear.
133
+ # This block is only needed if you have custom Linear variants later.
134
+ pass
135
+
136
+
137
+
138
+ MOSSTTS_START_DOCSTRING = r"""
139
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
140
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
141
+ etc.)
142
+
143
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
144
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
145
+ and behavior.
146
+
147
+ Parameters:
148
+ config ([`MossTTSDelayConfig`]):
149
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
150
+ load the weights associated with the model, only the configuration. Check out the
151
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
152
+ """
153
+
154
+
155
+ @add_start_docstrings(
156
+ "The MossTTSDelay Model architecture tailored for Text-to-Speech generation with multi-head VQ prediction.",
157
+ MOSSTTS_START_DOCSTRING,
158
+ )
159
+ class MossTTSDelayModel(MossTTSDelayPreTrainedModel):
160
+ UserMessage = UserMessage
161
+ AssistantMessage = AssistantMessage
162
+ Processor = MossTTSDelayProcessor
163
+
164
+ def __init__(self, config: MossTTSDelayConfig):
165
+ super().__init__(config)
166
+ self.config = config
167
+
168
+ config.language_config.torch_dtype = config.torch_dtype
169
+
170
+ self.language_model = Qwen3Model(config.language_config)
171
+
172
+ # Audio VQ Embeddings (Extra channels)
173
+ # Note: input_ids[..., 0] uses Qwen's embedding.
174
+ # input_ids[..., 1:] use these extensions.
175
+ self.emb_ext = nn.ModuleList()
176
+ for vq_idx in range(self.config.n_vq):
177
+ # Add +1 for potential padding/special tokens logic if strictly required by upstream data prep
178
+ self.emb_ext.append(
179
+ nn.Embedding(self.config.audio_vocab_size + 1, config.language_config.hidden_size, padding_idx=None)
180
+ )
181
+
182
+ # Multi-Head Prediction Layers
183
+ # Head 0: Main language head
184
+ # Head 1..N: Audio VQ heads
185
+ self.lm_heads = nn.ModuleList([
186
+ nn.Linear(config.language_config.hidden_size, config.language_config.vocab_size, bias=False)
187
+ ])
188
+ for vq_idx in range(self.config.n_vq):
189
+ self.lm_heads.append(
190
+ nn.Linear(config.language_config.hidden_size, self.config.audio_vocab_size + 1, bias=False)
191
+ )
192
+
193
+ # Initialize weights and apply final processing
194
+ self.post_init()
195
+
196
+ def get_input_embeddings(self, input_ids: torch.LongTensor) -> torch.Tensor:
197
+ inputs_embeds = self.language_model.get_input_embeddings()(input_ids[..., 0])
198
+ for i, embed_layer in enumerate(self.emb_ext):
199
+ inputs_embeds = inputs_embeds + embed_layer(input_ids[..., i + 1])
200
+ return inputs_embeds.to(torch.float16) # ← force fp16
201
+
202
+ def set_input_embeddings(self, value):
203
+ self.language_model.embed_tokens = value
204
+
205
+ def get_output_embeddings(self):
206
+ # Returning a list of heads might break some HF utilities expecting a single head.
207
+ # However, for custom models, this is acceptable.
208
+ return self.lm_heads
209
+
210
+ @add_start_docstrings_to_model_forward(MOSSTTS_START_DOCSTRING)
211
+ @replace_return_docstrings(output_type=MossTTSDelayOutputWithPast, config_class=_CONFIG_FOR_DOC)
212
+ def forward(
213
+ self,
214
+ input_ids: Optional[torch.LongTensor] = None,
215
+ attention_mask: Optional[torch.Tensor] = None,
216
+ position_ids: Optional[torch.LongTensor] = None,
217
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
218
+ inputs_embeds: Optional[torch.FloatTensor] = None,
219
+ labels: Optional[torch.LongTensor] = None,
220
+ use_cache: Optional[bool] = None,
221
+ output_attentions: Optional[bool] = None,
222
+ cache_position: Optional[torch.LongTensor] = None,
223
+ hidden_out_layers: Optional[List[int]] = None,
224
+ channelwise_loss_weight: Optional[List[float]] = None,
225
+ **kwargs,
226
+ ) -> Union[Tuple, MossTTSDelayOutputWithPast]:
227
+ r"""
228
+ Args:
229
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length, 1 + n_vq)`):
230
+ Indices of input sequence tokens in the vocabulary.
231
+ Dimension 2 contains: [Text/Semantics, VQ_0, VQ_1, ..., VQ_N].
232
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length, 1 + n_vq)`, *optional*):
233
+ Labels for computing the masked language modeling loss.
234
+ channelwise_loss_weight (`List[float]`, *optional*):
235
+ Manual weights for summing losses across different heads (Text vs Audio channels).
236
+
237
+ Returns:
238
+ """
239
+
240
+ if len(input_ids.shape) != 3 or input_ids.shape[-1] != self.config.n_vq + 1:
241
+ raise ValueError("`Input_ids`'s shape should be exactly (batch_size, sequence_length, 1 + n_vq).")
242
+
243
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
244
+
245
+ # 1. Prepare Embeddings
246
+ if inputs_embeds is None:
247
+ inputs_embeds = self.get_input_embeddings(input_ids)
248
+
249
+ # 2. Backbone Forward
250
+ # Qwen3Model outputs standard CausalLMOutputWithPast or similar
251
+ outputs = self.language_model(
252
+ input_ids=None, # Passed via inputs_embeds
253
+ position_ids=position_ids,
254
+ attention_mask=attention_mask,
255
+ past_key_values=past_key_values,
256
+ inputs_embeds=inputs_embeds,
257
+ use_cache=use_cache,
258
+ output_attentions=output_attentions,
259
+ output_hidden_states=True, # Always need hidden states for multi-head projection
260
+ return_dict=True,
261
+ cache_position=cache_position,
262
+ **kwargs,
263
+ )
264
+
265
+ # 3. Handle specific layer outputs if requested (Delay Pattern often requires features from specific layers)
266
+ last_hidden_state = outputs.last_hidden_state
267
+ if hidden_out_layers is None:
268
+ # Default to using the last layer for all heads
269
+ # In some architectures (like MusicGen), different codebooks come from different transformer layers.
270
+ # Here we default to the final layer as per original code behavior [-1] * (n + 1).
271
+ hidden_states_for_heads = [last_hidden_state] * (len(self.lm_heads))
272
+ else:
273
+ # If hidden_out_layers is provided (e.g. [-1, -2, -3...]), fetch them from all_hidden_states
274
+ # Note: outputs.hidden_states includes embedding output at index 0 usually.
275
+ all_hs = outputs.hidden_states
276
+ hidden_states_for_heads = [all_hs[idx] for idx in hidden_out_layers]
277
+
278
+ # 4. Project to Logits (Multi-Head)
279
+ layer_logits = []
280
+ for i, (hs, head) in enumerate(zip(hidden_states_for_heads, self.lm_heads)):
281
+ logits = head(hs)
282
+ # Original code logic: Mask the last token index for audio heads (indices > 0)
283
+ # This implies the vocab size is (N+1) but the model shouldn't predict the (N+1)-th token
284
+ # (perhaps reserved for padding in the input but invalid for prediction).
285
+ if i > 0:
286
+ logits[..., -1] = float("-inf")
287
+ layer_logits.append(logits)
288
+
289
+ # 5. Loss Calculation
290
+ loss = None
291
+ all_sum_losses = None
292
+ all_token_nums = None
293
+ sample_losses = None
294
+ channel_losses = None
295
+
296
+ if labels is not None:
297
+ # Ensure labels match input shape rank (B, S, C)
298
+ if labels.dim() != 3:
299
+ raise ValueError(f"Labels must have rank 3 (B, S, C), got {labels.shape}")
300
+
301
+ batch_size = labels.size(0)
302
+ n_heads = len(layer_logits)
303
+
304
+ # Container for per-sample, per-channel losses
305
+ # Shape: [Batch, n_heads]
306
+ all_sum_losses_list = []
307
+
308
+ # Count valid tokens (not -100) per sample.
309
+ # Note: Assuming mask is consistent across channels or we take sum over dim 1 (seq)
310
+ # Usually strict masking means checking one channel or all.
311
+ # Original code: torch.sum(labels != -100, dim=1) -> [B, C]
312
+ all_token_nums = torch.sum(labels != -100, dim=1)
313
+
314
+ for i, logits in enumerate(layer_logits):
315
+ # logits: [B, S, V]
316
+ # cur_labels: [B, S]
317
+ cur_labels = labels[..., i]
318
+
319
+ # Flatten for CrossEntropy
320
+ # logits: [B*S, V], labels: [B*S]
321
+ loss_fct = CrossEntropyLoss(reduction='none')
322
+ vocab_size = logits.size(-1)
323
+
324
+ reshaped_logits = logits.view(-1, vocab_size)
325
+ reshaped_labels = cur_labels.contiguous().view(-1)
326
+
327
+ # Calculate loss per token
328
+ per_token_loss = loss_fct(reshaped_logits, reshaped_labels)
329
+
330
+ # Reshape back to [B, S] and sum over Sequence dimension to get per-sample loss
331
+ per_token_loss = per_token_loss.view(batch_size, -1)
332
+ per_sample_loss = torch.sum(per_token_loss, dim=-1) # [B]
333
+
334
+ all_sum_losses_list.append(per_sample_loss)
335
+
336
+ # Stack to [B, n_heads]
337
+ all_sum_losses = torch.stack(all_sum_losses_list, dim=1)
338
+
339
+ # Weighted Loss Aggregation
340
+ if channelwise_loss_weight is not None:
341
+ if len(channelwise_loss_weight) != n_heads:
342
+ raise ValueError(f"channelwise_loss_weight length {len(channelwise_loss_weight)} != {n_heads}")
343
+
344
+ w_tensor = torch.tensor(channelwise_loss_weight, device=all_sum_losses.device, dtype=all_sum_losses.dtype)
345
+
346
+ # Sample losses: Weighted sum over channels per sample / Total weight
347
+ # Normalize by token count per channel
348
+ # Avoid division by zero with epsilon or mask
349
+ token_counts_safe = all_token_nums.float().clamp(min=1.0)
350
+
351
+ normalized_losses = all_sum_losses / token_counts_safe
352
+ sample_losses = (normalized_losses * w_tensor).sum(dim=1) / w_tensor.sum()
353
+
354
+ # Channel losses: Sum over batch / Sum tokens over batch
355
+ total_loss_per_channel = all_sum_losses.sum(dim=0)
356
+ total_tokens_per_channel = all_token_nums.sum(dim=0).float().clamp(min=1.0)
357
+ channel_losses = total_loss_per_channel / total_tokens_per_channel
358
+
359
+ # Final scalar loss
360
+ loss = (channel_losses * w_tensor).sum() / w_tensor.sum()
361
+ else:
362
+ # Default average if no weights provided
363
+ total_tokens = all_token_nums.sum().float().clamp(min=1.0)
364
+ loss = all_sum_losses.sum() / total_tokens
365
+ channel_losses = all_sum_losses.sum(dim=0) / all_token_nums.sum(dim=0).clamp(min=1.0)
366
+
367
+ return MossTTSDelayOutputWithPast(
368
+ loss=loss,
369
+ all_sum_losses=all_sum_losses,
370
+ all_token_nums=all_token_nums,
371
+ sample_losses=sample_losses,
372
+ channel_losses=channel_losses,
373
+ logits=layer_logits,
374
+ past_key_values=outputs.past_key_values,
375
+ hidden_states=outputs.hidden_states,
376
+ attentions=outputs.attentions,
377
+ )
378
+
379
+ @torch.inference_mode()
380
+ def generate(
381
+ self,
382
+ input_ids: torch.LongTensor,
383
+ attention_mask: Optional[torch.Tensor] = None,
384
+ max_new_tokens: int = 1000,
385
+ text_temperature: float = 1.5,
386
+ text_top_p: float = 1.0,
387
+ text_top_k: int = 50,
388
+ audio_temperature: float = 1.7,
389
+ audio_top_p: float = 0.8,
390
+ audio_top_k: int = 25,
391
+ audio_repetition_penalty: float = 1.0,
392
+ ):
393
+ if text_temperature > 0:
394
+ text_do_sample = True
395
+ else:
396
+ text_temperature = 1
397
+ text_do_sample = False
398
+ if audio_temperature > 0:
399
+ audio_do_sample = True
400
+ else:
401
+ audio_temperature = 1
402
+ audio_do_sample = False
403
+
404
+ past_key_values = None
405
+ device = input_ids.device
406
+ current_input_ids = input_ids
407
+ current_attention_mask = attention_mask
408
+ batch_size, seq_len, n_vq = input_ids.shape
409
+ n_vq -= 1
410
+
411
+ generation_ids = input_ids[:]
412
+ is_stopping = torch.zeros(batch_size, dtype=torch.bool, device=device)
413
+
414
+ audio_lengths = torch.zeros(batch_size, dtype=torch.int64, device=device)
415
+ torch_int64_max = torch.iinfo(torch.int64).max
416
+ delayed_lengths = torch.full((batch_size,), torch_int64_max, dtype=torch.int64, device=device)
417
+
418
+ is_continuation = (input_ids[:, -1, 0] == self.config.audio_start_token_id) | (input_ids[:, -1, 0] == self.config.audio_assistant_gen_slot_token_id)
419
+ audio_start_indices = find_last_equal_C(input_ids[..., 0], self.config.audio_start_token_id)
420
+ audio_start_mask = is_continuation & (audio_start_indices != -1)
421
+ audio_lengths[audio_start_mask] = seq_len - audio_start_indices[audio_start_mask]
422
+
423
+ is_audio = audio_start_mask.clone()
424
+
425
+ pre_exclude_mask0 = torch.tensor([self.config.pad_token_id, self.config.audio_assistant_gen_slot_token_id, self.config.audio_assistant_delay_slot_token_id, self.config.audio_end_token_id], device=device)
426
+ pre_exclude_mask1 = torch.ones(self.config.language_config.vocab_size, device=device).bool()
427
+ pre_exclude_mask1[[self.config.audio_assistant_gen_slot_token_id, self.config.audio_assistant_delay_slot_token_id]] = False
428
+
429
+ for time_step in tqdm(range(max_new_tokens), desc=f"Generating bs{batch_size} ..."):
430
+ outputs = self(
431
+ input_ids=current_input_ids,
432
+ attention_mask=current_attention_mask,
433
+ past_key_values=past_key_values,
434
+ use_cache=True,
435
+ )
436
+ past_key_values = outputs.past_key_values
437
+
438
+ next_token_logits = [logit[:, -1, :] / text_temperature if logit_idx == 0 else logit[:, -1, :] / audio_temperature for logit_idx, logit in enumerate(outputs.logits)] # List, len=n_vq+1, [batch_size, 1, vocab_size];
439
+ next_token_logits[0] = next_token_logits[0].clone()
440
+ next_text_token = torch.full((batch_size,), self.config.pad_token_id, device=device)
441
+ next_text_token[~is_stopping & (delayed_lengths < n_vq)] = self.config.audio_assistant_delay_slot_token_id
442
+ is_audio_eos = ~is_stopping & (delayed_lengths == n_vq)
443
+ next_text_token[is_audio_eos] = self.config.audio_end_token_id
444
+ is_audio[is_audio_eos] = False
445
+ sampling_text_mask = ~is_stopping & (delayed_lengths > n_vq)
446
+ next_token_logits[0][~is_audio] = next_token_logits[0][~is_audio].index_fill(-1, pre_exclude_mask0, float('-inf'))
447
+ next_token_logits[0][is_audio] = next_token_logits[0][is_audio].masked_fill(pre_exclude_mask1, float('-inf'))
448
+ if time_step == 0:
449
+ next_token_logits[0][..., 151662] = float('-inf')
450
+ if time_step <= n_vq:
451
+ next_token_logits[0][..., self.config.im_end_token_id] = float('-inf')
452
+
453
+ next_text_token[sampling_text_mask] = sample_token(
454
+ logits=next_token_logits[0][sampling_text_mask],
455
+ top_p=text_top_p,
456
+ top_k=text_top_k,
457
+ do_sample=text_do_sample
458
+ )
459
+ is_audio[next_text_token == self.config.audio_start_token_id] = True
460
+ is_stopping[next_text_token == self.config.im_end_token_id] = True
461
+
462
+ next_audio_tokens = torch.full((batch_size, n_vq), self.config.audio_pad_code, device=device)
463
+
464
+ pre_audio_mask = audio_lengths.unsqueeze(1) > torch.arange(n_vq, dtype=int, device=device).expand(batch_size, n_vq)
465
+ post_audio_mask = torch.arange(n_vq, dtype=int, device=device).expand(batch_size, n_vq) > delayed_lengths.unsqueeze(1) - 1
466
+ post_audio_mask[delayed_lengths == torch_int64_max] = True
467
+ sampling_audio_mask = pre_audio_mask & post_audio_mask
468
+ next_audio_tokens[~sampling_audio_mask] = self.config.audio_pad_code
469
+
470
+ if sampling_audio_mask.sum() > 0:
471
+ audio_ch0_logits = next_token_logits[1][sampling_audio_mask[:, 0]]
472
+ audio_logits = torch.stack(next_token_logits[2:], dim=1)[sampling_audio_mask[:, 1:]]
473
+ audio_ch0_logits[..., self.config.audio_pad_code] = float('-inf')
474
+ audio_logits[..., self.config.audio_pad_code] = float('-inf')
475
+ next_audio_tokens[:, 0][sampling_audio_mask[:, 0]] = sample_token(
476
+ logits=audio_ch0_logits,
477
+ prev_tokens=generation_ids[:, :, 1],
478
+ repetition_penalty=audio_repetition_penalty,
479
+ top_p=audio_top_p,
480
+ top_k=audio_top_k,
481
+ do_sample=audio_do_sample
482
+ )
483
+ next_audio_tokens[:, 1:][sampling_audio_mask[:, 1:]] = sample_token(
484
+ logits=audio_logits,
485
+ prev_tokens=generation_ids[:, :, 2:],
486
+ repetition_penalty=audio_repetition_penalty,
487
+ top_p=audio_top_p,
488
+ top_k=audio_top_k,
489
+ do_sample=audio_do_sample
490
+ )
491
+
492
+ audio_lengths[(next_text_token == self.config.audio_start_token_id) | (next_text_token == self.config.audio_assistant_gen_slot_token_id) | (next_text_token == self.config.audio_assistant_delay_slot_token_id)] += 1
493
+ audio_lengths[next_text_token == self.config.audio_end_token_id] = 0
494
+ delayed_lengths[(delayed_lengths == torch_int64_max) & (next_text_token == self.config.audio_assistant_delay_slot_token_id)] = 0
495
+ delayed_lengths[delayed_lengths != torch_int64_max] += 1
496
+ delayed_lengths[delayed_lengths > n_vq] = torch_int64_max
497
+
498
+ current_input_ids = torch.cat([next_text_token[:, None, None], next_audio_tokens[:, None, :]], dim=2)
499
+ current_attention_mask = torch.cat([current_attention_mask, (~is_stopping).unsqueeze(-1)], dim=-1)
500
+ generation_ids = torch.cat([generation_ids, current_input_ids], dim=1)
501
+
502
+ if is_stopping.sum() == batch_size:
503
+ break
504
+
505
+ start_indices = find_last_equal_C(input_ids[..., 0], self.config.im_start_token_id) + 3
506
+ start_lengths = seq_len - start_indices
507
+
508
+ output = []
509
+ for start_idx, start_length, cur_generation_ids in zip(start_indices, start_lengths, generation_ids):
510
+ output.append((start_length, cur_generation_ids[start_idx:]))
511
+
512
+ return output
moss_processing_moss_tts.py ADDED
@@ -0,0 +1,930 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2026 OpenMOSS and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import os
17
+ from typing import Any, Dict, List, Optional, Tuple, Type, Union, Literal, Final, cast
18
+ from dataclasses import dataclass
19
+ from pathlib import Path
20
+ import re
21
+ import torchaudio
22
+
23
+ from transformers import processing_utils
24
+
25
+ processing_utils.MODALITY_TO_BASE_CLASS_MAPPING["audio_tokenizer"] = "PreTrainedModel"
26
+
27
+ import torch
28
+ from transformers import (
29
+ PreTrainedTokenizerBase,
30
+ BatchFeature,
31
+ ProcessorMixin,
32
+ logging,
33
+ AutoConfig,
34
+ AutoModel,
35
+ AutoTokenizer,
36
+ )
37
+
38
+ from .configuration_moss_tts import MossTTSDelayConfig
39
+
40
+
41
+ logger = logging.get_logger(__name__)
42
+
43
+
44
+ AUDIO_PLACEHOLDER = "<|audio|>"
45
+
46
+
47
+ @dataclass
48
+ class Message:
49
+ def to_dict(self) -> Dict[str, Any]:
50
+ raise NotImplementedError
51
+
52
+
53
+ @dataclass
54
+ class UserMessage(Message):
55
+ text: Optional[str] = None
56
+ reference: Optional[List[Optional[Union[str, torch.Tensor]]]] = None
57
+ instruction: Optional[str] = None
58
+ tokens: Optional[int] = None
59
+ quality: Optional[str] = None
60
+ sound_event: Optional[str] = None
61
+ ambient_sound: Optional[str] = None
62
+ language: Optional[str] = None
63
+
64
+ def __post_init__(self):
65
+ template = """<user_inst>
66
+ - Reference(s):
67
+ {reference}
68
+ - Instruction:
69
+ {instruction}
70
+ - Tokens:
71
+ {tokens}
72
+ - Quality:
73
+ {quality}
74
+ - Sound Event:
75
+ {sound_event}
76
+ - Ambient Sound:
77
+ {ambient_sound}
78
+ - Language:
79
+ {language}
80
+ - Text:
81
+ {text}
82
+ </user_inst>"""
83
+
84
+ audio_codes_list = []
85
+ if self.reference is None:
86
+ reference = "None"
87
+ elif isinstance(self.reference, List):
88
+ reference = []
89
+ for speaker_idx, speaker_reference in enumerate(self.reference):
90
+ if speaker_reference is not None:
91
+ reference.append(f"[S{speaker_idx+1}]:\n{AUDIO_PLACEHOLDER}")
92
+ reference = "\n".join(reference)
93
+ audio_codes_list = [
94
+ speaker_reference
95
+ for speaker_reference in self.reference
96
+ if speaker_reference is not None
97
+ ]
98
+ else:
99
+ raise TypeError("`reference` should be exactly a list when it is not None.")
100
+
101
+ content = (
102
+ template.replace("{reference}", str(reference))
103
+ .replace("{instruction}", str(self.instruction))
104
+ .replace("{tokens}", str(self.tokens))
105
+ .replace("{quality}", str(self.quality))
106
+ .replace("{sound_event}", str(self.sound_event))
107
+ .replace("{ambient_sound}", str(self.ambient_sound))
108
+ .replace("{language}", str(self.language))
109
+ .replace("{text}", str(self.text))
110
+ )
111
+
112
+ self._content = content
113
+ self._audio_codes_list = audio_codes_list
114
+
115
+ def to_dict(self):
116
+ return {
117
+ "role": "user",
118
+ "content": self._content,
119
+ "audio_codes_list": self._audio_codes_list,
120
+ }
121
+
122
+
123
+ @dataclass
124
+ class AssistantMessage(Message):
125
+ audio_codes_list: List[Union[str, torch.Tensor]]
126
+ content: str = AUDIO_PLACEHOLDER
127
+
128
+ def to_dict(self):
129
+ return {
130
+ "role": "assistant",
131
+ "content": self.content,
132
+ "audio_codes_list": self.audio_codes_list,
133
+ }
134
+
135
+
136
+ USER_MESSAGE_FIELDS = (
137
+ "text",
138
+ "reference",
139
+ "instruction",
140
+ "tokens",
141
+ "quality",
142
+ "sound_event",
143
+ "ambient_sound",
144
+ "language",
145
+ )
146
+
147
+
148
+ class MossTTSDelayProcessor(ProcessorMixin):
149
+ tokenizer_class = "AutoTokenizer"
150
+ audio_tokenizer_class = "AutoModel"
151
+
152
+ tokenizer: PreTrainedTokenizerBase
153
+ audio_tokenizer: Any
154
+
155
+ def __init__(
156
+ self,
157
+ tokenizer: PreTrainedTokenizerBase,
158
+ audio_tokenizer: Any = None,
159
+ model_config: Optional[MossTTSDelayConfig] = None,
160
+ **kwargs,
161
+ ):
162
+ super().__init__(tokenizer=tokenizer, audio_tokenizer=audio_tokenizer, **kwargs)
163
+
164
+ # Explicit assignments for type-checkers; ProcessorMixin sets these too.
165
+ self.tokenizer = tokenizer
166
+ self.audio_tokenizer = audio_tokenizer
167
+ if model_config is None:
168
+ model_config = MossTTSDelayConfig()
169
+ self.model_config = model_config
170
+
171
+ self.imstart_token_id = tokenizer.convert_tokens_to_ids("<|im_start|>")
172
+ self.imend_token_id = tokenizer.convert_tokens_to_ids("<|im_end|>")
173
+ self.newline_token_id = 198
174
+
175
+ def _id_to_token(token_id: int) -> str:
176
+ tok = tokenizer.convert_ids_to_tokens(int(token_id))
177
+ if isinstance(tok, list):
178
+ return tok[0] if len(tok) > 0 else ""
179
+ return cast(str, tok)
180
+
181
+ self.audio_user_slot_token = _id_to_token(
182
+ self.model_config.audio_user_slot_token_id
183
+ )
184
+ self.audio_assistant_gen_slot_token = _id_to_token(
185
+ self.model_config.audio_assistant_gen_slot_token_id
186
+ )
187
+ self.audio_assistant_delay_slot_token = _id_to_token(
188
+ self.model_config.audio_assistant_delay_slot_token_id
189
+ )
190
+ self.audio_start_token = _id_to_token(self.model_config.audio_start_token_id)
191
+ self.audio_end_token = _id_to_token(self.model_config.audio_end_token_id)
192
+
193
+ @classmethod
194
+ def from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs):
195
+ trust_remote_code = kwargs.pop("trust_remote_code", True)
196
+ kwargs.pop("_from_auto", None)
197
+
198
+ audio_tokenizer_name_or_path = kwargs.pop(
199
+ "codec_path", "OpenMOSS-Team/MOSS-Audio-Tokenizer"
200
+ )
201
+
202
+ pretrained_model_name_or_path = Path(pretrained_model_name_or_path)
203
+ model_config = cast(
204
+ MossTTSDelayConfig,
205
+ AutoConfig.from_pretrained(
206
+ pretrained_model_name_or_path,
207
+ *args,
208
+ trust_remote_code=trust_remote_code,
209
+ **kwargs,
210
+ ),
211
+ )
212
+ tokenizer = AutoTokenizer.from_pretrained(
213
+ pretrained_model_name_or_path,
214
+ *args,
215
+ trust_remote_code=trust_remote_code,
216
+ **kwargs,
217
+ )
218
+ audio_tokenizer = AutoModel.from_pretrained(
219
+ audio_tokenizer_name_or_path,
220
+ trust_remote_code=trust_remote_code,
221
+ **kwargs,
222
+ )
223
+
224
+ return cls(
225
+ tokenizer=tokenizer,
226
+ audio_tokenizer=audio_tokenizer,
227
+ model_config=model_config,
228
+ **kwargs,
229
+ )
230
+
231
+ def __call__(self, *args, **kwargs) -> BatchFeature:
232
+ conversations = args[0] if len(args) > 0 else kwargs.pop("conversations")
233
+ mode: str = kwargs.pop("mode", "generation")
234
+ apply_chat_template: bool = kwargs.pop("apply_chat_template", True)
235
+ n_vq: Optional[int] = kwargs.pop("n_vq", None)
236
+
237
+ # Common ProcessorMixin kwargs that we ignore because we always return torch tensors.
238
+ kwargs.pop("return_tensors", None)
239
+ kwargs.pop("padding", None)
240
+ kwargs.pop("truncation", None)
241
+
242
+ """
243
+ mode only works when a Message is converted to a dict.
244
+ """
245
+
246
+ if mode not in {"generation", "continuation"}:
247
+ raise RuntimeError
248
+
249
+ if isinstance(conversations, (Message, Dict)):
250
+ conversations = [conversations]
251
+
252
+ truncation = False
253
+ if mode == "continuation":
254
+ truncation = True
255
+
256
+ input_ids_list = []
257
+ for conversation in conversations:
258
+ if isinstance(conversation, (Message, Dict)):
259
+ conversation = [conversation]
260
+
261
+ # Normalize early so downstream logic always deals with dict messages.
262
+ conversation = [self._normalize_message(m) for m in conversation]
263
+
264
+ if (mode == "generation") ^ (len(conversation) % 2 != 0):
265
+ raise ValueError
266
+
267
+ if (mode == "generation") ^ (conversation[-1]["role"] == "user"):
268
+ raise ValueError
269
+
270
+ unified_codes = []
271
+ for message_idx, message in enumerate(conversation):
272
+ if apply_chat_template:
273
+ add_generation_prompt = (
274
+ mode == "generation" and message_idx == len(conversation) - 1
275
+ )
276
+ try:
277
+ content = self.tokenizer.apply_chat_template(
278
+ [{"role": message["role"], "content": message["content"]}],
279
+ add_generation_prompt=add_generation_prompt,
280
+ tokenize=False,
281
+ )
282
+ except TypeError:
283
+ try:
284
+ content = self.tokenizer.apply_chat_template(
285
+ [
286
+ {
287
+ "role": message["role"],
288
+ "content": message["content"],
289
+ }
290
+ ],
291
+ add_generation_prompt=add_generation_prompt,
292
+ )
293
+ except Exception:
294
+ logger.warning(
295
+ "apply_chat_template failed; fallback to raw content."
296
+ )
297
+ content = message["content"]
298
+ else:
299
+ content = message["content"]
300
+
301
+ if not isinstance(content, str):
302
+ content = str(content)
303
+
304
+ # Batch-encode all path-based references in one call when possible.
305
+ # This ensures we actually exercise audio_tokenizer.batch_encode for multi-reference prompts,
306
+ # instead of repeatedly calling it with batch=1.
307
+ raw_audio_items = message.get("audio_codes_list", [])
308
+
309
+ audio_codes_list: List[torch.Tensor] = []
310
+ if len(raw_audio_items) > 0:
311
+ encoded_items: List[Optional[torch.Tensor]] = [None] * len(
312
+ raw_audio_items
313
+ )
314
+ paths: List[str] = []
315
+ path_positions: List[int] = []
316
+
317
+ for idx, item in enumerate(raw_audio_items):
318
+ if isinstance(item, torch.Tensor):
319
+ if n_vq is not None and item.shape[1] != n_vq:
320
+ raise RuntimeError(
321
+ "audio_codes's n_vq is not equal to the parameter `n_vq`. Your can set the parameter `n_vq` as None if you have already tokenzied the wavs."
322
+ )
323
+ encoded_items[idx] = item
324
+ continue
325
+
326
+ if isinstance(item, (str, os.PathLike)):
327
+ paths.append(str(item))
328
+ path_positions.append(idx)
329
+ continue
330
+
331
+ raise TypeError(
332
+ "Each audio item must be a torch.Tensor of codes or a path-like string."
333
+ )
334
+
335
+ if len(paths) > 0:
336
+ encoded_from_paths = self.encode_audios_from_path(paths, n_vq)
337
+ if len(encoded_from_paths) != len(paths):
338
+ raise RuntimeError(
339
+ "encode_audios_from_path returned an unexpected number of items."
340
+ )
341
+ for pos, codes in zip(path_positions, encoded_from_paths):
342
+ encoded_items[pos] = codes
343
+
344
+ audio_codes_list = [cast(torch.Tensor, t) for t in encoded_items]
345
+ unified_codes.append(
346
+ self._get_unified_codes(
347
+ message["role"], content, audio_codes_list, truncation
348
+ )
349
+ )
350
+
351
+ unified_codes = torch.cat(unified_codes)
352
+ input_ids_list.append(unified_codes)
353
+
354
+ return BatchFeature(data=self._pad(input_ids_list))
355
+
356
+ @staticmethod
357
+ def build_user_message(
358
+ text: Optional[str] = None,
359
+ reference: Optional[List[Optional[Union[str, torch.Tensor]]]] = None,
360
+ instruction: Optional[str] = None,
361
+ tokens: Optional[int] = None,
362
+ quality: Optional[str] = None,
363
+ sound_event: Optional[str] = None,
364
+ ambient_sound: Optional[str] = None,
365
+ language: Optional[str] = None,
366
+ ) -> Dict:
367
+ if reference is not None and not isinstance(reference, list):
368
+ reference = [reference]
369
+ return UserMessage(
370
+ text=text,
371
+ reference=reference,
372
+ instruction=instruction,
373
+ tokens=tokens,
374
+ quality=quality,
375
+ sound_event=sound_event,
376
+ ambient_sound=ambient_sound,
377
+ language=language,
378
+ ).to_dict()
379
+
380
+ @staticmethod
381
+ def build_assistant_message(
382
+ audio_codes_list: List[Union[str, torch.Tensor]],
383
+ content: str = AUDIO_PLACEHOLDER,
384
+ ) -> Dict:
385
+ return AssistantMessage(
386
+ audio_codes_list=audio_codes_list,
387
+ content=content,
388
+ ).to_dict()
389
+
390
+ def _normalize_message(self, message: Union[Message, Dict]) -> Dict:
391
+ if isinstance(message, Message):
392
+ return message.to_dict()
393
+ if not isinstance(message, dict):
394
+ raise TypeError("Each message must be a Message or dict.")
395
+ if "role" not in message:
396
+ raise ValueError("Message dict must include a 'role' field.")
397
+ if "content" in message and "audio_codes_list" in message:
398
+ return message
399
+ role = message["role"]
400
+ if role == "user":
401
+ kwargs = {key: message.get(key) for key in USER_MESSAGE_FIELDS}
402
+ return self.build_user_message(**kwargs)
403
+ if role == "assistant":
404
+ return self.build_assistant_message(
405
+ audio_codes_list=message.get("audio_codes_list", []),
406
+ content=message.get("content", AUDIO_PLACEHOLDER),
407
+ )
408
+ raise ValueError(f"Unsupported role: {role}")
409
+
410
+ def _pad(self, input_ids_list: List[torch.Tensor]):
411
+ device = input_ids_list[0].device
412
+ lengths = torch.tensor([w.shape[0] for w in input_ids_list], device=device)
413
+ pad_input_ids = torch.nn.utils.rnn.pad_sequence(
414
+ input_ids_list,
415
+ batch_first=True,
416
+ padding_value=self.model_config.audio_pad_code,
417
+ padding_side="left",
418
+ )
419
+ other_channel_mask = (pad_input_ids.shape[1] - lengths).unsqueeze(
420
+ 1
421
+ ) > torch.arange(pad_input_ids.shape[1], device=device).unsqueeze(0)
422
+ pad_input_ids[..., 0][other_channel_mask] = self.model_config.pad_token_id
423
+ attention_mask = torch.zeros(
424
+ pad_input_ids.shape[0], pad_input_ids.shape[1], device=device
425
+ )
426
+ attention_mask[~other_channel_mask] = 1
427
+ attention_mask = attention_mask.bool()
428
+ return {
429
+ "input_ids": pad_input_ids, # [batch_size, seqlen, n_vq]
430
+ "attention_mask": attention_mask,
431
+ }
432
+
433
+ @staticmethod
434
+ def _replace_audio_placeholders(
435
+ content: str,
436
+ lengths: List[int],
437
+ n_vq: int,
438
+ gen_slot_token: str,
439
+ delay_slot_token: str,
440
+ audio_start_token: str,
441
+ audio_end_token: str,
442
+ ) -> str:
443
+ if n_vq < 1:
444
+ raise ValueError(f"n_vq must be >= 1, got {n_vq}")
445
+
446
+ num_placeholders = content.count(AUDIO_PLACEHOLDER)
447
+ if num_placeholders != len(lengths):
448
+ raise ValueError(
449
+ f"Number of {AUDIO_PLACEHOLDER} ({num_placeholders}) "
450
+ f"does not match lengths ({len(lengths)})"
451
+ )
452
+
453
+ def build_audio_block(length: int) -> str:
454
+ if length < 0:
455
+ raise ValueError(f"length must be >= 0, got {length}")
456
+
457
+ if length == 0:
458
+ return f"{audio_start_token}{audio_end_token}"
459
+
460
+ step_tokens = gen_slot_token * length + (delay_slot_token * (n_vq - 1))
461
+ return f"{audio_start_token}{step_tokens}{audio_end_token}"
462
+
463
+ lengths_iter = iter(lengths)
464
+
465
+ def replacer(match: re.Match) -> str:
466
+ length = next(lengths_iter)
467
+ return build_audio_block(length)
468
+
469
+ result = re.sub(re.escape(AUDIO_PLACEHOLDER), replacer, content)
470
+
471
+ return result
472
+
473
+ @staticmethod
474
+ def _merge_consecutive_audio_placeholders(
475
+ content: str,
476
+ audio_codes_list: List[torch.Tensor],
477
+ ) -> Tuple[str, List[torch.Tensor]]:
478
+ matches = list(re.finditer(re.escape(AUDIO_PLACEHOLDER), content))
479
+ if len(matches) <= 1:
480
+ return content, audio_codes_list
481
+
482
+ if len(matches) != len(audio_codes_list):
483
+ raise ValueError(
484
+ "Audio placeholders do not match the provided audio codes list."
485
+ )
486
+
487
+ new_audio_codes_list = []
488
+ new_parts = []
489
+ last_pos = 0
490
+ i = 0
491
+ while i < len(matches):
492
+ j = i
493
+ while (
494
+ j + 1 < len(matches)
495
+ and content[matches[j].end() : matches[j + 1].start()].strip() == ""
496
+ ):
497
+ j += 1
498
+
499
+ new_parts.append(content[last_pos : matches[i].start()])
500
+ new_parts.append(AUDIO_PLACEHOLDER)
501
+ last_pos = matches[j].end()
502
+
503
+ if j == i:
504
+ new_audio_codes_list.append(audio_codes_list[i])
505
+ else:
506
+ new_audio_codes_list.append(
507
+ torch.cat(audio_codes_list[i : j + 1], dim=0)
508
+ )
509
+
510
+ i = j + 1
511
+
512
+ new_parts.append(content[last_pos:])
513
+ return "".join(new_parts), new_audio_codes_list
514
+
515
+ @staticmethod
516
+ def apply_delay_pattern(codes: torch.Tensor, pad_code: int) -> torch.Tensor:
517
+ delayed_tokens = torch.full(
518
+ (codes.shape[0] + codes.shape[1] - 1, codes.shape[1]),
519
+ pad_code,
520
+ device=codes.device,
521
+ dtype=codes.dtype,
522
+ )
523
+ for i in range(codes.shape[1]):
524
+ delayed_tokens[i : i + codes.shape[0], i] = codes[:, i]
525
+ return delayed_tokens
526
+
527
+ @staticmethod
528
+ def apply_de_delay_pattern(delay_codes: torch.Tensor) -> torch.Tensor:
529
+ tokens = torch.full(
530
+ (delay_codes.shape[0] - delay_codes.shape[1] + 1, delay_codes.shape[1]),
531
+ 0,
532
+ device=delay_codes.device,
533
+ dtype=delay_codes.dtype,
534
+ )
535
+ for i in range(delay_codes.shape[1]):
536
+ tokens[:, i] = delay_codes[i : i + tokens.shape[0], i]
537
+ return tokens
538
+
539
+ def _get_unified_codes(
540
+ self,
541
+ role: str,
542
+ content: str,
543
+ audio_codes_list: List[torch.Tensor],
544
+ truncation: bool,
545
+ ) -> torch.Tensor:
546
+ """
547
+ 此时的 content 已经是带上了对话格式
548
+ """
549
+ if role == "user":
550
+ audio_gen_slot_token = audio_delay_slot_token = self.audio_user_slot_token
551
+ truncation = False
552
+ else:
553
+ audio_gen_slot_token = self.audio_assistant_gen_slot_token
554
+ audio_delay_slot_token = self.audio_assistant_delay_slot_token
555
+
556
+ if len(audio_codes_list):
557
+ n_vq = audio_codes_list[0].shape[1]
558
+ else:
559
+ n_vq = self.model_config.n_vq
560
+
561
+ if len(audio_codes_list) > 1 and AUDIO_PLACEHOLDER in content:
562
+ content, audio_codes_list = self._merge_consecutive_audio_placeholders(
563
+ content, audio_codes_list
564
+ )
565
+ content = self._replace_audio_placeholders(
566
+ content=content,
567
+ lengths=[len(audio_codes) for audio_codes in audio_codes_list],
568
+ n_vq=n_vq,
569
+ gen_slot_token=audio_gen_slot_token,
570
+ delay_slot_token=audio_delay_slot_token,
571
+ audio_start_token=self.audio_start_token,
572
+ audio_end_token=self.audio_end_token,
573
+ )
574
+ text_codes = torch.tensor(
575
+ self.tokenizer.encode(content),
576
+ device=audio_codes_list[0].device if audio_codes_list else None,
577
+ )
578
+
579
+ audio_start_indices = torch.where(
580
+ text_codes == self.model_config.audio_start_token_id
581
+ )[0]
582
+ audio_end_indices = torch.where(
583
+ text_codes == self.model_config.audio_end_token_id
584
+ )[0]
585
+ if len(audio_start_indices) != len(audio_codes_list) or len(
586
+ audio_end_indices
587
+ ) != len(audio_codes_list):
588
+ raise ValueError(
589
+ "Audio placeholders do not match the provided audio codes list."
590
+ )
591
+
592
+ delay_audio_codes_list = []
593
+ if len(audio_codes_list) == 0:
594
+ delay_audio_codes_list = torch.full(
595
+ (len(text_codes), n_vq),
596
+ self.model_config.audio_pad_code,
597
+ device=text_codes.device,
598
+ dtype=text_codes.dtype,
599
+ )
600
+ else:
601
+ prefix_idx = 0
602
+ for audio_start_idx_t, audio_end_idx_t, audio_codes in zip(
603
+ audio_start_indices, audio_end_indices, audio_codes_list
604
+ ):
605
+ audio_start_idx = int(audio_start_idx_t.item())
606
+ audio_end_idx = int(audio_end_idx_t.item())
607
+ delay_audio_codes = self.apply_delay_pattern(
608
+ audio_codes, self.model_config.audio_pad_code
609
+ )
610
+ pad_codes = torch.full(
611
+ (audio_start_idx - prefix_idx + 1, n_vq),
612
+ self.model_config.audio_pad_code,
613
+ device=audio_codes.device,
614
+ dtype=audio_codes.dtype,
615
+ )
616
+ delay_audio_codes_list.extend([pad_codes, delay_audio_codes])
617
+ prefix_idx = audio_end_idx
618
+
619
+ if truncation:
620
+ delay_audio_codes_list[-1] = delay_audio_codes_list[-1][
621
+ : -(n_vq - 1), :
622
+ ]
623
+ else:
624
+ last_audio_end_idx = int(audio_end_indices[-1].item())
625
+ pad_codes = torch.full(
626
+ (len(text_codes) - last_audio_end_idx, n_vq),
627
+ self.model_config.audio_pad_code,
628
+ device=audio_codes_list[0].device,
629
+ dtype=audio_codes_list[0].dtype,
630
+ )
631
+ delay_audio_codes_list.append(pad_codes)
632
+
633
+ delay_audio_codes_list = torch.cat(delay_audio_codes_list)
634
+
635
+ if text_codes.shape[0] != delay_audio_codes_list.shape[0]:
636
+ text_codes = text_codes[: delay_audio_codes_list.shape[0]]
637
+
638
+ unified_codes = torch.cat(
639
+ [text_codes.unsqueeze(1), delay_audio_codes_list], dim=1
640
+ )
641
+ return unified_codes
642
+
643
+ def _parse_text_codes(self, start_length, text_codes):
644
+ text = cast(str, self.tokenizer.decode(text_codes))
645
+ prefix = cast(str, self.tokenizer.decode(text_codes[:start_length]))
646
+ text = text[len(prefix) :]
647
+
648
+ AUDIO_PATTERN = re.compile(
649
+ rf"(?:{self.audio_start_token})?"
650
+ rf"(?:{self.audio_assistant_gen_slot_token})*"
651
+ rf"(?:{self.audio_assistant_delay_slot_token})*"
652
+ rf"{self.audio_end_token}"
653
+ )
654
+
655
+ def normalize_audio_segments(text: str) -> str:
656
+ def repl(match: re.Match) -> str:
657
+ seg = match.group(0)
658
+ # Replace with <|audio|> if gen_slot is present in the segment;
659
+ if self.audio_assistant_gen_slot_token in seg:
660
+ return AUDIO_PLACEHOLDER
661
+ # Otherwise, remove it.
662
+ return ""
663
+
664
+ return AUDIO_PATTERN.sub(repl, text)
665
+
666
+ return normalize_audio_segments(text)
667
+
668
+ def _parse_audio_codes(self, start_length, audio_codes):
669
+ # De-delay back to [T', n_vq]
670
+ audio_codes = self.apply_de_delay_pattern(audio_codes)
671
+
672
+ # Rows that are all pad are separators between real audio segments.
673
+ is_pad = (audio_codes == self.model_config.audio_pad_code).all(dim=1)
674
+ non_pad = ~is_pad
675
+ if not non_pad.any():
676
+ return []
677
+
678
+ idx = torch.nonzero(non_pad).squeeze(1)
679
+ breaks = torch.where(idx[1:] != idx[:-1] + 1)[0] + 1
680
+ if breaks.numel() == 0:
681
+ segments_idx = [idx]
682
+ else:
683
+ segments_idx = torch.split(idx, breaks.tolist())
684
+
685
+ audio_codes_list = [audio_codes[s] for s in segments_idx]
686
+
687
+ # Batch-decode all audio segments together.
688
+ decoded_audio_list = self.decode_audio_codes(audio_codes_list)
689
+
690
+ # Keep codec causal context by decoding the whole first segment first,
691
+ # then trim at waveform level according to start_length ratio.
692
+ if (
693
+ start_length > 0
694
+ and len(audio_codes_list) > 0
695
+ and len(decoded_audio_list) > 0
696
+ ):
697
+ first_codes_length = audio_codes_list[0].shape[0]
698
+ if first_codes_length > 0:
699
+ trim_ratio = max(
700
+ 0.0, min(float(start_length) / float(first_codes_length), 1.0)
701
+ )
702
+ first_audio = decoded_audio_list[0]
703
+ if trim_ratio >= 1.0:
704
+ decoded_audio_list = decoded_audio_list[1:]
705
+ elif trim_ratio > 0.0:
706
+ trim_samples = int(first_audio.shape[-1] * trim_ratio)
707
+ decoded_audio_list[0] = first_audio[..., trim_samples:]
708
+
709
+ return decoded_audio_list
710
+
711
+ def decode(self, output: List[Tuple[int, torch.Tensor]]):
712
+ """
713
+ 1. 这里不管怎样,都需要一个完整的 assistant generation ids;
714
+ 2. 支持从任意位置进行截断;
715
+ """
716
+
717
+ genearted_messages = []
718
+ for start_length, generation_ids in output:
719
+ content = self._parse_text_codes(start_length, generation_ids[:, 0])
720
+ audio_codes_list = self._parse_audio_codes(
721
+ start_length, generation_ids[:, 1:]
722
+ )
723
+ if content == "":
724
+ message = None
725
+ else:
726
+ message = AssistantMessage(
727
+ content=content,
728
+ audio_codes_list=cast(
729
+ List[Union[str, torch.Tensor]], audio_codes_list
730
+ ),
731
+ )
732
+ genearted_messages.append(message)
733
+ return genearted_messages
734
+
735
+ @staticmethod
736
+ def loudness_normalize(
737
+ wav: torch.Tensor,
738
+ target_dbfs: float = -20,
739
+ gain_range: tuple[float, float] = (-3.0, 3.0),
740
+ ) -> torch.Tensor:
741
+ wav = wav.to(torch.float32)
742
+ if wav.numel() == 0:
743
+ return wav
744
+ current_dbfs = 10.0 * torch.log10(torch.mean(wav**2) + 1e-9)
745
+ gain = float(target_dbfs - current_dbfs)
746
+ gain = max(gain_range[0], min(gain, gain_range[1]))
747
+ factor = 10.0 ** (gain / 20.0)
748
+ return wav * factor
749
+
750
+ def _get_audio_tokenizer_device(self) -> torch.device:
751
+ """Best-effort device inference for `self.audio_tokenizer`.
752
+
753
+ Notes:
754
+ - Old TAC wrapper exposed `.device`, but standard `torch.nn.Module` does not.
755
+ - New MossAudioTokenizerModel is a `PreTrainedModel`; parameters define its device.
756
+ """
757
+
758
+ audio_tokenizer = getattr(self, "audio_tokenizer", None)
759
+ if audio_tokenizer is None:
760
+ logger.warning(
761
+ "audio_tokenizer is not set on processor. Using CPU as default."
762
+ )
763
+ return torch.device("cpu")
764
+
765
+ device_attr = getattr(audio_tokenizer, "device", None)
766
+ if isinstance(device_attr, torch.device):
767
+ return device_attr
768
+
769
+ try:
770
+ return next(audio_tokenizer.parameters()).device
771
+ except StopIteration:
772
+ # No parameters (shouldn't happen for real models); default to CPU.
773
+ logger.warning(
774
+ "No parameters found on audio_tokenizer. Using CPU as default."
775
+ )
776
+ return torch.device("cpu")
777
+
778
+ def encode_audios_from_wav(
779
+ self,
780
+ wav_list: List[torch.Tensor],
781
+ sampling_rate: int,
782
+ n_vq: Optional[int] = None,
783
+ ):
784
+ if self.audio_tokenizer is None:
785
+ raise RuntimeError("audio_tokenizer is not set on processor.")
786
+ audio_tokenizer = self.audio_tokenizer
787
+
788
+ if isinstance(wav_list, torch.Tensor):
789
+ wav_list = [wav_list]
790
+ wav_list_ = []
791
+ resample = False
792
+ if sampling_rate != self.model_config.sampling_rate:
793
+ resample = True
794
+ device = self._get_audio_tokenizer_device()
795
+ for wav in wav_list:
796
+ if wav.shape[0] > 1:
797
+ wav = torch.mean(wav, dim=0, keepdim=True)
798
+ if resample:
799
+ wav = torchaudio.functional.resample(
800
+ waveform=wav,
801
+ orig_freq=sampling_rate,
802
+ new_freq=self.model_config.sampling_rate,
803
+ )
804
+ wav = wav.to(device)
805
+ wav_list_.append(self.loudness_normalize(wav.squeeze(0)))
806
+
807
+ # New MossAudioTokenizerModel API: prefer batch_encode(list[wav])
808
+ if hasattr(audio_tokenizer, "batch_encode"):
809
+ enc = audio_tokenizer.batch_encode(wav_list_, num_quantizers=n_vq)
810
+ audio_codes = enc.audio_codes # (NQ, B, T)
811
+ audio_codes_lengths = enc.audio_codes_lengths # (B,)
812
+ else:
813
+ # Fallback: use encode() with explicit padding.
814
+ max_len = max(int(wav.shape[-1]) for wav in wav_list_)
815
+ input_values = torch.zeros(
816
+ len(wav_list_), 1, max_len, device=device, dtype=torch.float32
817
+ )
818
+ padding_mask = torch.zeros(
819
+ len(wav_list_), max_len, device=device, dtype=torch.bool
820
+ )
821
+ for i, wav in enumerate(wav_list_):
822
+ this_len = int(wav.shape[-1])
823
+ input_values[i, 0, :this_len] = wav
824
+ padding_mask[i, :this_len] = True
825
+ enc = audio_tokenizer.encode(
826
+ input_values,
827
+ padding_mask=padding_mask,
828
+ num_quantizers=n_vq,
829
+ return_dict=True,
830
+ )
831
+ audio_codes = enc.audio_codes
832
+ audio_codes_lengths = enc.audio_codes_lengths
833
+
834
+ if audio_codes is None or audio_codes_lengths is None:
835
+ raise RuntimeError(
836
+ "audio_tokenizer.encode() returned empty outputs (audio_codes/audio_codes_lengths)."
837
+ )
838
+
839
+ # Keep processor's historical contract: list[Tensor] with shape (T, NQ)
840
+ # and on CPU (so downstream text/audio packing remains device-agnostic).
841
+ codes_list: List[torch.Tensor] = []
842
+ for i in range(int(audio_codes.shape[1])):
843
+ length_i = int(audio_codes_lengths[i].item())
844
+ codes_i = (
845
+ audio_codes[:, i, :length_i]
846
+ .transpose(0, 1)
847
+ .contiguous()
848
+ .to(torch.long)
849
+ .cpu()
850
+ )
851
+ codes_list.append(codes_i)
852
+ return codes_list
853
+
854
+ def encode_audios_from_path(
855
+ self, wav_path_list: Union[str, List[str]], n_vq: Optional[int] = None
856
+ ):
857
+ if isinstance(wav_path_list, str):
858
+ wav_path_list = [wav_path_list]
859
+
860
+ if len(wav_path_list) == 0:
861
+ raise ValueError("Empty wav_path_list")
862
+
863
+ # Load + (if needed) resample each wav independently, so callers can
864
+ # pass a heterogeneous batch of files while still benefiting from
865
+ # audio_tokenizer.batch_encode.
866
+ target_sr = int(self.model_config.sampling_rate)
867
+ wav_list: List[torch.Tensor] = []
868
+ for wav_path in wav_path_list:
869
+ wav, sr = torchaudio.load(wav_path)
870
+ if int(sr) != target_sr:
871
+ wav = torchaudio.functional.resample(
872
+ waveform=wav,
873
+ orig_freq=int(sr),
874
+ new_freq=target_sr,
875
+ )
876
+ wav_list.append(wav)
877
+
878
+ return self.encode_audios_from_wav(wav_list, target_sr, n_vq)
879
+
880
+ def decode_audio_codes(
881
+ self, audio_tokens_list: Union[torch.Tensor, List[torch.Tensor]]
882
+ ):
883
+ if self.audio_tokenizer is None:
884
+ raise RuntimeError("audio_tokenizer is not set on processor.")
885
+ audio_tokenizer = self.audio_tokenizer
886
+
887
+ if isinstance(audio_tokens_list, torch.Tensor):
888
+ audio_tokens_list = [audio_tokens_list]
889
+ if len(audio_tokens_list) == 0:
890
+ return []
891
+
892
+ device = self._get_audio_tokenizer_device()
893
+
894
+ # Processor uses (T, NQ); MossAudioTokenizer expects (NQ, T) (or (NQ, B, T)).
895
+ codes_list = [
896
+ codes.transpose(0, 1).contiguous().to(device=device, dtype=torch.long)
897
+ for codes in audio_tokens_list
898
+ ]
899
+
900
+ # Fallback: pad to (NQ, B, T) + mask, then decode.
901
+ nq = int(codes_list[0].shape[0])
902
+ max_t = max(int(c.shape[1]) for c in codes_list)
903
+ audio_codes = torch.zeros(
904
+ nq, len(codes_list), max_t, device=device, dtype=torch.long
905
+ )
906
+ padding_mask = torch.zeros(
907
+ len(codes_list), max_t, device=device, dtype=torch.bool
908
+ )
909
+ for i, c in enumerate(codes_list):
910
+ t = int(c.shape[1])
911
+ audio_codes[:, i, :t] = c
912
+ padding_mask[i, :t] = True
913
+ dec = audio_tokenizer.decode(
914
+ audio_codes, padding_mask=padding_mask, return_dict=True, chunk_duration=8
915
+ )
916
+ audio = dec.audio
917
+ audio_lengths = dec.audio_lengths
918
+
919
+ if audio is None or audio_lengths is None:
920
+ raise RuntimeError(
921
+ "audio_tokenizer.decode() returned empty outputs (audio/audio_lengths)."
922
+ )
923
+
924
+ # Return historical contract: list of 1D waveforms (T,)
925
+ wav_list: List[torch.Tensor] = []
926
+ for i in range(int(audio.shape[0])):
927
+ length_i = int(audio_lengths[i].item())
928
+ wav = audio[i, 0, :length_i].contiguous().to(torch.float32).cpu()
929
+ wav_list.append(wav)
930
+ return wav_list
processing_moss_tts.py ADDED
@@ -0,0 +1,930 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2026 OpenMOSS and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import os
17
+ from typing import Any, Dict, List, Optional, Tuple, Type, Union, Literal, Final, cast
18
+ from dataclasses import dataclass
19
+ from pathlib import Path
20
+ import re
21
+ import torchaudio
22
+
23
+ from transformers import processing_utils
24
+
25
+ processing_utils.MODALITY_TO_BASE_CLASS_MAPPING["audio_tokenizer"] = "PreTrainedModel"
26
+
27
+ import torch
28
+ from transformers import (
29
+ PreTrainedTokenizerBase,
30
+ BatchFeature,
31
+ ProcessorMixin,
32
+ logging,
33
+ AutoConfig,
34
+ AutoModel,
35
+ AutoTokenizer,
36
+ )
37
+
38
+ from .configuration_moss_tts import MossTTSDelayConfig
39
+
40
+
41
+ logger = logging.get_logger(__name__)
42
+
43
+
44
+ AUDIO_PLACEHOLDER = "<|audio|>"
45
+
46
+
47
+ @dataclass
48
+ class Message:
49
+ def to_dict(self) -> Dict[str, Any]:
50
+ raise NotImplementedError
51
+
52
+
53
+ @dataclass
54
+ class UserMessage(Message):
55
+ text: Optional[str] = None
56
+ reference: Optional[List[Optional[Union[str, torch.Tensor]]]] = None
57
+ instruction: Optional[str] = None
58
+ tokens: Optional[int] = None
59
+ quality: Optional[str] = None
60
+ sound_event: Optional[str] = None
61
+ ambient_sound: Optional[str] = None
62
+ language: Optional[str] = None
63
+
64
+ def __post_init__(self):
65
+ template = """<user_inst>
66
+ - Reference(s):
67
+ {reference}
68
+ - Instruction:
69
+ {instruction}
70
+ - Tokens:
71
+ {tokens}
72
+ - Quality:
73
+ {quality}
74
+ - Sound Event:
75
+ {sound_event}
76
+ - Ambient Sound:
77
+ {ambient_sound}
78
+ - Language:
79
+ {language}
80
+ - Text:
81
+ {text}
82
+ </user_inst>"""
83
+
84
+ audio_codes_list = []
85
+ if self.reference is None:
86
+ reference = "None"
87
+ elif isinstance(self.reference, List):
88
+ reference = []
89
+ for speaker_idx, speaker_reference in enumerate(self.reference):
90
+ if speaker_reference is not None:
91
+ reference.append(f"[S{speaker_idx+1}]:\n{AUDIO_PLACEHOLDER}")
92
+ reference = "\n".join(reference)
93
+ audio_codes_list = [
94
+ speaker_reference
95
+ for speaker_reference in self.reference
96
+ if speaker_reference is not None
97
+ ]
98
+ else:
99
+ raise TypeError("`reference` should be exactly a list when it is not None.")
100
+
101
+ content = (
102
+ template.replace("{reference}", str(reference))
103
+ .replace("{instruction}", str(self.instruction))
104
+ .replace("{tokens}", str(self.tokens))
105
+ .replace("{quality}", str(self.quality))
106
+ .replace("{sound_event}", str(self.sound_event))
107
+ .replace("{ambient_sound}", str(self.ambient_sound))
108
+ .replace("{language}", str(self.language))
109
+ .replace("{text}", str(self.text))
110
+ )
111
+
112
+ self._content = content
113
+ self._audio_codes_list = audio_codes_list
114
+
115
+ def to_dict(self):
116
+ return {
117
+ "role": "user",
118
+ "content": self._content,
119
+ "audio_codes_list": self._audio_codes_list,
120
+ }
121
+
122
+
123
+ @dataclass
124
+ class AssistantMessage(Message):
125
+ audio_codes_list: List[Union[str, torch.Tensor]]
126
+ content: str = AUDIO_PLACEHOLDER
127
+
128
+ def to_dict(self):
129
+ return {
130
+ "role": "assistant",
131
+ "content": self.content,
132
+ "audio_codes_list": self.audio_codes_list,
133
+ }
134
+
135
+
136
+ USER_MESSAGE_FIELDS = (
137
+ "text",
138
+ "reference",
139
+ "instruction",
140
+ "tokens",
141
+ "quality",
142
+ "sound_event",
143
+ "ambient_sound",
144
+ "language",
145
+ )
146
+
147
+
148
+ class MossTTSDelayProcessor(ProcessorMixin):
149
+ tokenizer_class = "AutoTokenizer"
150
+ audio_tokenizer_class = "AutoModel"
151
+
152
+ tokenizer: PreTrainedTokenizerBase
153
+ audio_tokenizer: Any
154
+
155
+ def __init__(
156
+ self,
157
+ tokenizer: PreTrainedTokenizerBase,
158
+ audio_tokenizer: Any = None,
159
+ model_config: Optional[MossTTSDelayConfig] = None,
160
+ **kwargs,
161
+ ):
162
+ super().__init__(tokenizer=tokenizer, audio_tokenizer=audio_tokenizer, **kwargs)
163
+
164
+ # Explicit assignments for type-checkers; ProcessorMixin sets these too.
165
+ self.tokenizer = tokenizer
166
+ self.audio_tokenizer = audio_tokenizer
167
+ if model_config is None:
168
+ model_config = MossTTSDelayConfig()
169
+ self.model_config = model_config
170
+
171
+ self.imstart_token_id = tokenizer.convert_tokens_to_ids("<|im_start|>")
172
+ self.imend_token_id = tokenizer.convert_tokens_to_ids("<|im_end|>")
173
+ self.newline_token_id = 198
174
+
175
+ def _id_to_token(token_id: int) -> str:
176
+ tok = tokenizer.convert_ids_to_tokens(int(token_id))
177
+ if isinstance(tok, list):
178
+ return tok[0] if len(tok) > 0 else ""
179
+ return cast(str, tok)
180
+
181
+ self.audio_user_slot_token = _id_to_token(
182
+ self.model_config.audio_user_slot_token_id
183
+ )
184
+ self.audio_assistant_gen_slot_token = _id_to_token(
185
+ self.model_config.audio_assistant_gen_slot_token_id
186
+ )
187
+ self.audio_assistant_delay_slot_token = _id_to_token(
188
+ self.model_config.audio_assistant_delay_slot_token_id
189
+ )
190
+ self.audio_start_token = _id_to_token(self.model_config.audio_start_token_id)
191
+ self.audio_end_token = _id_to_token(self.model_config.audio_end_token_id)
192
+
193
+ @classmethod
194
+ def from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs):
195
+ trust_remote_code = kwargs.pop("trust_remote_code", True)
196
+ kwargs.pop("_from_auto", None)
197
+
198
+ audio_tokenizer_name_or_path = kwargs.pop(
199
+ "codec_path", "OpenMOSS-Team/MOSS-Audio-Tokenizer"
200
+ )
201
+
202
+ pretrained_model_name_or_path = Path(pretrained_model_name_or_path)
203
+ model_config = cast(
204
+ MossTTSDelayConfig,
205
+ AutoConfig.from_pretrained(
206
+ pretrained_model_name_or_path,
207
+ *args,
208
+ trust_remote_code=trust_remote_code,
209
+ **kwargs,
210
+ ),
211
+ )
212
+ tokenizer = AutoTokenizer.from_pretrained(
213
+ pretrained_model_name_or_path,
214
+ *args,
215
+ trust_remote_code=trust_remote_code,
216
+ **kwargs,
217
+ )
218
+ audio_tokenizer = AutoModel.from_pretrained(
219
+ audio_tokenizer_name_or_path,
220
+ trust_remote_code=trust_remote_code,
221
+ **kwargs,
222
+ )
223
+
224
+ return cls(
225
+ tokenizer=tokenizer,
226
+ audio_tokenizer=audio_tokenizer,
227
+ model_config=model_config,
228
+ **kwargs,
229
+ )
230
+
231
+ def __call__(self, *args, **kwargs) -> BatchFeature:
232
+ conversations = args[0] if len(args) > 0 else kwargs.pop("conversations")
233
+ mode: str = kwargs.pop("mode", "generation")
234
+ apply_chat_template: bool = kwargs.pop("apply_chat_template", True)
235
+ n_vq: Optional[int] = kwargs.pop("n_vq", None)
236
+
237
+ # Common ProcessorMixin kwargs that we ignore because we always return torch tensors.
238
+ kwargs.pop("return_tensors", None)
239
+ kwargs.pop("padding", None)
240
+ kwargs.pop("truncation", None)
241
+
242
+ """
243
+ mode only works when a Message is converted to a dict.
244
+ """
245
+
246
+ if mode not in {"generation", "continuation"}:
247
+ raise RuntimeError
248
+
249
+ if isinstance(conversations, (Message, Dict)):
250
+ conversations = [conversations]
251
+
252
+ truncation = False
253
+ if mode == "continuation":
254
+ truncation = True
255
+
256
+ input_ids_list = []
257
+ for conversation in conversations:
258
+ if isinstance(conversation, (Message, Dict)):
259
+ conversation = [conversation]
260
+
261
+ # Normalize early so downstream logic always deals with dict messages.
262
+ conversation = [self._normalize_message(m) for m in conversation]
263
+
264
+ if (mode == "generation") ^ (len(conversation) % 2 != 0):
265
+ raise ValueError
266
+
267
+ if (mode == "generation") ^ (conversation[-1]["role"] == "user"):
268
+ raise ValueError
269
+
270
+ unified_codes = []
271
+ for message_idx, message in enumerate(conversation):
272
+ if apply_chat_template:
273
+ add_generation_prompt = (
274
+ mode == "generation" and message_idx == len(conversation) - 1
275
+ )
276
+ try:
277
+ content = self.tokenizer.apply_chat_template(
278
+ [{"role": message["role"], "content": message["content"]}],
279
+ add_generation_prompt=add_generation_prompt,
280
+ tokenize=False,
281
+ )
282
+ except TypeError:
283
+ try:
284
+ content = self.tokenizer.apply_chat_template(
285
+ [
286
+ {
287
+ "role": message["role"],
288
+ "content": message["content"],
289
+ }
290
+ ],
291
+ add_generation_prompt=add_generation_prompt,
292
+ )
293
+ except Exception:
294
+ logger.warning(
295
+ "apply_chat_template failed; fallback to raw content."
296
+ )
297
+ content = message["content"]
298
+ else:
299
+ content = message["content"]
300
+
301
+ if not isinstance(content, str):
302
+ content = str(content)
303
+
304
+ # Batch-encode all path-based references in one call when possible.
305
+ # This ensures we actually exercise audio_tokenizer.batch_encode for multi-reference prompts,
306
+ # instead of repeatedly calling it with batch=1.
307
+ raw_audio_items = message.get("audio_codes_list", [])
308
+
309
+ audio_codes_list: List[torch.Tensor] = []
310
+ if len(raw_audio_items) > 0:
311
+ encoded_items: List[Optional[torch.Tensor]] = [None] * len(
312
+ raw_audio_items
313
+ )
314
+ paths: List[str] = []
315
+ path_positions: List[int] = []
316
+
317
+ for idx, item in enumerate(raw_audio_items):
318
+ if isinstance(item, torch.Tensor):
319
+ if n_vq is not None and item.shape[1] != n_vq:
320
+ raise RuntimeError(
321
+ "audio_codes's n_vq is not equal to the parameter `n_vq`. Your can set the parameter `n_vq` as None if you have already tokenzied the wavs."
322
+ )
323
+ encoded_items[idx] = item
324
+ continue
325
+
326
+ if isinstance(item, (str, os.PathLike)):
327
+ paths.append(str(item))
328
+ path_positions.append(idx)
329
+ continue
330
+
331
+ raise TypeError(
332
+ "Each audio item must be a torch.Tensor of codes or a path-like string."
333
+ )
334
+
335
+ if len(paths) > 0:
336
+ encoded_from_paths = self.encode_audios_from_path(paths, n_vq)
337
+ if len(encoded_from_paths) != len(paths):
338
+ raise RuntimeError(
339
+ "encode_audios_from_path returned an unexpected number of items."
340
+ )
341
+ for pos, codes in zip(path_positions, encoded_from_paths):
342
+ encoded_items[pos] = codes
343
+
344
+ audio_codes_list = [cast(torch.Tensor, t) for t in encoded_items]
345
+ unified_codes.append(
346
+ self._get_unified_codes(
347
+ message["role"], content, audio_codes_list, truncation
348
+ )
349
+ )
350
+
351
+ unified_codes = torch.cat(unified_codes)
352
+ input_ids_list.append(unified_codes)
353
+
354
+ return BatchFeature(data=self._pad(input_ids_list))
355
+
356
+ @staticmethod
357
+ def build_user_message(
358
+ text: Optional[str] = None,
359
+ reference: Optional[List[Optional[Union[str, torch.Tensor]]]] = None,
360
+ instruction: Optional[str] = None,
361
+ tokens: Optional[int] = None,
362
+ quality: Optional[str] = None,
363
+ sound_event: Optional[str] = None,
364
+ ambient_sound: Optional[str] = None,
365
+ language: Optional[str] = None,
366
+ ) -> Dict:
367
+ if reference is not None and not isinstance(reference, list):
368
+ reference = [reference]
369
+ return UserMessage(
370
+ text=text,
371
+ reference=reference,
372
+ instruction=instruction,
373
+ tokens=tokens,
374
+ quality=quality,
375
+ sound_event=sound_event,
376
+ ambient_sound=ambient_sound,
377
+ language=language,
378
+ ).to_dict()
379
+
380
+ @staticmethod
381
+ def build_assistant_message(
382
+ audio_codes_list: List[Union[str, torch.Tensor]],
383
+ content: str = AUDIO_PLACEHOLDER,
384
+ ) -> Dict:
385
+ return AssistantMessage(
386
+ audio_codes_list=audio_codes_list,
387
+ content=content,
388
+ ).to_dict()
389
+
390
+ def _normalize_message(self, message: Union[Message, Dict]) -> Dict:
391
+ if isinstance(message, Message):
392
+ return message.to_dict()
393
+ if not isinstance(message, dict):
394
+ raise TypeError("Each message must be a Message or dict.")
395
+ if "role" not in message:
396
+ raise ValueError("Message dict must include a 'role' field.")
397
+ if "content" in message and "audio_codes_list" in message:
398
+ return message
399
+ role = message["role"]
400
+ if role == "user":
401
+ kwargs = {key: message.get(key) for key in USER_MESSAGE_FIELDS}
402
+ return self.build_user_message(**kwargs)
403
+ if role == "assistant":
404
+ return self.build_assistant_message(
405
+ audio_codes_list=message.get("audio_codes_list", []),
406
+ content=message.get("content", AUDIO_PLACEHOLDER),
407
+ )
408
+ raise ValueError(f"Unsupported role: {role}")
409
+
410
+ def _pad(self, input_ids_list: List[torch.Tensor]):
411
+ device = input_ids_list[0].device
412
+ lengths = torch.tensor([w.shape[0] for w in input_ids_list], device=device)
413
+ pad_input_ids = torch.nn.utils.rnn.pad_sequence(
414
+ input_ids_list,
415
+ batch_first=True,
416
+ padding_value=self.model_config.audio_pad_code,
417
+ padding_side="left",
418
+ )
419
+ other_channel_mask = (pad_input_ids.shape[1] - lengths).unsqueeze(
420
+ 1
421
+ ) > torch.arange(pad_input_ids.shape[1], device=device).unsqueeze(0)
422
+ pad_input_ids[..., 0][other_channel_mask] = self.model_config.pad_token_id
423
+ attention_mask = torch.zeros(
424
+ pad_input_ids.shape[0], pad_input_ids.shape[1], device=device
425
+ )
426
+ attention_mask[~other_channel_mask] = 1
427
+ attention_mask = attention_mask.bool()
428
+ return {
429
+ "input_ids": pad_input_ids, # [batch_size, seqlen, n_vq]
430
+ "attention_mask": attention_mask,
431
+ }
432
+
433
+ @staticmethod
434
+ def _replace_audio_placeholders(
435
+ content: str,
436
+ lengths: List[int],
437
+ n_vq: int,
438
+ gen_slot_token: str,
439
+ delay_slot_token: str,
440
+ audio_start_token: str,
441
+ audio_end_token: str,
442
+ ) -> str:
443
+ if n_vq < 1:
444
+ raise ValueError(f"n_vq must be >= 1, got {n_vq}")
445
+
446
+ num_placeholders = content.count(AUDIO_PLACEHOLDER)
447
+ if num_placeholders != len(lengths):
448
+ raise ValueError(
449
+ f"Number of {AUDIO_PLACEHOLDER} ({num_placeholders}) "
450
+ f"does not match lengths ({len(lengths)})"
451
+ )
452
+
453
+ def build_audio_block(length: int) -> str:
454
+ if length < 0:
455
+ raise ValueError(f"length must be >= 0, got {length}")
456
+
457
+ if length == 0:
458
+ return f"{audio_start_token}{audio_end_token}"
459
+
460
+ step_tokens = gen_slot_token * length + (delay_slot_token * (n_vq - 1))
461
+ return f"{audio_start_token}{step_tokens}{audio_end_token}"
462
+
463
+ lengths_iter = iter(lengths)
464
+
465
+ def replacer(match: re.Match) -> str:
466
+ length = next(lengths_iter)
467
+ return build_audio_block(length)
468
+
469
+ result = re.sub(re.escape(AUDIO_PLACEHOLDER), replacer, content)
470
+
471
+ return result
472
+
473
+ @staticmethod
474
+ def _merge_consecutive_audio_placeholders(
475
+ content: str,
476
+ audio_codes_list: List[torch.Tensor],
477
+ ) -> Tuple[str, List[torch.Tensor]]:
478
+ matches = list(re.finditer(re.escape(AUDIO_PLACEHOLDER), content))
479
+ if len(matches) <= 1:
480
+ return content, audio_codes_list
481
+
482
+ if len(matches) != len(audio_codes_list):
483
+ raise ValueError(
484
+ "Audio placeholders do not match the provided audio codes list."
485
+ )
486
+
487
+ new_audio_codes_list = []
488
+ new_parts = []
489
+ last_pos = 0
490
+ i = 0
491
+ while i < len(matches):
492
+ j = i
493
+ while (
494
+ j + 1 < len(matches)
495
+ and content[matches[j].end() : matches[j + 1].start()].strip() == ""
496
+ ):
497
+ j += 1
498
+
499
+ new_parts.append(content[last_pos : matches[i].start()])
500
+ new_parts.append(AUDIO_PLACEHOLDER)
501
+ last_pos = matches[j].end()
502
+
503
+ if j == i:
504
+ new_audio_codes_list.append(audio_codes_list[i])
505
+ else:
506
+ new_audio_codes_list.append(
507
+ torch.cat(audio_codes_list[i : j + 1], dim=0)
508
+ )
509
+
510
+ i = j + 1
511
+
512
+ new_parts.append(content[last_pos:])
513
+ return "".join(new_parts), new_audio_codes_list
514
+
515
+ @staticmethod
516
+ def apply_delay_pattern(codes: torch.Tensor, pad_code: int) -> torch.Tensor:
517
+ delayed_tokens = torch.full(
518
+ (codes.shape[0] + codes.shape[1] - 1, codes.shape[1]),
519
+ pad_code,
520
+ device=codes.device,
521
+ dtype=codes.dtype,
522
+ )
523
+ for i in range(codes.shape[1]):
524
+ delayed_tokens[i : i + codes.shape[0], i] = codes[:, i]
525
+ return delayed_tokens
526
+
527
+ @staticmethod
528
+ def apply_de_delay_pattern(delay_codes: torch.Tensor) -> torch.Tensor:
529
+ tokens = torch.full(
530
+ (delay_codes.shape[0] - delay_codes.shape[1] + 1, delay_codes.shape[1]),
531
+ 0,
532
+ device=delay_codes.device,
533
+ dtype=delay_codes.dtype,
534
+ )
535
+ for i in range(delay_codes.shape[1]):
536
+ tokens[:, i] = delay_codes[i : i + tokens.shape[0], i]
537
+ return tokens
538
+
539
+ def _get_unified_codes(
540
+ self,
541
+ role: str,
542
+ content: str,
543
+ audio_codes_list: List[torch.Tensor],
544
+ truncation: bool,
545
+ ) -> torch.Tensor:
546
+ """
547
+ 此时的 content 已经是带上了对话格式
548
+ """
549
+ if role == "user":
550
+ audio_gen_slot_token = audio_delay_slot_token = self.audio_user_slot_token
551
+ truncation = False
552
+ else:
553
+ audio_gen_slot_token = self.audio_assistant_gen_slot_token
554
+ audio_delay_slot_token = self.audio_assistant_delay_slot_token
555
+
556
+ if len(audio_codes_list):
557
+ n_vq = audio_codes_list[0].shape[1]
558
+ else:
559
+ n_vq = self.model_config.n_vq
560
+
561
+ if len(audio_codes_list) > 1 and AUDIO_PLACEHOLDER in content:
562
+ content, audio_codes_list = self._merge_consecutive_audio_placeholders(
563
+ content, audio_codes_list
564
+ )
565
+ content = self._replace_audio_placeholders(
566
+ content=content,
567
+ lengths=[len(audio_codes) for audio_codes in audio_codes_list],
568
+ n_vq=n_vq,
569
+ gen_slot_token=audio_gen_slot_token,
570
+ delay_slot_token=audio_delay_slot_token,
571
+ audio_start_token=self.audio_start_token,
572
+ audio_end_token=self.audio_end_token,
573
+ )
574
+ text_codes = torch.tensor(
575
+ self.tokenizer.encode(content),
576
+ device=audio_codes_list[0].device if audio_codes_list else None,
577
+ )
578
+
579
+ audio_start_indices = torch.where(
580
+ text_codes == self.model_config.audio_start_token_id
581
+ )[0]
582
+ audio_end_indices = torch.where(
583
+ text_codes == self.model_config.audio_end_token_id
584
+ )[0]
585
+ if len(audio_start_indices) != len(audio_codes_list) or len(
586
+ audio_end_indices
587
+ ) != len(audio_codes_list):
588
+ raise ValueError(
589
+ "Audio placeholders do not match the provided audio codes list."
590
+ )
591
+
592
+ delay_audio_codes_list = []
593
+ if len(audio_codes_list) == 0:
594
+ delay_audio_codes_list = torch.full(
595
+ (len(text_codes), n_vq),
596
+ self.model_config.audio_pad_code,
597
+ device=text_codes.device,
598
+ dtype=text_codes.dtype,
599
+ )
600
+ else:
601
+ prefix_idx = 0
602
+ for audio_start_idx_t, audio_end_idx_t, audio_codes in zip(
603
+ audio_start_indices, audio_end_indices, audio_codes_list
604
+ ):
605
+ audio_start_idx = int(audio_start_idx_t.item())
606
+ audio_end_idx = int(audio_end_idx_t.item())
607
+ delay_audio_codes = self.apply_delay_pattern(
608
+ audio_codes, self.model_config.audio_pad_code
609
+ )
610
+ pad_codes = torch.full(
611
+ (audio_start_idx - prefix_idx + 1, n_vq),
612
+ self.model_config.audio_pad_code,
613
+ device=audio_codes.device,
614
+ dtype=audio_codes.dtype,
615
+ )
616
+ delay_audio_codes_list.extend([pad_codes, delay_audio_codes])
617
+ prefix_idx = audio_end_idx
618
+
619
+ if truncation:
620
+ delay_audio_codes_list[-1] = delay_audio_codes_list[-1][
621
+ : -(n_vq - 1), :
622
+ ]
623
+ else:
624
+ last_audio_end_idx = int(audio_end_indices[-1].item())
625
+ pad_codes = torch.full(
626
+ (len(text_codes) - last_audio_end_idx, n_vq),
627
+ self.model_config.audio_pad_code,
628
+ device=audio_codes_list[0].device,
629
+ dtype=audio_codes_list[0].dtype,
630
+ )
631
+ delay_audio_codes_list.append(pad_codes)
632
+
633
+ delay_audio_codes_list = torch.cat(delay_audio_codes_list)
634
+
635
+ if text_codes.shape[0] != delay_audio_codes_list.shape[0]:
636
+ text_codes = text_codes[: delay_audio_codes_list.shape[0]]
637
+
638
+ unified_codes = torch.cat(
639
+ [text_codes.unsqueeze(1), delay_audio_codes_list], dim=1
640
+ )
641
+ return unified_codes
642
+
643
+ def _parse_text_codes(self, start_length, text_codes):
644
+ text = cast(str, self.tokenizer.decode(text_codes))
645
+ prefix = cast(str, self.tokenizer.decode(text_codes[:start_length]))
646
+ text = text[len(prefix) :]
647
+
648
+ AUDIO_PATTERN = re.compile(
649
+ rf"(?:{self.audio_start_token})?"
650
+ rf"(?:{self.audio_assistant_gen_slot_token})*"
651
+ rf"(?:{self.audio_assistant_delay_slot_token})*"
652
+ rf"{self.audio_end_token}"
653
+ )
654
+
655
+ def normalize_audio_segments(text: str) -> str:
656
+ def repl(match: re.Match) -> str:
657
+ seg = match.group(0)
658
+ # Replace with <|audio|> if gen_slot is present in the segment;
659
+ if self.audio_assistant_gen_slot_token in seg:
660
+ return AUDIO_PLACEHOLDER
661
+ # Otherwise, remove it.
662
+ return ""
663
+
664
+ return AUDIO_PATTERN.sub(repl, text)
665
+
666
+ return normalize_audio_segments(text)
667
+
668
+ def _parse_audio_codes(self, start_length, audio_codes):
669
+ # De-delay back to [T', n_vq]
670
+ audio_codes = self.apply_de_delay_pattern(audio_codes)
671
+
672
+ # Rows that are all pad are separators between real audio segments.
673
+ is_pad = (audio_codes == self.model_config.audio_pad_code).all(dim=1)
674
+ non_pad = ~is_pad
675
+ if not non_pad.any():
676
+ return []
677
+
678
+ idx = torch.nonzero(non_pad).squeeze(1)
679
+ breaks = torch.where(idx[1:] != idx[:-1] + 1)[0] + 1
680
+ if breaks.numel() == 0:
681
+ segments_idx = [idx]
682
+ else:
683
+ segments_idx = torch.split(idx, breaks.tolist())
684
+
685
+ audio_codes_list = [audio_codes[s] for s in segments_idx]
686
+
687
+ # Batch-decode all audio segments together.
688
+ decoded_audio_list = self.decode_audio_codes(audio_codes_list)
689
+
690
+ # Keep codec causal context by decoding the whole first segment first,
691
+ # then trim at waveform level according to start_length ratio.
692
+ if (
693
+ start_length > 0
694
+ and len(audio_codes_list) > 0
695
+ and len(decoded_audio_list) > 0
696
+ ):
697
+ first_codes_length = audio_codes_list[0].shape[0]
698
+ if first_codes_length > 0:
699
+ trim_ratio = max(
700
+ 0.0, min(float(start_length) / float(first_codes_length), 1.0)
701
+ )
702
+ first_audio = decoded_audio_list[0]
703
+ if trim_ratio >= 1.0:
704
+ decoded_audio_list = decoded_audio_list[1:]
705
+ elif trim_ratio > 0.0:
706
+ trim_samples = int(first_audio.shape[-1] * trim_ratio)
707
+ decoded_audio_list[0] = first_audio[..., trim_samples:]
708
+
709
+ return decoded_audio_list
710
+
711
+ def decode(self, output: List[Tuple[int, torch.Tensor]]):
712
+ """
713
+ 1. 这里不管怎样,都需要一个完整的 assistant generation ids;
714
+ 2. 支持从任意位置进行截断;
715
+ """
716
+
717
+ genearted_messages = []
718
+ for start_length, generation_ids in output:
719
+ content = self._parse_text_codes(start_length, generation_ids[:, 0])
720
+ audio_codes_list = self._parse_audio_codes(
721
+ start_length, generation_ids[:, 1:]
722
+ )
723
+ if content == "":
724
+ message = None
725
+ else:
726
+ message = AssistantMessage(
727
+ content=content,
728
+ audio_codes_list=cast(
729
+ List[Union[str, torch.Tensor]], audio_codes_list
730
+ ),
731
+ )
732
+ genearted_messages.append(message)
733
+ return genearted_messages
734
+
735
+ @staticmethod
736
+ def loudness_normalize(
737
+ wav: torch.Tensor,
738
+ target_dbfs: float = -20,
739
+ gain_range: tuple[float, float] = (-3.0, 3.0),
740
+ ) -> torch.Tensor:
741
+ wav = wav.to(torch.float32)
742
+ if wav.numel() == 0:
743
+ return wav
744
+ current_dbfs = 10.0 * torch.log10(torch.mean(wav**2) + 1e-9)
745
+ gain = float(target_dbfs - current_dbfs)
746
+ gain = max(gain_range[0], min(gain, gain_range[1]))
747
+ factor = 10.0 ** (gain / 20.0)
748
+ return wav * factor
749
+
750
+ def _get_audio_tokenizer_device(self) -> torch.device:
751
+ """Best-effort device inference for `self.audio_tokenizer`.
752
+
753
+ Notes:
754
+ - Old TAC wrapper exposed `.device`, but standard `torch.nn.Module` does not.
755
+ - New MossAudioTokenizerModel is a `PreTrainedModel`; parameters define its device.
756
+ """
757
+
758
+ audio_tokenizer = getattr(self, "audio_tokenizer", None)
759
+ if audio_tokenizer is None:
760
+ logger.warning(
761
+ "audio_tokenizer is not set on processor. Using CPU as default."
762
+ )
763
+ return torch.device("cpu")
764
+
765
+ device_attr = getattr(audio_tokenizer, "device", None)
766
+ if isinstance(device_attr, torch.device):
767
+ return device_attr
768
+
769
+ try:
770
+ return next(audio_tokenizer.parameters()).device
771
+ except StopIteration:
772
+ # No parameters (shouldn't happen for real models); default to CPU.
773
+ logger.warning(
774
+ "No parameters found on audio_tokenizer. Using CPU as default."
775
+ )
776
+ return torch.device("cpu")
777
+
778
+ def encode_audios_from_wav(
779
+ self,
780
+ wav_list: List[torch.Tensor],
781
+ sampling_rate: int,
782
+ n_vq: Optional[int] = None,
783
+ ):
784
+ if self.audio_tokenizer is None:
785
+ raise RuntimeError("audio_tokenizer is not set on processor.")
786
+ audio_tokenizer = self.audio_tokenizer
787
+
788
+ if isinstance(wav_list, torch.Tensor):
789
+ wav_list = [wav_list]
790
+ wav_list_ = []
791
+ resample = False
792
+ if sampling_rate != self.model_config.sampling_rate:
793
+ resample = True
794
+ device = self._get_audio_tokenizer_device()
795
+ for wav in wav_list:
796
+ if wav.shape[0] > 1:
797
+ wav = torch.mean(wav, dim=0, keepdim=True)
798
+ if resample:
799
+ wav = torchaudio.functional.resample(
800
+ waveform=wav,
801
+ orig_freq=sampling_rate,
802
+ new_freq=self.model_config.sampling_rate,
803
+ )
804
+ wav = wav.to(device)
805
+ wav_list_.append(self.loudness_normalize(wav.squeeze(0)))
806
+
807
+ # New MossAudioTokenizerModel API: prefer batch_encode(list[wav])
808
+ if hasattr(audio_tokenizer, "batch_encode"):
809
+ enc = audio_tokenizer.batch_encode(wav_list_, num_quantizers=n_vq)
810
+ audio_codes = enc.audio_codes # (NQ, B, T)
811
+ audio_codes_lengths = enc.audio_codes_lengths # (B,)
812
+ else:
813
+ # Fallback: use encode() with explicit padding.
814
+ max_len = max(int(wav.shape[-1]) for wav in wav_list_)
815
+ input_values = torch.zeros(
816
+ len(wav_list_), 1, max_len, device=device, dtype=torch.float32
817
+ )
818
+ padding_mask = torch.zeros(
819
+ len(wav_list_), max_len, device=device, dtype=torch.bool
820
+ )
821
+ for i, wav in enumerate(wav_list_):
822
+ this_len = int(wav.shape[-1])
823
+ input_values[i, 0, :this_len] = wav
824
+ padding_mask[i, :this_len] = True
825
+ enc = audio_tokenizer.encode(
826
+ input_values,
827
+ padding_mask=padding_mask,
828
+ num_quantizers=n_vq,
829
+ return_dict=True,
830
+ )
831
+ audio_codes = enc.audio_codes
832
+ audio_codes_lengths = enc.audio_codes_lengths
833
+
834
+ if audio_codes is None or audio_codes_lengths is None:
835
+ raise RuntimeError(
836
+ "audio_tokenizer.encode() returned empty outputs (audio_codes/audio_codes_lengths)."
837
+ )
838
+
839
+ # Keep processor's historical contract: list[Tensor] with shape (T, NQ)
840
+ # and on CPU (so downstream text/audio packing remains device-agnostic).
841
+ codes_list: List[torch.Tensor] = []
842
+ for i in range(int(audio_codes.shape[1])):
843
+ length_i = int(audio_codes_lengths[i].item())
844
+ codes_i = (
845
+ audio_codes[:, i, :length_i]
846
+ .transpose(0, 1)
847
+ .contiguous()
848
+ .to(torch.long)
849
+ .cpu()
850
+ )
851
+ codes_list.append(codes_i)
852
+ return codes_list
853
+
854
+ def encode_audios_from_path(
855
+ self, wav_path_list: Union[str, List[str]], n_vq: Optional[int] = None
856
+ ):
857
+ if isinstance(wav_path_list, str):
858
+ wav_path_list = [wav_path_list]
859
+
860
+ if len(wav_path_list) == 0:
861
+ raise ValueError("Empty wav_path_list")
862
+
863
+ # Load + (if needed) resample each wav independently, so callers can
864
+ # pass a heterogeneous batch of files while still benefiting from
865
+ # audio_tokenizer.batch_encode.
866
+ target_sr = int(self.model_config.sampling_rate)
867
+ wav_list: List[torch.Tensor] = []
868
+ for wav_path in wav_path_list:
869
+ wav, sr = torchaudio.load(wav_path)
870
+ if int(sr) != target_sr:
871
+ wav = torchaudio.functional.resample(
872
+ waveform=wav,
873
+ orig_freq=int(sr),
874
+ new_freq=target_sr,
875
+ )
876
+ wav_list.append(wav)
877
+
878
+ return self.encode_audios_from_wav(wav_list, target_sr, n_vq)
879
+
880
+ def decode_audio_codes(
881
+ self, audio_tokens_list: Union[torch.Tensor, List[torch.Tensor]]
882
+ ):
883
+ if self.audio_tokenizer is None:
884
+ raise RuntimeError("audio_tokenizer is not set on processor.")
885
+ audio_tokenizer = self.audio_tokenizer
886
+
887
+ if isinstance(audio_tokens_list, torch.Tensor):
888
+ audio_tokens_list = [audio_tokens_list]
889
+ if len(audio_tokens_list) == 0:
890
+ return []
891
+
892
+ device = self._get_audio_tokenizer_device()
893
+
894
+ # Processor uses (T, NQ); MossAudioTokenizer expects (NQ, T) (or (NQ, B, T)).
895
+ codes_list = [
896
+ codes.transpose(0, 1).contiguous().to(device=device, dtype=torch.long)
897
+ for codes in audio_tokens_list
898
+ ]
899
+
900
+ # Fallback: pad to (NQ, B, T) + mask, then decode.
901
+ nq = int(codes_list[0].shape[0])
902
+ max_t = max(int(c.shape[1]) for c in codes_list)
903
+ audio_codes = torch.zeros(
904
+ nq, len(codes_list), max_t, device=device, dtype=torch.long
905
+ )
906
+ padding_mask = torch.zeros(
907
+ len(codes_list), max_t, device=device, dtype=torch.bool
908
+ )
909
+ for i, c in enumerate(codes_list):
910
+ t = int(c.shape[1])
911
+ audio_codes[:, i, :t] = c
912
+ padding_mask[i, :t] = True
913
+ dec = audio_tokenizer.decode(
914
+ audio_codes, padding_mask=padding_mask, return_dict=True, chunk_duration=8
915
+ )
916
+ audio = dec.audio
917
+ audio_lengths = dec.audio_lengths
918
+
919
+ if audio is None or audio_lengths is None:
920
+ raise RuntimeError(
921
+ "audio_tokenizer.decode() returned empty outputs (audio/audio_lengths)."
922
+ )
923
+
924
+ # Return historical contract: list of 1D waveforms (T,)
925
+ wav_list: List[torch.Tensor] = []
926
+ for i in range(int(audio.shape[0])):
927
+ length_i = int(audio_lengths[i].item())
928
+ wav = audio[i, 0, :length_i].contiguous().to(torch.float32).cpu()
929
+ wav_list.append(wav)
930
+ return wav_list
quant_log.csv ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ layer,module,loss,samples,damp,time
2
+ 0,self_attn.v_proj,0.0000000010,0.01000,1.829
3
+ 0,self_attn.q_proj,0.0000000062,0.01000,1.845
4
+ 0,self_attn.k_proj,0.0000000016,0.01000,1.847
5
+ 0,self_attn.o_proj,0.0000000027,0.01000,0.577
6
+ 0,mlp.gate_proj,0.0000005435,0.01000,1.155
7
+ 0,mlp.up_proj,0.0000004846,0.01000,1.162
8
+ 0,mlp.down_proj,0.0000002644,0.01000,2.252
9
+ 1,self_attn.v_proj,0.0000000130,0.01000,1.642
10
+ 1,self_attn.q_proj,0.0000000625,0.01000,1.648
11
+ 1,self_attn.k_proj,0.0000000153,0.01000,1.652
12
+ 1,self_attn.o_proj,0.0000000898,0.01000,0.568
13
+ 1,mlp.up_proj,0.0000072422,0.01000,1.143
14
+ 1,mlp.gate_proj,0.0000082405,0.01000,1.145
15
+ 1,mlp.down_proj,0.0000001166,0.01000,2.235
16
+ 2,self_attn.q_proj,0.0000000749,0.01000,1.535
17
+ 2,self_attn.v_proj,0.0000000177,0.01000,1.563
18
+ 2,self_attn.k_proj,0.0000000193,0.01000,1.566
19
+ 2,self_attn.o_proj,0.0000000921,0.01000,0.570
20
+ 2,mlp.up_proj,0.0000127681,0.01000,1.150
21
+ 2,mlp.gate_proj,0.0000122131,0.01000,1.151
22
+ 2,mlp.down_proj,0.0000003517,0.01000,2.241
23
+ 3,self_attn.v_proj,0.0000000529,0.01000,1.574
24
+ 3,self_attn.k_proj,0.0000000404,0.01000,1.573
25
+ 3,self_attn.q_proj,0.0000001661,0.01000,1.543
26
+ 3,self_attn.o_proj,0.0000002439,0.01000,0.574
27
+ 3,mlp.up_proj,0.0000191999,0.01000,1.128
28
+ 3,mlp.gate_proj,0.0000186392,0.01000,1.133
29
+ 3,mlp.down_proj,0.0000030536,0.01000,2.273
30
+ 4,self_attn.v_proj,0.0000000613,0.01000,1.539
31
+ 4,self_attn.q_proj,0.0000002399,0.01000,1.545
32
+ 4,self_attn.k_proj,0.0000000552,0.01000,1.554
33
+ 4,self_attn.o_proj,0.0000003474,0.01000,0.573
34
+ 4,mlp.gate_proj,0.0000143707,0.01000,1.140
35
+ 4,mlp.up_proj,0.0000126579,0.01000,1.146
36
+ 4,mlp.down_proj,0.0000051150,0.01000,2.245
37
+ 5,self_attn.v_proj,0.0000000678,0.01000,1.541
38
+ 5,self_attn.q_proj,0.0000002662,0.01000,1.547
39
+ 5,self_attn.k_proj,0.0000000669,0.01000,1.552
40
+ 5,self_attn.o_proj,0.0000001778,0.01000,0.571
41
+ 5,mlp.gate_proj,0.0000023585,0.01000,1.141
42
+ 5,mlp.up_proj,0.0000018802,0.01000,1.149
43
+ 5,mlp.down_proj,0.0000004271,0.01000,2.224
44
+ 6,self_attn.q_proj,0.0000002649,0.01000,1.560
45
+ 6,self_attn.k_proj,0.0000000600,0.01000,1.563
46
+ 6,self_attn.v_proj,0.0000000583,0.01000,1.566
47
+ 6,self_attn.o_proj,0.0000001879,0.01000,0.583
48
+ 6,mlp.gate_proj,0.0000024982,0.01000,1.135
49
+ 6,mlp.up_proj,0.0000023775,0.01000,1.138
50
+ 6,mlp.down_proj,0.0000003491,0.01000,2.253
51
+ 7,self_attn.v_proj,0.0000000447,0.01000,1.562
52
+ 7,self_attn.k_proj,0.0000000380,0.01000,1.567
53
+ 7,self_attn.q_proj,0.0000001416,0.01000,1.576
54
+ 7,self_attn.o_proj,0.0000002175,0.01000,0.576
55
+ 7,mlp.up_proj,0.0000024159,0.01000,1.150
56
+ 7,mlp.gate_proj,0.0000028353,0.01000,1.154
57
+ 7,mlp.down_proj,0.0000003850,0.01000,2.244
58
+ 8,self_attn.q_proj,0.0000001304,0.01000,1.590
59
+ 8,self_attn.v_proj,0.0000000394,0.01000,1.592
60
+ 8,self_attn.k_proj,0.0000000326,0.01000,1.604
61
+ 8,self_attn.o_proj,0.0000001448,0.01000,0.575
62
+ 8,mlp.gate_proj,0.0000018485,0.01000,1.137
63
+ 8,mlp.up_proj,0.0000019048,0.01000,1.141
64
+ 8,mlp.down_proj,0.0000003137,0.01000,2.253
65
+ 9,self_attn.v_proj,0.0000000571,0.01000,1.579
66
+ 9,self_attn.q_proj,0.0000001757,0.01000,1.582
67
+ 9,self_attn.k_proj,0.0000000423,0.01000,1.585
68
+ 9,self_attn.o_proj,0.0000002859,0.01000,0.584
69
+ 9,mlp.gate_proj,0.0000019399,0.01000,1.186
70
+ 9,mlp.up_proj,0.0000018338,0.01000,1.193
71
+ 9,mlp.down_proj,0.0000003901,0.01000,2.240
72
+ 10,self_attn.v_proj,0.0000000418,0.01000,1.544
73
+ 10,self_attn.k_proj,0.0000000374,0.01000,1.549
74
+ 10,self_attn.q_proj,0.0000001466,0.01000,1.563
75
+ 10,self_attn.o_proj,0.0000003586,0.01000,0.568
76
+ 10,mlp.up_proj,0.0000012885,0.01000,1.135
77
+ 10,mlp.gate_proj,0.0000015318,0.01000,1.140
78
+ 10,mlp.down_proj,0.0000001714,0.01000,2.251
79
+ 11,self_attn.q_proj,0.0000000464,0.01000,1.541
80
+ 11,self_attn.v_proj,0.0000000131,0.01000,1.542
81
+ 11,self_attn.k_proj,0.0000000114,0.01000,1.546
82
+ 11,self_attn.o_proj,0.0000001012,0.01000,0.568
83
+ 11,mlp.gate_proj,0.0000006189,0.01000,1.147
84
+ 11,mlp.up_proj,0.0000005842,0.01000,1.161
85
+ 11,mlp.down_proj,0.0000001167,0.01000,2.239
86
+ 12,self_attn.q_proj,0.0000000243,0.01000,1.589
87
+ 12,self_attn.v_proj,0.0000000072,0.01000,1.600
88
+ 12,self_attn.k_proj,0.0000000058,0.01000,1.604
89
+ 12,self_attn.o_proj,0.0000000608,0.01000,0.578
90
+ 12,mlp.gate_proj,0.0000005512,0.01000,1.144
91
+ 12,mlp.up_proj,0.0000005652,0.01000,1.152
92
+ 12,mlp.down_proj,0.0000000815,0.01000,2.234
93
+ 13,self_attn.q_proj,0.0000000319,0.01000,1.542
94
+ 13,self_attn.v_proj,0.0000000089,0.01000,1.546
95
+ 13,self_attn.k_proj,0.0000000074,0.01000,1.549
96
+ 13,self_attn.o_proj,0.0000000500,0.01000,0.566
97
+ 13,mlp.gate_proj,0.0000004800,0.01000,1.142
98
+ 13,mlp.up_proj,0.0000004858,0.01000,1.147
99
+ 13,mlp.down_proj,0.0000000940,0.01000,2.240
100
+ 14,self_attn.k_proj,0.0000000096,0.01000,1.534
101
+ 14,self_attn.q_proj,0.0000000405,0.01000,1.539
102
+ 14,self_attn.v_proj,0.0000000106,0.01000,1.544
103
+ 14,self_attn.o_proj,0.0000000484,0.01000,0.575
104
+ 14,mlp.up_proj,0.0000005409,0.01000,1.146
105
+ 14,mlp.gate_proj,0.0000005316,0.01000,1.150
106
+ 14,mlp.down_proj,0.0000000756,0.01000,2.261
107
+ 15,self_attn.k_proj,0.0000000103,0.01000,1.544
108
+ 15,self_attn.q_proj,0.0000000466,0.01000,1.564
109
+ 15,self_attn.v_proj,0.0000000119,0.01000,1.567
110
+ 15,self_attn.o_proj,0.0000000454,0.01000,0.566
111
+ 15,mlp.up_proj,0.0000005134,0.01000,1.148
112
+ 15,mlp.gate_proj,0.0000005055,0.01000,1.153
113
+ 15,mlp.down_proj,0.0000001016,0.01000,2.260
114
+ 16,self_attn.k_proj,0.0000000187,0.01000,1.558
115
+ 16,self_attn.q_proj,0.0000000835,0.01000,1.570
116
+ 16,self_attn.v_proj,0.0000000236,0.01000,1.574
117
+ 16,self_attn.o_proj,0.0000000851,0.01000,0.576
118
+ 16,mlp.gate_proj,0.0000006101,0.01000,1.139
119
+ 16,mlp.up_proj,0.0000006160,0.01000,1.142
120
+ 16,mlp.down_proj,0.0000004110,0.01000,2.231
121
+ 17,self_attn.k_proj,0.0000000142,0.01000,1.549
122
+ 17,self_attn.v_proj,0.0000000171,0.01000,1.560
123
+ 17,self_attn.q_proj,0.0000000693,0.01000,1.566
124
+ 17,self_attn.o_proj,0.0000000767,0.01000,0.569
125
+ 17,mlp.gate_proj,0.0000005645,0.01000,1.157
126
+ 17,mlp.up_proj,0.0000005859,0.01000,1.164
127
+ 17,mlp.down_proj,0.0000000809,0.01000,2.231
128
+ 18,self_attn.q_proj,0.0000001014,0.01000,1.529
129
+ 18,self_attn.v_proj,0.0000000304,0.01000,1.539
130
+ 18,self_attn.k_proj,0.0000000222,0.01000,1.541
131
+ 18,self_attn.o_proj,0.0000000898,0.01000,0.566
132
+ 18,mlp.gate_proj,0.0000004769,0.01000,1.132
133
+ 18,mlp.up_proj,0.0000005321,0.01000,1.137
134
+ 18,mlp.down_proj,0.0000001979,0.01000,2.247
135
+ 19,self_attn.q_proj,0.0000001481,0.01000,1.541
136
+ 19,self_attn.k_proj,0.0000000314,0.01000,1.548
137
+ 19,self_attn.v_proj,0.0000000349,0.01000,1.551
138
+ 19,self_attn.o_proj,0.0000000803,0.01000,0.573
139
+ 19,mlp.gate_proj,0.0000004752,0.01000,1.147
140
+ 19,mlp.up_proj,0.0000004978,0.01000,1.149
141
+ 19,mlp.down_proj,0.0000000639,0.01000,2.242
142
+ 20,self_attn.q_proj,0.0000001669,0.01000,1.539
143
+ 20,self_attn.k_proj,0.0000000367,0.01000,1.551
144
+ 20,self_attn.v_proj,0.0000000457,0.01000,1.553
145
+ 20,self_attn.o_proj,0.0000000969,0.01000,0.567
146
+ 20,mlp.up_proj,0.0000004723,0.01000,1.139
147
+ 20,mlp.gate_proj,0.0000004650,0.01000,1.143
148
+ 20,mlp.down_proj,0.0000000665,0.01000,2.265
149
+ 21,self_attn.q_proj,0.0000001604,0.01000,1.552
150
+ 21,self_attn.v_proj,0.0000000494,0.01000,1.559
151
+ 21,self_attn.k_proj,0.0000000325,0.01000,1.566
152
+ 21,self_attn.o_proj,0.0000000864,0.01000,0.566
153
+ 21,mlp.gate_proj,0.0000004808,0.01000,1.142
154
+ 21,mlp.up_proj,0.0000005138,0.01000,1.148
155
+ 21,mlp.down_proj,0.0000002167,0.01000,2.243
156
+ 22,self_attn.q_proj,0.0000005798,0.01000,1.572
157
+ 22,self_attn.k_proj,0.0000001053,0.01000,1.580
158
+ 22,self_attn.v_proj,0.0000001031,0.01000,1.582
159
+ 22,self_attn.o_proj,0.0000001522,0.01000,0.563
160
+ 22,mlp.up_proj,0.0000006384,0.01000,1.142
161
+ 22,mlp.gate_proj,0.0000005433,0.01000,1.146
162
+ 22,mlp.down_proj,0.0000000918,0.01000,2.259
163
+ 23,self_attn.q_proj,0.0000006371,0.01000,1.548
164
+ 23,self_attn.k_proj,0.0000001273,0.01000,1.554
165
+ 23,self_attn.v_proj,0.0000001431,0.01000,1.557
166
+ 23,self_attn.o_proj,0.0000002528,0.01000,0.573
167
+ 23,mlp.gate_proj,0.0000006702,0.01000,1.130
168
+ 23,mlp.up_proj,0.0000007339,0.01000,1.137
169
+ 23,mlp.down_proj,0.0000000830,0.01000,2.247
170
+ 24,self_attn.k_proj,0.0000001151,0.01000,1.554
171
+ 24,self_attn.v_proj,0.0000001562,0.01000,1.558
172
+ 24,self_attn.q_proj,0.0000008313,0.01000,1.564
173
+ 24,self_attn.o_proj,0.0000002746,0.01000,0.572
174
+ 24,mlp.up_proj,0.0000009086,0.01000,1.142
175
+ 24,mlp.gate_proj,0.0000008630,0.01000,1.148
176
+ 24,mlp.down_proj,0.0000002657,0.01000,2.239
177
+ 25,self_attn.q_proj,0.0000007934,0.01000,1.552
178
+ 25,self_attn.v_proj,0.0000001541,0.01000,1.554
179
+ 25,self_attn.k_proj,0.0000001487,0.01000,1.561
180
+ 25,self_attn.o_proj,0.0000003166,0.01000,0.572
181
+ 25,mlp.gate_proj,0.0000008579,0.01000,1.151
182
+ 25,mlp.up_proj,0.0000009756,0.01000,1.156
183
+ 25,mlp.down_proj,0.0000002044,0.01000,2.242
184
+ 26,self_attn.q_proj,0.0000014293,0.01000,1.558
185
+ 26,self_attn.k_proj,0.0000002228,0.01000,1.562
186
+ 26,self_attn.v_proj,0.0000002375,0.01000,1.563
187
+ 26,self_attn.o_proj,0.0000004076,0.01000,0.567
188
+ 26,mlp.gate_proj,0.0000009329,0.01000,1.151
189
+ 26,mlp.up_proj,0.0000011207,0.01000,1.154
190
+ 26,mlp.down_proj,0.0000003374,0.01000,2.246
191
+ 27,self_attn.k_proj,0.0000004542,0.01000,1.571
192
+ 27,self_attn.q_proj,0.0000023284,0.01000,1.599
193
+ 27,self_attn.v_proj,0.0000008071,0.01000,1.606
194
+ 27,self_attn.o_proj,0.0000011174,0.01000,0.568
195
+ 27,mlp.up_proj,0.0000015285,0.01000,1.143
196
+ 27,mlp.gate_proj,0.0000011756,0.01000,1.147
197
+ 27,mlp.down_proj,0.0000007143,0.01000,2.246
198
+ 28,self_attn.v_proj,0.0000006405,0.01000,1.542
199
+ 28,self_attn.k_proj,0.0000006730,0.01000,1.546
200
+ 28,self_attn.q_proj,0.0000030264,0.01000,1.549
201
+ 28,self_attn.o_proj,0.0000012090,0.01000,0.572
202
+ 28,mlp.up_proj,0.0000021163,0.01000,1.138
203
+ 28,mlp.gate_proj,0.0000018347,0.01000,1.146
204
+ 28,mlp.down_proj,0.0000017199,0.01000,2.240
205
+ 29,self_attn.v_proj,0.0000015738,0.01000,1.545
206
+ 29,self_attn.q_proj,0.0000077582,0.01000,1.558
207
+ 29,self_attn.k_proj,0.0000012017,0.01000,1.566
208
+ 29,self_attn.o_proj,0.0000032131,0.01000,0.565
209
+ 29,mlp.up_proj,0.0000028664,0.01000,1.148
210
+ 29,mlp.gate_proj,0.0000025585,0.01000,1.151
211
+ 29,mlp.down_proj,0.0000256958,0.01000,2.225
212
+ 30,self_attn.k_proj,0.0000013016,0.01000,1.539
213
+ 30,self_attn.q_proj,0.0000079752,0.01000,1.542
214
+ 30,self_attn.v_proj,0.0000017943,0.01000,1.547
215
+ 30,self_attn.o_proj,0.0000069710,0.01000,0.563
216
+ 30,mlp.up_proj,0.0000044374,0.01000,1.152
217
+ 30,mlp.gate_proj,0.0000036016,0.01000,1.156
218
+ 30,mlp.down_proj,0.0000099136,0.01000,2.248
219
+ 31,self_attn.k_proj,0.0000022095,0.01000,1.536
220
+ 31,self_attn.q_proj,0.0000119859,0.01000,1.540
221
+ 31,self_attn.v_proj,0.0000024236,0.01000,1.543
222
+ 31,self_attn.o_proj,0.0000090073,0.01000,0.565
223
+ 31,mlp.gate_proj,0.0000042423,0.01000,1.140
224
+ 31,mlp.up_proj,0.0000057331,0.01000,1.150
225
+ 31,mlp.down_proj,0.0000113583,0.01000,2.248
226
+ 32,self_attn.k_proj,0.0000032344,0.01000,1.553
227
+ 32,self_attn.q_proj,0.0000177639,0.01000,1.556
228
+ 32,self_attn.v_proj,0.0000057728,0.01000,1.588
229
+ 32,self_attn.o_proj,0.0000294938,0.01000,0.575
230
+ 32,mlp.gate_proj,0.0000079738,0.01000,1.134
231
+ 32,mlp.up_proj,0.0000090901,0.01000,1.134
232
+ 32,mlp.down_proj,0.0001718242,0.01000,2.271
233
+ 33,self_attn.k_proj,0.0000067906,0.01000,1.549
234
+ 33,self_attn.q_proj,0.0000625890,0.01000,1.553
235
+ 33,self_attn.v_proj,0.0000118461,0.01000,1.557
236
+ 33,self_attn.o_proj,0.0000358326,0.01000,0.568
237
+ 33,mlp.up_proj,0.0000198184,0.01000,1.151
238
+ 33,mlp.gate_proj,0.0000165273,0.01000,1.159
239
+ 33,mlp.down_proj,0.0001491802,0.01000,2.239
240
+ 34,self_attn.q_proj,0.0000543061,0.01000,1.567
241
+ 34,self_attn.v_proj,0.0000131741,0.01000,1.573
242
+ 34,self_attn.k_proj,0.0000087816,0.01000,1.579
243
+ 34,self_attn.o_proj,0.0000818334,0.01000,0.569
244
+ 34,mlp.gate_proj,0.0000169936,0.01000,1.145
245
+ 34,mlp.up_proj,0.0000183243,0.01000,1.151
246
+ 34,mlp.down_proj,0.0000622494,0.01000,2.241
247
+ 35,self_attn.q_proj,0.0000360077,0.01000,1.567
248
+ 35,self_attn.k_proj,0.0000084222,0.01000,1.570
249
+ 35,self_attn.v_proj,0.0000127596,0.01000,1.587
250
+ 35,self_attn.o_proj,0.0000860495,0.01000,0.571
251
+ 35,mlp.gate_proj,0.0000566747,0.01000,1.142
252
+ 35,mlp.up_proj,0.0000673418,0.01000,1.145
253
+ 35,mlp.down_proj,0.0008014260,0.01000,2.267
quantize_config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bits": 4,
3
+ "group_size": 128,
4
+ "desc_act": false,
5
+ "lm_head": false,
6
+ "quant_method": "gptq",
7
+ "checkpoint_format": "gptq",
8
+ "pack_dtype": "int32",
9
+ "meta": {
10
+ "quantizer": [
11
+ "gptqmodel:5.7.1"
12
+ ],
13
+ "uri": "https://github.com/modelcloud/gptqmodel",
14
+ "damp_percent": 0.01,
15
+ "damp_auto_increment": 0.01,
16
+ "static_groups": false,
17
+ "true_sequential": true,
18
+ "mse": 0.0,
19
+ "gptaq": null,
20
+ "act_group_aware": true,
21
+ "failsafe": {
22
+ "strategy": "rtn",
23
+ "threshold": "0.5%",
24
+ "smooth": {
25
+ "type": "mad",
26
+ "group_size_threshold": 128,
27
+ "k": 2.75
28
+ }
29
+ },
30
+ "offload_to_disk": true,
31
+ "offload_to_disk_path": "./gptqmodel_offload/hqdpgrum-rkaakpxx/",
32
+ "pack_impl": "cpu",
33
+ "mock_quantization": false,
34
+ "gc_mode": "interval",
35
+ "wait_for_submodule_finalizers": false,
36
+ "auto_forward_data_parallel": true,
37
+ "hessian": {
38
+ "chunk_size": null,
39
+ "chunk_bytes": null,
40
+ "staging_dtype": "float32"
41
+ },
42
+ "vram_strategy": "exclusive"
43
+ },
44
+ "sym": true,
45
+ "format": "gptq"
46
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|audio_start|>",
12
+ "<|audio_end|>",
13
+ "<|audio_user_slot|>",
14
+ "<|image_pad|>",
15
+ "<|audio_assistant_gen_slot|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb3c8fa82993d515469c2800cc455bff4aaa3c4fed9da1f2b0c0668c304f335a
3
+ size 11422691
tokenizer_config.json ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|audio_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|audio_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|audio_user_slot|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|audio_assistant_gen_slot|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|audio_assistant_delay_slot|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ },
181
+ "151665": {
182
+ "content": "<tool_response>",
183
+ "lstrip": false,
184
+ "normalized": false,
185
+ "rstrip": false,
186
+ "single_word": false,
187
+ "special": false
188
+ },
189
+ "151666": {
190
+ "content": "</tool_response>",
191
+ "lstrip": false,
192
+ "normalized": false,
193
+ "rstrip": false,
194
+ "single_word": false,
195
+ "special": false
196
+ },
197
+ "151667": {
198
+ "content": "<think>",
199
+ "lstrip": false,
200
+ "normalized": false,
201
+ "rstrip": false,
202
+ "single_word": false,
203
+ "special": false
204
+ },
205
+ "151668": {
206
+ "content": "</think>",
207
+ "lstrip": false,
208
+ "normalized": false,
209
+ "rstrip": false,
210
+ "single_word": false,
211
+ "special": false
212
+ }
213
+ },
214
+ "additional_special_tokens": [
215
+ "<|im_start|>",
216
+ "<|im_end|>",
217
+ "<|object_ref_start|>",
218
+ "<|object_ref_end|>",
219
+ "<|box_start|>",
220
+ "<|box_end|>",
221
+ "<|quad_start|>",
222
+ "<|quad_end|>",
223
+ "<|audio_start|>",
224
+ "<|audio_end|>",
225
+ "<|audio_user_slot|>",
226
+ "<|image_pad|>",
227
+ "<|audio_assistant_gen_slot|>"
228
+ ],
229
+ "bos_token": null,
230
+ "clean_up_tokenization_spaces": false,
231
+ "eos_token": "<|im_end|>",
232
+ "errors": "replace",
233
+ "extra_special_tokens": {},
234
+ "model_max_length": 131072,
235
+ "pad_token": "<|endoftext|>",
236
+ "processor_class": "AsteroidProcessor",
237
+ "split_special_tokens": false,
238
+ "tokenizer_class": "Qwen2Tokenizer",
239
+ "unk_token": null
240
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
Free AI Image Generator No sign-up. Instant results. Open Now