Add checkpoint files via LFS
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +13 -0
- checkpoint/campplus/.msc +0 -0
- checkpoint/campplus/.mv +1 -0
- checkpoint/campplus/README.md +25 -0
- checkpoint/campplus/campplus_cn_common.pt +3 -0
- checkpoint/campplus/config.yaml +23 -0
- checkpoint/campplus/configuration.json +23 -0
- checkpoint/mimi/.msc +0 -0
- checkpoint/mimi/.mv +1 -0
- checkpoint/mimi/README.md +23 -0
- checkpoint/mimi/config.json +49 -0
- checkpoint/mimi/configuration.json +1 -0
- checkpoint/mimi/model.safetensors +3 -0
- checkpoint/mimi/preprocessor_config.json +10 -0
- checkpoint/omni-o/.msc +0 -0
- checkpoint/omni-o/.mv +1 -0
- checkpoint/omni-o/omni-o-hf/chat_template.jinja +85 -0
- checkpoint/omni-o/omni-o-hf/config.json +60 -0
- checkpoint/omni-o/omni-o-hf/config.py +24 -0
- checkpoint/omni-o/omni-o-hf/generation_config.json +8 -0
- checkpoint/omni-o/omni-o-hf/model.py +415 -0
- checkpoint/omni-o/omni-o-hf/model.safetensors +3 -0
- checkpoint/omni-o/omni-o-hf/modeling_omni_o.py +3 -0
- checkpoint/omni-o/omni-o-hf/tokenizer.json +0 -0
- checkpoint/omni-o/omni-o-hf/tokenizer_config.json +33 -0
- checkpoint/omni-o/omni-o-moe-hf/chat_template.jinja +85 -0
- checkpoint/omni-o/omni-o-moe-hf/config.json +60 -0
- checkpoint/omni-o/omni-o-moe-hf/config.py +24 -0
- checkpoint/omni-o/omni-o-moe-hf/generation_config.json +8 -0
- checkpoint/omni-o/omni-o-moe-hf/model.py +415 -0
- checkpoint/omni-o/omni-o-moe-hf/model.safetensors +3 -0
- checkpoint/omni-o/omni-o-moe-hf/modeling_omni_o.py +3 -0
- checkpoint/omni-o/omni-o-moe-hf/tokenizer.json +0 -0
- checkpoint/omni-o/omni-o-moe-hf/tokenizer_config.json +33 -0
- checkpoint/omni-o/omni-o.pth +3 -0
- checkpoint/omni-o/omni-o_moe.pth +3 -0
- checkpoint/omni/native_hf/chat_template.jinja +85 -0
- checkpoint/omni/native_hf/config.json +33 -0
- checkpoint/omni/native_hf/generation_config.json +8 -0
- checkpoint/omni/native_hf/model.safetensors +3 -0
- checkpoint/omni/native_hf/tokenizer.json +0 -0
- checkpoint/omni/native_hf/tokenizer_config.json +33 -0
- checkpoint/omni/omni.pth +3 -0
- checkpoint/sensevoice/.msc +0 -0
- checkpoint/sensevoice/.mv +1 -0
- checkpoint/sensevoice/README.md +27 -0
- checkpoint/sensevoice/am.mvn +8 -0
- checkpoint/sensevoice/chn_jpn_yue_eng_ko_spectok.bpe.model +3 -0
- checkpoint/sensevoice/config.yaml +97 -0
- checkpoint/sensevoice/configuration.json +14 -0
.gitattributes
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
checkpoint/vad/silero_vad.onnx filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
checkpoint/vad/silero_vad_v4.onnx filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
checkpoint/omni-o/omni-o-hf/model.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
checkpoint/omni-o/omni-o-moe-hf/model.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
checkpoint/omni-o/omni-o.pth filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
checkpoint/omni-o/omni-o_moe.pth filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
checkpoint/siglip/model.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
checkpoint/sensevoice/chn_jpn_yue_eng_ko_spectok.bpe.model filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
checkpoint/sensevoice/model.pt filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
checkpoint/mimi/model.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
checkpoint/campplus/campplus_cn_common.pt filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
checkpoint/omni/native_hf/model.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
checkpoint/omni/omni.pth filter=lfs diff=lfs merge=lfs -text
|
checkpoint/campplus/.msc
ADDED
|
Binary file (305 Bytes). View file
|
|
|
checkpoint/campplus/.mv
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Revision:master,CreatedAt:1777630305
|
checkpoint/campplus/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- zh
|
| 5 |
+
tags:
|
| 6 |
+
- speaker-verification
|
| 7 |
+
- speaker-recognition
|
| 8 |
+
- speaker-embedding
|
| 9 |
+
- speech
|
| 10 |
+
- audio
|
| 11 |
+
- campplus
|
| 12 |
+
pipeline_tag: audio-classification
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# CAMPPlus Speaker Encoder
|
| 16 |
+
|
| 17 |
+
This directory contains a local copy of the CAMPPlus speaker verification model, originally released through ModelScope / 3D-Speaker. The model is used to extract speaker embeddings from speech, while the original model architecture, weights, authorship, and license remain attributed to the original authors.
|
| 18 |
+
|
| 19 |
+
The upstream 3D-Speaker project is released under the `Apache-2.0` license. When using, redistributing, or citing these files, please keep the original author information, model link, and license notice.
|
| 20 |
+
|
| 21 |
+
Original links:
|
| 22 |
+
|
| 23 |
+
- ModelScope: https://www.modelscope.cn/models/iic/speech_campplus_sv_zh-cn_16k-common
|
| 24 |
+
- 3D-Speaker: https://github.com/modelscope/3D-Speaker
|
| 25 |
+
- License: https://www.apache.org/licenses/LICENSE-2.0
|
checkpoint/campplus/campplus_cn_common.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:55ffb1a55d04bac4a9b7ed80497cb731909985c9b55d120fce04b851a697886c
|
| 3 |
+
size 14173135
|
checkpoint/campplus/config.yaml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This is an example that demonstrates how to configure a model file.
|
| 2 |
+
# You can modify the configuration according to your own requirements.
|
| 3 |
+
|
| 4 |
+
# to print the register_table:
|
| 5 |
+
# from funasr.register import tables
|
| 6 |
+
# tables.print()
|
| 7 |
+
|
| 8 |
+
# network architecture
|
| 9 |
+
model: CAMPPlus
|
| 10 |
+
model_conf:
|
| 11 |
+
feat_dim: 80
|
| 12 |
+
embedding_size: 192
|
| 13 |
+
growth_rate: 32
|
| 14 |
+
bn_size: 4
|
| 15 |
+
init_channels: 128
|
| 16 |
+
config_str: 'batchnorm-relu'
|
| 17 |
+
memory_efficient: True
|
| 18 |
+
output_level: 'segment'
|
| 19 |
+
|
| 20 |
+
# frontend related
|
| 21 |
+
frontend: WavFrontend
|
| 22 |
+
frontend_conf:
|
| 23 |
+
fs: 16000
|
checkpoint/campplus/configuration.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"framework": "pytorch",
|
| 3 |
+
"task": "speaker-verification",
|
| 4 |
+
"model_config": "config.yaml",
|
| 5 |
+
"model_file": "campplus_cn_common.bin",
|
| 6 |
+
"model": {
|
| 7 |
+
"type": "cam++-sv",
|
| 8 |
+
"model_config": {
|
| 9 |
+
"sample_rate": 16000,
|
| 10 |
+
"fbank_dim": 80,
|
| 11 |
+
"emb_size": 192
|
| 12 |
+
},
|
| 13 |
+
"pretrained_model": "campplus_cn_common.bin",
|
| 14 |
+
"yesOrno_thr": 0.31
|
| 15 |
+
},
|
| 16 |
+
"pipeline": {
|
| 17 |
+
"type": "speaker-verification"
|
| 18 |
+
},
|
| 19 |
+
"file_path_metas": {
|
| 20 |
+
"init_param":"campplus_cn_common.bin",
|
| 21 |
+
"config":"config.yaml"
|
| 22 |
+
}
|
| 23 |
+
}
|
checkpoint/mimi/.msc
ADDED
|
Binary file (379 Bytes). View file
|
|
|
checkpoint/mimi/.mv
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Revision:master,CreatedAt:1777630495
|
checkpoint/mimi/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
tags:
|
| 6 |
+
- audio
|
| 7 |
+
- codec
|
| 8 |
+
- feature-extraction
|
| 9 |
+
- mimi
|
| 10 |
+
- fp16
|
| 11 |
+
pipeline_tag: feature-extraction
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# Mimi FP16
|
| 15 |
+
|
| 16 |
+
This directory contains an FP16 converted version of [Kyutai Mimi](https://huggingface.co/kyutai/mimi), used as an audio codec for encoding and decoding. The original model was released by Kyutai, and the model architecture, weights, authorship, and license remain attributed to the original authors.
|
| 17 |
+
|
| 18 |
+
The original Mimi model is released under the `CC-BY-4.0` license. The files here are only converted to FP16 to reduce memory usage and make local usage more convenient. When using, redistributing, or citing these files, please keep the original Kyutai attribution, model link, and license notice.
|
| 19 |
+
|
| 20 |
+
Original links:
|
| 21 |
+
|
| 22 |
+
- Hugging Face: https://huggingface.co/kyutai/mimi
|
| 23 |
+
- License: https://creativecommons.org/licenses/by/4.0/
|
checkpoint/mimi/config.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"MimiModel"
|
| 4 |
+
],
|
| 5 |
+
"attention_dropout": 0.0,
|
| 6 |
+
"audio_channels": 1,
|
| 7 |
+
"codebook_dim": 256,
|
| 8 |
+
"codebook_size": 2048,
|
| 9 |
+
"compress": 2,
|
| 10 |
+
"dilation_growth_rate": 2,
|
| 11 |
+
"frame_rate": 12.5,
|
| 12 |
+
"head_dim": 64,
|
| 13 |
+
"hidden_act": "gelu",
|
| 14 |
+
"hidden_size": 512,
|
| 15 |
+
"initializer_range": 0.02,
|
| 16 |
+
"intermediate_size": 2048,
|
| 17 |
+
"kernel_size": 7,
|
| 18 |
+
"last_kernel_size": 3,
|
| 19 |
+
"layer_scale_initial_scale": 0.01,
|
| 20 |
+
"max_position_embeddings": 8000,
|
| 21 |
+
"model_type": "mimi",
|
| 22 |
+
"norm_eps": 1e-05,
|
| 23 |
+
"normalize": false,
|
| 24 |
+
"num_attention_heads": 8,
|
| 25 |
+
"num_filters": 64,
|
| 26 |
+
"num_hidden_layers": 8,
|
| 27 |
+
"num_key_value_heads": 8,
|
| 28 |
+
"num_residual_layers": 1,
|
| 29 |
+
"num_semantic_quantizers": 1,
|
| 30 |
+
"pad_mode": "constant",
|
| 31 |
+
"residual_kernel_size": 3,
|
| 32 |
+
"rope_theta": 10000.0,
|
| 33 |
+
"sampling_rate": 24000,
|
| 34 |
+
"sliding_window": 250,
|
| 35 |
+
"torch_dtype": "float16",
|
| 36 |
+
"transformers_version": "4.45.0.dev0",
|
| 37 |
+
"trim_right_ratio": 1.0,
|
| 38 |
+
"upsample_groups": 512,
|
| 39 |
+
"upsampling_ratios": [
|
| 40 |
+
8,
|
| 41 |
+
6,
|
| 42 |
+
5,
|
| 43 |
+
4
|
| 44 |
+
],
|
| 45 |
+
"use_cache": false,
|
| 46 |
+
"use_causal_conv": true,
|
| 47 |
+
"use_conv_shortcut": false,
|
| 48 |
+
"vector_quantization_hidden_dimension": 256
|
| 49 |
+
}
|
checkpoint/mimi/configuration.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"framework":"Pytorch","task":"text-to-speech"}
|
checkpoint/mimi/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7542ee039d3025d5089cf227d21df64b6b8eff08fcd376a11a1fbd178dd9d3f5
|
| 3 |
+
size 192346842
|
checkpoint/mimi/preprocessor_config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"chunk_length_s": null,
|
| 3 |
+
"feature_extractor_type": "EncodecFeatureExtractor",
|
| 4 |
+
"feature_size": 1,
|
| 5 |
+
"overlap": null,
|
| 6 |
+
"padding_side": "right",
|
| 7 |
+
"padding_value": 0.0,
|
| 8 |
+
"return_attention_mask": true,
|
| 9 |
+
"sampling_rate": 24000
|
| 10 |
+
}
|
checkpoint/omni-o/.msc
ADDED
|
Binary file (513 Bytes). View file
|
|
|
checkpoint/omni-o/.mv
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Revision:master,CreatedAt:1778047169
|
checkpoint/omni-o/omni-o-hf/chat_template.jinja
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if tools %}
|
| 2 |
+
{{- '<|im_start|>system\n' }}
|
| 3 |
+
{%- if messages[0].role == 'system' %}
|
| 4 |
+
{{- messages[0].content + '\n\n' }}
|
| 5 |
+
{%- endif %}
|
| 6 |
+
{{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
| 7 |
+
{%- for tool in tools %}
|
| 8 |
+
{{- "\n" }}
|
| 9 |
+
{{- tool | tojson }}
|
| 10 |
+
{%- endfor %}
|
| 11 |
+
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
|
| 12 |
+
{%- else %}
|
| 13 |
+
{%- if messages[0].role == 'system' %}
|
| 14 |
+
{{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
|
| 15 |
+
{%- endif %}
|
| 16 |
+
{%- endif %}
|
| 17 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 18 |
+
{%- for message in messages[::-1] %}
|
| 19 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 20 |
+
{%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
|
| 21 |
+
{%- set ns.multi_step_tool = false %}
|
| 22 |
+
{%- set ns.last_query_index = index %}
|
| 23 |
+
{%- endif %}
|
| 24 |
+
{%- endfor %}
|
| 25 |
+
{%- for message in messages %}
|
| 26 |
+
{%- if message.content is string %}
|
| 27 |
+
{%- set content = message.content %}
|
| 28 |
+
{%- else %}
|
| 29 |
+
{%- set content = '' %}
|
| 30 |
+
{%- endif %}
|
| 31 |
+
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 32 |
+
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
|
| 33 |
+
{%- elif message.role == "assistant" %}
|
| 34 |
+
{%- set reasoning_content = '' %}
|
| 35 |
+
{%- if message.reasoning_content is string %}
|
| 36 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 37 |
+
{%- else %}
|
| 38 |
+
{%- if '</think>' in content %}
|
| 39 |
+
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 40 |
+
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 41 |
+
{%- endif %}
|
| 42 |
+
{%- endif %}
|
| 43 |
+
{%- if true %}
|
| 44 |
+
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
|
| 45 |
+
{%- endif %}
|
| 46 |
+
{%- if message.tool_calls %}
|
| 47 |
+
{%- for tool_call in message.tool_calls %}
|
| 48 |
+
{%- if (loop.first and content) or (not loop.first) %}
|
| 49 |
+
{{- '\n' }}
|
| 50 |
+
{%- endif %}
|
| 51 |
+
{%- if tool_call.function %}
|
| 52 |
+
{%- set tool_call = tool_call.function %}
|
| 53 |
+
{%- endif %}
|
| 54 |
+
{{- '<tool_call>\n{"name": "' }}
|
| 55 |
+
{{- tool_call.name }}
|
| 56 |
+
{{- '", "arguments": ' }}
|
| 57 |
+
{%- if tool_call.arguments is string %}
|
| 58 |
+
{{- tool_call.arguments }}
|
| 59 |
+
{%- else %}
|
| 60 |
+
{{- tool_call.arguments | tojson }}
|
| 61 |
+
{%- endif %}
|
| 62 |
+
{{- '}\n</tool_call>' }}
|
| 63 |
+
{%- endfor %}
|
| 64 |
+
{%- endif %}
|
| 65 |
+
{{- '<|im_end|>\n' }}
|
| 66 |
+
{%- elif message.role == "tool" %}
|
| 67 |
+
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 68 |
+
{{- '<|im_start|>user' }}
|
| 69 |
+
{%- endif %}
|
| 70 |
+
{{- '\n<tool_response>\n' }}
|
| 71 |
+
{{- content }}
|
| 72 |
+
{{- '\n</tool_response>' }}
|
| 73 |
+
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 74 |
+
{{- '<|im_end|>\n' }}
|
| 75 |
+
{%- endif %}
|
| 76 |
+
{%- endif %}
|
| 77 |
+
{%- endfor %}
|
| 78 |
+
{%- if add_generation_prompt %}
|
| 79 |
+
{{- '<|im_start|>assistant\n' }}
|
| 80 |
+
{%- if open_thinking is defined and open_thinking is true %}
|
| 81 |
+
{{- '<think>\n' }}
|
| 82 |
+
{%- else %}
|
| 83 |
+
{{- '<think>\n\n</think>\n\n' }}
|
| 84 |
+
{%- endif %}
|
| 85 |
+
{%- endif %}
|
checkpoint/omni-o/omni-o-hf/config.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"VAM"
|
| 4 |
+
],
|
| 5 |
+
"audio_hidden_size": 512,
|
| 6 |
+
"audio_ids": [
|
| 7 |
+
16
|
| 8 |
+
],
|
| 9 |
+
"audio_pad_token": 2049,
|
| 10 |
+
"audio_special_token": "<|audio_pad|>",
|
| 11 |
+
"audio_spk_token": 2051,
|
| 12 |
+
"audio_stop_token": 2050,
|
| 13 |
+
"audio_vocab_size": 2112,
|
| 14 |
+
"auto_map": {
|
| 15 |
+
"AutoConfig": "modeling_omni_o.VAMConfig",
|
| 16 |
+
"AutoModelForCausalLM": "modeling_omni_o.VAM"
|
| 17 |
+
},
|
| 18 |
+
"bos_token_id": 1,
|
| 19 |
+
"bridge_layer": 3,
|
| 20 |
+
"dropout": 0.0,
|
| 21 |
+
"dtype": "float16",
|
| 22 |
+
"eos_token_id": 2,
|
| 23 |
+
"flash_attn": true,
|
| 24 |
+
"head_dim": 96,
|
| 25 |
+
"hidden_act": "silu",
|
| 26 |
+
"hidden_size": 768,
|
| 27 |
+
"image_hidden_size": 768,
|
| 28 |
+
"image_ids": [
|
| 29 |
+
12
|
| 30 |
+
],
|
| 31 |
+
"image_special_token": "<|image_pad|>",
|
| 32 |
+
"image_token_len": 64,
|
| 33 |
+
"inference_rope_scaling": false,
|
| 34 |
+
"intermediate_size": 2432,
|
| 35 |
+
"max_position_embeddings": 32768,
|
| 36 |
+
"model_type": "omni-o",
|
| 37 |
+
"moe_intermediate_size": 2432,
|
| 38 |
+
"norm_topk_prob": true,
|
| 39 |
+
"num_attention_heads": 8,
|
| 40 |
+
"num_experts": 4,
|
| 41 |
+
"num_experts_per_tok": 1,
|
| 42 |
+
"num_hidden_layers": 8,
|
| 43 |
+
"num_key_value_heads": 4,
|
| 44 |
+
"num_talker_hidden_layers": 4,
|
| 45 |
+
"rms_norm_eps": 1e-06,
|
| 46 |
+
"rope_parameters": null,
|
| 47 |
+
"rope_theta": 1000000.0,
|
| 48 |
+
"router_aux_loss_coef": 0.0005,
|
| 49 |
+
"spk_emb_size": 192,
|
| 50 |
+
"talker_hidden_size": 768,
|
| 51 |
+
"think_end_ids": [
|
| 52 |
+
26,
|
| 53 |
+
234,
|
| 54 |
+
234
|
| 55 |
+
],
|
| 56 |
+
"tie_word_embeddings": true,
|
| 57 |
+
"transformers_version": "5.14.1",
|
| 58 |
+
"use_moe": false,
|
| 59 |
+
"vocab_size": 6400
|
| 60 |
+
}
|
checkpoint/omni-o/omni-o-hf/config.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from models.lm.config import LMConfig
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class VAMConfig(LMConfig):
|
| 5 |
+
model_type = "omni-o"
|
| 6 |
+
|
| 7 |
+
def __init__(self, **kwargs):
|
| 8 |
+
super().__init__(**kwargs)
|
| 9 |
+
self.num_talker_hidden_layers = kwargs.get("num_talker_hidden_layers", 4)
|
| 10 |
+
self.talker_hidden_size = kwargs.get("talker_hidden_size", 768)
|
| 11 |
+
self.audio_ids = kwargs.get("audio_ids", [16])
|
| 12 |
+
self.audio_special_token = kwargs.get("audio_special_token", "<|audio_pad|>")
|
| 13 |
+
self.audio_hidden_size = kwargs.get("audio_hidden_size", 512)
|
| 14 |
+
self.audio_vocab_size = kwargs.get("audio_vocab_size", 2112)
|
| 15 |
+
self.audio_pad_token = kwargs.get("audio_pad_token", 2049)
|
| 16 |
+
self.audio_stop_token = kwargs.get("audio_stop_token", 2050)
|
| 17 |
+
self.audio_spk_token = kwargs.get("audio_spk_token", 2051)
|
| 18 |
+
self.spk_emb_size = kwargs.get("spk_emb_size", 192)
|
| 19 |
+
self.think_end_ids = kwargs.get("think_end_ids", [26, 234, 234])
|
| 20 |
+
self.image_ids = kwargs.get("image_ids", [12])
|
| 21 |
+
self.image_special_token = kwargs.get("image_special_token", "<|image_pad|>")
|
| 22 |
+
self.image_hidden_size = kwargs.get("image_hidden_size", 768)
|
| 23 |
+
self.image_token_len = kwargs.get("image_token_len", 64)
|
| 24 |
+
self.bridge_layer = kwargs.get("bridge_layer", self.num_hidden_layers // 2 - 1)
|
checkpoint/omni-o/omni-o-hf/generation_config.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"eos_token_id": 2,
|
| 5 |
+
"output_attentions": false,
|
| 6 |
+
"output_hidden_states": false,
|
| 7 |
+
"transformers_version": "5.14.1"
|
| 8 |
+
}
|
checkpoint/omni-o/omni-o-hf/model.py
ADDED
|
@@ -0,0 +1,415 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import math
|
| 3 |
+
import torch
|
| 4 |
+
import warnings
|
| 5 |
+
import logging
|
| 6 |
+
import contextlib
|
| 7 |
+
import io
|
| 8 |
+
from torch import nn
|
| 9 |
+
from torch.nn import functional as F
|
| 10 |
+
from transformers.modeling_outputs import MoeCausalLMOutputWithPast
|
| 11 |
+
from transformers import SiglipVisionModel, SiglipImageProcessor, logging as hf_logging
|
| 12 |
+
|
| 13 |
+
from core import RMSNorm, precompute_freqs_cis, Block, MOEFeedForward
|
| 14 |
+
from models.lm.config import LMConfig
|
| 15 |
+
from models.lm.model import LMForCausalLM
|
| 16 |
+
from models.vam.config import VAMConfig
|
| 17 |
+
from encoders.audio import SenseVoiceAudioEncoder, SenseVoiceAudioProcessor
|
| 18 |
+
from encoders.vision import SiglipVisionEncoder
|
| 19 |
+
from projectors import MMVisionProjector, MMAudioProjector
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class TalkerHead(nn.Module):
|
| 23 |
+
def __init__(self, in_features, out_features, num_layers=8, rank=256):
|
| 24 |
+
super().__init__()
|
| 25 |
+
self.num_layers = num_layers
|
| 26 |
+
self.base = nn.Linear(in_features, out_features, bias=False)
|
| 27 |
+
self.adapters = nn.ModuleList([
|
| 28 |
+
nn.Sequential(nn.Linear(in_features, rank, bias=False), nn.GELU(), nn.Linear(rank, out_features, bias=False))
|
| 29 |
+
for _ in range(num_layers)
|
| 30 |
+
])
|
| 31 |
+
|
| 32 |
+
def forward(self, x):
|
| 33 |
+
base_out = self.base(x)
|
| 34 |
+
return [base_out + adapter(x) for adapter in self.adapters]
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class TalkerEmbedding(nn.Module):
|
| 38 |
+
def __init__(self, num_embeddings, embedding_dim, num_layers=8, rank=256):
|
| 39 |
+
super().__init__()
|
| 40 |
+
self.num_layers = num_layers
|
| 41 |
+
self.base = nn.Embedding(num_embeddings, embedding_dim)
|
| 42 |
+
self.adapters = nn.ModuleList([
|
| 43 |
+
nn.Sequential(nn.Embedding(num_embeddings, rank), nn.GELU(), nn.Linear(rank, embedding_dim, bias=False))
|
| 44 |
+
for _ in range(num_layers)
|
| 45 |
+
])
|
| 46 |
+
|
| 47 |
+
def forward(self, x):
|
| 48 |
+
base_out = self.base(x)
|
| 49 |
+
return sum(base_out[:, i, :] + self.adapters[i](x[:, i, :]) for i in range(len(self.adapters))) / self.num_layers
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class TalkerModule(nn.Module):
|
| 53 |
+
def __init__(self, config: VAMConfig):
|
| 54 |
+
super().__init__()
|
| 55 |
+
self.talker_config = LMConfig(hidden_size=config.talker_hidden_size, use_moe=config.use_moe)
|
| 56 |
+
self.layers = nn.ModuleList([Block(l, self.talker_config) for l in range(config.num_talker_hidden_layers)])
|
| 57 |
+
self.norm = RMSNorm(config.talker_hidden_size, eps=config.rms_norm_eps)
|
| 58 |
+
self.lm_head = TalkerHead(config.talker_hidden_size, config.audio_vocab_size)
|
| 59 |
+
self.embed_tokens = TalkerEmbedding(config.audio_vocab_size, config.talker_hidden_size)
|
| 60 |
+
self.codec_proj = nn.Sequential(
|
| 61 |
+
nn.Linear(config.talker_hidden_size, config.talker_hidden_size),
|
| 62 |
+
nn.GELU(),
|
| 63 |
+
nn.Linear(config.talker_hidden_size, config.talker_hidden_size),
|
| 64 |
+
RMSNorm(config.talker_hidden_size, eps=config.rms_norm_eps),
|
| 65 |
+
)
|
| 66 |
+
self.embed_proj = nn.Sequential(
|
| 67 |
+
nn.Linear(config.hidden_size, config.hidden_size),
|
| 68 |
+
nn.GELU(),
|
| 69 |
+
nn.Linear(config.hidden_size, config.talker_hidden_size),
|
| 70 |
+
RMSNorm(config.talker_hidden_size, eps=config.rms_norm_eps),
|
| 71 |
+
)
|
| 72 |
+
self.text_scale, self.audio_scale = nn.Parameter(torch.tensor(3.0)), nn.Parameter(torch.tensor(1.0))
|
| 73 |
+
self.spk_proj = nn.Linear(config.spk_emb_size, config.talker_hidden_size, bias=False)
|
| 74 |
+
freqs_cos, freqs_sin = precompute_freqs_cis(
|
| 75 |
+
dim=self.talker_config.head_dim, end=config.max_position_embeddings,
|
| 76 |
+
rope_base=config.rope_theta, rope_scaling=config.rope_scaling
|
| 77 |
+
)
|
| 78 |
+
self.register_buffer("freqs_cos", freqs_cos, persistent=False)
|
| 79 |
+
self.register_buffer("freqs_sin", freqs_sin, persistent=False)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class VAM(LMForCausalLM):
|
| 83 |
+
config_class = VAMConfig
|
| 84 |
+
|
| 85 |
+
def __init__(self, config: VAMConfig = None, audio_encoder_path: str = None, vision_model_path: str = None):
|
| 86 |
+
config = config or VAMConfig()
|
| 87 |
+
super().__init__(config)
|
| 88 |
+
object.__setattr__(self, 'thinker', self.model)
|
| 89 |
+
object.__setattr__(self.model, 'lm_head', self.lm_head)
|
| 90 |
+
self.talker = TalkerModule(config)
|
| 91 |
+
self.audio_proj = MMAudioProjector(config.audio_hidden_size, config.hidden_size)
|
| 92 |
+
self.vision_proj = MMVisionProjector(config.image_hidden_size, config.hidden_size, target_tokens=config.image_token_len)
|
| 93 |
+
self.audio_pad_token, self.audio_stop_token, self.audio_spk_token = config.audio_pad_token, config.audio_stop_token, config.audio_spk_token
|
| 94 |
+
meta_init = any(p.device.type == 'meta' for p in self.parameters())
|
| 95 |
+
if meta_init:
|
| 96 |
+
object.__setattr__(self, 'audio_encoder', None)
|
| 97 |
+
object.__setattr__(self, 'audio_processor', None)
|
| 98 |
+
object.__setattr__(self, 'vision_encoder', None)
|
| 99 |
+
object.__setattr__(self, 'vision_processor', None)
|
| 100 |
+
else:
|
| 101 |
+
audio_enc = SenseVoiceAudioEncoder(audio_encoder_path) if audio_encoder_path else SenseVoiceAudioEncoder()
|
| 102 |
+
object.__setattr__(self, 'audio_encoder', audio_enc)
|
| 103 |
+
object.__setattr__(self, 'audio_processor', audio_enc.processor)
|
| 104 |
+
vision_enc = SiglipVisionEncoder(vision_model_path) if vision_model_path else SiglipVisionEncoder()
|
| 105 |
+
object.__setattr__(self, 'vision_encoder', vision_enc)
|
| 106 |
+
object.__setattr__(self, 'vision_processor', vision_enc.processor)
|
| 107 |
+
|
| 108 |
+
@classmethod
|
| 109 |
+
def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
|
| 110 |
+
audio_encoder_path = kwargs.pop('audio_encoder_path', None)
|
| 111 |
+
vision_model_path = kwargs.pop('vision_model_path', None)
|
| 112 |
+
model = super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)
|
| 113 |
+
if audio_encoder_path and model.audio_encoder is None:
|
| 114 |
+
enc, proc = cls.load_sensevoice(audio_encoder_path)
|
| 115 |
+
object.__setattr__(model, 'audio_encoder', enc)
|
| 116 |
+
object.__setattr__(model, 'audio_processor', proc)
|
| 117 |
+
if vision_model_path and model.vision_encoder is None:
|
| 118 |
+
enc, proc = cls.load_vision(vision_model_path)
|
| 119 |
+
object.__setattr__(model, 'vision_encoder', enc)
|
| 120 |
+
object.__setattr__(model, 'vision_processor', proc)
|
| 121 |
+
return model
|
| 122 |
+
|
| 123 |
+
@staticmethod
|
| 124 |
+
def load_sensevoice(path):
|
| 125 |
+
if not os.path.exists(path):
|
| 126 |
+
warnings.warn(f"[VAM] SenseVoice path not found: {path}")
|
| 127 |
+
return None, None
|
| 128 |
+
logging.getLogger().setLevel(logging.ERROR)
|
| 129 |
+
hf_logging.set_verbosity_error()
|
| 130 |
+
with contextlib.redirect_stdout(io.StringIO()):
|
| 131 |
+
from funasr import AutoModel
|
| 132 |
+
m = AutoModel(model=path, trust_remote_code=True, disable_update=True, device="cpu")
|
| 133 |
+
encoder, frontend = m.model.encoder, m.kwargs["frontend"]
|
| 134 |
+
for p in encoder.parameters():
|
| 135 |
+
p.requires_grad = False
|
| 136 |
+
return encoder.eval().float(), SenseVoiceAudioProcessor(frontend.eval())
|
| 137 |
+
|
| 138 |
+
@staticmethod
|
| 139 |
+
def load_vision(path):
|
| 140 |
+
if path is None or not os.path.exists(path):
|
| 141 |
+
warnings.warn(f"[VAM] Vision model path not found: {path}. vision_encoder will be None!")
|
| 142 |
+
return None, None
|
| 143 |
+
hf_logging.set_verbosity_error()
|
| 144 |
+
try:
|
| 145 |
+
model = SiglipVisionModel.from_pretrained(path)
|
| 146 |
+
except (RuntimeError, ValueError):
|
| 147 |
+
return None, None
|
| 148 |
+
processor = SiglipImageProcessor.from_pretrained(path)
|
| 149 |
+
for p in model.parameters():
|
| 150 |
+
p.requires_grad = False
|
| 151 |
+
return model.eval(), processor
|
| 152 |
+
|
| 153 |
+
@torch.compiler.disable
|
| 154 |
+
def encode_audio_inputs(self, audio_inputs, audio_lens=None):
|
| 155 |
+
if (audio_inputs is None) or (self.audio_encoder is None) or (not audio_inputs.any()):
|
| 156 |
+
return None
|
| 157 |
+
batch_mask = audio_inputs.flatten(1).any(1)
|
| 158 |
+
enc_dtype = next(self.audio_encoder.parameters()).dtype
|
| 159 |
+
valid_fbank = audio_inputs[batch_mask].to(dtype=enc_dtype)
|
| 160 |
+
if audio_lens is not None:
|
| 161 |
+
valid_lens = audio_lens[batch_mask].to(valid_fbank.device)
|
| 162 |
+
else:
|
| 163 |
+
valid_lens = torch.tensor([valid_fbank.size(1)] * valid_fbank.size(0), device=valid_fbank.device)
|
| 164 |
+
with torch.no_grad():
|
| 165 |
+
emb, _ = self.audio_encoder.model(valid_fbank, valid_lens)
|
| 166 |
+
proj_dtype = next(self.audio_proj.parameters()).dtype
|
| 167 |
+
emb_list = [self.audio_proj(emb[i, :max(1, min(valid_lens[i].item(), emb.size(1)))].unsqueeze(0).to(proj_dtype)).squeeze(0) for i in range(emb.size(0))]
|
| 168 |
+
if batch_mask.all():
|
| 169 |
+
return emb_list
|
| 170 |
+
out = [None] * audio_inputs.size(0)
|
| 171 |
+
j = 0
|
| 172 |
+
for i in range(audio_inputs.size(0)):
|
| 173 |
+
if batch_mask[i]:
|
| 174 |
+
out[i] = emb_list[j]
|
| 175 |
+
j += 1
|
| 176 |
+
return out
|
| 177 |
+
|
| 178 |
+
@torch.compiler.disable
|
| 179 |
+
def inject_audio_features(self, tokens, h, audio_feats, seqlen):
|
| 180 |
+
if audio_feats is None or not self.config.audio_ids:
|
| 181 |
+
return h
|
| 182 |
+
marker = self.config.audio_ids[0]
|
| 183 |
+
out = []
|
| 184 |
+
for b in range(h.size(0)):
|
| 185 |
+
hb, seq, i = h[b], tokens[b].tolist(), 0
|
| 186 |
+
af = audio_feats[b] if audio_feats[b] is not None else None
|
| 187 |
+
while i < len(seq):
|
| 188 |
+
if seq[i] == marker:
|
| 189 |
+
start = i
|
| 190 |
+
while i < len(seq) and seq[i] == marker:
|
| 191 |
+
i += 1
|
| 192 |
+
if af is not None:
|
| 193 |
+
inject_len = min(af.size(0), i - start)
|
| 194 |
+
hb = torch.cat((hb[:start], af[:inject_len], hb[start + inject_len:]), dim=0)
|
| 195 |
+
af = None
|
| 196 |
+
else:
|
| 197 |
+
i += 1
|
| 198 |
+
out.append(hb)
|
| 199 |
+
return torch.stack(out)
|
| 200 |
+
|
| 201 |
+
@torch.compiler.disable
|
| 202 |
+
def get_image_embeddings(self, image_inputs):
|
| 203 |
+
if hasattr(image_inputs, 'keys'):
|
| 204 |
+
image_inputs = {k: (v.squeeze(1) if v.ndim > 2 and v.shape[1] == 1 else v) for k, v in image_inputs.items()}
|
| 205 |
+
pixel_attention_mask = image_inputs.get('pixel_attention_mask')
|
| 206 |
+
if pixel_attention_mask is not None and not pixel_attention_mask.any():
|
| 207 |
+
pv = image_inputs['pixel_values']
|
| 208 |
+
return pv.new_zeros(pv.size(0), pv.size(1), self.config.image_hidden_size)
|
| 209 |
+
with torch.no_grad():
|
| 210 |
+
outputs = self.vision_encoder.model(**image_inputs)
|
| 211 |
+
return outputs.last_hidden_state
|
| 212 |
+
|
| 213 |
+
@torch.compiler.disable
|
| 214 |
+
def encode_image_inputs(self, pixel_values):
|
| 215 |
+
if pixel_values is None or self.vision_encoder is None:
|
| 216 |
+
return None
|
| 217 |
+
mask = pixel_values.flatten(1).any(1)
|
| 218 |
+
if not mask.any():
|
| 219 |
+
return pixel_values.new_zeros(pixel_values.size(0), self.config.image_token_len, self.config.hidden_size)
|
| 220 |
+
with torch.no_grad():
|
| 221 |
+
emb = self.vision_encoder.model(pixel_values=pixel_values[mask]).last_hidden_state
|
| 222 |
+
if emb.dim() == 2:
|
| 223 |
+
emb = emb.unsqueeze(0)
|
| 224 |
+
emb = self.vision_proj(emb)
|
| 225 |
+
if mask.all():
|
| 226 |
+
return emb
|
| 227 |
+
idx = mask.nonzero().view(-1, 1, 1).expand_as(emb)
|
| 228 |
+
return emb.new_zeros(pixel_values.size(0), *emb.shape[1:]).scatter(0, idx, emb)
|
| 229 |
+
|
| 230 |
+
@torch.compiler.disable
|
| 231 |
+
def count_vision_proj(self, tokens, h, vision_tensors=None, seqlen=512):
|
| 232 |
+
if vision_tensors is None or not self.config.image_ids:
|
| 233 |
+
return h
|
| 234 |
+
marker, vf = self.config.image_ids[0], vision_tensors
|
| 235 |
+
if vf.dim() == 3:
|
| 236 |
+
vf = vf.unsqueeze(1)
|
| 237 |
+
out = []
|
| 238 |
+
for b in range(h.size(0)):
|
| 239 |
+
hb, seq, k, i = h[b], tokens[b].tolist(), 0, 0
|
| 240 |
+
while i < len(seq):
|
| 241 |
+
if seq[i] == marker:
|
| 242 |
+
start = i
|
| 243 |
+
while i < len(seq) and seq[i] == marker:
|
| 244 |
+
i += 1
|
| 245 |
+
if k < vf.size(1):
|
| 246 |
+
hb = torch.cat((hb[:start], vf[b][k][:i - start], hb[i:]), dim=0)[:seqlen]
|
| 247 |
+
k += 1
|
| 248 |
+
else:
|
| 249 |
+
i += 1
|
| 250 |
+
out.append(hb)
|
| 251 |
+
return torch.stack(out)
|
| 252 |
+
|
| 253 |
+
def forward(self, input_ids, attention_mask=None, past_key_values=None, use_cache=False, logits_to_keep=0,
|
| 254 |
+
audio_inputs=None, audio_lens=None, pixel_values=None, **args):
|
| 255 |
+
if len(input_ids.shape) == 2:
|
| 256 |
+
batch_size, seq_length = input_ids.shape
|
| 257 |
+
text_ids = input_ids
|
| 258 |
+
audio_ids = torch.full((batch_size, 8, seq_length), self.audio_pad_token, dtype=torch.long, device=input_ids.device)
|
| 259 |
+
else:
|
| 260 |
+
batch_size, _, seq_length = input_ids.shape
|
| 261 |
+
text_ids, audio_ids = input_ids[:, 8, :], input_ids[:, :8, :]
|
| 262 |
+
if hasattr(past_key_values, 'layers'):
|
| 263 |
+
past_key_values = None
|
| 264 |
+
n_thinker, n_talker = len(self.thinker.layers), len(self.talker.layers)
|
| 265 |
+
past_key_values = past_key_values or ([None] * (n_thinker + n_talker))
|
| 266 |
+
start_pos = past_key_values[0][0].shape[1] if past_key_values[0] is not None else 0
|
| 267 |
+
if self.thinker.freqs_cos[0, 0] == 0:
|
| 268 |
+
freqs_cos, freqs_sin = precompute_freqs_cis(dim=self.config.head_dim, end=self.config.max_position_embeddings, rope_base=self.config.rope_theta, rope_scaling=self.config.rope_scaling)
|
| 269 |
+
self.thinker.freqs_cos, self.thinker.freqs_sin = freqs_cos.to(input_ids.device), freqs_sin.to(input_ids.device)
|
| 270 |
+
if self.talker.freqs_cos[0, 0] == 0:
|
| 271 |
+
freqs_cos, freqs_sin = precompute_freqs_cis(dim=self.talker.talker_config.head_dim, end=self.config.max_position_embeddings, rope_base=self.config.rope_theta, rope_scaling=self.config.rope_scaling)
|
| 272 |
+
self.talker.freqs_cos, self.talker.freqs_sin = freqs_cos.to(input_ids.device), freqs_sin.to(input_ids.device)
|
| 273 |
+
presents = []
|
| 274 |
+
|
| 275 |
+
hidden_states = self.thinker.dropout(self.thinker.embed_tokens(text_ids))
|
| 276 |
+
position_embeddings = (self.thinker.freqs_cos[start_pos:start_pos + seq_length], self.thinker.freqs_sin[start_pos:start_pos + seq_length])
|
| 277 |
+
if audio_inputs is not None and start_pos == 0:
|
| 278 |
+
audio_features = self.encode_audio_inputs(audio_inputs, audio_lens)
|
| 279 |
+
hidden_states = self.inject_audio_features(text_ids, hidden_states, audio_features, seq_length)
|
| 280 |
+
if pixel_values is not None and start_pos == 0:
|
| 281 |
+
if hasattr(pixel_values, 'keys'):
|
| 282 |
+
img_emb = self.get_image_embeddings(pixel_values).to(hidden_states.dtype)
|
| 283 |
+
vision_tensors = self.vision_proj(img_emb)
|
| 284 |
+
else:
|
| 285 |
+
if len(pixel_values.shape) == 6:
|
| 286 |
+
pixel_values = pixel_values.squeeze(2)
|
| 287 |
+
if len(pixel_values.shape) == 4:
|
| 288 |
+
pixel_values = pixel_values.unsqueeze(1)
|
| 289 |
+
bs, num, c, im_h, im_w = pixel_values.shape
|
| 290 |
+
stack_dim = 1 if bs > 1 else 0
|
| 291 |
+
vision_tensors = torch.stack([self.encode_image_inputs(pixel_values[:, i, :, :, :]) for i in range(num)], dim=stack_dim)
|
| 292 |
+
hidden_states = self.count_vision_proj(tokens=text_ids, h=hidden_states, vision_tensors=vision_tensors, seqlen=seq_length)
|
| 293 |
+
bridge_states = hidden_states
|
| 294 |
+
for i, (layer, past_key_value) in enumerate(zip(self.thinker.layers, past_key_values[:n_thinker])):
|
| 295 |
+
hidden_states, present = layer(hidden_states, position_embeddings, past_key_value=past_key_value, use_cache=use_cache, attention_mask=attention_mask)
|
| 296 |
+
presents.append(present)
|
| 297 |
+
if i == self.config.bridge_layer:
|
| 298 |
+
bridge_states = hidden_states
|
| 299 |
+
h_thinker = self.thinker.norm(hidden_states)
|
| 300 |
+
|
| 301 |
+
talker_emb = self.talker.embed_tokens(audio_ids)
|
| 302 |
+
spk_emb = args.get('spk_emb', None)
|
| 303 |
+
if spk_emb is not None:
|
| 304 |
+
spk_mask = (audio_ids[:, 0, :] == self.audio_spk_token).unsqueeze(-1)
|
| 305 |
+
talker_emb = torch.where(spk_mask, self.talker.spk_proj(spk_emb).unsqueeze(1), talker_emb)
|
| 306 |
+
hidden_states = self.talker.embed_proj(bridge_states) * self.talker.text_scale + self.talker.codec_proj(talker_emb) * self.talker.audio_scale
|
| 307 |
+
talker_pos_emb = (self.talker.freqs_cos[start_pos:start_pos + seq_length], self.talker.freqs_sin[start_pos:start_pos + seq_length])
|
| 308 |
+
for layer, past_key_value in zip(self.talker.layers, past_key_values[n_thinker:]):
|
| 309 |
+
hidden_states, present = layer(hidden_states, talker_pos_emb, past_key_value=past_key_value, use_cache=use_cache, attention_mask=attention_mask)
|
| 310 |
+
presents.append(present)
|
| 311 |
+
h_talker = self.talker.norm(hidden_states)
|
| 312 |
+
|
| 313 |
+
slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
|
| 314 |
+
aux_loss = sum(l.mlp.aux_loss for l in list(self.thinker.layers) + list(self.talker.layers) if isinstance(l.mlp, MOEFeedForward))
|
| 315 |
+
aux_loss += sum(p.sum() for p in self.audio_proj.parameters()) * 0 + sum(p.sum() for p in self.vision_proj.parameters()) * 0 + sum(p.sum() for p in self.talker.lm_head.adapters.parameters()) * 0 + sum(p.sum() for p in self.talker.spk_proj.parameters()) * 0
|
| 316 |
+
text_logits = self.thinker.lm_head(h_thinker[:, slice_indices, :])
|
| 317 |
+
audio_logits = self.talker.lm_head(h_talker[:, slice_indices, :])
|
| 318 |
+
|
| 319 |
+
out = MoeCausalLMOutputWithPast(aux_loss=aux_loss, logits=text_logits, past_key_values=presents)
|
| 320 |
+
out.audio_logits = audio_logits
|
| 321 |
+
return out
|
| 322 |
+
|
| 323 |
+
@torch.inference_mode()
|
| 324 |
+
def generate(self, input_ids, eos_token_id=2, max_new_tokens=1024, temperature=0.75, top_p=0.90,
|
| 325 |
+
stream=False, rp=1., use_cache=True, return_audio_codes=False, **args):
|
| 326 |
+
if stream:
|
| 327 |
+
return self.stream_generate(input_ids, eos_token_id, max_new_tokens, temperature, top_p, rp, use_cache, return_audio_codes, **args)
|
| 328 |
+
tokens = list(self.stream_generate(input_ids, eos_token_id, max_new_tokens, temperature, top_p, rp, use_cache, return_audio_codes, **args))
|
| 329 |
+
if tokens:
|
| 330 |
+
for text_out, _ in reversed(tokens):
|
| 331 |
+
if text_out is not None:
|
| 332 |
+
return text_out
|
| 333 |
+
return tokens[-1]
|
| 334 |
+
return input_ids
|
| 335 |
+
|
| 336 |
+
def stream_generate(self, input_ids, eos_token_id, max_new_tokens, temperature, top_p, rp, use_cache, return_audio_codes=False, **args):
|
| 337 |
+
start_pos, past_kvs, text_finished, first_finished = input_ids.shape[1], None, False, True
|
| 338 |
+
audio_codes = [[] for _ in range(8)]
|
| 339 |
+
audio_stop_pos = [None] * 8
|
| 340 |
+
audio_buffer = torch.full((1, 8, start_pos), self.audio_pad_token, dtype=torch.long, device=input_ids.device)
|
| 341 |
+
spk_emb = args.get('spk_emb', None)
|
| 342 |
+
ref_codes = args.get('ref_codes', None)
|
| 343 |
+
ref_len = ref_codes.shape[2] if ref_codes is not None else 0
|
| 344 |
+
spk_reserve = 1 if spk_emb is not None else 0
|
| 345 |
+
fill_end = start_pos
|
| 346 |
+
fill_start = max(spk_reserve, start_pos - ref_len)
|
| 347 |
+
if ref_codes is not None and fill_start < fill_end:
|
| 348 |
+
audio_buffer[:, :, fill_start:fill_end] = ref_codes[:, :, -(fill_end - fill_start):]
|
| 349 |
+
if spk_emb is not None and fill_start > 0:
|
| 350 |
+
audio_buffer[:, :, fill_start - 1] = self.audio_spk_token
|
| 351 |
+
think_end_step, generated_tokens = None, ([] if args.get('open_thinking', False) else None)
|
| 352 |
+
while input_ids.shape[1] < start_pos + max_new_tokens:
|
| 353 |
+
if past_kvs is None or not use_cache:
|
| 354 |
+
out = self.forward(torch.cat((audio_buffer, input_ids.unsqueeze(1)), dim=1), past_key_values=past_kvs, use_cache=use_cache, **args)
|
| 355 |
+
else:
|
| 356 |
+
out = self.forward(torch.cat((audio_buffer[:, :, -1:], input_ids[:, -1:].unsqueeze(1)), dim=1), past_key_values=past_kvs, use_cache=use_cache, **args)
|
| 357 |
+
past_kvs = out.past_key_values
|
| 358 |
+
|
| 359 |
+
logits = out.logits[0, -1, :].clone() / (temperature + 1e-9)
|
| 360 |
+
if rp != 1.0:
|
| 361 |
+
seen = list(set(input_ids[0].tolist()))
|
| 362 |
+
score = logits[seen]
|
| 363 |
+
logits[seen] = torch.where(score > 0, score / rp, score * rp)
|
| 364 |
+
if top_p and top_p < 1.0:
|
| 365 |
+
sorted_l, sorted_i = torch.sort(logits, descending=True)
|
| 366 |
+
mask = torch.cumsum(F.softmax(sorted_l, dim=-1), dim=-1) > top_p
|
| 367 |
+
mask[1:], mask[0] = mask[:-1].clone(), False
|
| 368 |
+
logits[sorted_i[mask]] = -float('Inf')
|
| 369 |
+
text_token = torch.multinomial(F.softmax(logits, dim=-1), 1).item()
|
| 370 |
+
|
| 371 |
+
if text_finished:
|
| 372 |
+
text_token = args.get('enter_token_id', 201) if first_finished else args.get('pad_token_id', 0)
|
| 373 |
+
first_finished = False
|
| 374 |
+
|
| 375 |
+
step = input_ids.shape[1] - start_pos
|
| 376 |
+
audio_step = step - 1
|
| 377 |
+
if generated_tokens is not None:
|
| 378 |
+
generated_tokens.append(text_token)
|
| 379 |
+
if not think_end_step and generated_tokens[-len(self.config.think_end_ids):] == list(self.config.think_end_ids):
|
| 380 |
+
think_end_step = step + 2
|
| 381 |
+
audio_step = (step - think_end_step) if think_end_step else -1
|
| 382 |
+
for i, al in enumerate(out.audio_logits):
|
| 383 |
+
if audio_step < i:
|
| 384 |
+
audio_codes[i].append(self.audio_pad_token)
|
| 385 |
+
else:
|
| 386 |
+
logits_i = al[0, -1, :].clone() / 0.2
|
| 387 |
+
for prev_code in audio_codes[i][-3:]:
|
| 388 |
+
score = logits_i[prev_code]
|
| 389 |
+
logits_i[prev_code] = torch.where(score > 0, score / 1.05, score * 1.05)
|
| 390 |
+
top_val, top_idx = logits_i.topk(50)
|
| 391 |
+
code = top_idx[torch.multinomial(F.softmax(top_val, dim=-1), 1)].item()
|
| 392 |
+
audio_codes[i].append(code)
|
| 393 |
+
if audio_stop_pos[i] is None and code >= 2048:
|
| 394 |
+
audio_stop_pos[i] = len(audio_codes[i]) - 1
|
| 395 |
+
|
| 396 |
+
if text_finished and all(audio_stop_pos[i] is not None for i in range(8)):
|
| 397 |
+
break
|
| 398 |
+
|
| 399 |
+
input_ids = torch.cat((input_ids, torch.tensor([[text_token]], device=input_ids.device)), dim=1)
|
| 400 |
+
audio_buffer = torch.cat((audio_buffer, torch.full((1, 8, 1), self.audio_pad_token, dtype=torch.long, device=input_ids.device)), dim=2)
|
| 401 |
+
for i in range(min(audio_step + 1, 8)):
|
| 402 |
+
audio_buffer[0, i, -1] = audio_codes[i][-1]
|
| 403 |
+
|
| 404 |
+
audio_frame = None
|
| 405 |
+
if return_audio_codes and audio_step >= 7:
|
| 406 |
+
frame = [audio_codes[i][step - 7 + i] for i in range(8)]
|
| 407 |
+
active_layers = sum(1 for i in range(8) if audio_stop_pos[i] is None or step - 7 + i < audio_stop_pos[i])
|
| 408 |
+
if active_layers >= 8:
|
| 409 |
+
audio_frame = frame
|
| 410 |
+
if not text_finished:
|
| 411 |
+
yield input_ids[:, start_pos:], audio_frame
|
| 412 |
+
if text_token == eos_token_id:
|
| 413 |
+
text_finished = True
|
| 414 |
+
else:
|
| 415 |
+
yield None, audio_frame
|
checkpoint/omni-o/omni-o-hf/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cda7e3a62c6db47795fb04730b85eb0b09780d13e86d12a4281d81c3964a937c
|
| 3 |
+
size 226283380
|
checkpoint/omni-o/omni-o-hf/modeling_omni_o.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys, os
|
| 2 |
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "src"))
|
| 3 |
+
from models.vam import VAM, VAMConfig
|
checkpoint/omni-o/omni-o-hf/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
checkpoint/omni-o/omni-o-hf/tokenizer_config.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"audio_bos_token": "<|audio_start|>",
|
| 4 |
+
"audio_eos_token": "<|audio_end|>",
|
| 5 |
+
"audio_token": "<|audio_pad|>",
|
| 6 |
+
"backend": "tokenizers",
|
| 7 |
+
"bos_token": "<|im_start|>",
|
| 8 |
+
"clean_up_tokenization_spaces": false,
|
| 9 |
+
"eos_token": "<|im_end|>",
|
| 10 |
+
"extra_special_tokens": {},
|
| 11 |
+
"image_token": "<|image_pad|>",
|
| 12 |
+
"is_local": true,
|
| 13 |
+
"legacy": true,
|
| 14 |
+
"local_files_only": false,
|
| 15 |
+
"model_max_length": 131072,
|
| 16 |
+
"model_specific_special_tokens": {
|
| 17 |
+
"audio_bos_token": "<|audio_start|>",
|
| 18 |
+
"audio_eos_token": "<|audio_end|>",
|
| 19 |
+
"audio_token": "<|audio_pad|>",
|
| 20 |
+
"image_token": "<|image_pad|>",
|
| 21 |
+
"video_token": "<|video_pad|>",
|
| 22 |
+
"vision_bos_token": "<|vision_start|>",
|
| 23 |
+
"vision_eos_token": "<|vision_end|>"
|
| 24 |
+
},
|
| 25 |
+
"pad_token": "<|endoftext|>",
|
| 26 |
+
"sp_model_kwargs": {},
|
| 27 |
+
"spaces_between_special_tokens": false,
|
| 28 |
+
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 29 |
+
"unk_token": "<|endoftext|>",
|
| 30 |
+
"video_token": "<|video_pad|>",
|
| 31 |
+
"vision_bos_token": "<|vision_start|>",
|
| 32 |
+
"vision_eos_token": "<|vision_end|>"
|
| 33 |
+
}
|
checkpoint/omni-o/omni-o-moe-hf/chat_template.jinja
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if tools %}
|
| 2 |
+
{{- '<|im_start|>system\n' }}
|
| 3 |
+
{%- if messages[0].role == 'system' %}
|
| 4 |
+
{{- messages[0].content + '\n\n' }}
|
| 5 |
+
{%- endif %}
|
| 6 |
+
{{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
| 7 |
+
{%- for tool in tools %}
|
| 8 |
+
{{- "\n" }}
|
| 9 |
+
{{- tool | tojson }}
|
| 10 |
+
{%- endfor %}
|
| 11 |
+
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
|
| 12 |
+
{%- else %}
|
| 13 |
+
{%- if messages[0].role == 'system' %}
|
| 14 |
+
{{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
|
| 15 |
+
{%- endif %}
|
| 16 |
+
{%- endif %}
|
| 17 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 18 |
+
{%- for message in messages[::-1] %}
|
| 19 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 20 |
+
{%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
|
| 21 |
+
{%- set ns.multi_step_tool = false %}
|
| 22 |
+
{%- set ns.last_query_index = index %}
|
| 23 |
+
{%- endif %}
|
| 24 |
+
{%- endfor %}
|
| 25 |
+
{%- for message in messages %}
|
| 26 |
+
{%- if message.content is string %}
|
| 27 |
+
{%- set content = message.content %}
|
| 28 |
+
{%- else %}
|
| 29 |
+
{%- set content = '' %}
|
| 30 |
+
{%- endif %}
|
| 31 |
+
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 32 |
+
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
|
| 33 |
+
{%- elif message.role == "assistant" %}
|
| 34 |
+
{%- set reasoning_content = '' %}
|
| 35 |
+
{%- if message.reasoning_content is string %}
|
| 36 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 37 |
+
{%- else %}
|
| 38 |
+
{%- if '</think>' in content %}
|
| 39 |
+
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 40 |
+
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 41 |
+
{%- endif %}
|
| 42 |
+
{%- endif %}
|
| 43 |
+
{%- if true %}
|
| 44 |
+
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
|
| 45 |
+
{%- endif %}
|
| 46 |
+
{%- if message.tool_calls %}
|
| 47 |
+
{%- for tool_call in message.tool_calls %}
|
| 48 |
+
{%- if (loop.first and content) or (not loop.first) %}
|
| 49 |
+
{{- '\n' }}
|
| 50 |
+
{%- endif %}
|
| 51 |
+
{%- if tool_call.function %}
|
| 52 |
+
{%- set tool_call = tool_call.function %}
|
| 53 |
+
{%- endif %}
|
| 54 |
+
{{- '<tool_call>\n{"name": "' }}
|
| 55 |
+
{{- tool_call.name }}
|
| 56 |
+
{{- '", "arguments": ' }}
|
| 57 |
+
{%- if tool_call.arguments is string %}
|
| 58 |
+
{{- tool_call.arguments }}
|
| 59 |
+
{%- else %}
|
| 60 |
+
{{- tool_call.arguments | tojson }}
|
| 61 |
+
{%- endif %}
|
| 62 |
+
{{- '}\n</tool_call>' }}
|
| 63 |
+
{%- endfor %}
|
| 64 |
+
{%- endif %}
|
| 65 |
+
{{- '<|im_end|>\n' }}
|
| 66 |
+
{%- elif message.role == "tool" %}
|
| 67 |
+
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 68 |
+
{{- '<|im_start|>user' }}
|
| 69 |
+
{%- endif %}
|
| 70 |
+
{{- '\n<tool_response>\n' }}
|
| 71 |
+
{{- content }}
|
| 72 |
+
{{- '\n</tool_response>' }}
|
| 73 |
+
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 74 |
+
{{- '<|im_end|>\n' }}
|
| 75 |
+
{%- endif %}
|
| 76 |
+
{%- endif %}
|
| 77 |
+
{%- endfor %}
|
| 78 |
+
{%- if add_generation_prompt %}
|
| 79 |
+
{{- '<|im_start|>assistant\n' }}
|
| 80 |
+
{%- if open_thinking is defined and open_thinking is true %}
|
| 81 |
+
{{- '<think>\n' }}
|
| 82 |
+
{%- else %}
|
| 83 |
+
{{- '<think>\n\n</think>\n\n' }}
|
| 84 |
+
{%- endif %}
|
| 85 |
+
{%- endif %}
|
checkpoint/omni-o/omni-o-moe-hf/config.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"VAM"
|
| 4 |
+
],
|
| 5 |
+
"audio_hidden_size": 512,
|
| 6 |
+
"audio_ids": [
|
| 7 |
+
16
|
| 8 |
+
],
|
| 9 |
+
"audio_pad_token": 2049,
|
| 10 |
+
"audio_special_token": "<|audio_pad|>",
|
| 11 |
+
"audio_spk_token": 2051,
|
| 12 |
+
"audio_stop_token": 2050,
|
| 13 |
+
"audio_vocab_size": 2112,
|
| 14 |
+
"auto_map": {
|
| 15 |
+
"AutoConfig": "modeling_omni_o.VAMConfig",
|
| 16 |
+
"AutoModelForCausalLM": "modeling_omni_o.VAM"
|
| 17 |
+
},
|
| 18 |
+
"bos_token_id": 1,
|
| 19 |
+
"bridge_layer": 3,
|
| 20 |
+
"dropout": 0.0,
|
| 21 |
+
"dtype": "float16",
|
| 22 |
+
"eos_token_id": 2,
|
| 23 |
+
"flash_attn": true,
|
| 24 |
+
"head_dim": 96,
|
| 25 |
+
"hidden_act": "silu",
|
| 26 |
+
"hidden_size": 768,
|
| 27 |
+
"image_hidden_size": 768,
|
| 28 |
+
"image_ids": [
|
| 29 |
+
12
|
| 30 |
+
],
|
| 31 |
+
"image_special_token": "<|image_pad|>",
|
| 32 |
+
"image_token_len": 64,
|
| 33 |
+
"inference_rope_scaling": false,
|
| 34 |
+
"intermediate_size": 2432,
|
| 35 |
+
"max_position_embeddings": 32768,
|
| 36 |
+
"model_type": "omni-o",
|
| 37 |
+
"moe_intermediate_size": 2432,
|
| 38 |
+
"norm_topk_prob": true,
|
| 39 |
+
"num_attention_heads": 8,
|
| 40 |
+
"num_experts": 4,
|
| 41 |
+
"num_experts_per_tok": 1,
|
| 42 |
+
"num_hidden_layers": 8,
|
| 43 |
+
"num_key_value_heads": 4,
|
| 44 |
+
"num_talker_hidden_layers": 4,
|
| 45 |
+
"rms_norm_eps": 1e-06,
|
| 46 |
+
"rope_parameters": null,
|
| 47 |
+
"rope_theta": 1000000.0,
|
| 48 |
+
"router_aux_loss_coef": 0.0005,
|
| 49 |
+
"spk_emb_size": 192,
|
| 50 |
+
"talker_hidden_size": 768,
|
| 51 |
+
"think_end_ids": [
|
| 52 |
+
26,
|
| 53 |
+
234,
|
| 54 |
+
234
|
| 55 |
+
],
|
| 56 |
+
"tie_word_embeddings": true,
|
| 57 |
+
"transformers_version": "5.14.1",
|
| 58 |
+
"use_moe": true,
|
| 59 |
+
"vocab_size": 6400
|
| 60 |
+
}
|
checkpoint/omni-o/omni-o-moe-hf/config.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from models.lm.config import LMConfig
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class VAMConfig(LMConfig):
|
| 5 |
+
model_type = "omni-o"
|
| 6 |
+
|
| 7 |
+
def __init__(self, **kwargs):
|
| 8 |
+
super().__init__(**kwargs)
|
| 9 |
+
self.num_talker_hidden_layers = kwargs.get("num_talker_hidden_layers", 4)
|
| 10 |
+
self.talker_hidden_size = kwargs.get("talker_hidden_size", 768)
|
| 11 |
+
self.audio_ids = kwargs.get("audio_ids", [16])
|
| 12 |
+
self.audio_special_token = kwargs.get("audio_special_token", "<|audio_pad|>")
|
| 13 |
+
self.audio_hidden_size = kwargs.get("audio_hidden_size", 512)
|
| 14 |
+
self.audio_vocab_size = kwargs.get("audio_vocab_size", 2112)
|
| 15 |
+
self.audio_pad_token = kwargs.get("audio_pad_token", 2049)
|
| 16 |
+
self.audio_stop_token = kwargs.get("audio_stop_token", 2050)
|
| 17 |
+
self.audio_spk_token = kwargs.get("audio_spk_token", 2051)
|
| 18 |
+
self.spk_emb_size = kwargs.get("spk_emb_size", 192)
|
| 19 |
+
self.think_end_ids = kwargs.get("think_end_ids", [26, 234, 234])
|
| 20 |
+
self.image_ids = kwargs.get("image_ids", [12])
|
| 21 |
+
self.image_special_token = kwargs.get("image_special_token", "<|image_pad|>")
|
| 22 |
+
self.image_hidden_size = kwargs.get("image_hidden_size", 768)
|
| 23 |
+
self.image_token_len = kwargs.get("image_token_len", 64)
|
| 24 |
+
self.bridge_layer = kwargs.get("bridge_layer", self.num_hidden_layers // 2 - 1)
|
checkpoint/omni-o/omni-o-moe-hf/generation_config.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"eos_token_id": 2,
|
| 5 |
+
"output_attentions": false,
|
| 6 |
+
"output_hidden_states": false,
|
| 7 |
+
"transformers_version": "5.14.1"
|
| 8 |
+
}
|
checkpoint/omni-o/omni-o-moe-hf/model.py
ADDED
|
@@ -0,0 +1,415 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import math
|
| 3 |
+
import torch
|
| 4 |
+
import warnings
|
| 5 |
+
import logging
|
| 6 |
+
import contextlib
|
| 7 |
+
import io
|
| 8 |
+
from torch import nn
|
| 9 |
+
from torch.nn import functional as F
|
| 10 |
+
from transformers.modeling_outputs import MoeCausalLMOutputWithPast
|
| 11 |
+
from transformers import SiglipVisionModel, SiglipImageProcessor, logging as hf_logging
|
| 12 |
+
|
| 13 |
+
from core import RMSNorm, precompute_freqs_cis, Block, MOEFeedForward
|
| 14 |
+
from models.lm.config import LMConfig
|
| 15 |
+
from models.lm.model import LMForCausalLM
|
| 16 |
+
from models.vam.config import VAMConfig
|
| 17 |
+
from encoders.audio import SenseVoiceAudioEncoder, SenseVoiceAudioProcessor
|
| 18 |
+
from encoders.vision import SiglipVisionEncoder
|
| 19 |
+
from projectors import MMVisionProjector, MMAudioProjector
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class TalkerHead(nn.Module):
|
| 23 |
+
def __init__(self, in_features, out_features, num_layers=8, rank=256):
|
| 24 |
+
super().__init__()
|
| 25 |
+
self.num_layers = num_layers
|
| 26 |
+
self.base = nn.Linear(in_features, out_features, bias=False)
|
| 27 |
+
self.adapters = nn.ModuleList([
|
| 28 |
+
nn.Sequential(nn.Linear(in_features, rank, bias=False), nn.GELU(), nn.Linear(rank, out_features, bias=False))
|
| 29 |
+
for _ in range(num_layers)
|
| 30 |
+
])
|
| 31 |
+
|
| 32 |
+
def forward(self, x):
|
| 33 |
+
base_out = self.base(x)
|
| 34 |
+
return [base_out + adapter(x) for adapter in self.adapters]
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class TalkerEmbedding(nn.Module):
|
| 38 |
+
def __init__(self, num_embeddings, embedding_dim, num_layers=8, rank=256):
|
| 39 |
+
super().__init__()
|
| 40 |
+
self.num_layers = num_layers
|
| 41 |
+
self.base = nn.Embedding(num_embeddings, embedding_dim)
|
| 42 |
+
self.adapters = nn.ModuleList([
|
| 43 |
+
nn.Sequential(nn.Embedding(num_embeddings, rank), nn.GELU(), nn.Linear(rank, embedding_dim, bias=False))
|
| 44 |
+
for _ in range(num_layers)
|
| 45 |
+
])
|
| 46 |
+
|
| 47 |
+
def forward(self, x):
|
| 48 |
+
base_out = self.base(x)
|
| 49 |
+
return sum(base_out[:, i, :] + self.adapters[i](x[:, i, :]) for i in range(len(self.adapters))) / self.num_layers
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class TalkerModule(nn.Module):
|
| 53 |
+
def __init__(self, config: VAMConfig):
|
| 54 |
+
super().__init__()
|
| 55 |
+
self.talker_config = LMConfig(hidden_size=config.talker_hidden_size, use_moe=config.use_moe)
|
| 56 |
+
self.layers = nn.ModuleList([Block(l, self.talker_config) for l in range(config.num_talker_hidden_layers)])
|
| 57 |
+
self.norm = RMSNorm(config.talker_hidden_size, eps=config.rms_norm_eps)
|
| 58 |
+
self.lm_head = TalkerHead(config.talker_hidden_size, config.audio_vocab_size)
|
| 59 |
+
self.embed_tokens = TalkerEmbedding(config.audio_vocab_size, config.talker_hidden_size)
|
| 60 |
+
self.codec_proj = nn.Sequential(
|
| 61 |
+
nn.Linear(config.talker_hidden_size, config.talker_hidden_size),
|
| 62 |
+
nn.GELU(),
|
| 63 |
+
nn.Linear(config.talker_hidden_size, config.talker_hidden_size),
|
| 64 |
+
RMSNorm(config.talker_hidden_size, eps=config.rms_norm_eps),
|
| 65 |
+
)
|
| 66 |
+
self.embed_proj = nn.Sequential(
|
| 67 |
+
nn.Linear(config.hidden_size, config.hidden_size),
|
| 68 |
+
nn.GELU(),
|
| 69 |
+
nn.Linear(config.hidden_size, config.talker_hidden_size),
|
| 70 |
+
RMSNorm(config.talker_hidden_size, eps=config.rms_norm_eps),
|
| 71 |
+
)
|
| 72 |
+
self.text_scale, self.audio_scale = nn.Parameter(torch.tensor(3.0)), nn.Parameter(torch.tensor(1.0))
|
| 73 |
+
self.spk_proj = nn.Linear(config.spk_emb_size, config.talker_hidden_size, bias=False)
|
| 74 |
+
freqs_cos, freqs_sin = precompute_freqs_cis(
|
| 75 |
+
dim=self.talker_config.head_dim, end=config.max_position_embeddings,
|
| 76 |
+
rope_base=config.rope_theta, rope_scaling=config.rope_scaling
|
| 77 |
+
)
|
| 78 |
+
self.register_buffer("freqs_cos", freqs_cos, persistent=False)
|
| 79 |
+
self.register_buffer("freqs_sin", freqs_sin, persistent=False)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class VAM(LMForCausalLM):
|
| 83 |
+
config_class = VAMConfig
|
| 84 |
+
|
| 85 |
+
def __init__(self, config: VAMConfig = None, audio_encoder_path: str = None, vision_model_path: str = None):
|
| 86 |
+
config = config or VAMConfig()
|
| 87 |
+
super().__init__(config)
|
| 88 |
+
object.__setattr__(self, 'thinker', self.model)
|
| 89 |
+
object.__setattr__(self.model, 'lm_head', self.lm_head)
|
| 90 |
+
self.talker = TalkerModule(config)
|
| 91 |
+
self.audio_proj = MMAudioProjector(config.audio_hidden_size, config.hidden_size)
|
| 92 |
+
self.vision_proj = MMVisionProjector(config.image_hidden_size, config.hidden_size, target_tokens=config.image_token_len)
|
| 93 |
+
self.audio_pad_token, self.audio_stop_token, self.audio_spk_token = config.audio_pad_token, config.audio_stop_token, config.audio_spk_token
|
| 94 |
+
meta_init = any(p.device.type == 'meta' for p in self.parameters())
|
| 95 |
+
if meta_init:
|
| 96 |
+
object.__setattr__(self, 'audio_encoder', None)
|
| 97 |
+
object.__setattr__(self, 'audio_processor', None)
|
| 98 |
+
object.__setattr__(self, 'vision_encoder', None)
|
| 99 |
+
object.__setattr__(self, 'vision_processor', None)
|
| 100 |
+
else:
|
| 101 |
+
audio_enc = SenseVoiceAudioEncoder(audio_encoder_path) if audio_encoder_path else SenseVoiceAudioEncoder()
|
| 102 |
+
object.__setattr__(self, 'audio_encoder', audio_enc)
|
| 103 |
+
object.__setattr__(self, 'audio_processor', audio_enc.processor)
|
| 104 |
+
vision_enc = SiglipVisionEncoder(vision_model_path) if vision_model_path else SiglipVisionEncoder()
|
| 105 |
+
object.__setattr__(self, 'vision_encoder', vision_enc)
|
| 106 |
+
object.__setattr__(self, 'vision_processor', vision_enc.processor)
|
| 107 |
+
|
| 108 |
+
@classmethod
|
| 109 |
+
def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
|
| 110 |
+
audio_encoder_path = kwargs.pop('audio_encoder_path', None)
|
| 111 |
+
vision_model_path = kwargs.pop('vision_model_path', None)
|
| 112 |
+
model = super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)
|
| 113 |
+
if audio_encoder_path and model.audio_encoder is None:
|
| 114 |
+
enc, proc = cls.load_sensevoice(audio_encoder_path)
|
| 115 |
+
object.__setattr__(model, 'audio_encoder', enc)
|
| 116 |
+
object.__setattr__(model, 'audio_processor', proc)
|
| 117 |
+
if vision_model_path and model.vision_encoder is None:
|
| 118 |
+
enc, proc = cls.load_vision(vision_model_path)
|
| 119 |
+
object.__setattr__(model, 'vision_encoder', enc)
|
| 120 |
+
object.__setattr__(model, 'vision_processor', proc)
|
| 121 |
+
return model
|
| 122 |
+
|
| 123 |
+
@staticmethod
|
| 124 |
+
def load_sensevoice(path):
|
| 125 |
+
if not os.path.exists(path):
|
| 126 |
+
warnings.warn(f"[VAM] SenseVoice path not found: {path}")
|
| 127 |
+
return None, None
|
| 128 |
+
logging.getLogger().setLevel(logging.ERROR)
|
| 129 |
+
hf_logging.set_verbosity_error()
|
| 130 |
+
with contextlib.redirect_stdout(io.StringIO()):
|
| 131 |
+
from funasr import AutoModel
|
| 132 |
+
m = AutoModel(model=path, trust_remote_code=True, disable_update=True, device="cpu")
|
| 133 |
+
encoder, frontend = m.model.encoder, m.kwargs["frontend"]
|
| 134 |
+
for p in encoder.parameters():
|
| 135 |
+
p.requires_grad = False
|
| 136 |
+
return encoder.eval().float(), SenseVoiceAudioProcessor(frontend.eval())
|
| 137 |
+
|
| 138 |
+
@staticmethod
|
| 139 |
+
def load_vision(path):
|
| 140 |
+
if path is None or not os.path.exists(path):
|
| 141 |
+
warnings.warn(f"[VAM] Vision model path not found: {path}. vision_encoder will be None!")
|
| 142 |
+
return None, None
|
| 143 |
+
hf_logging.set_verbosity_error()
|
| 144 |
+
try:
|
| 145 |
+
model = SiglipVisionModel.from_pretrained(path)
|
| 146 |
+
except (RuntimeError, ValueError):
|
| 147 |
+
return None, None
|
| 148 |
+
processor = SiglipImageProcessor.from_pretrained(path)
|
| 149 |
+
for p in model.parameters():
|
| 150 |
+
p.requires_grad = False
|
| 151 |
+
return model.eval(), processor
|
| 152 |
+
|
| 153 |
+
@torch.compiler.disable
|
| 154 |
+
def encode_audio_inputs(self, audio_inputs, audio_lens=None):
|
| 155 |
+
if (audio_inputs is None) or (self.audio_encoder is None) or (not audio_inputs.any()):
|
| 156 |
+
return None
|
| 157 |
+
batch_mask = audio_inputs.flatten(1).any(1)
|
| 158 |
+
enc_dtype = next(self.audio_encoder.parameters()).dtype
|
| 159 |
+
valid_fbank = audio_inputs[batch_mask].to(dtype=enc_dtype)
|
| 160 |
+
if audio_lens is not None:
|
| 161 |
+
valid_lens = audio_lens[batch_mask].to(valid_fbank.device)
|
| 162 |
+
else:
|
| 163 |
+
valid_lens = torch.tensor([valid_fbank.size(1)] * valid_fbank.size(0), device=valid_fbank.device)
|
| 164 |
+
with torch.no_grad():
|
| 165 |
+
emb, _ = self.audio_encoder.model(valid_fbank, valid_lens)
|
| 166 |
+
proj_dtype = next(self.audio_proj.parameters()).dtype
|
| 167 |
+
emb_list = [self.audio_proj(emb[i, :max(1, min(valid_lens[i].item(), emb.size(1)))].unsqueeze(0).to(proj_dtype)).squeeze(0) for i in range(emb.size(0))]
|
| 168 |
+
if batch_mask.all():
|
| 169 |
+
return emb_list
|
| 170 |
+
out = [None] * audio_inputs.size(0)
|
| 171 |
+
j = 0
|
| 172 |
+
for i in range(audio_inputs.size(0)):
|
| 173 |
+
if batch_mask[i]:
|
| 174 |
+
out[i] = emb_list[j]
|
| 175 |
+
j += 1
|
| 176 |
+
return out
|
| 177 |
+
|
| 178 |
+
@torch.compiler.disable
|
| 179 |
+
def inject_audio_features(self, tokens, h, audio_feats, seqlen):
|
| 180 |
+
if audio_feats is None or not self.config.audio_ids:
|
| 181 |
+
return h
|
| 182 |
+
marker = self.config.audio_ids[0]
|
| 183 |
+
out = []
|
| 184 |
+
for b in range(h.size(0)):
|
| 185 |
+
hb, seq, i = h[b], tokens[b].tolist(), 0
|
| 186 |
+
af = audio_feats[b] if audio_feats[b] is not None else None
|
| 187 |
+
while i < len(seq):
|
| 188 |
+
if seq[i] == marker:
|
| 189 |
+
start = i
|
| 190 |
+
while i < len(seq) and seq[i] == marker:
|
| 191 |
+
i += 1
|
| 192 |
+
if af is not None:
|
| 193 |
+
inject_len = min(af.size(0), i - start)
|
| 194 |
+
hb = torch.cat((hb[:start], af[:inject_len], hb[start + inject_len:]), dim=0)
|
| 195 |
+
af = None
|
| 196 |
+
else:
|
| 197 |
+
i += 1
|
| 198 |
+
out.append(hb)
|
| 199 |
+
return torch.stack(out)
|
| 200 |
+
|
| 201 |
+
@torch.compiler.disable
|
| 202 |
+
def get_image_embeddings(self, image_inputs):
|
| 203 |
+
if hasattr(image_inputs, 'keys'):
|
| 204 |
+
image_inputs = {k: (v.squeeze(1) if v.ndim > 2 and v.shape[1] == 1 else v) for k, v in image_inputs.items()}
|
| 205 |
+
pixel_attention_mask = image_inputs.get('pixel_attention_mask')
|
| 206 |
+
if pixel_attention_mask is not None and not pixel_attention_mask.any():
|
| 207 |
+
pv = image_inputs['pixel_values']
|
| 208 |
+
return pv.new_zeros(pv.size(0), pv.size(1), self.config.image_hidden_size)
|
| 209 |
+
with torch.no_grad():
|
| 210 |
+
outputs = self.vision_encoder.model(**image_inputs)
|
| 211 |
+
return outputs.last_hidden_state
|
| 212 |
+
|
| 213 |
+
@torch.compiler.disable
|
| 214 |
+
def encode_image_inputs(self, pixel_values):
|
| 215 |
+
if pixel_values is None or self.vision_encoder is None:
|
| 216 |
+
return None
|
| 217 |
+
mask = pixel_values.flatten(1).any(1)
|
| 218 |
+
if not mask.any():
|
| 219 |
+
return pixel_values.new_zeros(pixel_values.size(0), self.config.image_token_len, self.config.hidden_size)
|
| 220 |
+
with torch.no_grad():
|
| 221 |
+
emb = self.vision_encoder.model(pixel_values=pixel_values[mask]).last_hidden_state
|
| 222 |
+
if emb.dim() == 2:
|
| 223 |
+
emb = emb.unsqueeze(0)
|
| 224 |
+
emb = self.vision_proj(emb)
|
| 225 |
+
if mask.all():
|
| 226 |
+
return emb
|
| 227 |
+
idx = mask.nonzero().view(-1, 1, 1).expand_as(emb)
|
| 228 |
+
return emb.new_zeros(pixel_values.size(0), *emb.shape[1:]).scatter(0, idx, emb)
|
| 229 |
+
|
| 230 |
+
@torch.compiler.disable
|
| 231 |
+
def count_vision_proj(self, tokens, h, vision_tensors=None, seqlen=512):
|
| 232 |
+
if vision_tensors is None or not self.config.image_ids:
|
| 233 |
+
return h
|
| 234 |
+
marker, vf = self.config.image_ids[0], vision_tensors
|
| 235 |
+
if vf.dim() == 3:
|
| 236 |
+
vf = vf.unsqueeze(1)
|
| 237 |
+
out = []
|
| 238 |
+
for b in range(h.size(0)):
|
| 239 |
+
hb, seq, k, i = h[b], tokens[b].tolist(), 0, 0
|
| 240 |
+
while i < len(seq):
|
| 241 |
+
if seq[i] == marker:
|
| 242 |
+
start = i
|
| 243 |
+
while i < len(seq) and seq[i] == marker:
|
| 244 |
+
i += 1
|
| 245 |
+
if k < vf.size(1):
|
| 246 |
+
hb = torch.cat((hb[:start], vf[b][k][:i - start], hb[i:]), dim=0)[:seqlen]
|
| 247 |
+
k += 1
|
| 248 |
+
else:
|
| 249 |
+
i += 1
|
| 250 |
+
out.append(hb)
|
| 251 |
+
return torch.stack(out)
|
| 252 |
+
|
| 253 |
+
def forward(self, input_ids, attention_mask=None, past_key_values=None, use_cache=False, logits_to_keep=0,
|
| 254 |
+
audio_inputs=None, audio_lens=None, pixel_values=None, **args):
|
| 255 |
+
if len(input_ids.shape) == 2:
|
| 256 |
+
batch_size, seq_length = input_ids.shape
|
| 257 |
+
text_ids = input_ids
|
| 258 |
+
audio_ids = torch.full((batch_size, 8, seq_length), self.audio_pad_token, dtype=torch.long, device=input_ids.device)
|
| 259 |
+
else:
|
| 260 |
+
batch_size, _, seq_length = input_ids.shape
|
| 261 |
+
text_ids, audio_ids = input_ids[:, 8, :], input_ids[:, :8, :]
|
| 262 |
+
if hasattr(past_key_values, 'layers'):
|
| 263 |
+
past_key_values = None
|
| 264 |
+
n_thinker, n_talker = len(self.thinker.layers), len(self.talker.layers)
|
| 265 |
+
past_key_values = past_key_values or ([None] * (n_thinker + n_talker))
|
| 266 |
+
start_pos = past_key_values[0][0].shape[1] if past_key_values[0] is not None else 0
|
| 267 |
+
if self.thinker.freqs_cos[0, 0] == 0:
|
| 268 |
+
freqs_cos, freqs_sin = precompute_freqs_cis(dim=self.config.head_dim, end=self.config.max_position_embeddings, rope_base=self.config.rope_theta, rope_scaling=self.config.rope_scaling)
|
| 269 |
+
self.thinker.freqs_cos, self.thinker.freqs_sin = freqs_cos.to(input_ids.device), freqs_sin.to(input_ids.device)
|
| 270 |
+
if self.talker.freqs_cos[0, 0] == 0:
|
| 271 |
+
freqs_cos, freqs_sin = precompute_freqs_cis(dim=self.talker.talker_config.head_dim, end=self.config.max_position_embeddings, rope_base=self.config.rope_theta, rope_scaling=self.config.rope_scaling)
|
| 272 |
+
self.talker.freqs_cos, self.talker.freqs_sin = freqs_cos.to(input_ids.device), freqs_sin.to(input_ids.device)
|
| 273 |
+
presents = []
|
| 274 |
+
|
| 275 |
+
hidden_states = self.thinker.dropout(self.thinker.embed_tokens(text_ids))
|
| 276 |
+
position_embeddings = (self.thinker.freqs_cos[start_pos:start_pos + seq_length], self.thinker.freqs_sin[start_pos:start_pos + seq_length])
|
| 277 |
+
if audio_inputs is not None and start_pos == 0:
|
| 278 |
+
audio_features = self.encode_audio_inputs(audio_inputs, audio_lens)
|
| 279 |
+
hidden_states = self.inject_audio_features(text_ids, hidden_states, audio_features, seq_length)
|
| 280 |
+
if pixel_values is not None and start_pos == 0:
|
| 281 |
+
if hasattr(pixel_values, 'keys'):
|
| 282 |
+
img_emb = self.get_image_embeddings(pixel_values).to(hidden_states.dtype)
|
| 283 |
+
vision_tensors = self.vision_proj(img_emb)
|
| 284 |
+
else:
|
| 285 |
+
if len(pixel_values.shape) == 6:
|
| 286 |
+
pixel_values = pixel_values.squeeze(2)
|
| 287 |
+
if len(pixel_values.shape) == 4:
|
| 288 |
+
pixel_values = pixel_values.unsqueeze(1)
|
| 289 |
+
bs, num, c, im_h, im_w = pixel_values.shape
|
| 290 |
+
stack_dim = 1 if bs > 1 else 0
|
| 291 |
+
vision_tensors = torch.stack([self.encode_image_inputs(pixel_values[:, i, :, :, :]) for i in range(num)], dim=stack_dim)
|
| 292 |
+
hidden_states = self.count_vision_proj(tokens=text_ids, h=hidden_states, vision_tensors=vision_tensors, seqlen=seq_length)
|
| 293 |
+
bridge_states = hidden_states
|
| 294 |
+
for i, (layer, past_key_value) in enumerate(zip(self.thinker.layers, past_key_values[:n_thinker])):
|
| 295 |
+
hidden_states, present = layer(hidden_states, position_embeddings, past_key_value=past_key_value, use_cache=use_cache, attention_mask=attention_mask)
|
| 296 |
+
presents.append(present)
|
| 297 |
+
if i == self.config.bridge_layer:
|
| 298 |
+
bridge_states = hidden_states
|
| 299 |
+
h_thinker = self.thinker.norm(hidden_states)
|
| 300 |
+
|
| 301 |
+
talker_emb = self.talker.embed_tokens(audio_ids)
|
| 302 |
+
spk_emb = args.get('spk_emb', None)
|
| 303 |
+
if spk_emb is not None:
|
| 304 |
+
spk_mask = (audio_ids[:, 0, :] == self.audio_spk_token).unsqueeze(-1)
|
| 305 |
+
talker_emb = torch.where(spk_mask, self.talker.spk_proj(spk_emb).unsqueeze(1), talker_emb)
|
| 306 |
+
hidden_states = self.talker.embed_proj(bridge_states) * self.talker.text_scale + self.talker.codec_proj(talker_emb) * self.talker.audio_scale
|
| 307 |
+
talker_pos_emb = (self.talker.freqs_cos[start_pos:start_pos + seq_length], self.talker.freqs_sin[start_pos:start_pos + seq_length])
|
| 308 |
+
for layer, past_key_value in zip(self.talker.layers, past_key_values[n_thinker:]):
|
| 309 |
+
hidden_states, present = layer(hidden_states, talker_pos_emb, past_key_value=past_key_value, use_cache=use_cache, attention_mask=attention_mask)
|
| 310 |
+
presents.append(present)
|
| 311 |
+
h_talker = self.talker.norm(hidden_states)
|
| 312 |
+
|
| 313 |
+
slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
|
| 314 |
+
aux_loss = sum(l.mlp.aux_loss for l in list(self.thinker.layers) + list(self.talker.layers) if isinstance(l.mlp, MOEFeedForward))
|
| 315 |
+
aux_loss += sum(p.sum() for p in self.audio_proj.parameters()) * 0 + sum(p.sum() for p in self.vision_proj.parameters()) * 0 + sum(p.sum() for p in self.talker.lm_head.adapters.parameters()) * 0 + sum(p.sum() for p in self.talker.spk_proj.parameters()) * 0
|
| 316 |
+
text_logits = self.thinker.lm_head(h_thinker[:, slice_indices, :])
|
| 317 |
+
audio_logits = self.talker.lm_head(h_talker[:, slice_indices, :])
|
| 318 |
+
|
| 319 |
+
out = MoeCausalLMOutputWithPast(aux_loss=aux_loss, logits=text_logits, past_key_values=presents)
|
| 320 |
+
out.audio_logits = audio_logits
|
| 321 |
+
return out
|
| 322 |
+
|
| 323 |
+
@torch.inference_mode()
|
| 324 |
+
def generate(self, input_ids, eos_token_id=2, max_new_tokens=1024, temperature=0.75, top_p=0.90,
|
| 325 |
+
stream=False, rp=1., use_cache=True, return_audio_codes=False, **args):
|
| 326 |
+
if stream:
|
| 327 |
+
return self.stream_generate(input_ids, eos_token_id, max_new_tokens, temperature, top_p, rp, use_cache, return_audio_codes, **args)
|
| 328 |
+
tokens = list(self.stream_generate(input_ids, eos_token_id, max_new_tokens, temperature, top_p, rp, use_cache, return_audio_codes, **args))
|
| 329 |
+
if tokens:
|
| 330 |
+
for text_out, _ in reversed(tokens):
|
| 331 |
+
if text_out is not None:
|
| 332 |
+
return text_out
|
| 333 |
+
return tokens[-1]
|
| 334 |
+
return input_ids
|
| 335 |
+
|
| 336 |
+
def stream_generate(self, input_ids, eos_token_id, max_new_tokens, temperature, top_p, rp, use_cache, return_audio_codes=False, **args):
|
| 337 |
+
start_pos, past_kvs, text_finished, first_finished = input_ids.shape[1], None, False, True
|
| 338 |
+
audio_codes = [[] for _ in range(8)]
|
| 339 |
+
audio_stop_pos = [None] * 8
|
| 340 |
+
audio_buffer = torch.full((1, 8, start_pos), self.audio_pad_token, dtype=torch.long, device=input_ids.device)
|
| 341 |
+
spk_emb = args.get('spk_emb', None)
|
| 342 |
+
ref_codes = args.get('ref_codes', None)
|
| 343 |
+
ref_len = ref_codes.shape[2] if ref_codes is not None else 0
|
| 344 |
+
spk_reserve = 1 if spk_emb is not None else 0
|
| 345 |
+
fill_end = start_pos
|
| 346 |
+
fill_start = max(spk_reserve, start_pos - ref_len)
|
| 347 |
+
if ref_codes is not None and fill_start < fill_end:
|
| 348 |
+
audio_buffer[:, :, fill_start:fill_end] = ref_codes[:, :, -(fill_end - fill_start):]
|
| 349 |
+
if spk_emb is not None and fill_start > 0:
|
| 350 |
+
audio_buffer[:, :, fill_start - 1] = self.audio_spk_token
|
| 351 |
+
think_end_step, generated_tokens = None, ([] if args.get('open_thinking', False) else None)
|
| 352 |
+
while input_ids.shape[1] < start_pos + max_new_tokens:
|
| 353 |
+
if past_kvs is None or not use_cache:
|
| 354 |
+
out = self.forward(torch.cat((audio_buffer, input_ids.unsqueeze(1)), dim=1), past_key_values=past_kvs, use_cache=use_cache, **args)
|
| 355 |
+
else:
|
| 356 |
+
out = self.forward(torch.cat((audio_buffer[:, :, -1:], input_ids[:, -1:].unsqueeze(1)), dim=1), past_key_values=past_kvs, use_cache=use_cache, **args)
|
| 357 |
+
past_kvs = out.past_key_values
|
| 358 |
+
|
| 359 |
+
logits = out.logits[0, -1, :].clone() / (temperature + 1e-9)
|
| 360 |
+
if rp != 1.0:
|
| 361 |
+
seen = list(set(input_ids[0].tolist()))
|
| 362 |
+
score = logits[seen]
|
| 363 |
+
logits[seen] = torch.where(score > 0, score / rp, score * rp)
|
| 364 |
+
if top_p and top_p < 1.0:
|
| 365 |
+
sorted_l, sorted_i = torch.sort(logits, descending=True)
|
| 366 |
+
mask = torch.cumsum(F.softmax(sorted_l, dim=-1), dim=-1) > top_p
|
| 367 |
+
mask[1:], mask[0] = mask[:-1].clone(), False
|
| 368 |
+
logits[sorted_i[mask]] = -float('Inf')
|
| 369 |
+
text_token = torch.multinomial(F.softmax(logits, dim=-1), 1).item()
|
| 370 |
+
|
| 371 |
+
if text_finished:
|
| 372 |
+
text_token = args.get('enter_token_id', 201) if first_finished else args.get('pad_token_id', 0)
|
| 373 |
+
first_finished = False
|
| 374 |
+
|
| 375 |
+
step = input_ids.shape[1] - start_pos
|
| 376 |
+
audio_step = step - 1
|
| 377 |
+
if generated_tokens is not None:
|
| 378 |
+
generated_tokens.append(text_token)
|
| 379 |
+
if not think_end_step and generated_tokens[-len(self.config.think_end_ids):] == list(self.config.think_end_ids):
|
| 380 |
+
think_end_step = step + 2
|
| 381 |
+
audio_step = (step - think_end_step) if think_end_step else -1
|
| 382 |
+
for i, al in enumerate(out.audio_logits):
|
| 383 |
+
if audio_step < i:
|
| 384 |
+
audio_codes[i].append(self.audio_pad_token)
|
| 385 |
+
else:
|
| 386 |
+
logits_i = al[0, -1, :].clone() / 0.2
|
| 387 |
+
for prev_code in audio_codes[i][-3:]:
|
| 388 |
+
score = logits_i[prev_code]
|
| 389 |
+
logits_i[prev_code] = torch.where(score > 0, score / 1.05, score * 1.05)
|
| 390 |
+
top_val, top_idx = logits_i.topk(50)
|
| 391 |
+
code = top_idx[torch.multinomial(F.softmax(top_val, dim=-1), 1)].item()
|
| 392 |
+
audio_codes[i].append(code)
|
| 393 |
+
if audio_stop_pos[i] is None and code >= 2048:
|
| 394 |
+
audio_stop_pos[i] = len(audio_codes[i]) - 1
|
| 395 |
+
|
| 396 |
+
if text_finished and all(audio_stop_pos[i] is not None for i in range(8)):
|
| 397 |
+
break
|
| 398 |
+
|
| 399 |
+
input_ids = torch.cat((input_ids, torch.tensor([[text_token]], device=input_ids.device)), dim=1)
|
| 400 |
+
audio_buffer = torch.cat((audio_buffer, torch.full((1, 8, 1), self.audio_pad_token, dtype=torch.long, device=input_ids.device)), dim=2)
|
| 401 |
+
for i in range(min(audio_step + 1, 8)):
|
| 402 |
+
audio_buffer[0, i, -1] = audio_codes[i][-1]
|
| 403 |
+
|
| 404 |
+
audio_frame = None
|
| 405 |
+
if return_audio_codes and audio_step >= 7:
|
| 406 |
+
frame = [audio_codes[i][step - 7 + i] for i in range(8)]
|
| 407 |
+
active_layers = sum(1 for i in range(8) if audio_stop_pos[i] is None or step - 7 + i < audio_stop_pos[i])
|
| 408 |
+
if active_layers >= 8:
|
| 409 |
+
audio_frame = frame
|
| 410 |
+
if not text_finished:
|
| 411 |
+
yield input_ids[:, start_pos:], audio_frame
|
| 412 |
+
if text_token == eos_token_id:
|
| 413 |
+
text_finished = True
|
| 414 |
+
else:
|
| 415 |
+
yield None, audio_frame
|
checkpoint/omni-o/omni-o-moe-hf/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:37f1f8e4fd120026b82bdef41dc2fc8d1a16328cf027d1f600327c88cec5b36f
|
| 3 |
+
size 629811308
|
checkpoint/omni-o/omni-o-moe-hf/modeling_omni_o.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys, os
|
| 2 |
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "src"))
|
| 3 |
+
from models.vam import VAM, VAMConfig
|
checkpoint/omni-o/omni-o-moe-hf/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
checkpoint/omni-o/omni-o-moe-hf/tokenizer_config.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"audio_bos_token": "<|audio_start|>",
|
| 4 |
+
"audio_eos_token": "<|audio_end|>",
|
| 5 |
+
"audio_token": "<|audio_pad|>",
|
| 6 |
+
"backend": "tokenizers",
|
| 7 |
+
"bos_token": "<|im_start|>",
|
| 8 |
+
"clean_up_tokenization_spaces": false,
|
| 9 |
+
"eos_token": "<|im_end|>",
|
| 10 |
+
"extra_special_tokens": {},
|
| 11 |
+
"image_token": "<|image_pad|>",
|
| 12 |
+
"is_local": true,
|
| 13 |
+
"legacy": true,
|
| 14 |
+
"local_files_only": false,
|
| 15 |
+
"model_max_length": 131072,
|
| 16 |
+
"model_specific_special_tokens": {
|
| 17 |
+
"audio_bos_token": "<|audio_start|>",
|
| 18 |
+
"audio_eos_token": "<|audio_end|>",
|
| 19 |
+
"audio_token": "<|audio_pad|>",
|
| 20 |
+
"image_token": "<|image_pad|>",
|
| 21 |
+
"video_token": "<|video_pad|>",
|
| 22 |
+
"vision_bos_token": "<|vision_start|>",
|
| 23 |
+
"vision_eos_token": "<|vision_end|>"
|
| 24 |
+
},
|
| 25 |
+
"pad_token": "<|endoftext|>",
|
| 26 |
+
"sp_model_kwargs": {},
|
| 27 |
+
"spaces_between_special_tokens": false,
|
| 28 |
+
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 29 |
+
"unk_token": "<|endoftext|>",
|
| 30 |
+
"video_token": "<|video_pad|>",
|
| 31 |
+
"vision_bos_token": "<|vision_start|>",
|
| 32 |
+
"vision_eos_token": "<|vision_end|>"
|
| 33 |
+
}
|
checkpoint/omni-o/omni-o.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5a05a617858453aa9490bb0ca9e22503e51dd8718348bc06d3a549ffecb589f8
|
| 3 |
+
size 236155558
|
checkpoint/omni-o/omni-o_moe.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6cef510dab06320b1e3991c2bec5ddf2263d1b0c89d1fa4070b2567e4fef6d1a
|
| 3 |
+
size 639710162
|
checkpoint/omni/native_hf/chat_template.jinja
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if tools %}
|
| 2 |
+
{{- '<|im_start|>system\n' }}
|
| 3 |
+
{%- if messages[0].role == 'system' %}
|
| 4 |
+
{{- messages[0].content + '\n\n' }}
|
| 5 |
+
{%- endif %}
|
| 6 |
+
{{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
| 7 |
+
{%- for tool in tools %}
|
| 8 |
+
{{- "\n" }}
|
| 9 |
+
{{- tool | tojson }}
|
| 10 |
+
{%- endfor %}
|
| 11 |
+
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
|
| 12 |
+
{%- else %}
|
| 13 |
+
{%- if messages[0].role == 'system' %}
|
| 14 |
+
{{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
|
| 15 |
+
{%- endif %}
|
| 16 |
+
{%- endif %}
|
| 17 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 18 |
+
{%- for message in messages[::-1] %}
|
| 19 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 20 |
+
{%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
|
| 21 |
+
{%- set ns.multi_step_tool = false %}
|
| 22 |
+
{%- set ns.last_query_index = index %}
|
| 23 |
+
{%- endif %}
|
| 24 |
+
{%- endfor %}
|
| 25 |
+
{%- for message in messages %}
|
| 26 |
+
{%- if message.content is string %}
|
| 27 |
+
{%- set content = message.content %}
|
| 28 |
+
{%- else %}
|
| 29 |
+
{%- set content = '' %}
|
| 30 |
+
{%- endif %}
|
| 31 |
+
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 32 |
+
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
|
| 33 |
+
{%- elif message.role == "assistant" %}
|
| 34 |
+
{%- set reasoning_content = '' %}
|
| 35 |
+
{%- if message.reasoning_content is string %}
|
| 36 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 37 |
+
{%- else %}
|
| 38 |
+
{%- if '</think>' in content %}
|
| 39 |
+
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 40 |
+
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 41 |
+
{%- endif %}
|
| 42 |
+
{%- endif %}
|
| 43 |
+
{%- if true %}
|
| 44 |
+
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
|
| 45 |
+
{%- endif %}
|
| 46 |
+
{%- if message.tool_calls %}
|
| 47 |
+
{%- for tool_call in message.tool_calls %}
|
| 48 |
+
{%- if (loop.first and content) or (not loop.first) %}
|
| 49 |
+
{{- '\n' }}
|
| 50 |
+
{%- endif %}
|
| 51 |
+
{%- if tool_call.function %}
|
| 52 |
+
{%- set tool_call = tool_call.function %}
|
| 53 |
+
{%- endif %}
|
| 54 |
+
{{- '<tool_call>\n{"name": "' }}
|
| 55 |
+
{{- tool_call.name }}
|
| 56 |
+
{{- '", "arguments": ' }}
|
| 57 |
+
{%- if tool_call.arguments is string %}
|
| 58 |
+
{{- tool_call.arguments }}
|
| 59 |
+
{%- else %}
|
| 60 |
+
{{- tool_call.arguments | tojson }}
|
| 61 |
+
{%- endif %}
|
| 62 |
+
{{- '}\n</tool_call>' }}
|
| 63 |
+
{%- endfor %}
|
| 64 |
+
{%- endif %}
|
| 65 |
+
{{- '<|im_end|>\n' }}
|
| 66 |
+
{%- elif message.role == "tool" %}
|
| 67 |
+
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 68 |
+
{{- '<|im_start|>user' }}
|
| 69 |
+
{%- endif %}
|
| 70 |
+
{{- '\n<tool_response>\n' }}
|
| 71 |
+
{{- content }}
|
| 72 |
+
{{- '\n</tool_response>' }}
|
| 73 |
+
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 74 |
+
{{- '<|im_end|>\n' }}
|
| 75 |
+
{%- endif %}
|
| 76 |
+
{%- endif %}
|
| 77 |
+
{%- endfor %}
|
| 78 |
+
{%- if add_generation_prompt %}
|
| 79 |
+
{{- '<|im_start|>assistant\n' }}
|
| 80 |
+
{%- if open_thinking is defined and open_thinking is true %}
|
| 81 |
+
{{- '<think>\n' }}
|
| 82 |
+
{%- else %}
|
| 83 |
+
{{- '<think>\n\n</think>\n\n' }}
|
| 84 |
+
{%- endif %}
|
| 85 |
+
{%- endif %}
|
checkpoint/omni/native_hf/config.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"LMForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"bos_token_id": 1,
|
| 6 |
+
"dropout": 0.0,
|
| 7 |
+
"dtype": "float16",
|
| 8 |
+
"eos_token_id": 2,
|
| 9 |
+
"flash_attn": true,
|
| 10 |
+
"head_dim": 96,
|
| 11 |
+
"hidden_act": "silu",
|
| 12 |
+
"hidden_size": 768,
|
| 13 |
+
"inference_rope_scaling": false,
|
| 14 |
+
"intermediate_size": 2432,
|
| 15 |
+
"max_position_embeddings": 32768,
|
| 16 |
+
"max_seq_len": 8192,
|
| 17 |
+
"model_type": "omni",
|
| 18 |
+
"moe_intermediate_size": 2432,
|
| 19 |
+
"norm_topk_prob": true,
|
| 20 |
+
"num_attention_heads": 8,
|
| 21 |
+
"num_experts": 4,
|
| 22 |
+
"num_experts_per_tok": 1,
|
| 23 |
+
"num_hidden_layers": 8,
|
| 24 |
+
"num_key_value_heads": 4,
|
| 25 |
+
"rms_norm_eps": 1e-06,
|
| 26 |
+
"rope_theta": 1000000.0,
|
| 27 |
+
"router_aux_loss_coef": 0.0005,
|
| 28 |
+
"tie_word_embeddings": true,
|
| 29 |
+
"transformers_version": "5.14.1",
|
| 30 |
+
"use_moe": false,
|
| 31 |
+
"vocab_size": 6400,
|
| 32 |
+
"rope_scaling": null
|
| 33 |
+
}
|
checkpoint/omni/native_hf/generation_config.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"eos_token_id": 2,
|
| 5 |
+
"output_attentions": false,
|
| 6 |
+
"output_hidden_states": false,
|
| 7 |
+
"transformers_version": "5.14.1"
|
| 8 |
+
}
|
checkpoint/omni/native_hf/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3adf69402b5d22e693151cabadc12528f923c4ba6bf343738aaf13f0892162e8
|
| 3 |
+
size 127834168
|
checkpoint/omni/native_hf/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
checkpoint/omni/native_hf/tokenizer_config.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"audio_bos_token": "<|audio_start|>",
|
| 4 |
+
"audio_eos_token": "<|audio_end|>",
|
| 5 |
+
"audio_token": "<|audio_pad|>",
|
| 6 |
+
"backend": "tokenizers",
|
| 7 |
+
"bos_token": "<|im_start|>",
|
| 8 |
+
"clean_up_tokenization_spaces": false,
|
| 9 |
+
"eos_token": "<|im_end|>",
|
| 10 |
+
"extra_special_tokens": {},
|
| 11 |
+
"image_token": "<|image_pad|>",
|
| 12 |
+
"is_local": true,
|
| 13 |
+
"legacy": true,
|
| 14 |
+
"local_files_only": false,
|
| 15 |
+
"model_max_length": 131072,
|
| 16 |
+
"model_specific_special_tokens": {
|
| 17 |
+
"audio_bos_token": "<|audio_start|>",
|
| 18 |
+
"audio_eos_token": "<|audio_end|>",
|
| 19 |
+
"audio_token": "<|audio_pad|>",
|
| 20 |
+
"image_token": "<|image_pad|>",
|
| 21 |
+
"video_token": "<|video_pad|>",
|
| 22 |
+
"vision_bos_token": "<|vision_start|>",
|
| 23 |
+
"vision_eos_token": "<|vision_end|>"
|
| 24 |
+
},
|
| 25 |
+
"pad_token": "<|endoftext|>",
|
| 26 |
+
"sp_model_kwargs": {},
|
| 27 |
+
"spaces_between_special_tokens": false,
|
| 28 |
+
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 29 |
+
"unk_token": "<|endoftext|>",
|
| 30 |
+
"video_token": "<|video_pad|>",
|
| 31 |
+
"vision_bos_token": "<|vision_start|>",
|
| 32 |
+
"vision_eos_token": "<|vision_end|>"
|
| 33 |
+
}
|
checkpoint/omni/omni.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5b8c49f6c9d965092e651cafeeaeb8705558632b3fd4ac8ab319cbc5a3cbc4a0
|
| 3 |
+
size 137683346
|
checkpoint/sensevoice/.msc
ADDED
|
Binary file (507 Bytes). View file
|
|
|
checkpoint/sensevoice/.mv
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Revision:master,CreatedAt:1777630553
|
checkpoint/sensevoice/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- zh
|
| 5 |
+
- en
|
| 6 |
+
- yue
|
| 7 |
+
- ja
|
| 8 |
+
- ko
|
| 9 |
+
tags:
|
| 10 |
+
- automatic-speech-recognition
|
| 11 |
+
- speech
|
| 12 |
+
- audio
|
| 13 |
+
- encoder
|
| 14 |
+
- sensevoice
|
| 15 |
+
pipeline_tag: automatic-speech-recognition
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# SenseVoiceSmall
|
| 19 |
+
|
| 20 |
+
This directory contains a local copy of [SenseVoiceSmall](https://www.modelscope.cn/iic/SenseVoiceSmall), released by the FunAudioLLM team. The model is used as a speech encoder / speech recognition component, while the original model architecture, weights, authorship, and license remain attributed to the original authors.
|
| 21 |
+
|
| 22 |
+
The original SenseVoiceSmall model is released under the `Apache-2.0` license. When using, redistributing, or citing these files, please keep the original author information, model link, and license notice.
|
| 23 |
+
|
| 24 |
+
Original links:
|
| 25 |
+
|
| 26 |
+
- ModelScope: https://www.modelscope.cn/iic/SenseVoiceSmall
|
| 27 |
+
- License: https://www.apache.org/licenses/LICENSE-2.0
|
checkpoint/sensevoice/am.mvn
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<Nnet>
|
| 2 |
+
<Splice> 560 560
|
| 3 |
+
[ 0 ]
|
| 4 |
+
<AddShift> 560 560
|
| 5 |
+
<LearnRateCoef> 0 [ -8.311879 -8.600912 -9.615928 -10.43595 -11.21292 -11.88333 -12.36243 -12.63706 -12.8818 -12.83066 -12.89103 -12.95666 -13.19763 -13.40598 -13.49113 -13.5546 -13.55639 -13.51915 -13.68284 -13.53289 -13.42107 -13.65519 -13.50713 -13.75251 -13.76715 -13.87408 -13.73109 -13.70412 -13.56073 -13.53488 -13.54895 -13.56228 -13.59408 -13.62047 -13.64198 -13.66109 -13.62669 -13.58297 -13.57387 -13.4739 -13.53063 -13.48348 -13.61047 -13.64716 -13.71546 -13.79184 -13.90614 -14.03098 -14.18205 -14.35881 -14.48419 -14.60172 -14.70591 -14.83362 -14.92122 -15.00622 -15.05122 -15.03119 -14.99028 -14.92302 -14.86927 -14.82691 -14.7972 -14.76909 -14.71356 -14.61277 -14.51696 -14.42252 -14.36405 -14.30451 -14.23161 -14.19851 -14.16633 -14.15649 -14.10504 -13.99518 -13.79562 -13.3996 -12.7767 -11.71208 -8.311879 -8.600912 -9.615928 -10.43595 -11.21292 -11.88333 -12.36243 -12.63706 -12.8818 -12.83066 -12.89103 -12.95666 -13.19763 -13.40598 -13.49113 -13.5546 -13.55639 -13.51915 -13.68284 -13.53289 -13.42107 -13.65519 -13.50713 -13.75251 -13.76715 -13.87408 -13.73109 -13.70412 -13.56073 -13.53488 -13.54895 -13.56228 -13.59408 -13.62047 -13.64198 -13.66109 -13.62669 -13.58297 -13.57387 -13.4739 -13.53063 -13.48348 -13.61047 -13.64716 -13.71546 -13.79184 -13.90614 -14.03098 -14.18205 -14.35881 -14.48419 -14.60172 -14.70591 -14.83362 -14.92122 -15.00622 -15.05122 -15.03119 -14.99028 -14.92302 -14.86927 -14.82691 -14.7972 -14.76909 -14.71356 -14.61277 -14.51696 -14.42252 -14.36405 -14.30451 -14.23161 -14.19851 -14.16633 -14.15649 -14.10504 -13.99518 -13.79562 -13.3996 -12.7767 -11.71208 -8.311879 -8.600912 -9.615928 -10.43595 -11.21292 -11.88333 -12.36243 -12.63706 -12.8818 -12.83066 -12.89103 -12.95666 -13.19763 -13.40598 -13.49113 -13.5546 -13.55639 -13.51915 -13.68284 -13.53289 -13.42107 -13.65519 -13.50713 -13.75251 -13.76715 -13.87408 -13.73109 -13.70412 -13.56073 -13.53488 -13.54895 -13.56228 -13.59408 -13.62047 -13.64198 -13.66109 -13.62669 -13.58297 -13.57387 -13.4739 -13.53063 -13.48348 -13.61047 -13.64716 -13.71546 -13.79184 -13.90614 -14.03098 -14.18205 -14.35881 -14.48419 -14.60172 -14.70591 -14.83362 -14.92122 -15.00622 -15.05122 -15.03119 -14.99028 -14.92302 -14.86927 -14.82691 -14.7972 -14.76909 -14.71356 -14.61277 -14.51696 -14.42252 -14.36405 -14.30451 -14.23161 -14.19851 -14.16633 -14.15649 -14.10504 -13.99518 -13.79562 -13.3996 -12.7767 -11.71208 -8.311879 -8.600912 -9.615928 -10.43595 -11.21292 -11.88333 -12.36243 -12.63706 -12.8818 -12.83066 -12.89103 -12.95666 -13.19763 -13.40598 -13.49113 -13.5546 -13.55639 -13.51915 -13.68284 -13.53289 -13.42107 -13.65519 -13.50713 -13.75251 -13.76715 -13.87408 -13.73109 -13.70412 -13.56073 -13.53488 -13.54895 -13.56228 -13.59408 -13.62047 -13.64198 -13.66109 -13.62669 -13.58297 -13.57387 -13.4739 -13.53063 -13.48348 -13.61047 -13.64716 -13.71546 -13.79184 -13.90614 -14.03098 -14.18205 -14.35881 -14.48419 -14.60172 -14.70591 -14.83362 -14.92122 -15.00622 -15.05122 -15.03119 -14.99028 -14.92302 -14.86927 -14.82691 -14.7972 -14.76909 -14.71356 -14.61277 -14.51696 -14.42252 -14.36405 -14.30451 -14.23161 -14.19851 -14.16633 -14.15649 -14.10504 -13.99518 -13.79562 -13.3996 -12.7767 -11.71208 -8.311879 -8.600912 -9.615928 -10.43595 -11.21292 -11.88333 -12.36243 -12.63706 -12.8818 -12.83066 -12.89103 -12.95666 -13.19763 -13.40598 -13.49113 -13.5546 -13.55639 -13.51915 -13.68284 -13.53289 -13.42107 -13.65519 -13.50713 -13.75251 -13.76715 -13.87408 -13.73109 -13.70412 -13.56073 -13.53488 -13.54895 -13.56228 -13.59408 -13.62047 -13.64198 -13.66109 -13.62669 -13.58297 -13.57387 -13.4739 -13.53063 -13.48348 -13.61047 -13.64716 -13.71546 -13.79184 -13.90614 -14.03098 -14.18205 -14.35881 -14.48419 -14.60172 -14.70591 -14.83362 -14.92122 -15.00622 -15.05122 -15.03119 -14.99028 -14.92302 -14.86927 -14.82691 -14.7972 -14.76909 -14.71356 -14.61277 -14.51696 -14.42252 -14.36405 -14.30451 -14.23161 -14.19851 -14.16633 -14.15649 -14.10504 -13.99518 -13.79562 -13.3996 -12.7767 -11.71208 -8.311879 -8.600912 -9.615928 -10.43595 -11.21292 -11.88333 -12.36243 -12.63706 -12.8818 -12.83066 -12.89103 -12.95666 -13.19763 -13.40598 -13.49113 -13.5546 -13.55639 -13.51915 -13.68284 -13.53289 -13.42107 -13.65519 -13.50713 -13.75251 -13.76715 -13.87408 -13.73109 -13.70412 -13.56073 -13.53488 -13.54895 -13.56228 -13.59408 -13.62047 -13.64198 -13.66109 -13.62669 -13.58297 -13.57387 -13.4739 -13.53063 -13.48348 -13.61047 -13.64716 -13.71546 -13.79184 -13.90614 -14.03098 -14.18205 -14.35881 -14.48419 -14.60172 -14.70591 -14.83362 -14.92122 -15.00622 -15.05122 -15.03119 -14.99028 -14.92302 -14.86927 -14.82691 -14.7972 -14.76909 -14.71356 -14.61277 -14.51696 -14.42252 -14.36405 -14.30451 -14.23161 -14.19851 -14.16633 -14.15649 -14.10504 -13.99518 -13.79562 -13.3996 -12.7767 -11.71208 -8.311879 -8.600912 -9.615928 -10.43595 -11.21292 -11.88333 -12.36243 -12.63706 -12.8818 -12.83066 -12.89103 -12.95666 -13.19763 -13.40598 -13.49113 -13.5546 -13.55639 -13.51915 -13.68284 -13.53289 -13.42107 -13.65519 -13.50713 -13.75251 -13.76715 -13.87408 -13.73109 -13.70412 -13.56073 -13.53488 -13.54895 -13.56228 -13.59408 -13.62047 -13.64198 -13.66109 -13.62669 -13.58297 -13.57387 -13.4739 -13.53063 -13.48348 -13.61047 -13.64716 -13.71546 -13.79184 -13.90614 -14.03098 -14.18205 -14.35881 -14.48419 -14.60172 -14.70591 -14.83362 -14.92122 -15.00622 -15.05122 -15.03119 -14.99028 -14.92302 -14.86927 -14.82691 -14.7972 -14.76909 -14.71356 -14.61277 -14.51696 -14.42252 -14.36405 -14.30451 -14.23161 -14.19851 -14.16633 -14.15649 -14.10504 -13.99518 -13.79562 -13.3996 -12.7767 -11.71208 ]
|
| 6 |
+
<Rescale> 560 560
|
| 7 |
+
<LearnRateCoef> 0 [ 0.155775 0.154484 0.1527379 0.1518718 0.1506028 0.1489256 0.147067 0.1447061 0.1436307 0.1443568 0.1451849 0.1455157 0.1452821 0.1445717 0.1439195 0.1435867 0.1436018 0.1438781 0.1442086 0.1448844 0.1454756 0.145663 0.146268 0.1467386 0.1472724 0.147664 0.1480913 0.1483739 0.1488841 0.1493636 0.1497088 0.1500379 0.1502916 0.1505389 0.1506787 0.1507102 0.1505992 0.1505445 0.1505938 0.1508133 0.1509569 0.1512396 0.1514625 0.1516195 0.1516156 0.1515561 0.1514966 0.1513976 0.1512612 0.151076 0.1510596 0.1510431 0.151077 0.1511168 0.1511917 0.151023 0.1508045 0.1505885 0.1503493 0.1502373 0.1501726 0.1500762 0.1500065 0.1499782 0.150057 0.1502658 0.150469 0.1505335 0.1505505 0.1505328 0.1504275 0.1502438 0.1499674 0.1497118 0.1494661 0.1493102 0.1493681 0.1495501 0.1499738 0.1509654 0.155775 0.154484 0.1527379 0.1518718 0.1506028 0.1489256 0.147067 0.1447061 0.1436307 0.1443568 0.1451849 0.1455157 0.1452821 0.1445717 0.1439195 0.1435867 0.1436018 0.1438781 0.1442086 0.1448844 0.1454756 0.145663 0.146268 0.1467386 0.1472724 0.147664 0.1480913 0.1483739 0.1488841 0.1493636 0.1497088 0.1500379 0.1502916 0.1505389 0.1506787 0.1507102 0.1505992 0.1505445 0.1505938 0.1508133 0.1509569 0.1512396 0.1514625 0.1516195 0.1516156 0.1515561 0.1514966 0.1513976 0.1512612 0.151076 0.1510596 0.1510431 0.151077 0.1511168 0.1511917 0.151023 0.1508045 0.1505885 0.1503493 0.1502373 0.1501726 0.1500762 0.1500065 0.1499782 0.150057 0.1502658 0.150469 0.1505335 0.1505505 0.1505328 0.1504275 0.1502438 0.1499674 0.1497118 0.1494661 0.1493102 0.1493681 0.1495501 0.1499738 0.1509654 0.155775 0.154484 0.1527379 0.1518718 0.1506028 0.1489256 0.147067 0.1447061 0.1436307 0.1443568 0.1451849 0.1455157 0.1452821 0.1445717 0.1439195 0.1435867 0.1436018 0.1438781 0.1442086 0.1448844 0.1454756 0.145663 0.146268 0.1467386 0.1472724 0.147664 0.1480913 0.1483739 0.1488841 0.1493636 0.1497088 0.1500379 0.1502916 0.1505389 0.1506787 0.1507102 0.1505992 0.1505445 0.1505938 0.1508133 0.1509569 0.1512396 0.1514625 0.1516195 0.1516156 0.1515561 0.1514966 0.1513976 0.1512612 0.151076 0.1510596 0.1510431 0.151077 0.1511168 0.1511917 0.151023 0.1508045 0.1505885 0.1503493 0.1502373 0.1501726 0.1500762 0.1500065 0.1499782 0.150057 0.1502658 0.150469 0.1505335 0.1505505 0.1505328 0.1504275 0.1502438 0.1499674 0.1497118 0.1494661 0.1493102 0.1493681 0.1495501 0.1499738 0.1509654 0.155775 0.154484 0.1527379 0.1518718 0.1506028 0.1489256 0.147067 0.1447061 0.1436307 0.1443568 0.1451849 0.1455157 0.1452821 0.1445717 0.1439195 0.1435867 0.1436018 0.1438781 0.1442086 0.1448844 0.1454756 0.145663 0.146268 0.1467386 0.1472724 0.147664 0.1480913 0.1483739 0.1488841 0.1493636 0.1497088 0.1500379 0.1502916 0.1505389 0.1506787 0.1507102 0.1505992 0.1505445 0.1505938 0.1508133 0.1509569 0.1512396 0.1514625 0.1516195 0.1516156 0.1515561 0.1514966 0.1513976 0.1512612 0.151076 0.1510596 0.1510431 0.151077 0.1511168 0.1511917 0.151023 0.1508045 0.1505885 0.1503493 0.1502373 0.1501726 0.1500762 0.1500065 0.1499782 0.150057 0.1502658 0.150469 0.1505335 0.1505505 0.1505328 0.1504275 0.1502438 0.1499674 0.1497118 0.1494661 0.1493102 0.1493681 0.1495501 0.1499738 0.1509654 0.155775 0.154484 0.1527379 0.1518718 0.1506028 0.1489256 0.147067 0.1447061 0.1436307 0.1443568 0.1451849 0.1455157 0.1452821 0.1445717 0.1439195 0.1435867 0.1436018 0.1438781 0.1442086 0.1448844 0.1454756 0.145663 0.146268 0.1467386 0.1472724 0.147664 0.1480913 0.1483739 0.1488841 0.1493636 0.1497088 0.1500379 0.1502916 0.1505389 0.1506787 0.1507102 0.1505992 0.1505445 0.1505938 0.1508133 0.1509569 0.1512396 0.1514625 0.1516195 0.1516156 0.1515561 0.1514966 0.1513976 0.1512612 0.151076 0.1510596 0.1510431 0.151077 0.1511168 0.1511917 0.151023 0.1508045 0.1505885 0.1503493 0.1502373 0.1501726 0.1500762 0.1500065 0.1499782 0.150057 0.1502658 0.150469 0.1505335 0.1505505 0.1505328 0.1504275 0.1502438 0.1499674 0.1497118 0.1494661 0.1493102 0.1493681 0.1495501 0.1499738 0.1509654 0.155775 0.154484 0.1527379 0.1518718 0.1506028 0.1489256 0.147067 0.1447061 0.1436307 0.1443568 0.1451849 0.1455157 0.1452821 0.1445717 0.1439195 0.1435867 0.1436018 0.1438781 0.1442086 0.1448844 0.1454756 0.145663 0.146268 0.1467386 0.1472724 0.147664 0.1480913 0.1483739 0.1488841 0.1493636 0.1497088 0.1500379 0.1502916 0.1505389 0.1506787 0.1507102 0.1505992 0.1505445 0.1505938 0.1508133 0.1509569 0.1512396 0.1514625 0.1516195 0.1516156 0.1515561 0.1514966 0.1513976 0.1512612 0.151076 0.1510596 0.1510431 0.151077 0.1511168 0.1511917 0.151023 0.1508045 0.1505885 0.1503493 0.1502373 0.1501726 0.1500762 0.1500065 0.1499782 0.150057 0.1502658 0.150469 0.1505335 0.1505505 0.1505328 0.1504275 0.1502438 0.1499674 0.1497118 0.1494661 0.1493102 0.1493681 0.1495501 0.1499738 0.1509654 0.155775 0.154484 0.1527379 0.1518718 0.1506028 0.1489256 0.147067 0.1447061 0.1436307 0.1443568 0.1451849 0.1455157 0.1452821 0.1445717 0.1439195 0.1435867 0.1436018 0.1438781 0.1442086 0.1448844 0.1454756 0.145663 0.146268 0.1467386 0.1472724 0.147664 0.1480913 0.1483739 0.1488841 0.1493636 0.1497088 0.1500379 0.1502916 0.1505389 0.1506787 0.1507102 0.1505992 0.1505445 0.1505938 0.1508133 0.1509569 0.1512396 0.1514625 0.1516195 0.1516156 0.1515561 0.1514966 0.1513976 0.1512612 0.151076 0.1510596 0.1510431 0.151077 0.1511168 0.1511917 0.151023 0.1508045 0.1505885 0.1503493 0.1502373 0.1501726 0.1500762 0.1500065 0.1499782 0.150057 0.1502658 0.150469 0.1505335 0.1505505 0.1505328 0.1504275 0.1502438 0.1499674 0.1497118 0.1494661 0.1493102 0.1493681 0.1495501 0.1499738 0.1509654 ]
|
| 8 |
+
</Nnet>
|
checkpoint/sensevoice/chn_jpn_yue_eng_ko_spectok.bpe.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aa87f86064c3730d799ddf7af3c04659151102cba548bce325cf06ba4da4e6a8
|
| 3 |
+
size 377341
|
checkpoint/sensevoice/config.yaml
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
encoder: SenseVoiceEncoderSmall
|
| 2 |
+
encoder_conf:
|
| 3 |
+
output_size: 512
|
| 4 |
+
attention_heads: 4
|
| 5 |
+
linear_units: 2048
|
| 6 |
+
num_blocks: 50
|
| 7 |
+
tp_blocks: 20
|
| 8 |
+
dropout_rate: 0.1
|
| 9 |
+
positional_dropout_rate: 0.1
|
| 10 |
+
attention_dropout_rate: 0.1
|
| 11 |
+
input_layer: pe
|
| 12 |
+
pos_enc_class: SinusoidalPositionEncoder
|
| 13 |
+
normalize_before: true
|
| 14 |
+
kernel_size: 11
|
| 15 |
+
sanm_shfit: 0
|
| 16 |
+
selfattention_layer_type: sanm
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
model: SenseVoiceSmall
|
| 20 |
+
model_conf:
|
| 21 |
+
length_normalized_loss: true
|
| 22 |
+
sos: 1
|
| 23 |
+
eos: 2
|
| 24 |
+
ignore_id: -1
|
| 25 |
+
|
| 26 |
+
tokenizer: SentencepiecesTokenizer
|
| 27 |
+
tokenizer_conf:
|
| 28 |
+
bpemodel: null
|
| 29 |
+
unk_symbol: <unk>
|
| 30 |
+
split_with_space: true
|
| 31 |
+
|
| 32 |
+
frontend: WavFrontend
|
| 33 |
+
frontend_conf:
|
| 34 |
+
fs: 16000
|
| 35 |
+
window: hamming
|
| 36 |
+
n_mels: 80
|
| 37 |
+
frame_length: 25
|
| 38 |
+
frame_shift: 10
|
| 39 |
+
lfr_m: 7
|
| 40 |
+
lfr_n: 6
|
| 41 |
+
cmvn_file: null
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
dataset: SenseVoiceCTCDataset
|
| 45 |
+
dataset_conf:
|
| 46 |
+
index_ds: IndexDSJsonl
|
| 47 |
+
batch_sampler: EspnetStyleBatchSampler
|
| 48 |
+
data_split_num: 32
|
| 49 |
+
batch_type: token
|
| 50 |
+
batch_size: 14000
|
| 51 |
+
max_token_length: 2000
|
| 52 |
+
min_token_length: 60
|
| 53 |
+
max_source_length: 2000
|
| 54 |
+
min_source_length: 60
|
| 55 |
+
max_target_length: 200
|
| 56 |
+
min_target_length: 0
|
| 57 |
+
shuffle: true
|
| 58 |
+
num_workers: 4
|
| 59 |
+
sos: ${model_conf.sos}
|
| 60 |
+
eos: ${model_conf.eos}
|
| 61 |
+
IndexDSJsonl: IndexDSJsonl
|
| 62 |
+
retry: 20
|
| 63 |
+
|
| 64 |
+
train_conf:
|
| 65 |
+
accum_grad: 1
|
| 66 |
+
grad_clip: 5
|
| 67 |
+
max_epoch: 20
|
| 68 |
+
keep_nbest_models: 10
|
| 69 |
+
avg_nbest_model: 10
|
| 70 |
+
log_interval: 100
|
| 71 |
+
resume: true
|
| 72 |
+
validate_interval: 10000
|
| 73 |
+
save_checkpoint_interval: 10000
|
| 74 |
+
|
| 75 |
+
optim: adamw
|
| 76 |
+
optim_conf:
|
| 77 |
+
lr: 0.00002
|
| 78 |
+
scheduler: warmuplr
|
| 79 |
+
scheduler_conf:
|
| 80 |
+
warmup_steps: 25000
|
| 81 |
+
|
| 82 |
+
specaug: SpecAugLFR
|
| 83 |
+
specaug_conf:
|
| 84 |
+
apply_time_warp: false
|
| 85 |
+
time_warp_window: 5
|
| 86 |
+
time_warp_mode: bicubic
|
| 87 |
+
apply_freq_mask: true
|
| 88 |
+
freq_mask_width_range:
|
| 89 |
+
- 0
|
| 90 |
+
- 30
|
| 91 |
+
lfr_rate: 6
|
| 92 |
+
num_freq_mask: 1
|
| 93 |
+
apply_time_mask: true
|
| 94 |
+
time_mask_width_range:
|
| 95 |
+
- 0
|
| 96 |
+
- 12
|
| 97 |
+
num_time_mask: 1
|
checkpoint/sensevoice/configuration.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"framework": "pytorch",
|
| 3 |
+
"task" : "auto-speech-recognition",
|
| 4 |
+
"model": {"type" : "funasr"},
|
| 5 |
+
"pipeline": {"type":"funasr-pipeline"},
|
| 6 |
+
"model_name_in_hub": {
|
| 7 |
+
"ms":"",
|
| 8 |
+
"hf":""},
|
| 9 |
+
"file_path_metas": {
|
| 10 |
+
"init_param":"model.pt",
|
| 11 |
+
"config":"config.yaml",
|
| 12 |
+
"tokenizer_conf": {"bpemodel": "chn_jpn_yue_eng_ko_spectok.bpe.model"},
|
| 13 |
+
"frontend_conf":{"cmvn_file": "am.mvn"}}
|
| 14 |
+
}
|