Video-Text-to-Text
Transformers
Safetensors
English
Chinese
qwen3_5
feature-extraction
wemm
multimodal
video
audio
quantized
fp8
custom_code
Instructions to use tencent/WeMM-Video-4B-FP8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tencent/WeMM-Video-4B-FP8 with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModel processor = AutoProcessor.from_pretrained("tencent/WeMM-Video-4B-FP8", trust_remote_code=True) model = AutoModel.from_pretrained("tencent/WeMM-Video-4B-FP8", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload WeMM-Video-4B-FP8 FP8 release
Browse files- .gitattributes +3 -0
- LICENSE +457 -0
- README.md +155 -0
- chat_template.jinja +154 -0
- config.json +1131 -0
- configuration_wemm.py +731 -0
- generation_config.json +9 -0
- h5_modeling_bert.py +1255 -0
- h5_modeling_whisper.py +1554 -0
- model.safetensors +3 -0
- modeling_wemm.py +0 -0
- official_qwen35_fp8_config.json +418 -0
- preprocessor_config.json +21 -0
- processing_wemm.py +392 -0
- processor_config.json +99 -0
- quantization_manifest.json +1121 -0
- tokenizer.json +3 -0
- tokenizer_config.json +31 -0
- video_preprocessor_config.json +21 -0
- wemm-video-architecture.png +3 -0
- wemm-video-capabilities-compact.png +3 -0
- wemm_media.py +238 -0
- wemm_video_policy.py +125 -0
- wemm_zip.py +335 -0
- wemm_zip_policy.py +37 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
wemm-video-architecture.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
wemm-video-capabilities-compact.png filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Tencent is pleased to support the open source community by making the models in WeMM-Video Collection available.
|
| 2 |
+
|
| 3 |
+
Copyright (C) 2026 Tencent. All rights reserved.
|
| 4 |
+
|
| 5 |
+
The open-source software and/or models included in this distribution may have been modified by Tencent (“Tencent Modifications”). All Tencent Modifications are Copyright (C) Tencent.
|
| 6 |
+
|
| 7 |
+
The models in the WeMM-Video Collection, as defined below, are licensed under the Apache License, Version 2.0, a copy of which is set forth below, except for the third-party components identified in the following section, which remain subject to their respective original license terms. Nothing in the Apache License, Version 2.0, is intended to impose additional restrictions on or modify the original license terms applicable to such third-party components. Users are required to comply with all applicable terms and conditions of the original licenses.
|
| 8 |
+
|
| 9 |
+
For the purposes of this document, the“WeMM-Video Collection” refers to the model repositories included in Tencent's Hugging Face Collection titled “WeMM-Video” (https://huggingface.co/collections/tencent/wemm-video) as of November 20, 2026.
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
Terms of Apache-2.0:
|
| 13 |
+
--------------------------------------------------------------------
|
| 14 |
+
Apache License
|
| 15 |
+
Version 2.0, January 2004
|
| 16 |
+
http://www.apache.org/licenses/
|
| 17 |
+
|
| 18 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 19 |
+
|
| 20 |
+
1. Definitions.
|
| 21 |
+
|
| 22 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 23 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 24 |
+
|
| 25 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 26 |
+
the copyright owner that is granting the License.
|
| 27 |
+
|
| 28 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 29 |
+
other entities that control, are controlled by, or are under common
|
| 30 |
+
control with that entity. For the purposes of this definition,
|
| 31 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 32 |
+
direction or management of such entity, whether by contract or
|
| 33 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 34 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 35 |
+
|
| 36 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 37 |
+
exercising permissions granted by this License.
|
| 38 |
+
|
| 39 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 40 |
+
including but not limited to software source code, documentation
|
| 41 |
+
source, and configuration files.
|
| 42 |
+
|
| 43 |
+
"Object" form shall mean any form resulting from mechanical
|
| 44 |
+
transformation or translation of a Source form, including but
|
| 45 |
+
not limited to compiled object code, generated documentation,
|
| 46 |
+
and conversions to other media types.
|
| 47 |
+
|
| 48 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 49 |
+
Object form, made available under the License, as indicated by a
|
| 50 |
+
copyright notice that is included in or attached to the work
|
| 51 |
+
(an example is provided in the Appendix below).
|
| 52 |
+
|
| 53 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 54 |
+
form, that is based on (or derived from) the Work and for which the
|
| 55 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 56 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 57 |
+
of this License, Derivative Works shall not include works that remain
|
| 58 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 59 |
+
the Work and Derivative Works thereof.
|
| 60 |
+
|
| 61 |
+
"Contribution" shall mean any work of authorship, including
|
| 62 |
+
the original version of the Work and any modifications or additions
|
| 63 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 64 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 65 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 66 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 67 |
+
means any form of electronic, verbal, or written communication sent
|
| 68 |
+
to the Licensor or its representatives, including but not limited to
|
| 69 |
+
communication on electronic mailing lists, source code control systems,
|
| 70 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 71 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 72 |
+
excluding communication that is conspicuously marked or otherwise
|
| 73 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 74 |
+
|
| 75 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 76 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 77 |
+
subsequently incorporated within the Work.
|
| 78 |
+
|
| 79 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 80 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 81 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 82 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 83 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 84 |
+
Work and such Derivative Works in Source or Object form.
|
| 85 |
+
|
| 86 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 87 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 88 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 89 |
+
(except as stated in this section) patent license to make, have made,
|
| 90 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 91 |
+
where such license applies only to those patent claims licensable
|
| 92 |
+
by such Contributor that are necessarily infringed by their
|
| 93 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 94 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 95 |
+
institute patent litigation against any entity (including a
|
| 96 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 97 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 98 |
+
or contributory patent infringement, then any patent licenses
|
| 99 |
+
granted to You under this License for that Work shall terminate
|
| 100 |
+
as of the date such litigation is filed.
|
| 101 |
+
|
| 102 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 103 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 104 |
+
modifications, and in Source or Object form, provided that You
|
| 105 |
+
meet the following conditions:
|
| 106 |
+
|
| 107 |
+
(a) You must give any other recipients of the Work or
|
| 108 |
+
Derivative Works a copy of this License; and
|
| 109 |
+
|
| 110 |
+
(b) You must cause any modified files to carry prominent notices
|
| 111 |
+
stating that You changed the files; and
|
| 112 |
+
|
| 113 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 114 |
+
that You distribute, all copyright, patent, trademark, and
|
| 115 |
+
attribution notices from the Source form of the Work,
|
| 116 |
+
excluding those notices that do not pertain to any part of
|
| 117 |
+
the Derivative Works; and
|
| 118 |
+
|
| 119 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 120 |
+
distribution, then any Derivative Works that You distribute must
|
| 121 |
+
include a readable copy of the attribution notices contained
|
| 122 |
+
within such NOTICE file, excluding those notices that do not
|
| 123 |
+
pertain to any part of the Derivative Works, in at least one
|
| 124 |
+
of the following places: within a NOTICE text file distributed
|
| 125 |
+
as part of the Derivative Works; within the Source form or
|
| 126 |
+
documentation, if provided along with the Derivative Works; or,
|
| 127 |
+
within a display generated by the Derivative Works, if and
|
| 128 |
+
wherever such third-party notices normally appear. The contents
|
| 129 |
+
of the NOTICE file are for informational purposes only and
|
| 130 |
+
do not modify the License. You may add Your own attribution
|
| 131 |
+
notices within Derivative Works that You distribute, alongside
|
| 132 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 133 |
+
that such additional attribution notices cannot be construed
|
| 134 |
+
as modifying the License.
|
| 135 |
+
|
| 136 |
+
You may add Your own copyright statement to Your modifications and
|
| 137 |
+
may provide additional or different license terms and conditions
|
| 138 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 139 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 140 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 141 |
+
the conditions stated in this License.
|
| 142 |
+
|
| 143 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 144 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 145 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 146 |
+
this License, without any additional terms or conditions.
|
| 147 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 148 |
+
the terms of any separate license agreement you may have executed
|
| 149 |
+
with Licensor regarding such Contributions.
|
| 150 |
+
|
| 151 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 152 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 153 |
+
except as required for reasonable and customary use in describing the
|
| 154 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 155 |
+
|
| 156 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 157 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 158 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 159 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 160 |
+
implied, including, without limitation, any warranties or conditions
|
| 161 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 162 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 163 |
+
appropriateness of using or redistributing the Work and assume any
|
| 164 |
+
risks associated with Your exercise of permissions under this License.
|
| 165 |
+
|
| 166 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 167 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 168 |
+
unless required by applicable law (such as deliberate and grossly
|
| 169 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 170 |
+
liable to You for damages, including any direct, indirect, special,
|
| 171 |
+
incidental, or consequential damages of any character arising as a
|
| 172 |
+
result of this License or out of the use or inability to use the
|
| 173 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 174 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 175 |
+
other commercial damages or losses), even if such Contributor
|
| 176 |
+
has been advised of the possibility of such damages.
|
| 177 |
+
|
| 178 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 179 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 180 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 181 |
+
or other liability obligations and/or rights consistent with this
|
| 182 |
+
License. However, in accepting such obligations, You may act only
|
| 183 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 184 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 185 |
+
defend, and hold each Contributor harmless for any liability
|
| 186 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 187 |
+
of your accepting any such warranty or additional liability.
|
| 188 |
+
|
| 189 |
+
END OF TERMS AND CONDITIONS
|
| 190 |
+
|
| 191 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 192 |
+
|
| 193 |
+
To apply the Apache License to your work, attach the following
|
| 194 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 195 |
+
replaced with your own identifying information. (Don't include
|
| 196 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 197 |
+
comment syntax for the file format. We also recommend that a
|
| 198 |
+
file or class name and description of purpose be included on the
|
| 199 |
+
same "printed page" as the copyright notice for easier
|
| 200 |
+
identification within third-party archives.
|
| 201 |
+
|
| 202 |
+
Copyright [yyyy] [name of copyright owner]
|
| 203 |
+
|
| 204 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 205 |
+
you may not use this file except in compliance with the License.
|
| 206 |
+
You may obtain a copy of the License at
|
| 207 |
+
|
| 208 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 209 |
+
|
| 210 |
+
Unless required by applicable law or agreed to in writing, software
|
| 211 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 212 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 213 |
+
See the License for the specific language governing permissions and
|
| 214 |
+
limitations under the License.
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
Dependencies and Licenses:
|
| 219 |
+
|
| 220 |
+
This project builds upon and/or incorporates the following open-source models and software components, each of which remains subject to its respective original license terms. Tencent may have made modifications to certain third-party components (“Tencent Modifications”), which are Copyright (C) Tencent.
|
| 221 |
+
|
| 222 |
+
In case you believe there have been errors in the attribution below, you may submit the concerns to us for review and correction.
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
Open Source Model Licensed under the Apache-2.0:
|
| 226 |
+
--------------------------------------------------------------------
|
| 227 |
+
1. Qwen/Qwen2.5-Omni-7B
|
| 228 |
+
Copyright 2025 Alibaba Cloud
|
| 229 |
+
Please note this model has been modified by Tencent in this distribution.
|
| 230 |
+
|
| 231 |
+
2. openai/whisper-large-v3
|
| 232 |
+
Copyright openai/whisper-large-v3 Original author and authors
|
| 233 |
+
Please note this model has been modified by Tencent in this distribution.
|
| 234 |
+
|
| 235 |
+
3. Qwen/Qwen3.6-35B-A3B
|
| 236 |
+
Copyright 2026 Alibaba Cloud
|
| 237 |
+
Please note this model has been modified by Tencent in this distribution.
|
| 238 |
+
|
| 239 |
+
4. Qwen/Qwen3.5-9B
|
| 240 |
+
Copyright 2026 Alibaba Cloud
|
| 241 |
+
Please note this model has been modified by Tencent in this distribution.
|
| 242 |
+
|
| 243 |
+
5. Qwen/Qwen3.5-4B
|
| 244 |
+
Copyright 2026 Alibaba Cloud
|
| 245 |
+
Please note this model has been modified by Tencent in this distribution.
|
| 246 |
+
|
| 247 |
+
6. Qwen/Qwen3.5-2B
|
| 248 |
+
Copyright 2026 Alibaba Cloud
|
| 249 |
+
Please note this model has been modified by Tencent in this distribution.
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
Terms of the Apache-2.0:
|
| 254 |
+
--------------------------------------------------------------------
|
| 255 |
+
Apache License
|
| 256 |
+
Version 2.0, January 2004
|
| 257 |
+
http://www.apache.org/licenses/
|
| 258 |
+
|
| 259 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 260 |
+
|
| 261 |
+
1. Definitions.
|
| 262 |
+
|
| 263 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 264 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 265 |
+
|
| 266 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 267 |
+
the copyright owner that is granting the License.
|
| 268 |
+
|
| 269 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 270 |
+
other entities that control, are controlled by, or are under common
|
| 271 |
+
control with that entity. For the purposes of this definition,
|
| 272 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 273 |
+
direction or management of such entity, whether by contract or
|
| 274 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 275 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 276 |
+
|
| 277 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 278 |
+
exercising permissions granted by this License.
|
| 279 |
+
|
| 280 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 281 |
+
including but not limited to software source code, documentation
|
| 282 |
+
source, and configuration files.
|
| 283 |
+
|
| 284 |
+
"Object" form shall mean any form resulting from mechanical
|
| 285 |
+
transformation or translation of a Source form, including but
|
| 286 |
+
not limited to compiled object code, generated documentation,
|
| 287 |
+
and conversions to other media types.
|
| 288 |
+
|
| 289 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 290 |
+
Object form, made available under the License, as indicated by a
|
| 291 |
+
copyright notice that is included in or attached to the work
|
| 292 |
+
(an example is provided in the Appendix below).
|
| 293 |
+
|
| 294 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 295 |
+
form, that is based on (or derived from) the Work and for which the
|
| 296 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 297 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 298 |
+
of this License, Derivative Works shall not include works that remain
|
| 299 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 300 |
+
the Work and Derivative Works thereof.
|
| 301 |
+
|
| 302 |
+
"Contribution" shall mean any work of authorship, including
|
| 303 |
+
the original version of the Work and any modifications or additions
|
| 304 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 305 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 306 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 307 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 308 |
+
means any form of electronic, verbal, or written communication sent
|
| 309 |
+
to the Licensor or its representatives, including but not limited to
|
| 310 |
+
communication on electronic mailing lists, source code control systems,
|
| 311 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 312 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 313 |
+
excluding communication that is conspicuously marked or otherwise
|
| 314 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 315 |
+
|
| 316 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 317 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 318 |
+
subsequently incorporated within the Work.
|
| 319 |
+
|
| 320 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 321 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 322 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 323 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 324 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 325 |
+
Work and such Derivative Works in Source or Object form.
|
| 326 |
+
|
| 327 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 328 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 329 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 330 |
+
(except as stated in this section) patent license to make, have made,
|
| 331 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 332 |
+
where such license applies only to those patent claims licensable
|
| 333 |
+
by such Contributor that are necessarily infringed by their
|
| 334 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 335 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 336 |
+
institute patent litigation against any entity (including a
|
| 337 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 338 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 339 |
+
or contributory patent infringement, then any patent licenses
|
| 340 |
+
granted to You under this License for that Work shall terminate
|
| 341 |
+
as of the date such litigation is filed.
|
| 342 |
+
|
| 343 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 344 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 345 |
+
modifications, and in Source or Object form, provided that You
|
| 346 |
+
meet the following conditions:
|
| 347 |
+
|
| 348 |
+
(a) You must give any other recipients of the Work or
|
| 349 |
+
Derivative Works a copy of this License; and
|
| 350 |
+
|
| 351 |
+
(b) You must cause any modified files to carry prominent notices
|
| 352 |
+
stating that You changed the files; and
|
| 353 |
+
|
| 354 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 355 |
+
that You distribute, all copyright, patent, trademark, and
|
| 356 |
+
attribution notices from the Source form of the Work,
|
| 357 |
+
excluding those notices that do not pertain to any part of
|
| 358 |
+
the Derivative Works; and
|
| 359 |
+
|
| 360 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 361 |
+
distribution, then any Derivative Works that You distribute must
|
| 362 |
+
include a readable copy of the attribution notices contained
|
| 363 |
+
within such NOTICE file, excluding those notices that do not
|
| 364 |
+
pertain to any part of the Derivative Works, in at least one
|
| 365 |
+
of the following places: within a NOTICE text file distributed
|
| 366 |
+
as part of the Derivative Works; within the Source form or
|
| 367 |
+
documentation, if provided along with the Derivative Works; or,
|
| 368 |
+
within a display generated by the Derivative Works, if and
|
| 369 |
+
wherever such third-party notices normally appear. The contents
|
| 370 |
+
of the NOTICE file are for informational purposes only and
|
| 371 |
+
do not modify the License. You may add Your own attribution
|
| 372 |
+
notices within Derivative Works that You distribute, alongside
|
| 373 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 374 |
+
that such additional attribution notices cannot be construed
|
| 375 |
+
as modifying the License.
|
| 376 |
+
|
| 377 |
+
You may add Your own copyright statement to Your modifications and
|
| 378 |
+
may provide additional or different license terms and conditions
|
| 379 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 380 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 381 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 382 |
+
the conditions stated in this License.
|
| 383 |
+
|
| 384 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 385 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 386 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 387 |
+
this License, without any additional terms or conditions.
|
| 388 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 389 |
+
the terms of any separate license agreement you may have executed
|
| 390 |
+
with Licensor regarding such Contributions.
|
| 391 |
+
|
| 392 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 393 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 394 |
+
except as required for reasonable and customary use in describing the
|
| 395 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 396 |
+
|
| 397 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 398 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 399 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 400 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 401 |
+
implied, including, without limitation, any warranties or conditions
|
| 402 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 403 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 404 |
+
appropriateness of using or redistributing the Work and assume any
|
| 405 |
+
risks associated with Your exercise of permissions under this License.
|
| 406 |
+
|
| 407 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 408 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 409 |
+
unless required by applicable law (such as deliberate and grossly
|
| 410 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 411 |
+
liable to You for damages, including any direct, indirect, special,
|
| 412 |
+
incidental, or consequential damages of any character arising as a
|
| 413 |
+
result of this License or out of the use or inability to use the
|
| 414 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 415 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 416 |
+
other commercial damages or losses), even if such Contributor
|
| 417 |
+
has been advised of the possibility of such damages.
|
| 418 |
+
|
| 419 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 420 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 421 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 422 |
+
or other liability obligations and/or rights consistent with this
|
| 423 |
+
License. However, in accepting such obligations, You may act only
|
| 424 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 425 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 426 |
+
defend, and hold each Contributor harmless for any liability
|
| 427 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 428 |
+
of your accepting any such warranty or additional liability.
|
| 429 |
+
|
| 430 |
+
END OF TERMS AND CONDITIONS
|
| 431 |
+
|
| 432 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 433 |
+
|
| 434 |
+
To apply the Apache License to your work, attach the following
|
| 435 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 436 |
+
replaced with your own identifying information. (Don't include
|
| 437 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 438 |
+
comment syntax for the file format. We also recommend that a
|
| 439 |
+
file or class name and description of purpose be included on the
|
| 440 |
+
same "printed page" as the copyright notice for easier
|
| 441 |
+
identification within third-party archives.
|
| 442 |
+
|
| 443 |
+
Copyright [yyyy] [name of copyright owner]
|
| 444 |
+
|
| 445 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 446 |
+
you may not use this file except in compliance with the License.
|
| 447 |
+
You may obtain a copy of the License at
|
| 448 |
+
|
| 449 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 450 |
+
|
| 451 |
+
Unless required by applicable law or agreed to in writing, software
|
| 452 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 453 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 454 |
+
See the License for the specific language governing permissions and
|
| 455 |
+
limitations under the License.
|
| 456 |
+
|
| 457 |
+
|
README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
- zh
|
| 6 |
+
pipeline_tag: image-text-to-text
|
| 7 |
+
base_model: tencent/WeMM-Video-4B
|
| 8 |
+
base_model_relation: quantized
|
| 9 |
+
tags:
|
| 10 |
+
- wemm
|
| 11 |
+
- multimodal
|
| 12 |
+
- video
|
| 13 |
+
- audio
|
| 14 |
+
- quantized
|
| 15 |
+
- fp8
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# WeMM-Video-4B · FP8 Block128
|
| 19 |
+
|
| 20 |
+
[Project](https://github.com/Tencent/WeMM-Video) · [Model Collection](https://huggingface.co/collections/tencent/wemm-video)
|
| 21 |
+
|
| 22 |
+
## Overview
|
| 23 |
+
|
| 24 |
+
This repository contains the **FP8 Block128** Safetensors variant of [WeMM-Video-4B](https://huggingface.co/tencent/WeMM-Video-4B). WeMM-Video is a Chinese–English bilingual family for joint audio-visual understanding and reasoning. It accepts text, images, audio, and video and generates text responses.
|
| 25 |
+
|
| 26 |
+
- **Weights** · 7.13 GiB of weight files
|
| 27 |
+
- **Runtime** · patched vLLM 0.18.0 on a GPU with FP8 support
|
| 28 |
+
|
| 29 |
+
### Capabilities
|
| 30 |
+
|
| 31 |
+
WeMM-Video can combine video frames with the original soundtrack to describe events, transcribe speech, and reason about what is seen and heard. It also accepts silent video, standalone audio, images, and text, with responses in Chinese or English.
|
| 32 |
+
|
| 33 |
+
<p align="center">
|
| 34 |
+
<img src="./wemm-video-capabilities-compact.png" width="90%" alt="Examples of WeMM-Video understanding and reasoning across audio-visual, audio, image, and text inputs.">
|
| 35 |
+
</p>
|
| 36 |
+
|
| 37 |
+
### Architecture and training
|
| 38 |
+
|
| 39 |
+
Vision and audio encoders turn media into tokens that the language model processes alongside text. Video frames carry timestamps. The family was pretrained on approximately 1.2 trillion multimodal tokens, then post-trained with multi-teacher OPD, anti-repetition MrDPO, and specialist reinforcement learning.
|
| 40 |
+
|
| 41 |
+
<p align="center">
|
| 42 |
+
<img src="./wemm-video-architecture.png" width="75%" alt="WeMM-Video architecture with separate vision and audio encoders feeding media tokens to the language model.">
|
| 43 |
+
</p>
|
| 44 |
+
|
| 45 |
+
See the [project overview](https://github.com/Tencent/WeMM-Video#overview) for family details.
|
| 46 |
+
|
| 47 |
+
## Quantization
|
| 48 |
+
|
| 49 |
+
Selected language linear weights use E4M3FN FP8 in 128 × 128 blocks with dynamic per-token activation scaling in groups of 128. The media encoders and protected language tensors retain their source precision. See the [quantization manifest](quantization_manifest.json) for tensor scope and export checks.
|
| 50 |
+
|
| 51 |
+
## Direct loading with Transformers
|
| 52 |
+
|
| 53 |
+
Use the [Transformers environment](https://github.com/Tencent/WeMM-Video#install-dependencies). The local release checkpoint passed full weight loading and generation on one NVIDIA L20 with Transformers 5.2.0 and PyTorch 2.10.0+cu129. Generation checks covered text, image, audio, video frames, and video with its soundtrack. The same loader accepts the model's Hub ID. The validation used local checkpoint files.
|
| 54 |
+
|
| 55 |
+
The loaded model retains FP8 weights in the quantized layers.
|
| 56 |
+
|
| 57 |
+
```python
|
| 58 |
+
import torch
|
| 59 |
+
from transformers import AutoModelForImageTextToText, AutoProcessor
|
| 60 |
+
|
| 61 |
+
model_id = "tencent/WeMM-Video-4B-FP8"
|
| 62 |
+
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
| 63 |
+
model = AutoModelForImageTextToText.from_pretrained(
|
| 64 |
+
model_id, trust_remote_code=True, dtype=torch.bfloat16,
|
| 65 |
+
device_map="cuda:0",
|
| 66 |
+
).eval()
|
| 67 |
+
|
| 68 |
+
messages = [{"role": "user", "content": [
|
| 69 |
+
{"type": "text", "text": "What is 2 + 2? Reply with the number only."},
|
| 70 |
+
]}]
|
| 71 |
+
inputs = processor.apply_chat_template(
|
| 72 |
+
messages, tokenize=True, return_dict=True, return_tensors="pt",
|
| 73 |
+
add_generation_prompt=True, enable_thinking=False,
|
| 74 |
+
).to(device=model.get_input_embeddings().weight.device, dtype=torch.bfloat16)
|
| 75 |
+
with torch.inference_mode():
|
| 76 |
+
output = model.generate(**inputs, do_sample=False, max_new_tokens=32)
|
| 77 |
+
print(processor.tokenizer.decode(output[0, inputs.input_ids.shape[1]:], skip_special_tokens=True))
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### Transformers input types
|
| 81 |
+
|
| 82 |
+
For a media request, place the media item before the text item in `messages[0]["content"]` and run the same preprocessing and generation.
|
| 83 |
+
|
| 84 |
+
| Input | Example content item |
|
| 85 |
+
| --- | --- |
|
| 86 |
+
| Text | `{"type": "text", "text": "Describe what you see."}` |
|
| 87 |
+
| Image | `{"type": "image", "image": "image.jpg"}` |
|
| 88 |
+
| Audio | `{"type": "audio", "audio": "speech.wav"}` |
|
| 89 |
+
| Video frames | `{"type": "video", "video": "clip.mp4"}` |
|
| 90 |
+
| Video with soundtrack | `{"type": "video_audio", "video": "clip.mp4"}` |
|
| 91 |
+
|
| 92 |
+
See the [Transformers examples](https://github.com/Tencent/WeMM-Video#load-from-hugging-face-with-transformers) for media decoding dependencies and sampling options.
|
| 93 |
+
|
| 94 |
+
## Serving
|
| 95 |
+
|
| 96 |
+
Install the [matching WeMM runtime patch](https://github.com/Tencent/WeMM-Video/blob/main/patch/README.md#manual-install-and-patch). The [serving guide](https://github.com/Tencent/WeMM-Video/blob/main/docs/serving.md#runtime-profiles) lists the dependency profiles and Docker images. Choose one server below.
|
| 97 |
+
|
| 98 |
+
### vLLM
|
| 99 |
+
|
| 100 |
+
Use patched vLLM 0.18.0 on a GPU with FP8 support. See the [vLLM recipe](https://github.com/Tencent/WeMM-Video/blob/main/docs/serving.md#serve-with-vllm) for setup details.
|
| 101 |
+
|
| 102 |
+
```bash
|
| 103 |
+
MODEL=tencent/WeMM-Video-4B-FP8
|
| 104 |
+
vllm serve "$MODEL" --served-model-name "$MODEL" --trust-remote-code --dtype bfloat16 \
|
| 105 |
+
--host 127.0.0.1 --port 8000 --max-model-len 8192 \
|
| 106 |
+
--no-enable-prefix-caching --mamba-ssm-cache-dtype float32 \
|
| 107 |
+
--limit-mm-per-prompt '{"image":4,"video":2,"audio":2}' \
|
| 108 |
+
--media-io-kwargs '{"video":{"fps":2,"min_frames":4,"max_frames":16,"total_pixels":262144}}'
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
### Input examples for the serving API
|
| 112 |
+
|
| 113 |
+
With the server running on port 8000, use the bundled request client from the project root in a second terminal. It sends media inline to the OpenAI-compatible chat endpoint.
|
| 114 |
+
|
| 115 |
+
```bash
|
| 116 |
+
MODEL=tencent/WeMM-Video-4B-FP8
|
| 117 |
+
python examples/chat.py text --model "$MODEL"
|
| 118 |
+
python examples/chat.py image --model "$MODEL"
|
| 119 |
+
python examples/chat.py audio --model "$MODEL"
|
| 120 |
+
python examples/chat.py video --model "$MODEL"
|
| 121 |
+
python examples/chat.py video-audio --model "$MODEL"
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
| Input | Request content |
|
| 125 |
+
| --- | --- |
|
| 126 |
+
| Text | Text string in `messages[].content` |
|
| 127 |
+
| Image | `image_url` with `image_url.url` |
|
| 128 |
+
| Audio | `audio_url` with `audio_url.url` |
|
| 129 |
+
| Video frames | `video_url` with `video_url.use_audio` set to `false` |
|
| 130 |
+
| Video with soundtrack | `video_url` with `video_url.use_audio` set to `true` |
|
| 131 |
+
|
| 132 |
+
Set `fps` and `max_frames` inside `video_url` to control sampling for a clip. Set `chat_template_kwargs.enable_thinking` to `true` for Thinking mode. See the [complete video request](https://github.com/Tencent/WeMM-Video/blob/main/docs/serving.md#send-a-video-request).
|
| 133 |
+
|
| 134 |
+
## Chat Modes
|
| 135 |
+
|
| 136 |
+
The checkpoint template defaults to Instruct. Set `enable_thinking=True` through the runtime's chat-template options to use Thinking mode. Use the media processor and chat template shipped with this checkpoint.
|
| 137 |
+
|
| 138 |
+
## Validation
|
| 139 |
+
|
| 140 |
+
Patched vLLM loaded the checkpoint on L20 and completed generation checks for text, image, audio, and video with a soundtrack. The runtime precision audit confirmed the W8A8 path.
|
| 141 |
+
|
| 142 |
+
## License
|
| 143 |
+
|
| 144 |
+
Apache License 2.0. See the [included license](LICENSE) and the [collection license and third-party attribution](https://github.com/Tencent/WeMM-Video/blob/main/LICENSE). Third-party components remain subject to their original terms.
|
| 145 |
+
|
| 146 |
+
## Citation
|
| 147 |
+
|
| 148 |
+
```bibtex
|
| 149 |
+
@misc{wemmvideo2026,
|
| 150 |
+
author = {{Tencent}},
|
| 151 |
+
title = {{WeMM-Video}},
|
| 152 |
+
year = {2026},
|
| 153 |
+
url = {https://github.com/Tencent/WeMM-Video}
|
| 154 |
+
}
|
| 155 |
+
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|
| 3 |
+
{%- macro render_content(content, do_vision_count, is_system_content=false) %}
|
| 4 |
+
{%- if content is string %}
|
| 5 |
+
{{- content }}
|
| 6 |
+
{%- elif content is iterable and content is not mapping %}
|
| 7 |
+
{%- for item in content %}
|
| 8 |
+
{%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
|
| 9 |
+
{%- if is_system_content %}
|
| 10 |
+
{{- raise_exception('System message cannot contain images.') }}
|
| 11 |
+
{%- endif %}
|
| 12 |
+
{%- if do_vision_count %}
|
| 13 |
+
{%- set image_count.value = image_count.value + 1 %}
|
| 14 |
+
{%- endif %}
|
| 15 |
+
{%- if add_vision_id %}
|
| 16 |
+
{{- 'Picture ' ~ image_count.value ~ ': ' }}
|
| 17 |
+
{%- endif %}
|
| 18 |
+
{{- '<|vision_start|><|image_pad|><|vision_end|>' }}
|
| 19 |
+
{%- elif 'video' in item or item.type == 'video' %}
|
| 20 |
+
{%- if is_system_content %}
|
| 21 |
+
{{- raise_exception('System message cannot contain videos.') }}
|
| 22 |
+
{%- endif %}
|
| 23 |
+
{%- if do_vision_count %}
|
| 24 |
+
{%- set video_count.value = video_count.value + 1 %}
|
| 25 |
+
{%- endif %}
|
| 26 |
+
{%- if add_vision_id %}
|
| 27 |
+
{{- 'Video ' ~ video_count.value ~ ': ' }}
|
| 28 |
+
{%- endif %}
|
| 29 |
+
{{- '<|vision_start|><|video_pad|><|vision_end|>' }}
|
| 30 |
+
{%- elif 'text' in item %}
|
| 31 |
+
{{- item.text }}
|
| 32 |
+
{%- else %}
|
| 33 |
+
{{- raise_exception('Unexpected item type in content.') }}
|
| 34 |
+
{%- endif %}
|
| 35 |
+
{%- endfor %}
|
| 36 |
+
{%- elif content is none or content is undefined %}
|
| 37 |
+
{{- '' }}
|
| 38 |
+
{%- else %}
|
| 39 |
+
{{- raise_exception('Unexpected content type.') }}
|
| 40 |
+
{%- endif %}
|
| 41 |
+
{%- endmacro %}
|
| 42 |
+
{%- if not messages %}
|
| 43 |
+
{{- raise_exception('No messages provided.') }}
|
| 44 |
+
{%- endif %}
|
| 45 |
+
{%- if tools and tools is iterable and tools is not mapping %}
|
| 46 |
+
{{- '<|im_start|>system\n' }}
|
| 47 |
+
{{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
|
| 48 |
+
{%- for tool in tools %}
|
| 49 |
+
{{- "\n" }}
|
| 50 |
+
{{- tool | tojson }}
|
| 51 |
+
{%- endfor %}
|
| 52 |
+
{{- "\n</tools>" }}
|
| 53 |
+
{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
|
| 54 |
+
{%- if messages[0].role == 'system' %}
|
| 55 |
+
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 56 |
+
{%- if content %}
|
| 57 |
+
{{- '\n\n' + content }}
|
| 58 |
+
{%- endif %}
|
| 59 |
+
{%- endif %}
|
| 60 |
+
{{- '<|im_end|>\n' }}
|
| 61 |
+
{%- else %}
|
| 62 |
+
{%- if messages[0].role == 'system' %}
|
| 63 |
+
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 64 |
+
{{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
|
| 65 |
+
{%- endif %}
|
| 66 |
+
{%- endif %}
|
| 67 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 68 |
+
{%- for message in messages[::-1] %}
|
| 69 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 70 |
+
{%- if ns.multi_step_tool and message.role == "user" %}
|
| 71 |
+
{%- set content = render_content(message.content, false)|trim %}
|
| 72 |
+
{%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
|
| 73 |
+
{%- set ns.multi_step_tool = false %}
|
| 74 |
+
{%- set ns.last_query_index = index %}
|
| 75 |
+
{%- endif %}
|
| 76 |
+
{%- endif %}
|
| 77 |
+
{%- endfor %}
|
| 78 |
+
{%- if ns.multi_step_tool %}
|
| 79 |
+
{{- raise_exception('No user query found in messages.') }}
|
| 80 |
+
{%- endif %}
|
| 81 |
+
{%- for message in messages %}
|
| 82 |
+
{%- set content = render_content(message.content, true)|trim %}
|
| 83 |
+
{%- if message.role == "system" %}
|
| 84 |
+
{%- if not loop.first %}
|
| 85 |
+
{{- raise_exception('System message must be at the beginning.') }}
|
| 86 |
+
{%- endif %}
|
| 87 |
+
{%- elif message.role == "user" %}
|
| 88 |
+
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
|
| 89 |
+
{%- elif message.role == "assistant" %}
|
| 90 |
+
{%- set reasoning_content = '' %}
|
| 91 |
+
{%- if message.reasoning_content is string %}
|
| 92 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 93 |
+
{%- else %}
|
| 94 |
+
{%- if '</think>' in content %}
|
| 95 |
+
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 96 |
+
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 97 |
+
{%- endif %}
|
| 98 |
+
{%- endif %}
|
| 99 |
+
{%- set reasoning_content = reasoning_content|trim %}
|
| 100 |
+
{%- if loop.index0 > ns.last_query_index %}
|
| 101 |
+
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
|
| 102 |
+
{%- else %}
|
| 103 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 104 |
+
{%- endif %}
|
| 105 |
+
{%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
|
| 106 |
+
{%- for tool_call in message.tool_calls %}
|
| 107 |
+
{%- if tool_call.function is defined %}
|
| 108 |
+
{%- set tool_call = tool_call.function %}
|
| 109 |
+
{%- endif %}
|
| 110 |
+
{%- if loop.first %}
|
| 111 |
+
{%- if content|trim %}
|
| 112 |
+
{{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 113 |
+
{%- else %}
|
| 114 |
+
{{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 115 |
+
{%- endif %}
|
| 116 |
+
{%- else %}
|
| 117 |
+
{{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 118 |
+
{%- endif %}
|
| 119 |
+
{%- if tool_call.arguments is defined %}
|
| 120 |
+
{%- for args_name, args_value in tool_call.arguments|items %}
|
| 121 |
+
{{- '<parameter=' + args_name + '>\n' }}
|
| 122 |
+
{%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
|
| 123 |
+
{{- args_value }}
|
| 124 |
+
{{- '\n</parameter>\n' }}
|
| 125 |
+
{%- endfor %}
|
| 126 |
+
{%- endif %}
|
| 127 |
+
{{- '</function>\n</tool_call>' }}
|
| 128 |
+
{%- endfor %}
|
| 129 |
+
{%- endif %}
|
| 130 |
+
{{- '<|im_end|>\n' }}
|
| 131 |
+
{%- elif message.role == "tool" %}
|
| 132 |
+
{%- if loop.previtem and loop.previtem.role != "tool" %}
|
| 133 |
+
{{- '<|im_start|>user' }}
|
| 134 |
+
{%- endif %}
|
| 135 |
+
{{- '\n<tool_response>\n' }}
|
| 136 |
+
{{- content }}
|
| 137 |
+
{{- '\n</tool_response>' }}
|
| 138 |
+
{%- if not loop.last and loop.nextitem.role != "tool" %}
|
| 139 |
+
{{- '<|im_end|>\n' }}
|
| 140 |
+
{%- elif loop.last %}
|
| 141 |
+
{{- '<|im_end|>\n' }}
|
| 142 |
+
{%- endif %}
|
| 143 |
+
{%- else %}
|
| 144 |
+
{{- raise_exception('Unexpected message role.') }}
|
| 145 |
+
{%- endif %}
|
| 146 |
+
{%- endfor %}
|
| 147 |
+
{%- if add_generation_prompt %}
|
| 148 |
+
{{- '<|im_start|>assistant\n' }}
|
| 149 |
+
{%- if enable_thinking is defined and enable_thinking is true %}
|
| 150 |
+
{{- '<think>\n' }}
|
| 151 |
+
{%- else %}
|
| 152 |
+
{{- '<think>\n\n</think>\n\n' }}
|
| 153 |
+
{%- endif %}
|
| 154 |
+
{%- endif %}
|
config.json
ADDED
|
@@ -0,0 +1,1131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
"audio_config": {
|
| 6 |
+
"attn_implementation": "flash_attention_2",
|
| 7 |
+
"activation_dropout": 0.0,
|
| 8 |
+
"activation_function": "gelu",
|
| 9 |
+
"apply_spec_augment": false,
|
| 10 |
+
"attention_dropout": 0.0,
|
| 11 |
+
"bos_token_id": 50257,
|
| 12 |
+
"classifier_proj_size": 256,
|
| 13 |
+
"d_model": 1280,
|
| 14 |
+
"decoder_attention_heads": 20,
|
| 15 |
+
"decoder_ffn_dim": 5120,
|
| 16 |
+
"decoder_layerdrop": 0.0,
|
| 17 |
+
"decoder_layers": 32,
|
| 18 |
+
"decoder_start_token_id": 50258,
|
| 19 |
+
"dropout": 0.0,
|
| 20 |
+
"dtype": "bfloat16",
|
| 21 |
+
"encoder_attention_heads": 20,
|
| 22 |
+
"encoder_ffn_dim": 5120,
|
| 23 |
+
"encoder_layerdrop": 0.0,
|
| 24 |
+
"encoder_layers": 32,
|
| 25 |
+
"eos_token_id": 50257,
|
| 26 |
+
"init_std": 0.02,
|
| 27 |
+
"mask_feature_length": 10,
|
| 28 |
+
"mask_feature_min_masks": 0,
|
| 29 |
+
"mask_feature_prob": 0.0,
|
| 30 |
+
"mask_time_length": 10,
|
| 31 |
+
"mask_time_min_masks": 2,
|
| 32 |
+
"mask_time_prob": 0.05,
|
| 33 |
+
"max_source_positions": 1500,
|
| 34 |
+
"max_target_positions": 448,
|
| 35 |
+
"median_filter_width": 7,
|
| 36 |
+
"model_type": "whisper",
|
| 37 |
+
"num_hidden_layers": 32,
|
| 38 |
+
"num_mel_bins": 128,
|
| 39 |
+
"pad_token_id": 50256,
|
| 40 |
+
"qformer_config": {
|
| 41 |
+
"add_cross_attention": true,
|
| 42 |
+
"architectures": null,
|
| 43 |
+
"attention_probs_dropout_prob": 0.1,
|
| 44 |
+
"chunk_size_feed_forward": 0,
|
| 45 |
+
"classifier_dropout": null,
|
| 46 |
+
"cross_attention_freq": 1,
|
| 47 |
+
"dtype": null,
|
| 48 |
+
"encoder_width": 1280,
|
| 49 |
+
"hidden_act": "gelu",
|
| 50 |
+
"hidden_dropout_prob": 0.1,
|
| 51 |
+
"hidden_size": 4104,
|
| 52 |
+
"id2label": {
|
| 53 |
+
"0": "LABEL_0",
|
| 54 |
+
"1": "LABEL_1"
|
| 55 |
+
},
|
| 56 |
+
"initializer_range": 0.02,
|
| 57 |
+
"intermediate_size": 12288,
|
| 58 |
+
"is_encoder_decoder": false,
|
| 59 |
+
"label2id": {
|
| 60 |
+
"LABEL_0": 0,
|
| 61 |
+
"LABEL_1": 1
|
| 62 |
+
},
|
| 63 |
+
"layer_norm_eps": 1e-12,
|
| 64 |
+
"max_position_embeddings": 512,
|
| 65 |
+
"model_type": "bert",
|
| 66 |
+
"num_attention_heads": 12,
|
| 67 |
+
"num_hidden_layers": 2,
|
| 68 |
+
"out_hidden_size": 2560,
|
| 69 |
+
"output_attentions": false,
|
| 70 |
+
"output_hidden_states": false,
|
| 71 |
+
"pad_token_id": 0,
|
| 72 |
+
"position_embedding_type": "absolute",
|
| 73 |
+
"problem_type": null,
|
| 74 |
+
"query_length": 1,
|
| 75 |
+
"return_dict": true,
|
| 76 |
+
"type_vocab_size": 2,
|
| 77 |
+
"use_cache": true,
|
| 78 |
+
"vocab_size": 30522
|
| 79 |
+
},
|
| 80 |
+
"scale_embedding": false,
|
| 81 |
+
"second_per_window": 0.1,
|
| 82 |
+
"second_stride": 0.1,
|
| 83 |
+
"tie_word_embeddings": true,
|
| 84 |
+
"use_cache": true,
|
| 85 |
+
"use_weighted_layer_sum": false,
|
| 86 |
+
"vocab_size": 51866
|
| 87 |
+
},
|
| 88 |
+
"audio_token_id": 248076,
|
| 89 |
+
"dtype": "bfloat16",
|
| 90 |
+
"image_token_id": 248056,
|
| 91 |
+
"model_type": "qwen3_5",
|
| 92 |
+
"text_config": {
|
| 93 |
+
"attention_bias": false,
|
| 94 |
+
"attention_dropout": 0.0,
|
| 95 |
+
"attn_output_gate": true,
|
| 96 |
+
"bos_token_id": null,
|
| 97 |
+
"dtype": "bfloat16",
|
| 98 |
+
"eos_token_id": 248044,
|
| 99 |
+
"full_attention_interval": 4,
|
| 100 |
+
"head_dim": 256,
|
| 101 |
+
"hidden_act": "silu",
|
| 102 |
+
"hidden_size": 2560,
|
| 103 |
+
"initializer_range": 0.02,
|
| 104 |
+
"intermediate_size": 9216,
|
| 105 |
+
"layer_types": [
|
| 106 |
+
"linear_attention",
|
| 107 |
+
"linear_attention",
|
| 108 |
+
"linear_attention",
|
| 109 |
+
"full_attention",
|
| 110 |
+
"linear_attention",
|
| 111 |
+
"linear_attention",
|
| 112 |
+
"linear_attention",
|
| 113 |
+
"full_attention",
|
| 114 |
+
"linear_attention",
|
| 115 |
+
"linear_attention",
|
| 116 |
+
"linear_attention",
|
| 117 |
+
"full_attention",
|
| 118 |
+
"linear_attention",
|
| 119 |
+
"linear_attention",
|
| 120 |
+
"linear_attention",
|
| 121 |
+
"full_attention",
|
| 122 |
+
"linear_attention",
|
| 123 |
+
"linear_attention",
|
| 124 |
+
"linear_attention",
|
| 125 |
+
"full_attention",
|
| 126 |
+
"linear_attention",
|
| 127 |
+
"linear_attention",
|
| 128 |
+
"linear_attention",
|
| 129 |
+
"full_attention",
|
| 130 |
+
"linear_attention",
|
| 131 |
+
"linear_attention",
|
| 132 |
+
"linear_attention",
|
| 133 |
+
"full_attention",
|
| 134 |
+
"linear_attention",
|
| 135 |
+
"linear_attention",
|
| 136 |
+
"linear_attention",
|
| 137 |
+
"full_attention"
|
| 138 |
+
],
|
| 139 |
+
"linear_conv_kernel_dim": 4,
|
| 140 |
+
"linear_key_head_dim": 128,
|
| 141 |
+
"linear_num_key_heads": 16,
|
| 142 |
+
"linear_num_value_heads": 32,
|
| 143 |
+
"linear_value_head_dim": 128,
|
| 144 |
+
"mamba_ssm_dtype": "float32",
|
| 145 |
+
"max_position_embeddings": 262144,
|
| 146 |
+
"mlp_only_layers": [],
|
| 147 |
+
"model_type": "qwen3_5_text",
|
| 148 |
+
"mtp_num_hidden_layers": 1,
|
| 149 |
+
"mtp_use_dedicated_embeddings": false,
|
| 150 |
+
"num_attention_heads": 16,
|
| 151 |
+
"num_hidden_layers": 32,
|
| 152 |
+
"num_key_value_heads": 4,
|
| 153 |
+
"pad_token_id": null,
|
| 154 |
+
"partial_rotary_factor": 0.25,
|
| 155 |
+
"rms_norm_eps": 1e-06,
|
| 156 |
+
"rope_parameters": {
|
| 157 |
+
"mrope_interleaved": true,
|
| 158 |
+
"mrope_section": [
|
| 159 |
+
11,
|
| 160 |
+
11,
|
| 161 |
+
10
|
| 162 |
+
],
|
| 163 |
+
"partial_rotary_factor": 0.25,
|
| 164 |
+
"rope_theta": 10000000,
|
| 165 |
+
"rope_type": "default"
|
| 166 |
+
},
|
| 167 |
+
"tie_word_embeddings": true,
|
| 168 |
+
"use_cache": true,
|
| 169 |
+
"vocab_size": 248320
|
| 170 |
+
},
|
| 171 |
+
"tie_word_embeddings": true,
|
| 172 |
+
"transformers_version": "5.2.0",
|
| 173 |
+
"video_token_id": 248057,
|
| 174 |
+
"vision_config": {
|
| 175 |
+
"deepstack_visual_indexes": [],
|
| 176 |
+
"depth": 24,
|
| 177 |
+
"dtype": "bfloat16",
|
| 178 |
+
"hidden_act": "gelu_pytorch_tanh",
|
| 179 |
+
"hidden_size": 1024,
|
| 180 |
+
"in_channels": 3,
|
| 181 |
+
"initializer_range": 0.02,
|
| 182 |
+
"intermediate_size": 4096,
|
| 183 |
+
"model_type": "qwen3_5",
|
| 184 |
+
"num_heads": 16,
|
| 185 |
+
"num_position_embeddings": 2304,
|
| 186 |
+
"out_hidden_size": 2560,
|
| 187 |
+
"patch_size": 16,
|
| 188 |
+
"spatial_merge_size": 2,
|
| 189 |
+
"temporal_patch_size": 2
|
| 190 |
+
},
|
| 191 |
+
"vision_end_token_id": 248054,
|
| 192 |
+
"vision_start_token_id": 248053,
|
| 193 |
+
"auto_map": {
|
| 194 |
+
"AutoConfig": "configuration_wemm.WeMMQwen3_5Config",
|
| 195 |
+
"AutoModel": "modeling_wemm.WeMMVideoForConditionalGeneration",
|
| 196 |
+
"AutoModelForImageTextToText": "modeling_wemm.WeMMVideoForConditionalGeneration",
|
| 197 |
+
"AutoProcessor": "processing_wemm.WeMMProcessor"
|
| 198 |
+
},
|
| 199 |
+
"quantization_config": {
|
| 200 |
+
"quant_method": "fp8",
|
| 201 |
+
"activation_scheme": "dynamic",
|
| 202 |
+
"weight_per_tensor": false,
|
| 203 |
+
"act_per_tensor": false,
|
| 204 |
+
"weight_block_size": [
|
| 205 |
+
128,
|
| 206 |
+
128
|
| 207 |
+
],
|
| 208 |
+
"modules_to_not_convert": [
|
| 209 |
+
"lm_head",
|
| 210 |
+
"model.audio",
|
| 211 |
+
"model.audio.audio_proj",
|
| 212 |
+
"model.audio.audio_proj.bias",
|
| 213 |
+
"model.audio.conv1",
|
| 214 |
+
"model.audio.conv1.bias",
|
| 215 |
+
"model.audio.conv2",
|
| 216 |
+
"model.audio.conv2.bias",
|
| 217 |
+
"model.audio.embed_positions",
|
| 218 |
+
"model.audio.layer_norm",
|
| 219 |
+
"model.audio.layer_norm.bias",
|
| 220 |
+
"model.audio.layers.0.fc1",
|
| 221 |
+
"model.audio.layers.0.fc1.bias",
|
| 222 |
+
"model.audio.layers.0.fc2",
|
| 223 |
+
"model.audio.layers.0.fc2.bias",
|
| 224 |
+
"model.audio.layers.0.final_layer_norm",
|
| 225 |
+
"model.audio.layers.0.final_layer_norm.bias",
|
| 226 |
+
"model.audio.layers.0.self_attn.k_proj",
|
| 227 |
+
"model.audio.layers.0.self_attn.out_proj",
|
| 228 |
+
"model.audio.layers.0.self_attn.out_proj.bias",
|
| 229 |
+
"model.audio.layers.0.self_attn.q_proj",
|
| 230 |
+
"model.audio.layers.0.self_attn.q_proj.bias",
|
| 231 |
+
"model.audio.layers.0.self_attn.v_proj",
|
| 232 |
+
"model.audio.layers.0.self_attn.v_proj.bias",
|
| 233 |
+
"model.audio.layers.0.self_attn_layer_norm",
|
| 234 |
+
"model.audio.layers.0.self_attn_layer_norm.bias",
|
| 235 |
+
"model.audio.layers.1.fc1",
|
| 236 |
+
"model.audio.layers.1.fc1.bias",
|
| 237 |
+
"model.audio.layers.1.fc2",
|
| 238 |
+
"model.audio.layers.1.fc2.bias",
|
| 239 |
+
"model.audio.layers.1.final_layer_norm",
|
| 240 |
+
"model.audio.layers.1.final_layer_norm.bias",
|
| 241 |
+
"model.audio.layers.1.self_attn.k_proj",
|
| 242 |
+
"model.audio.layers.1.self_attn.out_proj",
|
| 243 |
+
"model.audio.layers.1.self_attn.out_proj.bias",
|
| 244 |
+
"model.audio.layers.1.self_attn.q_proj",
|
| 245 |
+
"model.audio.layers.1.self_attn.q_proj.bias",
|
| 246 |
+
"model.audio.layers.1.self_attn.v_proj",
|
| 247 |
+
"model.audio.layers.1.self_attn.v_proj.bias",
|
| 248 |
+
"model.audio.layers.1.self_attn_layer_norm",
|
| 249 |
+
"model.audio.layers.1.self_attn_layer_norm.bias",
|
| 250 |
+
"model.audio.layers.10.fc1",
|
| 251 |
+
"model.audio.layers.10.fc1.bias",
|
| 252 |
+
"model.audio.layers.10.fc2",
|
| 253 |
+
"model.audio.layers.10.fc2.bias",
|
| 254 |
+
"model.audio.layers.10.final_layer_norm",
|
| 255 |
+
"model.audio.layers.10.final_layer_norm.bias",
|
| 256 |
+
"model.audio.layers.10.self_attn.k_proj",
|
| 257 |
+
"model.audio.layers.10.self_attn.out_proj",
|
| 258 |
+
"model.audio.layers.10.self_attn.out_proj.bias",
|
| 259 |
+
"model.audio.layers.10.self_attn.q_proj",
|
| 260 |
+
"model.audio.layers.10.self_attn.q_proj.bias",
|
| 261 |
+
"model.audio.layers.10.self_attn.v_proj",
|
| 262 |
+
"model.audio.layers.10.self_attn.v_proj.bias",
|
| 263 |
+
"model.audio.layers.10.self_attn_layer_norm",
|
| 264 |
+
"model.audio.layers.10.self_attn_layer_norm.bias",
|
| 265 |
+
"model.audio.layers.11.fc1",
|
| 266 |
+
"model.audio.layers.11.fc1.bias",
|
| 267 |
+
"model.audio.layers.11.fc2",
|
| 268 |
+
"model.audio.layers.11.fc2.bias",
|
| 269 |
+
"model.audio.layers.11.final_layer_norm",
|
| 270 |
+
"model.audio.layers.11.final_layer_norm.bias",
|
| 271 |
+
"model.audio.layers.11.self_attn.k_proj",
|
| 272 |
+
"model.audio.layers.11.self_attn.out_proj",
|
| 273 |
+
"model.audio.layers.11.self_attn.out_proj.bias",
|
| 274 |
+
"model.audio.layers.11.self_attn.q_proj",
|
| 275 |
+
"model.audio.layers.11.self_attn.q_proj.bias",
|
| 276 |
+
"model.audio.layers.11.self_attn.v_proj",
|
| 277 |
+
"model.audio.layers.11.self_attn.v_proj.bias",
|
| 278 |
+
"model.audio.layers.11.self_attn_layer_norm",
|
| 279 |
+
"model.audio.layers.11.self_attn_layer_norm.bias",
|
| 280 |
+
"model.audio.layers.12.fc1",
|
| 281 |
+
"model.audio.layers.12.fc1.bias",
|
| 282 |
+
"model.audio.layers.12.fc2",
|
| 283 |
+
"model.audio.layers.12.fc2.bias",
|
| 284 |
+
"model.audio.layers.12.final_layer_norm",
|
| 285 |
+
"model.audio.layers.12.final_layer_norm.bias",
|
| 286 |
+
"model.audio.layers.12.self_attn.k_proj",
|
| 287 |
+
"model.audio.layers.12.self_attn.out_proj",
|
| 288 |
+
"model.audio.layers.12.self_attn.out_proj.bias",
|
| 289 |
+
"model.audio.layers.12.self_attn.q_proj",
|
| 290 |
+
"model.audio.layers.12.self_attn.q_proj.bias",
|
| 291 |
+
"model.audio.layers.12.self_attn.v_proj",
|
| 292 |
+
"model.audio.layers.12.self_attn.v_proj.bias",
|
| 293 |
+
"model.audio.layers.12.self_attn_layer_norm",
|
| 294 |
+
"model.audio.layers.12.self_attn_layer_norm.bias",
|
| 295 |
+
"model.audio.layers.13.fc1",
|
| 296 |
+
"model.audio.layers.13.fc1.bias",
|
| 297 |
+
"model.audio.layers.13.fc2",
|
| 298 |
+
"model.audio.layers.13.fc2.bias",
|
| 299 |
+
"model.audio.layers.13.final_layer_norm",
|
| 300 |
+
"model.audio.layers.13.final_layer_norm.bias",
|
| 301 |
+
"model.audio.layers.13.self_attn.k_proj",
|
| 302 |
+
"model.audio.layers.13.self_attn.out_proj",
|
| 303 |
+
"model.audio.layers.13.self_attn.out_proj.bias",
|
| 304 |
+
"model.audio.layers.13.self_attn.q_proj",
|
| 305 |
+
"model.audio.layers.13.self_attn.q_proj.bias",
|
| 306 |
+
"model.audio.layers.13.self_attn.v_proj",
|
| 307 |
+
"model.audio.layers.13.self_attn.v_proj.bias",
|
| 308 |
+
"model.audio.layers.13.self_attn_layer_norm",
|
| 309 |
+
"model.audio.layers.13.self_attn_layer_norm.bias",
|
| 310 |
+
"model.audio.layers.14.fc1",
|
| 311 |
+
"model.audio.layers.14.fc1.bias",
|
| 312 |
+
"model.audio.layers.14.fc2",
|
| 313 |
+
"model.audio.layers.14.fc2.bias",
|
| 314 |
+
"model.audio.layers.14.final_layer_norm",
|
| 315 |
+
"model.audio.layers.14.final_layer_norm.bias",
|
| 316 |
+
"model.audio.layers.14.self_attn.k_proj",
|
| 317 |
+
"model.audio.layers.14.self_attn.out_proj",
|
| 318 |
+
"model.audio.layers.14.self_attn.out_proj.bias",
|
| 319 |
+
"model.audio.layers.14.self_attn.q_proj",
|
| 320 |
+
"model.audio.layers.14.self_attn.q_proj.bias",
|
| 321 |
+
"model.audio.layers.14.self_attn.v_proj",
|
| 322 |
+
"model.audio.layers.14.self_attn.v_proj.bias",
|
| 323 |
+
"model.audio.layers.14.self_attn_layer_norm",
|
| 324 |
+
"model.audio.layers.14.self_attn_layer_norm.bias",
|
| 325 |
+
"model.audio.layers.15.fc1",
|
| 326 |
+
"model.audio.layers.15.fc1.bias",
|
| 327 |
+
"model.audio.layers.15.fc2",
|
| 328 |
+
"model.audio.layers.15.fc2.bias",
|
| 329 |
+
"model.audio.layers.15.final_layer_norm",
|
| 330 |
+
"model.audio.layers.15.final_layer_norm.bias",
|
| 331 |
+
"model.audio.layers.15.self_attn.k_proj",
|
| 332 |
+
"model.audio.layers.15.self_attn.out_proj",
|
| 333 |
+
"model.audio.layers.15.self_attn.out_proj.bias",
|
| 334 |
+
"model.audio.layers.15.self_attn.q_proj",
|
| 335 |
+
"model.audio.layers.15.self_attn.q_proj.bias",
|
| 336 |
+
"model.audio.layers.15.self_attn.v_proj",
|
| 337 |
+
"model.audio.layers.15.self_attn.v_proj.bias",
|
| 338 |
+
"model.audio.layers.15.self_attn_layer_norm",
|
| 339 |
+
"model.audio.layers.15.self_attn_layer_norm.bias",
|
| 340 |
+
"model.audio.layers.16.fc1",
|
| 341 |
+
"model.audio.layers.16.fc1.bias",
|
| 342 |
+
"model.audio.layers.16.fc2",
|
| 343 |
+
"model.audio.layers.16.fc2.bias",
|
| 344 |
+
"model.audio.layers.16.final_layer_norm",
|
| 345 |
+
"model.audio.layers.16.final_layer_norm.bias",
|
| 346 |
+
"model.audio.layers.16.self_attn.k_proj",
|
| 347 |
+
"model.audio.layers.16.self_attn.out_proj",
|
| 348 |
+
"model.audio.layers.16.self_attn.out_proj.bias",
|
| 349 |
+
"model.audio.layers.16.self_attn.q_proj",
|
| 350 |
+
"model.audio.layers.16.self_attn.q_proj.bias",
|
| 351 |
+
"model.audio.layers.16.self_attn.v_proj",
|
| 352 |
+
"model.audio.layers.16.self_attn.v_proj.bias",
|
| 353 |
+
"model.audio.layers.16.self_attn_layer_norm",
|
| 354 |
+
"model.audio.layers.16.self_attn_layer_norm.bias",
|
| 355 |
+
"model.audio.layers.17.fc1",
|
| 356 |
+
"model.audio.layers.17.fc1.bias",
|
| 357 |
+
"model.audio.layers.17.fc2",
|
| 358 |
+
"model.audio.layers.17.fc2.bias",
|
| 359 |
+
"model.audio.layers.17.final_layer_norm",
|
| 360 |
+
"model.audio.layers.17.final_layer_norm.bias",
|
| 361 |
+
"model.audio.layers.17.self_attn.k_proj",
|
| 362 |
+
"model.audio.layers.17.self_attn.out_proj",
|
| 363 |
+
"model.audio.layers.17.self_attn.out_proj.bias",
|
| 364 |
+
"model.audio.layers.17.self_attn.q_proj",
|
| 365 |
+
"model.audio.layers.17.self_attn.q_proj.bias",
|
| 366 |
+
"model.audio.layers.17.self_attn.v_proj",
|
| 367 |
+
"model.audio.layers.17.self_attn.v_proj.bias",
|
| 368 |
+
"model.audio.layers.17.self_attn_layer_norm",
|
| 369 |
+
"model.audio.layers.17.self_attn_layer_norm.bias",
|
| 370 |
+
"model.audio.layers.18.fc1",
|
| 371 |
+
"model.audio.layers.18.fc1.bias",
|
| 372 |
+
"model.audio.layers.18.fc2",
|
| 373 |
+
"model.audio.layers.18.fc2.bias",
|
| 374 |
+
"model.audio.layers.18.final_layer_norm",
|
| 375 |
+
"model.audio.layers.18.final_layer_norm.bias",
|
| 376 |
+
"model.audio.layers.18.self_attn.k_proj",
|
| 377 |
+
"model.audio.layers.18.self_attn.out_proj",
|
| 378 |
+
"model.audio.layers.18.self_attn.out_proj.bias",
|
| 379 |
+
"model.audio.layers.18.self_attn.q_proj",
|
| 380 |
+
"model.audio.layers.18.self_attn.q_proj.bias",
|
| 381 |
+
"model.audio.layers.18.self_attn.v_proj",
|
| 382 |
+
"model.audio.layers.18.self_attn.v_proj.bias",
|
| 383 |
+
"model.audio.layers.18.self_attn_layer_norm",
|
| 384 |
+
"model.audio.layers.18.self_attn_layer_norm.bias",
|
| 385 |
+
"model.audio.layers.19.fc1",
|
| 386 |
+
"model.audio.layers.19.fc1.bias",
|
| 387 |
+
"model.audio.layers.19.fc2",
|
| 388 |
+
"model.audio.layers.19.fc2.bias",
|
| 389 |
+
"model.audio.layers.19.final_layer_norm",
|
| 390 |
+
"model.audio.layers.19.final_layer_norm.bias",
|
| 391 |
+
"model.audio.layers.19.self_attn.k_proj",
|
| 392 |
+
"model.audio.layers.19.self_attn.out_proj",
|
| 393 |
+
"model.audio.layers.19.self_attn.out_proj.bias",
|
| 394 |
+
"model.audio.layers.19.self_attn.q_proj",
|
| 395 |
+
"model.audio.layers.19.self_attn.q_proj.bias",
|
| 396 |
+
"model.audio.layers.19.self_attn.v_proj",
|
| 397 |
+
"model.audio.layers.19.self_attn.v_proj.bias",
|
| 398 |
+
"model.audio.layers.19.self_attn_layer_norm",
|
| 399 |
+
"model.audio.layers.19.self_attn_layer_norm.bias",
|
| 400 |
+
"model.audio.layers.2.fc1",
|
| 401 |
+
"model.audio.layers.2.fc1.bias",
|
| 402 |
+
"model.audio.layers.2.fc2",
|
| 403 |
+
"model.audio.layers.2.fc2.bias",
|
| 404 |
+
"model.audio.layers.2.final_layer_norm",
|
| 405 |
+
"model.audio.layers.2.final_layer_norm.bias",
|
| 406 |
+
"model.audio.layers.2.self_attn.k_proj",
|
| 407 |
+
"model.audio.layers.2.self_attn.out_proj",
|
| 408 |
+
"model.audio.layers.2.self_attn.out_proj.bias",
|
| 409 |
+
"model.audio.layers.2.self_attn.q_proj",
|
| 410 |
+
"model.audio.layers.2.self_attn.q_proj.bias",
|
| 411 |
+
"model.audio.layers.2.self_attn.v_proj",
|
| 412 |
+
"model.audio.layers.2.self_attn.v_proj.bias",
|
| 413 |
+
"model.audio.layers.2.self_attn_layer_norm",
|
| 414 |
+
"model.audio.layers.2.self_attn_layer_norm.bias",
|
| 415 |
+
"model.audio.layers.20.fc1",
|
| 416 |
+
"model.audio.layers.20.fc1.bias",
|
| 417 |
+
"model.audio.layers.20.fc2",
|
| 418 |
+
"model.audio.layers.20.fc2.bias",
|
| 419 |
+
"model.audio.layers.20.final_layer_norm",
|
| 420 |
+
"model.audio.layers.20.final_layer_norm.bias",
|
| 421 |
+
"model.audio.layers.20.self_attn.k_proj",
|
| 422 |
+
"model.audio.layers.20.self_attn.out_proj",
|
| 423 |
+
"model.audio.layers.20.self_attn.out_proj.bias",
|
| 424 |
+
"model.audio.layers.20.self_attn.q_proj",
|
| 425 |
+
"model.audio.layers.20.self_attn.q_proj.bias",
|
| 426 |
+
"model.audio.layers.20.self_attn.v_proj",
|
| 427 |
+
"model.audio.layers.20.self_attn.v_proj.bias",
|
| 428 |
+
"model.audio.layers.20.self_attn_layer_norm",
|
| 429 |
+
"model.audio.layers.20.self_attn_layer_norm.bias",
|
| 430 |
+
"model.audio.layers.21.fc1",
|
| 431 |
+
"model.audio.layers.21.fc1.bias",
|
| 432 |
+
"model.audio.layers.21.fc2",
|
| 433 |
+
"model.audio.layers.21.fc2.bias",
|
| 434 |
+
"model.audio.layers.21.final_layer_norm",
|
| 435 |
+
"model.audio.layers.21.final_layer_norm.bias",
|
| 436 |
+
"model.audio.layers.21.self_attn.k_proj",
|
| 437 |
+
"model.audio.layers.21.self_attn.out_proj",
|
| 438 |
+
"model.audio.layers.21.self_attn.out_proj.bias",
|
| 439 |
+
"model.audio.layers.21.self_attn.q_proj",
|
| 440 |
+
"model.audio.layers.21.self_attn.q_proj.bias",
|
| 441 |
+
"model.audio.layers.21.self_attn.v_proj",
|
| 442 |
+
"model.audio.layers.21.self_attn.v_proj.bias",
|
| 443 |
+
"model.audio.layers.21.self_attn_layer_norm",
|
| 444 |
+
"model.audio.layers.21.self_attn_layer_norm.bias",
|
| 445 |
+
"model.audio.layers.22.fc1",
|
| 446 |
+
"model.audio.layers.22.fc1.bias",
|
| 447 |
+
"model.audio.layers.22.fc2",
|
| 448 |
+
"model.audio.layers.22.fc2.bias",
|
| 449 |
+
"model.audio.layers.22.final_layer_norm",
|
| 450 |
+
"model.audio.layers.22.final_layer_norm.bias",
|
| 451 |
+
"model.audio.layers.22.self_attn.k_proj",
|
| 452 |
+
"model.audio.layers.22.self_attn.out_proj",
|
| 453 |
+
"model.audio.layers.22.self_attn.out_proj.bias",
|
| 454 |
+
"model.audio.layers.22.self_attn.q_proj",
|
| 455 |
+
"model.audio.layers.22.self_attn.q_proj.bias",
|
| 456 |
+
"model.audio.layers.22.self_attn.v_proj",
|
| 457 |
+
"model.audio.layers.22.self_attn.v_proj.bias",
|
| 458 |
+
"model.audio.layers.22.self_attn_layer_norm",
|
| 459 |
+
"model.audio.layers.22.self_attn_layer_norm.bias",
|
| 460 |
+
"model.audio.layers.23.fc1",
|
| 461 |
+
"model.audio.layers.23.fc1.bias",
|
| 462 |
+
"model.audio.layers.23.fc2",
|
| 463 |
+
"model.audio.layers.23.fc2.bias",
|
| 464 |
+
"model.audio.layers.23.final_layer_norm",
|
| 465 |
+
"model.audio.layers.23.final_layer_norm.bias",
|
| 466 |
+
"model.audio.layers.23.self_attn.k_proj",
|
| 467 |
+
"model.audio.layers.23.self_attn.out_proj",
|
| 468 |
+
"model.audio.layers.23.self_attn.out_proj.bias",
|
| 469 |
+
"model.audio.layers.23.self_attn.q_proj",
|
| 470 |
+
"model.audio.layers.23.self_attn.q_proj.bias",
|
| 471 |
+
"model.audio.layers.23.self_attn.v_proj",
|
| 472 |
+
"model.audio.layers.23.self_attn.v_proj.bias",
|
| 473 |
+
"model.audio.layers.23.self_attn_layer_norm",
|
| 474 |
+
"model.audio.layers.23.self_attn_layer_norm.bias",
|
| 475 |
+
"model.audio.layers.24.fc1",
|
| 476 |
+
"model.audio.layers.24.fc1.bias",
|
| 477 |
+
"model.audio.layers.24.fc2",
|
| 478 |
+
"model.audio.layers.24.fc2.bias",
|
| 479 |
+
"model.audio.layers.24.final_layer_norm",
|
| 480 |
+
"model.audio.layers.24.final_layer_norm.bias",
|
| 481 |
+
"model.audio.layers.24.self_attn.k_proj",
|
| 482 |
+
"model.audio.layers.24.self_attn.out_proj",
|
| 483 |
+
"model.audio.layers.24.self_attn.out_proj.bias",
|
| 484 |
+
"model.audio.layers.24.self_attn.q_proj",
|
| 485 |
+
"model.audio.layers.24.self_attn.q_proj.bias",
|
| 486 |
+
"model.audio.layers.24.self_attn.v_proj",
|
| 487 |
+
"model.audio.layers.24.self_attn.v_proj.bias",
|
| 488 |
+
"model.audio.layers.24.self_attn_layer_norm",
|
| 489 |
+
"model.audio.layers.24.self_attn_layer_norm.bias",
|
| 490 |
+
"model.audio.layers.25.fc1",
|
| 491 |
+
"model.audio.layers.25.fc1.bias",
|
| 492 |
+
"model.audio.layers.25.fc2",
|
| 493 |
+
"model.audio.layers.25.fc2.bias",
|
| 494 |
+
"model.audio.layers.25.final_layer_norm",
|
| 495 |
+
"model.audio.layers.25.final_layer_norm.bias",
|
| 496 |
+
"model.audio.layers.25.self_attn.k_proj",
|
| 497 |
+
"model.audio.layers.25.self_attn.out_proj",
|
| 498 |
+
"model.audio.layers.25.self_attn.out_proj.bias",
|
| 499 |
+
"model.audio.layers.25.self_attn.q_proj",
|
| 500 |
+
"model.audio.layers.25.self_attn.q_proj.bias",
|
| 501 |
+
"model.audio.layers.25.self_attn.v_proj",
|
| 502 |
+
"model.audio.layers.25.self_attn.v_proj.bias",
|
| 503 |
+
"model.audio.layers.25.self_attn_layer_norm",
|
| 504 |
+
"model.audio.layers.25.self_attn_layer_norm.bias",
|
| 505 |
+
"model.audio.layers.26.fc1",
|
| 506 |
+
"model.audio.layers.26.fc1.bias",
|
| 507 |
+
"model.audio.layers.26.fc2",
|
| 508 |
+
"model.audio.layers.26.fc2.bias",
|
| 509 |
+
"model.audio.layers.26.final_layer_norm",
|
| 510 |
+
"model.audio.layers.26.final_layer_norm.bias",
|
| 511 |
+
"model.audio.layers.26.self_attn.k_proj",
|
| 512 |
+
"model.audio.layers.26.self_attn.out_proj",
|
| 513 |
+
"model.audio.layers.26.self_attn.out_proj.bias",
|
| 514 |
+
"model.audio.layers.26.self_attn.q_proj",
|
| 515 |
+
"model.audio.layers.26.self_attn.q_proj.bias",
|
| 516 |
+
"model.audio.layers.26.self_attn.v_proj",
|
| 517 |
+
"model.audio.layers.26.self_attn.v_proj.bias",
|
| 518 |
+
"model.audio.layers.26.self_attn_layer_norm",
|
| 519 |
+
"model.audio.layers.26.self_attn_layer_norm.bias",
|
| 520 |
+
"model.audio.layers.27.fc1",
|
| 521 |
+
"model.audio.layers.27.fc1.bias",
|
| 522 |
+
"model.audio.layers.27.fc2",
|
| 523 |
+
"model.audio.layers.27.fc2.bias",
|
| 524 |
+
"model.audio.layers.27.final_layer_norm",
|
| 525 |
+
"model.audio.layers.27.final_layer_norm.bias",
|
| 526 |
+
"model.audio.layers.27.self_attn.k_proj",
|
| 527 |
+
"model.audio.layers.27.self_attn.out_proj",
|
| 528 |
+
"model.audio.layers.27.self_attn.out_proj.bias",
|
| 529 |
+
"model.audio.layers.27.self_attn.q_proj",
|
| 530 |
+
"model.audio.layers.27.self_attn.q_proj.bias",
|
| 531 |
+
"model.audio.layers.27.self_attn.v_proj",
|
| 532 |
+
"model.audio.layers.27.self_attn.v_proj.bias",
|
| 533 |
+
"model.audio.layers.27.self_attn_layer_norm",
|
| 534 |
+
"model.audio.layers.27.self_attn_layer_norm.bias",
|
| 535 |
+
"model.audio.layers.28.fc1",
|
| 536 |
+
"model.audio.layers.28.fc1.bias",
|
| 537 |
+
"model.audio.layers.28.fc2",
|
| 538 |
+
"model.audio.layers.28.fc2.bias",
|
| 539 |
+
"model.audio.layers.28.final_layer_norm",
|
| 540 |
+
"model.audio.layers.28.final_layer_norm.bias",
|
| 541 |
+
"model.audio.layers.28.self_attn.k_proj",
|
| 542 |
+
"model.audio.layers.28.self_attn.out_proj",
|
| 543 |
+
"model.audio.layers.28.self_attn.out_proj.bias",
|
| 544 |
+
"model.audio.layers.28.self_attn.q_proj",
|
| 545 |
+
"model.audio.layers.28.self_attn.q_proj.bias",
|
| 546 |
+
"model.audio.layers.28.self_attn.v_proj",
|
| 547 |
+
"model.audio.layers.28.self_attn.v_proj.bias",
|
| 548 |
+
"model.audio.layers.28.self_attn_layer_norm",
|
| 549 |
+
"model.audio.layers.28.self_attn_layer_norm.bias",
|
| 550 |
+
"model.audio.layers.29.fc1",
|
| 551 |
+
"model.audio.layers.29.fc1.bias",
|
| 552 |
+
"model.audio.layers.29.fc2",
|
| 553 |
+
"model.audio.layers.29.fc2.bias",
|
| 554 |
+
"model.audio.layers.29.final_layer_norm",
|
| 555 |
+
"model.audio.layers.29.final_layer_norm.bias",
|
| 556 |
+
"model.audio.layers.29.self_attn.k_proj",
|
| 557 |
+
"model.audio.layers.29.self_attn.out_proj",
|
| 558 |
+
"model.audio.layers.29.self_attn.out_proj.bias",
|
| 559 |
+
"model.audio.layers.29.self_attn.q_proj",
|
| 560 |
+
"model.audio.layers.29.self_attn.q_proj.bias",
|
| 561 |
+
"model.audio.layers.29.self_attn.v_proj",
|
| 562 |
+
"model.audio.layers.29.self_attn.v_proj.bias",
|
| 563 |
+
"model.audio.layers.29.self_attn_layer_norm",
|
| 564 |
+
"model.audio.layers.29.self_attn_layer_norm.bias",
|
| 565 |
+
"model.audio.layers.3.fc1",
|
| 566 |
+
"model.audio.layers.3.fc1.bias",
|
| 567 |
+
"model.audio.layers.3.fc2",
|
| 568 |
+
"model.audio.layers.3.fc2.bias",
|
| 569 |
+
"model.audio.layers.3.final_layer_norm",
|
| 570 |
+
"model.audio.layers.3.final_layer_norm.bias",
|
| 571 |
+
"model.audio.layers.3.self_attn.k_proj",
|
| 572 |
+
"model.audio.layers.3.self_attn.out_proj",
|
| 573 |
+
"model.audio.layers.3.self_attn.out_proj.bias",
|
| 574 |
+
"model.audio.layers.3.self_attn.q_proj",
|
| 575 |
+
"model.audio.layers.3.self_attn.q_proj.bias",
|
| 576 |
+
"model.audio.layers.3.self_attn.v_proj",
|
| 577 |
+
"model.audio.layers.3.self_attn.v_proj.bias",
|
| 578 |
+
"model.audio.layers.3.self_attn_layer_norm",
|
| 579 |
+
"model.audio.layers.3.self_attn_layer_norm.bias",
|
| 580 |
+
"model.audio.layers.30.fc1",
|
| 581 |
+
"model.audio.layers.30.fc1.bias",
|
| 582 |
+
"model.audio.layers.30.fc2",
|
| 583 |
+
"model.audio.layers.30.fc2.bias",
|
| 584 |
+
"model.audio.layers.30.final_layer_norm",
|
| 585 |
+
"model.audio.layers.30.final_layer_norm.bias",
|
| 586 |
+
"model.audio.layers.30.self_attn.k_proj",
|
| 587 |
+
"model.audio.layers.30.self_attn.out_proj",
|
| 588 |
+
"model.audio.layers.30.self_attn.out_proj.bias",
|
| 589 |
+
"model.audio.layers.30.self_attn.q_proj",
|
| 590 |
+
"model.audio.layers.30.self_attn.q_proj.bias",
|
| 591 |
+
"model.audio.layers.30.self_attn.v_proj",
|
| 592 |
+
"model.audio.layers.30.self_attn.v_proj.bias",
|
| 593 |
+
"model.audio.layers.30.self_attn_layer_norm",
|
| 594 |
+
"model.audio.layers.30.self_attn_layer_norm.bias",
|
| 595 |
+
"model.audio.layers.31.fc1",
|
| 596 |
+
"model.audio.layers.31.fc1.bias",
|
| 597 |
+
"model.audio.layers.31.fc2",
|
| 598 |
+
"model.audio.layers.31.fc2.bias",
|
| 599 |
+
"model.audio.layers.31.final_layer_norm",
|
| 600 |
+
"model.audio.layers.31.final_layer_norm.bias",
|
| 601 |
+
"model.audio.layers.31.self_attn.k_proj",
|
| 602 |
+
"model.audio.layers.31.self_attn.out_proj",
|
| 603 |
+
"model.audio.layers.31.self_attn.out_proj.bias",
|
| 604 |
+
"model.audio.layers.31.self_attn.q_proj",
|
| 605 |
+
"model.audio.layers.31.self_attn.q_proj.bias",
|
| 606 |
+
"model.audio.layers.31.self_attn.v_proj",
|
| 607 |
+
"model.audio.layers.31.self_attn.v_proj.bias",
|
| 608 |
+
"model.audio.layers.31.self_attn_layer_norm",
|
| 609 |
+
"model.audio.layers.31.self_attn_layer_norm.bias",
|
| 610 |
+
"model.audio.layers.4.fc1",
|
| 611 |
+
"model.audio.layers.4.fc1.bias",
|
| 612 |
+
"model.audio.layers.4.fc2",
|
| 613 |
+
"model.audio.layers.4.fc2.bias",
|
| 614 |
+
"model.audio.layers.4.final_layer_norm",
|
| 615 |
+
"model.audio.layers.4.final_layer_norm.bias",
|
| 616 |
+
"model.audio.layers.4.self_attn.k_proj",
|
| 617 |
+
"model.audio.layers.4.self_attn.out_proj",
|
| 618 |
+
"model.audio.layers.4.self_attn.out_proj.bias",
|
| 619 |
+
"model.audio.layers.4.self_attn.q_proj",
|
| 620 |
+
"model.audio.layers.4.self_attn.q_proj.bias",
|
| 621 |
+
"model.audio.layers.4.self_attn.v_proj",
|
| 622 |
+
"model.audio.layers.4.self_attn.v_proj.bias",
|
| 623 |
+
"model.audio.layers.4.self_attn_layer_norm",
|
| 624 |
+
"model.audio.layers.4.self_attn_layer_norm.bias",
|
| 625 |
+
"model.audio.layers.5.fc1",
|
| 626 |
+
"model.audio.layers.5.fc1.bias",
|
| 627 |
+
"model.audio.layers.5.fc2",
|
| 628 |
+
"model.audio.layers.5.fc2.bias",
|
| 629 |
+
"model.audio.layers.5.final_layer_norm",
|
| 630 |
+
"model.audio.layers.5.final_layer_norm.bias",
|
| 631 |
+
"model.audio.layers.5.self_attn.k_proj",
|
| 632 |
+
"model.audio.layers.5.self_attn.out_proj",
|
| 633 |
+
"model.audio.layers.5.self_attn.out_proj.bias",
|
| 634 |
+
"model.audio.layers.5.self_attn.q_proj",
|
| 635 |
+
"model.audio.layers.5.self_attn.q_proj.bias",
|
| 636 |
+
"model.audio.layers.5.self_attn.v_proj",
|
| 637 |
+
"model.audio.layers.5.self_attn.v_proj.bias",
|
| 638 |
+
"model.audio.layers.5.self_attn_layer_norm",
|
| 639 |
+
"model.audio.layers.5.self_attn_layer_norm.bias",
|
| 640 |
+
"model.audio.layers.6.fc1",
|
| 641 |
+
"model.audio.layers.6.fc1.bias",
|
| 642 |
+
"model.audio.layers.6.fc2",
|
| 643 |
+
"model.audio.layers.6.fc2.bias",
|
| 644 |
+
"model.audio.layers.6.final_layer_norm",
|
| 645 |
+
"model.audio.layers.6.final_layer_norm.bias",
|
| 646 |
+
"model.audio.layers.6.self_attn.k_proj",
|
| 647 |
+
"model.audio.layers.6.self_attn.out_proj",
|
| 648 |
+
"model.audio.layers.6.self_attn.out_proj.bias",
|
| 649 |
+
"model.audio.layers.6.self_attn.q_proj",
|
| 650 |
+
"model.audio.layers.6.self_attn.q_proj.bias",
|
| 651 |
+
"model.audio.layers.6.self_attn.v_proj",
|
| 652 |
+
"model.audio.layers.6.self_attn.v_proj.bias",
|
| 653 |
+
"model.audio.layers.6.self_attn_layer_norm",
|
| 654 |
+
"model.audio.layers.6.self_attn_layer_norm.bias",
|
| 655 |
+
"model.audio.layers.7.fc1",
|
| 656 |
+
"model.audio.layers.7.fc1.bias",
|
| 657 |
+
"model.audio.layers.7.fc2",
|
| 658 |
+
"model.audio.layers.7.fc2.bias",
|
| 659 |
+
"model.audio.layers.7.final_layer_norm",
|
| 660 |
+
"model.audio.layers.7.final_layer_norm.bias",
|
| 661 |
+
"model.audio.layers.7.self_attn.k_proj",
|
| 662 |
+
"model.audio.layers.7.self_attn.out_proj",
|
| 663 |
+
"model.audio.layers.7.self_attn.out_proj.bias",
|
| 664 |
+
"model.audio.layers.7.self_attn.q_proj",
|
| 665 |
+
"model.audio.layers.7.self_attn.q_proj.bias",
|
| 666 |
+
"model.audio.layers.7.self_attn.v_proj",
|
| 667 |
+
"model.audio.layers.7.self_attn.v_proj.bias",
|
| 668 |
+
"model.audio.layers.7.self_attn_layer_norm",
|
| 669 |
+
"model.audio.layers.7.self_attn_layer_norm.bias",
|
| 670 |
+
"model.audio.layers.8.fc1",
|
| 671 |
+
"model.audio.layers.8.fc1.bias",
|
| 672 |
+
"model.audio.layers.8.fc2",
|
| 673 |
+
"model.audio.layers.8.fc2.bias",
|
| 674 |
+
"model.audio.layers.8.final_layer_norm",
|
| 675 |
+
"model.audio.layers.8.final_layer_norm.bias",
|
| 676 |
+
"model.audio.layers.8.self_attn.k_proj",
|
| 677 |
+
"model.audio.layers.8.self_attn.out_proj",
|
| 678 |
+
"model.audio.layers.8.self_attn.out_proj.bias",
|
| 679 |
+
"model.audio.layers.8.self_attn.q_proj",
|
| 680 |
+
"model.audio.layers.8.self_attn.q_proj.bias",
|
| 681 |
+
"model.audio.layers.8.self_attn.v_proj",
|
| 682 |
+
"model.audio.layers.8.self_attn.v_proj.bias",
|
| 683 |
+
"model.audio.layers.8.self_attn_layer_norm",
|
| 684 |
+
"model.audio.layers.8.self_attn_layer_norm.bias",
|
| 685 |
+
"model.audio.layers.9.fc1",
|
| 686 |
+
"model.audio.layers.9.fc1.bias",
|
| 687 |
+
"model.audio.layers.9.fc2",
|
| 688 |
+
"model.audio.layers.9.fc2.bias",
|
| 689 |
+
"model.audio.layers.9.final_layer_norm",
|
| 690 |
+
"model.audio.layers.9.final_layer_norm.bias",
|
| 691 |
+
"model.audio.layers.9.self_attn.k_proj",
|
| 692 |
+
"model.audio.layers.9.self_attn.out_proj",
|
| 693 |
+
"model.audio.layers.9.self_attn.out_proj.bias",
|
| 694 |
+
"model.audio.layers.9.self_attn.q_proj",
|
| 695 |
+
"model.audio.layers.9.self_attn.q_proj.bias",
|
| 696 |
+
"model.audio.layers.9.self_attn.v_proj",
|
| 697 |
+
"model.audio.layers.9.self_attn.v_proj.bias",
|
| 698 |
+
"model.audio.layers.9.self_attn_layer_norm",
|
| 699 |
+
"model.audio.layers.9.self_attn_layer_norm.bias",
|
| 700 |
+
"model.audio.q_tokens",
|
| 701 |
+
"model.audio.qformer.bert.embeddings.LayerNorm.beta",
|
| 702 |
+
"model.audio.qformer.bert.embeddings.LayerNorm.gamma",
|
| 703 |
+
"model.audio.qformer.bert.embeddings.position_ids",
|
| 704 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.output.LayerNorm.beta",
|
| 705 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.output.LayerNorm.gamma",
|
| 706 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.output.dense",
|
| 707 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.output.dense.bias",
|
| 708 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.self.key",
|
| 709 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.self.key.bias",
|
| 710 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.self.query",
|
| 711 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.self.query.bias",
|
| 712 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.self.value",
|
| 713 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.self.value.bias",
|
| 714 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.output.LayerNorm.beta",
|
| 715 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.output.LayerNorm.gamma",
|
| 716 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.output.dense",
|
| 717 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.output.dense.bias",
|
| 718 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.self.key",
|
| 719 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.self.key.bias",
|
| 720 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.self.query",
|
| 721 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.self.query.bias",
|
| 722 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.self.value",
|
| 723 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.self.value.bias",
|
| 724 |
+
"model.audio.qformer.bert.encoder.layer.0.intermediate_query.dense",
|
| 725 |
+
"model.audio.qformer.bert.encoder.layer.0.intermediate_query.dense.bias",
|
| 726 |
+
"model.audio.qformer.bert.encoder.layer.0.output_query.LayerNorm.beta",
|
| 727 |
+
"model.audio.qformer.bert.encoder.layer.0.output_query.LayerNorm.gamma",
|
| 728 |
+
"model.audio.qformer.bert.encoder.layer.0.output_query.dense",
|
| 729 |
+
"model.audio.qformer.bert.encoder.layer.0.output_query.dense.bias",
|
| 730 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.output.LayerNorm.beta",
|
| 731 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.output.LayerNorm.gamma",
|
| 732 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.output.dense",
|
| 733 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.output.dense.bias",
|
| 734 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.self.key",
|
| 735 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.self.key.bias",
|
| 736 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.self.query",
|
| 737 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.self.query.bias",
|
| 738 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.self.value",
|
| 739 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.self.value.bias",
|
| 740 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.output.LayerNorm.beta",
|
| 741 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.output.LayerNorm.gamma",
|
| 742 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.output.dense",
|
| 743 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.output.dense.bias",
|
| 744 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.self.key",
|
| 745 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.self.key.bias",
|
| 746 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.self.query",
|
| 747 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.self.query.bias",
|
| 748 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.self.value",
|
| 749 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.self.value.bias",
|
| 750 |
+
"model.audio.qformer.bert.encoder.layer.1.intermediate_query.dense",
|
| 751 |
+
"model.audio.qformer.bert.encoder.layer.1.intermediate_query.dense.bias",
|
| 752 |
+
"model.audio.qformer.bert.encoder.layer.1.output_query.LayerNorm.beta",
|
| 753 |
+
"model.audio.qformer.bert.encoder.layer.1.output_query.LayerNorm.gamma",
|
| 754 |
+
"model.audio.qformer.bert.encoder.layer.1.output_query.dense",
|
| 755 |
+
"model.audio.qformer.bert.encoder.layer.1.output_query.dense.bias",
|
| 756 |
+
"model.language_model.embed_tokens",
|
| 757 |
+
"model.language_model.layers.0.linear_attn.conv1d",
|
| 758 |
+
"model.language_model.layers.0.linear_attn.in_proj_a",
|
| 759 |
+
"model.language_model.layers.0.linear_attn.in_proj_b",
|
| 760 |
+
"model.language_model.layers.1.linear_attn.conv1d",
|
| 761 |
+
"model.language_model.layers.1.linear_attn.in_proj_a",
|
| 762 |
+
"model.language_model.layers.1.linear_attn.in_proj_b",
|
| 763 |
+
"model.language_model.layers.10.linear_attn.conv1d",
|
| 764 |
+
"model.language_model.layers.10.linear_attn.in_proj_a",
|
| 765 |
+
"model.language_model.layers.10.linear_attn.in_proj_b",
|
| 766 |
+
"model.language_model.layers.12.linear_attn.conv1d",
|
| 767 |
+
"model.language_model.layers.12.linear_attn.in_proj_a",
|
| 768 |
+
"model.language_model.layers.12.linear_attn.in_proj_b",
|
| 769 |
+
"model.language_model.layers.13.linear_attn.conv1d",
|
| 770 |
+
"model.language_model.layers.13.linear_attn.in_proj_a",
|
| 771 |
+
"model.language_model.layers.13.linear_attn.in_proj_b",
|
| 772 |
+
"model.language_model.layers.14.linear_attn.conv1d",
|
| 773 |
+
"model.language_model.layers.14.linear_attn.in_proj_a",
|
| 774 |
+
"model.language_model.layers.14.linear_attn.in_proj_b",
|
| 775 |
+
"model.language_model.layers.16.linear_attn.conv1d",
|
| 776 |
+
"model.language_model.layers.16.linear_attn.in_proj_a",
|
| 777 |
+
"model.language_model.layers.16.linear_attn.in_proj_b",
|
| 778 |
+
"model.language_model.layers.17.linear_attn.conv1d",
|
| 779 |
+
"model.language_model.layers.17.linear_attn.in_proj_a",
|
| 780 |
+
"model.language_model.layers.17.linear_attn.in_proj_b",
|
| 781 |
+
"model.language_model.layers.18.linear_attn.conv1d",
|
| 782 |
+
"model.language_model.layers.18.linear_attn.in_proj_a",
|
| 783 |
+
"model.language_model.layers.18.linear_attn.in_proj_b",
|
| 784 |
+
"model.language_model.layers.2.linear_attn.conv1d",
|
| 785 |
+
"model.language_model.layers.2.linear_attn.in_proj_a",
|
| 786 |
+
"model.language_model.layers.2.linear_attn.in_proj_b",
|
| 787 |
+
"model.language_model.layers.20.linear_attn.conv1d",
|
| 788 |
+
"model.language_model.layers.20.linear_attn.in_proj_a",
|
| 789 |
+
"model.language_model.layers.20.linear_attn.in_proj_b",
|
| 790 |
+
"model.language_model.layers.21.linear_attn.conv1d",
|
| 791 |
+
"model.language_model.layers.21.linear_attn.in_proj_a",
|
| 792 |
+
"model.language_model.layers.21.linear_attn.in_proj_b",
|
| 793 |
+
"model.language_model.layers.22.linear_attn.conv1d",
|
| 794 |
+
"model.language_model.layers.22.linear_attn.in_proj_a",
|
| 795 |
+
"model.language_model.layers.22.linear_attn.in_proj_b",
|
| 796 |
+
"model.language_model.layers.24.linear_attn.conv1d",
|
| 797 |
+
"model.language_model.layers.24.linear_attn.in_proj_a",
|
| 798 |
+
"model.language_model.layers.24.linear_attn.in_proj_b",
|
| 799 |
+
"model.language_model.layers.25.linear_attn.conv1d",
|
| 800 |
+
"model.language_model.layers.25.linear_attn.in_proj_a",
|
| 801 |
+
"model.language_model.layers.25.linear_attn.in_proj_b",
|
| 802 |
+
"model.language_model.layers.26.linear_attn.conv1d",
|
| 803 |
+
"model.language_model.layers.26.linear_attn.in_proj_a",
|
| 804 |
+
"model.language_model.layers.26.linear_attn.in_proj_b",
|
| 805 |
+
"model.language_model.layers.28.linear_attn.conv1d",
|
| 806 |
+
"model.language_model.layers.28.linear_attn.in_proj_a",
|
| 807 |
+
"model.language_model.layers.28.linear_attn.in_proj_b",
|
| 808 |
+
"model.language_model.layers.29.linear_attn.conv1d",
|
| 809 |
+
"model.language_model.layers.29.linear_attn.in_proj_a",
|
| 810 |
+
"model.language_model.layers.29.linear_attn.in_proj_b",
|
| 811 |
+
"model.language_model.layers.30.linear_attn.conv1d",
|
| 812 |
+
"model.language_model.layers.30.linear_attn.in_proj_a",
|
| 813 |
+
"model.language_model.layers.30.linear_attn.in_proj_b",
|
| 814 |
+
"model.language_model.layers.4.linear_attn.conv1d",
|
| 815 |
+
"model.language_model.layers.4.linear_attn.in_proj_a",
|
| 816 |
+
"model.language_model.layers.4.linear_attn.in_proj_b",
|
| 817 |
+
"model.language_model.layers.5.linear_attn.conv1d",
|
| 818 |
+
"model.language_model.layers.5.linear_attn.in_proj_a",
|
| 819 |
+
"model.language_model.layers.5.linear_attn.in_proj_b",
|
| 820 |
+
"model.language_model.layers.6.linear_attn.conv1d",
|
| 821 |
+
"model.language_model.layers.6.linear_attn.in_proj_a",
|
| 822 |
+
"model.language_model.layers.6.linear_attn.in_proj_b",
|
| 823 |
+
"model.language_model.layers.8.linear_attn.conv1d",
|
| 824 |
+
"model.language_model.layers.8.linear_attn.in_proj_a",
|
| 825 |
+
"model.language_model.layers.8.linear_attn.in_proj_b",
|
| 826 |
+
"model.language_model.layers.9.linear_attn.conv1d",
|
| 827 |
+
"model.language_model.layers.9.linear_attn.in_proj_a",
|
| 828 |
+
"model.language_model.layers.9.linear_attn.in_proj_b",
|
| 829 |
+
"model.language_model.norm",
|
| 830 |
+
"model.visual",
|
| 831 |
+
"model.visual.blocks.0.attn.proj",
|
| 832 |
+
"model.visual.blocks.0.attn.proj.bias",
|
| 833 |
+
"model.visual.blocks.0.attn.qkv",
|
| 834 |
+
"model.visual.blocks.0.attn.qkv.bias",
|
| 835 |
+
"model.visual.blocks.0.mlp.linear_fc1",
|
| 836 |
+
"model.visual.blocks.0.mlp.linear_fc1.bias",
|
| 837 |
+
"model.visual.blocks.0.mlp.linear_fc2",
|
| 838 |
+
"model.visual.blocks.0.mlp.linear_fc2.bias",
|
| 839 |
+
"model.visual.blocks.0.norm1",
|
| 840 |
+
"model.visual.blocks.0.norm1.bias",
|
| 841 |
+
"model.visual.blocks.0.norm2",
|
| 842 |
+
"model.visual.blocks.0.norm2.bias",
|
| 843 |
+
"model.visual.blocks.1.attn.proj",
|
| 844 |
+
"model.visual.blocks.1.attn.proj.bias",
|
| 845 |
+
"model.visual.blocks.1.attn.qkv",
|
| 846 |
+
"model.visual.blocks.1.attn.qkv.bias",
|
| 847 |
+
"model.visual.blocks.1.mlp.linear_fc1",
|
| 848 |
+
"model.visual.blocks.1.mlp.linear_fc1.bias",
|
| 849 |
+
"model.visual.blocks.1.mlp.linear_fc2",
|
| 850 |
+
"model.visual.blocks.1.mlp.linear_fc2.bias",
|
| 851 |
+
"model.visual.blocks.1.norm1",
|
| 852 |
+
"model.visual.blocks.1.norm1.bias",
|
| 853 |
+
"model.visual.blocks.1.norm2",
|
| 854 |
+
"model.visual.blocks.1.norm2.bias",
|
| 855 |
+
"model.visual.blocks.10.attn.proj",
|
| 856 |
+
"model.visual.blocks.10.attn.proj.bias",
|
| 857 |
+
"model.visual.blocks.10.attn.qkv",
|
| 858 |
+
"model.visual.blocks.10.attn.qkv.bias",
|
| 859 |
+
"model.visual.blocks.10.mlp.linear_fc1",
|
| 860 |
+
"model.visual.blocks.10.mlp.linear_fc1.bias",
|
| 861 |
+
"model.visual.blocks.10.mlp.linear_fc2",
|
| 862 |
+
"model.visual.blocks.10.mlp.linear_fc2.bias",
|
| 863 |
+
"model.visual.blocks.10.norm1",
|
| 864 |
+
"model.visual.blocks.10.norm1.bias",
|
| 865 |
+
"model.visual.blocks.10.norm2",
|
| 866 |
+
"model.visual.blocks.10.norm2.bias",
|
| 867 |
+
"model.visual.blocks.11.attn.proj",
|
| 868 |
+
"model.visual.blocks.11.attn.proj.bias",
|
| 869 |
+
"model.visual.blocks.11.attn.qkv",
|
| 870 |
+
"model.visual.blocks.11.attn.qkv.bias",
|
| 871 |
+
"model.visual.blocks.11.mlp.linear_fc1",
|
| 872 |
+
"model.visual.blocks.11.mlp.linear_fc1.bias",
|
| 873 |
+
"model.visual.blocks.11.mlp.linear_fc2",
|
| 874 |
+
"model.visual.blocks.11.mlp.linear_fc2.bias",
|
| 875 |
+
"model.visual.blocks.11.norm1",
|
| 876 |
+
"model.visual.blocks.11.norm1.bias",
|
| 877 |
+
"model.visual.blocks.11.norm2",
|
| 878 |
+
"model.visual.blocks.11.norm2.bias",
|
| 879 |
+
"model.visual.blocks.12.attn.proj",
|
| 880 |
+
"model.visual.blocks.12.attn.proj.bias",
|
| 881 |
+
"model.visual.blocks.12.attn.qkv",
|
| 882 |
+
"model.visual.blocks.12.attn.qkv.bias",
|
| 883 |
+
"model.visual.blocks.12.mlp.linear_fc1",
|
| 884 |
+
"model.visual.blocks.12.mlp.linear_fc1.bias",
|
| 885 |
+
"model.visual.blocks.12.mlp.linear_fc2",
|
| 886 |
+
"model.visual.blocks.12.mlp.linear_fc2.bias",
|
| 887 |
+
"model.visual.blocks.12.norm1",
|
| 888 |
+
"model.visual.blocks.12.norm1.bias",
|
| 889 |
+
"model.visual.blocks.12.norm2",
|
| 890 |
+
"model.visual.blocks.12.norm2.bias",
|
| 891 |
+
"model.visual.blocks.13.attn.proj",
|
| 892 |
+
"model.visual.blocks.13.attn.proj.bias",
|
| 893 |
+
"model.visual.blocks.13.attn.qkv",
|
| 894 |
+
"model.visual.blocks.13.attn.qkv.bias",
|
| 895 |
+
"model.visual.blocks.13.mlp.linear_fc1",
|
| 896 |
+
"model.visual.blocks.13.mlp.linear_fc1.bias",
|
| 897 |
+
"model.visual.blocks.13.mlp.linear_fc2",
|
| 898 |
+
"model.visual.blocks.13.mlp.linear_fc2.bias",
|
| 899 |
+
"model.visual.blocks.13.norm1",
|
| 900 |
+
"model.visual.blocks.13.norm1.bias",
|
| 901 |
+
"model.visual.blocks.13.norm2",
|
| 902 |
+
"model.visual.blocks.13.norm2.bias",
|
| 903 |
+
"model.visual.blocks.14.attn.proj",
|
| 904 |
+
"model.visual.blocks.14.attn.proj.bias",
|
| 905 |
+
"model.visual.blocks.14.attn.qkv",
|
| 906 |
+
"model.visual.blocks.14.attn.qkv.bias",
|
| 907 |
+
"model.visual.blocks.14.mlp.linear_fc1",
|
| 908 |
+
"model.visual.blocks.14.mlp.linear_fc1.bias",
|
| 909 |
+
"model.visual.blocks.14.mlp.linear_fc2",
|
| 910 |
+
"model.visual.blocks.14.mlp.linear_fc2.bias",
|
| 911 |
+
"model.visual.blocks.14.norm1",
|
| 912 |
+
"model.visual.blocks.14.norm1.bias",
|
| 913 |
+
"model.visual.blocks.14.norm2",
|
| 914 |
+
"model.visual.blocks.14.norm2.bias",
|
| 915 |
+
"model.visual.blocks.15.attn.proj",
|
| 916 |
+
"model.visual.blocks.15.attn.proj.bias",
|
| 917 |
+
"model.visual.blocks.15.attn.qkv",
|
| 918 |
+
"model.visual.blocks.15.attn.qkv.bias",
|
| 919 |
+
"model.visual.blocks.15.mlp.linear_fc1",
|
| 920 |
+
"model.visual.blocks.15.mlp.linear_fc1.bias",
|
| 921 |
+
"model.visual.blocks.15.mlp.linear_fc2",
|
| 922 |
+
"model.visual.blocks.15.mlp.linear_fc2.bias",
|
| 923 |
+
"model.visual.blocks.15.norm1",
|
| 924 |
+
"model.visual.blocks.15.norm1.bias",
|
| 925 |
+
"model.visual.blocks.15.norm2",
|
| 926 |
+
"model.visual.blocks.15.norm2.bias",
|
| 927 |
+
"model.visual.blocks.16.attn.proj",
|
| 928 |
+
"model.visual.blocks.16.attn.proj.bias",
|
| 929 |
+
"model.visual.blocks.16.attn.qkv",
|
| 930 |
+
"model.visual.blocks.16.attn.qkv.bias",
|
| 931 |
+
"model.visual.blocks.16.mlp.linear_fc1",
|
| 932 |
+
"model.visual.blocks.16.mlp.linear_fc1.bias",
|
| 933 |
+
"model.visual.blocks.16.mlp.linear_fc2",
|
| 934 |
+
"model.visual.blocks.16.mlp.linear_fc2.bias",
|
| 935 |
+
"model.visual.blocks.16.norm1",
|
| 936 |
+
"model.visual.blocks.16.norm1.bias",
|
| 937 |
+
"model.visual.blocks.16.norm2",
|
| 938 |
+
"model.visual.blocks.16.norm2.bias",
|
| 939 |
+
"model.visual.blocks.17.attn.proj",
|
| 940 |
+
"model.visual.blocks.17.attn.proj.bias",
|
| 941 |
+
"model.visual.blocks.17.attn.qkv",
|
| 942 |
+
"model.visual.blocks.17.attn.qkv.bias",
|
| 943 |
+
"model.visual.blocks.17.mlp.linear_fc1",
|
| 944 |
+
"model.visual.blocks.17.mlp.linear_fc1.bias",
|
| 945 |
+
"model.visual.blocks.17.mlp.linear_fc2",
|
| 946 |
+
"model.visual.blocks.17.mlp.linear_fc2.bias",
|
| 947 |
+
"model.visual.blocks.17.norm1",
|
| 948 |
+
"model.visual.blocks.17.norm1.bias",
|
| 949 |
+
"model.visual.blocks.17.norm2",
|
| 950 |
+
"model.visual.blocks.17.norm2.bias",
|
| 951 |
+
"model.visual.blocks.18.attn.proj",
|
| 952 |
+
"model.visual.blocks.18.attn.proj.bias",
|
| 953 |
+
"model.visual.blocks.18.attn.qkv",
|
| 954 |
+
"model.visual.blocks.18.attn.qkv.bias",
|
| 955 |
+
"model.visual.blocks.18.mlp.linear_fc1",
|
| 956 |
+
"model.visual.blocks.18.mlp.linear_fc1.bias",
|
| 957 |
+
"model.visual.blocks.18.mlp.linear_fc2",
|
| 958 |
+
"model.visual.blocks.18.mlp.linear_fc2.bias",
|
| 959 |
+
"model.visual.blocks.18.norm1",
|
| 960 |
+
"model.visual.blocks.18.norm1.bias",
|
| 961 |
+
"model.visual.blocks.18.norm2",
|
| 962 |
+
"model.visual.blocks.18.norm2.bias",
|
| 963 |
+
"model.visual.blocks.19.attn.proj",
|
| 964 |
+
"model.visual.blocks.19.attn.proj.bias",
|
| 965 |
+
"model.visual.blocks.19.attn.qkv",
|
| 966 |
+
"model.visual.blocks.19.attn.qkv.bias",
|
| 967 |
+
"model.visual.blocks.19.mlp.linear_fc1",
|
| 968 |
+
"model.visual.blocks.19.mlp.linear_fc1.bias",
|
| 969 |
+
"model.visual.blocks.19.mlp.linear_fc2",
|
| 970 |
+
"model.visual.blocks.19.mlp.linear_fc2.bias",
|
| 971 |
+
"model.visual.blocks.19.norm1",
|
| 972 |
+
"model.visual.blocks.19.norm1.bias",
|
| 973 |
+
"model.visual.blocks.19.norm2",
|
| 974 |
+
"model.visual.blocks.19.norm2.bias",
|
| 975 |
+
"model.visual.blocks.2.attn.proj",
|
| 976 |
+
"model.visual.blocks.2.attn.proj.bias",
|
| 977 |
+
"model.visual.blocks.2.attn.qkv",
|
| 978 |
+
"model.visual.blocks.2.attn.qkv.bias",
|
| 979 |
+
"model.visual.blocks.2.mlp.linear_fc1",
|
| 980 |
+
"model.visual.blocks.2.mlp.linear_fc1.bias",
|
| 981 |
+
"model.visual.blocks.2.mlp.linear_fc2",
|
| 982 |
+
"model.visual.blocks.2.mlp.linear_fc2.bias",
|
| 983 |
+
"model.visual.blocks.2.norm1",
|
| 984 |
+
"model.visual.blocks.2.norm1.bias",
|
| 985 |
+
"model.visual.blocks.2.norm2",
|
| 986 |
+
"model.visual.blocks.2.norm2.bias",
|
| 987 |
+
"model.visual.blocks.20.attn.proj",
|
| 988 |
+
"model.visual.blocks.20.attn.proj.bias",
|
| 989 |
+
"model.visual.blocks.20.attn.qkv",
|
| 990 |
+
"model.visual.blocks.20.attn.qkv.bias",
|
| 991 |
+
"model.visual.blocks.20.mlp.linear_fc1",
|
| 992 |
+
"model.visual.blocks.20.mlp.linear_fc1.bias",
|
| 993 |
+
"model.visual.blocks.20.mlp.linear_fc2",
|
| 994 |
+
"model.visual.blocks.20.mlp.linear_fc2.bias",
|
| 995 |
+
"model.visual.blocks.20.norm1",
|
| 996 |
+
"model.visual.blocks.20.norm1.bias",
|
| 997 |
+
"model.visual.blocks.20.norm2",
|
| 998 |
+
"model.visual.blocks.20.norm2.bias",
|
| 999 |
+
"model.visual.blocks.21.attn.proj",
|
| 1000 |
+
"model.visual.blocks.21.attn.proj.bias",
|
| 1001 |
+
"model.visual.blocks.21.attn.qkv",
|
| 1002 |
+
"model.visual.blocks.21.attn.qkv.bias",
|
| 1003 |
+
"model.visual.blocks.21.mlp.linear_fc1",
|
| 1004 |
+
"model.visual.blocks.21.mlp.linear_fc1.bias",
|
| 1005 |
+
"model.visual.blocks.21.mlp.linear_fc2",
|
| 1006 |
+
"model.visual.blocks.21.mlp.linear_fc2.bias",
|
| 1007 |
+
"model.visual.blocks.21.norm1",
|
| 1008 |
+
"model.visual.blocks.21.norm1.bias",
|
| 1009 |
+
"model.visual.blocks.21.norm2",
|
| 1010 |
+
"model.visual.blocks.21.norm2.bias",
|
| 1011 |
+
"model.visual.blocks.22.attn.proj",
|
| 1012 |
+
"model.visual.blocks.22.attn.proj.bias",
|
| 1013 |
+
"model.visual.blocks.22.attn.qkv",
|
| 1014 |
+
"model.visual.blocks.22.attn.qkv.bias",
|
| 1015 |
+
"model.visual.blocks.22.mlp.linear_fc1",
|
| 1016 |
+
"model.visual.blocks.22.mlp.linear_fc1.bias",
|
| 1017 |
+
"model.visual.blocks.22.mlp.linear_fc2",
|
| 1018 |
+
"model.visual.blocks.22.mlp.linear_fc2.bias",
|
| 1019 |
+
"model.visual.blocks.22.norm1",
|
| 1020 |
+
"model.visual.blocks.22.norm1.bias",
|
| 1021 |
+
"model.visual.blocks.22.norm2",
|
| 1022 |
+
"model.visual.blocks.22.norm2.bias",
|
| 1023 |
+
"model.visual.blocks.23.attn.proj",
|
| 1024 |
+
"model.visual.blocks.23.attn.proj.bias",
|
| 1025 |
+
"model.visual.blocks.23.attn.qkv",
|
| 1026 |
+
"model.visual.blocks.23.attn.qkv.bias",
|
| 1027 |
+
"model.visual.blocks.23.mlp.linear_fc1",
|
| 1028 |
+
"model.visual.blocks.23.mlp.linear_fc1.bias",
|
| 1029 |
+
"model.visual.blocks.23.mlp.linear_fc2",
|
| 1030 |
+
"model.visual.blocks.23.mlp.linear_fc2.bias",
|
| 1031 |
+
"model.visual.blocks.23.norm1",
|
| 1032 |
+
"model.visual.blocks.23.norm1.bias",
|
| 1033 |
+
"model.visual.blocks.23.norm2",
|
| 1034 |
+
"model.visual.blocks.23.norm2.bias",
|
| 1035 |
+
"model.visual.blocks.3.attn.proj",
|
| 1036 |
+
"model.visual.blocks.3.attn.proj.bias",
|
| 1037 |
+
"model.visual.blocks.3.attn.qkv",
|
| 1038 |
+
"model.visual.blocks.3.attn.qkv.bias",
|
| 1039 |
+
"model.visual.blocks.3.mlp.linear_fc1",
|
| 1040 |
+
"model.visual.blocks.3.mlp.linear_fc1.bias",
|
| 1041 |
+
"model.visual.blocks.3.mlp.linear_fc2",
|
| 1042 |
+
"model.visual.blocks.3.mlp.linear_fc2.bias",
|
| 1043 |
+
"model.visual.blocks.3.norm1",
|
| 1044 |
+
"model.visual.blocks.3.norm1.bias",
|
| 1045 |
+
"model.visual.blocks.3.norm2",
|
| 1046 |
+
"model.visual.blocks.3.norm2.bias",
|
| 1047 |
+
"model.visual.blocks.4.attn.proj",
|
| 1048 |
+
"model.visual.blocks.4.attn.proj.bias",
|
| 1049 |
+
"model.visual.blocks.4.attn.qkv",
|
| 1050 |
+
"model.visual.blocks.4.attn.qkv.bias",
|
| 1051 |
+
"model.visual.blocks.4.mlp.linear_fc1",
|
| 1052 |
+
"model.visual.blocks.4.mlp.linear_fc1.bias",
|
| 1053 |
+
"model.visual.blocks.4.mlp.linear_fc2",
|
| 1054 |
+
"model.visual.blocks.4.mlp.linear_fc2.bias",
|
| 1055 |
+
"model.visual.blocks.4.norm1",
|
| 1056 |
+
"model.visual.blocks.4.norm1.bias",
|
| 1057 |
+
"model.visual.blocks.4.norm2",
|
| 1058 |
+
"model.visual.blocks.4.norm2.bias",
|
| 1059 |
+
"model.visual.blocks.5.attn.proj",
|
| 1060 |
+
"model.visual.blocks.5.attn.proj.bias",
|
| 1061 |
+
"model.visual.blocks.5.attn.qkv",
|
| 1062 |
+
"model.visual.blocks.5.attn.qkv.bias",
|
| 1063 |
+
"model.visual.blocks.5.mlp.linear_fc1",
|
| 1064 |
+
"model.visual.blocks.5.mlp.linear_fc1.bias",
|
| 1065 |
+
"model.visual.blocks.5.mlp.linear_fc2",
|
| 1066 |
+
"model.visual.blocks.5.mlp.linear_fc2.bias",
|
| 1067 |
+
"model.visual.blocks.5.norm1",
|
| 1068 |
+
"model.visual.blocks.5.norm1.bias",
|
| 1069 |
+
"model.visual.blocks.5.norm2",
|
| 1070 |
+
"model.visual.blocks.5.norm2.bias",
|
| 1071 |
+
"model.visual.blocks.6.attn.proj",
|
| 1072 |
+
"model.visual.blocks.6.attn.proj.bias",
|
| 1073 |
+
"model.visual.blocks.6.attn.qkv",
|
| 1074 |
+
"model.visual.blocks.6.attn.qkv.bias",
|
| 1075 |
+
"model.visual.blocks.6.mlp.linear_fc1",
|
| 1076 |
+
"model.visual.blocks.6.mlp.linear_fc1.bias",
|
| 1077 |
+
"model.visual.blocks.6.mlp.linear_fc2",
|
| 1078 |
+
"model.visual.blocks.6.mlp.linear_fc2.bias",
|
| 1079 |
+
"model.visual.blocks.6.norm1",
|
| 1080 |
+
"model.visual.blocks.6.norm1.bias",
|
| 1081 |
+
"model.visual.blocks.6.norm2",
|
| 1082 |
+
"model.visual.blocks.6.norm2.bias",
|
| 1083 |
+
"model.visual.blocks.7.attn.proj",
|
| 1084 |
+
"model.visual.blocks.7.attn.proj.bias",
|
| 1085 |
+
"model.visual.blocks.7.attn.qkv",
|
| 1086 |
+
"model.visual.blocks.7.attn.qkv.bias",
|
| 1087 |
+
"model.visual.blocks.7.mlp.linear_fc1",
|
| 1088 |
+
"model.visual.blocks.7.mlp.linear_fc1.bias",
|
| 1089 |
+
"model.visual.blocks.7.mlp.linear_fc2",
|
| 1090 |
+
"model.visual.blocks.7.mlp.linear_fc2.bias",
|
| 1091 |
+
"model.visual.blocks.7.norm1",
|
| 1092 |
+
"model.visual.blocks.7.norm1.bias",
|
| 1093 |
+
"model.visual.blocks.7.norm2",
|
| 1094 |
+
"model.visual.blocks.7.norm2.bias",
|
| 1095 |
+
"model.visual.blocks.8.attn.proj",
|
| 1096 |
+
"model.visual.blocks.8.attn.proj.bias",
|
| 1097 |
+
"model.visual.blocks.8.attn.qkv",
|
| 1098 |
+
"model.visual.blocks.8.attn.qkv.bias",
|
| 1099 |
+
"model.visual.blocks.8.mlp.linear_fc1",
|
| 1100 |
+
"model.visual.blocks.8.mlp.linear_fc1.bias",
|
| 1101 |
+
"model.visual.blocks.8.mlp.linear_fc2",
|
| 1102 |
+
"model.visual.blocks.8.mlp.linear_fc2.bias",
|
| 1103 |
+
"model.visual.blocks.8.norm1",
|
| 1104 |
+
"model.visual.blocks.8.norm1.bias",
|
| 1105 |
+
"model.visual.blocks.8.norm2",
|
| 1106 |
+
"model.visual.blocks.8.norm2.bias",
|
| 1107 |
+
"model.visual.blocks.9.attn.proj",
|
| 1108 |
+
"model.visual.blocks.9.attn.proj.bias",
|
| 1109 |
+
"model.visual.blocks.9.attn.qkv",
|
| 1110 |
+
"model.visual.blocks.9.attn.qkv.bias",
|
| 1111 |
+
"model.visual.blocks.9.mlp.linear_fc1",
|
| 1112 |
+
"model.visual.blocks.9.mlp.linear_fc1.bias",
|
| 1113 |
+
"model.visual.blocks.9.mlp.linear_fc2",
|
| 1114 |
+
"model.visual.blocks.9.mlp.linear_fc2.bias",
|
| 1115 |
+
"model.visual.blocks.9.norm1",
|
| 1116 |
+
"model.visual.blocks.9.norm1.bias",
|
| 1117 |
+
"model.visual.blocks.9.norm2",
|
| 1118 |
+
"model.visual.blocks.9.norm2.bias",
|
| 1119 |
+
"model.visual.merger.linear_fc1",
|
| 1120 |
+
"model.visual.merger.linear_fc1.bias",
|
| 1121 |
+
"model.visual.merger.linear_fc2",
|
| 1122 |
+
"model.visual.merger.linear_fc2.bias",
|
| 1123 |
+
"model.visual.merger.norm",
|
| 1124 |
+
"model.visual.merger.norm.bias",
|
| 1125 |
+
"model.visual.patch_embed.proj",
|
| 1126 |
+
"model.visual.patch_embed.proj.bias",
|
| 1127 |
+
"model.visual.pos_embed",
|
| 1128 |
+
"mtp"
|
| 1129 |
+
]
|
| 1130 |
+
}
|
| 1131 |
+
}
|
configuration_wemm.py
ADDED
|
@@ -0,0 +1,731 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 2 |
+
# This file was automatically generated from src/transformers/models/qwen3_5/modular_qwen3_5.py.
|
| 3 |
+
# Do NOT edit this file manually as any edits will be overwritten by the generation of
|
| 4 |
+
# the file from the modular. If any change should be done, please apply the change to the
|
| 5 |
+
# modular_qwen3_5.py file directly. One of our CI enforces this.
|
| 6 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 7 |
+
# Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved.
|
| 8 |
+
#
|
| 9 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
# you may not use this file except in compliance with the License.
|
| 11 |
+
# You may obtain a copy of the License at
|
| 12 |
+
#
|
| 13 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
#
|
| 15 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
# See the License for the specific language governing permissions and
|
| 19 |
+
# limitations under the License.
|
| 20 |
+
from transformers.configuration_utils import PreTrainedConfig, layer_type_validation
|
| 21 |
+
from transformers.modeling_rope_utils import RopeParameters
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class BertConfig(PreTrainedConfig):
|
| 25 |
+
r"""
|
| 26 |
+
This is the configuration class to store the configuration of a [`BertModel`] or a [`TFBertModel`]. It is used to
|
| 27 |
+
instantiate a BERT model according to the specified arguments, defining the model architecture. Instantiating a
|
| 28 |
+
configuration with the defaults will yield a similar configuration to that of the BERT
|
| 29 |
+
[google-bert/bert-base-uncased](https://huggingface.co/google-bert/bert-base-uncased) architecture.
|
| 30 |
+
|
| 31 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 32 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Args:
|
| 36 |
+
vocab_size (`int`, *optional*, defaults to 30522):
|
| 37 |
+
Vocabulary size of the BERT model. Defines the number of different tokens that can be represented by the
|
| 38 |
+
`inputs_ids` passed when calling [`BertModel`] or [`TFBertModel`].
|
| 39 |
+
hidden_size (`int`, *optional*, defaults to 768):
|
| 40 |
+
Dimensionality of the encoder layers and the pooler layer.
|
| 41 |
+
num_hidden_layers (`int`, *optional*, defaults to 12):
|
| 42 |
+
Number of hidden layers in the Transformer encoder.
|
| 43 |
+
num_attention_heads (`int`, *optional*, defaults to 12):
|
| 44 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
| 45 |
+
intermediate_size (`int`, *optional*, defaults to 3072):
|
| 46 |
+
Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
|
| 47 |
+
hidden_act (`str` or `Callable`, *optional*, defaults to `"gelu"`):
|
| 48 |
+
The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
|
| 49 |
+
`"relu"`, `"silu"` and `"gelu_new"` are supported.
|
| 50 |
+
hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
|
| 51 |
+
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
|
| 52 |
+
attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
|
| 53 |
+
The dropout ratio for the attention probabilities.
|
| 54 |
+
max_position_embeddings (`int`, *optional*, defaults to 512):
|
| 55 |
+
The maximum sequence length that this model might ever be used with. Typically set this to something large
|
| 56 |
+
just in case (e.g., 512 or 1024 or 2048).
|
| 57 |
+
type_vocab_size (`int`, *optional*, defaults to 2):
|
| 58 |
+
The vocabulary size of the `token_type_ids` passed when calling [`BertModel`] or [`TFBertModel`].
|
| 59 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 60 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 61 |
+
layer_norm_eps (`float`, *optional*, defaults to 1e-12):
|
| 62 |
+
The epsilon used by the layer normalization layers.
|
| 63 |
+
position_embedding_type (`str`, *optional*, defaults to `"absolute"`):
|
| 64 |
+
Type of position embedding. Choose one of `"absolute"`, `"relative_key"`, `"relative_key_query"`. For
|
| 65 |
+
positional embeddings use `"absolute"`. For more information on `"relative_key"`, please refer to
|
| 66 |
+
[Self-Attention with Relative Position Representations (Shaw et al.)](https://arxiv.org/abs/1803.02155).
|
| 67 |
+
For more information on `"relative_key_query"`, please refer to *Method 4* in [Improve Transformer Models
|
| 68 |
+
with Better Relative Position Embeddings (Huang et al.)](https://arxiv.org/abs/2009.13658).
|
| 69 |
+
is_decoder (`bool`, *optional*, defaults to `False`):
|
| 70 |
+
Whether the model is used as a decoder or not. If `False`, the model is used as an encoder.
|
| 71 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 72 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 73 |
+
relevant if `config.is_decoder=True`.
|
| 74 |
+
classifier_dropout (`float`, *optional*):
|
| 75 |
+
The dropout ratio for the classification head.
|
| 76 |
+
|
| 77 |
+
Examples:
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
>>> from transformers import BertConfig, BertModel
|
| 81 |
+
|
| 82 |
+
>>> # Initializing a BERT google-bert/bert-base-uncased style configuration
|
| 83 |
+
>>> configuration = BertConfig()
|
| 84 |
+
|
| 85 |
+
>>> # Initializing a model (with random weights) from the google-bert/bert-base-uncased style configuration
|
| 86 |
+
>>> model = BertModel(configuration)
|
| 87 |
+
|
| 88 |
+
>>> # Accessing the model configuration
|
| 89 |
+
>>> configuration = model.config
|
| 90 |
+
```"""
|
| 91 |
+
|
| 92 |
+
model_type = "bert"
|
| 93 |
+
|
| 94 |
+
def __init__(
|
| 95 |
+
self,
|
| 96 |
+
vocab_size=30522,
|
| 97 |
+
hidden_size=4104,
|
| 98 |
+
num_hidden_layers=2,
|
| 99 |
+
num_attention_heads=12,
|
| 100 |
+
intermediate_size=12288,
|
| 101 |
+
hidden_act="gelu",
|
| 102 |
+
hidden_dropout_prob=0.1,
|
| 103 |
+
attention_probs_dropout_prob=0.1,
|
| 104 |
+
max_position_embeddings=512,
|
| 105 |
+
type_vocab_size=2,
|
| 106 |
+
initializer_range=0.02,
|
| 107 |
+
layer_norm_eps=1e-12,
|
| 108 |
+
pad_token_id=0,
|
| 109 |
+
position_embedding_type="absolute",
|
| 110 |
+
encoder_width=1280,
|
| 111 |
+
add_cross_attention=True,
|
| 112 |
+
cross_attention_freq=1,
|
| 113 |
+
query_length=1,
|
| 114 |
+
use_cache=True,
|
| 115 |
+
classifier_dropout=None,
|
| 116 |
+
out_hidden_size=4096,
|
| 117 |
+
**kwargs,
|
| 118 |
+
):
|
| 119 |
+
super().__init__(pad_token_id=pad_token_id, **kwargs)
|
| 120 |
+
|
| 121 |
+
self.vocab_size = vocab_size
|
| 122 |
+
self.hidden_size = hidden_size
|
| 123 |
+
self.num_hidden_layers = num_hidden_layers
|
| 124 |
+
self.num_attention_heads = num_attention_heads
|
| 125 |
+
self.hidden_act = hidden_act
|
| 126 |
+
self.intermediate_size = intermediate_size
|
| 127 |
+
self.hidden_dropout_prob = hidden_dropout_prob
|
| 128 |
+
self.attention_probs_dropout_prob = attention_probs_dropout_prob
|
| 129 |
+
self.max_position_embeddings = max_position_embeddings
|
| 130 |
+
self.type_vocab_size = type_vocab_size
|
| 131 |
+
self.initializer_range = initializer_range
|
| 132 |
+
self.layer_norm_eps = layer_norm_eps
|
| 133 |
+
self.position_embedding_type = position_embedding_type
|
| 134 |
+
self.use_cache = use_cache
|
| 135 |
+
self.classifier_dropout = classifier_dropout
|
| 136 |
+
self.encoder_width = encoder_width
|
| 137 |
+
self.add_cross_attention = add_cross_attention
|
| 138 |
+
self.cross_attention_freq = cross_attention_freq
|
| 139 |
+
self.query_length = query_length
|
| 140 |
+
self.out_hidden_size = out_hidden_size
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
class WhisperConfig(PreTrainedConfig):
|
| 144 |
+
r"""
|
| 145 |
+
This is the configuration class to store the configuration of a [`WhisperModel`]. It is used to instantiate a
|
| 146 |
+
Whisper model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
| 147 |
+
with the defaults will yield a similar configuration to that of the Whisper
|
| 148 |
+
[openai/whisper-tiny](https://huggingface.co/openai/whisper-tiny) architecture.
|
| 149 |
+
|
| 150 |
+
Configuration objects inherit from [`PreTrainedConfig`] and can be used to control the model outputs. Read the
|
| 151 |
+
documentation from [`PreTrainedConfig`] for more information.
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
Args:
|
| 155 |
+
vocab_size (`int`, *optional*, defaults to 51865):
|
| 156 |
+
Vocabulary size of the Whisper model. Defines the number of different tokens that can be represented by the
|
| 157 |
+
`decoder_input_ids` passed when calling [`WhisperModel`]
|
| 158 |
+
num_mel_bins (`int`, *optional*, defaults to 80):
|
| 159 |
+
Number of mel features used per input features. Should correspond to the value used in the
|
| 160 |
+
`WhisperProcessor` class.
|
| 161 |
+
encoder_layers (`int`, *optional*, defaults to 4):
|
| 162 |
+
Number of encoder layers.
|
| 163 |
+
decoder_layers (`int`, *optional*, defaults to 4):
|
| 164 |
+
Number of decoder layers.
|
| 165 |
+
encoder_attention_heads (`int`, *optional*, defaults to 6):
|
| 166 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
| 167 |
+
decoder_attention_heads (`int`, *optional*, defaults to 6):
|
| 168 |
+
Number of attention heads for each attention layer in the Transformer decoder.
|
| 169 |
+
encoder_ffn_dim (`int`, *optional*, defaults to 1536):
|
| 170 |
+
Dimensionality of the "intermediate" (often named feed-forward) layer in encoder.
|
| 171 |
+
decoder_ffn_dim (`int`, *optional*, defaults to 1536):
|
| 172 |
+
Dimensionality of the "intermediate" (often named feed-forward) layer in decoder.
|
| 173 |
+
encoder_layerdrop (`float`, *optional*, defaults to 0.0):
|
| 174 |
+
The LayerDrop probability for the encoder. See the [LayerDrop paper](see https://huggingface.co/papers/1909.11556)
|
| 175 |
+
for more details.
|
| 176 |
+
decoder_layerdrop (`float`, *optional*, defaults to 0.0):
|
| 177 |
+
The LayerDrop probability for the decoder. See the [LayerDrop paper](see https://huggingface.co/papers/1909.11556)
|
| 178 |
+
for more details.
|
| 179 |
+
decoder_start_token_id (`int`, *optional*, defaults to 50257):
|
| 180 |
+
Corresponds to the "<|startoftranscript|>" token, which is automatically used when no `decoder_input_ids`
|
| 181 |
+
are provided to the `generate` function. It is used to guide the model`s generation process depending on
|
| 182 |
+
the task.
|
| 183 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 184 |
+
Whether or not the model should return the last key/values attentions (not used by all models).
|
| 185 |
+
is_encoder_decoder (`bool`, *optional*, defaults to `True`):
|
| 186 |
+
Whether the model is used as an encoder/decoder or not.
|
| 187 |
+
activation_function (`str`, *optional*, defaults to `"gelu"`):
|
| 188 |
+
The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
|
| 189 |
+
`"relu"`, `"silu"` and `"gelu_new"` are supported.
|
| 190 |
+
d_model (`int`, *optional*, defaults to 384):
|
| 191 |
+
Dimensionality of the layers.
|
| 192 |
+
dropout (`float`, *optional*, defaults to 0.1):
|
| 193 |
+
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
|
| 194 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 195 |
+
The dropout ratio for the attention probabilities.
|
| 196 |
+
activation_dropout (`float`, *optional*, defaults to 0.0):
|
| 197 |
+
The dropout ratio for activations inside the fully connected layer.
|
| 198 |
+
init_std (`float`, *optional*, defaults to 0.02):
|
| 199 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 200 |
+
scale_embedding (`bool`, *optional*, defaults to False):
|
| 201 |
+
Scale embeddings by diving by sqrt(d_model).
|
| 202 |
+
max_source_positions (`int`, *optional*, defaults to 1500):
|
| 203 |
+
The maximum sequence length of log-mel filter-bank features that this model might ever be used with.
|
| 204 |
+
max_target_positions (`int`, *optional*, defaults to 448):
|
| 205 |
+
The maximum sequence length that this model might ever be used with. Typically set this to something large
|
| 206 |
+
just in case (e.g., 512 or 1024 or 2048).
|
| 207 |
+
pad_token_id (`int`, *optional*, defaults to 50256):
|
| 208 |
+
Padding token id.
|
| 209 |
+
bos_token_id (`int`, *optional*, defaults to 50256):
|
| 210 |
+
Begin of stream token id.
|
| 211 |
+
eos_token_id (`int`, *optional*, defaults to 50256):
|
| 212 |
+
End of stream token id.
|
| 213 |
+
suppress_tokens (`list[int]`, *optional*):
|
| 214 |
+
A list containing the non-speech tokens that will be used by the logit processor in the `generate`
|
| 215 |
+
function. NON_SPEECH_TOKENS and NON_SPEECH_TOKENS_MULTI each correspond to the `english-only` and the
|
| 216 |
+
`multilingual` model.
|
| 217 |
+
begin_suppress_tokens (`list[int]`, *optional*, defaults to `[220,50256]`):
|
| 218 |
+
A list containing tokens that will be suppressed at the beginning of the sampling process. Initialized as
|
| 219 |
+
the token for `" "` (`blank_token_id`) and the `eos_token_id`
|
| 220 |
+
use_weighted_layer_sum (`bool`, *optional*, defaults to `False`):
|
| 221 |
+
Whether to use a weighted average of layer outputs with learned weights. Only relevant when using an
|
| 222 |
+
instance of [`WhisperForAudioClassification`].
|
| 223 |
+
classifier_proj_size (`int`, *optional*, defaults to 256):
|
| 224 |
+
Dimensionality of the projection before token mean-pooling for classification. Only relevant when using an
|
| 225 |
+
instance of [`WhisperForAudioClassification`].
|
| 226 |
+
apply_spec_augment (`bool`, *optional*, defaults to `False`):
|
| 227 |
+
Whether to apply *SpecAugment* data augmentation to the outputs of the feature encoder. For reference see
|
| 228 |
+
[SpecAugment: A Simple Data Augmentation Method for Automatic Speech
|
| 229 |
+
Recognition](https://huggingface.co/papers/1904.08779).
|
| 230 |
+
mask_time_prob (`float`, *optional*, defaults to 0.05):
|
| 231 |
+
Percentage (between 0 and 1) of all feature vectors along the time axis which will be masked. The masking
|
| 232 |
+
procedure generates `mask_time_prob*len(time_axis)/mask_time_length` independent masks over the axis. If
|
| 233 |
+
reasoning from the probability of each feature vector to be chosen as the start of the vector span to be
|
| 234 |
+
masked, *mask_time_prob* should be `prob_vector_start*mask_time_length`. Note that overlap may decrease the
|
| 235 |
+
actual percentage of masked vectors. This is only relevant if `apply_spec_augment == True`.
|
| 236 |
+
mask_time_length (`int`, *optional*, defaults to 10):
|
| 237 |
+
Length of vector span along the time axis.
|
| 238 |
+
mask_time_min_masks (`int`, *optional*, defaults to 2),:
|
| 239 |
+
The minimum number of masks of length `mask_feature_length` generated along the time axis, each time step,
|
| 240 |
+
irrespectively of `mask_feature_prob`. Only relevant if ''mask_time_prob*len(time_axis)/mask_time_length <
|
| 241 |
+
mask_time_min_masks''
|
| 242 |
+
mask_feature_prob (`float`, *optional*, defaults to 0.0):
|
| 243 |
+
Percentage (between 0 and 1) of all feature vectors along the feature axis which will be masked. The
|
| 244 |
+
masking procedure generates `mask_feature_prob*len(feature_axis)/mask_time_length` independent masks over
|
| 245 |
+
the axis. If reasoning from the probability of each feature vector to be chosen as the start of the vector
|
| 246 |
+
span to be masked, *mask_feature_prob* should be `prob_vector_start*mask_feature_length`. Note that overlap
|
| 247 |
+
may decrease the actual percentage of masked vectors. This is only relevant if `apply_spec_augment is
|
| 248 |
+
True`.
|
| 249 |
+
mask_feature_length (`int`, *optional*, defaults to 10):
|
| 250 |
+
Length of vector span along the feature axis.
|
| 251 |
+
mask_feature_min_masks (`int`, *optional*, defaults to 0),:
|
| 252 |
+
The minimum number of masks of length `mask_feature_length` generated along the feature axis, each time
|
| 253 |
+
step, irrespectively of `mask_feature_prob`. Only relevant if
|
| 254 |
+
`mask_feature_prob*len(feature_axis)/mask_feature_length < mask_feature_min_masks`.
|
| 255 |
+
median_filter_width (`int`, *optional*, defaults to 7):
|
| 256 |
+
Width of the median filter used to smoothen to cross-attention outputs when computing token timestamps.
|
| 257 |
+
Should be an odd number.
|
| 258 |
+
|
| 259 |
+
Example:
|
| 260 |
+
|
| 261 |
+
```python
|
| 262 |
+
>>> from transformers import WhisperConfig, WhisperModel
|
| 263 |
+
|
| 264 |
+
>>> # Initializing a Whisper tiny style configuration
|
| 265 |
+
>>> configuration = WhisperConfig()
|
| 266 |
+
|
| 267 |
+
>>> # Initializing a model (with random weights) from the tiny style configuration
|
| 268 |
+
>>> model = WhisperModel(configuration)
|
| 269 |
+
|
| 270 |
+
>>> # Accessing the model configuration
|
| 271 |
+
>>> configuration = model.config
|
| 272 |
+
```"""
|
| 273 |
+
|
| 274 |
+
model_type = "whisper"
|
| 275 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 276 |
+
attribute_map = {
|
| 277 |
+
"num_key_value_heads": "encoder_attention_heads",
|
| 278 |
+
"num_attention_heads": "encoder_attention_heads",
|
| 279 |
+
"hidden_size": "d_model",
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
def __init__(
|
| 283 |
+
self,
|
| 284 |
+
vocab_size=51866,
|
| 285 |
+
num_mel_bins=128,
|
| 286 |
+
encoder_layers=32, # 从 JSON 中的 encoder_layers 获取
|
| 287 |
+
encoder_attention_heads=20, # 从 JSON 中的 encoder_attention_heads 获取
|
| 288 |
+
decoder_layers=32, # 从 JSON 中的 decoder_layers 获取
|
| 289 |
+
decoder_attention_heads=20, # 从 JSON 中的 decoder_attention_heads 获取
|
| 290 |
+
decoder_ffn_dim=5120, # 从 JSON 中的 decoder_ffn_dim 获取
|
| 291 |
+
encoder_ffn_dim=5120, # 从 JSON 中的 encoder_ffn_dim 获取
|
| 292 |
+
encoder_layerdrop=0.0,
|
| 293 |
+
decoder_layerdrop=0.0,
|
| 294 |
+
decoder_start_token_id=50258, # 从 JSON 中的 decoder_start_token_id 获取
|
| 295 |
+
use_cache=True,
|
| 296 |
+
is_encoder_decoder=True,
|
| 297 |
+
activation_function="gelu",
|
| 298 |
+
d_model=1280, # 从 JSON 中的 d_model 获取
|
| 299 |
+
dropout=0.0,
|
| 300 |
+
attention_dropout=0.0,
|
| 301 |
+
activation_dropout=0.0,
|
| 302 |
+
init_std=0.02,
|
| 303 |
+
scale_embedding=False,
|
| 304 |
+
max_source_positions=1500,
|
| 305 |
+
max_target_positions=448,
|
| 306 |
+
pad_token_id=50256,
|
| 307 |
+
bos_token_id=50257, # 从 JSON 中的 bos_token_id 获取
|
| 308 |
+
eos_token_id=50257, # 从 JSON 中的 eos_token_id 获取
|
| 309 |
+
suppress_tokens=None,
|
| 310 |
+
begin_suppress_tokens=[220, 50257], # 从 JSON 中的 begin_suppress_tokens 获取
|
| 311 |
+
use_weighted_layer_sum=False,
|
| 312 |
+
classifier_proj_size=256,
|
| 313 |
+
apply_spec_augment=False,
|
| 314 |
+
mask_time_prob=0.05,
|
| 315 |
+
mask_time_length=10,
|
| 316 |
+
mask_time_min_masks=2,
|
| 317 |
+
mask_feature_prob=0.0,
|
| 318 |
+
mask_feature_length=10,
|
| 319 |
+
mask_feature_min_masks=0,
|
| 320 |
+
median_filter_width=7,
|
| 321 |
+
tie_word_embeddings=True, # JSON 未明确说明,通常为 True
|
| 322 |
+
second_per_window=0.5, # JSON 未提供,保留原样
|
| 323 |
+
second_stride=0.5, # JSON 未提供,保留原样
|
| 324 |
+
qformer_config=None, # JSON 未提供,保留原样
|
| 325 |
+
**kwargs,
|
| 326 |
+
):
|
| 327 |
+
if isinstance(qformer_config, dict):
|
| 328 |
+
self.qformer_config = BertConfig(**qformer_config)
|
| 329 |
+
elif qformer_config is None:
|
| 330 |
+
self.qformer_config = BertConfig()
|
| 331 |
+
self.second_per_window = second_per_window
|
| 332 |
+
self.second_stride = second_stride
|
| 333 |
+
|
| 334 |
+
self.vocab_size = vocab_size
|
| 335 |
+
self.num_mel_bins = num_mel_bins
|
| 336 |
+
self.d_model = d_model
|
| 337 |
+
self.encoder_layers = encoder_layers
|
| 338 |
+
self.encoder_attention_heads = encoder_attention_heads
|
| 339 |
+
self.decoder_layers = decoder_layers
|
| 340 |
+
self.decoder_attention_heads = decoder_attention_heads
|
| 341 |
+
self.decoder_ffn_dim = decoder_ffn_dim
|
| 342 |
+
self.encoder_ffn_dim = encoder_ffn_dim
|
| 343 |
+
self.dropout = dropout
|
| 344 |
+
self.attention_dropout = attention_dropout
|
| 345 |
+
self.activation_dropout = activation_dropout
|
| 346 |
+
self.activation_function = activation_function
|
| 347 |
+
self.init_std = init_std
|
| 348 |
+
self.encoder_layerdrop = encoder_layerdrop
|
| 349 |
+
self.decoder_layerdrop = decoder_layerdrop
|
| 350 |
+
self.use_cache = use_cache
|
| 351 |
+
self.num_hidden_layers = encoder_layers
|
| 352 |
+
self.scale_embedding = scale_embedding # scale factor will be sqrt(d_model) if True
|
| 353 |
+
self.max_source_positions = max_source_positions
|
| 354 |
+
self.max_target_positions = max_target_positions
|
| 355 |
+
|
| 356 |
+
# Audio Classification-specific parameters. Feel free to ignore for other classes.
|
| 357 |
+
self.classifier_proj_size = classifier_proj_size
|
| 358 |
+
self.use_weighted_layer_sum = use_weighted_layer_sum
|
| 359 |
+
|
| 360 |
+
# fine-tuning config parameters for SpecAugment: https://huggingface.co/papers/1904.08779
|
| 361 |
+
self.apply_spec_augment = apply_spec_augment
|
| 362 |
+
self.mask_time_prob = mask_time_prob
|
| 363 |
+
self.mask_time_length = mask_time_length
|
| 364 |
+
self.mask_time_min_masks = mask_time_min_masks
|
| 365 |
+
self.mask_feature_prob = mask_feature_prob
|
| 366 |
+
self.mask_feature_length = mask_feature_length
|
| 367 |
+
self.mask_feature_min_masks = mask_feature_min_masks
|
| 368 |
+
|
| 369 |
+
self.median_filter_width = median_filter_width
|
| 370 |
+
self.pad_token_id = pad_token_id
|
| 371 |
+
self.bos_token_id = bos_token_id
|
| 372 |
+
self.eos_token_id = eos_token_id
|
| 373 |
+
self.decoder_start_token_id = decoder_start_token_id
|
| 374 |
+
self.tie_word_embeddings = tie_word_embeddings
|
| 375 |
+
|
| 376 |
+
super().__init__(
|
| 377 |
+
is_encoder_decoder=is_encoder_decoder,
|
| 378 |
+
suppress_tokens=suppress_tokens,
|
| 379 |
+
begin_suppress_tokens=begin_suppress_tokens,
|
| 380 |
+
**kwargs,
|
| 381 |
+
)
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
# class WhisperConfig(PreTrainedConfig):
|
| 385 |
+
|
| 386 |
+
# model_type = "whisper"
|
| 387 |
+
# keys_to_ignore_at_inference = ["past_key_values"]
|
| 388 |
+
# attribute_map = {
|
| 389 |
+
# "num_key_value_heads": "encoder_attention_heads",
|
| 390 |
+
# "num_attention_heads": "encoder_attention_heads",
|
| 391 |
+
# "hidden_size": "d_model",
|
| 392 |
+
# }
|
| 393 |
+
|
| 394 |
+
# def __init__(
|
| 395 |
+
# self,
|
| 396 |
+
# num_mel_bins=128,
|
| 397 |
+
# encoder_layers=32,
|
| 398 |
+
# encoder_attention_heads=20,
|
| 399 |
+
# encoder_ffn_dim=5120,
|
| 400 |
+
# encoder_layerdrop=0.0,
|
| 401 |
+
# use_cache=True,
|
| 402 |
+
# activation_function="gelu",
|
| 403 |
+
# d_model=1280,
|
| 404 |
+
# dropout=0.0,
|
| 405 |
+
# attention_dropout=0.0,
|
| 406 |
+
# activation_dropout=0.0,
|
| 407 |
+
# init_std=0.02,
|
| 408 |
+
# scale_embedding=False,
|
| 409 |
+
# max_source_positions=1500,
|
| 410 |
+
# second_per_window=0.5,
|
| 411 |
+
# second_stride=0.5,
|
| 412 |
+
# qformer_config=None,
|
| 413 |
+
# **kwargs,
|
| 414 |
+
# ):
|
| 415 |
+
# if isinstance(qformer_config, dict):
|
| 416 |
+
# self.qformer_config = BertConfig(**qformer_config)
|
| 417 |
+
# elif qformer_config is None:
|
| 418 |
+
# self.qformer_config = BertConfig()
|
| 419 |
+
# self.num_mel_bins = num_mel_bins
|
| 420 |
+
# self.d_model = d_model
|
| 421 |
+
# self.encoder_layers = encoder_layers
|
| 422 |
+
# self.encoder_attention_heads = encoder_attention_heads
|
| 423 |
+
# self.encoder_ffn_dim = encoder_ffn_dim
|
| 424 |
+
# self.dropout = dropout
|
| 425 |
+
# self.attention_dropout = attention_dropout
|
| 426 |
+
# self.activation_dropout = activation_dropout
|
| 427 |
+
# self.activation_function = activation_function
|
| 428 |
+
# self.init_std = init_std
|
| 429 |
+
# self.encoder_layerdrop = encoder_layerdrop
|
| 430 |
+
# self.use_cache = use_cache
|
| 431 |
+
# self.num_hidden_layers = encoder_layers
|
| 432 |
+
# self.scale_embedding = scale_embedding # scale factor will be sqrt(d_model) if True
|
| 433 |
+
# self.max_source_positions = max_source_positions
|
| 434 |
+
# self.second_per_window = second_per_window
|
| 435 |
+
# self.second_stride = second_stride
|
| 436 |
+
|
| 437 |
+
# super().__init__(**kwargs)
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
class Qwen3_5TextConfig(PreTrainedConfig):
|
| 441 |
+
r"""
|
| 442 |
+
This is the configuration class to store the configuration of a [`Qwen3_5TextModel`]. It is used to instantiate a
|
| 443 |
+
Qwen3_5 model according to the specified arguments, defining the model architecture.
|
| 444 |
+
Instantiating a configuration with the defaults will yield a similar configuration to that of
|
| 445 |
+
Qwen3.5-9B-Instruct [Qwen/Qwen3.5-9B-Instruct](https://huggingface.co/Qwen/Qwen3.5-9B-Instruct).
|
| 446 |
+
|
| 447 |
+
Configuration objects inherit from [`PreTrainedConfig`] and can be used to control the model outputs. Read the
|
| 448 |
+
documentation from [`PreTrainedConfig`] for more information.
|
| 449 |
+
|
| 450 |
+
|
| 451 |
+
Args:
|
| 452 |
+
vocab_size (`int`, *optional*, defaults to 248320):
|
| 453 |
+
Vocabulary size of the model. Defines the number of different tokens that can be represented by the
|
| 454 |
+
`inputs_ids`.
|
| 455 |
+
hidden_size (`int`, *optional*, defaults to 4096):
|
| 456 |
+
Dimension of the hidden representations.
|
| 457 |
+
intermediate_size (`int`, *optional*, defaults to 12288):
|
| 458 |
+
Dimension of the MLP representations.
|
| 459 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
| 460 |
+
Number of hidden layers in the Transformer encoder.
|
| 461 |
+
num_attention_heads (`int`, *optional*, defaults to 16):
|
| 462 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
| 463 |
+
num_key_value_heads (`int`, *optional*, defaults to 4):
|
| 464 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
| 465 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
| 466 |
+
`num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
| 467 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
| 468 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
| 469 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `32`.
|
| 470 |
+
hidden_act (`str`, *optional*, defaults to `"silu"`):
|
| 471 |
+
The non-linear activation function in the decoder.
|
| 472 |
+
max_position_embeddings (`int`, *optional*, defaults to 32768):
|
| 473 |
+
The maximum sequence length that this model might ever be used with.
|
| 474 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 475 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 476 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
| 477 |
+
The epsilon used by the rms normalization layers.
|
| 478 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 479 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 480 |
+
relevant if `config.is_decoder=True`.
|
| 481 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 482 |
+
Whether the model's input and output word embeddings should be tied.
|
| 483 |
+
rope_parameters (`RopeParameters`, *optional*):
|
| 484 |
+
Dictionary containing the configuration parameters for the RoPE embeddings. The dictionary should contain
|
| 485 |
+
a value for `rope_theta` and optionally parameters used for scaling in case you want to use RoPE
|
| 486 |
+
with longer `max_position_embeddings`.
|
| 487 |
+
attention_bias (`bool`, *optional*, defaults to `False`):
|
| 488 |
+
Whether to use a bias in the query, key, value and output projection layers during self-attention.
|
| 489 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 490 |
+
The dropout ratio for the attention probabilities.
|
| 491 |
+
head_dim (`int`, *optional*, defaults to 256):
|
| 492 |
+
Projection weights dimension in multi-head attention.
|
| 493 |
+
linear_conv_kernel_dim (`int`, *optional*, defaults to 4):
|
| 494 |
+
Kernel size of the convolution used in linear attention layers.
|
| 495 |
+
linear_key_head_dim (`int`, *optional*, defaults to 128):
|
| 496 |
+
Dimension of each key head in linear attention.
|
| 497 |
+
linear_value_head_dim (`int`, *optional*, defaults to 128):
|
| 498 |
+
Dimension of each value head in linear attention.
|
| 499 |
+
linear_num_key_heads (`int`, *optional*, defaults to 16):
|
| 500 |
+
Number of key heads used in linear attention layers.
|
| 501 |
+
linear_num_value_heads (`int`, *optional*, defaults to 32):
|
| 502 |
+
Number of value heads used in linear attention layers.
|
| 503 |
+
layer_types (`list[str]`, *optional*):
|
| 504 |
+
Types of each layer (attention or linear).
|
| 505 |
+
pad_token_id (`int`, *optional*):
|
| 506 |
+
Padding token id.
|
| 507 |
+
bos_token_id (`int`, *optional*):
|
| 508 |
+
Beginning of stream token id.
|
| 509 |
+
eos_token_id (`int`, *optional*):
|
| 510 |
+
End of stream token id.
|
| 511 |
+
|
| 512 |
+
```python
|
| 513 |
+
>>> from transformers import Qwen3_5TextModel, Qwen3_5TextConfig
|
| 514 |
+
|
| 515 |
+
>>> # Initializing a Qwen3.5 style configuration
|
| 516 |
+
>>> configuration = Qwen3_5TextConfig()
|
| 517 |
+
|
| 518 |
+
>>> # Initializing a model from the Qwen3.5-9B style configuration
|
| 519 |
+
>>> model = Qwen3_5TextModel(configuration)
|
| 520 |
+
|
| 521 |
+
>>> # Accessing the model configuration
|
| 522 |
+
>>> configuration = model.config
|
| 523 |
+
```
|
| 524 |
+
"""
|
| 525 |
+
|
| 526 |
+
model_type = "qwen3_5_text"
|
| 527 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 528 |
+
|
| 529 |
+
base_model_tp_plan = {
|
| 530 |
+
"layers.*.self_attn.q_proj": "colwise",
|
| 531 |
+
"layers.*.self_attn.k_proj": "colwise",
|
| 532 |
+
"layers.*.self_attn.v_proj": "colwise",
|
| 533 |
+
"layers.*.self_attn.o_proj": "rowwise",
|
| 534 |
+
"layers.*.mlp.gate_proj": "colwise",
|
| 535 |
+
"layers.*.mlp.up_proj": "colwise",
|
| 536 |
+
"layers.*.mlp.down_proj": "rowwise",
|
| 537 |
+
}
|
| 538 |
+
base_model_pp_plan = {
|
| 539 |
+
"embed_tokens": (["input_ids"], ["inputs_embeds"]),
|
| 540 |
+
"layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
|
| 541 |
+
"norm": (["hidden_states"], ["hidden_states"]),
|
| 542 |
+
}
|
| 543 |
+
base_config_key = "text_config"
|
| 544 |
+
|
| 545 |
+
def __init__(
|
| 546 |
+
self,
|
| 547 |
+
vocab_size=248320,
|
| 548 |
+
hidden_size=4096,
|
| 549 |
+
intermediate_size=12288,
|
| 550 |
+
num_hidden_layers=32,
|
| 551 |
+
num_attention_heads=16,
|
| 552 |
+
num_key_value_heads=4,
|
| 553 |
+
hidden_act="silu",
|
| 554 |
+
max_position_embeddings=32768,
|
| 555 |
+
initializer_range=0.02,
|
| 556 |
+
rms_norm_eps=1e-6,
|
| 557 |
+
use_cache=True,
|
| 558 |
+
tie_word_embeddings=False,
|
| 559 |
+
rope_parameters: RopeParameters | dict[str, RopeParameters] | None = None,
|
| 560 |
+
attention_bias=False,
|
| 561 |
+
attention_dropout=0.0,
|
| 562 |
+
head_dim=256,
|
| 563 |
+
linear_conv_kernel_dim=4,
|
| 564 |
+
linear_key_head_dim=128,
|
| 565 |
+
linear_value_head_dim=128,
|
| 566 |
+
linear_num_key_heads=16,
|
| 567 |
+
linear_num_value_heads=32,
|
| 568 |
+
layer_types=None,
|
| 569 |
+
pad_token_id: int | None = None,
|
| 570 |
+
bos_token_id: int | None = None,
|
| 571 |
+
eos_token_id: int | None = None,
|
| 572 |
+
**kwargs,
|
| 573 |
+
):
|
| 574 |
+
kwargs["ignore_keys_at_rope_validation"] = {"mrope_section", "mrope_interleaved"}
|
| 575 |
+
self.pad_token_id = pad_token_id
|
| 576 |
+
self.bos_token_id = bos_token_id
|
| 577 |
+
self.eos_token_id = eos_token_id
|
| 578 |
+
self.tie_word_embeddings = tie_word_embeddings
|
| 579 |
+
self.vocab_size = vocab_size
|
| 580 |
+
self.max_position_embeddings = max_position_embeddings
|
| 581 |
+
self.hidden_size = hidden_size
|
| 582 |
+
self.intermediate_size = intermediate_size
|
| 583 |
+
self.num_hidden_layers = num_hidden_layers
|
| 584 |
+
self.num_attention_heads = num_attention_heads
|
| 585 |
+
self.num_key_value_heads = num_key_value_heads
|
| 586 |
+
self.hidden_act = hidden_act
|
| 587 |
+
self.initializer_range = initializer_range
|
| 588 |
+
self.rms_norm_eps = rms_norm_eps
|
| 589 |
+
self.use_cache = use_cache
|
| 590 |
+
self.attention_bias = attention_bias
|
| 591 |
+
self.attention_dropout = attention_dropout
|
| 592 |
+
self.head_dim = head_dim
|
| 593 |
+
self.rope_parameters = rope_parameters
|
| 594 |
+
kwargs.setdefault("partial_rotary_factor", 0.25) # assign default for BC
|
| 595 |
+
|
| 596 |
+
self.layer_types = layer_types
|
| 597 |
+
if self.layer_types is None:
|
| 598 |
+
interval_pattern = kwargs.get("full_attention_interval", 4)
|
| 599 |
+
self.layer_types = [
|
| 600 |
+
"linear_attention" if bool((i + 1) % interval_pattern) else "full_attention"
|
| 601 |
+
for i in range(self.num_hidden_layers)
|
| 602 |
+
]
|
| 603 |
+
layer_type_validation(self.layer_types, self.num_hidden_layers)
|
| 604 |
+
|
| 605 |
+
# linear attention part
|
| 606 |
+
self.linear_conv_kernel_dim = linear_conv_kernel_dim
|
| 607 |
+
self.linear_key_head_dim = linear_key_head_dim
|
| 608 |
+
self.linear_value_head_dim = linear_value_head_dim
|
| 609 |
+
self.linear_num_key_heads = linear_num_key_heads
|
| 610 |
+
self.linear_num_value_heads = linear_num_value_heads
|
| 611 |
+
super().__init__(**kwargs)
|
| 612 |
+
|
| 613 |
+
|
| 614 |
+
class Qwen3_5VisionConfig(PreTrainedConfig):
|
| 615 |
+
model_type = "qwen3_5"
|
| 616 |
+
base_config_key = "vision_config"
|
| 617 |
+
|
| 618 |
+
def __init__(
|
| 619 |
+
self,
|
| 620 |
+
depth=27,
|
| 621 |
+
hidden_size=1152,
|
| 622 |
+
hidden_act="gelu_pytorch_tanh",
|
| 623 |
+
intermediate_size=4304,
|
| 624 |
+
num_heads=16,
|
| 625 |
+
in_channels=3,
|
| 626 |
+
patch_size=16,
|
| 627 |
+
spatial_merge_size=2,
|
| 628 |
+
temporal_patch_size=2,
|
| 629 |
+
out_hidden_size=3584,
|
| 630 |
+
num_position_embeddings=2304,
|
| 631 |
+
initializer_range=0.02,
|
| 632 |
+
**kwargs,
|
| 633 |
+
):
|
| 634 |
+
super().__init__(**kwargs)
|
| 635 |
+
|
| 636 |
+
self.depth = depth
|
| 637 |
+
self.hidden_size = hidden_size
|
| 638 |
+
self.hidden_act = hidden_act
|
| 639 |
+
self.intermediate_size = intermediate_size
|
| 640 |
+
self.num_heads = num_heads
|
| 641 |
+
self.in_channels = in_channels
|
| 642 |
+
self.patch_size = patch_size
|
| 643 |
+
self.spatial_merge_size = spatial_merge_size
|
| 644 |
+
self.temporal_patch_size = temporal_patch_size
|
| 645 |
+
self.out_hidden_size = out_hidden_size
|
| 646 |
+
self.num_position_embeddings = num_position_embeddings
|
| 647 |
+
self.initializer_range = initializer_range
|
| 648 |
+
|
| 649 |
+
|
| 650 |
+
class WeMMQwen3_5Config(PreTrainedConfig):
|
| 651 |
+
r"""
|
| 652 |
+
This is the configuration class to store the configuration of a [`Qwen3_5Model`]. It is used to instantiate a
|
| 653 |
+
Qwen3.5 model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
| 654 |
+
with the defaults will yield a similar configuration to that of
|
| 655 |
+
Qwen3.5-9B-Instruct [Qwen/Qwen3.5-9B-Instruct](https://huggingface.co/Qwen/Qwen3.5-9B-Instruct).
|
| 656 |
+
|
| 657 |
+
Configuration objects inherit from [`PreTrainedConfig`] and can be used to control the model outputs. Read the
|
| 658 |
+
documentation from [`PreTrainedConfig`] for more information.
|
| 659 |
+
|
| 660 |
+
|
| 661 |
+
Args:
|
| 662 |
+
text_config (`Union[PreTrainedConfig, dict]`, *optional*, defaults to `Qwen3_5TextConfig`):
|
| 663 |
+
The config object or dictionary of the text backbone.
|
| 664 |
+
vision_config (`Union[PreTrainedConfig, dict]`, *optional*, defaults to `Qwen3_5VisionConfig`):
|
| 665 |
+
The config object or dictionary of the vision backbone.
|
| 666 |
+
image_token_id (`int`, *optional*, defaults to 248056):
|
| 667 |
+
The image token index to encode the image prompt.
|
| 668 |
+
video_token_id (`int`, *optional*, defaults to 248057):
|
| 669 |
+
The video token index to encode the image prompt.
|
| 670 |
+
vision_start_token_id (`int`, *optional*, defaults to 248053):
|
| 671 |
+
The start token index to encode the image prompt.
|
| 672 |
+
vision_end_token_id (`int`, *optional*, defaults to 248054):
|
| 673 |
+
The end token index to encode the image prompt.
|
| 674 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 675 |
+
Whether to tie the word embeddings.
|
| 676 |
+
|
| 677 |
+
```python
|
| 678 |
+
>>> from transformers import WeMMVideoForConditionalGeneration, WeMMQwen3_5Config
|
| 679 |
+
|
| 680 |
+
>>> # Initializing a Qwen3.5 style configuration
|
| 681 |
+
>>> configuration = WeMMQwen3_5Config()
|
| 682 |
+
|
| 683 |
+
>>> # Initializing a model from the Qwen3.5-9B style configuration
|
| 684 |
+
>>> model = WeMMVideoForConditionalGeneration(configuration)
|
| 685 |
+
|
| 686 |
+
>>> # Accessing the model configuration
|
| 687 |
+
>>> configuration = model.config
|
| 688 |
+
```"""
|
| 689 |
+
|
| 690 |
+
model_type = "qwen3_5"
|
| 691 |
+
sub_configs = {"vision_config": Qwen3_5VisionConfig, "text_config": Qwen3_5TextConfig, "audio_config": WhisperConfig}
|
| 692 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 693 |
+
|
| 694 |
+
def __init__(
|
| 695 |
+
self,
|
| 696 |
+
text_config=None,
|
| 697 |
+
vision_config=None,
|
| 698 |
+
image_token_id=248056,
|
| 699 |
+
video_token_id=248057,
|
| 700 |
+
vision_start_token_id=248053,
|
| 701 |
+
vision_end_token_id=248054,
|
| 702 |
+
tie_word_embeddings=False,
|
| 703 |
+
audio_config=None,
|
| 704 |
+
audio_token_id=248076,
|
| 705 |
+
**kwargs,
|
| 706 |
+
):
|
| 707 |
+
if isinstance(vision_config, dict):
|
| 708 |
+
self.vision_config = self.sub_configs["vision_config"](**vision_config)
|
| 709 |
+
elif vision_config is None:
|
| 710 |
+
self.vision_config = self.sub_configs["vision_config"]()
|
| 711 |
+
|
| 712 |
+
if isinstance(text_config, dict):
|
| 713 |
+
self.text_config = self.sub_configs["text_config"](**text_config)
|
| 714 |
+
elif text_config is None:
|
| 715 |
+
self.text_config = self.sub_configs["text_config"]()
|
| 716 |
+
|
| 717 |
+
if isinstance(audio_config, dict):
|
| 718 |
+
self.audio_config = self.sub_configs["audio_config"](**audio_config)
|
| 719 |
+
elif audio_config is None:
|
| 720 |
+
self.audio_config = self.sub_configs["audio_config"]()
|
| 721 |
+
|
| 722 |
+
self.image_token_id = image_token_id
|
| 723 |
+
self.video_token_id = video_token_id
|
| 724 |
+
self.audio_token_id = audio_token_id
|
| 725 |
+
self.vision_start_token_id = vision_start_token_id
|
| 726 |
+
self.vision_end_token_id = vision_end_token_id
|
| 727 |
+
self.tie_word_embeddings = tie_word_embeddings
|
| 728 |
+
super().__init__(**kwargs)
|
| 729 |
+
|
| 730 |
+
|
| 731 |
+
__all__ = ["WeMMQwen3_5Config", "Qwen3_5TextConfig"]
|
generation_config.json
ADDED
|
@@ -0,0 +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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Adapted from salesforce@LAVIS. Below is the original copyright:
|
| 3 |
+
* Copyright (c) 2023, salesforce.com, inc.
|
| 4 |
+
* All rights reserved.
|
| 5 |
+
* SPDX-License-Identifier: BSD-3-Clause
|
| 6 |
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
| 7 |
+
* By Junnan Li
|
| 8 |
+
* Based on huggingface code base
|
| 9 |
+
* https://github.com/huggingface/transformers/blob/v4.15.0/src/transformers/models/bert
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import math
|
| 13 |
+
import os
|
| 14 |
+
import warnings
|
| 15 |
+
from dataclasses import dataclass
|
| 16 |
+
from typing import Optional, Tuple, Dict, Any
|
| 17 |
+
|
| 18 |
+
import torch
|
| 19 |
+
from torch import Tensor, device, dtype, nn
|
| 20 |
+
import torch.utils.checkpoint
|
| 21 |
+
from torch import nn
|
| 22 |
+
from torch.nn import CrossEntropyLoss
|
| 23 |
+
import torch.nn.functional as F
|
| 24 |
+
|
| 25 |
+
from transformers.activations import ACT2FN
|
| 26 |
+
from transformers.file_utils import (
|
| 27 |
+
ModelOutput,
|
| 28 |
+
)
|
| 29 |
+
from transformers.modeling_outputs import (
|
| 30 |
+
BaseModelOutputWithPastAndCrossAttentions,
|
| 31 |
+
BaseModelOutputWithPoolingAndCrossAttentions,
|
| 32 |
+
CausalLMOutputWithCrossAttentions,
|
| 33 |
+
MaskedLMOutput,
|
| 34 |
+
MultipleChoiceModelOutput,
|
| 35 |
+
NextSentencePredictorOutput,
|
| 36 |
+
QuestionAnsweringModelOutput,
|
| 37 |
+
SequenceClassifierOutput,
|
| 38 |
+
TokenClassifierOutput,
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
from transformers.pytorch_utils import apply_chunking_to_forward, prune_linear_layer
|
| 42 |
+
from transformers.modeling_utils import (
|
| 43 |
+
PreTrainedModel,
|
| 44 |
+
)
|
| 45 |
+
from transformers.utils import logging
|
| 46 |
+
from transformers.models.bert.configuration_bert import BertConfig
|
| 47 |
+
|
| 48 |
+
logger = logging.get_logger(__name__)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
try:
|
| 52 |
+
from transformers.pytorch_utils import find_pruneable_heads_and_indices
|
| 53 |
+
except ImportError:
|
| 54 |
+
# Fallback for transformers >= 4.40.0 where this function was removed
|
| 55 |
+
from typing import List, Set
|
| 56 |
+
def find_pruneable_heads_and_indices(
|
| 57 |
+
heads: List[int], n_heads: int, head_dim: int, already_pruned_heads: Set[int]
|
| 58 |
+
):
|
| 59 |
+
mask = torch.ones(n_heads, head_dim)
|
| 60 |
+
for head in set(heads) - already_pruned_heads:
|
| 61 |
+
mask[head] = 0
|
| 62 |
+
mask = mask.view(-1).contiguous().eq(1)
|
| 63 |
+
return set(heads) - already_pruned_heads, torch.arange(len(mask))[mask].long()
|
| 64 |
+
|
| 65 |
+
class BertEmbeddings(nn.Module):
|
| 66 |
+
"""Construct the embeddings from word and position embeddings."""
|
| 67 |
+
|
| 68 |
+
def __init__(self, config):
|
| 69 |
+
super().__init__()
|
| 70 |
+
self.word_embeddings = None
|
| 71 |
+
self.position_embeddings = None
|
| 72 |
+
|
| 73 |
+
# self.LayerNorm is not snake-cased to stick with TensorFlow model variable name and be able to load
|
| 74 |
+
# any TensorFlow checkpoint file
|
| 75 |
+
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
| 76 |
+
self.dropout = nn.Dropout(config.hidden_dropout_prob)
|
| 77 |
+
|
| 78 |
+
# position_ids (1, len position emb) is contiguous in memory and exported when serialized
|
| 79 |
+
self.register_buffer(
|
| 80 |
+
"position_ids", torch.arange(config.max_position_embeddings).expand((1, -1)),
|
| 81 |
+
)
|
| 82 |
+
self.position_embedding_type = getattr(
|
| 83 |
+
config, "position_embedding_type", "absolute"
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
self.config = config
|
| 87 |
+
|
| 88 |
+
def forward(
|
| 89 |
+
self,
|
| 90 |
+
input_ids=None,
|
| 91 |
+
position_ids=None,
|
| 92 |
+
query_embeds=None,
|
| 93 |
+
past_key_values_length=0,
|
| 94 |
+
):
|
| 95 |
+
if input_ids is not None:
|
| 96 |
+
seq_length = input_ids.size()[1]
|
| 97 |
+
else:
|
| 98 |
+
seq_length = 0
|
| 99 |
+
|
| 100 |
+
if position_ids is None:
|
| 101 |
+
position_ids = self.position_ids[
|
| 102 |
+
:, past_key_values_length : seq_length + past_key_values_length
|
| 103 |
+
].clone()
|
| 104 |
+
|
| 105 |
+
if input_ids is not None:
|
| 106 |
+
embeddings = self.word_embeddings(input_ids)
|
| 107 |
+
if self.position_embedding_type == "absolute":
|
| 108 |
+
position_embeddings = self.position_embeddings(position_ids)
|
| 109 |
+
embeddings = embeddings + position_embeddings
|
| 110 |
+
|
| 111 |
+
if query_embeds is not None:
|
| 112 |
+
embeddings = torch.cat((query_embeds, embeddings), dim=1)
|
| 113 |
+
else:
|
| 114 |
+
embeddings = query_embeds
|
| 115 |
+
|
| 116 |
+
embeddings = self.LayerNorm(embeddings)
|
| 117 |
+
embeddings = self.dropout(embeddings)
|
| 118 |
+
return embeddings
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
class BertSelfAttention(nn.Module):
|
| 122 |
+
def __init__(self, config, is_cross_attention):
|
| 123 |
+
super().__init__()
|
| 124 |
+
self.config = config
|
| 125 |
+
if config.hidden_size % config.num_attention_heads != 0 and not hasattr(
|
| 126 |
+
config, "embedding_size"
|
| 127 |
+
):
|
| 128 |
+
raise ValueError(
|
| 129 |
+
"The hidden size (%d) is not a multiple of the number of attention "
|
| 130 |
+
"heads (%d)" % (config.hidden_size, config.num_attention_heads)
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
self.num_attention_heads = config.num_attention_heads
|
| 134 |
+
self.attention_head_size = int(config.hidden_size / config.num_attention_heads)
|
| 135 |
+
self.all_head_size = self.num_attention_heads * self.attention_head_size
|
| 136 |
+
|
| 137 |
+
self.query = nn.Linear(config.hidden_size, self.all_head_size)
|
| 138 |
+
if is_cross_attention:
|
| 139 |
+
self.key = nn.Linear(config.encoder_width, self.all_head_size)
|
| 140 |
+
self.value = nn.Linear(config.encoder_width, self.all_head_size)
|
| 141 |
+
else:
|
| 142 |
+
self.key = nn.Linear(config.hidden_size, self.all_head_size)
|
| 143 |
+
self.value = nn.Linear(config.hidden_size, self.all_head_size)
|
| 144 |
+
|
| 145 |
+
self.dropout = nn.Dropout(config.attention_probs_dropout_prob)
|
| 146 |
+
self.position_embedding_type = getattr(
|
| 147 |
+
config, "position_embedding_type", "absolute"
|
| 148 |
+
)
|
| 149 |
+
if (
|
| 150 |
+
self.position_embedding_type == "relative_key"
|
| 151 |
+
or self.position_embedding_type == "relative_key_query"
|
| 152 |
+
):
|
| 153 |
+
self.max_position_embeddings = config.max_position_embeddings
|
| 154 |
+
self.distance_embedding = nn.Embedding(
|
| 155 |
+
2 * config.max_position_embeddings - 1, self.attention_head_size
|
| 156 |
+
)
|
| 157 |
+
self.save_attention = False
|
| 158 |
+
|
| 159 |
+
def save_attn_gradients(self, attn_gradients):
|
| 160 |
+
self.attn_gradients = attn_gradients
|
| 161 |
+
|
| 162 |
+
def get_attn_gradients(self):
|
| 163 |
+
return self.attn_gradients
|
| 164 |
+
|
| 165 |
+
def save_attention_map(self, attention_map):
|
| 166 |
+
self.attention_map = attention_map
|
| 167 |
+
|
| 168 |
+
def get_attention_map(self):
|
| 169 |
+
return self.attention_map
|
| 170 |
+
|
| 171 |
+
def transpose_for_scores(self, x):
|
| 172 |
+
new_x_shape = x.size()[:-1] + (
|
| 173 |
+
self.num_attention_heads,
|
| 174 |
+
self.attention_head_size,
|
| 175 |
+
)
|
| 176 |
+
x = x.view(*new_x_shape)
|
| 177 |
+
return x.permute(0, 2, 1, 3)
|
| 178 |
+
|
| 179 |
+
def forward(
|
| 180 |
+
self,
|
| 181 |
+
hidden_states,
|
| 182 |
+
attention_mask=None,
|
| 183 |
+
head_mask=None,
|
| 184 |
+
encoder_hidden_states=None,
|
| 185 |
+
encoder_attention_mask=None,
|
| 186 |
+
past_key_value=None,
|
| 187 |
+
output_attentions=False,
|
| 188 |
+
):
|
| 189 |
+
|
| 190 |
+
# If this is instantiated as a cross-attention module, the keys
|
| 191 |
+
# and values come from an encoder; the attention mask needs to be
|
| 192 |
+
# such that the encoder's padding tokens are not attended to.
|
| 193 |
+
is_cross_attention = encoder_hidden_states is not None
|
| 194 |
+
|
| 195 |
+
if is_cross_attention:
|
| 196 |
+
key_layer = self.transpose_for_scores(self.key(encoder_hidden_states))
|
| 197 |
+
value_layer = self.transpose_for_scores(self.value(encoder_hidden_states))
|
| 198 |
+
attention_mask = encoder_attention_mask
|
| 199 |
+
elif past_key_value is not None:
|
| 200 |
+
key_layer = self.transpose_for_scores(self.key(hidden_states))
|
| 201 |
+
value_layer = self.transpose_for_scores(self.value(hidden_states))
|
| 202 |
+
key_layer = torch.cat([past_key_value[0], key_layer], dim=2)
|
| 203 |
+
value_layer = torch.cat([past_key_value[1], value_layer], dim=2)
|
| 204 |
+
else:
|
| 205 |
+
key_layer = self.transpose_for_scores(self.key(hidden_states))
|
| 206 |
+
value_layer = self.transpose_for_scores(self.value(hidden_states))
|
| 207 |
+
|
| 208 |
+
mixed_query_layer = self.query(hidden_states)
|
| 209 |
+
|
| 210 |
+
query_layer = self.transpose_for_scores(mixed_query_layer)
|
| 211 |
+
|
| 212 |
+
past_key_value = (key_layer, value_layer)
|
| 213 |
+
|
| 214 |
+
# Take the dot product between "query" and "key" to get the raw attention scores.
|
| 215 |
+
attention_scores = torch.matmul(query_layer, key_layer.transpose(-1, -2))
|
| 216 |
+
|
| 217 |
+
if (
|
| 218 |
+
self.position_embedding_type == "relative_key"
|
| 219 |
+
or self.position_embedding_type == "relative_key_query"
|
| 220 |
+
):
|
| 221 |
+
seq_length = hidden_states.size()[1]
|
| 222 |
+
position_ids_l = torch.arange(
|
| 223 |
+
seq_length, dtype=torch.long, device=hidden_states.device
|
| 224 |
+
).view(-1, 1)
|
| 225 |
+
position_ids_r = torch.arange(
|
| 226 |
+
seq_length, dtype=torch.long, device=hidden_states.device
|
| 227 |
+
).view(1, -1)
|
| 228 |
+
distance = position_ids_l - position_ids_r
|
| 229 |
+
positional_embedding = self.distance_embedding(
|
| 230 |
+
distance + self.max_position_embeddings - 1
|
| 231 |
+
)
|
| 232 |
+
positional_embedding = positional_embedding.to(
|
| 233 |
+
dtype=query_layer.dtype
|
| 234 |
+
) # fp16 compatibility
|
| 235 |
+
|
| 236 |
+
if self.position_embedding_type == "relative_key":
|
| 237 |
+
relative_position_scores = torch.einsum(
|
| 238 |
+
"bhld,lrd->bhlr", query_layer, positional_embedding
|
| 239 |
+
)
|
| 240 |
+
attention_scores = attention_scores + relative_position_scores
|
| 241 |
+
elif self.position_embedding_type == "relative_key_query":
|
| 242 |
+
relative_position_scores_query = torch.einsum(
|
| 243 |
+
"bhld,lrd->bhlr", query_layer, positional_embedding
|
| 244 |
+
)
|
| 245 |
+
relative_position_scores_key = torch.einsum(
|
| 246 |
+
"bhrd,lrd->bhlr", key_layer, positional_embedding
|
| 247 |
+
)
|
| 248 |
+
attention_scores = (
|
| 249 |
+
attention_scores
|
| 250 |
+
+ relative_position_scores_query
|
| 251 |
+
+ relative_position_scores_key
|
| 252 |
+
)
|
| 253 |
+
|
| 254 |
+
attention_scores = attention_scores / math.sqrt(self.attention_head_size)
|
| 255 |
+
if attention_mask is not None:
|
| 256 |
+
# Apply the attention mask is (precomputed for all layers in BertModel forward() function)
|
| 257 |
+
attention_scores = attention_scores + attention_mask
|
| 258 |
+
|
| 259 |
+
# Normalize the attention scores to probabilities.
|
| 260 |
+
attention_probs = nn.Softmax(dim=-1)(attention_scores)
|
| 261 |
+
|
| 262 |
+
if is_cross_attention and self.save_attention:
|
| 263 |
+
self.save_attention_map(attention_probs)
|
| 264 |
+
attention_probs.register_hook(self.save_attn_gradients)
|
| 265 |
+
|
| 266 |
+
# This is actually dropping out entire tokens to attend to, which might
|
| 267 |
+
# seem a bit unusual, but is taken from the original Transformer paper.
|
| 268 |
+
attention_probs_dropped = self.dropout(attention_probs)
|
| 269 |
+
|
| 270 |
+
# Mask heads if we want to
|
| 271 |
+
if head_mask is not None:
|
| 272 |
+
attention_probs_dropped = attention_probs_dropped * head_mask
|
| 273 |
+
|
| 274 |
+
context_layer = torch.matmul(attention_probs_dropped, value_layer)
|
| 275 |
+
|
| 276 |
+
context_layer = context_layer.permute(0, 2, 1, 3).contiguous()
|
| 277 |
+
new_context_layer_shape = context_layer.size()[:-2] + (self.all_head_size,)
|
| 278 |
+
context_layer = context_layer.view(*new_context_layer_shape)
|
| 279 |
+
|
| 280 |
+
outputs = (
|
| 281 |
+
(context_layer, attention_probs) if output_attentions else (context_layer,)
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
outputs = outputs + (past_key_value,)
|
| 285 |
+
return outputs
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
class BertSelfOutput(nn.Module):
|
| 289 |
+
def __init__(self, config):
|
| 290 |
+
super().__init__()
|
| 291 |
+
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
|
| 292 |
+
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
| 293 |
+
self.dropout = nn.Dropout(config.hidden_dropout_prob)
|
| 294 |
+
|
| 295 |
+
def forward(self, hidden_states, input_tensor):
|
| 296 |
+
hidden_states = self.dense(hidden_states)
|
| 297 |
+
hidden_states = self.dropout(hidden_states)
|
| 298 |
+
hidden_states = self.LayerNorm(hidden_states + input_tensor)
|
| 299 |
+
return hidden_states
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
class BertAttention(nn.Module):
|
| 303 |
+
def __init__(self, config, is_cross_attention=False):
|
| 304 |
+
super().__init__()
|
| 305 |
+
self.self = BertSelfAttention(config, is_cross_attention)
|
| 306 |
+
self.output = BertSelfOutput(config)
|
| 307 |
+
self.pruned_heads = set()
|
| 308 |
+
|
| 309 |
+
def prune_heads(self, heads):
|
| 310 |
+
if len(heads) == 0:
|
| 311 |
+
return
|
| 312 |
+
heads, index = find_pruneable_heads_and_indices(
|
| 313 |
+
heads,
|
| 314 |
+
self.self.num_attention_heads,
|
| 315 |
+
self.self.attention_head_size,
|
| 316 |
+
self.pruned_heads,
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
# Prune linear layers
|
| 320 |
+
self.self.query = prune_linear_layer(self.self.query, index)
|
| 321 |
+
self.self.key = prune_linear_layer(self.self.key, index)
|
| 322 |
+
self.self.value = prune_linear_layer(self.self.value, index)
|
| 323 |
+
self.output.dense = prune_linear_layer(self.output.dense, index, dim=1)
|
| 324 |
+
|
| 325 |
+
# Update hyper params and store pruned heads
|
| 326 |
+
self.self.num_attention_heads = self.self.num_attention_heads - len(heads)
|
| 327 |
+
self.self.all_head_size = (
|
| 328 |
+
self.self.attention_head_size * self.self.num_attention_heads
|
| 329 |
+
)
|
| 330 |
+
self.pruned_heads = self.pruned_heads.union(heads)
|
| 331 |
+
|
| 332 |
+
def forward(
|
| 333 |
+
self,
|
| 334 |
+
hidden_states,
|
| 335 |
+
attention_mask=None,
|
| 336 |
+
head_mask=None,
|
| 337 |
+
encoder_hidden_states=None,
|
| 338 |
+
encoder_attention_mask=None,
|
| 339 |
+
past_key_value=None,
|
| 340 |
+
output_attentions=False,
|
| 341 |
+
):
|
| 342 |
+
self_outputs = self.self(
|
| 343 |
+
hidden_states,
|
| 344 |
+
attention_mask,
|
| 345 |
+
head_mask,
|
| 346 |
+
encoder_hidden_states,
|
| 347 |
+
encoder_attention_mask,
|
| 348 |
+
past_key_value,
|
| 349 |
+
output_attentions,
|
| 350 |
+
)
|
| 351 |
+
attention_output = self.output(self_outputs[0], hidden_states)
|
| 352 |
+
|
| 353 |
+
outputs = (attention_output,) + self_outputs[
|
| 354 |
+
1:
|
| 355 |
+
] # add attentions if we output them
|
| 356 |
+
return outputs
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
class BertIntermediate(nn.Module):
|
| 360 |
+
def __init__(self, config):
|
| 361 |
+
super().__init__()
|
| 362 |
+
self.dense = nn.Linear(config.hidden_size, config.intermediate_size)
|
| 363 |
+
if isinstance(config.hidden_act, str):
|
| 364 |
+
self.intermediate_act_fn = ACT2FN[config.hidden_act]
|
| 365 |
+
else:
|
| 366 |
+
self.intermediate_act_fn = config.hidden_act
|
| 367 |
+
|
| 368 |
+
def forward(self, hidden_states):
|
| 369 |
+
hidden_states = self.dense(hidden_states)
|
| 370 |
+
hidden_states = self.intermediate_act_fn(hidden_states)
|
| 371 |
+
return hidden_states
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
class BertOutput(nn.Module):
|
| 375 |
+
def __init__(self, config):
|
| 376 |
+
super().__init__()
|
| 377 |
+
self.dense = nn.Linear(config.intermediate_size, config.hidden_size)
|
| 378 |
+
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
| 379 |
+
self.dropout = nn.Dropout(config.hidden_dropout_prob)
|
| 380 |
+
|
| 381 |
+
def forward(self, hidden_states, input_tensor):
|
| 382 |
+
hidden_states = self.dense(hidden_states)
|
| 383 |
+
hidden_states = self.dropout(hidden_states)
|
| 384 |
+
hidden_states = self.LayerNorm(hidden_states + input_tensor)
|
| 385 |
+
return hidden_states
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
class BertLayer(nn.Module):
|
| 389 |
+
def __init__(self, config, layer_num):
|
| 390 |
+
super().__init__()
|
| 391 |
+
self.config = config
|
| 392 |
+
self.chunk_size_feed_forward = config.chunk_size_feed_forward
|
| 393 |
+
self.seq_len_dim = 1
|
| 394 |
+
self.attention = BertAttention(config)
|
| 395 |
+
self.layer_num = layer_num
|
| 396 |
+
if (
|
| 397 |
+
self.config.add_cross_attention
|
| 398 |
+
and layer_num % self.config.cross_attention_freq == 0
|
| 399 |
+
):
|
| 400 |
+
self.crossattention = BertAttention(
|
| 401 |
+
config, is_cross_attention=self.config.add_cross_attention
|
| 402 |
+
)
|
| 403 |
+
self.has_cross_attention = True
|
| 404 |
+
else:
|
| 405 |
+
self.has_cross_attention = False
|
| 406 |
+
self.intermediate = None
|
| 407 |
+
self.output = None
|
| 408 |
+
|
| 409 |
+
self.intermediate_query = BertIntermediate(config)
|
| 410 |
+
self.output_query = BertOutput(config)
|
| 411 |
+
|
| 412 |
+
def forward(
|
| 413 |
+
self,
|
| 414 |
+
hidden_states,
|
| 415 |
+
attention_mask=None,
|
| 416 |
+
head_mask=None,
|
| 417 |
+
encoder_hidden_states=None,
|
| 418 |
+
encoder_attention_mask=None,
|
| 419 |
+
past_key_value=None,
|
| 420 |
+
output_attentions=False,
|
| 421 |
+
query_length=0,
|
| 422 |
+
):
|
| 423 |
+
# decoder uni-directional self-attention cached key/values tuple is at positions 1,2
|
| 424 |
+
self_attn_past_key_value = (
|
| 425 |
+
past_key_value[:2] if past_key_value is not None else None
|
| 426 |
+
)
|
| 427 |
+
self_attention_outputs = self.attention(
|
| 428 |
+
hidden_states,
|
| 429 |
+
attention_mask,
|
| 430 |
+
head_mask,
|
| 431 |
+
output_attentions=output_attentions,
|
| 432 |
+
past_key_value=self_attn_past_key_value,
|
| 433 |
+
)
|
| 434 |
+
attention_output = self_attention_outputs[0]
|
| 435 |
+
outputs = self_attention_outputs[1:-1]
|
| 436 |
+
|
| 437 |
+
present_key_value = self_attention_outputs[-1]
|
| 438 |
+
|
| 439 |
+
if query_length > 0:
|
| 440 |
+
query_attention_output = attention_output[:, :query_length, :]
|
| 441 |
+
|
| 442 |
+
if self.has_cross_attention:
|
| 443 |
+
assert (
|
| 444 |
+
encoder_hidden_states is not None
|
| 445 |
+
), "encoder_hidden_states must be given for cross-attention layers"
|
| 446 |
+
cross_attention_outputs = self.crossattention(
|
| 447 |
+
query_attention_output,
|
| 448 |
+
attention_mask,
|
| 449 |
+
head_mask,
|
| 450 |
+
encoder_hidden_states,
|
| 451 |
+
encoder_attention_mask,
|
| 452 |
+
output_attentions=output_attentions,
|
| 453 |
+
)
|
| 454 |
+
query_attention_output = cross_attention_outputs[0]
|
| 455 |
+
outputs = (
|
| 456 |
+
outputs + cross_attention_outputs[1:-1]
|
| 457 |
+
) # add cross attentions if we output attention weights
|
| 458 |
+
|
| 459 |
+
layer_output = apply_chunking_to_forward(
|
| 460 |
+
self.feed_forward_chunk_query,
|
| 461 |
+
self.chunk_size_feed_forward,
|
| 462 |
+
self.seq_len_dim,
|
| 463 |
+
query_attention_output,
|
| 464 |
+
)
|
| 465 |
+
if attention_output.shape[1] > query_length:
|
| 466 |
+
layer_output_text = apply_chunking_to_forward(
|
| 467 |
+
self.feed_forward_chunk,
|
| 468 |
+
self.chunk_size_feed_forward,
|
| 469 |
+
self.seq_len_dim,
|
| 470 |
+
attention_output[:, query_length:, :],
|
| 471 |
+
)
|
| 472 |
+
layer_output = torch.cat([layer_output, layer_output_text], dim=1)
|
| 473 |
+
else:
|
| 474 |
+
layer_output = apply_chunking_to_forward(
|
| 475 |
+
self.feed_forward_chunk,
|
| 476 |
+
self.chunk_size_feed_forward,
|
| 477 |
+
self.seq_len_dim,
|
| 478 |
+
attention_output,
|
| 479 |
+
)
|
| 480 |
+
outputs = (layer_output,) + outputs
|
| 481 |
+
|
| 482 |
+
outputs = outputs + (present_key_value,)
|
| 483 |
+
|
| 484 |
+
return outputs
|
| 485 |
+
|
| 486 |
+
def feed_forward_chunk(self, attention_output):
|
| 487 |
+
intermediate_output = self.intermediate(attention_output)
|
| 488 |
+
layer_output = self.output(intermediate_output, attention_output)
|
| 489 |
+
return layer_output
|
| 490 |
+
|
| 491 |
+
def feed_forward_chunk_query(self, attention_output):
|
| 492 |
+
intermediate_output = self.intermediate_query(attention_output)
|
| 493 |
+
layer_output = self.output_query(intermediate_output, attention_output)
|
| 494 |
+
return layer_output
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
class BertEncoder(nn.Module):
|
| 498 |
+
def __init__(self, config):
|
| 499 |
+
super().__init__()
|
| 500 |
+
self.config = config
|
| 501 |
+
self.layer = nn.ModuleList(
|
| 502 |
+
[BertLayer(config, i) for i in range(config.num_hidden_layers)]
|
| 503 |
+
)
|
| 504 |
+
|
| 505 |
+
def forward(
|
| 506 |
+
self,
|
| 507 |
+
hidden_states,
|
| 508 |
+
attention_mask=None,
|
| 509 |
+
head_mask=None,
|
| 510 |
+
encoder_hidden_states=None,
|
| 511 |
+
encoder_attention_mask=None,
|
| 512 |
+
past_key_values=None,
|
| 513 |
+
use_cache=None,
|
| 514 |
+
output_attentions=False,
|
| 515 |
+
output_hidden_states=False,
|
| 516 |
+
return_dict=True,
|
| 517 |
+
query_length=0,
|
| 518 |
+
):
|
| 519 |
+
all_hidden_states = () if output_hidden_states else None
|
| 520 |
+
all_self_attentions = () if output_attentions else None
|
| 521 |
+
all_cross_attentions = (
|
| 522 |
+
() if output_attentions and self.config.add_cross_attention else None
|
| 523 |
+
)
|
| 524 |
+
|
| 525 |
+
next_decoder_cache = () if use_cache else None
|
| 526 |
+
|
| 527 |
+
for i in range(self.config.num_hidden_layers):
|
| 528 |
+
layer_module = self.layer[i]
|
| 529 |
+
if output_hidden_states:
|
| 530 |
+
all_hidden_states = all_hidden_states + (hidden_states,)
|
| 531 |
+
|
| 532 |
+
layer_head_mask = head_mask[i] if head_mask is not None else None
|
| 533 |
+
past_key_value = past_key_values[i] if past_key_values is not None else None
|
| 534 |
+
|
| 535 |
+
if getattr(self.config, "gradient_checkpointing", False) and self.training:
|
| 536 |
+
|
| 537 |
+
if use_cache:
|
| 538 |
+
logger.warn(
|
| 539 |
+
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
|
| 540 |
+
)
|
| 541 |
+
use_cache = False
|
| 542 |
+
|
| 543 |
+
def create_custom_forward(module):
|
| 544 |
+
def custom_forward(*inputs):
|
| 545 |
+
return module(
|
| 546 |
+
*inputs, past_key_value, output_attentions, query_length
|
| 547 |
+
)
|
| 548 |
+
|
| 549 |
+
return custom_forward
|
| 550 |
+
|
| 551 |
+
layer_outputs = torch.utils.checkpoint.checkpoint(
|
| 552 |
+
create_custom_forward(layer_module),
|
| 553 |
+
hidden_states,
|
| 554 |
+
attention_mask,
|
| 555 |
+
layer_head_mask,
|
| 556 |
+
encoder_hidden_states,
|
| 557 |
+
encoder_attention_mask,
|
| 558 |
+
)
|
| 559 |
+
else:
|
| 560 |
+
layer_outputs = layer_module(
|
| 561 |
+
hidden_states,
|
| 562 |
+
attention_mask,
|
| 563 |
+
layer_head_mask,
|
| 564 |
+
encoder_hidden_states,
|
| 565 |
+
encoder_attention_mask,
|
| 566 |
+
past_key_value,
|
| 567 |
+
output_attentions,
|
| 568 |
+
query_length,
|
| 569 |
+
)
|
| 570 |
+
|
| 571 |
+
hidden_states = layer_outputs[0]
|
| 572 |
+
if use_cache:
|
| 573 |
+
next_decoder_cache += (layer_outputs[-1],)
|
| 574 |
+
if output_attentions:
|
| 575 |
+
all_self_attentions = all_self_attentions + (layer_outputs[1],)
|
| 576 |
+
all_cross_attentions = all_cross_attentions + (layer_outputs[2],)
|
| 577 |
+
|
| 578 |
+
if output_hidden_states:
|
| 579 |
+
all_hidden_states = all_hidden_states + (hidden_states,)
|
| 580 |
+
|
| 581 |
+
if not return_dict:
|
| 582 |
+
return tuple(
|
| 583 |
+
v
|
| 584 |
+
for v in [
|
| 585 |
+
hidden_states,
|
| 586 |
+
next_decoder_cache,
|
| 587 |
+
all_hidden_states,
|
| 588 |
+
all_self_attentions,
|
| 589 |
+
all_cross_attentions,
|
| 590 |
+
]
|
| 591 |
+
if v is not None
|
| 592 |
+
)
|
| 593 |
+
return BaseModelOutputWithPastAndCrossAttentions(
|
| 594 |
+
last_hidden_state=hidden_states,
|
| 595 |
+
past_key_values=next_decoder_cache,
|
| 596 |
+
hidden_states=all_hidden_states,
|
| 597 |
+
attentions=all_self_attentions,
|
| 598 |
+
cross_attentions=all_cross_attentions,
|
| 599 |
+
)
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
class BertPooler(nn.Module):
|
| 603 |
+
def __init__(self, config):
|
| 604 |
+
super().__init__()
|
| 605 |
+
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
|
| 606 |
+
self.activation = nn.Tanh()
|
| 607 |
+
|
| 608 |
+
def forward(self, hidden_states):
|
| 609 |
+
# We "pool" the model by simply taking the hidden state corresponding
|
| 610 |
+
# to the first token.
|
| 611 |
+
first_token_tensor = hidden_states[:, 0]
|
| 612 |
+
pooled_output = self.dense(first_token_tensor)
|
| 613 |
+
pooled_output = self.activation(pooled_output)
|
| 614 |
+
return pooled_output
|
| 615 |
+
|
| 616 |
+
|
| 617 |
+
class BertPredictionHeadTransform(nn.Module):
|
| 618 |
+
def __init__(self, config):
|
| 619 |
+
super().__init__()
|
| 620 |
+
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
|
| 621 |
+
if isinstance(config.hidden_act, str):
|
| 622 |
+
self.transform_act_fn = ACT2FN[config.hidden_act]
|
| 623 |
+
else:
|
| 624 |
+
self.transform_act_fn = config.hidden_act
|
| 625 |
+
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
| 626 |
+
|
| 627 |
+
def forward(self, hidden_states):
|
| 628 |
+
hidden_states = self.dense(hidden_states)
|
| 629 |
+
hidden_states = self.transform_act_fn(hidden_states)
|
| 630 |
+
hidden_states = self.LayerNorm(hidden_states)
|
| 631 |
+
return hidden_states
|
| 632 |
+
|
| 633 |
+
|
| 634 |
+
class BertLMPredictionHead(nn.Module):
|
| 635 |
+
def __init__(self, config):
|
| 636 |
+
super().__init__()
|
| 637 |
+
self.transform = BertPredictionHeadTransform(config)
|
| 638 |
+
|
| 639 |
+
# The output weights are the same as the input embeddings, but there is
|
| 640 |
+
# an output-only bias for each token.
|
| 641 |
+
self.decoder = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 642 |
+
|
| 643 |
+
self.bias = nn.Parameter(torch.zeros(config.vocab_size))
|
| 644 |
+
|
| 645 |
+
# Need a link between the two variables so that the bias is correctly resized with `resize_token_embeddings`
|
| 646 |
+
self.decoder.bias = self.bias
|
| 647 |
+
|
| 648 |
+
def forward(self, hidden_states):
|
| 649 |
+
hidden_states = self.transform(hidden_states)
|
| 650 |
+
hidden_states = self.decoder(hidden_states)
|
| 651 |
+
return hidden_states
|
| 652 |
+
|
| 653 |
+
|
| 654 |
+
class BertOnlyMLMHead(nn.Module):
|
| 655 |
+
def __init__(self, config):
|
| 656 |
+
super().__init__()
|
| 657 |
+
self.predictions = BertLMPredictionHead(config)
|
| 658 |
+
|
| 659 |
+
def forward(self, sequence_output):
|
| 660 |
+
prediction_scores = self.predictions(sequence_output)
|
| 661 |
+
return prediction_scores
|
| 662 |
+
|
| 663 |
+
|
| 664 |
+
class BertPreTrainedModel(PreTrainedModel):
|
| 665 |
+
"""
|
| 666 |
+
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
|
| 667 |
+
models.
|
| 668 |
+
"""
|
| 669 |
+
|
| 670 |
+
config_class = BertConfig
|
| 671 |
+
base_model_prefix = "bert"
|
| 672 |
+
_keys_to_ignore_on_load_missing = [r"position_ids"]
|
| 673 |
+
|
| 674 |
+
def _init_weights(self, module):
|
| 675 |
+
"""Initialize the weights"""
|
| 676 |
+
if isinstance(module, (nn.Linear, nn.Embedding)):
|
| 677 |
+
# Slightly different from the TF version which uses truncated_normal for initialization
|
| 678 |
+
# cf https://github.com/pytorch/pytorch/pull/5617
|
| 679 |
+
module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
|
| 680 |
+
elif isinstance(module, nn.LayerNorm):
|
| 681 |
+
module.bias.data.zero_()
|
| 682 |
+
module.weight.data.fill_(1.0)
|
| 683 |
+
# print(module)
|
| 684 |
+
if isinstance(module, nn.Linear) and module.bias is not None:
|
| 685 |
+
module.bias.data.zero_()
|
| 686 |
+
|
| 687 |
+
def get_head_mask(
|
| 688 |
+
self, head_mask: Optional[Tensor], num_hidden_layers: int, is_attention_chunked: bool = False
|
| 689 |
+
) -> Tensor:
|
| 690 |
+
"""
|
| 691 |
+
Prepare the head mask if needed.
|
| 692 |
+
|
| 693 |
+
Args:
|
| 694 |
+
head_mask (`torch.Tensor` with shape `[num_heads]` or `[num_hidden_layers x num_heads]`, *optional*):
|
| 695 |
+
The mask indicating if we should keep the heads or not (1.0 for keep, 0.0 for discard).
|
| 696 |
+
num_hidden_layers (`int`):
|
| 697 |
+
The number of hidden layers in the model.
|
| 698 |
+
is_attention_chunked (`bool`, *optional*, defaults to `False`):
|
| 699 |
+
Whether or not the attentions scores are computed by chunks or not.
|
| 700 |
+
|
| 701 |
+
Returns:
|
| 702 |
+
`torch.Tensor` with shape `[num_hidden_layers x batch x num_heads x seq_length x seq_length]` or list with
|
| 703 |
+
`[None]` for each layer.
|
| 704 |
+
"""
|
| 705 |
+
if head_mask is not None:
|
| 706 |
+
head_mask = self._convert_head_mask_to_5d(head_mask, num_hidden_layers)
|
| 707 |
+
if is_attention_chunked is True:
|
| 708 |
+
head_mask = head_mask.unsqueeze(-1)
|
| 709 |
+
else:
|
| 710 |
+
head_mask = [None] * num_hidden_layers
|
| 711 |
+
|
| 712 |
+
return head_mask
|
| 713 |
+
|
| 714 |
+
|
| 715 |
+
class BertModel(BertPreTrainedModel):
|
| 716 |
+
"""
|
| 717 |
+
The model can behave as an encoder (with only self-attention) as well as a decoder, in which case a layer of
|
| 718 |
+
cross-attention is added between the self-attention layers, following the architecture described in `Attention is
|
| 719 |
+
all you need <https://arxiv.org/abs/1706.03762>`__ by Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit,
|
| 720 |
+
Llion Jones, Aidan N. Gomez, Lukasz Kaiser and Illia Polosukhin.
|
| 721 |
+
argument and :obj:`add_cross_attention` set to :obj:`True`; an :obj:`encoder_hidden_states` is then expected as an
|
| 722 |
+
input to the forward pass.
|
| 723 |
+
"""
|
| 724 |
+
|
| 725 |
+
def __init__(self, config, add_pooling_layer=False):
|
| 726 |
+
super().__init__(config)
|
| 727 |
+
self.config = config
|
| 728 |
+
|
| 729 |
+
self.embeddings = BertEmbeddings(config)
|
| 730 |
+
|
| 731 |
+
self.encoder = BertEncoder(config)
|
| 732 |
+
|
| 733 |
+
self.pooler = BertPooler(config) if add_pooling_layer else None
|
| 734 |
+
|
| 735 |
+
self.post_init()
|
| 736 |
+
|
| 737 |
+
def get_input_embeddings(self):
|
| 738 |
+
return self.embeddings.word_embeddings
|
| 739 |
+
|
| 740 |
+
def set_input_embeddings(self, value):
|
| 741 |
+
self.embeddings.word_embeddings = value
|
| 742 |
+
|
| 743 |
+
def _prune_heads(self, heads_to_prune):
|
| 744 |
+
"""
|
| 745 |
+
Prunes heads of the model. heads_to_prune: dict of {layer_num: list of heads to prune in this layer} See base
|
| 746 |
+
class PreTrainedModel
|
| 747 |
+
"""
|
| 748 |
+
for layer, heads in heads_to_prune.items():
|
| 749 |
+
self.encoder.layer[layer].attention.prune_heads(heads)
|
| 750 |
+
|
| 751 |
+
def get_extended_attention_mask(
|
| 752 |
+
self,
|
| 753 |
+
attention_mask: Tensor,
|
| 754 |
+
input_shape: Tuple[int],
|
| 755 |
+
device: device,
|
| 756 |
+
is_decoder: bool,
|
| 757 |
+
has_query: bool = False,
|
| 758 |
+
) -> Tensor:
|
| 759 |
+
"""
|
| 760 |
+
Makes broadcastable attention and causal masks so that future and masked tokens are ignored.
|
| 761 |
+
|
| 762 |
+
Arguments:
|
| 763 |
+
attention_mask (:obj:`torch.Tensor`):
|
| 764 |
+
Mask with ones indicating tokens to attend to, zeros for tokens to ignore.
|
| 765 |
+
input_shape (:obj:`Tuple[int]`):
|
| 766 |
+
The shape of the input to the model.
|
| 767 |
+
device: (:obj:`torch.device`):
|
| 768 |
+
The device of the input to the model.
|
| 769 |
+
|
| 770 |
+
Returns:
|
| 771 |
+
:obj:`torch.Tensor` The extended attention mask, with a the same dtype as :obj:`attention_mask.dtype`.
|
| 772 |
+
"""
|
| 773 |
+
# We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
|
| 774 |
+
# ourselves in which case we just need to make it broadcastable to all heads.
|
| 775 |
+
if attention_mask.dim() == 3:
|
| 776 |
+
extended_attention_mask = attention_mask[:, None, :, :]
|
| 777 |
+
elif attention_mask.dim() == 2:
|
| 778 |
+
# Provided a padding mask of dimensions [batch_size, seq_length]
|
| 779 |
+
# - if the model is a decoder, apply a causal mask in addition to the padding mask
|
| 780 |
+
# - if the model is an encoder, make the mask broadcastable to [batch_size, num_heads, seq_length, seq_length]
|
| 781 |
+
if is_decoder:
|
| 782 |
+
batch_size, seq_length = input_shape
|
| 783 |
+
|
| 784 |
+
seq_ids = torch.arange(seq_length, device=device)
|
| 785 |
+
causal_mask = (
|
| 786 |
+
seq_ids[None, None, :].repeat(batch_size, seq_length, 1)
|
| 787 |
+
<= seq_ids[None, :, None]
|
| 788 |
+
)
|
| 789 |
+
|
| 790 |
+
# add a prefix ones mask to the causal mask
|
| 791 |
+
# causal and attention masks must have same type with pytorch version < 1.3
|
| 792 |
+
causal_mask = causal_mask.to(attention_mask.dtype)
|
| 793 |
+
|
| 794 |
+
if causal_mask.shape[1] < attention_mask.shape[1]:
|
| 795 |
+
prefix_seq_len = attention_mask.shape[1] - causal_mask.shape[1]
|
| 796 |
+
if has_query: # UniLM style attention mask
|
| 797 |
+
causal_mask = torch.cat(
|
| 798 |
+
[
|
| 799 |
+
torch.zeros(
|
| 800 |
+
(batch_size, prefix_seq_len, seq_length),
|
| 801 |
+
device=device,
|
| 802 |
+
dtype=causal_mask.dtype,
|
| 803 |
+
),
|
| 804 |
+
causal_mask,
|
| 805 |
+
],
|
| 806 |
+
axis=1,
|
| 807 |
+
)
|
| 808 |
+
causal_mask = torch.cat(
|
| 809 |
+
[
|
| 810 |
+
torch.ones(
|
| 811 |
+
(batch_size, causal_mask.shape[1], prefix_seq_len),
|
| 812 |
+
device=device,
|
| 813 |
+
dtype=causal_mask.dtype,
|
| 814 |
+
),
|
| 815 |
+
causal_mask,
|
| 816 |
+
],
|
| 817 |
+
axis=-1,
|
| 818 |
+
)
|
| 819 |
+
extended_attention_mask = (
|
| 820 |
+
causal_mask[:, None, :, :] * attention_mask[:, None, None, :]
|
| 821 |
+
)
|
| 822 |
+
else:
|
| 823 |
+
extended_attention_mask = attention_mask[:, None, None, :]
|
| 824 |
+
else:
|
| 825 |
+
raise ValueError(
|
| 826 |
+
"Wrong shape for input_ids (shape {}) or attention_mask (shape {})".format(
|
| 827 |
+
input_shape, attention_mask.shape
|
| 828 |
+
)
|
| 829 |
+
)
|
| 830 |
+
|
| 831 |
+
# Since attention_mask is 1.0 for positions we want to attend and 0.0 for
|
| 832 |
+
# masked positions, this operation will create a tensor which is 0.0 for
|
| 833 |
+
# positions we want to attend and -10000.0 for masked positions.
|
| 834 |
+
# Since we are adding it to the raw scores before the softmax, this is
|
| 835 |
+
# effectively the same as removing these entirely.
|
| 836 |
+
extended_attention_mask = extended_attention_mask.to(
|
| 837 |
+
dtype=self.dtype
|
| 838 |
+
) # fp16 compatibility
|
| 839 |
+
extended_attention_mask = (1.0 - extended_attention_mask) * -10000.0
|
| 840 |
+
return extended_attention_mask
|
| 841 |
+
|
| 842 |
+
def forward(
|
| 843 |
+
self,
|
| 844 |
+
input_ids=None,
|
| 845 |
+
attention_mask=None,
|
| 846 |
+
position_ids=None,
|
| 847 |
+
head_mask=None,
|
| 848 |
+
query_embeds=None,
|
| 849 |
+
encoder_hidden_states=None,
|
| 850 |
+
encoder_attention_mask=None,
|
| 851 |
+
past_key_values=None,
|
| 852 |
+
use_cache=None,
|
| 853 |
+
output_attentions=None,
|
| 854 |
+
output_hidden_states=None,
|
| 855 |
+
return_dict=None,
|
| 856 |
+
is_decoder=False,
|
| 857 |
+
):
|
| 858 |
+
r"""
|
| 859 |
+
encoder_hidden_states (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length, hidden_size)`, `optional`):
|
| 860 |
+
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
|
| 861 |
+
the model is configured as a decoder.
|
| 862 |
+
encoder_attention_mask (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`):
|
| 863 |
+
Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in
|
| 864 |
+
the cross-attention if the model is configured as a decoder. Mask values selected in ``[0, 1]``:
|
| 865 |
+
- 1 for tokens that are **not masked**,
|
| 866 |
+
- 0 for tokens that are **masked**.
|
| 867 |
+
past_key_values (:obj:`tuple(tuple(torch.FloatTensor))` of length :obj:`config.n_layers` with each tuple having 4 tensors of shape :obj:`(batch_size, num_heads, sequence_length - 1, embed_size_per_head)`):
|
| 868 |
+
Contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding.
|
| 869 |
+
If :obj:`past_key_values` are used, the user can optionally input only the last :obj:`decoder_input_ids`
|
| 870 |
+
(those that don't have their past key value states given to this model) of shape :obj:`(batch_size, 1)`
|
| 871 |
+
instead of all :obj:`decoder_input_ids` of shape :obj:`(batch_size, sequence_length)`.
|
| 872 |
+
use_cache (:obj:`bool`, `optional`):
|
| 873 |
+
If set to :obj:`True`, :obj:`past_key_values` key value states are returned and can be used to speed up
|
| 874 |
+
decoding (see :obj:`past_key_values`).
|
| 875 |
+
"""
|
| 876 |
+
output_attentions = (
|
| 877 |
+
output_attentions
|
| 878 |
+
if output_attentions is not None
|
| 879 |
+
else self.config.output_attentions
|
| 880 |
+
)
|
| 881 |
+
output_hidden_states = (
|
| 882 |
+
output_hidden_states
|
| 883 |
+
if output_hidden_states is not None
|
| 884 |
+
else self.config.output_hidden_states
|
| 885 |
+
)
|
| 886 |
+
return_dict = (
|
| 887 |
+
return_dict if return_dict is not None else self.config.use_return_dict
|
| 888 |
+
)
|
| 889 |
+
|
| 890 |
+
# use_cache = use_cache if use_cache is not None else self.config.use_cache
|
| 891 |
+
|
| 892 |
+
if input_ids is None:
|
| 893 |
+
assert (
|
| 894 |
+
query_embeds is not None
|
| 895 |
+
), "You have to specify query_embeds when input_ids is None"
|
| 896 |
+
|
| 897 |
+
# past_key_values_length
|
| 898 |
+
past_key_values_length = (
|
| 899 |
+
past_key_values[0][0].shape[2] - self.config.query_length
|
| 900 |
+
if past_key_values is not None
|
| 901 |
+
else 0
|
| 902 |
+
)
|
| 903 |
+
|
| 904 |
+
query_length = query_embeds.shape[1] if query_embeds is not None else 0
|
| 905 |
+
|
| 906 |
+
embedding_output = self.embeddings(
|
| 907 |
+
input_ids=input_ids,
|
| 908 |
+
position_ids=position_ids,
|
| 909 |
+
query_embeds=query_embeds,
|
| 910 |
+
past_key_values_length=past_key_values_length,
|
| 911 |
+
)
|
| 912 |
+
|
| 913 |
+
input_shape = embedding_output.size()[:-1]
|
| 914 |
+
batch_size, seq_length = input_shape
|
| 915 |
+
device = embedding_output.device
|
| 916 |
+
|
| 917 |
+
if attention_mask is None:
|
| 918 |
+
attention_mask = torch.ones(
|
| 919 |
+
((batch_size, seq_length + past_key_values_length)), device=device
|
| 920 |
+
)
|
| 921 |
+
|
| 922 |
+
# We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
|
| 923 |
+
# ourselves in which case we just need to make it broadcastable to all heads.
|
| 924 |
+
if is_decoder:
|
| 925 |
+
extended_attention_mask = self.get_extended_attention_mask(
|
| 926 |
+
attention_mask,
|
| 927 |
+
input_ids.shape,
|
| 928 |
+
device,
|
| 929 |
+
is_decoder,
|
| 930 |
+
has_query=(query_embeds is not None),
|
| 931 |
+
)
|
| 932 |
+
else:
|
| 933 |
+
extended_attention_mask = self.get_extended_attention_mask(
|
| 934 |
+
attention_mask, input_shape, device, is_decoder
|
| 935 |
+
)
|
| 936 |
+
|
| 937 |
+
# If a 2D or 3D attention mask is provided for the cross-attention
|
| 938 |
+
# we need to make broadcastable to [batch_size, num_heads, seq_length, seq_length]
|
| 939 |
+
if encoder_hidden_states is not None:
|
| 940 |
+
if type(encoder_hidden_states) == list:
|
| 941 |
+
encoder_batch_size, encoder_sequence_length, _ = encoder_hidden_states[
|
| 942 |
+
0
|
| 943 |
+
].size()
|
| 944 |
+
else:
|
| 945 |
+
(
|
| 946 |
+
encoder_batch_size,
|
| 947 |
+
encoder_sequence_length,
|
| 948 |
+
_,
|
| 949 |
+
) = encoder_hidden_states.size()
|
| 950 |
+
encoder_hidden_shape = (encoder_batch_size, encoder_sequence_length)
|
| 951 |
+
|
| 952 |
+
if type(encoder_attention_mask) == list:
|
| 953 |
+
encoder_extended_attention_mask = [
|
| 954 |
+
self.invert_attention_mask(mask) for mask in encoder_attention_mask
|
| 955 |
+
]
|
| 956 |
+
elif encoder_attention_mask is None:
|
| 957 |
+
encoder_attention_mask = torch.ones(encoder_hidden_shape, device=device)
|
| 958 |
+
encoder_extended_attention_mask = self.invert_attention_mask(
|
| 959 |
+
encoder_attention_mask
|
| 960 |
+
)
|
| 961 |
+
else:
|
| 962 |
+
encoder_extended_attention_mask = self.invert_attention_mask(
|
| 963 |
+
encoder_attention_mask
|
| 964 |
+
)
|
| 965 |
+
else:
|
| 966 |
+
encoder_extended_attention_mask = None
|
| 967 |
+
|
| 968 |
+
# Prepare head mask if needed
|
| 969 |
+
# 1.0 in head_mask indicate we keep the head
|
| 970 |
+
# attention_probs has shape bsz x n_heads x N x N
|
| 971 |
+
# input head_mask has shape [num_heads] or [num_hidden_layers x num_heads]
|
| 972 |
+
# and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length]
|
| 973 |
+
head_mask = self.get_head_mask(head_mask, self.config.num_hidden_layers)
|
| 974 |
+
|
| 975 |
+
encoder_outputs = self.encoder(
|
| 976 |
+
embedding_output,
|
| 977 |
+
attention_mask=extended_attention_mask,
|
| 978 |
+
head_mask=head_mask,
|
| 979 |
+
encoder_hidden_states=encoder_hidden_states,
|
| 980 |
+
encoder_attention_mask=encoder_extended_attention_mask,
|
| 981 |
+
past_key_values=past_key_values,
|
| 982 |
+
use_cache=use_cache,
|
| 983 |
+
output_attentions=output_attentions,
|
| 984 |
+
output_hidden_states=output_hidden_states,
|
| 985 |
+
return_dict=return_dict,
|
| 986 |
+
query_length=query_length,
|
| 987 |
+
)
|
| 988 |
+
sequence_output = encoder_outputs[0]
|
| 989 |
+
pooled_output = (
|
| 990 |
+
self.pooler(sequence_output) if self.pooler is not None else None
|
| 991 |
+
)
|
| 992 |
+
|
| 993 |
+
if not return_dict:
|
| 994 |
+
return (sequence_output, pooled_output) + encoder_outputs[1:]
|
| 995 |
+
|
| 996 |
+
return BaseModelOutputWithPoolingAndCrossAttentions(
|
| 997 |
+
last_hidden_state=sequence_output,
|
| 998 |
+
pooler_output=pooled_output,
|
| 999 |
+
past_key_values=encoder_outputs.past_key_values,
|
| 1000 |
+
hidden_states=encoder_outputs.hidden_states,
|
| 1001 |
+
attentions=encoder_outputs.attentions,
|
| 1002 |
+
cross_attentions=encoder_outputs.cross_attentions,
|
| 1003 |
+
)
|
| 1004 |
+
|
| 1005 |
+
|
| 1006 |
+
class BertLMHeadModel(BertPreTrainedModel):
|
| 1007 |
+
|
| 1008 |
+
_keys_to_ignore_on_load_unexpected = [r"pooler"]
|
| 1009 |
+
_keys_to_ignore_on_load_missing = [r"position_ids", r"predictions.decoder.bias"]
|
| 1010 |
+
|
| 1011 |
+
def __init__(self, config):
|
| 1012 |
+
super().__init__(config)
|
| 1013 |
+
|
| 1014 |
+
self.bert = BertModel(config, add_pooling_layer=False)
|
| 1015 |
+
self.cls = None
|
| 1016 |
+
|
| 1017 |
+
self.post_init()
|
| 1018 |
+
|
| 1019 |
+
def get_output_embeddings(self):
|
| 1020 |
+
pass
|
| 1021 |
+
# return self.cls.predictions.decoder
|
| 1022 |
+
|
| 1023 |
+
def set_output_embeddings(self, new_embeddings):
|
| 1024 |
+
self.cls.predictions.decoder = new_embeddings
|
| 1025 |
+
|
| 1026 |
+
def forward(
|
| 1027 |
+
self,
|
| 1028 |
+
input_ids=None,
|
| 1029 |
+
attention_mask=None,
|
| 1030 |
+
position_ids=None,
|
| 1031 |
+
head_mask=None,
|
| 1032 |
+
query_embeds=None,
|
| 1033 |
+
encoder_hidden_states=None,
|
| 1034 |
+
encoder_attention_mask=None,
|
| 1035 |
+
labels=None,
|
| 1036 |
+
past_key_values=None,
|
| 1037 |
+
use_cache=True,
|
| 1038 |
+
output_attentions=None,
|
| 1039 |
+
output_hidden_states=None,
|
| 1040 |
+
return_dict=None,
|
| 1041 |
+
return_logits=False,
|
| 1042 |
+
is_decoder=True,
|
| 1043 |
+
reduction="mean",
|
| 1044 |
+
):
|
| 1045 |
+
r"""
|
| 1046 |
+
encoder_hidden_states (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length, hidden_size)`, `optional`):
|
| 1047 |
+
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
|
| 1048 |
+
the model is configured as a decoder.
|
| 1049 |
+
encoder_attention_mask (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`):
|
| 1050 |
+
Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in
|
| 1051 |
+
the cross-attention if the model is configured as a decoder. Mask values selected in ``[0, 1]``:
|
| 1052 |
+
- 1 for tokens that are **not masked**,
|
| 1053 |
+
- 0 for tokens that are **masked**.
|
| 1054 |
+
labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`):
|
| 1055 |
+
Labels for computing the left-to-right language modeling loss (next word prediction). Indices should be in
|
| 1056 |
+
``[-100, 0, ..., config.vocab_size]`` (see ``input_ids`` docstring) Tokens with indices set to ``-100`` are
|
| 1057 |
+
ignored (masked), the loss is only computed for the tokens with labels n ``[0, ..., config.vocab_size]``
|
| 1058 |
+
past_key_values (:obj:`tuple(tuple(torch.FloatTensor))` of length :obj:`config.n_layers` with each tuple having 4 tensors of shape :obj:`(batch_size, num_heads, sequence_length - 1, embed_size_per_head)`):
|
| 1059 |
+
Contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding.
|
| 1060 |
+
If :obj:`past_key_values` are used, the user can optionally input only the last :obj:`decoder_input_ids`
|
| 1061 |
+
(those that don't have their past key value states given to this model) of shape :obj:`(batch_size, 1)`
|
| 1062 |
+
instead of all :obj:`decoder_input_ids` of shape :obj:`(batch_size, sequence_length)`.
|
| 1063 |
+
use_cache (:obj:`bool`, `optional`):
|
| 1064 |
+
If set to :obj:`True`, :obj:`past_key_values` key value states are returned and can be used to speed up
|
| 1065 |
+
decoding (see :obj:`past_key_values`).
|
| 1066 |
+
Returns:
|
| 1067 |
+
Example::
|
| 1068 |
+
>>> from transformers import BertTokenizer, BertLMHeadModel, BertConfig
|
| 1069 |
+
>>> import torch
|
| 1070 |
+
>>> tokenizer = BertTokenizer.from_pretrained('bert-base-cased')
|
| 1071 |
+
>>> config = BertConfig.from_pretrained("bert-base-cased")
|
| 1072 |
+
>>> model = BertLMHeadModel.from_pretrained('bert-base-cased', config=config)
|
| 1073 |
+
>>> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
|
| 1074 |
+
>>> outputs = model(**inputs)
|
| 1075 |
+
>>> prediction_logits = outputs.logits
|
| 1076 |
+
"""
|
| 1077 |
+
return_dict = (
|
| 1078 |
+
return_dict if return_dict is not None else self.config.use_return_dict
|
| 1079 |
+
)
|
| 1080 |
+
if labels is not None:
|
| 1081 |
+
use_cache = False
|
| 1082 |
+
if past_key_values is not None:
|
| 1083 |
+
query_embeds = None
|
| 1084 |
+
|
| 1085 |
+
outputs = self.bert(
|
| 1086 |
+
input_ids,
|
| 1087 |
+
attention_mask=attention_mask,
|
| 1088 |
+
position_ids=position_ids,
|
| 1089 |
+
head_mask=head_mask,
|
| 1090 |
+
query_embeds=query_embeds,
|
| 1091 |
+
encoder_hidden_states=encoder_hidden_states,
|
| 1092 |
+
encoder_attention_mask=encoder_attention_mask,
|
| 1093 |
+
past_key_values=past_key_values,
|
| 1094 |
+
use_cache=use_cache,
|
| 1095 |
+
output_attentions=output_attentions,
|
| 1096 |
+
output_hidden_states=output_hidden_states,
|
| 1097 |
+
return_dict=return_dict,
|
| 1098 |
+
is_decoder=is_decoder,
|
| 1099 |
+
)
|
| 1100 |
+
|
| 1101 |
+
sequence_output = outputs[0]
|
| 1102 |
+
if query_embeds is not None:
|
| 1103 |
+
sequence_output = outputs[0][:, query_embeds.shape[1] :, :]
|
| 1104 |
+
|
| 1105 |
+
prediction_scores = self.cls(sequence_output)
|
| 1106 |
+
|
| 1107 |
+
if return_logits:
|
| 1108 |
+
return prediction_scores[:, :-1, :].contiguous()
|
| 1109 |
+
|
| 1110 |
+
lm_loss = None
|
| 1111 |
+
if labels is not None:
|
| 1112 |
+
# we are doing next-token prediction; shift prediction scores and input ids by one
|
| 1113 |
+
shifted_prediction_scores = prediction_scores[:, :-1, :].contiguous()
|
| 1114 |
+
labels = labels[:, 1:].contiguous()
|
| 1115 |
+
loss_fct = CrossEntropyLoss(reduction=reduction, label_smoothing=0.1)
|
| 1116 |
+
lm_loss = loss_fct(
|
| 1117 |
+
shifted_prediction_scores.view(-1, self.config.vocab_size),
|
| 1118 |
+
labels.view(-1),
|
| 1119 |
+
)
|
| 1120 |
+
if reduction == "none":
|
| 1121 |
+
lm_loss = lm_loss.view(prediction_scores.size(0), -1).sum(1)
|
| 1122 |
+
|
| 1123 |
+
if not return_dict:
|
| 1124 |
+
output = (prediction_scores,) + outputs[2:]
|
| 1125 |
+
return ((lm_loss,) + output) if lm_loss is not None else output
|
| 1126 |
+
|
| 1127 |
+
return CausalLMOutputWithCrossAttentions(
|
| 1128 |
+
loss=lm_loss,
|
| 1129 |
+
logits=prediction_scores,
|
| 1130 |
+
past_key_values=outputs.past_key_values,
|
| 1131 |
+
hidden_states=outputs.hidden_states,
|
| 1132 |
+
attentions=outputs.attentions,
|
| 1133 |
+
cross_attentions=outputs.cross_attentions,
|
| 1134 |
+
)
|
| 1135 |
+
|
| 1136 |
+
def prepare_inputs_for_generation(
|
| 1137 |
+
self, input_ids, query_embeds, past=None, attention_mask=None, **model_kwargs
|
| 1138 |
+
):
|
| 1139 |
+
# if model is used as a decoder in encoder-decoder model, the decoder attention mask is created on the fly
|
| 1140 |
+
if attention_mask is None:
|
| 1141 |
+
attention_mask = input_ids.new_ones(input_ids.shape)
|
| 1142 |
+
query_mask = input_ids.new_ones(query_embeds.shape[:-1])
|
| 1143 |
+
attention_mask = torch.cat([query_mask, attention_mask], dim=-1)
|
| 1144 |
+
|
| 1145 |
+
# cut decoder_input_ids if past is used
|
| 1146 |
+
if past is not None:
|
| 1147 |
+
input_ids = input_ids[:, -1:]
|
| 1148 |
+
|
| 1149 |
+
return {
|
| 1150 |
+
"input_ids": input_ids,
|
| 1151 |
+
"query_embeds": query_embeds,
|
| 1152 |
+
"attention_mask": attention_mask,
|
| 1153 |
+
"past_key_values": past,
|
| 1154 |
+
"encoder_hidden_states": model_kwargs.get("encoder_hidden_states", None),
|
| 1155 |
+
"encoder_attention_mask": model_kwargs.get("encoder_attention_mask", None),
|
| 1156 |
+
"is_decoder": True,
|
| 1157 |
+
}
|
| 1158 |
+
|
| 1159 |
+
def _reorder_cache(self, past, beam_idx):
|
| 1160 |
+
reordered_past = ()
|
| 1161 |
+
for layer_past in past:
|
| 1162 |
+
reordered_past += (
|
| 1163 |
+
tuple(
|
| 1164 |
+
past_state.index_select(0, beam_idx) for past_state in layer_past
|
| 1165 |
+
),
|
| 1166 |
+
)
|
| 1167 |
+
return reordered_past
|
| 1168 |
+
|
| 1169 |
+
|
| 1170 |
+
class BertForMaskedLM(BertPreTrainedModel):
|
| 1171 |
+
|
| 1172 |
+
_keys_to_ignore_on_load_unexpected = [r"pooler"]
|
| 1173 |
+
_keys_to_ignore_on_load_missing = [r"position_ids", r"predictions.decoder.bias"]
|
| 1174 |
+
|
| 1175 |
+
def __init__(self, config):
|
| 1176 |
+
super().__init__(config)
|
| 1177 |
+
|
| 1178 |
+
self.bert = BertModel(config, add_pooling_layer=False)
|
| 1179 |
+
self.cls = BertOnlyMLMHead(config)
|
| 1180 |
+
|
| 1181 |
+
self.post_init()
|
| 1182 |
+
|
| 1183 |
+
def get_output_embeddings(self):
|
| 1184 |
+
return self.cls.predictions.decoder
|
| 1185 |
+
|
| 1186 |
+
def set_output_embeddings(self, new_embeddings):
|
| 1187 |
+
self.cls.predictions.decoder = new_embeddings
|
| 1188 |
+
|
| 1189 |
+
def forward(
|
| 1190 |
+
self,
|
| 1191 |
+
input_ids=None,
|
| 1192 |
+
attention_mask=None,
|
| 1193 |
+
position_ids=None,
|
| 1194 |
+
head_mask=None,
|
| 1195 |
+
query_embeds=None,
|
| 1196 |
+
encoder_hidden_states=None,
|
| 1197 |
+
encoder_attention_mask=None,
|
| 1198 |
+
labels=None,
|
| 1199 |
+
output_attentions=None,
|
| 1200 |
+
output_hidden_states=None,
|
| 1201 |
+
return_dict=None,
|
| 1202 |
+
return_logits=False,
|
| 1203 |
+
is_decoder=False,
|
| 1204 |
+
):
|
| 1205 |
+
r"""
|
| 1206 |
+
labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`):
|
| 1207 |
+
Labels for computing the masked language modeling loss. Indices should be in ``[-100, 0, ...,
|
| 1208 |
+
config.vocab_size]`` (see ``input_ids`` docstring) Tokens with indices set to ``-100`` are ignored
|
| 1209 |
+
(masked), the loss is only computed for the tokens with labels in ``[0, ..., config.vocab_size]``
|
| 1210 |
+
"""
|
| 1211 |
+
|
| 1212 |
+
return_dict = (
|
| 1213 |
+
return_dict if return_dict is not None else self.config.use_return_dict
|
| 1214 |
+
)
|
| 1215 |
+
|
| 1216 |
+
outputs = self.bert(
|
| 1217 |
+
input_ids,
|
| 1218 |
+
attention_mask=attention_mask,
|
| 1219 |
+
position_ids=position_ids,
|
| 1220 |
+
head_mask=head_mask,
|
| 1221 |
+
query_embeds=query_embeds,
|
| 1222 |
+
encoder_hidden_states=encoder_hidden_states,
|
| 1223 |
+
encoder_attention_mask=encoder_attention_mask,
|
| 1224 |
+
output_attentions=output_attentions,
|
| 1225 |
+
output_hidden_states=output_hidden_states,
|
| 1226 |
+
return_dict=return_dict,
|
| 1227 |
+
is_decoder=is_decoder,
|
| 1228 |
+
)
|
| 1229 |
+
|
| 1230 |
+
if query_embeds is not None:
|
| 1231 |
+
sequence_output = outputs[0][:, query_embeds.shape[1] :, :]
|
| 1232 |
+
prediction_scores = self.cls(sequence_output)
|
| 1233 |
+
|
| 1234 |
+
if return_logits:
|
| 1235 |
+
return prediction_scores
|
| 1236 |
+
|
| 1237 |
+
masked_lm_loss = None
|
| 1238 |
+
if labels is not None:
|
| 1239 |
+
loss_fct = CrossEntropyLoss() # -100 index = padding token
|
| 1240 |
+
masked_lm_loss = loss_fct(
|
| 1241 |
+
prediction_scores.view(-1, self.config.vocab_size), labels.view(-1)
|
| 1242 |
+
)
|
| 1243 |
+
|
| 1244 |
+
if not return_dict:
|
| 1245 |
+
output = (prediction_scores,) + outputs[2:]
|
| 1246 |
+
return (
|
| 1247 |
+
((masked_lm_loss,) + output) if masked_lm_loss is not None else output
|
| 1248 |
+
)
|
| 1249 |
+
|
| 1250 |
+
return Ma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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2022 The OpenAI Authors and The HuggingFace Inc. team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""PyTorch Whisper model."""
|
| 15 |
+
|
| 16 |
+
import math
|
| 17 |
+
from collections.abc import Callable
|
| 18 |
+
|
| 19 |
+
import numpy as np
|
| 20 |
+
import torch
|
| 21 |
+
from torch import nn
|
| 22 |
+
from torch.nn import CrossEntropyLoss
|
| 23 |
+
import torch.nn.functional as F
|
| 24 |
+
from transformers import initialization as init
|
| 25 |
+
from transformers.activations import ACT2FN
|
| 26 |
+
from transformers.cache_utils import Cache, DynamicCache, EncoderDecoderCache
|
| 27 |
+
from transformers.generation import GenerationMixin
|
| 28 |
+
from transformers.masking_utils import create_causal_mask
|
| 29 |
+
from transformers.modeling_flash_attention_utils import (
|
| 30 |
+
FlashAttentionKwargs,
|
| 31 |
+
)
|
| 32 |
+
from transformers.modeling_layers import GradientCheckpointingLayer
|
| 33 |
+
from transformers.modeling_outputs import (
|
| 34 |
+
BaseModelOutput,
|
| 35 |
+
BaseModelOutputWithPastAndCrossAttentions,
|
| 36 |
+
CausalLMOutputWithCrossAttentions,
|
| 37 |
+
Seq2SeqLMOutput,
|
| 38 |
+
Seq2SeqModelOutput,
|
| 39 |
+
SequenceClassifierOutput,
|
| 40 |
+
)
|
| 41 |
+
from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
|
| 42 |
+
from transformers.processing_utils import Unpack
|
| 43 |
+
from transformers.utils import auto_docstring, logging
|
| 44 |
+
from transformers.models.whisper.configuration_whisper import WhisperConfig
|
| 45 |
+
from transformers.models.whisper.generation_whisper import WhisperGenerationMixin
|
| 46 |
+
from .h5_modeling_bert import BertLMHeadModel
|
| 47 |
+
|
| 48 |
+
logger = logging.get_logger(__name__)
|
| 49 |
+
|
| 50 |
+
_HIDDEN_STATES_START_POSITION = 1
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def sinusoids(length: int, channels: int, max_timescale: float = 10000) -> torch.Tensor:
|
| 54 |
+
"""Returns sinusoids for positional embedding"""
|
| 55 |
+
if channels % 2 != 0:
|
| 56 |
+
raise ValueError(
|
| 57 |
+
f"Number of channels has to be divisible by 2 for sinusoidal positional embeddings, got {channels} channels."
|
| 58 |
+
)
|
| 59 |
+
log_timescale_increment = math.log(max_timescale) / (channels // 2 - 1)
|
| 60 |
+
inv_timescales = torch.exp(-log_timescale_increment * torch.arange(channels // 2))
|
| 61 |
+
scaled_time = torch.arange(length).view(-1, 1) * inv_timescales.view(1, -1)
|
| 62 |
+
return torch.cat([scaled_time.sin(), scaled_time.cos()], dim=1)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
# Copied from transformers.models.bart.modeling_bart.shift_tokens_right
|
| 66 |
+
def shift_tokens_right(input_ids: torch.Tensor, pad_token_id: int, decoder_start_token_id: int):
|
| 67 |
+
"""
|
| 68 |
+
Shift input ids one token to the right.
|
| 69 |
+
"""
|
| 70 |
+
shifted_input_ids = input_ids.new_zeros(input_ids.shape)
|
| 71 |
+
shifted_input_ids[:, 1:] = input_ids[:, :-1].clone()
|
| 72 |
+
shifted_input_ids[:, 0] = decoder_start_token_id
|
| 73 |
+
|
| 74 |
+
if pad_token_id is None:
|
| 75 |
+
raise ValueError("self.model.config.pad_token_id has to be defined.")
|
| 76 |
+
# replace possible -100 values in labels by `pad_token_id`
|
| 77 |
+
shifted_input_ids.masked_fill_(shifted_input_ids == -100, pad_token_id)
|
| 78 |
+
|
| 79 |
+
return shifted_input_ids
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
# Copied from transformers.models.wav2vec2.modeling_wav2vec2._compute_mask_indices
|
| 83 |
+
def _compute_mask_indices(
|
| 84 |
+
shape: tuple[int, int],
|
| 85 |
+
mask_prob: float,
|
| 86 |
+
mask_length: int,
|
| 87 |
+
attention_mask: torch.LongTensor | None = None,
|
| 88 |
+
min_masks: int = 0,
|
| 89 |
+
) -> np.ndarray:
|
| 90 |
+
"""
|
| 91 |
+
Computes random mask spans for a given shape. Used to implement [SpecAugment: A Simple Data Augmentation Method for
|
| 92 |
+
ASR](https://huggingface.co/papers/1904.08779). Note that this method is not optimized to run on TPU and should be run on
|
| 93 |
+
CPU as part of the preprocessing during training.
|
| 94 |
+
|
| 95 |
+
Args:
|
| 96 |
+
shape: The shape for which to compute masks. This should be of a tuple of size 2 where
|
| 97 |
+
the first element is the batch size and the second element is the length of the axis to span.
|
| 98 |
+
mask_prob: The percentage of the whole axis (between 0 and 1) which will be masked. The number of
|
| 99 |
+
independently generated mask spans of length `mask_length` is computed by
|
| 100 |
+
`mask_prob*shape[1]/mask_length`. Note that due to overlaps, `mask_prob` is an upper bound and the
|
| 101 |
+
actual percentage will be smaller.
|
| 102 |
+
mask_length: size of the mask
|
| 103 |
+
min_masks: minimum number of masked spans
|
| 104 |
+
attention_mask: A (right-padded) attention mask which independently shortens the feature axis of
|
| 105 |
+
each batch dimension.
|
| 106 |
+
"""
|
| 107 |
+
batch_size, sequence_length = shape
|
| 108 |
+
|
| 109 |
+
if mask_length < 1:
|
| 110 |
+
raise ValueError("`mask_length` has to be bigger than 0.")
|
| 111 |
+
|
| 112 |
+
if mask_length > sequence_length:
|
| 113 |
+
raise ValueError(
|
| 114 |
+
f"`mask_length` has to be smaller than `sequence_length`, but got `mask_length`: {mask_length}"
|
| 115 |
+
f" and `sequence_length`: {sequence_length}`"
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
# epsilon is used for probabilistic rounding
|
| 119 |
+
epsilon = np.random.rand(1).item()
|
| 120 |
+
|
| 121 |
+
def compute_num_masked_span(input_length):
|
| 122 |
+
"""Given input length, compute how many spans should be masked"""
|
| 123 |
+
num_masked_span = int(mask_prob * input_length / mask_length + epsilon)
|
| 124 |
+
num_masked_span = max(num_masked_span, min_masks)
|
| 125 |
+
|
| 126 |
+
# make sure num masked span <= sequence_length
|
| 127 |
+
if num_masked_span * mask_length > sequence_length:
|
| 128 |
+
num_masked_span = sequence_length // mask_length
|
| 129 |
+
|
| 130 |
+
# make sure num_masked span is also <= input_length - (mask_length - 1)
|
| 131 |
+
if input_length - (mask_length - 1) < num_masked_span:
|
| 132 |
+
num_masked_span = max(input_length - (mask_length - 1), 0)
|
| 133 |
+
|
| 134 |
+
return num_masked_span
|
| 135 |
+
|
| 136 |
+
# compute number of masked spans in batch
|
| 137 |
+
input_lengths = (
|
| 138 |
+
attention_mask.detach().sum(-1).tolist()
|
| 139 |
+
if attention_mask is not None
|
| 140 |
+
else [sequence_length for _ in range(batch_size)]
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
# SpecAugment mask to fill
|
| 144 |
+
spec_aug_mask = np.zeros((batch_size, sequence_length), dtype=bool)
|
| 145 |
+
spec_aug_mask_idxs = []
|
| 146 |
+
|
| 147 |
+
max_num_masked_span = compute_num_masked_span(sequence_length)
|
| 148 |
+
|
| 149 |
+
if max_num_masked_span == 0:
|
| 150 |
+
return spec_aug_mask
|
| 151 |
+
|
| 152 |
+
for input_length in input_lengths:
|
| 153 |
+
# compute num of masked spans for this input
|
| 154 |
+
num_masked_span = compute_num_masked_span(input_length)
|
| 155 |
+
|
| 156 |
+
# get random indices to mask
|
| 157 |
+
spec_aug_mask_idx = np.random.choice(
|
| 158 |
+
np.arange(input_length - (mask_length - 1)), num_masked_span, replace=False
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
# pick first sampled index that will serve as a dummy index to pad vector
|
| 162 |
+
# to ensure same dimension for all batches due to probabilistic rounding
|
| 163 |
+
# Picking first sample just pads those vectors twice.
|
| 164 |
+
if len(spec_aug_mask_idx) == 0:
|
| 165 |
+
# this case can only happen if `input_length` is strictly smaller then
|
| 166 |
+
# `sequence_length` in which case the last token has to be a padding
|
| 167 |
+
# token which we can use as a dummy mask id
|
| 168 |
+
dummy_mask_idx = sequence_length - 1
|
| 169 |
+
else:
|
| 170 |
+
dummy_mask_idx = spec_aug_mask_idx[0]
|
| 171 |
+
|
| 172 |
+
spec_aug_mask_idx = np.concatenate(
|
| 173 |
+
[spec_aug_mask_idx, np.ones(max_num_masked_span - num_masked_span, dtype=np.int32) * dummy_mask_idx]
|
| 174 |
+
)
|
| 175 |
+
spec_aug_mask_idxs.append(spec_aug_mask_idx)
|
| 176 |
+
|
| 177 |
+
spec_aug_mask_idxs = np.array(spec_aug_mask_idxs)
|
| 178 |
+
|
| 179 |
+
# expand masked indices to masked spans
|
| 180 |
+
spec_aug_mask_idxs = np.broadcast_to(
|
| 181 |
+
spec_aug_mask_idxs[:, :, None], (batch_size, max_num_masked_span, mask_length)
|
| 182 |
+
)
|
| 183 |
+
spec_aug_mask_idxs = spec_aug_mask_idxs.reshape(batch_size, max_num_masked_span * mask_length)
|
| 184 |
+
|
| 185 |
+
# add offset to the starting indexes so that indexes now create a span
|
| 186 |
+
offsets = np.arange(mask_length)[None, None, :]
|
| 187 |
+
offsets = np.broadcast_to(offsets, (batch_size, max_num_masked_span, mask_length)).reshape(
|
| 188 |
+
batch_size, max_num_masked_span * mask_length
|
| 189 |
+
)
|
| 190 |
+
spec_aug_mask_idxs = spec_aug_mask_idxs + offsets
|
| 191 |
+
|
| 192 |
+
# ensure that we cannot have indices larger than sequence_length
|
| 193 |
+
if spec_aug_mask_idxs.max() > sequence_length - 1:
|
| 194 |
+
spec_aug_mask_idxs[spec_aug_mask_idxs > sequence_length - 1] = sequence_length - 1
|
| 195 |
+
|
| 196 |
+
# scatter indices to mask
|
| 197 |
+
np.put_along_axis(spec_aug_mask, spec_aug_mask_idxs, 1, -1)
|
| 198 |
+
|
| 199 |
+
return spec_aug_mask
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
class WhisperPositionalEmbedding(nn.Embedding):
|
| 203 |
+
def __init__(self, num_positions: int, embedding_dim: int, padding_idx: int | None = None):
|
| 204 |
+
super().__init__(num_positions, embedding_dim)
|
| 205 |
+
|
| 206 |
+
def forward(self, input_ids, past_key_values_length=0, position_ids=None):
|
| 207 |
+
if position_ids is None:
|
| 208 |
+
return self.weight[past_key_values_length : past_key_values_length + input_ids.shape[1]]
|
| 209 |
+
else:
|
| 210 |
+
return self.weight[position_ids]
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def eager_attention_forward(
|
| 214 |
+
module: nn.Module,
|
| 215 |
+
query: torch.Tensor,
|
| 216 |
+
key: torch.Tensor,
|
| 217 |
+
value: torch.Tensor,
|
| 218 |
+
attention_mask: torch.Tensor | None,
|
| 219 |
+
scaling: float | None = None,
|
| 220 |
+
dropout: float = 0.0,
|
| 221 |
+
**kwargs,
|
| 222 |
+
):
|
| 223 |
+
if scaling is None:
|
| 224 |
+
scaling = query.size(-1) ** -0.5
|
| 225 |
+
|
| 226 |
+
attn_weights = torch.matmul(query, key.transpose(2, 3)) * scaling
|
| 227 |
+
if attention_mask is not None:
|
| 228 |
+
attn_weights = attn_weights + attention_mask
|
| 229 |
+
|
| 230 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1)
|
| 231 |
+
|
| 232 |
+
attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
|
| 233 |
+
attn_output = torch.matmul(attn_weights, value)
|
| 234 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 235 |
+
|
| 236 |
+
return attn_output, attn_weights
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
class WhisperAttention(nn.Module):
|
| 240 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 241 |
+
|
| 242 |
+
def __init__(
|
| 243 |
+
self,
|
| 244 |
+
embed_dim: int,
|
| 245 |
+
num_heads: int,
|
| 246 |
+
dropout: float = 0.0,
|
| 247 |
+
is_decoder: bool = False,
|
| 248 |
+
bias: bool = True,
|
| 249 |
+
is_causal: bool = False,
|
| 250 |
+
layer_idx: int | None = None,
|
| 251 |
+
config: WhisperConfig | None = None,
|
| 252 |
+
):
|
| 253 |
+
super().__init__()
|
| 254 |
+
self.embed_dim = embed_dim
|
| 255 |
+
self.num_heads = num_heads
|
| 256 |
+
self.dropout = dropout
|
| 257 |
+
self.head_dim = embed_dim // num_heads
|
| 258 |
+
self.config = config
|
| 259 |
+
|
| 260 |
+
if (self.head_dim * num_heads) != self.embed_dim:
|
| 261 |
+
raise ValueError(
|
| 262 |
+
f"embed_dim must be divisible by num_heads (got `embed_dim`: {self.embed_dim}"
|
| 263 |
+
f" and `num_heads`: {num_heads})."
|
| 264 |
+
)
|
| 265 |
+
self.scaling = self.head_dim**-0.5
|
| 266 |
+
self.is_decoder = is_decoder
|
| 267 |
+
self.is_causal = is_causal
|
| 268 |
+
|
| 269 |
+
if layer_idx is None and is_decoder:
|
| 270 |
+
logger.warning_once(
|
| 271 |
+
f"Instantiating a decoder {self.__class__.__name__} without passing `layer_idx` is not recommended and "
|
| 272 |
+
"will to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` "
|
| 273 |
+
"when creating this class."
|
| 274 |
+
)
|
| 275 |
+
self.layer_idx = layer_idx
|
| 276 |
+
|
| 277 |
+
self.k_proj = nn.Linear(embed_dim, embed_dim, bias=False)
|
| 278 |
+
self.v_proj = nn.Linear(embed_dim, embed_dim, bias=bias)
|
| 279 |
+
self.q_proj = nn.Linear(embed_dim, embed_dim, bias=bias)
|
| 280 |
+
self.out_proj = nn.Linear(embed_dim, embed_dim, bias=bias)
|
| 281 |
+
|
| 282 |
+
def forward(
|
| 283 |
+
self,
|
| 284 |
+
hidden_states: torch.Tensor,
|
| 285 |
+
key_value_states: torch.Tensor | None = None,
|
| 286 |
+
past_key_values: Cache | None = None,
|
| 287 |
+
attention_mask: torch.Tensor | None = None,
|
| 288 |
+
output_attentions: bool = False,
|
| 289 |
+
cache_position: torch.Tensor | None = None,
|
| 290 |
+
# TODO: we need a refactor so that the different attention modules can get their specific kwargs
|
| 291 |
+
# ATM, we have mixed things encoder, decoder, and encoder-decoder attn
|
| 292 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 293 |
+
) -> tuple[torch.Tensor, torch.Tensor | None, tuple[torch.Tensor] | None]:
|
| 294 |
+
"""Input shape: Batch x Time x Channel"""
|
| 295 |
+
|
| 296 |
+
# if key_value_states are provided this layer is used as a cross-attention layer
|
| 297 |
+
# for the decoder
|
| 298 |
+
is_cross_attention = key_value_states is not None
|
| 299 |
+
|
| 300 |
+
# determine input shapes
|
| 301 |
+
bsz, tgt_len = hidden_states.shape[:-1]
|
| 302 |
+
q_input_shape = (bsz, tgt_len, -1, self.head_dim)
|
| 303 |
+
|
| 304 |
+
# Scaling is susceptible to floating point arithmetics' inprecisions
|
| 305 |
+
# which can lead to different results (this is dependent from model
|
| 306 |
+
# to model, e.g. whisper is one such case). We therefore keep the
|
| 307 |
+
# original order of scaling to follow the original implementation
|
| 308 |
+
# and enforce no scaling (1.0) in the attention call below.
|
| 309 |
+
query_states = self.q_proj(hidden_states) * self.scaling
|
| 310 |
+
query_states = query_states.view(*q_input_shape)
|
| 311 |
+
query_states = query_states.transpose(1, 2).contiguous()
|
| 312 |
+
|
| 313 |
+
# Check is encoder-decoder model is being used. Otherwise we'll get `DynamicCache`
|
| 314 |
+
if past_key_values is not None and isinstance(past_key_values, EncoderDecoderCache):
|
| 315 |
+
is_updated = past_key_values.is_updated.get(self.layer_idx)
|
| 316 |
+
if is_cross_attention:
|
| 317 |
+
# after the first generated id, we can subsequently re-use all key/value_states from cache
|
| 318 |
+
past_key_values.is_updated[self.layer_idx] = True
|
| 319 |
+
past_key_values = past_key_values.cross_attention_cache
|
| 320 |
+
else:
|
| 321 |
+
past_key_values = past_key_values.self_attention_cache
|
| 322 |
+
|
| 323 |
+
# use key_value_states if cross attention
|
| 324 |
+
current_states = key_value_states if key_value_states is not None else hidden_states
|
| 325 |
+
if is_cross_attention and past_key_values and is_updated:
|
| 326 |
+
# reuse k,v, cross_attentions
|
| 327 |
+
key_states = past_key_values.layers[self.layer_idx].keys
|
| 328 |
+
value_states = past_key_values.layers[self.layer_idx].values
|
| 329 |
+
else:
|
| 330 |
+
key_states = self.k_proj(current_states).view(bsz, -1, self.num_heads, self.head_dim)
|
| 331 |
+
value_states = self.v_proj(current_states).view(bsz, -1, self.num_heads, self.head_dim)
|
| 332 |
+
key_states = key_states.transpose(1, 2).contiguous()
|
| 333 |
+
value_states = value_states.transpose(1, 2).contiguous()
|
| 334 |
+
if past_key_values is not None:
|
| 335 |
+
# save all key/value_states to cache to be re-used for fast auto-regressive generation
|
| 336 |
+
cache_position = cache_position if not is_cross_attention else None
|
| 337 |
+
key_states, value_states = past_key_values.update(
|
| 338 |
+
key_states, value_states, self.layer_idx, {"cache_position": cache_position}
|
| 339 |
+
)
|
| 340 |
+
|
| 341 |
+
attention_interface: Callable = ALL_ATTENTION_FUNCTIONS.get_interface(
|
| 342 |
+
self.config._attn_implementation, eager_attention_forward
|
| 343 |
+
)
|
| 344 |
+
|
| 345 |
+
attn_output, attn_weights = attention_interface(
|
| 346 |
+
self,
|
| 347 |
+
query_states,
|
| 348 |
+
key_states,
|
| 349 |
+
value_states,
|
| 350 |
+
attention_mask,
|
| 351 |
+
dropout=0.0 if not self.training else self.dropout,
|
| 352 |
+
scaling=1.0,
|
| 353 |
+
output_attentions=output_attentions,
|
| 354 |
+
**kwargs,
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
attn_output = attn_output.reshape(bsz, tgt_len, -1).contiguous()
|
| 358 |
+
attn_output = self.out_proj(attn_output)
|
| 359 |
+
|
| 360 |
+
return attn_output, attn_weights
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
# Copied from transformers.models.mbart.modeling_mbart.MBartEncoderLayer with MBart->Whisper, MBART->WHISPER
|
| 364 |
+
class WhisperEncoderLayer(GradientCheckpointingLayer):
|
| 365 |
+
def __init__(self, config: WhisperConfig):
|
| 366 |
+
super().__init__()
|
| 367 |
+
self.embed_dim = config.d_model
|
| 368 |
+
|
| 369 |
+
self.self_attn = WhisperAttention(
|
| 370 |
+
embed_dim=self.embed_dim,
|
| 371 |
+
num_heads=config.encoder_attention_heads,
|
| 372 |
+
dropout=config.attention_dropout,
|
| 373 |
+
config=config,
|
| 374 |
+
)
|
| 375 |
+
self.self_attn_layer_norm = nn.LayerNorm(self.embed_dim)
|
| 376 |
+
self.dropout = config.dropout
|
| 377 |
+
self.activation_fn = ACT2FN[config.activation_function]
|
| 378 |
+
self.activation_dropout = config.activation_dropout
|
| 379 |
+
self.fc1 = nn.Linear(self.embed_dim, config.encoder_ffn_dim)
|
| 380 |
+
self.fc2 = nn.Linear(config.encoder_ffn_dim, self.embed_dim)
|
| 381 |
+
self.final_layer_norm = nn.LayerNorm(self.embed_dim)
|
| 382 |
+
|
| 383 |
+
def forward(
|
| 384 |
+
self,
|
| 385 |
+
hidden_states: torch.Tensor,
|
| 386 |
+
attention_mask: torch.Tensor,
|
| 387 |
+
output_attentions: bool = False,
|
| 388 |
+
) -> torch.Tensor:
|
| 389 |
+
"""
|
| 390 |
+
Args:
|
| 391 |
+
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
|
| 392 |
+
attention_mask (`torch.FloatTensor`): attention mask of size
|
| 393 |
+
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
|
| 394 |
+
output_attentions (`bool`, *optional*):
|
| 395 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
| 396 |
+
returned tensors for more detail.
|
| 397 |
+
"""
|
| 398 |
+
residual = hidden_states
|
| 399 |
+
hidden_states = self.self_attn_layer_norm(hidden_states)
|
| 400 |
+
hidden_states, attn_weights = self.self_attn(
|
| 401 |
+
hidden_states=hidden_states,
|
| 402 |
+
attention_mask=attention_mask,
|
| 403 |
+
output_attentions=output_attentions,
|
| 404 |
+
)
|
| 405 |
+
hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
|
| 406 |
+
hidden_states = residual + hidden_states
|
| 407 |
+
|
| 408 |
+
residual = hidden_states
|
| 409 |
+
hidden_states = self.final_layer_norm(hidden_states)
|
| 410 |
+
hidden_states = self.activation_fn(self.fc1(hidden_states))
|
| 411 |
+
hidden_states = nn.functional.dropout(hidden_states, p=self.activation_dropout, training=self.training)
|
| 412 |
+
hidden_states = self.fc2(hidden_states)
|
| 413 |
+
hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
|
| 414 |
+
hidden_states = residual + hidden_states
|
| 415 |
+
|
| 416 |
+
if hidden_states.dtype == torch.float16:
|
| 417 |
+
clamp_value = torch.finfo(hidden_states.dtype).max - 1000
|
| 418 |
+
hidden_states = torch.clamp(hidden_states, min=-clamp_value, max=clamp_value)
|
| 419 |
+
|
| 420 |
+
return hidden_states, attn_weights
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
class WhisperDecoderLayer(GradientCheckpointingLayer):
|
| 424 |
+
def __init__(self, config: WhisperConfig, layer_idx: int | None = None):
|
| 425 |
+
super().__init__()
|
| 426 |
+
self.embed_dim = config.d_model
|
| 427 |
+
|
| 428 |
+
self.self_attn = WhisperAttention(
|
| 429 |
+
embed_dim=self.embed_dim,
|
| 430 |
+
num_heads=config.decoder_attention_heads,
|
| 431 |
+
dropout=config.attention_dropout,
|
| 432 |
+
is_decoder=True,
|
| 433 |
+
is_causal=True,
|
| 434 |
+
layer_idx=layer_idx,
|
| 435 |
+
config=config,
|
| 436 |
+
)
|
| 437 |
+
self.dropout = config.dropout
|
| 438 |
+
self.activation_fn = ACT2FN[config.activation_function]
|
| 439 |
+
self.activation_dropout = config.activation_dropout
|
| 440 |
+
|
| 441 |
+
self.self_attn_layer_norm = nn.LayerNorm(self.embed_dim)
|
| 442 |
+
self.encoder_attn = WhisperAttention(
|
| 443 |
+
self.embed_dim,
|
| 444 |
+
config.decoder_attention_heads,
|
| 445 |
+
dropout=config.attention_dropout,
|
| 446 |
+
is_decoder=True,
|
| 447 |
+
layer_idx=layer_idx,
|
| 448 |
+
config=config,
|
| 449 |
+
)
|
| 450 |
+
self.encoder_attn_layer_norm = nn.LayerNorm(self.embed_dim)
|
| 451 |
+
self.fc1 = nn.Linear(self.embed_dim, config.decoder_ffn_dim)
|
| 452 |
+
self.fc2 = nn.Linear(config.decoder_ffn_dim, self.embed_dim)
|
| 453 |
+
self.final_layer_norm = nn.LayerNorm(self.embed_dim)
|
| 454 |
+
|
| 455 |
+
def forward(
|
| 456 |
+
self,
|
| 457 |
+
hidden_states: torch.Tensor,
|
| 458 |
+
attention_mask: torch.Tensor | None = None,
|
| 459 |
+
encoder_hidden_states: torch.Tensor | None = None,
|
| 460 |
+
encoder_attention_mask: torch.Tensor | None = None,
|
| 461 |
+
past_key_values: EncoderDecoderCache | None = None,
|
| 462 |
+
output_attentions: bool | None = False,
|
| 463 |
+
use_cache: bool | None = True,
|
| 464 |
+
cache_position: torch.LongTensor | None = None,
|
| 465 |
+
) -> torch.Tensor:
|
| 466 |
+
"""
|
| 467 |
+
Args:
|
| 468 |
+
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
|
| 469 |
+
attention_mask (`torch.FloatTensor`): attention mask of size
|
| 470 |
+
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
|
| 471 |
+
encoder_hidden_states (`torch.FloatTensor`):
|
| 472 |
+
cross attention input to the layer of shape `(batch, seq_len, embed_dim)`
|
| 473 |
+
encoder_attention_mask (`torch.FloatTensor`): encoder attention mask of size
|
| 474 |
+
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
|
| 475 |
+
past_key_values (`Cache`): cached past key and value projection states
|
| 476 |
+
output_attentions (`bool`, *optional*):
|
| 477 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
| 478 |
+
returned tensors for more detail.
|
| 479 |
+
"""
|
| 480 |
+
residual = hidden_states
|
| 481 |
+
hidden_states = self.self_attn_layer_norm(hidden_states)
|
| 482 |
+
|
| 483 |
+
# Self Attention
|
| 484 |
+
hidden_states, self_attn_weights = self.self_attn(
|
| 485 |
+
hidden_states=hidden_states,
|
| 486 |
+
past_key_values=past_key_values,
|
| 487 |
+
attention_mask=attention_mask,
|
| 488 |
+
output_attentions=output_attentions,
|
| 489 |
+
cache_position=cache_position,
|
| 490 |
+
)
|
| 491 |
+
hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
|
| 492 |
+
hidden_states = residual + hidden_states
|
| 493 |
+
|
| 494 |
+
# Cross-Attention Block
|
| 495 |
+
cross_attn_weights = None
|
| 496 |
+
if encoder_hidden_states is not None:
|
| 497 |
+
residual = hidden_states
|
| 498 |
+
hidden_states = self.encoder_attn_layer_norm(hidden_states)
|
| 499 |
+
hidden_states, cross_attn_weights = self.encoder_attn(
|
| 500 |
+
hidden_states=hidden_states,
|
| 501 |
+
key_value_states=encoder_hidden_states,
|
| 502 |
+
attention_mask=encoder_attention_mask,
|
| 503 |
+
past_key_values=past_key_values,
|
| 504 |
+
output_attentions=output_attentions,
|
| 505 |
+
)
|
| 506 |
+
hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
|
| 507 |
+
hidden_states = residual + hidden_states
|
| 508 |
+
|
| 509 |
+
# Fully Connected
|
| 510 |
+
residual = hidden_states
|
| 511 |
+
hidden_states = self.final_layer_norm(hidden_states)
|
| 512 |
+
hidden_states = self.activation_fn(self.fc1(hidden_states))
|
| 513 |
+
hidden_states = nn.functional.dropout(hidden_states, p=self.activation_dropout, training=self.training)
|
| 514 |
+
hidden_states = self.fc2(hidden_states)
|
| 515 |
+
hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
|
| 516 |
+
hidden_states = residual + hidden_states
|
| 517 |
+
|
| 518 |
+
outputs = (hidden_states,)
|
| 519 |
+
|
| 520 |
+
if output_attentions:
|
| 521 |
+
outputs += (self_attn_weights, cross_attn_weights)
|
| 522 |
+
|
| 523 |
+
return outputs
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
@auto_docstring
|
| 527 |
+
class WhisperPreTrainedModel(PreTrainedModel):
|
| 528 |
+
config: WhisperConfig
|
| 529 |
+
base_model_prefix = "model"
|
| 530 |
+
main_input_name = "input_features"
|
| 531 |
+
input_modalities = ("audio", "text")
|
| 532 |
+
supports_gradient_checkpointing = True
|
| 533 |
+
_no_split_modules = ["WhisperEncoderLayer", "WhisperDecoderLayer"]
|
| 534 |
+
_supports_flash_attn = True
|
| 535 |
+
_supports_sdpa = True
|
| 536 |
+
_supports_flex_attn = True
|
| 537 |
+
|
| 538 |
+
_can_compile_fullgraph = True
|
| 539 |
+
|
| 540 |
+
@torch.no_grad()
|
| 541 |
+
def _init_weights(self, module):
|
| 542 |
+
super()._init_weights(module)
|
| 543 |
+
if isinstance(module, WhisperEncoder):
|
| 544 |
+
init.copy_(module.embed_positions.weight, sinusoids(*module.embed_positions.weight.shape))
|
| 545 |
+
elif isinstance(module, WhisperForAudioClassification):
|
| 546 |
+
if self.config.use_weighted_layer_sum:
|
| 547 |
+
init.constant_(module.layer_weights, 1.0 / (self.config.num_hidden_layers + 1))
|
| 548 |
+
|
| 549 |
+
def _get_feat_extract_output_lengths(self, input_lengths: torch.LongTensor):
|
| 550 |
+
"""
|
| 551 |
+
Computes the output length of the convolutional layers
|
| 552 |
+
"""
|
| 553 |
+
input_lengths = (input_lengths - 1) // 2 + 1
|
| 554 |
+
|
| 555 |
+
return input_lengths
|
| 556 |
+
|
| 557 |
+
|
| 558 |
+
class WhisperEncoder(WhisperPreTrainedModel):
|
| 559 |
+
"""
|
| 560 |
+
Transformer encoder consisting of *config.encoder_layers* self attention layers. Each layer is a
|
| 561 |
+
[`WhisperEncoderLayer`].
|
| 562 |
+
|
| 563 |
+
Args:
|
| 564 |
+
config: WhisperConfig
|
| 565 |
+
"""
|
| 566 |
+
|
| 567 |
+
def __init__(self, config: WhisperConfig):
|
| 568 |
+
super().__init__(config)
|
| 569 |
+
self.dropout = config.dropout
|
| 570 |
+
self.layerdrop = config.encoder_layerdrop
|
| 571 |
+
|
| 572 |
+
embed_dim = config.d_model
|
| 573 |
+
self.num_mel_bins = config.num_mel_bins
|
| 574 |
+
self.padding_idx = config.pad_token_id
|
| 575 |
+
self.max_source_positions = config.max_source_positions
|
| 576 |
+
self.embed_scale = math.sqrt(embed_dim) if config.scale_embedding else 1.0
|
| 577 |
+
|
| 578 |
+
self.conv1 = nn.Conv1d(self.num_mel_bins, embed_dim, kernel_size=3, padding=1)
|
| 579 |
+
self.conv2 = nn.Conv1d(embed_dim, embed_dim, kernel_size=3, stride=2, padding=1)
|
| 580 |
+
|
| 581 |
+
self.embed_positions = nn.Embedding(self.max_source_positions, embed_dim)
|
| 582 |
+
self.embed_positions.requires_grad_(False)
|
| 583 |
+
|
| 584 |
+
self.layers = nn.ModuleList([WhisperEncoderLayer(config) for _ in range(config.encoder_layers)])
|
| 585 |
+
self.layer_norm = nn.LayerNorm(config.d_model)
|
| 586 |
+
|
| 587 |
+
self.qformer = BertLMHeadModel._from_config(config.qformer_config, torch_dtype=torch.bfloat16)
|
| 588 |
+
self.q_tokens = nn.Parameter(torch.randn(1, config.qformer_config.query_length, config.qformer_config.hidden_size) * config.qformer_config.initializer_range)
|
| 589 |
+
self.q_tokens.data.normal_(mean=0.0, std=config.qformer_config.initializer_range)
|
| 590 |
+
self.audio_proj = nn.Linear(config.qformer_config.hidden_size, config.qformer_config.out_hidden_size, dtype=torch.bfloat16)
|
| 591 |
+
|
| 592 |
+
self.gradient_checkpointing = False
|
| 593 |
+
# Initialize weights and apply final processing
|
| 594 |
+
self.post_init()
|
| 595 |
+
|
| 596 |
+
def _freeze_parameters(self):
|
| 597 |
+
for param in self.parameters():
|
| 598 |
+
param.requires_grad = False
|
| 599 |
+
self._requires_grad = False
|
| 600 |
+
|
| 601 |
+
def get_input_embeddings(self) -> nn.Module:
|
| 602 |
+
return self.conv1
|
| 603 |
+
|
| 604 |
+
def set_input_embeddings(self, value: nn.Module):
|
| 605 |
+
self.conv1 = value
|
| 606 |
+
|
| 607 |
+
def forward(
|
| 608 |
+
self,
|
| 609 |
+
input_features,
|
| 610 |
+
attention_mask=None,
|
| 611 |
+
output_attentions=None,
|
| 612 |
+
output_hidden_states=None,
|
| 613 |
+
return_dict=None,
|
| 614 |
+
**kwargs,
|
| 615 |
+
):
|
| 616 |
+
r"""
|
| 617 |
+
Args:
|
| 618 |
+
input_features (`torch.LongTensor` of shape `(batch_size, feature_size, sequence_length)`):
|
| 619 |
+
Float values of mel features extracted from the raw speech waveform. Raw speech waveform can be
|
| 620 |
+
obtained by loading a `.flac` or `.wav` audio file into an array of type `list[float]`, a
|
| 621 |
+
`numpy.ndarray` or a `torch.Tensor`, *e.g.* via the torchcodec library (`pip install torchcodec`) or
|
| 622 |
+
the soundfile library (`pip install soundfile`). To prepare the array into
|
| 623 |
+
`input_features`, the [`AutoFeatureExtractor`] should be used for extracting the mel features, padding
|
| 624 |
+
and conversion into a tensor of type `torch.FloatTensor`. See [`~WhisperFeatureExtractor.__call__`]
|
| 625 |
+
attention_mask (`torch.Tensor`)`, *optional*):
|
| 626 |
+
Whisper does not support masking of the `input_features`, this argument is preserved for compatibility,
|
| 627 |
+
but it is not used. By default the silence in the input log mel spectrogram are ignored.
|
| 628 |
+
output_attentions (`bool`, *optional*):
|
| 629 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
| 630 |
+
returned tensors for more detail.
|
| 631 |
+
output_hidden_states (`bool`, *optional*):
|
| 632 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
|
| 633 |
+
for more detail.
|
| 634 |
+
return_dict (`bool`, *optional*):
|
| 635 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
| 636 |
+
"""
|
| 637 |
+
|
| 638 |
+
expected_seq_length = self.config.max_source_positions * self.conv1.stride[0] * self.conv2.stride[0]
|
| 639 |
+
if input_features.shape[-1] != expected_seq_length:
|
| 640 |
+
raise ValueError(
|
| 641 |
+
f"Whisper expects the mel input features to be of length {expected_seq_length}, but found {input_features.shape[-1]}. Make sure to pad the input mel features to {expected_seq_length}."
|
| 642 |
+
)
|
| 643 |
+
|
| 644 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 645 |
+
output_hidden_states = (
|
| 646 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 647 |
+
)
|
| 648 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 649 |
+
inputs_embeds = nn.functional.gelu(self.conv1(input_features))
|
| 650 |
+
inputs_embeds = nn.functional.gelu(self.conv2(inputs_embeds))
|
| 651 |
+
|
| 652 |
+
inputs_embeds = inputs_embeds.permute(0, 2, 1)
|
| 653 |
+
all_positions = torch.arange(self.embed_positions.num_embeddings, device=inputs_embeds.device)
|
| 654 |
+
|
| 655 |
+
hidden_states = inputs_embeds + self.embed_positions(all_positions)
|
| 656 |
+
hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
|
| 657 |
+
|
| 658 |
+
encoder_states = () if output_hidden_states else None
|
| 659 |
+
all_attentions = () if output_attentions else None
|
| 660 |
+
|
| 661 |
+
for idx, encoder_layer in enumerate(self.layers):
|
| 662 |
+
if output_hidden_states:
|
| 663 |
+
encoder_states = encoder_states + (hidden_states,)
|
| 664 |
+
# add LayerDrop (see https://huggingface.co/papers/1909.11556 for description)
|
| 665 |
+
to_drop = False
|
| 666 |
+
if self.training:
|
| 667 |
+
dropout_probability = torch.rand([])
|
| 668 |
+
if dropout_probability < self.layerdrop: # skip the layer
|
| 669 |
+
to_drop = True
|
| 670 |
+
|
| 671 |
+
if to_drop:
|
| 672 |
+
layer_outputs = (None, None)
|
| 673 |
+
else:
|
| 674 |
+
layer_outputs = encoder_layer(
|
| 675 |
+
hidden_states,
|
| 676 |
+
attention_mask=None,
|
| 677 |
+
output_attentions=output_attentions,
|
| 678 |
+
)
|
| 679 |
+
|
| 680 |
+
hidden_states = layer_outputs[0]
|
| 681 |
+
|
| 682 |
+
if output_attentions:
|
| 683 |
+
all_attentions = all_attentions + (layer_outputs[1],)
|
| 684 |
+
|
| 685 |
+
|
| 686 |
+
speech_embeds = self.layer_norm(hidden_states)
|
| 687 |
+
speech_atts = torch.ones(speech_embeds.size()[:-1], dtype=torch.long).to(speech_embeds.device)
|
| 688 |
+
B, T, C = speech_embeds.shape
|
| 689 |
+
kernel = round(1500 * self.config.second_per_window / 30.0)
|
| 690 |
+
stride = round(1500 * self.config.second_stride / 30.0)
|
| 691 |
+
kernel = (1, kernel)
|
| 692 |
+
stride = (1, stride)
|
| 693 |
+
speech_embeds_tr = speech_embeds.transpose(1, 2).unsqueeze(2)
|
| 694 |
+
speech_embeds_overlap = F.unfold(speech_embeds_tr, kernel_size=kernel, dilation=1, padding=0, stride=stride)
|
| 695 |
+
_, _, L = speech_embeds_overlap.shape
|
| 696 |
+
speech_embeds_overlap = speech_embeds_overlap.view(B, -1, kernel[1], L)
|
| 697 |
+
speech_embeds_overlap = torch.permute(speech_embeds_overlap, [0, 3, 2, 1])
|
| 698 |
+
speech_embeds = speech_embeds_overlap.reshape(-1, kernel[1], C)
|
| 699 |
+
speech_atts = torch.ones(speech_embeds.size()[:-1], dtype=torch.long, device=speech_embeds.device)
|
| 700 |
+
query_tokens = self.q_tokens.expand(speech_embeds.shape[0], -1, -1)
|
| 701 |
+
query_output = self.qformer.bert(
|
| 702 |
+
query_embeds=query_tokens,
|
| 703 |
+
encoder_hidden_states=speech_embeds,
|
| 704 |
+
encoder_attention_mask=speech_atts,
|
| 705 |
+
return_dict=True,
|
| 706 |
+
)
|
| 707 |
+
speech_embeds = self.audio_proj(query_output.last_hidden_state)
|
| 708 |
+
speech_embeds = speech_embeds.view(B, -1, speech_embeds.size(2)).contiguous()
|
| 709 |
+
return speech_embeds
|
| 710 |
+
|
| 711 |
+
# hidden_states = self.layer_norm(hidden_states)
|
| 712 |
+
# if output_hidden_states:
|
| 713 |
+
# encoder_states = encoder_states + (hidden_states,)
|
| 714 |
+
|
| 715 |
+
# if not return_dict:
|
| 716 |
+
# return tuple(v for v in [hidden_states, encoder_states, all_attentions] if v is not None)
|
| 717 |
+
# return BaseModelOutput(
|
| 718 |
+
# last_hidden_state=hidden_states, hidden_states=encoder_states, attentions=all_attentions
|
| 719 |
+
# )
|
| 720 |
+
|
| 721 |
+
|
| 722 |
+
class WhisperDecoder(WhisperPreTrainedModel):
|
| 723 |
+
"""
|
| 724 |
+
Transformer decoder consisting of *config.decoder_layers* layers. Each layer is a [`WhisperDecoderLayer`]
|
| 725 |
+
|
| 726 |
+
Args:
|
| 727 |
+
config: WhisperConfig
|
| 728 |
+
"""
|
| 729 |
+
|
| 730 |
+
main_input_name = "input_ids"
|
| 731 |
+
|
| 732 |
+
def __init__(self, config: WhisperConfig):
|
| 733 |
+
super().__init__(config)
|
| 734 |
+
self.dropout = config.dropout
|
| 735 |
+
self.layerdrop = config.decoder_layerdrop
|
| 736 |
+
self.padding_idx = config.pad_token_id
|
| 737 |
+
self.max_target_positions = config.max_target_positions
|
| 738 |
+
self.max_source_positions = config.max_source_positions
|
| 739 |
+
self.embed_scale = math.sqrt(config.d_model) if config.scale_embedding else 1.0
|
| 740 |
+
|
| 741 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.d_model, self.padding_idx)
|
| 742 |
+
self.embed_positions = WhisperPositionalEmbedding(self.max_target_positions, config.d_model)
|
| 743 |
+
|
| 744 |
+
self.layers = nn.ModuleList(
|
| 745 |
+
[WhisperDecoderLayer(config, layer_idx) for layer_idx in range(config.decoder_layers)]
|
| 746 |
+
)
|
| 747 |
+
|
| 748 |
+
self.layer_norm = nn.LayerNorm(config.d_model)
|
| 749 |
+
|
| 750 |
+
self.gradient_checkpointing = False
|
| 751 |
+
# Initialize weights and apply final processing
|
| 752 |
+
self.post_init()
|
| 753 |
+
|
| 754 |
+
def forward(
|
| 755 |
+
self,
|
| 756 |
+
input_ids=None,
|
| 757 |
+
attention_mask=None,
|
| 758 |
+
encoder_hidden_states=None,
|
| 759 |
+
past_key_values=None,
|
| 760 |
+
inputs_embeds=None,
|
| 761 |
+
position_ids=None,
|
| 762 |
+
use_cache=None,
|
| 763 |
+
output_attentions=None,
|
| 764 |
+
output_hidden_states=None,
|
| 765 |
+
return_dict=None,
|
| 766 |
+
cache_position=None,
|
| 767 |
+
**kwargs,
|
| 768 |
+
):
|
| 769 |
+
r"""
|
| 770 |
+
Args:
|
| 771 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
| 772 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
|
| 773 |
+
provide it.
|
| 774 |
+
|
| 775 |
+
Indices can be obtained using [`WhisperTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 776 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 777 |
+
|
| 778 |
+
[What are input IDs?](../glossary#input-ids)
|
| 779 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 780 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
| 781 |
+
|
| 782 |
+
- 1 for tokens that are **not masked**,
|
| 783 |
+
- 0 for tokens that are **masked**.
|
| 784 |
+
|
| 785 |
+
[What are attention masks?](../glossary#attention-mask)
|
| 786 |
+
encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, encoder_sequence_length, hidden_size)`, *optional*):
|
| 787 |
+
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention
|
| 788 |
+
of the decoder.
|
| 789 |
+
past_key_values (`EncoderDecoderCache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
|
| 790 |
+
It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).
|
| 791 |
+
|
| 792 |
+
If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those
|
| 793 |
+
that don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of
|
| 794 |
+
all `decoder_input_ids` of shape `(batch_size, sequence_length)`.
|
| 795 |
+
inputs_embeds (`torch.FloatTensor` of
|
| 796 |
+
shape `(batch_size, sequence_length, hidden_size)`, *optional*): Optionally, instead of passing
|
| 797 |
+
`input_ids` you can choose to directly pass an embedded representation. This is useful if you want more
|
| 798 |
+
control over how to convert `input_ids` indices into associated vectors than the model's internal
|
| 799 |
+
embedding lookup matrix.
|
| 800 |
+
output_attentions (`bool`, *optional*):
|
| 801 |
+
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
|
| 802 |
+
returned tensors for more detail.
|
| 803 |
+
output_hidden_states (`bool`, *optional*):
|
| 804 |
+
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
|
| 805 |
+
for more detail.
|
| 806 |
+
return_dict (`bool`, *optional*):
|
| 807 |
+
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
|
| 808 |
+
cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
|
| 809 |
+
Indices depicting the position of the input sequence tokens in the sequence. It is used to update the
|
| 810 |
+
cache in the correct position and to infer the complete sequence length.
|
| 811 |
+
"""
|
| 812 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 813 |
+
output_hidden_states = (
|
| 814 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 815 |
+
)
|
| 816 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
| 817 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 818 |
+
|
| 819 |
+
# retrieve input_ids and inputs_embeds
|
| 820 |
+
if input_ids is not None and inputs_embeds is not None:
|
| 821 |
+
raise ValueError("You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time")
|
| 822 |
+
elif input_ids is not None:
|
| 823 |
+
input_shape = input_ids.size()
|
| 824 |
+
input_ids = input_ids.view(-1, input_shape[-1])
|
| 825 |
+
elif inputs_embeds is not None:
|
| 826 |
+
input_shape = inputs_embeds.size()[:-1]
|
| 827 |
+
else:
|
| 828 |
+
raise ValueError("You have to specify either decoder_input_ids or decoder_inputs_embeds")
|
| 829 |
+
|
| 830 |
+
if inputs_embeds is None:
|
| 831 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 832 |
+
|
| 833 |
+
if use_cache and past_key_values is None:
|
| 834 |
+
past_key_values = (
|
| 835 |
+
EncoderDecoderCache(DynamicCache(config=self.config), DynamicCache(config=self.config))
|
| 836 |
+
if encoder_hidden_states is not None or self.config.is_encoder_decoder
|
| 837 |
+
else DynamicCache(config=self.config)
|
| 838 |
+
)
|
| 839 |
+
|
| 840 |
+
past_key_values_length = 0
|
| 841 |
+
if cache_position is not None:
|
| 842 |
+
past_key_values_length = cache_position[0]
|
| 843 |
+
elif past_key_values is not None:
|
| 844 |
+
past_key_values_length = past_key_values.get_seq_length()
|
| 845 |
+
|
| 846 |
+
if cache_position is None:
|
| 847 |
+
cache_position = torch.arange(
|
| 848 |
+
past_key_values_length, past_key_values_length + input_shape[1], device=inputs_embeds.device
|
| 849 |
+
)
|
| 850 |
+
|
| 851 |
+
if position_ids is None:
|
| 852 |
+
position_ids = cache_position.unsqueeze(0).repeat(input_shape[0], 1)
|
| 853 |
+
|
| 854 |
+
# embed positions
|
| 855 |
+
if input_ids is not None:
|
| 856 |
+
positions = self.embed_positions(
|
| 857 |
+
input_ids, past_key_values_length=past_key_values_length, position_ids=position_ids
|
| 858 |
+
)
|
| 859 |
+
else:
|
| 860 |
+
positions = self.embed_positions(
|
| 861 |
+
inputs_embeds, past_key_values_length=past_key_values_length, position_ids=position_ids
|
| 862 |
+
)
|
| 863 |
+
|
| 864 |
+
hidden_states = inputs_embeds + positions.to(inputs_embeds.device)
|
| 865 |
+
hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
|
| 866 |
+
|
| 867 |
+
causal_mask = create_causal_mask(
|
| 868 |
+
config=self.config,
|
| 869 |
+
inputs_embeds=inputs_embeds,
|
| 870 |
+
attention_mask=attention_mask,
|
| 871 |
+
cache_position=cache_position,
|
| 872 |
+
past_key_values=past_key_values,
|
| 873 |
+
position_ids=position_ids,
|
| 874 |
+
)
|
| 875 |
+
|
| 876 |
+
if self.gradient_checkpointing and self.training:
|
| 877 |
+
if use_cache:
|
| 878 |
+
logger.warning_once(
|
| 879 |
+
"`use_cache = True` is incompatible with gradient checkpointing. Setting `use_cache = False`..."
|
| 880 |
+
)
|
| 881 |
+
use_cache = False
|
| 882 |
+
# decoder layers
|
| 883 |
+
all_hidden_states = () if output_hidden_states else None
|
| 884 |
+
all_self_attns = () if output_attentions else None
|
| 885 |
+
all_cross_attentions = () if (output_attentions and encoder_hidden_states is not None) else None
|
| 886 |
+
|
| 887 |
+
for idx, decoder_layer in enumerate(self.layers):
|
| 888 |
+
# add LayerDrop (see https://huggingface.co/papers/1909.11556 for description)
|
| 889 |
+
if output_hidden_states:
|
| 890 |
+
all_hidden_states += (hidden_states,)
|
| 891 |
+
if self.training:
|
| 892 |
+
dropout_probability = torch.rand([])
|
| 893 |
+
if dropout_probability < self.layerdrop:
|
| 894 |
+
continue
|
| 895 |
+
|
| 896 |
+
layer_outputs = decoder_layer(
|
| 897 |
+
hidden_states,
|
| 898 |
+
causal_mask,
|
| 899 |
+
encoder_hidden_states,
|
| 900 |
+
encoder_attention_mask=None,
|
| 901 |
+
past_key_values=past_key_values if use_cache else None,
|
| 902 |
+
output_attentions=output_attentions,
|
| 903 |
+
use_cache=use_cache,
|
| 904 |
+
cache_position=cache_position,
|
| 905 |
+
)
|
| 906 |
+
hidden_states = layer_outputs[0]
|
| 907 |
+
|
| 908 |
+
if output_attentions:
|
| 909 |
+
all_self_attns += (layer_outputs[1],)
|
| 910 |
+
|
| 911 |
+
if encoder_hidden_states is not None:
|
| 912 |
+
all_cross_attentions += (layer_outputs[2],)
|
| 913 |
+
|
| 914 |
+
hidden_states = self.layer_norm(hidden_states)
|
| 915 |
+
# add hidden states from the last decoder layer
|
| 916 |
+
if output_hidden_states:
|
| 917 |
+
all_hidden_states += (hidden_states,)
|
| 918 |
+
|
| 919 |
+
next_cache = past_key_values if use_cache else None
|
| 920 |
+
if not return_dict:
|
| 921 |
+
return tuple(
|
| 922 |
+
v
|
| 923 |
+
for v in [hidden_states, next_cache, all_hidden_states, all_self_attns, all_cross_attentions]
|
| 924 |
+
if v is not None
|
| 925 |
+
)
|
| 926 |
+
return BaseModelOutputWithPastAndCrossAttentions(
|
| 927 |
+
last_hidden_state=hidden_states,
|
| 928 |
+
past_key_values=next_cache,
|
| 929 |
+
hidden_states=all_hidden_states,
|
| 930 |
+
attentions=all_self_attns,
|
| 931 |
+
cross_attentions=all_cross_attentions,
|
| 932 |
+
)
|
| 933 |
+
|
| 934 |
+
|
| 935 |
+
@auto_docstring
|
| 936 |
+
class WhisperModel(WhisperPreTrainedModel):
|
| 937 |
+
def __init__(self, config: WhisperConfig):
|
| 938 |
+
super().__init__(config)
|
| 939 |
+
|
| 940 |
+
self.encoder = WhisperEncoder(config)
|
| 941 |
+
self.decoder = WhisperDecoder(config)
|
| 942 |
+
# Initialize weights and apply final processing
|
| 943 |
+
self.post_init()
|
| 944 |
+
|
| 945 |
+
def get_input_embeddings(self):
|
| 946 |
+
return self.decoder.embed_tokens
|
| 947 |
+
|
| 948 |
+
def set_input_embeddings(self, value):
|
| 949 |
+
self.decoder.embed_tokens = value
|
| 950 |
+
|
| 951 |
+
def freeze_encoder(self):
|
| 952 |
+
"""
|
| 953 |
+
Calling this function will disable the gradient computation for the Whisper encoder so that its parameters will
|
| 954 |
+
not be updated during training.
|
| 955 |
+
"""
|
| 956 |
+
self.encoder._freeze_parameters()
|
| 957 |
+
|
| 958 |
+
def _mask_input_features(
|
| 959 |
+
self,
|
| 960 |
+
input_features: torch.FloatTensor,
|
| 961 |
+
attention_mask: torch.LongTensor | None = None,
|
| 962 |
+
):
|
| 963 |
+
"""
|
| 964 |
+
Masks extracted features along time axis and/or along feature axis according to
|
| 965 |
+
[SpecAugment](https://huggingface.co/papers/1904.08779).
|
| 966 |
+
"""
|
| 967 |
+
|
| 968 |
+
# `config.apply_spec_augment` can set masking to False
|
| 969 |
+
if not getattr(self.config, "apply_spec_augment", True):
|
| 970 |
+
return input_features
|
| 971 |
+
|
| 972 |
+
# generate indices & apply SpecAugment along time axis
|
| 973 |
+
batch_size, hidden_size, sequence_length = input_features.size()
|
| 974 |
+
|
| 975 |
+
if self.config.mask_time_prob > 0 and self.training:
|
| 976 |
+
# generate indices & apply SpecAugment along time axis
|
| 977 |
+
mask_time_indices = _compute_mask_indices(
|
| 978 |
+
(batch_size, sequence_length),
|
| 979 |
+
mask_prob=self.config.mask_time_prob,
|
| 980 |
+
mask_length=self.config.mask_time_length,
|
| 981 |
+
attention_mask=attention_mask,
|
| 982 |
+
min_masks=self.config.mask_time_min_masks,
|
| 983 |
+
)
|
| 984 |
+
mask_time_indices = torch.tensor(mask_time_indices, device=input_features.device, dtype=torch.bool)
|
| 985 |
+
mask_time_indices = mask_time_indices[:, None].expand(-1, hidden_size, -1)
|
| 986 |
+
input_features[mask_time_indices] = 0
|
| 987 |
+
|
| 988 |
+
if self.config.mask_feature_prob > 0 and self.training:
|
| 989 |
+
# generate indices & apply SpecAugment along feature axis
|
| 990 |
+
mask_feature_indices = _compute_mask_indices(
|
| 991 |
+
(batch_size, hidden_size),
|
| 992 |
+
mask_prob=self.config.mask_feature_prob,
|
| 993 |
+
mask_length=self.config.mask_feature_length,
|
| 994 |
+
min_masks=self.config.mask_feature_min_masks,
|
| 995 |
+
)
|
| 996 |
+
mask_feature_indices = torch.tensor(mask_feature_indices, device=input_features.device, dtype=torch.bool)
|
| 997 |
+
input_features[mask_feature_indices] = 0
|
| 998 |
+
|
| 999 |
+
return input_features
|
| 1000 |
+
|
| 1001 |
+
@auto_docstring
|
| 1002 |
+
def forward(
|
| 1003 |
+
self,
|
| 1004 |
+
input_features: torch.FloatTensor | None = None,
|
| 1005 |
+
attention_mask: torch.LongTensor | None = None,
|
| 1006 |
+
decoder_input_ids: torch.LongTensor | None = None,
|
| 1007 |
+
decoder_attention_mask: torch.LongTensor | None = None,
|
| 1008 |
+
encoder_outputs: tuple[tuple[torch.FloatTensor]] | None = None,
|
| 1009 |
+
past_key_values: Cache | None = None,
|
| 1010 |
+
decoder_inputs_embeds: tuple[torch.FloatTensor] | None = None,
|
| 1011 |
+
decoder_position_ids: tuple[torch.LongTensor] | None = None,
|
| 1012 |
+
use_cache: bool | None = None,
|
| 1013 |
+
output_attentions: bool | None = None,
|
| 1014 |
+
output_hidden_states: bool | None = None,
|
| 1015 |
+
return_dict: bool | None = None,
|
| 1016 |
+
cache_position: torch.LongTensor | None = None,
|
| 1017 |
+
**kwargs,
|
| 1018 |
+
) -> tuple[torch.Tensor] | Seq2SeqModelOutput:
|
| 1019 |
+
r"""
|
| 1020 |
+
decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
|
| 1021 |
+
Indices of decoder input sequence tokens in the vocabulary.
|
| 1022 |
+
|
| 1023 |
+
Indices can be obtained using [`WhisperTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 1024 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 1025 |
+
|
| 1026 |
+
[What are decoder input IDs?](../glossary#decoder-input-ids)
|
| 1027 |
+
|
| 1028 |
+
Whisper uses the `decoder_start_token_id` as the starting token for `decoder_input_ids` generation. If
|
| 1029 |
+
`past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
|
| 1030 |
+
`past_key_values`).
|
| 1031 |
+
decoder_attention_mask (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
|
| 1032 |
+
Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
|
| 1033 |
+
be used by default.
|
| 1034 |
+
|
| 1035 |
+
If you want to change padding behavior, you should read
|
| 1036 |
+
[`modeling_whisper._prepare_decoder_attention_mask`] and modify to your needs. See diagram 1 in [the BART
|
| 1037 |
+
paper](https://huggingface.co/papers/1910.13461) for more information on the default strategy.
|
| 1038 |
+
decoder_position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1039 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
| 1040 |
+
config.n_positions - 1]`.
|
| 1041 |
+
|
| 1042 |
+
[What are position IDs?](../glossary#position-ids)
|
| 1043 |
+
|
| 1044 |
+
Example:
|
| 1045 |
+
```python
|
| 1046 |
+
>>> import torch
|
| 1047 |
+
>>> from transformers import AutoFeatureExtractor, WhisperModel
|
| 1048 |
+
>>> from datasets import load_dataset
|
| 1049 |
+
|
| 1050 |
+
>>> model = WhisperModel.from_pretrained("openai/whisper-base")
|
| 1051 |
+
>>> feature_extractor = AutoFeatureExtractor.from_pretrained("openai/whisper-base")
|
| 1052 |
+
>>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
| 1053 |
+
>>> inputs = feature_extractor(ds[0]["audio"]["array"], return_tensors="pt")
|
| 1054 |
+
>>> input_features = inputs.input_features
|
| 1055 |
+
>>> decoder_input_ids = torch.tensor([[1, 1]]) * model.config.decoder_start_token_id
|
| 1056 |
+
>>> last_hidden_state = model(input_features, decoder_input_ids=decoder_input_ids).last_hidden_state
|
| 1057 |
+
>>> list(last_hidden_state.shape)
|
| 1058 |
+
[1, 2, 512]
|
| 1059 |
+
```"""
|
| 1060 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 1061 |
+
output_hidden_states = (
|
| 1062 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 1063 |
+
)
|
| 1064 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
| 1065 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1066 |
+
|
| 1067 |
+
if encoder_outputs is None:
|
| 1068 |
+
input_features = self._mask_input_features(input_features, attention_mask=attention_mask)
|
| 1069 |
+
|
| 1070 |
+
encoder_outputs = self.encoder(
|
| 1071 |
+
input_features,
|
| 1072 |
+
output_attentions=output_attentions,
|
| 1073 |
+
output_hidden_states=output_hidden_states,
|
| 1074 |
+
return_dict=return_dict,
|
| 1075 |
+
)
|
| 1076 |
+
# If the user passed a tuple for encoder_outputs, we wrap it in a BaseModelOutput when return_dict=True
|
| 1077 |
+
elif return_dict and not isinstance(encoder_outputs, BaseModelOutput):
|
| 1078 |
+
encoder_outputs = BaseModelOutput(
|
| 1079 |
+
last_hidden_state=encoder_outputs[0],
|
| 1080 |
+
hidden_states=encoder_outputs[1] if len(encoder_outputs) > 1 else None,
|
| 1081 |
+
attentions=encoder_outputs[2] if len(encoder_outputs) > 2 else None,
|
| 1082 |
+
)
|
| 1083 |
+
|
| 1084 |
+
# decoder outputs consists of (dec_features, past_key_values, dec_hidden, dec_attn)
|
| 1085 |
+
decoder_outputs = self.decoder(
|
| 1086 |
+
input_ids=decoder_input_ids,
|
| 1087 |
+
attention_mask=decoder_attention_mask,
|
| 1088 |
+
encoder_hidden_states=encoder_outputs[0],
|
| 1089 |
+
past_key_values=past_key_values,
|
| 1090 |
+
inputs_embeds=decoder_inputs_embeds,
|
| 1091 |
+
position_ids=decoder_position_ids,
|
| 1092 |
+
use_cache=use_cache,
|
| 1093 |
+
output_attentions=output_attentions,
|
| 1094 |
+
output_hidden_states=output_hidden_states,
|
| 1095 |
+
return_dict=return_dict,
|
| 1096 |
+
cache_position=cache_position,
|
| 1097 |
+
)
|
| 1098 |
+
|
| 1099 |
+
if not return_dict:
|
| 1100 |
+
return decoder_outputs + encoder_outputs
|
| 1101 |
+
|
| 1102 |
+
return Seq2SeqModelOutput(
|
| 1103 |
+
last_hidden_state=decoder_outputs.last_hidden_state,
|
| 1104 |
+
past_key_values=decoder_outputs.past_key_values,
|
| 1105 |
+
decoder_hidden_states=decoder_outputs.hidden_states,
|
| 1106 |
+
decoder_attentions=decoder_outputs.attentions,
|
| 1107 |
+
cross_attentions=decoder_outputs.cross_attentions,
|
| 1108 |
+
encoder_last_hidden_state=encoder_outputs.last_hidden_state,
|
| 1109 |
+
encoder_hidden_states=encoder_outputs.hidden_states,
|
| 1110 |
+
encoder_attentions=encoder_outputs.attentions,
|
| 1111 |
+
)
|
| 1112 |
+
|
| 1113 |
+
|
| 1114 |
+
@auto_docstring(
|
| 1115 |
+
custom_intro="""
|
| 1116 |
+
The Whisper Model with a language modeling head. Can be used for automatic speech recognition.
|
| 1117 |
+
"""
|
| 1118 |
+
)
|
| 1119 |
+
class WhisperForConditionalGeneration(WhisperGenerationMixin, WhisperPreTrainedModel):
|
| 1120 |
+
base_model_prefix = "model"
|
| 1121 |
+
_tied_weights_keys = {"proj_out.weight": "model.decoder.embed_tokens.weight"}
|
| 1122 |
+
|
| 1123 |
+
def __init__(self, config: WhisperConfig):
|
| 1124 |
+
super().__init__(config)
|
| 1125 |
+
self.model = WhisperModel(config)
|
| 1126 |
+
self.proj_out = nn.Linear(config.d_model, config.vocab_size, bias=False)
|
| 1127 |
+
self.max_target_positions = config.max_target_positions
|
| 1128 |
+
|
| 1129 |
+
# Initialize weights and apply final processing
|
| 1130 |
+
self.post_init()
|
| 1131 |
+
|
| 1132 |
+
def get_output_embeddings(self):
|
| 1133 |
+
return self.proj_out
|
| 1134 |
+
|
| 1135 |
+
def set_output_embeddings(self, new_embeddings):
|
| 1136 |
+
self.proj_out = new_embeddings
|
| 1137 |
+
|
| 1138 |
+
def get_input_embeddings(self) -> nn.Module:
|
| 1139 |
+
return self.model.get_input_embeddings()
|
| 1140 |
+
|
| 1141 |
+
def freeze_encoder(self):
|
| 1142 |
+
"""
|
| 1143 |
+
Calling this function will disable the gradient computation for the Whisper encoder so that its parameters will
|
| 1144 |
+
not be updated during training.
|
| 1145 |
+
"""
|
| 1146 |
+
self.model.encoder._freeze_parameters()
|
| 1147 |
+
|
| 1148 |
+
@auto_docstring
|
| 1149 |
+
def forward(
|
| 1150 |
+
self,
|
| 1151 |
+
input_features: torch.FloatTensor | None = None,
|
| 1152 |
+
attention_mask: torch.LongTensor | None = None,
|
| 1153 |
+
decoder_input_ids: torch.LongTensor | None = None,
|
| 1154 |
+
decoder_attention_mask: torch.LongTensor | None = None,
|
| 1155 |
+
encoder_outputs: tuple[tuple[torch.FloatTensor]] | None = None,
|
| 1156 |
+
past_key_values: Cache | None = None,
|
| 1157 |
+
decoder_inputs_embeds: tuple[torch.FloatTensor] | None = None,
|
| 1158 |
+
decoder_position_ids: tuple[torch.LongTensor] | None = None,
|
| 1159 |
+
labels: torch.LongTensor | None = None,
|
| 1160 |
+
use_cache: bool | None = None,
|
| 1161 |
+
output_attentions: bool | None = None,
|
| 1162 |
+
output_hidden_states: bool | None = None,
|
| 1163 |
+
return_dict: bool | None = None,
|
| 1164 |
+
cache_position: torch.LongTensor | None = None,
|
| 1165 |
+
**kwargs,
|
| 1166 |
+
) -> tuple[torch.Tensor] | Seq2SeqLMOutput:
|
| 1167 |
+
r"""
|
| 1168 |
+
decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
|
| 1169 |
+
Indices of decoder input sequence tokens in the vocabulary.
|
| 1170 |
+
|
| 1171 |
+
Indices can be obtained using [`WhisperTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 1172 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 1173 |
+
|
| 1174 |
+
[What are decoder input IDs?](../glossary#decoder-input-ids)
|
| 1175 |
+
|
| 1176 |
+
Whisper uses the `decoder_start_token_id` as the starting token for `decoder_input_ids` generation. If
|
| 1177 |
+
`past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
|
| 1178 |
+
`past_key_values`).
|
| 1179 |
+
decoder_attention_mask (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
|
| 1180 |
+
Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
|
| 1181 |
+
be used by default.
|
| 1182 |
+
|
| 1183 |
+
If you want to change padding behavior, you should read
|
| 1184 |
+
[`modeling_whisper._prepare_decoder_attention_mask`] and modify to your needs. See diagram 1 in [the BART
|
| 1185 |
+
paper](https://huggingface.co/papers/1910.13461) for more information on the default strategy.
|
| 1186 |
+
decoder_position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1187 |
+
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
|
| 1188 |
+
config.n_positions - 1]`.
|
| 1189 |
+
|
| 1190 |
+
[What are position IDs?](../glossary#position-ids)
|
| 1191 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1192 |
+
Labels for computing the language modeling loss. Indices should either be in `[0, ..., config.vocab_size]`
|
| 1193 |
+
or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored (masked), the loss is
|
| 1194 |
+
only computed for the tokens with labels in `[0, ..., config.vocab_size]`. `sequence_length` should be smaller than or equal to `config.max_target_positions`.
|
| 1195 |
+
|
| 1196 |
+
Example:
|
| 1197 |
+
|
| 1198 |
+
```python
|
| 1199 |
+
>>> import torch
|
| 1200 |
+
>>> from transformers import AutoProcessor, WhisperForConditionalGeneration
|
| 1201 |
+
>>> from datasets import load_dataset
|
| 1202 |
+
|
| 1203 |
+
>>> processor = AutoProcessor.from_pretrained("openai/whisper-tiny.en")
|
| 1204 |
+
>>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-tiny.en")
|
| 1205 |
+
|
| 1206 |
+
>>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
| 1207 |
+
|
| 1208 |
+
>>> inputs = processor(ds[0]["audio"]["array"], return_tensors="pt")
|
| 1209 |
+
>>> input_features = inputs.input_features
|
| 1210 |
+
|
| 1211 |
+
>>> generated_ids = model.generate(inputs=input_features)
|
| 1212 |
+
|
| 1213 |
+
>>> transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 1214 |
+
>>> transcription
|
| 1215 |
+
' Mr. Quilter is the apostle of the middle classes, and we are glad to welcome his gospel.'
|
| 1216 |
+
```"""
|
| 1217 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1218 |
+
|
| 1219 |
+
if labels is not None:
|
| 1220 |
+
if labels.shape[1] > self.max_target_positions:
|
| 1221 |
+
raise ValueError(
|
| 1222 |
+
f"Labels' sequence length {labels.shape[1]} cannot exceed the maximum allowed length of {self.max_target_positions} tokens."
|
| 1223 |
+
)
|
| 1224 |
+
if decoder_input_ids is None and decoder_inputs_embeds is None:
|
| 1225 |
+
decoder_input_ids = shift_tokens_right(
|
| 1226 |
+
labels, self.config.pad_token_id, self.config.decoder_start_token_id
|
| 1227 |
+
)
|
| 1228 |
+
|
| 1229 |
+
outputs = self.model(
|
| 1230 |
+
input_features,
|
| 1231 |
+
attention_mask=attention_mask,
|
| 1232 |
+
decoder_input_ids=decoder_input_ids,
|
| 1233 |
+
encoder_outputs=encoder_outputs,
|
| 1234 |
+
decoder_attention_mask=decoder_attention_mask,
|
| 1235 |
+
past_key_values=past_key_values,
|
| 1236 |
+
decoder_inputs_embeds=decoder_inputs_embeds,
|
| 1237 |
+
decoder_position_ids=decoder_position_ids,
|
| 1238 |
+
use_cache=use_cache,
|
| 1239 |
+
output_attentions=output_attentions,
|
| 1240 |
+
output_hidden_states=output_hidden_states,
|
| 1241 |
+
return_dict=return_dict,
|
| 1242 |
+
cache_position=cache_position,
|
| 1243 |
+
)
|
| 1244 |
+
lm_logits = self.proj_out(outputs[0])
|
| 1245 |
+
|
| 1246 |
+
loss = None
|
| 1247 |
+
if labels is not None:
|
| 1248 |
+
loss_fct = CrossEntropyLoss()
|
| 1249 |
+
# move labels to correct device to enable PP
|
| 1250 |
+
labels = labels.to(lm_logits.device)
|
| 1251 |
+
loss = loss_fct(lm_logits.view(-1, self.config.vocab_size), labels.reshape(-1))
|
| 1252 |
+
|
| 1253 |
+
if not return_dict:
|
| 1254 |
+
output = (lm_logits,) + outputs[1:]
|
| 1255 |
+
return ((loss,) + output) if loss is not None else output
|
| 1256 |
+
|
| 1257 |
+
return Seq2SeqLMOutput(
|
| 1258 |
+
loss=loss,
|
| 1259 |
+
logits=lm_logits,
|
| 1260 |
+
past_key_values=outputs.past_key_values,
|
| 1261 |
+
decoder_hidden_states=outputs.decoder_hidden_states,
|
| 1262 |
+
decoder_attentions=outputs.decoder_attentions,
|
| 1263 |
+
cross_attentions=outputs.cross_attentions,
|
| 1264 |
+
encoder_last_hidden_state=outputs.encoder_last_hidden_state,
|
| 1265 |
+
encoder_hidden_states=outputs.encoder_hidden_states,
|
| 1266 |
+
encoder_attentions=outputs.encoder_attentions,
|
| 1267 |
+
)
|
| 1268 |
+
|
| 1269 |
+
|
| 1270 |
+
class WhisperDecoderWrapper(WhisperPreTrainedModel):
|
| 1271 |
+
"""
|
| 1272 |
+
This wrapper class is a helper class to correctly load pretrained checkpoints when the causal language model is
|
| 1273 |
+
used in combination with the [`EncoderDecoderModel`] framework.
|
| 1274 |
+
"""
|
| 1275 |
+
|
| 1276 |
+
def __init__(self, config):
|
| 1277 |
+
super().__init__(config)
|
| 1278 |
+
config.is_encoder_decoder = False
|
| 1279 |
+
self.decoder = WhisperDecoder(config)
|
| 1280 |
+
self.post_init()
|
| 1281 |
+
|
| 1282 |
+
def get_input_embeddings(self):
|
| 1283 |
+
return self.decoder.embed_tokens
|
| 1284 |
+
|
| 1285 |
+
def set_input_embeddings(self, value):
|
| 1286 |
+
self.decoder.embed_tokens = value
|
| 1287 |
+
|
| 1288 |
+
def forward(self, *args, **kwargs):
|
| 1289 |
+
return self.decoder(*args, **kwargs)
|
| 1290 |
+
|
| 1291 |
+
|
| 1292 |
+
@auto_docstring(
|
| 1293 |
+
custom_intro="""
|
| 1294 |
+
Whisper decoder with a language modeling head on top (linear layer with weights tied to the input embeddings).
|
| 1295 |
+
"""
|
| 1296 |
+
)
|
| 1297 |
+
class WhisperForCausalLM(WhisperPreTrainedModel, GenerationMixin):
|
| 1298 |
+
_tied_weights_keys = {"proj_out.weight": "model.decoder.embed_tokens.weight"}
|
| 1299 |
+
main_input_name = "input_ids"
|
| 1300 |
+
|
| 1301 |
+
def __init__(self, config):
|
| 1302 |
+
super().__init__(config)
|
| 1303 |
+
config.is_encoder_decoder = False
|
| 1304 |
+
self.model = WhisperDecoderWrapper(config)
|
| 1305 |
+
|
| 1306 |
+
self.proj_out = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 1307 |
+
|
| 1308 |
+
# Initialize weights and apply final processing
|
| 1309 |
+
self.post_init()
|
| 1310 |
+
|
| 1311 |
+
def get_output_embeddings(self):
|
| 1312 |
+
return self.proj_out
|
| 1313 |
+
|
| 1314 |
+
def set_output_embeddings(self, new_embeddings):
|
| 1315 |
+
self.proj_out = new_embeddings
|
| 1316 |
+
|
| 1317 |
+
def get_input_embeddings(self) -> nn.Module:
|
| 1318 |
+
return self.model.get_input_embeddings()
|
| 1319 |
+
|
| 1320 |
+
def set_input_embeddings(self, value):
|
| 1321 |
+
self.model.set_input_embeddings(value)
|
| 1322 |
+
|
| 1323 |
+
@auto_docstring
|
| 1324 |
+
def forward(
|
| 1325 |
+
self,
|
| 1326 |
+
input_ids: torch.LongTensor | None = None,
|
| 1327 |
+
attention_mask: torch.Tensor | None = None,
|
| 1328 |
+
encoder_outputs: tuple[torch.FloatTensor] | None = None,
|
| 1329 |
+
past_key_values: Cache | None = None,
|
| 1330 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 1331 |
+
labels: torch.LongTensor | None = None,
|
| 1332 |
+
use_cache: bool | None = None,
|
| 1333 |
+
output_attentions: bool | None = None,
|
| 1334 |
+
output_hidden_states: bool | None = None,
|
| 1335 |
+
return_dict: bool | None = None,
|
| 1336 |
+
cache_position: torch.LongTensor | None = None,
|
| 1337 |
+
**kwargs,
|
| 1338 |
+
) -> tuple | CausalLMOutputWithCrossAttentions:
|
| 1339 |
+
r"""
|
| 1340 |
+
encoder_outputs (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
|
| 1341 |
+
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention
|
| 1342 |
+
if the model is configured as a decoder.
|
| 1343 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1344 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 1345 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 1346 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 1347 |
+
|
| 1348 |
+
Example:
|
| 1349 |
+
|
| 1350 |
+
```python
|
| 1351 |
+
>>> from transformers import WhisperForCausalLM, WhisperForConditionalGeneration, WhisperProcessor
|
| 1352 |
+
>>> import torch
|
| 1353 |
+
>>> from datasets import load_dataset
|
| 1354 |
+
|
| 1355 |
+
>>> processor = WhisperProcessor.from_pretrained("openai/whisper-large-v2")
|
| 1356 |
+
>>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large-v2")
|
| 1357 |
+
|
| 1358 |
+
>>> assistant_model = WhisperForCausalLM.from_pretrained("distil-whisper/distil-large-v2")
|
| 1359 |
+
|
| 1360 |
+
>>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
| 1361 |
+
>>> sample = ds[0]["audio"]
|
| 1362 |
+
>>> input_features = processor(
|
| 1363 |
+
... sample["array"], sampling_rate=sample["sampling_rate"], return_tensors="pt"
|
| 1364 |
+
... ).input_features
|
| 1365 |
+
|
| 1366 |
+
>>> predicted_ids = model.generate(input_features, assistant_model=assistant_model)
|
| 1367 |
+
|
| 1368 |
+
>>> # decode token ids to text
|
| 1369 |
+
>>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
|
| 1370 |
+
>>> transcription
|
| 1371 |
+
' Mr. Quilter is the apostle of the middle classes and we are glad to welcome his gospel.'
|
| 1372 |
+
```"""
|
| 1373 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 1374 |
+
output_hidden_states = (
|
| 1375 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 1376 |
+
)
|
| 1377 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1378 |
+
|
| 1379 |
+
# If the user passed a tuple or `BaseModelOutput` for encoder_outputs, we extract only the hidden states
|
| 1380 |
+
if isinstance(encoder_outputs, (BaseModelOutput, tuple, list)):
|
| 1381 |
+
encoder_outputs = encoder_outputs[0]
|
| 1382 |
+
|
| 1383 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
| 1384 |
+
outputs = self.model.decoder(
|
| 1385 |
+
input_ids=input_ids,
|
| 1386 |
+
attention_mask=attention_mask,
|
| 1387 |
+
encoder_hidden_states=encoder_outputs,
|
| 1388 |
+
past_key_values=past_key_values,
|
| 1389 |
+
inputs_embeds=inputs_embeds,
|
| 1390 |
+
use_cache=use_cache,
|
| 1391 |
+
output_attentions=output_attentions,
|
| 1392 |
+
output_hidden_states=output_hidden_states,
|
| 1393 |
+
return_dict=return_dict,
|
| 1394 |
+
cache_position=cache_position,
|
| 1395 |
+
)
|
| 1396 |
+
|
| 1397 |
+
logits = self.proj_out(outputs[0])
|
| 1398 |
+
|
| 1399 |
+
loss = None
|
| 1400 |
+
if labels is not None:
|
| 1401 |
+
labels = labels.to(logits.device)
|
| 1402 |
+
loss_fct = CrossEntropyLoss()
|
| 1403 |
+
loss = loss_fct(logits.view(-1, self.config.vocab_size), labels.view(-1))
|
| 1404 |
+
|
| 1405 |
+
if not return_dict:
|
| 1406 |
+
output = (logits,) + outputs[1:]
|
| 1407 |
+
return (loss,) + output if loss is not None else output
|
| 1408 |
+
|
| 1409 |
+
return CausalLMOutputWithCrossAttentions(
|
| 1410 |
+
loss=loss,
|
| 1411 |
+
logits=logits,
|
| 1412 |
+
past_key_values=outputs.past_key_values,
|
| 1413 |
+
hidden_states=outputs.hidden_states,
|
| 1414 |
+
attentions=outputs.attentions,
|
| 1415 |
+
cross_attentions=outputs.cross_attentions,
|
| 1416 |
+
)
|
| 1417 |
+
|
| 1418 |
+
|
| 1419 |
+
@auto_docstring(
|
| 1420 |
+
custom_intro="""
|
| 1421 |
+
Whisper Encoder Model with a sequence classification head on top (a linear layer over the pooled output) for tasks
|
| 1422 |
+
like SUPERB Keyword Spotting.
|
| 1423 |
+
"""
|
| 1424 |
+
)
|
| 1425 |
+
class WhisperForAudioClassification(WhisperPreTrainedModel):
|
| 1426 |
+
def __init__(self, config):
|
| 1427 |
+
super().__init__(config)
|
| 1428 |
+
|
| 1429 |
+
self.encoder = WhisperEncoder(config)
|
| 1430 |
+
num_layers = config.num_hidden_layers + 1 # transformer layers + input embeddings
|
| 1431 |
+
if config.use_weighted_layer_sum:
|
| 1432 |
+
self.layer_weights = nn.Parameter(torch.ones(num_layers) / num_layers)
|
| 1433 |
+
self.projector = nn.Linear(config.hidden_size, config.classifier_proj_size)
|
| 1434 |
+
self.classifier = nn.Linear(config.classifier_proj_size, config.num_labels)
|
| 1435 |
+
|
| 1436 |
+
# Initialize weights and apply final processing
|
| 1437 |
+
self.post_init()
|
| 1438 |
+
|
| 1439 |
+
def freeze_encoder(self):
|
| 1440 |
+
"""
|
| 1441 |
+
Calling this function will disable the gradient computation for the Whisper encoder so that its parameters will
|
| 1442 |
+
not be updated during training. Only the projection layers and classification head will be updated.
|
| 1443 |
+
"""
|
| 1444 |
+
self.encoder._freeze_parameters()
|
| 1445 |
+
|
| 1446 |
+
def get_input_embeddings(self) -> nn.Module:
|
| 1447 |
+
return self.encoder.get_input_embeddings()
|
| 1448 |
+
|
| 1449 |
+
def set_input_embeddings(self, value: nn.Module):
|
| 1450 |
+
self.encoder.set_input_embeddings(value)
|
| 1451 |
+
|
| 1452 |
+
@auto_docstring
|
| 1453 |
+
def forward(
|
| 1454 |
+
self,
|
| 1455 |
+
input_features: torch.LongTensor | None = None,
|
| 1456 |
+
encoder_outputs: tuple[tuple[torch.FloatTensor]] | None = None,
|
| 1457 |
+
labels: torch.LongTensor | None = None,
|
| 1458 |
+
output_attentions: bool | None = None,
|
| 1459 |
+
output_hidden_states: bool | None = None,
|
| 1460 |
+
return_dict: bool | None = None,
|
| 1461 |
+
**kwargs,
|
| 1462 |
+
) -> tuple[torch.Tensor] | SequenceClassifierOutput:
|
| 1463 |
+
r"""
|
| 1464 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 1465 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 1466 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 1467 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 1468 |
+
|
| 1469 |
+
Example:
|
| 1470 |
+
|
| 1471 |
+
```python
|
| 1472 |
+
>>> import torch
|
| 1473 |
+
>>> from transformers import AutoFeatureExtractor, WhisperForAudioClassification
|
| 1474 |
+
>>> from datasets import load_dataset
|
| 1475 |
+
|
| 1476 |
+
>>> feature_extractor = AutoFeatureExtractor.from_pretrained("sanchit-gandhi/whisper-medium-fleurs-lang-id")
|
| 1477 |
+
>>> model = WhisperForAudioClassification.from_pretrained("sanchit-gandhi/whisper-medium-fleurs-lang-id")
|
| 1478 |
+
|
| 1479 |
+
>>> ds = load_dataset("google/fleurs", "all", split="validation", streaming=True)
|
| 1480 |
+
>>> sample = next(iter(ds))
|
| 1481 |
+
|
| 1482 |
+
>>> inputs = feature_extractor(
|
| 1483 |
+
... sample["audio"]["array"], sampling_rate=sample["audio"]["sampling_rate"], return_tensors="pt"
|
| 1484 |
+
... )
|
| 1485 |
+
>>> input_features = inputs.input_features
|
| 1486 |
+
|
| 1487 |
+
>>> with torch.no_grad():
|
| 1488 |
+
... logits = model(input_features).logits
|
| 1489 |
+
|
| 1490 |
+
>>> predicted_class_ids = torch.argmax(logits).item()
|
| 1491 |
+
>>> predicted_label = model.config.id2label[predicted_class_ids]
|
| 1492 |
+
>>> predicted_label
|
| 1493 |
+
'Afrikaans'
|
| 1494 |
+
```"""
|
| 1495 |
+
|
| 1496 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 1497 |
+
output_hidden_states = (
|
| 1498 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 1499 |
+
)
|
| 1500 |
+
if self.config.use_weighted_layer_sum:
|
| 1501 |
+
output_hidden_states = True
|
| 1502 |
+
elif output_hidden_states is None:
|
| 1503 |
+
output_hidden_states = self.config.output_hidden_states
|
| 1504 |
+
|
| 1505 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1506 |
+
|
| 1507 |
+
if encoder_outputs is None:
|
| 1508 |
+
encoder_outputs = self.encoder(
|
| 1509 |
+
input_features,
|
| 1510 |
+
output_attentions=output_attentions,
|
| 1511 |
+
output_hidden_states=output_hidden_states,
|
| 1512 |
+
return_dict=return_dict,
|
| 1513 |
+
)
|
| 1514 |
+
|
| 1515 |
+
if self.config.use_weighted_layer_sum:
|
| 1516 |
+
hidden_states = encoder_outputs[_HIDDEN_STATES_START_POSITION]
|
| 1517 |
+
hidden_states = torch.stack(hidden_states, dim=1)
|
| 1518 |
+
norm_weights = nn.functional.softmax(self.layer_weights, dim=-1)
|
| 1519 |
+
hidden_states = (hidden_states * norm_weights.view(-1, 1, 1)).sum(dim=1)
|
| 1520 |
+
else:
|
| 1521 |
+
hidden_states = encoder_outputs[0]
|
| 1522 |
+
|
| 1523 |
+
hidden_states = self.projector(hidden_states)
|
| 1524 |
+
pooled_output = hidden_states.mean(dim=1)
|
| 1525 |
+
|
| 1526 |
+
logits = self.classifier(pooled_output)
|
| 1527 |
+
|
| 1528 |
+
loss = None
|
| 1529 |
+
|
| 1530 |
+
if labels is not None:
|
| 1531 |
+
loss_fct = CrossEntropyLoss()
|
| 1532 |
+
# move labels to correct device to enable PP
|
| 1533 |
+
labels = labels.to(logits.device)
|
| 1534 |
+
loss = loss_fct(logits.view(-1, self.config.num_labels), labels.view(-1))
|
| 1535 |
+
|
| 1536 |
+
if not return_dict:
|
| 1537 |
+
output = (logits,) + encoder_outputs[1:]
|
| 1538 |
+
return ((loss,) + output) if loss is not None else output
|
| 1539 |
+
|
| 1540 |
+
return SequenceClassifierOutput(
|
| 1541 |
+
loss=loss,
|
| 1542 |
+
logits=logits,
|
| 1543 |
+
hidden_states=encoder_outputs.hidden_states,
|
| 1544 |
+
attentions=encoder_outputs.attentions,
|
| 1545 |
+
)
|
| 1546 |
+
|
| 1547 |
+
|
| 1548 |
+
__all__ = [
|
| 1549 |
+
"WhisperForCausalLM",
|
| 1550 |
+
"WhisperForConditionalGeneration",
|
| 1551 |
+
"WhisperModel",
|
| 1552 |
+
"WhisperPreTrainedModel",
|
| 1553 |
+
"WhisperForAudioClassification",
|
| 1554 |
+
]
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bd5ed7eaf0682ee781175a249c9f86b9366d0d31980f72409ec6b7d939486ef4
|
| 3 |
+
size 7659403688
|
modeling_wemm.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
official_qwen35_fp8_config.json
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"repo_id": "Qwen/Qwen3.5-35B-A3B-FP8",
|
| 3 |
+
"revision": "9d1823d2dee688a6b25e77009dc727688c44936e",
|
| 4 |
+
"config": {
|
| 5 |
+
"architectures": [
|
| 6 |
+
"Qwen3_5MoeForConditionalGeneration"
|
| 7 |
+
],
|
| 8 |
+
"image_token_id": 248056,
|
| 9 |
+
"model_type": "qwen3_5_moe",
|
| 10 |
+
"text_config": {
|
| 11 |
+
"attention_bias": false,
|
| 12 |
+
"attention_dropout": 0.0,
|
| 13 |
+
"attn_output_gate": true,
|
| 14 |
+
"dtype": "bfloat16",
|
| 15 |
+
"eos_token_id": 248044,
|
| 16 |
+
"full_attention_interval": 4,
|
| 17 |
+
"head_dim": 256,
|
| 18 |
+
"hidden_act": "silu",
|
| 19 |
+
"hidden_size": 2048,
|
| 20 |
+
"initializer_range": 0.02,
|
| 21 |
+
"layer_types": [
|
| 22 |
+
"linear_attention",
|
| 23 |
+
"linear_attention",
|
| 24 |
+
"linear_attention",
|
| 25 |
+
"full_attention",
|
| 26 |
+
"linear_attention",
|
| 27 |
+
"linear_attention",
|
| 28 |
+
"linear_attention",
|
| 29 |
+
"full_attention",
|
| 30 |
+
"linear_attention",
|
| 31 |
+
"linear_attention",
|
| 32 |
+
"linear_attention",
|
| 33 |
+
"full_attention",
|
| 34 |
+
"linear_attention",
|
| 35 |
+
"linear_attention",
|
| 36 |
+
"linear_attention",
|
| 37 |
+
"full_attention",
|
| 38 |
+
"linear_attention",
|
| 39 |
+
"linear_attention",
|
| 40 |
+
"linear_attention",
|
| 41 |
+
"full_attention",
|
| 42 |
+
"linear_attention",
|
| 43 |
+
"linear_attention",
|
| 44 |
+
"linear_attention",
|
| 45 |
+
"full_attention",
|
| 46 |
+
"linear_attention",
|
| 47 |
+
"linear_attention",
|
| 48 |
+
"linear_attention",
|
| 49 |
+
"full_attention",
|
| 50 |
+
"linear_attention",
|
| 51 |
+
"linear_attention",
|
| 52 |
+
"linear_attention",
|
| 53 |
+
"full_attention",
|
| 54 |
+
"linear_attention",
|
| 55 |
+
"linear_attention",
|
| 56 |
+
"linear_attention",
|
| 57 |
+
"full_attention",
|
| 58 |
+
"linear_attention",
|
| 59 |
+
"linear_attention",
|
| 60 |
+
"linear_attention",
|
| 61 |
+
"full_attention"
|
| 62 |
+
],
|
| 63 |
+
"linear_conv_kernel_dim": 4,
|
| 64 |
+
"linear_key_head_dim": 128,
|
| 65 |
+
"linear_num_key_heads": 16,
|
| 66 |
+
"linear_num_value_heads": 32,
|
| 67 |
+
"linear_value_head_dim": 128,
|
| 68 |
+
"max_position_embeddings": 262144,
|
| 69 |
+
"mlp_only_layers": [],
|
| 70 |
+
"model_type": "qwen3_5_moe_text",
|
| 71 |
+
"moe_intermediate_size": 512,
|
| 72 |
+
"mtp_num_hidden_layers": 1,
|
| 73 |
+
"mtp_use_dedicated_embeddings": false,
|
| 74 |
+
"num_attention_heads": 16,
|
| 75 |
+
"num_experts": 256,
|
| 76 |
+
"num_experts_per_tok": 8,
|
| 77 |
+
"num_hidden_layers": 40,
|
| 78 |
+
"num_key_value_heads": 2,
|
| 79 |
+
"rms_norm_eps": 1e-06,
|
| 80 |
+
"router_aux_loss_coef": 0.001,
|
| 81 |
+
"shared_expert_intermediate_size": 512,
|
| 82 |
+
"use_cache": true,
|
| 83 |
+
"vocab_size": 248320,
|
| 84 |
+
"mamba_ssm_dtype": "float32",
|
| 85 |
+
"rope_parameters": {
|
| 86 |
+
"mrope_interleaved": true,
|
| 87 |
+
"mrope_section": [
|
| 88 |
+
11,
|
| 89 |
+
11,
|
| 90 |
+
10
|
| 91 |
+
],
|
| 92 |
+
"rope_type": "default",
|
| 93 |
+
"rope_theta": 10000000,
|
| 94 |
+
"partial_rotary_factor": 0.25
|
| 95 |
+
}
|
| 96 |
+
},
|
| 97 |
+
"tie_word_embeddings": false,
|
| 98 |
+
"transformers_version": "4.57.0.dev0",
|
| 99 |
+
"video_token_id": 248057,
|
| 100 |
+
"vision_config": {
|
| 101 |
+
"deepstack_visual_indexes": [],
|
| 102 |
+
"depth": 27,
|
| 103 |
+
"hidden_act": "gelu_pytorch_tanh",
|
| 104 |
+
"hidden_size": 1152,
|
| 105 |
+
"in_channels": 3,
|
| 106 |
+
"initializer_range": 0.02,
|
| 107 |
+
"intermediate_size": 4304,
|
| 108 |
+
"model_type": "qwen3_5_moe",
|
| 109 |
+
"num_heads": 16,
|
| 110 |
+
"num_position_embeddings": 2304,
|
| 111 |
+
"out_hidden_size": 2048,
|
| 112 |
+
"patch_size": 16,
|
| 113 |
+
"spatial_merge_size": 2,
|
| 114 |
+
"temporal_patch_size": 2
|
| 115 |
+
},
|
| 116 |
+
"vision_end_token_id": 248054,
|
| 117 |
+
"vision_start_token_id": 248053,
|
| 118 |
+
"quantization_config": {
|
| 119 |
+
"quant_method": "fp8",
|
| 120 |
+
"activation_scheme": "dynamic",
|
| 121 |
+
"weight_per_tensor": false,
|
| 122 |
+
"act_per_tensor": false,
|
| 123 |
+
"weight_block_size": [
|
| 124 |
+
128,
|
| 125 |
+
128
|
| 126 |
+
],
|
| 127 |
+
"modules_to_not_convert": [
|
| 128 |
+
"lm_head",
|
| 129 |
+
"model.language_model.embed_tokens",
|
| 130 |
+
"model.language_model.layers.0.linear_attn.conv1d",
|
| 131 |
+
"model.language_model.layers.0.linear_attn.in_proj_a",
|
| 132 |
+
"model.language_model.layers.0.linear_attn.in_proj_b",
|
| 133 |
+
"model.language_model.layers.0.mlp.gate",
|
| 134 |
+
"model.language_model.layers.0.mlp.shared_expert_gate",
|
| 135 |
+
"model.language_model.layers.1.linear_attn.conv1d",
|
| 136 |
+
"model.language_model.layers.1.linear_attn.in_proj_a",
|
| 137 |
+
"model.language_model.layers.1.linear_attn.in_proj_b",
|
| 138 |
+
"model.language_model.layers.1.mlp.gate",
|
| 139 |
+
"model.language_model.layers.1.mlp.shared_expert_gate",
|
| 140 |
+
"model.language_model.layers.10.linear_attn.conv1d",
|
| 141 |
+
"model.language_model.layers.10.linear_attn.in_proj_a",
|
| 142 |
+
"model.language_model.layers.10.linear_attn.in_proj_b",
|
| 143 |
+
"model.language_model.layers.10.mlp.gate",
|
| 144 |
+
"model.language_model.layers.10.mlp.shared_expert_gate",
|
| 145 |
+
"model.language_model.layers.11.mlp.gate",
|
| 146 |
+
"model.language_model.layers.11.mlp.shared_expert_gate",
|
| 147 |
+
"model.language_model.layers.12.linear_attn.conv1d",
|
| 148 |
+
"model.language_model.layers.12.linear_attn.in_proj_a",
|
| 149 |
+
"model.language_model.layers.12.linear_attn.in_proj_b",
|
| 150 |
+
"model.language_model.layers.12.mlp.gate",
|
| 151 |
+
"model.language_model.layers.12.mlp.shared_expert_gate",
|
| 152 |
+
"model.language_model.layers.13.linear_attn.conv1d",
|
| 153 |
+
"model.language_model.layers.13.linear_attn.in_proj_a",
|
| 154 |
+
"model.language_model.layers.13.linear_attn.in_proj_b",
|
| 155 |
+
"model.language_model.layers.13.mlp.gate",
|
| 156 |
+
"model.language_model.layers.13.mlp.shared_expert_gate",
|
| 157 |
+
"model.language_model.layers.14.linear_attn.conv1d",
|
| 158 |
+
"model.language_model.layers.14.linear_attn.in_proj_a",
|
| 159 |
+
"model.language_model.layers.14.linear_attn.in_proj_b",
|
| 160 |
+
"model.language_model.layers.14.mlp.gate",
|
| 161 |
+
"model.language_model.layers.14.mlp.shared_expert_gate",
|
| 162 |
+
"model.language_model.layers.15.mlp.gate",
|
| 163 |
+
"model.language_model.layers.15.mlp.shared_expert_gate",
|
| 164 |
+
"model.language_model.layers.16.linear_attn.conv1d",
|
| 165 |
+
"model.language_model.layers.16.linear_attn.in_proj_a",
|
| 166 |
+
"model.language_model.layers.16.linear_attn.in_proj_b",
|
| 167 |
+
"model.language_model.layers.16.mlp.gate",
|
| 168 |
+
"model.language_model.layers.16.mlp.shared_expert_gate",
|
| 169 |
+
"model.language_model.layers.17.linear_attn.conv1d",
|
| 170 |
+
"model.language_model.layers.17.linear_attn.in_proj_a",
|
| 171 |
+
"model.language_model.layers.17.linear_attn.in_proj_b",
|
| 172 |
+
"model.language_model.layers.17.mlp.gate",
|
| 173 |
+
"model.language_model.layers.17.mlp.shared_expert_gate",
|
| 174 |
+
"model.language_model.layers.18.linear_attn.conv1d",
|
| 175 |
+
"model.language_model.layers.18.linear_attn.in_proj_a",
|
| 176 |
+
"model.language_model.layers.18.linear_attn.in_proj_b",
|
| 177 |
+
"model.language_model.layers.18.mlp.gate",
|
| 178 |
+
"model.language_model.layers.18.mlp.shared_expert_gate",
|
| 179 |
+
"model.language_model.layers.19.mlp.gate",
|
| 180 |
+
"model.language_model.layers.19.mlp.shared_expert_gate",
|
| 181 |
+
"model.language_model.layers.2.linear_attn.conv1d",
|
| 182 |
+
"model.language_model.layers.2.linear_attn.in_proj_a",
|
| 183 |
+
"model.language_model.layers.2.linear_attn.in_proj_b",
|
| 184 |
+
"model.language_model.layers.2.mlp.gate",
|
| 185 |
+
"model.language_model.layers.2.mlp.shared_expert_gate",
|
| 186 |
+
"model.language_model.layers.20.linear_attn.conv1d",
|
| 187 |
+
"model.language_model.layers.20.linear_attn.in_proj_a",
|
| 188 |
+
"model.language_model.layers.20.linear_attn.in_proj_b",
|
| 189 |
+
"model.language_model.layers.20.mlp.gate",
|
| 190 |
+
"model.language_model.layers.20.mlp.shared_expert_gate",
|
| 191 |
+
"model.language_model.layers.21.linear_attn.conv1d",
|
| 192 |
+
"model.language_model.layers.21.linear_attn.in_proj_a",
|
| 193 |
+
"model.language_model.layers.21.linear_attn.in_proj_b",
|
| 194 |
+
"model.language_model.layers.21.mlp.gate",
|
| 195 |
+
"model.language_model.layers.21.mlp.shared_expert_gate",
|
| 196 |
+
"model.language_model.layers.22.linear_attn.conv1d",
|
| 197 |
+
"model.language_model.layers.22.linear_attn.in_proj_a",
|
| 198 |
+
"model.language_model.layers.22.linear_attn.in_proj_b",
|
| 199 |
+
"model.language_model.layers.22.mlp.gate",
|
| 200 |
+
"model.language_model.layers.22.mlp.shared_expert_gate",
|
| 201 |
+
"model.language_model.layers.23.mlp.gate",
|
| 202 |
+
"model.language_model.layers.23.mlp.shared_expert_gate",
|
| 203 |
+
"model.language_model.layers.24.linear_attn.conv1d",
|
| 204 |
+
"model.language_model.layers.24.linear_attn.in_proj_a",
|
| 205 |
+
"model.language_model.layers.24.linear_attn.in_proj_b",
|
| 206 |
+
"model.language_model.layers.24.mlp.gate",
|
| 207 |
+
"model.language_model.layers.24.mlp.shared_expert_gate",
|
| 208 |
+
"model.language_model.layers.25.linear_attn.conv1d",
|
| 209 |
+
"model.language_model.layers.25.linear_attn.in_proj_a",
|
| 210 |
+
"model.language_model.layers.25.linear_attn.in_proj_b",
|
| 211 |
+
"model.language_model.layers.25.mlp.gate",
|
| 212 |
+
"model.language_model.layers.25.mlp.shared_expert_gate",
|
| 213 |
+
"model.language_model.layers.26.linear_attn.conv1d",
|
| 214 |
+
"model.language_model.layers.26.linear_attn.in_proj_a",
|
| 215 |
+
"model.language_model.layers.26.linear_attn.in_proj_b",
|
| 216 |
+
"model.language_model.layers.26.mlp.gate",
|
| 217 |
+
"model.language_model.layers.26.mlp.shared_expert_gate",
|
| 218 |
+
"model.language_model.layers.27.mlp.gate",
|
| 219 |
+
"model.language_model.layers.27.mlp.shared_expert_gate",
|
| 220 |
+
"model.language_model.layers.28.linear_attn.conv1d",
|
| 221 |
+
"model.language_model.layers.28.linear_attn.in_proj_a",
|
| 222 |
+
"model.language_model.layers.28.linear_attn.in_proj_b",
|
| 223 |
+
"model.language_model.layers.28.mlp.gate",
|
| 224 |
+
"model.language_model.layers.28.mlp.shared_expert_gate",
|
| 225 |
+
"model.language_model.layers.29.linear_attn.conv1d",
|
| 226 |
+
"model.language_model.layers.29.linear_attn.in_proj_a",
|
| 227 |
+
"model.language_model.layers.29.linear_attn.in_proj_b",
|
| 228 |
+
"model.language_model.layers.29.mlp.gate",
|
| 229 |
+
"model.language_model.layers.29.mlp.shared_expert_gate",
|
| 230 |
+
"model.language_model.layers.3.mlp.gate",
|
| 231 |
+
"model.language_model.layers.3.mlp.shared_expert_gate",
|
| 232 |
+
"model.language_model.layers.30.linear_attn.conv1d",
|
| 233 |
+
"model.language_model.layers.30.linear_attn.in_proj_a",
|
| 234 |
+
"model.language_model.layers.30.linear_attn.in_proj_b",
|
| 235 |
+
"model.language_model.layers.30.mlp.gate",
|
| 236 |
+
"model.language_model.layers.30.mlp.shared_expert_gate",
|
| 237 |
+
"model.language_model.layers.31.mlp.gate",
|
| 238 |
+
"model.language_model.layers.31.mlp.shared_expert_gate",
|
| 239 |
+
"model.language_model.layers.32.linear_attn.conv1d",
|
| 240 |
+
"model.language_model.layers.32.linear_attn.in_proj_a",
|
| 241 |
+
"model.language_model.layers.32.linear_attn.in_proj_b",
|
| 242 |
+
"model.language_model.layers.32.mlp.gate",
|
| 243 |
+
"model.language_model.layers.32.mlp.shared_expert_gate",
|
| 244 |
+
"model.language_model.layers.33.linear_attn.conv1d",
|
| 245 |
+
"model.language_model.layers.33.linear_attn.in_proj_a",
|
| 246 |
+
"model.language_model.layers.33.linear_attn.in_proj_b",
|
| 247 |
+
"model.language_model.layers.33.mlp.gate",
|
| 248 |
+
"model.language_model.layers.33.mlp.shared_expert_gate",
|
| 249 |
+
"model.language_model.layers.34.linear_attn.conv1d",
|
| 250 |
+
"model.language_model.layers.34.linear_attn.in_proj_a",
|
| 251 |
+
"model.language_model.layers.34.linear_attn.in_proj_b",
|
| 252 |
+
"model.language_model.layers.34.mlp.gate",
|
| 253 |
+
"model.language_model.layers.34.mlp.shared_expert_gate",
|
| 254 |
+
"model.language_model.layers.35.mlp.gate",
|
| 255 |
+
"model.language_model.layers.35.mlp.shared_expert_gate",
|
| 256 |
+
"model.language_model.layers.36.linear_attn.conv1d",
|
| 257 |
+
"model.language_model.layers.36.linear_attn.in_proj_a",
|
| 258 |
+
"model.language_model.layers.36.linear_attn.in_proj_b",
|
| 259 |
+
"model.language_model.layers.36.mlp.gate",
|
| 260 |
+
"model.language_model.layers.36.mlp.shared_expert_gate",
|
| 261 |
+
"model.language_model.layers.37.linear_attn.conv1d",
|
| 262 |
+
"model.language_model.layers.37.linear_attn.in_proj_a",
|
| 263 |
+
"model.language_model.layers.37.linear_attn.in_proj_b",
|
| 264 |
+
"model.language_model.layers.37.mlp.gate",
|
| 265 |
+
"model.language_model.layers.37.mlp.shared_expert_gate",
|
| 266 |
+
"model.language_model.layers.38.linear_attn.conv1d",
|
| 267 |
+
"model.language_model.layers.38.linear_attn.in_proj_a",
|
| 268 |
+
"model.language_model.layers.38.linear_attn.in_proj_b",
|
| 269 |
+
"model.language_model.layers.38.mlp.gate",
|
| 270 |
+
"model.language_model.layers.38.mlp.shared_expert_gate",
|
| 271 |
+
"model.language_model.layers.39.mlp.gate",
|
| 272 |
+
"model.language_model.layers.39.mlp.shared_expert_gate",
|
| 273 |
+
"model.language_model.layers.4.linear_attn.conv1d",
|
| 274 |
+
"model.language_model.layers.4.linear_attn.in_proj_a",
|
| 275 |
+
"model.language_model.layers.4.linear_attn.in_proj_b",
|
| 276 |
+
"model.language_model.layers.4.mlp.gate",
|
| 277 |
+
"model.language_model.layers.4.mlp.shared_expert_gate",
|
| 278 |
+
"model.language_model.layers.5.linear_attn.conv1d",
|
| 279 |
+
"model.language_model.layers.5.linear_attn.in_proj_a",
|
| 280 |
+
"model.language_model.layers.5.linear_attn.in_proj_b",
|
| 281 |
+
"model.language_model.layers.5.mlp.gate",
|
| 282 |
+
"model.language_model.layers.5.mlp.shared_expert_gate",
|
| 283 |
+
"model.language_model.layers.6.linear_attn.conv1d",
|
| 284 |
+
"model.language_model.layers.6.linear_attn.in_proj_a",
|
| 285 |
+
"model.language_model.layers.6.linear_attn.in_proj_b",
|
| 286 |
+
"model.language_model.layers.6.mlp.gate",
|
| 287 |
+
"model.language_model.layers.6.mlp.shared_expert_gate",
|
| 288 |
+
"model.language_model.layers.7.mlp.gate",
|
| 289 |
+
"model.language_model.layers.7.mlp.shared_expert_gate",
|
| 290 |
+
"model.language_model.layers.8.linear_attn.conv1d",
|
| 291 |
+
"model.language_model.layers.8.linear_attn.in_proj_a",
|
| 292 |
+
"model.language_model.layers.8.linear_attn.in_proj_b",
|
| 293 |
+
"model.language_model.layers.8.mlp.gate",
|
| 294 |
+
"model.language_model.layers.8.mlp.shared_expert_gate",
|
| 295 |
+
"model.language_model.layers.9.linear_attn.conv1d",
|
| 296 |
+
"model.language_model.layers.9.linear_attn.in_proj_a",
|
| 297 |
+
"model.language_model.layers.9.linear_attn.in_proj_b",
|
| 298 |
+
"model.language_model.layers.9.mlp.gate",
|
| 299 |
+
"model.language_model.layers.9.mlp.shared_expert_gate",
|
| 300 |
+
"model.visual.blocks.0.attn.proj",
|
| 301 |
+
"model.visual.blocks.0.attn.qkv",
|
| 302 |
+
"model.visual.blocks.0.mlp.linear_fc1",
|
| 303 |
+
"model.visual.blocks.0.mlp.linear_fc2",
|
| 304 |
+
"model.visual.blocks.1.attn.proj",
|
| 305 |
+
"model.visual.blocks.1.attn.qkv",
|
| 306 |
+
"model.visual.blocks.1.mlp.linear_fc1",
|
| 307 |
+
"model.visual.blocks.1.mlp.linear_fc2",
|
| 308 |
+
"model.visual.blocks.10.attn.proj",
|
| 309 |
+
"model.visual.blocks.10.attn.qkv",
|
| 310 |
+
"model.visual.blocks.10.mlp.linear_fc1",
|
| 311 |
+
"model.visual.blocks.10.mlp.linear_fc2",
|
| 312 |
+
"model.visual.blocks.11.attn.proj",
|
| 313 |
+
"model.visual.blocks.11.attn.qkv",
|
| 314 |
+
"model.visual.blocks.11.mlp.linear_fc1",
|
| 315 |
+
"model.visual.blocks.11.mlp.linear_fc2",
|
| 316 |
+
"model.visual.blocks.12.attn.proj",
|
| 317 |
+
"model.visual.blocks.12.attn.qkv",
|
| 318 |
+
"model.visual.blocks.12.mlp.linear_fc1",
|
| 319 |
+
"model.visual.blocks.12.mlp.linear_fc2",
|
| 320 |
+
"model.visual.blocks.13.attn.proj",
|
| 321 |
+
"model.visual.blocks.13.attn.qkv",
|
| 322 |
+
"model.visual.blocks.13.mlp.linear_fc1",
|
| 323 |
+
"model.visual.blocks.13.mlp.linear_fc2",
|
| 324 |
+
"model.visual.blocks.14.attn.proj",
|
| 325 |
+
"model.visual.blocks.14.attn.qkv",
|
| 326 |
+
"model.visual.blocks.14.mlp.linear_fc1",
|
| 327 |
+
"model.visual.blocks.14.mlp.linear_fc2",
|
| 328 |
+
"model.visual.blocks.15.attn.proj",
|
| 329 |
+
"model.visual.blocks.15.attn.qkv",
|
| 330 |
+
"model.visual.blocks.15.mlp.linear_fc1",
|
| 331 |
+
"model.visual.blocks.15.mlp.linear_fc2",
|
| 332 |
+
"model.visual.blocks.16.attn.proj",
|
| 333 |
+
"model.visual.blocks.16.attn.qkv",
|
| 334 |
+
"model.visual.blocks.16.mlp.linear_fc1",
|
| 335 |
+
"model.visual.blocks.16.mlp.linear_fc2",
|
| 336 |
+
"model.visual.blocks.17.attn.proj",
|
| 337 |
+
"model.visual.blocks.17.attn.qkv",
|
| 338 |
+
"model.visual.blocks.17.mlp.linear_fc1",
|
| 339 |
+
"model.visual.blocks.17.mlp.linear_fc2",
|
| 340 |
+
"model.visual.blocks.18.attn.proj",
|
| 341 |
+
"model.visual.blocks.18.attn.qkv",
|
| 342 |
+
"model.visual.blocks.18.mlp.linear_fc1",
|
| 343 |
+
"model.visual.blocks.18.mlp.linear_fc2",
|
| 344 |
+
"model.visual.blocks.19.attn.proj",
|
| 345 |
+
"model.visual.blocks.19.attn.qkv",
|
| 346 |
+
"model.visual.blocks.19.mlp.linear_fc1",
|
| 347 |
+
"model.visual.blocks.19.mlp.linear_fc2",
|
| 348 |
+
"model.visual.blocks.2.attn.proj",
|
| 349 |
+
"model.visual.blocks.2.attn.qkv",
|
| 350 |
+
"model.visual.blocks.2.mlp.linear_fc1",
|
| 351 |
+
"model.visual.blocks.2.mlp.linear_fc2",
|
| 352 |
+
"model.visual.blocks.20.attn.proj",
|
| 353 |
+
"model.visual.blocks.20.attn.qkv",
|
| 354 |
+
"model.visual.blocks.20.mlp.linear_fc1",
|
| 355 |
+
"model.visual.blocks.20.mlp.linear_fc2",
|
| 356 |
+
"model.visual.blocks.21.attn.proj",
|
| 357 |
+
"model.visual.blocks.21.attn.qkv",
|
| 358 |
+
"model.visual.blocks.21.mlp.linear_fc1",
|
| 359 |
+
"model.visual.blocks.21.mlp.linear_fc2",
|
| 360 |
+
"model.visual.blocks.22.attn.proj",
|
| 361 |
+
"model.visual.blocks.22.attn.qkv",
|
| 362 |
+
"model.visual.blocks.22.mlp.linear_fc1",
|
| 363 |
+
"model.visual.blocks.22.mlp.linear_fc2",
|
| 364 |
+
"model.visual.blocks.23.attn.proj",
|
| 365 |
+
"model.visual.blocks.23.attn.qkv",
|
| 366 |
+
"model.visual.blocks.23.mlp.linear_fc1",
|
| 367 |
+
"model.visual.blocks.23.mlp.linear_fc2",
|
| 368 |
+
"model.visual.blocks.24.attn.proj",
|
| 369 |
+
"model.visual.blocks.24.attn.qkv",
|
| 370 |
+
"model.visual.blocks.24.mlp.linear_fc1",
|
| 371 |
+
"model.visual.blocks.24.mlp.linear_fc2",
|
| 372 |
+
"model.visual.blocks.25.attn.proj",
|
| 373 |
+
"model.visual.blocks.25.attn.qkv",
|
| 374 |
+
"model.visual.blocks.25.mlp.linear_fc1",
|
| 375 |
+
"model.visual.blocks.25.mlp.linear_fc2",
|
| 376 |
+
"model.visual.blocks.26.attn.proj",
|
| 377 |
+
"model.visual.blocks.26.attn.qkv",
|
| 378 |
+
"model.visual.blocks.26.mlp.linear_fc1",
|
| 379 |
+
"model.visual.blocks.26.mlp.linear_fc2",
|
| 380 |
+
"model.visual.blocks.3.attn.proj",
|
| 381 |
+
"model.visual.blocks.3.attn.qkv",
|
| 382 |
+
"model.visual.blocks.3.mlp.linear_fc1",
|
| 383 |
+
"model.visual.blocks.3.mlp.linear_fc2",
|
| 384 |
+
"model.visual.blocks.4.attn.proj",
|
| 385 |
+
"model.visual.blocks.4.attn.qkv",
|
| 386 |
+
"model.visual.blocks.4.mlp.linear_fc1",
|
| 387 |
+
"model.visual.blocks.4.mlp.linear_fc2",
|
| 388 |
+
"model.visual.blocks.5.attn.proj",
|
| 389 |
+
"model.visual.blocks.5.attn.qkv",
|
| 390 |
+
"model.visual.blocks.5.mlp.linear_fc1",
|
| 391 |
+
"model.visual.blocks.5.mlp.linear_fc2",
|
| 392 |
+
"model.visual.blocks.6.attn.proj",
|
| 393 |
+
"model.visual.blocks.6.attn.qkv",
|
| 394 |
+
"model.visual.blocks.6.mlp.linear_fc1",
|
| 395 |
+
"model.visual.blocks.6.mlp.linear_fc2",
|
| 396 |
+
"model.visual.blocks.7.attn.proj",
|
| 397 |
+
"model.visual.blocks.7.attn.qkv",
|
| 398 |
+
"model.visual.blocks.7.mlp.linear_fc1",
|
| 399 |
+
"model.visual.blocks.7.mlp.linear_fc2",
|
| 400 |
+
"model.visual.blocks.8.attn.proj",
|
| 401 |
+
"model.visual.blocks.8.attn.qkv",
|
| 402 |
+
"model.visual.blocks.8.mlp.linear_fc1",
|
| 403 |
+
"model.visual.blocks.8.mlp.linear_fc2",
|
| 404 |
+
"model.visual.blocks.9.attn.proj",
|
| 405 |
+
"model.visual.blocks.9.attn.qkv",
|
| 406 |
+
"model.visual.blocks.9.mlp.linear_fc1",
|
| 407 |
+
"model.visual.blocks.9.mlp.linear_fc2",
|
| 408 |
+
"model.visual.merger.linear_fc1",
|
| 409 |
+
"model.visual.merger.linear_fc2",
|
| 410 |
+
"model.visual.patch_embed.proj",
|
| 411 |
+
"model.visual.pos_embed",
|
| 412 |
+
"mtp.fc",
|
| 413 |
+
"mtp.layers.0.mlp.gate",
|
| 414 |
+
"mtp.layers.0.mlp.shared_expert_gate"
|
| 415 |
+
]
|
| 416 |
+
}
|
| 417 |
+
}
|
| 418 |
+
}
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"size": {
|
| 3 |
+
"longest_edge": 16777216,
|
| 4 |
+
"shortest_edge": 65536
|
| 5 |
+
},
|
| 6 |
+
"patch_size": 16,
|
| 7 |
+
"temporal_patch_size": 2,
|
| 8 |
+
"merge_size": 2,
|
| 9 |
+
"image_mean": [
|
| 10 |
+
0.5,
|
| 11 |
+
0.5,
|
| 12 |
+
0.5
|
| 13 |
+
],
|
| 14 |
+
"image_std": [
|
| 15 |
+
0.5,
|
| 16 |
+
0.5,
|
| 17 |
+
0.5
|
| 18 |
+
],
|
| 19 |
+
"processor_class": "Qwen3VLProcessor",
|
| 20 |
+
"image_processor_type": "Qwen2VLImageProcessorFast"
|
| 21 |
+
}
|
processing_wemm.py
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Unified HF processor for the WeMM Video 1.5 Qwen3.5 audio checkpoints."""
|
| 2 |
+
import copy
|
| 3 |
+
import json
|
| 4 |
+
import shutil
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
from transformers import BatchFeature, ProcessorMixin, Qwen3VLProcessor, WhisperFeatureExtractor
|
| 9 |
+
from transformers.utils.hub import cached_file
|
| 10 |
+
from transformers.video_utils import VideoMetadata
|
| 11 |
+
|
| 12 |
+
from .wemm_media import AUDIO, IMAGE, VIDEO, audio_features, audio_ids, decode_audio
|
| 13 |
+
from .wemm_media import decode_video, load_image, resolve_media, tokens_per_segment, video_ids
|
| 14 |
+
from .wemm_media import audio_timestamp_groups, resolve_timestamp_interval, timestamp_interval_option
|
| 15 |
+
from .wemm_video_policy import resolve_video_options, video_environment_defaults, video_resize_size
|
| 16 |
+
# Transformers 5.2 must see these dependencies directly when caching remote
|
| 17 |
+
# processor code; an import through wemm_media alone misses the nested file.
|
| 18 |
+
from .wemm_zip import load_zip_video as _zip_decoder_dependency
|
| 19 |
+
from .wemm_zip_policy import positive_frame_count
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class WeMMProcessor(ProcessorMixin):
|
| 23 |
+
"""Single-conversation media + question API, including ordered chat messages.
|
| 24 |
+
|
| 25 |
+
``processor(question='描述视频', videos='clip.mp4', use_audio_in_video=True)``
|
| 26 |
+
returns a BatchFeature directly accepted by ``model.generate(**inputs)``.
|
| 27 |
+
Lists of media belong to the same conversation, not a batch of requests.
|
| 28 |
+
"""
|
| 29 |
+
image_processor_class = 'AutoImageProcessor'
|
| 30 |
+
video_processor_class = 'AutoVideoProcessor'
|
| 31 |
+
tokenizer_class = 'AutoTokenizer'
|
| 32 |
+
feature_extractor_class = 'WhisperFeatureExtractor'
|
| 33 |
+
|
| 34 |
+
@classmethod
|
| 35 |
+
def get_attributes(cls):
|
| 36 |
+
return ['image_processor', 'tokenizer', 'video_processor', 'feature_extractor']
|
| 37 |
+
|
| 38 |
+
def __init__(self, image_processor, tokenizer, video_processor, feature_extractor,
|
| 39 |
+
audio_config, fps=2.0, min_frames=4, max_frames=128, total_pixels=None,
|
| 40 |
+
min_pixels=4096, system_prompt='You are a helpful assistant.', chat_template=None,
|
| 41 |
+
timestamp_interval_sec=1.0, max_allowed_frames=None, max_allowed_total_pixels=None):
|
| 42 |
+
super().__init__(image_processor=image_processor, tokenizer=tokenizer,
|
| 43 |
+
video_processor=video_processor, feature_extractor=feature_extractor,
|
| 44 |
+
chat_template=chat_template or tokenizer.chat_template)
|
| 45 |
+
self.audio_config = copy.deepcopy(audio_config)
|
| 46 |
+
self.fps, self.min_frames, self.max_frames = fps, min_frames, max_frames
|
| 47 |
+
self.total_pixels = total_pixels or video_processor.size['longest_edge']
|
| 48 |
+
self.min_pixels, self.system_prompt = min_pixels, system_prompt
|
| 49 |
+
self.timestamp_interval_sec = resolve_timestamp_interval(timestamp_interval_sec)
|
| 50 |
+
self.max_allowed_frames = max_allowed_frames
|
| 51 |
+
self.max_allowed_total_pixels = max_allowed_total_pixels
|
| 52 |
+
self._native = Qwen3VLProcessor(image_processor=image_processor,
|
| 53 |
+
tokenizer=tokenizer, video_processor=video_processor)
|
| 54 |
+
|
| 55 |
+
@classmethod
|
| 56 |
+
def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
|
| 57 |
+
names = ('fps', 'min_frames', 'max_frames', 'total_pixels', 'min_pixels', 'system_prompt',
|
| 58 |
+
'timestamp_interval_sec', 'max_allowed_frames', 'max_allowed_total_pixels')
|
| 59 |
+
overrides = {key: kwargs.pop(key) for key in names if key in kwargs}
|
| 60 |
+
if 'TIMESTAMP_INTERVAL_SEC' in kwargs:
|
| 61 |
+
raise ValueError('Use lowercase timestamp_interval_sec in processor arguments')
|
| 62 |
+
trust_remote_code = kwargs.pop('trust_remote_code', True)
|
| 63 |
+
kwargs.pop('_from_auto', None)
|
| 64 |
+
hub = {key: kwargs[key] for key in ('cache_dir', 'force_download', 'local_files_only',
|
| 65 |
+
'token', 'revision', 'subfolder') if key in kwargs}
|
| 66 |
+
proc_path = cached_file(pretrained_model_name_or_path, 'processor_config.json',
|
| 67 |
+
_raise_exceptions_for_missing_entries=False, **hub)
|
| 68 |
+
processor_config = json.loads(Path(proc_path).read_text()) if proc_path else {}
|
| 69 |
+
config_path = cached_file(pretrained_model_name_or_path, 'config.json',
|
| 70 |
+
_raise_exceptions_for_missing_entries=False, **hub)
|
| 71 |
+
config = json.loads(Path(config_path).read_text()) if config_path else processor_config
|
| 72 |
+
defaults = processor_config.get('wemm_defaults', {})
|
| 73 |
+
native = Qwen3VLProcessor.from_pretrained(
|
| 74 |
+
pretrained_model_name_or_path, trust_remote_code=trust_remote_code, **kwargs)
|
| 75 |
+
audio = config['audio_config']
|
| 76 |
+
extractor = WhisperFeatureExtractor(feature_size=audio['num_mel_bins'], sampling_rate=16000,
|
| 77 |
+
hop_length=160, chunk_length=30)
|
| 78 |
+
environment = video_environment_defaults()
|
| 79 |
+
effective = resolve_video_options({"total_pixels": native.video_processor.size['longest_edge'],
|
| 80 |
+
**defaults, **environment}, overrides)
|
| 81 |
+
parameters = {**defaults, **overrides, **{key: effective[key] for key in names if key in effective}}
|
| 82 |
+
return cls(native.image_processor, native.tokenizer, native.video_processor,
|
| 83 |
+
extractor, audio, chat_template=native.chat_template, **parameters)
|
| 84 |
+
|
| 85 |
+
def save_pretrained(self, save_directory, **kwargs):
|
| 86 |
+
"""Save processor metadata/code beside a config containing audio_config."""
|
| 87 |
+
destination = Path(save_directory)
|
| 88 |
+
destination.mkdir(parents=True, exist_ok=True)
|
| 89 |
+
self._native.save_pretrained(destination, **kwargs)
|
| 90 |
+
# Transformers 5.2 stores nested components in processor_config.json.
|
| 91 |
+
# Also write standalone component configs before our custom metadata.
|
| 92 |
+
self.image_processor.save_pretrained(destination)
|
| 93 |
+
self.video_processor.save_pretrained(destination)
|
| 94 |
+
defaults = {key: getattr(self, key) for key in
|
| 95 |
+
('fps', 'min_frames', 'max_frames', 'total_pixels', 'min_pixels', 'system_prompt',
|
| 96 |
+
'timestamp_interval_sec', 'max_allowed_frames', 'max_allowed_total_pixels')}
|
| 97 |
+
mapping = {'AutoProcessor': 'processing_wemm.WeMMProcessor'}
|
| 98 |
+
(destination / 'processor_config.json').write_text(json.dumps({
|
| 99 |
+
'processor_class': 'WeMMProcessor', 'auto_map': mapping,
|
| 100 |
+
'wemm_defaults': defaults, 'audio_config': self.audio_config}, indent=2) + '\n')
|
| 101 |
+
for name in ('processing_wemm.py', 'wemm_media.py', 'wemm_video_policy.py',
|
| 102 |
+
'wemm_zip.py', 'wemm_zip_policy.py'):
|
| 103 |
+
source = Path(__file__).parent / name
|
| 104 |
+
if source.resolve() != (destination / name).resolve():
|
| 105 |
+
shutil.copy2(source, destination / name)
|
| 106 |
+
config_path = destination / 'config.json'
|
| 107 |
+
if config_path.exists():
|
| 108 |
+
config = json.loads(config_path.read_text())
|
| 109 |
+
config.setdefault('auto_map', {}).update(mapping)
|
| 110 |
+
config_path.write_text(json.dumps(config, indent=2) + '\n')
|
| 111 |
+
return [str(destination / 'processor_config.json')]
|
| 112 |
+
|
| 113 |
+
@property
|
| 114 |
+
def model_input_names(self):
|
| 115 |
+
return ['input_ids', 'attention_mask', 'pixel_values', 'image_grid_thw',
|
| 116 |
+
'pixel_values_videos', 'video_grid_thw', 'audio_feature']
|
| 117 |
+
|
| 118 |
+
def decode(self, *args, **kwargs):
|
| 119 |
+
return self.tokenizer.decode(*args, **kwargs)
|
| 120 |
+
|
| 121 |
+
def batch_decode(self, *args, **kwargs):
|
| 122 |
+
return self.tokenizer.batch_decode(*args, **kwargs)
|
| 123 |
+
|
| 124 |
+
@property
|
| 125 |
+
def _calculate_timestamps(self):
|
| 126 |
+
# Existing project helpers override native timestamp arithmetic for AV.
|
| 127 |
+
return self._native._calculate_timestamps
|
| 128 |
+
|
| 129 |
+
@_calculate_timestamps.setter
|
| 130 |
+
def _calculate_timestamps(self, function):
|
| 131 |
+
self._native._calculate_timestamps = function
|
| 132 |
+
|
| 133 |
+
@staticmethod
|
| 134 |
+
def _items(value, modality):
|
| 135 |
+
if value is None:
|
| 136 |
+
return []
|
| 137 |
+
if modality == 'audio' and isinstance(value, tuple) and len(value) == 2:
|
| 138 |
+
return [value]
|
| 139 |
+
return value if isinstance(value, list) else [value]
|
| 140 |
+
|
| 141 |
+
def _messages(self, question, media, images, videos, audios, video_audio, use_audio_in_video):
|
| 142 |
+
items = []
|
| 143 |
+
for kind, value in (('image', images), ('video', videos), ('audio', audios), ('video_audio', video_audio)):
|
| 144 |
+
for item in self._items(value, kind):
|
| 145 |
+
items.append({'type': 'video_audio' if kind == 'video' and use_audio_in_video else kind,
|
| 146 |
+
kind if kind != 'video_audio' else 'video': item})
|
| 147 |
+
for item in self._items(media, 'media'):
|
| 148 |
+
if isinstance(item, dict):
|
| 149 |
+
items.append(item)
|
| 150 |
+
continue
|
| 151 |
+
suffix = Path(str(item)).suffix.lower()
|
| 152 |
+
if suffix in ('.jpg', '.jpeg', '.png', '.webp', '.bmp', '.tiff'):
|
| 153 |
+
kind = 'image'
|
| 154 |
+
elif suffix in ('.wav', '.flac', '.mp3', '.ogg', '.m4a', '.aac'):
|
| 155 |
+
kind = 'audio'
|
| 156 |
+
elif suffix in ('.mp4', '.mov', '.mkv', '.webm', '.avi', '.zip'):
|
| 157 |
+
kind = 'video_audio' if use_audio_in_video else 'video'
|
| 158 |
+
else:
|
| 159 |
+
raise ValueError('Specify the media type explicitly for this input')
|
| 160 |
+
items.append({'type': kind, 'video' if kind == 'video_audio' else kind: item})
|
| 161 |
+
content = []
|
| 162 |
+
for item in items:
|
| 163 |
+
content.extend([item, {'type': 'text', 'text': '\n'}])
|
| 164 |
+
content.append({'type': 'text', 'text': question})
|
| 165 |
+
return [{'role': 'system', 'content': self.system_prompt}, {'role': 'user', 'content': content}]
|
| 166 |
+
|
| 167 |
+
def _normalize_messages(self, messages, use_audio_in_video=False):
|
| 168 |
+
normalized, routes = [], []
|
| 169 |
+
for message in messages:
|
| 170 |
+
row = {key: value for key, value in message.items() if key != 'content'}
|
| 171 |
+
if isinstance(message['content'], str):
|
| 172 |
+
row['content'] = message['content']
|
| 173 |
+
else:
|
| 174 |
+
parts = []
|
| 175 |
+
for item in message['content']:
|
| 176 |
+
kind = item['type']
|
| 177 |
+
if kind in ('video_url', 'video_audio_url'):
|
| 178 |
+
payload = item.get('video_url')
|
| 179 |
+
nested = payload if isinstance(payload, dict) else {}
|
| 180 |
+
video_source = nested.get('url') if nested else payload
|
| 181 |
+
audio = item.get('audio_url') or nested.get('audio')
|
| 182 |
+
audio_source = audio.get('url') if isinstance(audio, dict) else audio
|
| 183 |
+
if video_source:
|
| 184 |
+
kind = 'video_audio' if audio_source or nested.get('use_audio') else 'video'
|
| 185 |
+
item = {**item, **nested, 'type': kind, 'video': video_source}
|
| 186 |
+
if audio_source:
|
| 187 |
+
item['audio'] = audio_source
|
| 188 |
+
elif item['type'] == 'video_audio_url' and audio_source:
|
| 189 |
+
kind, item = 'audio', {'type': 'audio', 'audio': audio_source}
|
| 190 |
+
else:
|
| 191 |
+
raise ValueError('Missing video URL in media item')
|
| 192 |
+
if kind in ('audio_url', 'input_audio'):
|
| 193 |
+
payload = item[kind]
|
| 194 |
+
if kind == 'audio_url':
|
| 195 |
+
source = payload['url'] if isinstance(payload, dict) else payload
|
| 196 |
+
else:
|
| 197 |
+
source = f"data:audio/{payload['format']};base64,{payload['data']}"
|
| 198 |
+
nested = payload if isinstance(payload, dict) else {}
|
| 199 |
+
interval = timestamp_interval_option(item, timestamp_interval_option(nested))
|
| 200 |
+
item = {'type': 'audio', 'audio': source, 'timestamp_interval_sec': interval}
|
| 201 |
+
kind = 'audio'
|
| 202 |
+
if kind == 'video' and item.get('use_audio_in_video', use_audio_in_video):
|
| 203 |
+
kind = 'video_audio'
|
| 204 |
+
if kind == 'text':
|
| 205 |
+
parts.append(item['text'])
|
| 206 |
+
elif kind in ('image', 'video', 'audio', 'video_audio'):
|
| 207 |
+
key = 'video' if kind == 'video_audio' else kind
|
| 208 |
+
if key not in item and 'path' not in item:
|
| 209 |
+
raise ValueError(f'Missing {key} or path in media item')
|
| 210 |
+
routes.append({**item, 'type': kind, 'source': item.get(key, item.get('path'))})
|
| 211 |
+
parts.append({'image': IMAGE, 'video': VIDEO, 'video_audio': VIDEO, 'audio': AUDIO}[kind])
|
| 212 |
+
else:
|
| 213 |
+
raise ValueError(f'Unsupported content type: {kind}')
|
| 214 |
+
row['content'] = ''.join(parts)
|
| 215 |
+
normalized.append(row)
|
| 216 |
+
return normalized, routes
|
| 217 |
+
|
| 218 |
+
def apply_chat_template(self, conversation, *, tokenize=False, return_dict=False,
|
| 219 |
+
return_tensors=None, add_generation_prompt=True, enable_thinking=False, **kwargs):
|
| 220 |
+
if tokenize:
|
| 221 |
+
result = self(messages=conversation, return_tensors=return_tensors or 'pt',
|
| 222 |
+
add_generation_prompt=add_generation_prompt, enable_thinking=enable_thinking, **kwargs)
|
| 223 |
+
return result if return_dict else result['input_ids']
|
| 224 |
+
messages, _ = self._normalize_messages(conversation)
|
| 225 |
+
return self.tokenizer.apply_chat_template(messages, tokenize=False,
|
| 226 |
+
add_generation_prompt=add_generation_prompt, enable_thinking=enable_thinking, **kwargs)
|
| 227 |
+
|
| 228 |
+
def __call__(self, text=None, *, question=None, media=None, images=None, videos=None,
|
| 229 |
+
audio=None, audios=None, video_audio=None, use_audio_in_video=False, messages=None,
|
| 230 |
+
text_is_prompt=False, fps=None, num_frames=None, nframes=None, min_frames=None, max_frames=None,
|
| 231 |
+
total_pixels=None, min_pixels=None, max_pixels=None, images_kwargs=None,
|
| 232 |
+
videos_kwargs=None, return_tensors='pt', add_generation_prompt=True,
|
| 233 |
+
enable_thinking=False, timestamp_interval_sec=None):
|
| 234 |
+
timestamp_interval_sec = resolve_timestamp_interval(
|
| 235 |
+
timestamp_interval_sec, default=self.timestamp_interval_sec)
|
| 236 |
+
if return_tensors != 'pt':
|
| 237 |
+
raise ValueError('WeMMProcessor currently returns PyTorch tensors; use return_tensors="pt"')
|
| 238 |
+
if audio is not None and audios is not None:
|
| 239 |
+
raise ValueError('Use either audio or audios')
|
| 240 |
+
audios = audio if audio is not None else audios
|
| 241 |
+
if messages is not None:
|
| 242 |
+
if any(x is not None for x in (text, question, media, images, videos, audios, video_audio)):
|
| 243 |
+
raise ValueError('Put media and text inside messages, or use the question/media interface')
|
| 244 |
+
normalized, routes = self._normalize_messages(messages, use_audio_in_video=use_audio_in_video)
|
| 245 |
+
prompt = self.tokenizer.apply_chat_template(normalized, tokenize=False,
|
| 246 |
+
add_generation_prompt=add_generation_prompt, enable_thinking=enable_thinking)
|
| 247 |
+
else:
|
| 248 |
+
if text is not None and question is not None:
|
| 249 |
+
raise ValueError('Use either text or question')
|
| 250 |
+
question = question if question is not None else text
|
| 251 |
+
if not isinstance(question, str):
|
| 252 |
+
raise ValueError('Pass one question string or one messages conversation')
|
| 253 |
+
normalized, routes = self._normalize_messages(self._messages(
|
| 254 |
+
question, media, images, videos, audios, video_audio, use_audio_in_video),
|
| 255 |
+
use_audio_in_video=use_audio_in_video)
|
| 256 |
+
prompt = question if text_is_prompt else self.tokenizer.apply_chat_template(
|
| 257 |
+
normalized, tokenize=False, add_generation_prompt=add_generation_prompt,
|
| 258 |
+
enable_thinking=enable_thinking)
|
| 259 |
+
image_pixels, image_grids, video_pixels, video_grids, features = [], [], [], [], []
|
| 260 |
+
blocks = {'image': [], 'video': [], 'audio': []}
|
| 261 |
+
block_features = {kind: [] for kind in blocks}
|
| 262 |
+
block_metadata = {kind: [] for kind in blocks}
|
| 263 |
+
metadata = []
|
| 264 |
+
for route in routes:
|
| 265 |
+
kind, source = route['type'], resolve_media(route['source'])
|
| 266 |
+
item_info = {'type': kind}
|
| 267 |
+
feature = None
|
| 268 |
+
if kind == 'image':
|
| 269 |
+
image = self.image_processor(images=[load_image(source)], return_tensors='pt',
|
| 270 |
+
**(images_kwargs or {}))
|
| 271 |
+
grid = image['image_grid_thw'][0]
|
| 272 |
+
image_pixels.append(image['pixel_values'])
|
| 273 |
+
image_grids.append(image['image_grid_thw'])
|
| 274 |
+
blocks['image'].append(self.tokenizer.encode('<|vision_start|>', add_special_tokens=False)
|
| 275 |
+
+ [self.tokenizer.convert_tokens_to_ids('<|image_pad|>')]
|
| 276 |
+
* (int(grid.prod()) // self.image_processor.merge_size**2)
|
| 277 |
+
+ self.tokenizer.encode('<|vision_end|>', add_special_tokens=False))
|
| 278 |
+
item_info['grid'] = grid.tolist()
|
| 279 |
+
elif kind == 'audio':
|
| 280 |
+
interval = resolve_timestamp_interval(timestamp_interval_option(route, timestamp_interval_sec))
|
| 281 |
+
samples = decode_audio(source)
|
| 282 |
+
duration = len(samples) / 16000
|
| 283 |
+
feature = audio_features(samples, self.feature_extractor)
|
| 284 |
+
count = feature.shape[0] * tokens_per_segment(self.audio_config)
|
| 285 |
+
blocks['audio'].append(audio_ids(self.tokenizer, count, self.audio_config['second_per_window'],
|
| 286 |
+
duration, interval))
|
| 287 |
+
groups, times, effective = audio_timestamp_groups(
|
| 288 |
+
count, self.audio_config['second_per_window'], duration, interval)
|
| 289 |
+
item_info.update(duration=duration, segments=len(feature), audio_tokens=count,
|
| 290 |
+
timestamp_interval_sec=interval, audio_groups=groups, timestamps=times,
|
| 291 |
+
effective_audio_tokens=effective, padding_audio_tokens=count-effective)
|
| 292 |
+
else:
|
| 293 |
+
options = resolve_video_options(dict(
|
| 294 |
+
fps=self.fps if fps is None else fps, num_frames=num_frames, nframes=nframes,
|
| 295 |
+
min_frames=self.min_frames if min_frames is None else min_frames,
|
| 296 |
+
max_frames=self.max_frames if max_frames is None else max_frames,
|
| 297 |
+
total_pixels=self.total_pixels if total_pixels is None else total_pixels,
|
| 298 |
+
min_pixels=self.min_pixels if min_pixels is None else min_pixels,
|
| 299 |
+
max_pixels=max_pixels, max_allowed_frames=self.max_allowed_frames,
|
| 300 |
+
max_allowed_total_pixels=self.max_allowed_total_pixels), route)
|
| 301 |
+
# SGLang supplies this internal cap from server-side defaults;
|
| 302 |
+
# the HTTP parser never accepts it from a request.
|
| 303 |
+
deployment_cap = positive_frame_count(
|
| 304 |
+
route.get('wemm_zip_max_frames', self.max_frames), 'ZIP deployment max_frames')
|
| 305 |
+
options['wemm_zip_max_frames'] = min(
|
| 306 |
+
deployment_cap, int(options.get('max_allowed_frames') or deployment_cap))
|
| 307 |
+
decode_keys = ('fps', 'num_frames', 'min_frames', 'max_frames', 'min_pixels',
|
| 308 |
+
'max_pixels', 'total_pixels', 'max_allowed_frames', 'max_allowed_total_pixels',
|
| 309 |
+
'wemm_zip_max_frames', 'resized_height', 'resized_width')
|
| 310 |
+
frames, info = decode_video(source, **{key: options[key] for key in decode_keys if key in options})
|
| 311 |
+
bundled_audio = info.pop('audio_bytes', None)
|
| 312 |
+
pre_resized = bool(info.get('wemm_pre_resized', False))
|
| 313 |
+
area = int(frames.shape[1] * frames.shape[2] * len(frames))
|
| 314 |
+
size = ({'longest_edge': area, 'shortest_edge': area} if pre_resized else
|
| 315 |
+
video_resize_size(len(frames), options))
|
| 316 |
+
kwargs = dict(videos_kwargs or {})
|
| 317 |
+
kwargs.setdefault('size', size)
|
| 318 |
+
if pre_resized:
|
| 319 |
+
kwargs.setdefault('do_resize', False)
|
| 320 |
+
video_metadata = {key: info[key] for key in
|
| 321 |
+
('total_num_frames', 'fps', 'frames_indices', 'duration', 'width', 'height', 'video_backend')
|
| 322 |
+
if key in info}
|
| 323 |
+
kwargs.update(do_sample_frames=False, video_metadata=[VideoMetadata(**video_metadata)])
|
| 324 |
+
video = self.video_processor(videos=[frames], return_tensors='pt', **kwargs)
|
| 325 |
+
grid = video['video_grid_thw'][0]
|
| 326 |
+
video_pixels.append(video['pixel_values_videos'])
|
| 327 |
+
video_grids.append(video['video_grid_thw'])
|
| 328 |
+
count, duration = 0, None
|
| 329 |
+
if kind == 'video_audio' or bundled_audio is not None:
|
| 330 |
+
try:
|
| 331 |
+
samples = decode_audio(route.get('audio', bundled_audio if bundled_audio is not None else source))
|
| 332 |
+
except (RuntimeError, ValueError) as exc:
|
| 333 |
+
if 'audio' not in str(exc).lower() or not any(word in str(exc).lower() for word in ('stream', 'best')):
|
| 334 |
+
raise
|
| 335 |
+
item_info['audio_fallback'] = 'no audio stream; video only'
|
| 336 |
+
else:
|
| 337 |
+
duration = len(samples) / 16000
|
| 338 |
+
feature = audio_features(samples, self.feature_extractor, pcm16=False)
|
| 339 |
+
count = len(feature) * tokens_per_segment(self.audio_config)
|
| 340 |
+
item_info['segments'] = len(feature)
|
| 341 |
+
ids, groups, times = video_ids(self.tokenizer, grid, info,
|
| 342 |
+
self.video_processor.temporal_patch_size, self.video_processor.merge_size,
|
| 343 |
+
count, duration, self.audio_config['second_per_window'])
|
| 344 |
+
blocks['video'].append(ids)
|
| 345 |
+
item_info.update(info, grid=grid.tolist(), size=kwargs['size'],
|
| 346 |
+
audio_tokens=count, audio_duration=duration, audio_groups=groups,
|
| 347 |
+
timestamps=times, sampled_frames=len(frames))
|
| 348 |
+
metadata.append(item_info)
|
| 349 |
+
block_kind = 'video' if kind == 'video_audio' else kind
|
| 350 |
+
block_features[block_kind].append(feature)
|
| 351 |
+
block_metadata[block_kind].append(item_info)
|
| 352 |
+
if blocks[block_kind][-1].count(self.tokenizer.convert_tokens_to_ids('<|audio_pad|>')) != item_info.get('audio_tokens', 0):
|
| 353 |
+
raise ValueError('Audio features and placeholders differ for one media item')
|
| 354 |
+
source_ids = self.tokenizer.encode(prompt, add_special_tokens=False)
|
| 355 |
+
patterns = {kind: self.tokenizer.encode(pattern, add_special_tokens=False)
|
| 356 |
+
for kind, pattern in (('image', IMAGE), ('video', VIDEO), ('audio', AUDIO))}
|
| 357 |
+
offsets = dict.fromkeys(patterns, 0)
|
| 358 |
+
ids, index, ordered_metadata = [], 0, []
|
| 359 |
+
while index < len(source_ids):
|
| 360 |
+
for kind, pattern in patterns.items():
|
| 361 |
+
if source_ids[index:index + len(pattern)] == pattern:
|
| 362 |
+
if offsets[kind] >= len(blocks[kind]):
|
| 363 |
+
raise ValueError(f'Extra {kind} placeholder in the question/prompt')
|
| 364 |
+
ids.extend(blocks[kind][offsets[kind]])
|
| 365 |
+
feature = block_features[kind][offsets[kind]]
|
| 366 |
+
if feature is not None:
|
| 367 |
+
features.append(feature)
|
| 368 |
+
ordered_metadata.append(block_metadata[kind][offsets[kind]])
|
| 369 |
+
offsets[kind] += 1
|
| 370 |
+
index += len(pattern)
|
| 371 |
+
break
|
| 372 |
+
else:
|
| 373 |
+
ids.append(source_ids[index])
|
| 374 |
+
index += 1
|
| 375 |
+
if any(offsets[kind] != len(blocks[kind]) for kind in blocks):
|
| 376 |
+
raise ValueError('Media items and prompt placeholders differ')
|
| 377 |
+
data = {'input_ids': torch.tensor([ids], dtype=torch.long),
|
| 378 |
+
'attention_mask': torch.ones(1, len(ids), dtype=torch.long)}
|
| 379 |
+
for pixels, grids, pkey, gkey in ((image_pixels, image_grids, 'pixel_values', 'image_grid_thw'),
|
| 380 |
+
(video_pixels, video_grids, 'pixel_values_videos', 'video_grid_thw')):
|
| 381 |
+
if pixels:
|
| 382 |
+
data[pkey], data[gkey] = torch.cat(pixels), torch.cat(grids)
|
| 383 |
+
if features:
|
| 384 |
+
data['audio_feature'] = torch.cat(features)
|
| 385 |
+
expected = sum(item.get('audio_tokens', 0) for item in metadata)
|
| 386 |
+
if ids.count(self.tokenizer.convert_tokens_to_ids('<|audio_pad|>')) != expected:
|
| 387 |
+
raise ValueError('Audio features and placeholder counts differ')
|
| 388 |
+
result = BatchFeature(data=data)
|
| 389 |
+
# These attributes are diagnostic metadata, never forwarded to generate.
|
| 390 |
+
result.media_metadata = ordered_metadata
|
| 391 |
+
result.prompt_text = prompt
|
| 392 |
+
return result
|
processor_config.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"processor_class": "WeMMProcessor",
|
| 3 |
+
"auto_map": {
|
| 4 |
+
"AutoProcessor": "processing_wemm.WeMMProcessor"
|
| 5 |
+
},
|
| 6 |
+
"wemm_defaults": {
|
| 7 |
+
"fps": 2.0,
|
| 8 |
+
"min_frames": 4,
|
| 9 |
+
"max_frames": 128,
|
| 10 |
+
"total_pixels": 25165824,
|
| 11 |
+
"min_pixels": 4096,
|
| 12 |
+
"system_prompt": "You are a helpful assistant.",
|
| 13 |
+
"timestamp_interval_sec": 1.0
|
| 14 |
+
},
|
| 15 |
+
"audio_config": {
|
| 16 |
+
"attn_implementation": "flash_attention_2",
|
| 17 |
+
"activation_dropout": 0.0,
|
| 18 |
+
"activation_function": "gelu",
|
| 19 |
+
"apply_spec_augment": false,
|
| 20 |
+
"attention_dropout": 0.0,
|
| 21 |
+
"bos_token_id": 50257,
|
| 22 |
+
"classifier_proj_size": 256,
|
| 23 |
+
"d_model": 1280,
|
| 24 |
+
"decoder_attention_heads": 20,
|
| 25 |
+
"decoder_ffn_dim": 5120,
|
| 26 |
+
"decoder_layerdrop": 0.0,
|
| 27 |
+
"decoder_layers": 32,
|
| 28 |
+
"decoder_start_token_id": 50258,
|
| 29 |
+
"dropout": 0.0,
|
| 30 |
+
"dtype": "bfloat16",
|
| 31 |
+
"encoder_attention_heads": 20,
|
| 32 |
+
"encoder_ffn_dim": 5120,
|
| 33 |
+
"encoder_layerdrop": 0.0,
|
| 34 |
+
"encoder_layers": 32,
|
| 35 |
+
"eos_token_id": 50257,
|
| 36 |
+
"init_std": 0.02,
|
| 37 |
+
"mask_feature_length": 10,
|
| 38 |
+
"mask_feature_min_masks": 0,
|
| 39 |
+
"mask_feature_prob": 0.0,
|
| 40 |
+
"mask_time_length": 10,
|
| 41 |
+
"mask_time_min_masks": 2,
|
| 42 |
+
"mask_time_prob": 0.05,
|
| 43 |
+
"max_source_positions": 1500,
|
| 44 |
+
"max_target_positions": 448,
|
| 45 |
+
"median_filter_width": 7,
|
| 46 |
+
"model_type": "whisper",
|
| 47 |
+
"num_hidden_layers": 32,
|
| 48 |
+
"num_mel_bins": 128,
|
| 49 |
+
"pad_token_id": 50256,
|
| 50 |
+
"qformer_config": {
|
| 51 |
+
"_name_or_path": "",
|
| 52 |
+
"add_cross_attention": true,
|
| 53 |
+
"architectures": null,
|
| 54 |
+
"attention_probs_dropout_prob": 0.1,
|
| 55 |
+
"chunk_size_feed_forward": 0,
|
| 56 |
+
"classifier_dropout": null,
|
| 57 |
+
"cross_attention_freq": 1,
|
| 58 |
+
"dtype": null,
|
| 59 |
+
"encoder_width": 1280,
|
| 60 |
+
"hidden_act": "gelu",
|
| 61 |
+
"hidden_dropout_prob": 0.1,
|
| 62 |
+
"hidden_size": 4104,
|
| 63 |
+
"id2label": {
|
| 64 |
+
"0": "LABEL_0",
|
| 65 |
+
"1": "LABEL_1"
|
| 66 |
+
},
|
| 67 |
+
"initializer_range": 0.02,
|
| 68 |
+
"intermediate_size": 12288,
|
| 69 |
+
"is_encoder_decoder": false,
|
| 70 |
+
"label2id": {
|
| 71 |
+
"LABEL_0": 0,
|
| 72 |
+
"LABEL_1": 1
|
| 73 |
+
},
|
| 74 |
+
"layer_norm_eps": 1e-12,
|
| 75 |
+
"max_position_embeddings": 512,
|
| 76 |
+
"model_type": "bert",
|
| 77 |
+
"num_attention_heads": 12,
|
| 78 |
+
"num_hidden_layers": 2,
|
| 79 |
+
"out_hidden_size": 2560,
|
| 80 |
+
"output_attentions": false,
|
| 81 |
+
"output_hidden_states": false,
|
| 82 |
+
"pad_token_id": 0,
|
| 83 |
+
"position_embedding_type": "absolute",
|
| 84 |
+
"problem_type": null,
|
| 85 |
+
"query_length": 1,
|
| 86 |
+
"return_dict": true,
|
| 87 |
+
"type_vocab_size": 2,
|
| 88 |
+
"use_cache": true,
|
| 89 |
+
"vocab_size": 30522
|
| 90 |
+
},
|
| 91 |
+
"scale_embedding": false,
|
| 92 |
+
"second_per_window": 0.1,
|
| 93 |
+
"second_stride": 0.1,
|
| 94 |
+
"tie_word_embeddings": true,
|
| 95 |
+
"use_cache": true,
|
| 96 |
+
"use_weighted_layer_sum": false,
|
| 97 |
+
"vocab_size": 51866
|
| 98 |
+
}
|
| 99 |
+
}
|
quantization_manifest.json
ADDED
|
@@ -0,0 +1,1121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"status": "quantized_and_independently_reloaded_native_inference_pending",
|
| 3 |
+
"algorithm": "Transformers 5.5.3 Fp8Quantize.convert",
|
| 4 |
+
"converter_sha256": "9baa1fdc55581355dabaf10d68ddafcd53983fe8736737c991c2ea78b03a3d9f",
|
| 5 |
+
"source": "tencent/WeMM-Video-4B",
|
| 6 |
+
"source_files": [
|
| 7 |
+
{
|
| 8 |
+
"path": "tencent/WeMM-Video-4B/model-00001-of-00003.safetensors",
|
| 9 |
+
"bytes": 4306667392,
|
| 10 |
+
"sha256": "43adb5f51324177c3c40661982f5729b2c927b8c2f3eba9352ece3e0d5b2e2fd"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"path": "tencent/WeMM-Video-4B/model-00002-of-00003.safetensors",
|
| 14 |
+
"bytes": 4331122608,
|
| 15 |
+
"sha256": "c271269cd9ad157ace651e2f6ee2f28c8ee80c52324f8979ddb138ba653f069c"
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"path": "tencent/WeMM-Video-4B/model-00003-of-00003.safetensors",
|
| 19 |
+
"bytes": 2585872480,
|
| 20 |
+
"sha256": "b9ecafb62c8c758242c926830ed628ef685c42e0be6b779c05d1eff2da1fdfd9"
|
| 21 |
+
}
|
| 22 |
+
],
|
| 23 |
+
"source_config_sha256": "5eca5c5955cdc4ec20ddb433053130c690304a0a26c2dcd031daef032b7235a4",
|
| 24 |
+
"official_repo": "Qwen/Qwen3.5-35B-A3B-FP8",
|
| 25 |
+
"official_revision": "9d1823d2dee688a6b25e77009dc727688c44936e",
|
| 26 |
+
"recipe_sha256": "1fa272f54cc586827ffa0e6d0ce14805d298adab4c9bd78663967bef155efda7",
|
| 27 |
+
"files": {
|
| 28 |
+
"wemm-video-capabilities-compact.png": {
|
| 29 |
+
"bytes": 2718998,
|
| 30 |
+
"sha256": "57d892abb395c639078b49ecf317698f038303adf1fc976ddf13ff9e9273c77f"
|
| 31 |
+
},
|
| 32 |
+
"wemm-video-architecture.png": {
|
| 33 |
+
"bytes": 116917,
|
| 34 |
+
"sha256": "9902c081a70abeaacf34c898c86c44587eebe0fd62f1923225d1726766eb0a7a"
|
| 35 |
+
},
|
| 36 |
+
"chat_template.jinja": {
|
| 37 |
+
"bytes": 7755,
|
| 38 |
+
"sha256": "273d8e0e683b885071fb17e08d71e5f2a5ddfb5309756181681de4f5a1822d80"
|
| 39 |
+
},
|
| 40 |
+
"config.json": {
|
| 41 |
+
"bytes": 50625,
|
| 42 |
+
"sha256": "77201ba25b2b6655411d8a5df5c03b51d730d140f89f82c826e11e5105ee027e"
|
| 43 |
+
},
|
| 44 |
+
"configuration_wemm.py": {
|
| 45 |
+
"bytes": 37064,
|
| 46 |
+
"sha256": "43ee3ec8477c6677f06835a893a146d18024aea0145086ceca3b6039e2d91887"
|
| 47 |
+
},
|
| 48 |
+
"generation_config.json": {
|
| 49 |
+
"bytes": 138,
|
| 50 |
+
"sha256": "b91f22ecb30192b6919660eb61c01d7602f93ff6764556b1991c71fbe9ca82e6"
|
| 51 |
+
},
|
| 52 |
+
"h5_modeling_bert.py": {
|
| 53 |
+
"bytes": 50024,
|
| 54 |
+
"sha256": "b2eac797422294be10295c27f5709c8fda362c55d6f476dcebfd5f38aa65c6dd"
|
| 55 |
+
},
|
| 56 |
+
"h5_modeling_whisper.py": {
|
| 57 |
+
"bytes": 69582,
|
| 58 |
+
"sha256": "b507884daee13857c17d2d97290183e71a5a1044253a49c5a9cb109ba3332907"
|
| 59 |
+
},
|
| 60 |
+
"model.safetensors": {
|
| 61 |
+
"bytes": 7659403688,
|
| 62 |
+
"sha256": "bd5ed7eaf0682ee781175a249c9f86b9366d0d31980f72409ec6b7d939486ef4"
|
| 63 |
+
},
|
| 64 |
+
"modeling_wemm.py": {
|
| 65 |
+
"bytes": 103798,
|
| 66 |
+
"sha256": "30c9e34d16f4b3720410c47034b2b807a3686c88f4558d5aab6c102fc1db0bde"
|
| 67 |
+
},
|
| 68 |
+
"official_qwen35_fp8_config.json": {
|
| 69 |
+
"bytes": 19172,
|
| 70 |
+
"sha256": "cc35eadc02b2a69542c59233f5d80cd89029234711ac11811afc46d57701f7b9"
|
| 71 |
+
},
|
| 72 |
+
"preprocessor_config.json": {
|
| 73 |
+
"bytes": 390,
|
| 74 |
+
"sha256": "27225450ac9c6529872ee1924fcb0962ff5634834f817040f444118116f4e516"
|
| 75 |
+
},
|
| 76 |
+
"processing_wemm.py": {
|
| 77 |
+
"bytes": 24880,
|
| 78 |
+
"sha256": "8f907439e011c47293a851e28efec1501c36b862ba8c04784d23a0a4a5aa36a8"
|
| 79 |
+
},
|
| 80 |
+
"processor_config.json": {
|
| 81 |
+
"bytes": 2734,
|
| 82 |
+
"sha256": "7067f0990504250c037bc718650754575b9002133b247d510ca86bf475b30d29"
|
| 83 |
+
},
|
| 84 |
+
"tokenizer.json": {
|
| 85 |
+
"bytes": 19989343,
|
| 86 |
+
"sha256": "510fd6ff51823f6b1c820595b5eed750b8ff0ee85961d2f330623b3cf5ff4019"
|
| 87 |
+
},
|
| 88 |
+
"tokenizer_config.json": {
|
| 89 |
+
"bytes": 1098,
|
| 90 |
+
"sha256": "83febe739ecefd99f984f546dfdc10149cedf293b9ee0291b99894341188b613"
|
| 91 |
+
},
|
| 92 |
+
"video_preprocessor_config.json": {
|
| 93 |
+
"bytes": 385,
|
| 94 |
+
"sha256": "7768af27c1fafa9cc9011c1dc20067e03f8915e03b63504550e11d5066986d13"
|
| 95 |
+
},
|
| 96 |
+
"wemm_media.py": {
|
| 97 |
+
"bytes": 11378,
|
| 98 |
+
"sha256": "2e4b427e3ddabc526f7984066a982bfa7c0a4d56f3d7c979fc41651463461122"
|
| 99 |
+
},
|
| 100 |
+
"wemm_video_policy.py": {
|
| 101 |
+
"bytes": 5670,
|
| 102 |
+
"sha256": "5a08358f04b011c401d6355cf396caebae4536442df76ae17dc89470c2b1a50e"
|
| 103 |
+
},
|
| 104 |
+
"wemm_zip.py": {
|
| 105 |
+
"bytes": 12156,
|
| 106 |
+
"sha256": "016d7a2bc9b50cf2bed2e901d7ec445260eff890751e94683c8fac0be09eecdb"
|
| 107 |
+
},
|
| 108 |
+
"wemm_zip_policy.py": {
|
| 109 |
+
"bytes": 1625,
|
| 110 |
+
"sha256": "f4029f5015cf6342da1bfacaa6b4847d7f20ca450019ff7bc5f4ad899e3706c8"
|
| 111 |
+
},
|
| 112 |
+
"README.md": {
|
| 113 |
+
"bytes": 7225,
|
| 114 |
+
"sha256": "686e4bb65bf86505b4d73fbca98ba374c2afb8aa448359eea7325290fd71d150"
|
| 115 |
+
},
|
| 116 |
+
"LICENSE": {
|
| 117 |
+
"bytes": 25380,
|
| 118 |
+
"sha256": "bac4d42ddebadb11e405fc4de2335579e67676362ac870108012ab4899ef1e5b"
|
| 119 |
+
}
|
| 120 |
+
},
|
| 121 |
+
"weights": "E4M3FN,128x128 blocks,FP32 weight_scale_inv",
|
| 122 |
+
"activations": "dynamic,per-token groups128",
|
| 123 |
+
"quantization_config": {
|
| 124 |
+
"quant_method": "fp8",
|
| 125 |
+
"activation_scheme": "dynamic",
|
| 126 |
+
"weight_per_tensor": false,
|
| 127 |
+
"act_per_tensor": false,
|
| 128 |
+
"weight_block_size": [
|
| 129 |
+
128,
|
| 130 |
+
128
|
| 131 |
+
],
|
| 132 |
+
"modules_to_not_convert": [
|
| 133 |
+
"lm_head",
|
| 134 |
+
"model.audio",
|
| 135 |
+
"model.audio.audio_proj",
|
| 136 |
+
"model.audio.audio_proj.bias",
|
| 137 |
+
"model.audio.conv1",
|
| 138 |
+
"model.audio.conv1.bias",
|
| 139 |
+
"model.audio.conv2",
|
| 140 |
+
"model.audio.conv2.bias",
|
| 141 |
+
"model.audio.embed_positions",
|
| 142 |
+
"model.audio.layer_norm",
|
| 143 |
+
"model.audio.layer_norm.bias",
|
| 144 |
+
"model.audio.layers.0.fc1",
|
| 145 |
+
"model.audio.layers.0.fc1.bias",
|
| 146 |
+
"model.audio.layers.0.fc2",
|
| 147 |
+
"model.audio.layers.0.fc2.bias",
|
| 148 |
+
"model.audio.layers.0.final_layer_norm",
|
| 149 |
+
"model.audio.layers.0.final_layer_norm.bias",
|
| 150 |
+
"model.audio.layers.0.self_attn.k_proj",
|
| 151 |
+
"model.audio.layers.0.self_attn.out_proj",
|
| 152 |
+
"model.audio.layers.0.self_attn.out_proj.bias",
|
| 153 |
+
"model.audio.layers.0.self_attn.q_proj",
|
| 154 |
+
"model.audio.layers.0.self_attn.q_proj.bias",
|
| 155 |
+
"model.audio.layers.0.self_attn.v_proj",
|
| 156 |
+
"model.audio.layers.0.self_attn.v_proj.bias",
|
| 157 |
+
"model.audio.layers.0.self_attn_layer_norm",
|
| 158 |
+
"model.audio.layers.0.self_attn_layer_norm.bias",
|
| 159 |
+
"model.audio.layers.1.fc1",
|
| 160 |
+
"model.audio.layers.1.fc1.bias",
|
| 161 |
+
"model.audio.layers.1.fc2",
|
| 162 |
+
"model.audio.layers.1.fc2.bias",
|
| 163 |
+
"model.audio.layers.1.final_layer_norm",
|
| 164 |
+
"model.audio.layers.1.final_layer_norm.bias",
|
| 165 |
+
"model.audio.layers.1.self_attn.k_proj",
|
| 166 |
+
"model.audio.layers.1.self_attn.out_proj",
|
| 167 |
+
"model.audio.layers.1.self_attn.out_proj.bias",
|
| 168 |
+
"model.audio.layers.1.self_attn.q_proj",
|
| 169 |
+
"model.audio.layers.1.self_attn.q_proj.bias",
|
| 170 |
+
"model.audio.layers.1.self_attn.v_proj",
|
| 171 |
+
"model.audio.layers.1.self_attn.v_proj.bias",
|
| 172 |
+
"model.audio.layers.1.self_attn_layer_norm",
|
| 173 |
+
"model.audio.layers.1.self_attn_layer_norm.bias",
|
| 174 |
+
"model.audio.layers.10.fc1",
|
| 175 |
+
"model.audio.layers.10.fc1.bias",
|
| 176 |
+
"model.audio.layers.10.fc2",
|
| 177 |
+
"model.audio.layers.10.fc2.bias",
|
| 178 |
+
"model.audio.layers.10.final_layer_norm",
|
| 179 |
+
"model.audio.layers.10.final_layer_norm.bias",
|
| 180 |
+
"model.audio.layers.10.self_attn.k_proj",
|
| 181 |
+
"model.audio.layers.10.self_attn.out_proj",
|
| 182 |
+
"model.audio.layers.10.self_attn.out_proj.bias",
|
| 183 |
+
"model.audio.layers.10.self_attn.q_proj",
|
| 184 |
+
"model.audio.layers.10.self_attn.q_proj.bias",
|
| 185 |
+
"model.audio.layers.10.self_attn.v_proj",
|
| 186 |
+
"model.audio.layers.10.self_attn.v_proj.bias",
|
| 187 |
+
"model.audio.layers.10.self_attn_layer_norm",
|
| 188 |
+
"model.audio.layers.10.self_attn_layer_norm.bias",
|
| 189 |
+
"model.audio.layers.11.fc1",
|
| 190 |
+
"model.audio.layers.11.fc1.bias",
|
| 191 |
+
"model.audio.layers.11.fc2",
|
| 192 |
+
"model.audio.layers.11.fc2.bias",
|
| 193 |
+
"model.audio.layers.11.final_layer_norm",
|
| 194 |
+
"model.audio.layers.11.final_layer_norm.bias",
|
| 195 |
+
"model.audio.layers.11.self_attn.k_proj",
|
| 196 |
+
"model.audio.layers.11.self_attn.out_proj",
|
| 197 |
+
"model.audio.layers.11.self_attn.out_proj.bias",
|
| 198 |
+
"model.audio.layers.11.self_attn.q_proj",
|
| 199 |
+
"model.audio.layers.11.self_attn.q_proj.bias",
|
| 200 |
+
"model.audio.layers.11.self_attn.v_proj",
|
| 201 |
+
"model.audio.layers.11.self_attn.v_proj.bias",
|
| 202 |
+
"model.audio.layers.11.self_attn_layer_norm",
|
| 203 |
+
"model.audio.layers.11.self_attn_layer_norm.bias",
|
| 204 |
+
"model.audio.layers.12.fc1",
|
| 205 |
+
"model.audio.layers.12.fc1.bias",
|
| 206 |
+
"model.audio.layers.12.fc2",
|
| 207 |
+
"model.audio.layers.12.fc2.bias",
|
| 208 |
+
"model.audio.layers.12.final_layer_norm",
|
| 209 |
+
"model.audio.layers.12.final_layer_norm.bias",
|
| 210 |
+
"model.audio.layers.12.self_attn.k_proj",
|
| 211 |
+
"model.audio.layers.12.self_attn.out_proj",
|
| 212 |
+
"model.audio.layers.12.self_attn.out_proj.bias",
|
| 213 |
+
"model.audio.layers.12.self_attn.q_proj",
|
| 214 |
+
"model.audio.layers.12.self_attn.q_proj.bias",
|
| 215 |
+
"model.audio.layers.12.self_attn.v_proj",
|
| 216 |
+
"model.audio.layers.12.self_attn.v_proj.bias",
|
| 217 |
+
"model.audio.layers.12.self_attn_layer_norm",
|
| 218 |
+
"model.audio.layers.12.self_attn_layer_norm.bias",
|
| 219 |
+
"model.audio.layers.13.fc1",
|
| 220 |
+
"model.audio.layers.13.fc1.bias",
|
| 221 |
+
"model.audio.layers.13.fc2",
|
| 222 |
+
"model.audio.layers.13.fc2.bias",
|
| 223 |
+
"model.audio.layers.13.final_layer_norm",
|
| 224 |
+
"model.audio.layers.13.final_layer_norm.bias",
|
| 225 |
+
"model.audio.layers.13.self_attn.k_proj",
|
| 226 |
+
"model.audio.layers.13.self_attn.out_proj",
|
| 227 |
+
"model.audio.layers.13.self_attn.out_proj.bias",
|
| 228 |
+
"model.audio.layers.13.self_attn.q_proj",
|
| 229 |
+
"model.audio.layers.13.self_attn.q_proj.bias",
|
| 230 |
+
"model.audio.layers.13.self_attn.v_proj",
|
| 231 |
+
"model.audio.layers.13.self_attn.v_proj.bias",
|
| 232 |
+
"model.audio.layers.13.self_attn_layer_norm",
|
| 233 |
+
"model.audio.layers.13.self_attn_layer_norm.bias",
|
| 234 |
+
"model.audio.layers.14.fc1",
|
| 235 |
+
"model.audio.layers.14.fc1.bias",
|
| 236 |
+
"model.audio.layers.14.fc2",
|
| 237 |
+
"model.audio.layers.14.fc2.bias",
|
| 238 |
+
"model.audio.layers.14.final_layer_norm",
|
| 239 |
+
"model.audio.layers.14.final_layer_norm.bias",
|
| 240 |
+
"model.audio.layers.14.self_attn.k_proj",
|
| 241 |
+
"model.audio.layers.14.self_attn.out_proj",
|
| 242 |
+
"model.audio.layers.14.self_attn.out_proj.bias",
|
| 243 |
+
"model.audio.layers.14.self_attn.q_proj",
|
| 244 |
+
"model.audio.layers.14.self_attn.q_proj.bias",
|
| 245 |
+
"model.audio.layers.14.self_attn.v_proj",
|
| 246 |
+
"model.audio.layers.14.self_attn.v_proj.bias",
|
| 247 |
+
"model.audio.layers.14.self_attn_layer_norm",
|
| 248 |
+
"model.audio.layers.14.self_attn_layer_norm.bias",
|
| 249 |
+
"model.audio.layers.15.fc1",
|
| 250 |
+
"model.audio.layers.15.fc1.bias",
|
| 251 |
+
"model.audio.layers.15.fc2",
|
| 252 |
+
"model.audio.layers.15.fc2.bias",
|
| 253 |
+
"model.audio.layers.15.final_layer_norm",
|
| 254 |
+
"model.audio.layers.15.final_layer_norm.bias",
|
| 255 |
+
"model.audio.layers.15.self_attn.k_proj",
|
| 256 |
+
"model.audio.layers.15.self_attn.out_proj",
|
| 257 |
+
"model.audio.layers.15.self_attn.out_proj.bias",
|
| 258 |
+
"model.audio.layers.15.self_attn.q_proj",
|
| 259 |
+
"model.audio.layers.15.self_attn.q_proj.bias",
|
| 260 |
+
"model.audio.layers.15.self_attn.v_proj",
|
| 261 |
+
"model.audio.layers.15.self_attn.v_proj.bias",
|
| 262 |
+
"model.audio.layers.15.self_attn_layer_norm",
|
| 263 |
+
"model.audio.layers.15.self_attn_layer_norm.bias",
|
| 264 |
+
"model.audio.layers.16.fc1",
|
| 265 |
+
"model.audio.layers.16.fc1.bias",
|
| 266 |
+
"model.audio.layers.16.fc2",
|
| 267 |
+
"model.audio.layers.16.fc2.bias",
|
| 268 |
+
"model.audio.layers.16.final_layer_norm",
|
| 269 |
+
"model.audio.layers.16.final_layer_norm.bias",
|
| 270 |
+
"model.audio.layers.16.self_attn.k_proj",
|
| 271 |
+
"model.audio.layers.16.self_attn.out_proj",
|
| 272 |
+
"model.audio.layers.16.self_attn.out_proj.bias",
|
| 273 |
+
"model.audio.layers.16.self_attn.q_proj",
|
| 274 |
+
"model.audio.layers.16.self_attn.q_proj.bias",
|
| 275 |
+
"model.audio.layers.16.self_attn.v_proj",
|
| 276 |
+
"model.audio.layers.16.self_attn.v_proj.bias",
|
| 277 |
+
"model.audio.layers.16.self_attn_layer_norm",
|
| 278 |
+
"model.audio.layers.16.self_attn_layer_norm.bias",
|
| 279 |
+
"model.audio.layers.17.fc1",
|
| 280 |
+
"model.audio.layers.17.fc1.bias",
|
| 281 |
+
"model.audio.layers.17.fc2",
|
| 282 |
+
"model.audio.layers.17.fc2.bias",
|
| 283 |
+
"model.audio.layers.17.final_layer_norm",
|
| 284 |
+
"model.audio.layers.17.final_layer_norm.bias",
|
| 285 |
+
"model.audio.layers.17.self_attn.k_proj",
|
| 286 |
+
"model.audio.layers.17.self_attn.out_proj",
|
| 287 |
+
"model.audio.layers.17.self_attn.out_proj.bias",
|
| 288 |
+
"model.audio.layers.17.self_attn.q_proj",
|
| 289 |
+
"model.audio.layers.17.self_attn.q_proj.bias",
|
| 290 |
+
"model.audio.layers.17.self_attn.v_proj",
|
| 291 |
+
"model.audio.layers.17.self_attn.v_proj.bias",
|
| 292 |
+
"model.audio.layers.17.self_attn_layer_norm",
|
| 293 |
+
"model.audio.layers.17.self_attn_layer_norm.bias",
|
| 294 |
+
"model.audio.layers.18.fc1",
|
| 295 |
+
"model.audio.layers.18.fc1.bias",
|
| 296 |
+
"model.audio.layers.18.fc2",
|
| 297 |
+
"model.audio.layers.18.fc2.bias",
|
| 298 |
+
"model.audio.layers.18.final_layer_norm",
|
| 299 |
+
"model.audio.layers.18.final_layer_norm.bias",
|
| 300 |
+
"model.audio.layers.18.self_attn.k_proj",
|
| 301 |
+
"model.audio.layers.18.self_attn.out_proj",
|
| 302 |
+
"model.audio.layers.18.self_attn.out_proj.bias",
|
| 303 |
+
"model.audio.layers.18.self_attn.q_proj",
|
| 304 |
+
"model.audio.layers.18.self_attn.q_proj.bias",
|
| 305 |
+
"model.audio.layers.18.self_attn.v_proj",
|
| 306 |
+
"model.audio.layers.18.self_attn.v_proj.bias",
|
| 307 |
+
"model.audio.layers.18.self_attn_layer_norm",
|
| 308 |
+
"model.audio.layers.18.self_attn_layer_norm.bias",
|
| 309 |
+
"model.audio.layers.19.fc1",
|
| 310 |
+
"model.audio.layers.19.fc1.bias",
|
| 311 |
+
"model.audio.layers.19.fc2",
|
| 312 |
+
"model.audio.layers.19.fc2.bias",
|
| 313 |
+
"model.audio.layers.19.final_layer_norm",
|
| 314 |
+
"model.audio.layers.19.final_layer_norm.bias",
|
| 315 |
+
"model.audio.layers.19.self_attn.k_proj",
|
| 316 |
+
"model.audio.layers.19.self_attn.out_proj",
|
| 317 |
+
"model.audio.layers.19.self_attn.out_proj.bias",
|
| 318 |
+
"model.audio.layers.19.self_attn.q_proj",
|
| 319 |
+
"model.audio.layers.19.self_attn.q_proj.bias",
|
| 320 |
+
"model.audio.layers.19.self_attn.v_proj",
|
| 321 |
+
"model.audio.layers.19.self_attn.v_proj.bias",
|
| 322 |
+
"model.audio.layers.19.self_attn_layer_norm",
|
| 323 |
+
"model.audio.layers.19.self_attn_layer_norm.bias",
|
| 324 |
+
"model.audio.layers.2.fc1",
|
| 325 |
+
"model.audio.layers.2.fc1.bias",
|
| 326 |
+
"model.audio.layers.2.fc2",
|
| 327 |
+
"model.audio.layers.2.fc2.bias",
|
| 328 |
+
"model.audio.layers.2.final_layer_norm",
|
| 329 |
+
"model.audio.layers.2.final_layer_norm.bias",
|
| 330 |
+
"model.audio.layers.2.self_attn.k_proj",
|
| 331 |
+
"model.audio.layers.2.self_attn.out_proj",
|
| 332 |
+
"model.audio.layers.2.self_attn.out_proj.bias",
|
| 333 |
+
"model.audio.layers.2.self_attn.q_proj",
|
| 334 |
+
"model.audio.layers.2.self_attn.q_proj.bias",
|
| 335 |
+
"model.audio.layers.2.self_attn.v_proj",
|
| 336 |
+
"model.audio.layers.2.self_attn.v_proj.bias",
|
| 337 |
+
"model.audio.layers.2.self_attn_layer_norm",
|
| 338 |
+
"model.audio.layers.2.self_attn_layer_norm.bias",
|
| 339 |
+
"model.audio.layers.20.fc1",
|
| 340 |
+
"model.audio.layers.20.fc1.bias",
|
| 341 |
+
"model.audio.layers.20.fc2",
|
| 342 |
+
"model.audio.layers.20.fc2.bias",
|
| 343 |
+
"model.audio.layers.20.final_layer_norm",
|
| 344 |
+
"model.audio.layers.20.final_layer_norm.bias",
|
| 345 |
+
"model.audio.layers.20.self_attn.k_proj",
|
| 346 |
+
"model.audio.layers.20.self_attn.out_proj",
|
| 347 |
+
"model.audio.layers.20.self_attn.out_proj.bias",
|
| 348 |
+
"model.audio.layers.20.self_attn.q_proj",
|
| 349 |
+
"model.audio.layers.20.self_attn.q_proj.bias",
|
| 350 |
+
"model.audio.layers.20.self_attn.v_proj",
|
| 351 |
+
"model.audio.layers.20.self_attn.v_proj.bias",
|
| 352 |
+
"model.audio.layers.20.self_attn_layer_norm",
|
| 353 |
+
"model.audio.layers.20.self_attn_layer_norm.bias",
|
| 354 |
+
"model.audio.layers.21.fc1",
|
| 355 |
+
"model.audio.layers.21.fc1.bias",
|
| 356 |
+
"model.audio.layers.21.fc2",
|
| 357 |
+
"model.audio.layers.21.fc2.bias",
|
| 358 |
+
"model.audio.layers.21.final_layer_norm",
|
| 359 |
+
"model.audio.layers.21.final_layer_norm.bias",
|
| 360 |
+
"model.audio.layers.21.self_attn.k_proj",
|
| 361 |
+
"model.audio.layers.21.self_attn.out_proj",
|
| 362 |
+
"model.audio.layers.21.self_attn.out_proj.bias",
|
| 363 |
+
"model.audio.layers.21.self_attn.q_proj",
|
| 364 |
+
"model.audio.layers.21.self_attn.q_proj.bias",
|
| 365 |
+
"model.audio.layers.21.self_attn.v_proj",
|
| 366 |
+
"model.audio.layers.21.self_attn.v_proj.bias",
|
| 367 |
+
"model.audio.layers.21.self_attn_layer_norm",
|
| 368 |
+
"model.audio.layers.21.self_attn_layer_norm.bias",
|
| 369 |
+
"model.audio.layers.22.fc1",
|
| 370 |
+
"model.audio.layers.22.fc1.bias",
|
| 371 |
+
"model.audio.layers.22.fc2",
|
| 372 |
+
"model.audio.layers.22.fc2.bias",
|
| 373 |
+
"model.audio.layers.22.final_layer_norm",
|
| 374 |
+
"model.audio.layers.22.final_layer_norm.bias",
|
| 375 |
+
"model.audio.layers.22.self_attn.k_proj",
|
| 376 |
+
"model.audio.layers.22.self_attn.out_proj",
|
| 377 |
+
"model.audio.layers.22.self_attn.out_proj.bias",
|
| 378 |
+
"model.audio.layers.22.self_attn.q_proj",
|
| 379 |
+
"model.audio.layers.22.self_attn.q_proj.bias",
|
| 380 |
+
"model.audio.layers.22.self_attn.v_proj",
|
| 381 |
+
"model.audio.layers.22.self_attn.v_proj.bias",
|
| 382 |
+
"model.audio.layers.22.self_attn_layer_norm",
|
| 383 |
+
"model.audio.layers.22.self_attn_layer_norm.bias",
|
| 384 |
+
"model.audio.layers.23.fc1",
|
| 385 |
+
"model.audio.layers.23.fc1.bias",
|
| 386 |
+
"model.audio.layers.23.fc2",
|
| 387 |
+
"model.audio.layers.23.fc2.bias",
|
| 388 |
+
"model.audio.layers.23.final_layer_norm",
|
| 389 |
+
"model.audio.layers.23.final_layer_norm.bias",
|
| 390 |
+
"model.audio.layers.23.self_attn.k_proj",
|
| 391 |
+
"model.audio.layers.23.self_attn.out_proj",
|
| 392 |
+
"model.audio.layers.23.self_attn.out_proj.bias",
|
| 393 |
+
"model.audio.layers.23.self_attn.q_proj",
|
| 394 |
+
"model.audio.layers.23.self_attn.q_proj.bias",
|
| 395 |
+
"model.audio.layers.23.self_attn.v_proj",
|
| 396 |
+
"model.audio.layers.23.self_attn.v_proj.bias",
|
| 397 |
+
"model.audio.layers.23.self_attn_layer_norm",
|
| 398 |
+
"model.audio.layers.23.self_attn_layer_norm.bias",
|
| 399 |
+
"model.audio.layers.24.fc1",
|
| 400 |
+
"model.audio.layers.24.fc1.bias",
|
| 401 |
+
"model.audio.layers.24.fc2",
|
| 402 |
+
"model.audio.layers.24.fc2.bias",
|
| 403 |
+
"model.audio.layers.24.final_layer_norm",
|
| 404 |
+
"model.audio.layers.24.final_layer_norm.bias",
|
| 405 |
+
"model.audio.layers.24.self_attn.k_proj",
|
| 406 |
+
"model.audio.layers.24.self_attn.out_proj",
|
| 407 |
+
"model.audio.layers.24.self_attn.out_proj.bias",
|
| 408 |
+
"model.audio.layers.24.self_attn.q_proj",
|
| 409 |
+
"model.audio.layers.24.self_attn.q_proj.bias",
|
| 410 |
+
"model.audio.layers.24.self_attn.v_proj",
|
| 411 |
+
"model.audio.layers.24.self_attn.v_proj.bias",
|
| 412 |
+
"model.audio.layers.24.self_attn_layer_norm",
|
| 413 |
+
"model.audio.layers.24.self_attn_layer_norm.bias",
|
| 414 |
+
"model.audio.layers.25.fc1",
|
| 415 |
+
"model.audio.layers.25.fc1.bias",
|
| 416 |
+
"model.audio.layers.25.fc2",
|
| 417 |
+
"model.audio.layers.25.fc2.bias",
|
| 418 |
+
"model.audio.layers.25.final_layer_norm",
|
| 419 |
+
"model.audio.layers.25.final_layer_norm.bias",
|
| 420 |
+
"model.audio.layers.25.self_attn.k_proj",
|
| 421 |
+
"model.audio.layers.25.self_attn.out_proj",
|
| 422 |
+
"model.audio.layers.25.self_attn.out_proj.bias",
|
| 423 |
+
"model.audio.layers.25.self_attn.q_proj",
|
| 424 |
+
"model.audio.layers.25.self_attn.q_proj.bias",
|
| 425 |
+
"model.audio.layers.25.self_attn.v_proj",
|
| 426 |
+
"model.audio.layers.25.self_attn.v_proj.bias",
|
| 427 |
+
"model.audio.layers.25.self_attn_layer_norm",
|
| 428 |
+
"model.audio.layers.25.self_attn_layer_norm.bias",
|
| 429 |
+
"model.audio.layers.26.fc1",
|
| 430 |
+
"model.audio.layers.26.fc1.bias",
|
| 431 |
+
"model.audio.layers.26.fc2",
|
| 432 |
+
"model.audio.layers.26.fc2.bias",
|
| 433 |
+
"model.audio.layers.26.final_layer_norm",
|
| 434 |
+
"model.audio.layers.26.final_layer_norm.bias",
|
| 435 |
+
"model.audio.layers.26.self_attn.k_proj",
|
| 436 |
+
"model.audio.layers.26.self_attn.out_proj",
|
| 437 |
+
"model.audio.layers.26.self_attn.out_proj.bias",
|
| 438 |
+
"model.audio.layers.26.self_attn.q_proj",
|
| 439 |
+
"model.audio.layers.26.self_attn.q_proj.bias",
|
| 440 |
+
"model.audio.layers.26.self_attn.v_proj",
|
| 441 |
+
"model.audio.layers.26.self_attn.v_proj.bias",
|
| 442 |
+
"model.audio.layers.26.self_attn_layer_norm",
|
| 443 |
+
"model.audio.layers.26.self_attn_layer_norm.bias",
|
| 444 |
+
"model.audio.layers.27.fc1",
|
| 445 |
+
"model.audio.layers.27.fc1.bias",
|
| 446 |
+
"model.audio.layers.27.fc2",
|
| 447 |
+
"model.audio.layers.27.fc2.bias",
|
| 448 |
+
"model.audio.layers.27.final_layer_norm",
|
| 449 |
+
"model.audio.layers.27.final_layer_norm.bias",
|
| 450 |
+
"model.audio.layers.27.self_attn.k_proj",
|
| 451 |
+
"model.audio.layers.27.self_attn.out_proj",
|
| 452 |
+
"model.audio.layers.27.self_attn.out_proj.bias",
|
| 453 |
+
"model.audio.layers.27.self_attn.q_proj",
|
| 454 |
+
"model.audio.layers.27.self_attn.q_proj.bias",
|
| 455 |
+
"model.audio.layers.27.self_attn.v_proj",
|
| 456 |
+
"model.audio.layers.27.self_attn.v_proj.bias",
|
| 457 |
+
"model.audio.layers.27.self_attn_layer_norm",
|
| 458 |
+
"model.audio.layers.27.self_attn_layer_norm.bias",
|
| 459 |
+
"model.audio.layers.28.fc1",
|
| 460 |
+
"model.audio.layers.28.fc1.bias",
|
| 461 |
+
"model.audio.layers.28.fc2",
|
| 462 |
+
"model.audio.layers.28.fc2.bias",
|
| 463 |
+
"model.audio.layers.28.final_layer_norm",
|
| 464 |
+
"model.audio.layers.28.final_layer_norm.bias",
|
| 465 |
+
"model.audio.layers.28.self_attn.k_proj",
|
| 466 |
+
"model.audio.layers.28.self_attn.out_proj",
|
| 467 |
+
"model.audio.layers.28.self_attn.out_proj.bias",
|
| 468 |
+
"model.audio.layers.28.self_attn.q_proj",
|
| 469 |
+
"model.audio.layers.28.self_attn.q_proj.bias",
|
| 470 |
+
"model.audio.layers.28.self_attn.v_proj",
|
| 471 |
+
"model.audio.layers.28.self_attn.v_proj.bias",
|
| 472 |
+
"model.audio.layers.28.self_attn_layer_norm",
|
| 473 |
+
"model.audio.layers.28.self_attn_layer_norm.bias",
|
| 474 |
+
"model.audio.layers.29.fc1",
|
| 475 |
+
"model.audio.layers.29.fc1.bias",
|
| 476 |
+
"model.audio.layers.29.fc2",
|
| 477 |
+
"model.audio.layers.29.fc2.bias",
|
| 478 |
+
"model.audio.layers.29.final_layer_norm",
|
| 479 |
+
"model.audio.layers.29.final_layer_norm.bias",
|
| 480 |
+
"model.audio.layers.29.self_attn.k_proj",
|
| 481 |
+
"model.audio.layers.29.self_attn.out_proj",
|
| 482 |
+
"model.audio.layers.29.self_attn.out_proj.bias",
|
| 483 |
+
"model.audio.layers.29.self_attn.q_proj",
|
| 484 |
+
"model.audio.layers.29.self_attn.q_proj.bias",
|
| 485 |
+
"model.audio.layers.29.self_attn.v_proj",
|
| 486 |
+
"model.audio.layers.29.self_attn.v_proj.bias",
|
| 487 |
+
"model.audio.layers.29.self_attn_layer_norm",
|
| 488 |
+
"model.audio.layers.29.self_attn_layer_norm.bias",
|
| 489 |
+
"model.audio.layers.3.fc1",
|
| 490 |
+
"model.audio.layers.3.fc1.bias",
|
| 491 |
+
"model.audio.layers.3.fc2",
|
| 492 |
+
"model.audio.layers.3.fc2.bias",
|
| 493 |
+
"model.audio.layers.3.final_layer_norm",
|
| 494 |
+
"model.audio.layers.3.final_layer_norm.bias",
|
| 495 |
+
"model.audio.layers.3.self_attn.k_proj",
|
| 496 |
+
"model.audio.layers.3.self_attn.out_proj",
|
| 497 |
+
"model.audio.layers.3.self_attn.out_proj.bias",
|
| 498 |
+
"model.audio.layers.3.self_attn.q_proj",
|
| 499 |
+
"model.audio.layers.3.self_attn.q_proj.bias",
|
| 500 |
+
"model.audio.layers.3.self_attn.v_proj",
|
| 501 |
+
"model.audio.layers.3.self_attn.v_proj.bias",
|
| 502 |
+
"model.audio.layers.3.self_attn_layer_norm",
|
| 503 |
+
"model.audio.layers.3.self_attn_layer_norm.bias",
|
| 504 |
+
"model.audio.layers.30.fc1",
|
| 505 |
+
"model.audio.layers.30.fc1.bias",
|
| 506 |
+
"model.audio.layers.30.fc2",
|
| 507 |
+
"model.audio.layers.30.fc2.bias",
|
| 508 |
+
"model.audio.layers.30.final_layer_norm",
|
| 509 |
+
"model.audio.layers.30.final_layer_norm.bias",
|
| 510 |
+
"model.audio.layers.30.self_attn.k_proj",
|
| 511 |
+
"model.audio.layers.30.self_attn.out_proj",
|
| 512 |
+
"model.audio.layers.30.self_attn.out_proj.bias",
|
| 513 |
+
"model.audio.layers.30.self_attn.q_proj",
|
| 514 |
+
"model.audio.layers.30.self_attn.q_proj.bias",
|
| 515 |
+
"model.audio.layers.30.self_attn.v_proj",
|
| 516 |
+
"model.audio.layers.30.self_attn.v_proj.bias",
|
| 517 |
+
"model.audio.layers.30.self_attn_layer_norm",
|
| 518 |
+
"model.audio.layers.30.self_attn_layer_norm.bias",
|
| 519 |
+
"model.audio.layers.31.fc1",
|
| 520 |
+
"model.audio.layers.31.fc1.bias",
|
| 521 |
+
"model.audio.layers.31.fc2",
|
| 522 |
+
"model.audio.layers.31.fc2.bias",
|
| 523 |
+
"model.audio.layers.31.final_layer_norm",
|
| 524 |
+
"model.audio.layers.31.final_layer_norm.bias",
|
| 525 |
+
"model.audio.layers.31.self_attn.k_proj",
|
| 526 |
+
"model.audio.layers.31.self_attn.out_proj",
|
| 527 |
+
"model.audio.layers.31.self_attn.out_proj.bias",
|
| 528 |
+
"model.audio.layers.31.self_attn.q_proj",
|
| 529 |
+
"model.audio.layers.31.self_attn.q_proj.bias",
|
| 530 |
+
"model.audio.layers.31.self_attn.v_proj",
|
| 531 |
+
"model.audio.layers.31.self_attn.v_proj.bias",
|
| 532 |
+
"model.audio.layers.31.self_attn_layer_norm",
|
| 533 |
+
"model.audio.layers.31.self_attn_layer_norm.bias",
|
| 534 |
+
"model.audio.layers.4.fc1",
|
| 535 |
+
"model.audio.layers.4.fc1.bias",
|
| 536 |
+
"model.audio.layers.4.fc2",
|
| 537 |
+
"model.audio.layers.4.fc2.bias",
|
| 538 |
+
"model.audio.layers.4.final_layer_norm",
|
| 539 |
+
"model.audio.layers.4.final_layer_norm.bias",
|
| 540 |
+
"model.audio.layers.4.self_attn.k_proj",
|
| 541 |
+
"model.audio.layers.4.self_attn.out_proj",
|
| 542 |
+
"model.audio.layers.4.self_attn.out_proj.bias",
|
| 543 |
+
"model.audio.layers.4.self_attn.q_proj",
|
| 544 |
+
"model.audio.layers.4.self_attn.q_proj.bias",
|
| 545 |
+
"model.audio.layers.4.self_attn.v_proj",
|
| 546 |
+
"model.audio.layers.4.self_attn.v_proj.bias",
|
| 547 |
+
"model.audio.layers.4.self_attn_layer_norm",
|
| 548 |
+
"model.audio.layers.4.self_attn_layer_norm.bias",
|
| 549 |
+
"model.audio.layers.5.fc1",
|
| 550 |
+
"model.audio.layers.5.fc1.bias",
|
| 551 |
+
"model.audio.layers.5.fc2",
|
| 552 |
+
"model.audio.layers.5.fc2.bias",
|
| 553 |
+
"model.audio.layers.5.final_layer_norm",
|
| 554 |
+
"model.audio.layers.5.final_layer_norm.bias",
|
| 555 |
+
"model.audio.layers.5.self_attn.k_proj",
|
| 556 |
+
"model.audio.layers.5.self_attn.out_proj",
|
| 557 |
+
"model.audio.layers.5.self_attn.out_proj.bias",
|
| 558 |
+
"model.audio.layers.5.self_attn.q_proj",
|
| 559 |
+
"model.audio.layers.5.self_attn.q_proj.bias",
|
| 560 |
+
"model.audio.layers.5.self_attn.v_proj",
|
| 561 |
+
"model.audio.layers.5.self_attn.v_proj.bias",
|
| 562 |
+
"model.audio.layers.5.self_attn_layer_norm",
|
| 563 |
+
"model.audio.layers.5.self_attn_layer_norm.bias",
|
| 564 |
+
"model.audio.layers.6.fc1",
|
| 565 |
+
"model.audio.layers.6.fc1.bias",
|
| 566 |
+
"model.audio.layers.6.fc2",
|
| 567 |
+
"model.audio.layers.6.fc2.bias",
|
| 568 |
+
"model.audio.layers.6.final_layer_norm",
|
| 569 |
+
"model.audio.layers.6.final_layer_norm.bias",
|
| 570 |
+
"model.audio.layers.6.self_attn.k_proj",
|
| 571 |
+
"model.audio.layers.6.self_attn.out_proj",
|
| 572 |
+
"model.audio.layers.6.self_attn.out_proj.bias",
|
| 573 |
+
"model.audio.layers.6.self_attn.q_proj",
|
| 574 |
+
"model.audio.layers.6.self_attn.q_proj.bias",
|
| 575 |
+
"model.audio.layers.6.self_attn.v_proj",
|
| 576 |
+
"model.audio.layers.6.self_attn.v_proj.bias",
|
| 577 |
+
"model.audio.layers.6.self_attn_layer_norm",
|
| 578 |
+
"model.audio.layers.6.self_attn_layer_norm.bias",
|
| 579 |
+
"model.audio.layers.7.fc1",
|
| 580 |
+
"model.audio.layers.7.fc1.bias",
|
| 581 |
+
"model.audio.layers.7.fc2",
|
| 582 |
+
"model.audio.layers.7.fc2.bias",
|
| 583 |
+
"model.audio.layers.7.final_layer_norm",
|
| 584 |
+
"model.audio.layers.7.final_layer_norm.bias",
|
| 585 |
+
"model.audio.layers.7.self_attn.k_proj",
|
| 586 |
+
"model.audio.layers.7.self_attn.out_proj",
|
| 587 |
+
"model.audio.layers.7.self_attn.out_proj.bias",
|
| 588 |
+
"model.audio.layers.7.self_attn.q_proj",
|
| 589 |
+
"model.audio.layers.7.self_attn.q_proj.bias",
|
| 590 |
+
"model.audio.layers.7.self_attn.v_proj",
|
| 591 |
+
"model.audio.layers.7.self_attn.v_proj.bias",
|
| 592 |
+
"model.audio.layers.7.self_attn_layer_norm",
|
| 593 |
+
"model.audio.layers.7.self_attn_layer_norm.bias",
|
| 594 |
+
"model.audio.layers.8.fc1",
|
| 595 |
+
"model.audio.layers.8.fc1.bias",
|
| 596 |
+
"model.audio.layers.8.fc2",
|
| 597 |
+
"model.audio.layers.8.fc2.bias",
|
| 598 |
+
"model.audio.layers.8.final_layer_norm",
|
| 599 |
+
"model.audio.layers.8.final_layer_norm.bias",
|
| 600 |
+
"model.audio.layers.8.self_attn.k_proj",
|
| 601 |
+
"model.audio.layers.8.self_attn.out_proj",
|
| 602 |
+
"model.audio.layers.8.self_attn.out_proj.bias",
|
| 603 |
+
"model.audio.layers.8.self_attn.q_proj",
|
| 604 |
+
"model.audio.layers.8.self_attn.q_proj.bias",
|
| 605 |
+
"model.audio.layers.8.self_attn.v_proj",
|
| 606 |
+
"model.audio.layers.8.self_attn.v_proj.bias",
|
| 607 |
+
"model.audio.layers.8.self_attn_layer_norm",
|
| 608 |
+
"model.audio.layers.8.self_attn_layer_norm.bias",
|
| 609 |
+
"model.audio.layers.9.fc1",
|
| 610 |
+
"model.audio.layers.9.fc1.bias",
|
| 611 |
+
"model.audio.layers.9.fc2",
|
| 612 |
+
"model.audio.layers.9.fc2.bias",
|
| 613 |
+
"model.audio.layers.9.final_layer_norm",
|
| 614 |
+
"model.audio.layers.9.final_layer_norm.bias",
|
| 615 |
+
"model.audio.layers.9.self_attn.k_proj",
|
| 616 |
+
"model.audio.layers.9.self_attn.out_proj",
|
| 617 |
+
"model.audio.layers.9.self_attn.out_proj.bias",
|
| 618 |
+
"model.audio.layers.9.self_attn.q_proj",
|
| 619 |
+
"model.audio.layers.9.self_attn.q_proj.bias",
|
| 620 |
+
"model.audio.layers.9.self_attn.v_proj",
|
| 621 |
+
"model.audio.layers.9.self_attn.v_proj.bias",
|
| 622 |
+
"model.audio.layers.9.self_attn_layer_norm",
|
| 623 |
+
"model.audio.layers.9.self_attn_layer_norm.bias",
|
| 624 |
+
"model.audio.q_tokens",
|
| 625 |
+
"model.audio.qformer.bert.embeddings.LayerNorm.beta",
|
| 626 |
+
"model.audio.qformer.bert.embeddings.LayerNorm.gamma",
|
| 627 |
+
"model.audio.qformer.bert.embeddings.position_ids",
|
| 628 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.output.LayerNorm.beta",
|
| 629 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.output.LayerNorm.gamma",
|
| 630 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.output.dense",
|
| 631 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.output.dense.bias",
|
| 632 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.self.key",
|
| 633 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.self.key.bias",
|
| 634 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.self.query",
|
| 635 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.self.query.bias",
|
| 636 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.self.value",
|
| 637 |
+
"model.audio.qformer.bert.encoder.layer.0.attention.self.value.bias",
|
| 638 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.output.LayerNorm.beta",
|
| 639 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.output.LayerNorm.gamma",
|
| 640 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.output.dense",
|
| 641 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.output.dense.bias",
|
| 642 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.self.key",
|
| 643 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.self.key.bias",
|
| 644 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.self.query",
|
| 645 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.self.query.bias",
|
| 646 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.self.value",
|
| 647 |
+
"model.audio.qformer.bert.encoder.layer.0.crossattention.self.value.bias",
|
| 648 |
+
"model.audio.qformer.bert.encoder.layer.0.intermediate_query.dense",
|
| 649 |
+
"model.audio.qformer.bert.encoder.layer.0.intermediate_query.dense.bias",
|
| 650 |
+
"model.audio.qformer.bert.encoder.layer.0.output_query.LayerNorm.beta",
|
| 651 |
+
"model.audio.qformer.bert.encoder.layer.0.output_query.LayerNorm.gamma",
|
| 652 |
+
"model.audio.qformer.bert.encoder.layer.0.output_query.dense",
|
| 653 |
+
"model.audio.qformer.bert.encoder.layer.0.output_query.dense.bias",
|
| 654 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.output.LayerNorm.beta",
|
| 655 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.output.LayerNorm.gamma",
|
| 656 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.output.dense",
|
| 657 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.output.dense.bias",
|
| 658 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.self.key",
|
| 659 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.self.key.bias",
|
| 660 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.self.query",
|
| 661 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.self.query.bias",
|
| 662 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.self.value",
|
| 663 |
+
"model.audio.qformer.bert.encoder.layer.1.attention.self.value.bias",
|
| 664 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.output.LayerNorm.beta",
|
| 665 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.output.LayerNorm.gamma",
|
| 666 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.output.dense",
|
| 667 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.output.dense.bias",
|
| 668 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.self.key",
|
| 669 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.self.key.bias",
|
| 670 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.self.query",
|
| 671 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.self.query.bias",
|
| 672 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.self.value",
|
| 673 |
+
"model.audio.qformer.bert.encoder.layer.1.crossattention.self.value.bias",
|
| 674 |
+
"model.audio.qformer.bert.encoder.layer.1.intermediate_query.dense",
|
| 675 |
+
"model.audio.qformer.bert.encoder.layer.1.intermediate_query.dense.bias",
|
| 676 |
+
"model.audio.qformer.bert.encoder.layer.1.output_query.LayerNorm.beta",
|
| 677 |
+
"model.audio.qformer.bert.encoder.layer.1.output_query.LayerNorm.gamma",
|
| 678 |
+
"model.audio.qformer.bert.encoder.layer.1.output_query.dense",
|
| 679 |
+
"model.audio.qformer.bert.encoder.layer.1.output_query.dense.bias",
|
| 680 |
+
"model.language_model.embed_tokens",
|
| 681 |
+
"model.language_model.layers.0.linear_attn.conv1d",
|
| 682 |
+
"model.language_model.layers.0.linear_attn.in_proj_a",
|
| 683 |
+
"model.language_model.layers.0.linear_attn.in_proj_b",
|
| 684 |
+
"model.language_model.layers.1.linear_attn.conv1d",
|
| 685 |
+
"model.language_model.layers.1.linear_attn.in_proj_a",
|
| 686 |
+
"model.language_model.layers.1.linear_attn.in_proj_b",
|
| 687 |
+
"model.language_model.layers.10.linear_attn.conv1d",
|
| 688 |
+
"model.language_model.layers.10.linear_attn.in_proj_a",
|
| 689 |
+
"model.language_model.layers.10.linear_attn.in_proj_b",
|
| 690 |
+
"model.language_model.layers.12.linear_attn.conv1d",
|
| 691 |
+
"model.language_model.layers.12.linear_attn.in_proj_a",
|
| 692 |
+
"model.language_model.layers.12.linear_attn.in_proj_b",
|
| 693 |
+
"model.language_model.layers.13.linear_attn.conv1d",
|
| 694 |
+
"model.language_model.layers.13.linear_attn.in_proj_a",
|
| 695 |
+
"model.language_model.layers.13.linear_attn.in_proj_b",
|
| 696 |
+
"model.language_model.layers.14.linear_attn.conv1d",
|
| 697 |
+
"model.language_model.layers.14.linear_attn.in_proj_a",
|
| 698 |
+
"model.language_model.layers.14.linear_attn.in_proj_b",
|
| 699 |
+
"model.language_model.layers.16.linear_attn.conv1d",
|
| 700 |
+
"model.language_model.layers.16.linear_attn.in_proj_a",
|
| 701 |
+
"model.language_model.layers.16.linear_attn.in_proj_b",
|
| 702 |
+
"model.language_model.layers.17.linear_attn.conv1d",
|
| 703 |
+
"model.language_model.layers.17.linear_attn.in_proj_a",
|
| 704 |
+
"model.language_model.layers.17.linear_attn.in_proj_b",
|
| 705 |
+
"model.language_model.layers.18.linear_attn.conv1d",
|
| 706 |
+
"model.language_model.layers.18.linear_attn.in_proj_a",
|
| 707 |
+
"model.language_model.layers.18.linear_attn.in_proj_b",
|
| 708 |
+
"model.language_model.layers.2.linear_attn.conv1d",
|
| 709 |
+
"model.language_model.layers.2.linear_attn.in_proj_a",
|
| 710 |
+
"model.language_model.layers.2.linear_attn.in_proj_b",
|
| 711 |
+
"model.language_model.layers.20.linear_attn.conv1d",
|
| 712 |
+
"model.language_model.layers.20.linear_attn.in_proj_a",
|
| 713 |
+
"model.language_model.layers.20.linear_attn.in_proj_b",
|
| 714 |
+
"model.language_model.layers.21.linear_attn.conv1d",
|
| 715 |
+
"model.language_model.layers.21.linear_attn.in_proj_a",
|
| 716 |
+
"model.language_model.layers.21.linear_attn.in_proj_b",
|
| 717 |
+
"model.language_model.layers.22.linear_attn.conv1d",
|
| 718 |
+
"model.language_model.layers.22.linear_attn.in_proj_a",
|
| 719 |
+
"model.language_model.layers.22.linear_attn.in_proj_b",
|
| 720 |
+
"model.language_model.layers.24.linear_attn.conv1d",
|
| 721 |
+
"model.language_model.layers.24.linear_attn.in_proj_a",
|
| 722 |
+
"model.language_model.layers.24.linear_attn.in_proj_b",
|
| 723 |
+
"model.language_model.layers.25.linear_attn.conv1d",
|
| 724 |
+
"model.language_model.layers.25.linear_attn.in_proj_a",
|
| 725 |
+
"model.language_model.layers.25.linear_attn.in_proj_b",
|
| 726 |
+
"model.language_model.layers.26.linear_attn.conv1d",
|
| 727 |
+
"model.language_model.layers.26.linear_attn.in_proj_a",
|
| 728 |
+
"model.language_model.layers.26.linear_attn.in_proj_b",
|
| 729 |
+
"model.language_model.layers.28.linear_attn.conv1d",
|
| 730 |
+
"model.language_model.layers.28.linear_attn.in_proj_a",
|
| 731 |
+
"model.language_model.layers.28.linear_attn.in_proj_b",
|
| 732 |
+
"model.language_model.layers.29.linear_attn.conv1d",
|
| 733 |
+
"model.language_model.layers.29.linear_attn.in_proj_a",
|
| 734 |
+
"model.language_model.layers.29.linear_attn.in_proj_b",
|
| 735 |
+
"model.language_model.layers.30.linear_attn.conv1d",
|
| 736 |
+
"model.language_model.layers.30.linear_attn.in_proj_a",
|
| 737 |
+
"model.language_model.layers.30.linear_attn.in_proj_b",
|
| 738 |
+
"model.language_model.layers.4.linear_attn.conv1d",
|
| 739 |
+
"model.language_model.layers.4.linear_attn.in_proj_a",
|
| 740 |
+
"model.language_model.layers.4.linear_attn.in_proj_b",
|
| 741 |
+
"model.language_model.layers.5.linear_attn.conv1d",
|
| 742 |
+
"model.language_model.layers.5.linear_attn.in_proj_a",
|
| 743 |
+
"model.language_model.layers.5.linear_attn.in_proj_b",
|
| 744 |
+
"model.language_model.layers.6.linear_attn.conv1d",
|
| 745 |
+
"model.language_model.layers.6.linear_attn.in_proj_a",
|
| 746 |
+
"model.language_model.layers.6.linear_attn.in_proj_b",
|
| 747 |
+
"model.language_model.layers.8.linear_attn.conv1d",
|
| 748 |
+
"model.language_model.layers.8.linear_attn.in_proj_a",
|
| 749 |
+
"model.language_model.layers.8.linear_attn.in_proj_b",
|
| 750 |
+
"model.language_model.layers.9.linear_attn.conv1d",
|
| 751 |
+
"model.language_model.layers.9.linear_attn.in_proj_a",
|
| 752 |
+
"model.language_model.layers.9.linear_attn.in_proj_b",
|
| 753 |
+
"model.language_model.norm",
|
| 754 |
+
"model.visual",
|
| 755 |
+
"model.visual.blocks.0.attn.proj",
|
| 756 |
+
"model.visual.blocks.0.attn.proj.bias",
|
| 757 |
+
"model.visual.blocks.0.attn.qkv",
|
| 758 |
+
"model.visual.blocks.0.attn.qkv.bias",
|
| 759 |
+
"model.visual.blocks.0.mlp.linear_fc1",
|
| 760 |
+
"model.visual.blocks.0.mlp.linear_fc1.bias",
|
| 761 |
+
"model.visual.blocks.0.mlp.linear_fc2",
|
| 762 |
+
"model.visual.blocks.0.mlp.linear_fc2.bias",
|
| 763 |
+
"model.visual.blocks.0.norm1",
|
| 764 |
+
"model.visual.blocks.0.norm1.bias",
|
| 765 |
+
"model.visual.blocks.0.norm2",
|
| 766 |
+
"model.visual.blocks.0.norm2.bias",
|
| 767 |
+
"model.visual.blocks.1.attn.proj",
|
| 768 |
+
"model.visual.blocks.1.attn.proj.bias",
|
| 769 |
+
"model.visual.blocks.1.attn.qkv",
|
| 770 |
+
"model.visual.blocks.1.attn.qkv.bias",
|
| 771 |
+
"model.visual.blocks.1.mlp.linear_fc1",
|
| 772 |
+
"model.visual.blocks.1.mlp.linear_fc1.bias",
|
| 773 |
+
"model.visual.blocks.1.mlp.linear_fc2",
|
| 774 |
+
"model.visual.blocks.1.mlp.linear_fc2.bias",
|
| 775 |
+
"model.visual.blocks.1.norm1",
|
| 776 |
+
"model.visual.blocks.1.norm1.bias",
|
| 777 |
+
"model.visual.blocks.1.norm2",
|
| 778 |
+
"model.visual.blocks.1.norm2.bias",
|
| 779 |
+
"model.visual.blocks.10.attn.proj",
|
| 780 |
+
"model.visual.blocks.10.attn.proj.bias",
|
| 781 |
+
"model.visual.blocks.10.attn.qkv",
|
| 782 |
+
"model.visual.blocks.10.attn.qkv.bias",
|
| 783 |
+
"model.visual.blocks.10.mlp.linear_fc1",
|
| 784 |
+
"model.visual.blocks.10.mlp.linear_fc1.bias",
|
| 785 |
+
"model.visual.blocks.10.mlp.linear_fc2",
|
| 786 |
+
"model.visual.blocks.10.mlp.linear_fc2.bias",
|
| 787 |
+
"model.visual.blocks.10.norm1",
|
| 788 |
+
"model.visual.blocks.10.norm1.bias",
|
| 789 |
+
"model.visual.blocks.10.norm2",
|
| 790 |
+
"model.visual.blocks.10.norm2.bias",
|
| 791 |
+
"model.visual.blocks.11.attn.proj",
|
| 792 |
+
"model.visual.blocks.11.attn.proj.bias",
|
| 793 |
+
"model.visual.blocks.11.attn.qkv",
|
| 794 |
+
"model.visual.blocks.11.attn.qkv.bias",
|
| 795 |
+
"model.visual.blocks.11.mlp.linear_fc1",
|
| 796 |
+
"model.visual.blocks.11.mlp.linear_fc1.bias",
|
| 797 |
+
"model.visual.blocks.11.mlp.linear_fc2",
|
| 798 |
+
"model.visual.blocks.11.mlp.linear_fc2.bias",
|
| 799 |
+
"model.visual.blocks.11.norm1",
|
| 800 |
+
"model.visual.blocks.11.norm1.bias",
|
| 801 |
+
"model.visual.blocks.11.norm2",
|
| 802 |
+
"model.visual.blocks.11.norm2.bias",
|
| 803 |
+
"model.visual.blocks.12.attn.proj",
|
| 804 |
+
"model.visual.blocks.12.attn.proj.bias",
|
| 805 |
+
"model.visual.blocks.12.attn.qkv",
|
| 806 |
+
"model.visual.blocks.12.attn.qkv.bias",
|
| 807 |
+
"model.visual.blocks.12.mlp.linear_fc1",
|
| 808 |
+
"model.visual.blocks.12.mlp.linear_fc1.bias",
|
| 809 |
+
"model.visual.blocks.12.mlp.linear_fc2",
|
| 810 |
+
"model.visual.blocks.12.mlp.linear_fc2.bias",
|
| 811 |
+
"model.visual.blocks.12.norm1",
|
| 812 |
+
"model.visual.blocks.12.norm1.bias",
|
| 813 |
+
"model.visual.blocks.12.norm2",
|
| 814 |
+
"model.visual.blocks.12.norm2.bias",
|
| 815 |
+
"model.visual.blocks.13.attn.proj",
|
| 816 |
+
"model.visual.blocks.13.attn.proj.bias",
|
| 817 |
+
"model.visual.blocks.13.attn.qkv",
|
| 818 |
+
"model.visual.blocks.13.attn.qkv.bias",
|
| 819 |
+
"model.visual.blocks.13.mlp.linear_fc1",
|
| 820 |
+
"model.visual.blocks.13.mlp.linear_fc1.bias",
|
| 821 |
+
"model.visual.blocks.13.mlp.linear_fc2",
|
| 822 |
+
"model.visual.blocks.13.mlp.linear_fc2.bias",
|
| 823 |
+
"model.visual.blocks.13.norm1",
|
| 824 |
+
"model.visual.blocks.13.norm1.bias",
|
| 825 |
+
"model.visual.blocks.13.norm2",
|
| 826 |
+
"model.visual.blocks.13.norm2.bias",
|
| 827 |
+
"model.visual.blocks.14.attn.proj",
|
| 828 |
+
"model.visual.blocks.14.attn.proj.bias",
|
| 829 |
+
"model.visual.blocks.14.attn.qkv",
|
| 830 |
+
"model.visual.blocks.14.attn.qkv.bias",
|
| 831 |
+
"model.visual.blocks.14.mlp.linear_fc1",
|
| 832 |
+
"model.visual.blocks.14.mlp.linear_fc1.bias",
|
| 833 |
+
"model.visual.blocks.14.mlp.linear_fc2",
|
| 834 |
+
"model.visual.blocks.14.mlp.linear_fc2.bias",
|
| 835 |
+
"model.visual.blocks.14.norm1",
|
| 836 |
+
"model.visual.blocks.14.norm1.bias",
|
| 837 |
+
"model.visual.blocks.14.norm2",
|
| 838 |
+
"model.visual.blocks.14.norm2.bias",
|
| 839 |
+
"model.visual.blocks.15.attn.proj",
|
| 840 |
+
"model.visual.blocks.15.attn.proj.bias",
|
| 841 |
+
"model.visual.blocks.15.attn.qkv",
|
| 842 |
+
"model.visual.blocks.15.attn.qkv.bias",
|
| 843 |
+
"model.visual.blocks.15.mlp.linear_fc1",
|
| 844 |
+
"model.visual.blocks.15.mlp.linear_fc1.bias",
|
| 845 |
+
"model.visual.blocks.15.mlp.linear_fc2",
|
| 846 |
+
"model.visual.blocks.15.mlp.linear_fc2.bias",
|
| 847 |
+
"model.visual.blocks.15.norm1",
|
| 848 |
+
"model.visual.blocks.15.norm1.bias",
|
| 849 |
+
"model.visual.blocks.15.norm2",
|
| 850 |
+
"model.visual.blocks.15.norm2.bias",
|
| 851 |
+
"model.visual.blocks.16.attn.proj",
|
| 852 |
+
"model.visual.blocks.16.attn.proj.bias",
|
| 853 |
+
"model.visual.blocks.16.attn.qkv",
|
| 854 |
+
"model.visual.blocks.16.attn.qkv.bias",
|
| 855 |
+
"model.visual.blocks.16.mlp.linear_fc1",
|
| 856 |
+
"model.visual.blocks.16.mlp.linear_fc1.bias",
|
| 857 |
+
"model.visual.blocks.16.mlp.linear_fc2",
|
| 858 |
+
"model.visual.blocks.16.mlp.linear_fc2.bias",
|
| 859 |
+
"model.visual.blocks.16.norm1",
|
| 860 |
+
"model.visual.blocks.16.norm1.bias",
|
| 861 |
+
"model.visual.blocks.16.norm2",
|
| 862 |
+
"model.visual.blocks.16.norm2.bias",
|
| 863 |
+
"model.visual.blocks.17.attn.proj",
|
| 864 |
+
"model.visual.blocks.17.attn.proj.bias",
|
| 865 |
+
"model.visual.blocks.17.attn.qkv",
|
| 866 |
+
"model.visual.blocks.17.attn.qkv.bias",
|
| 867 |
+
"model.visual.blocks.17.mlp.linear_fc1",
|
| 868 |
+
"model.visual.blocks.17.mlp.linear_fc1.bias",
|
| 869 |
+
"model.visual.blocks.17.mlp.linear_fc2",
|
| 870 |
+
"model.visual.blocks.17.mlp.linear_fc2.bias",
|
| 871 |
+
"model.visual.blocks.17.norm1",
|
| 872 |
+
"model.visual.blocks.17.norm1.bias",
|
| 873 |
+
"model.visual.blocks.17.norm2",
|
| 874 |
+
"model.visual.blocks.17.norm2.bias",
|
| 875 |
+
"model.visual.blocks.18.attn.proj",
|
| 876 |
+
"model.visual.blocks.18.attn.proj.bias",
|
| 877 |
+
"model.visual.blocks.18.attn.qkv",
|
| 878 |
+
"model.visual.blocks.18.attn.qkv.bias",
|
| 879 |
+
"model.visual.blocks.18.mlp.linear_fc1",
|
| 880 |
+
"model.visual.blocks.18.mlp.linear_fc1.bias",
|
| 881 |
+
"model.visual.blocks.18.mlp.linear_fc2",
|
| 882 |
+
"model.visual.blocks.18.mlp.linear_fc2.bias",
|
| 883 |
+
"model.visual.blocks.18.norm1",
|
| 884 |
+
"model.visual.blocks.18.norm1.bias",
|
| 885 |
+
"model.visual.blocks.18.norm2",
|
| 886 |
+
"model.visual.blocks.18.norm2.bias",
|
| 887 |
+
"model.visual.blocks.19.attn.proj",
|
| 888 |
+
"model.visual.blocks.19.attn.proj.bias",
|
| 889 |
+
"model.visual.blocks.19.attn.qkv",
|
| 890 |
+
"model.visual.blocks.19.attn.qkv.bias",
|
| 891 |
+
"model.visual.blocks.19.mlp.linear_fc1",
|
| 892 |
+
"model.visual.blocks.19.mlp.linear_fc1.bias",
|
| 893 |
+
"model.visual.blocks.19.mlp.linear_fc2",
|
| 894 |
+
"model.visual.blocks.19.mlp.linear_fc2.bias",
|
| 895 |
+
"model.visual.blocks.19.norm1",
|
| 896 |
+
"model.visual.blocks.19.norm1.bias",
|
| 897 |
+
"model.visual.blocks.19.norm2",
|
| 898 |
+
"model.visual.blocks.19.norm2.bias",
|
| 899 |
+
"model.visual.blocks.2.attn.proj",
|
| 900 |
+
"model.visual.blocks.2.attn.proj.bias",
|
| 901 |
+
"model.visual.blocks.2.attn.qkv",
|
| 902 |
+
"model.visual.blocks.2.attn.qkv.bias",
|
| 903 |
+
"model.visual.blocks.2.mlp.linear_fc1",
|
| 904 |
+
"model.visual.blocks.2.mlp.linear_fc1.bias",
|
| 905 |
+
"model.visual.blocks.2.mlp.linear_fc2",
|
| 906 |
+
"model.visual.blocks.2.mlp.linear_fc2.bias",
|
| 907 |
+
"model.visual.blocks.2.norm1",
|
| 908 |
+
"model.visual.blocks.2.norm1.bias",
|
| 909 |
+
"model.visual.blocks.2.norm2",
|
| 910 |
+
"model.visual.blocks.2.norm2.bias",
|
| 911 |
+
"model.visual.blocks.20.attn.proj",
|
| 912 |
+
"model.visual.blocks.20.attn.proj.bias",
|
| 913 |
+
"model.visual.blocks.20.attn.qkv",
|
| 914 |
+
"model.visual.blocks.20.attn.qkv.bias",
|
| 915 |
+
"model.visual.blocks.20.mlp.linear_fc1",
|
| 916 |
+
"model.visual.blocks.20.mlp.linear_fc1.bias",
|
| 917 |
+
"model.visual.blocks.20.mlp.linear_fc2",
|
| 918 |
+
"model.visual.blocks.20.mlp.linear_fc2.bias",
|
| 919 |
+
"model.visual.blocks.20.norm1",
|
| 920 |
+
"model.visual.blocks.20.norm1.bias",
|
| 921 |
+
"model.visual.blocks.20.norm2",
|
| 922 |
+
"model.visual.blocks.20.norm2.bias",
|
| 923 |
+
"model.visual.blocks.21.attn.proj",
|
| 924 |
+
"model.visual.blocks.21.attn.proj.bias",
|
| 925 |
+
"model.visual.blocks.21.attn.qkv",
|
| 926 |
+
"model.visual.blocks.21.attn.qkv.bias",
|
| 927 |
+
"model.visual.blocks.21.mlp.linear_fc1",
|
| 928 |
+
"model.visual.blocks.21.mlp.linear_fc1.bias",
|
| 929 |
+
"model.visual.blocks.21.mlp.linear_fc2",
|
| 930 |
+
"model.visual.blocks.21.mlp.linear_fc2.bias",
|
| 931 |
+
"model.visual.blocks.21.norm1",
|
| 932 |
+
"model.visual.blocks.21.norm1.bias",
|
| 933 |
+
"model.visual.blocks.21.norm2",
|
| 934 |
+
"model.visual.blocks.21.norm2.bias",
|
| 935 |
+
"model.visual.blocks.22.attn.proj",
|
| 936 |
+
"model.visual.blocks.22.attn.proj.bias",
|
| 937 |
+
"model.visual.blocks.22.attn.qkv",
|
| 938 |
+
"model.visual.blocks.22.attn.qkv.bias",
|
| 939 |
+
"model.visual.blocks.22.mlp.linear_fc1",
|
| 940 |
+
"model.visual.blocks.22.mlp.linear_fc1.bias",
|
| 941 |
+
"model.visual.blocks.22.mlp.linear_fc2",
|
| 942 |
+
"model.visual.blocks.22.mlp.linear_fc2.bias",
|
| 943 |
+
"model.visual.blocks.22.norm1",
|
| 944 |
+
"model.visual.blocks.22.norm1.bias",
|
| 945 |
+
"model.visual.blocks.22.norm2",
|
| 946 |
+
"model.visual.blocks.22.norm2.bias",
|
| 947 |
+
"model.visual.blocks.23.attn.proj",
|
| 948 |
+
"model.visual.blocks.23.attn.proj.bias",
|
| 949 |
+
"model.visual.blocks.23.attn.qkv",
|
| 950 |
+
"model.visual.blocks.23.attn.qkv.bias",
|
| 951 |
+
"model.visual.blocks.23.mlp.linear_fc1",
|
| 952 |
+
"model.visual.blocks.23.mlp.linear_fc1.bias",
|
| 953 |
+
"model.visual.blocks.23.mlp.linear_fc2",
|
| 954 |
+
"model.visual.blocks.23.mlp.linear_fc2.bias",
|
| 955 |
+
"model.visual.blocks.23.norm1",
|
| 956 |
+
"model.visual.blocks.23.norm1.bias",
|
| 957 |
+
"model.visual.blocks.23.norm2",
|
| 958 |
+
"model.visual.blocks.23.norm2.bias",
|
| 959 |
+
"model.visual.blocks.3.attn.proj",
|
| 960 |
+
"model.visual.blocks.3.attn.proj.bias",
|
| 961 |
+
"model.visual.blocks.3.attn.qkv",
|
| 962 |
+
"model.visual.blocks.3.attn.qkv.bias",
|
| 963 |
+
"model.visual.blocks.3.mlp.linear_fc1",
|
| 964 |
+
"model.visual.blocks.3.mlp.linear_fc1.bias",
|
| 965 |
+
"model.visual.blocks.3.mlp.linear_fc2",
|
| 966 |
+
"model.visual.blocks.3.mlp.linear_fc2.bias",
|
| 967 |
+
"model.visual.blocks.3.norm1",
|
| 968 |
+
"model.visual.blocks.3.norm1.bias",
|
| 969 |
+
"model.visual.blocks.3.norm2",
|
| 970 |
+
"model.visual.blocks.3.norm2.bias",
|
| 971 |
+
"model.visual.blocks.4.attn.proj",
|
| 972 |
+
"model.visual.blocks.4.attn.proj.bias",
|
| 973 |
+
"model.visual.blocks.4.attn.qkv",
|
| 974 |
+
"model.visual.blocks.4.attn.qkv.bias",
|
| 975 |
+
"model.visual.blocks.4.mlp.linear_fc1",
|
| 976 |
+
"model.visual.blocks.4.mlp.linear_fc1.bias",
|
| 977 |
+
"model.visual.blocks.4.mlp.linear_fc2",
|
| 978 |
+
"model.visual.blocks.4.mlp.linear_fc2.bias",
|
| 979 |
+
"model.visual.blocks.4.norm1",
|
| 980 |
+
"model.visual.blocks.4.norm1.bias",
|
| 981 |
+
"model.visual.blocks.4.norm2",
|
| 982 |
+
"model.visual.blocks.4.norm2.bias",
|
| 983 |
+
"model.visual.blocks.5.attn.proj",
|
| 984 |
+
"model.visual.blocks.5.attn.proj.bias",
|
| 985 |
+
"model.visual.blocks.5.attn.qkv",
|
| 986 |
+
"model.visual.blocks.5.attn.qkv.bias",
|
| 987 |
+
"model.visual.blocks.5.mlp.linear_fc1",
|
| 988 |
+
"model.visual.blocks.5.mlp.linear_fc1.bias",
|
| 989 |
+
"model.visual.blocks.5.mlp.linear_fc2",
|
| 990 |
+
"model.visual.blocks.5.mlp.linear_fc2.bias",
|
| 991 |
+
"model.visual.blocks.5.norm1",
|
| 992 |
+
"model.visual.blocks.5.norm1.bias",
|
| 993 |
+
"model.visual.blocks.5.norm2",
|
| 994 |
+
"model.visual.blocks.5.norm2.bias",
|
| 995 |
+
"model.visual.blocks.6.attn.proj",
|
| 996 |
+
"model.visual.blocks.6.attn.proj.bias",
|
| 997 |
+
"model.visual.blocks.6.attn.qkv",
|
| 998 |
+
"model.visual.blocks.6.attn.qkv.bias",
|
| 999 |
+
"model.visual.blocks.6.mlp.linear_fc1",
|
| 1000 |
+
"model.visual.blocks.6.mlp.linear_fc1.bias",
|
| 1001 |
+
"model.visual.blocks.6.mlp.linear_fc2",
|
| 1002 |
+
"model.visual.blocks.6.mlp.linear_fc2.bias",
|
| 1003 |
+
"model.visual.blocks.6.norm1",
|
| 1004 |
+
"model.visual.blocks.6.norm1.bias",
|
| 1005 |
+
"model.visual.blocks.6.norm2",
|
| 1006 |
+
"model.visual.blocks.6.norm2.bias",
|
| 1007 |
+
"model.visual.blocks.7.attn.proj",
|
| 1008 |
+
"model.visual.blocks.7.attn.proj.bias",
|
| 1009 |
+
"model.visual.blocks.7.attn.qkv",
|
| 1010 |
+
"model.visual.blocks.7.attn.qkv.bias",
|
| 1011 |
+
"model.visual.blocks.7.mlp.linear_fc1",
|
| 1012 |
+
"model.visual.blocks.7.mlp.linear_fc1.bias",
|
| 1013 |
+
"model.visual.blocks.7.mlp.linear_fc2",
|
| 1014 |
+
"model.visual.blocks.7.mlp.linear_fc2.bias",
|
| 1015 |
+
"model.visual.blocks.7.norm1",
|
| 1016 |
+
"model.visual.blocks.7.norm1.bias",
|
| 1017 |
+
"model.visual.blocks.7.norm2",
|
| 1018 |
+
"model.visual.blocks.7.norm2.bias",
|
| 1019 |
+
"model.visual.blocks.8.attn.proj",
|
| 1020 |
+
"model.visual.blocks.8.attn.proj.bias",
|
| 1021 |
+
"model.visual.blocks.8.attn.qkv",
|
| 1022 |
+
"model.visual.blocks.8.attn.qkv.bias",
|
| 1023 |
+
"model.visual.blocks.8.mlp.linear_fc1",
|
| 1024 |
+
"model.visual.blocks.8.mlp.linear_fc1.bias",
|
| 1025 |
+
"model.visual.blocks.8.mlp.linear_fc2",
|
| 1026 |
+
"model.visual.blocks.8.mlp.linear_fc2.bias",
|
| 1027 |
+
"model.visual.blocks.8.norm1",
|
| 1028 |
+
"model.visual.blocks.8.norm1.bias",
|
| 1029 |
+
"model.visual.blocks.8.norm2",
|
| 1030 |
+
"model.visual.blocks.8.norm2.bias",
|
| 1031 |
+
"model.visual.blocks.9.attn.proj",
|
| 1032 |
+
"model.visual.blocks.9.attn.proj.bias",
|
| 1033 |
+
"model.visual.blocks.9.attn.qkv",
|
| 1034 |
+
"model.visual.blocks.9.attn.qkv.bias",
|
| 1035 |
+
"model.visual.blocks.9.mlp.linear_fc1",
|
| 1036 |
+
"model.visual.blocks.9.mlp.linear_fc1.bias",
|
| 1037 |
+
"model.visual.blocks.9.mlp.linear_fc2",
|
| 1038 |
+
"model.visual.blocks.9.mlp.linear_fc2.bias",
|
| 1039 |
+
"model.visual.blocks.9.norm1",
|
| 1040 |
+
"model.visual.blocks.9.norm1.bias",
|
| 1041 |
+
"model.visual.blocks.9.norm2",
|
| 1042 |
+
"model.visual.blocks.9.norm2.bias",
|
| 1043 |
+
"model.visual.merger.linear_fc1",
|
| 1044 |
+
"model.visual.merger.linear_fc1.bias",
|
| 1045 |
+
"model.visual.merger.linear_fc2",
|
| 1046 |
+
"model.visual.merger.linear_fc2.bias",
|
| 1047 |
+
"model.visual.merger.norm",
|
| 1048 |
+
"model.visual.merger.norm.bias",
|
| 1049 |
+
"model.visual.patch_embed.proj",
|
| 1050 |
+
"model.visual.patch_embed.proj.bias",
|
| 1051 |
+
"model.visual.pos_embed",
|
| 1052 |
+
"mtp"
|
| 1053 |
+
]
|
| 1054 |
+
},
|
| 1055 |
+
"quantized_linear_matrices": 200,
|
| 1056 |
+
"architecture": {
|
| 1057 |
+
"family": "dense",
|
| 1058 |
+
"model_type": "qwen3_5",
|
| 1059 |
+
"layers": 32,
|
| 1060 |
+
"experts": 0,
|
| 1061 |
+
"hidden_size": 2560,
|
| 1062 |
+
"intermediate_size": 9216,
|
| 1063 |
+
"shared_expert_intermediate_size": null,
|
| 1064 |
+
"layer_types": [
|
| 1065 |
+
"linear_attention",
|
| 1066 |
+
"linear_attention",
|
| 1067 |
+
"linear_attention",
|
| 1068 |
+
"full_attention",
|
| 1069 |
+
"linear_attention",
|
| 1070 |
+
"linear_attention",
|
| 1071 |
+
"linear_attention",
|
| 1072 |
+
"full_attention",
|
| 1073 |
+
"linear_attention",
|
| 1074 |
+
"linear_attention",
|
| 1075 |
+
"linear_attention",
|
| 1076 |
+
"full_attention",
|
| 1077 |
+
"linear_attention",
|
| 1078 |
+
"linear_attention",
|
| 1079 |
+
"linear_attention",
|
| 1080 |
+
"full_attention",
|
| 1081 |
+
"linear_attention",
|
| 1082 |
+
"linear_attention",
|
| 1083 |
+
"linear_attention",
|
| 1084 |
+
"full_attention",
|
| 1085 |
+
"linear_attention",
|
| 1086 |
+
"linear_attention",
|
| 1087 |
+
"linear_attention",
|
| 1088 |
+
"full_attention",
|
| 1089 |
+
"linear_attention",
|
| 1090 |
+
"linear_attention",
|
| 1091 |
+
"linear_attention",
|
| 1092 |
+
"full_attention",
|
| 1093 |
+
"linear_attention",
|
| 1094 |
+
"linear_attention",
|
| 1095 |
+
"linear_attention",
|
| 1096 |
+
"full_attention"
|
| 1097 |
+
],
|
| 1098 |
+
"linear_attention_layers": 24,
|
| 1099 |
+
"full_attention_layers": 8,
|
| 1100 |
+
"model_class": "modeling_wemm.WeMMVideoForConditionalGeneration"
|
| 1101 |
+
},
|
| 1102 |
+
"quantized_expert_matrices": 0,
|
| 1103 |
+
"protected_gdn_in_proj_a_b": 48,
|
| 1104 |
+
"protected_tensor_count": 1068,
|
| 1105 |
+
"protected_tensors_bit_exact": true,
|
| 1106 |
+
"independent_final_file_audit": {
|
| 1107 |
+
"completed": true,
|
| 1108 |
+
"tensor_count": 1468,
|
| 1109 |
+
"sha256": "bd5ed7eaf0682ee781175a249c9f86b9366d0d31980f72409ec6b7d939486ef4",
|
| 1110 |
+
"bytes": 7659403688,
|
| 1111 |
+
"all_tensor_hashes_reloaded": true
|
| 1112 |
+
},
|
| 1113 |
+
"native_inference_validated": false,
|
| 1114 |
+
"native_low_precision_gemm_validated": false,
|
| 1115 |
+
"published": false,
|
| 1116 |
+
"versions": {
|
| 1117 |
+
"torch": "2.6.0+cu124",
|
| 1118 |
+
"transformers": "5.5.3"
|
| 1119 |
+
},
|
| 1120 |
+
"conversion_elapsed_seconds": 97.74387492053211
|
| 1121 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:510fd6ff51823f6b1c820595b5eed750b8ff0ee85961d2f330623b3cf5ff4019
|
| 3 |
+
size 19989343
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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": null,
|
| 8 |
+
"clean_up_tokenization_spaces": false,
|
| 9 |
+
"eos_token": "<|im_end|>",
|
| 10 |
+
"errors": "replace",
|
| 11 |
+
"image_token": "<|image_pad|>",
|
| 12 |
+
"is_local": true,
|
| 13 |
+
"model_max_length": 262144,
|
| 14 |
+
"model_specific_special_tokens": {
|
| 15 |
+
"audio_bos_token": "<|audio_start|>",
|
| 16 |
+
"audio_eos_token": "<|audio_end|>",
|
| 17 |
+
"audio_token": "<|audio_pad|>",
|
| 18 |
+
"image_token": "<|image_pad|>",
|
| 19 |
+
"video_token": "<|video_pad|>",
|
| 20 |
+
"vision_bos_token": "<|vision_start|>",
|
| 21 |
+
"vision_eos_token": "<|vision_end|>"
|
| 22 |
+
},
|
| 23 |
+
"pad_token": "<|endoftext|>",
|
| 24 |
+
"pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
|
| 25 |
+
"split_special_tokens": false,
|
| 26 |
+
"tokenizer_class": "TokenizersBackend",
|
| 27 |
+
"unk_token": null,
|
| 28 |
+
"video_token": "<|video_pad|>",
|
| 29 |
+
"vision_bos_token": "<|vision_start|>",
|
| 30 |
+
"vision_eos_token": "<|vision_end|>"
|
| 31 |
+
}
|
video_preprocessor_config.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"size": {
|
| 3 |
+
"longest_edge": 25165824,
|
| 4 |
+
"shortest_edge": 4096
|
| 5 |
+
},
|
| 6 |
+
"patch_size": 16,
|
| 7 |
+
"temporal_patch_size": 2,
|
| 8 |
+
"merge_size": 2,
|
| 9 |
+
"image_mean": [
|
| 10 |
+
0.5,
|
| 11 |
+
0.5,
|
| 12 |
+
0.5
|
| 13 |
+
],
|
| 14 |
+
"image_std": [
|
| 15 |
+
0.5,
|
| 16 |
+
0.5,
|
| 17 |
+
0.5
|
| 18 |
+
],
|
| 19 |
+
"processor_class": "Qwen3VLProcessor",
|
| 20 |
+
"video_processor_type": "Qwen3VLVideoProcessor"
|
| 21 |
+
}
|
wemm-video-architecture.png
ADDED
|
Git LFS Details
|
wemm-video-capabilities-compact.png
ADDED
|
Git LFS Details
|
wemm_media.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
import soundfile as sf
|
| 9 |
+
import torch
|
| 10 |
+
from PIL import Image
|
| 11 |
+
from scipy.signal import resample_poly
|
| 12 |
+
from .wemm_video_policy import resolve_video_options, video_frame_count, video_metadata_fps
|
| 13 |
+
from .wemm_zip import load_zip_video
|
| 14 |
+
|
| 15 |
+
IMAGE = '<|vision_start|><|image_pad|><|vision_end|>'
|
| 16 |
+
VIDEO = '<|vision_start|><|video_pad|><|vision_end|>'
|
| 17 |
+
AUDIO = '<|audio_start|><|audio_pad|><|audio_end|>'
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def resolve_media(source):
|
| 21 |
+
"""Fetch HTTP(S) media using Requests' inherited proxy and TLS settings."""
|
| 22 |
+
if isinstance(source, str) and source.startswith('data:'):
|
| 23 |
+
# Decode the transport ourselves. FFmpeg's data-URI input can truncate
|
| 24 |
+
# WAV audio, changing both the waveform and its reported duration.
|
| 25 |
+
import base64
|
| 26 |
+
from urllib.parse import unquote_to_bytes
|
| 27 |
+
header, separator, payload = source.partition(',')
|
| 28 |
+
if not separator:
|
| 29 |
+
raise ValueError('Malformed media data URL')
|
| 30 |
+
data = unquote_to_bytes(payload)
|
| 31 |
+
return base64.b64decode(data, validate=True) if header.endswith(';base64') else data
|
| 32 |
+
if isinstance(source, str) and source.startswith(('https://', 'http://')):
|
| 33 |
+
import requests
|
| 34 |
+
with requests.get(source, timeout=(10, 120)) as response:
|
| 35 |
+
response.raise_for_status()
|
| 36 |
+
return response.content
|
| 37 |
+
if isinstance(source, str) and source.startswith('file://'):
|
| 38 |
+
from urllib.parse import unquote, urlparse
|
| 39 |
+
return unquote(urlparse(source).path)
|
| 40 |
+
return source
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def pcm16_bytes(samples):
|
| 44 |
+
buffer = io.BytesIO()
|
| 45 |
+
sf.write(buffer, samples, 16000, format='WAV', subtype='PCM_16')
|
| 46 |
+
return buffer.getvalue()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def decode_audio(source):
|
| 50 |
+
"""Paths/encoded bytes, (waveform, rate), or {array, sampling_rate}."""
|
| 51 |
+
if isinstance(source, dict):
|
| 52 |
+
if source.get('array') is not None:
|
| 53 |
+
source = (source['array'], source.get('sampling_rate', 16000))
|
| 54 |
+
else:
|
| 55 |
+
source = source['path']
|
| 56 |
+
source = resolve_media(source)
|
| 57 |
+
if isinstance(source, tuple) and len(source) == 2:
|
| 58 |
+
samples, rate = source
|
| 59 |
+
samples = np.asarray(samples, dtype=np.float32)
|
| 60 |
+
if samples.ndim != 1:
|
| 61 |
+
raise ValueError('Waveform arrays must be mono, shape [samples]')
|
| 62 |
+
rate = int(rate)
|
| 63 |
+
if rate <= 0:
|
| 64 |
+
raise ValueError('Audio sampling rate must be positive')
|
| 65 |
+
if rate != 16000:
|
| 66 |
+
divisor = math.gcd(rate, 16000)
|
| 67 |
+
samples = resample_poly(samples, 16000 // divisor, rate // divisor)
|
| 68 |
+
else:
|
| 69 |
+
# Same decoder as the evaluation adapter and the vLLM media stack.
|
| 70 |
+
from torchcodec.decoders import AudioDecoder
|
| 71 |
+
decoder = AudioDecoder(source if isinstance(source, bytes) else str(source),
|
| 72 |
+
sample_rate=16000, num_channels=1)
|
| 73 |
+
samples = decoder.get_all_samples().data[0].numpy()
|
| 74 |
+
samples = np.asarray(samples, dtype=np.float32)
|
| 75 |
+
if samples.size == 0 or not np.isfinite(samples).all():
|
| 76 |
+
raise ValueError('Audio must contain finite, nonempty samples')
|
| 77 |
+
return samples
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def audio_features(samples, extractor, *, pcm16=True):
|
| 81 |
+
"""Match the native route's waveform precision before mel extraction.
|
| 82 |
+
|
| 83 |
+
Standalone audio arrays pass through a PCM16 WAV in vLLM. Bundled video
|
| 84 |
+
audio is decoded directly from the video and retains its float32 samples.
|
| 85 |
+
"""
|
| 86 |
+
if pcm16:
|
| 87 |
+
samples, _ = sf.read(io.BytesIO(pcm16_bytes(samples)), dtype='float32')
|
| 88 |
+
else:
|
| 89 |
+
samples = np.asarray(samples, dtype=np.float32)
|
| 90 |
+
if samples.ndim != 1 or samples.size == 0 or not np.isfinite(samples).all():
|
| 91 |
+
raise ValueError('Video audio must be finite, nonempty mono float32 samples')
|
| 92 |
+
if len(samples) < 16000:
|
| 93 |
+
samples = np.pad(samples, (0, 16000 - len(samples)))
|
| 94 |
+
return torch.cat([extractor(samples[i:i + 480000], sampling_rate=16000,
|
| 95 |
+
return_tensors='pt')['input_features']
|
| 96 |
+
for i in range(0, len(samples), 480000)])
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def load_image(source):
|
| 100 |
+
source = resolve_media(source)
|
| 101 |
+
if isinstance(source, (str, Path, bytes)):
|
| 102 |
+
from PIL import ImageOps
|
| 103 |
+
with Image.open(io.BytesIO(source) if isinstance(source, bytes) else source) as image:
|
| 104 |
+
return ImageOps.exif_transpose(image).convert('RGB')
|
| 105 |
+
if isinstance(source, Image.Image):
|
| 106 |
+
return source.convert('RGB')
|
| 107 |
+
return source
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def decode_video(source, *, fps=2.0, num_frames=None, min_frames=4, max_frames=128, **kwargs):
|
| 111 |
+
source = resolve_media(source)
|
| 112 |
+
options = resolve_video_options(dict(fps=fps, num_frames=num_frames,
|
| 113 |
+
min_frames=min_frames, max_frames=max_frames, **kwargs))
|
| 114 |
+
# Detect the archive before invoking FFmpeg: stored and compressed ZIPs
|
| 115 |
+
# must share vLLM's explicit sorting, sampling, source FPS and resizing.
|
| 116 |
+
if isinstance(source, bytes):
|
| 117 |
+
header = source[:4]
|
| 118 |
+
else:
|
| 119 |
+
with open(source, 'rb') as stream:
|
| 120 |
+
header = stream.read(4)
|
| 121 |
+
if header == b'PK\x03\x04':
|
| 122 |
+
raw = source if isinstance(source, bytes) else Path(source).read_bytes()
|
| 123 |
+
zip_options = dict(options)
|
| 124 |
+
sample_fps = zip_options.pop('fps')
|
| 125 |
+
count = zip_options.pop('num_frames', None)
|
| 126 |
+
return load_zip_video(raw, sample_fps=sample_fps, num_frames=count, **zip_options)
|
| 127 |
+
from torchcodec.decoders import VideoDecoder
|
| 128 |
+
decoder = VideoDecoder(source if isinstance(source, bytes) else str(source), num_ffmpeg_threads=2)
|
| 129 |
+
info = decoder.metadata
|
| 130 |
+
total, origin_fps = int(info.num_frames), video_metadata_fps(info)
|
| 131 |
+
count = video_frame_count(total, origin_fps, options)
|
| 132 |
+
indices = np.linspace(0, total - 1, count, dtype=int).tolist()
|
| 133 |
+
frames = decoder.get_frames_at(indices=indices).data.permute(0, 2, 3, 1).contiguous().numpy()
|
| 134 |
+
metadata = dict(total_num_frames=total, fps=origin_fps, frames_indices=indices,
|
| 135 |
+
duration=total / origin_fps, width=int(frames.shape[2]),
|
| 136 |
+
height=int(frames.shape[1]), video_backend='torchcodec')
|
| 137 |
+
return frames, metadata
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def tokens_per_segment(config):
|
| 141 |
+
window = float(config['second_per_window'])
|
| 142 |
+
stride = float(config.get('second_stride', window))
|
| 143 |
+
kernel, step = round(1500 * window / 30), max(1, round(1500 * stride / 30))
|
| 144 |
+
return ((1500 - kernel) // step + 1) * int(config['qformer_config']['query_length'])
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def resolve_timestamp_interval(value=None, default=1.0):
|
| 148 |
+
"""Seconds per timestamp: explicit value, environment, processor default."""
|
| 149 |
+
if value is None:
|
| 150 |
+
value = os.environ.get('TIMESTAMP_INTERVAL_SEC', default)
|
| 151 |
+
if isinstance(value, bool):
|
| 152 |
+
raise ValueError('timestamp_interval_sec must be a finite positive number')
|
| 153 |
+
try:
|
| 154 |
+
value = float(value)
|
| 155 |
+
except (TypeError, ValueError) as exc:
|
| 156 |
+
raise ValueError('timestamp_interval_sec must be a finite positive number') from exc
|
| 157 |
+
if not math.isfinite(value) or value <= 0:
|
| 158 |
+
raise ValueError('timestamp_interval_sec must be a finite positive number')
|
| 159 |
+
return value
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def timestamp_interval_option(options, default=None):
|
| 163 |
+
nested = options.get('audio_url', {})
|
| 164 |
+
sources = [options, nested] if isinstance(nested, dict) else [options]
|
| 165 |
+
if any('TIMESTAMP_INTERVAL_SEC' in source for source in sources):
|
| 166 |
+
raise ValueError('Use lowercase timestamp_interval_sec in audio options')
|
| 167 |
+
values = [source['timestamp_interval_sec'] for source in sources
|
| 168 |
+
if source.get('timestamp_interval_sec') is not None]
|
| 169 |
+
if values and any(resolve_timestamp_interval(value) != resolve_timestamp_interval(values[0])
|
| 170 |
+
for value in values[1:]):
|
| 171 |
+
raise ValueError('Conflicting timestamp_interval_sec values')
|
| 172 |
+
return values[0] if values else default
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def audio_timestamp_groups(count, window, duration=None, timestamp_interval_sec=None):
|
| 176 |
+
"""Training renderer: ceil real duration, balanced effective pads, padded tail."""
|
| 177 |
+
interval = resolve_timestamp_interval(timestamp_interval_sec)
|
| 178 |
+
count = int(count)
|
| 179 |
+
if count <= 0:
|
| 180 |
+
return [], [], 0
|
| 181 |
+
padded_duration = count * float(window)
|
| 182 |
+
if duration is None:
|
| 183 |
+
duration, effective = padded_duration, count
|
| 184 |
+
else:
|
| 185 |
+
duration = float(duration)
|
| 186 |
+
if not math.isfinite(duration) or duration <= 0:
|
| 187 |
+
raise ValueError('Audio duration must be finite and positive')
|
| 188 |
+
duration = min(duration, padded_duration)
|
| 189 |
+
effective = max(1, min(count, math.ceil(duration / float(window) - 1e-9)))
|
| 190 |
+
sample_fps = 1 / interval
|
| 191 |
+
groups = max(1, math.ceil(duration * sample_fps - 1e-9))
|
| 192 |
+
base, remainder = divmod(effective, groups)
|
| 193 |
+
sizes = [base] * groups
|
| 194 |
+
step = float(groups) / float(remainder) if remainder else 0
|
| 195 |
+
for i in range(1, remainder + 1):
|
| 196 |
+
sizes[min(groups - 1, math.floor(i * step) - 1)] += 1
|
| 197 |
+
sizes[-1] += count - effective
|
| 198 |
+
return sizes, [index / sample_fps for index in range(groups)], effective
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def audio_ids(tokenizer, count, window, duration=None, timestamp_interval_sec=None):
|
| 202 |
+
sizes, times, _ = audio_timestamp_groups(count, window, duration, timestamp_interval_sec)
|
| 203 |
+
result = [tokenizer.convert_tokens_to_ids('<|audio_start|>')]
|
| 204 |
+
pad = tokenizer.convert_tokens_to_ids('<|audio_pad|>')
|
| 205 |
+
for timestamp, size in zip(times, sizes):
|
| 206 |
+
result.extend(tokenizer.encode(f'<{timestamp:.1f} seconds>', add_special_tokens=False))
|
| 207 |
+
result.extend([pad] * size)
|
| 208 |
+
return result + [tokenizer.convert_tokens_to_ids('<|audio_end|>')]
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def video_ids(tokenizer, grid, metadata, temporal_patch_size, merge_size,
|
| 212 |
+
audio_count=0, audio_duration=None, window=.2):
|
| 213 |
+
time, height, width = (int(x) for x in grid)
|
| 214 |
+
indices = list(metadata['frames_indices'])
|
| 215 |
+
indices += [indices[-1]] * max(0, time * temporal_patch_size - len(indices))
|
| 216 |
+
if audio_count:
|
| 217 |
+
sampled_fps = len(metadata['frames_indices']) / audio_duration
|
| 218 |
+
# Preserve the reference's float32 boundary arithmetic and padded tail.
|
| 219 |
+
boundary = torch.floor(torch.arange(1, time, dtype=torch.float32)
|
| 220 |
+
* (temporal_patch_size / sampled_fps / window)).long()
|
| 221 |
+
bounds = [0, *boundary.clamp(0, audio_count).tolist(), audio_count]
|
| 222 |
+
groups = [b - a for a, b in zip(bounds, bounds[1:])]
|
| 223 |
+
else:
|
| 224 |
+
groups = [0] * time
|
| 225 |
+
start, end, video, audio = [tokenizer.convert_tokens_to_ids(token) for token in
|
| 226 |
+
('<|vision_start|>', '<|vision_end|>', '<|video_pad|>', '<|audio_pad|>')]
|
| 227 |
+
result, timestamps = [], []
|
| 228 |
+
for index in range(time):
|
| 229 |
+
left, right = indices[index * temporal_patch_size], indices[(index + 1) * temporal_patch_size - 1]
|
| 230 |
+
# Bundled audio: mean frame indices then divide (reference WeMM).
|
| 231 |
+
# Pure video: divide first then mean (native Qwen3VL).
|
| 232 |
+
seconds = ((left + right) / (2 * metadata['fps']) if audio_count else
|
| 233 |
+
(left / metadata['fps'] + right / metadata['fps']) / 2)
|
| 234 |
+
timestamps.append(seconds)
|
| 235 |
+
result.extend(tokenizer.encode(f'<{seconds:.1f} seconds>', add_special_tokens=False))
|
| 236 |
+
result.extend([start] + [video] * (height * width // merge_size**2)
|
| 237 |
+
+ [audio] * groups[index] + [end])
|
| 238 |
+
return result, groups, timestamps
|
wemm_video_policy.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Shared WeMM video policy v2; mirrored unchanged into the vLLM overlay."""
|
| 2 |
+
|
| 3 |
+
import math
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
POLICY_VERSION = "wemm_video_v2"
|
| 7 |
+
VIDEO_OPTION_KEYS = (
|
| 8 |
+
"fps", "num_frames", "min_frames", "max_frames", "total_pixels",
|
| 9 |
+
"min_pixels", "max_pixels",
|
| 10 |
+
)
|
| 11 |
+
VIDEO_CAP_KEYS = ("max_allowed_frames", "max_allowed_total_pixels")
|
| 12 |
+
VIDEO_ENV = {
|
| 13 |
+
"fps": "WEMM_VIDEO_FPS",
|
| 14 |
+
"min_frames": "WEMM_VIDEO_MIN_FRAMES",
|
| 15 |
+
"max_frames": "WEMM_VIDEO_MAX_FRAMES",
|
| 16 |
+
"total_pixels": "WEMM_VIDEO_LONGEST_EDGE",
|
| 17 |
+
"min_pixels": "WEMM_VIDEO_SHORTEST_EDGE",
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def video_environment_defaults():
|
| 22 |
+
"""Legacy environment variables supply defaults, never request locks."""
|
| 23 |
+
return {key: os.environ[name] for key, name in VIDEO_ENV.items()
|
| 24 |
+
if os.environ.get(name, "").strip()}
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _number(name, value, integer=False):
|
| 28 |
+
if isinstance(value, bool):
|
| 29 |
+
raise ValueError(f"{name} must be a positive finite number")
|
| 30 |
+
try:
|
| 31 |
+
number = float(value)
|
| 32 |
+
except (TypeError, ValueError, OverflowError) as exc:
|
| 33 |
+
raise ValueError(f"{name} must be a positive finite number") from exc
|
| 34 |
+
if not math.isfinite(number) or number <= 0 or (integer and not number.is_integer()):
|
| 35 |
+
raise ValueError(f"{name} must be a positive {'integer' if integer else 'finite number'}")
|
| 36 |
+
return int(number) if integer else number
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def video_metadata_fps(metadata, default=None):
|
| 40 |
+
"""Prefer header precision only when it agrees with the effective FPS.
|
| 41 |
+
|
| 42 |
+
Older TorchCodec serializes header FPS with six decimal places, while
|
| 43 |
+
newer versions expose the full rational float. Keep that precision for
|
| 44 |
+
stable one-decimal timestamp tokens at half-decimal boundaries.
|
| 45 |
+
A discrepancy above 1% is not rounding noise: use the duration-derived
|
| 46 |
+
average instead, including streams whose header advertises twice the FPS.
|
| 47 |
+
"""
|
| 48 |
+
rates = {}
|
| 49 |
+
for name in ('average_fps_from_header', 'average_fps'):
|
| 50 |
+
value = getattr(metadata, name, None)
|
| 51 |
+
if value is not None:
|
| 52 |
+
try:
|
| 53 |
+
rates[name] = _number('video FPS', value)
|
| 54 |
+
except ValueError:
|
| 55 |
+
pass
|
| 56 |
+
header = rates.get('average_fps_from_header')
|
| 57 |
+
average = rates.get('average_fps')
|
| 58 |
+
fps = header if header is not None else average
|
| 59 |
+
if header is not None and average is not None:
|
| 60 |
+
if not math.isclose(header, average, rel_tol=0.01, abs_tol=1e-6):
|
| 61 |
+
fps = average
|
| 62 |
+
if fps is not None:
|
| 63 |
+
return round(fps, 6) or fps
|
| 64 |
+
return _number('video FPS', default)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def resolve_video_options(defaults=None, overrides=None):
|
| 68 |
+
"""Request values override defaults; explicit service caps stay immutable."""
|
| 69 |
+
defaults, overrides = dict(defaults or {}), dict(overrides or {})
|
| 70 |
+
for values in (defaults, overrides):
|
| 71 |
+
if values.get("nframes") is not None:
|
| 72 |
+
if values.get("num_frames") is not None and values["num_frames"] != values["nframes"]:
|
| 73 |
+
raise ValueError("Conflicting num_frames and nframes")
|
| 74 |
+
values["num_frames"] = values.pop("nframes")
|
| 75 |
+
result = {key: value for key, value in defaults.items() if value is not None}
|
| 76 |
+
result.update({key: value for key, value in overrides.items() if value is not None})
|
| 77 |
+
for key in VIDEO_CAP_KEYS:
|
| 78 |
+
if key in defaults:
|
| 79 |
+
result[key] = defaults[key]
|
| 80 |
+
for key, value in {
|
| 81 |
+
"fps": 2.0, "min_frames": 4, "max_frames": 128,
|
| 82 |
+
"total_pixels": 117964800, "min_pixels": 4096,
|
| 83 |
+
}.items():
|
| 84 |
+
result.setdefault(key, value)
|
| 85 |
+
for key in VIDEO_OPTION_KEYS + VIDEO_CAP_KEYS:
|
| 86 |
+
if result.get(key) is not None:
|
| 87 |
+
result[key] = _number(key, result[key], integer=key != "fps")
|
| 88 |
+
if result["min_frames"] < 2 or result["max_frames"] < result["min_frames"]:
|
| 89 |
+
raise ValueError("Video frame limits require 2 <= min_frames <= max_frames")
|
| 90 |
+
if result.get("max_pixels", result["min_pixels"]) < result["min_pixels"]:
|
| 91 |
+
raise ValueError("max_pixels must be at least min_pixels")
|
| 92 |
+
frame_cap = result.get("max_allowed_frames")
|
| 93 |
+
if frame_cap is not None and max(result["max_frames"], result.get("num_frames", 0)) > frame_cap:
|
| 94 |
+
raise ValueError("Requested video frames exceed max_allowed_frames")
|
| 95 |
+
pixel_cap = result.get("max_allowed_total_pixels")
|
| 96 |
+
if pixel_cap is not None and result["total_pixels"] > pixel_cap:
|
| 97 |
+
raise ValueError("Requested total_pixels exceeds max_allowed_total_pixels")
|
| 98 |
+
return result
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def video_frame_count(total_frames, original_fps, options):
|
| 102 |
+
"""Preserve temporal pairs and the existing num_frames-before-fps recipe."""
|
| 103 |
+
options = resolve_video_options(options)
|
| 104 |
+
original_fps = _number("original_fps", original_fps)
|
| 105 |
+
if total_frames < 2:
|
| 106 |
+
raise ValueError("Video needs at least two frames")
|
| 107 |
+
lower = math.ceil(options["min_frames"] / 2) * 2
|
| 108 |
+
upper = min(options["max_frames"], total_frames) // 2 * 2
|
| 109 |
+
desired = options.get("num_frames", total_frames / original_fps * options["fps"])
|
| 110 |
+
return int(min(max(desired, lower), upper, total_frames)) // 2 * 2
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def video_resize_size(num_frames, options):
|
| 114 |
+
"""Keep the legacy factor 2; longest/shortest_edge are video pixel volumes."""
|
| 115 |
+
options = resolve_video_options(options)
|
| 116 |
+
if num_frames < 2 or num_frames % 2:
|
| 117 |
+
raise ValueError("Decoded video frames must form temporal pairs")
|
| 118 |
+
maximum = int(max(
|
| 119 |
+
min(768 * 32**2, options["total_pixels"] / num_frames * 2),
|
| 120 |
+
int(options["min_pixels"] * 1.05),
|
| 121 |
+
))
|
| 122 |
+
if options.get("max_pixels") is not None:
|
| 123 |
+
maximum = min(maximum, options["max_pixels"])
|
| 124 |
+
return {"longest_edge": num_frames * maximum,
|
| 125 |
+
"shortest_edge": num_frames * options["min_pixels"]}
|
wemm_zip.py
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Shared ZIP frame decoder; preserves the release vLLM resize and time policy."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import logging
|
| 5 |
+
import math
|
| 6 |
+
import os
|
| 7 |
+
import time
|
| 8 |
+
import zipfile
|
| 9 |
+
from io import BytesIO
|
| 10 |
+
from typing import Any
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
import numpy.typing as npt
|
| 14 |
+
import torch
|
| 15 |
+
from PIL import Image
|
| 16 |
+
from torchvision import transforms
|
| 17 |
+
from torchvision.transforms import InterpolationMode
|
| 18 |
+
|
| 19 |
+
from .wemm_zip_policy import zip_frame_indices
|
| 20 |
+
|
| 21 |
+
logger = logging.getLogger(__name__)
|
| 22 |
+
MAX_RATIO = 200
|
| 23 |
+
SPATIAL_MERGE_SIZE = 2
|
| 24 |
+
IMAGE_PATCH_SIZE = 16
|
| 25 |
+
IMAGE_MIN_TOKEN_NUM = 4
|
| 26 |
+
IMAGE_MAX_TOKEN_NUM = 16384
|
| 27 |
+
VIDEO_MIN_TOKEN_NUM = 128
|
| 28 |
+
VIDEO_MAX_TOKEN_NUM = 768
|
| 29 |
+
FRAME_FACTOR = 2
|
| 30 |
+
MODEL_SEQ_LEN = int(float(os.environ.get("MODEL_SEQ_LEN", 128000)))
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def round_by_factor(number: int, factor: int) -> int:
|
| 34 |
+
"""Returns the closest integer to 'number' that is divisible by 'factor'."""
|
| 35 |
+
return round(number / factor) * factor
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def ceil_by_factor(number: int, factor: int) -> int:
|
| 39 |
+
"""Returns the smallest integer >= 'number' that is divisible by 'factor'."""
|
| 40 |
+
return math.ceil(number / factor) * factor
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def floor_by_factor(number: int, factor: int) -> int:
|
| 44 |
+
"""Returns the largest integer <= 'number' that is divisible by 'factor'."""
|
| 45 |
+
return math.floor(number / factor) * factor
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def smart_resize(
|
| 49 |
+
height: int,
|
| 50 |
+
width: int,
|
| 51 |
+
factor: int,
|
| 52 |
+
min_pixels: int | None = None,
|
| 53 |
+
max_pixels: int | None = None,
|
| 54 |
+
) -> tuple[int, int]:
|
| 55 |
+
"""
|
| 56 |
+
Rescales the image so that the following conditions are met:
|
| 57 |
+
|
| 58 |
+
1. Both dimensions (height and width) are divisible by 'factor'.
|
| 59 |
+
2. The total number of pixels is within the range ['min_pixels', 'max_pixels'].
|
| 60 |
+
3. The aspect ratio of the image is maintained as closely as possible.
|
| 61 |
+
"""
|
| 62 |
+
max_pixels = (
|
| 63 |
+
max_pixels if max_pixels is not None else (IMAGE_MAX_TOKEN_NUM * factor**2)
|
| 64 |
+
)
|
| 65 |
+
min_pixels = (
|
| 66 |
+
min_pixels if min_pixels is not None else (IMAGE_MIN_TOKEN_NUM * factor**2)
|
| 67 |
+
)
|
| 68 |
+
assert max_pixels >= min_pixels, (
|
| 69 |
+
"The max_pixels of image must be greater than or equal to min_pixels."
|
| 70 |
+
)
|
| 71 |
+
if max(height, width) / min(height, width) > MAX_RATIO:
|
| 72 |
+
raise ValueError(
|
| 73 |
+
f"absolute aspect ratio must be smaller than {MAX_RATIO}, "
|
| 74 |
+
f"got {max(height, width) / min(height, width)}"
|
| 75 |
+
)
|
| 76 |
+
h_bar = max(factor, round_by_factor(height, factor))
|
| 77 |
+
w_bar = max(factor, round_by_factor(width, factor))
|
| 78 |
+
if h_bar * w_bar > max_pixels:
|
| 79 |
+
beta = math.sqrt((height * width) / max_pixels)
|
| 80 |
+
h_bar = floor_by_factor(height / beta, factor)
|
| 81 |
+
w_bar = floor_by_factor(width / beta, factor)
|
| 82 |
+
elif h_bar * w_bar < min_pixels:
|
| 83 |
+
beta = math.sqrt(min_pixels / (height * width))
|
| 84 |
+
h_bar = ceil_by_factor(height * beta, factor)
|
| 85 |
+
w_bar = ceil_by_factor(width * beta, factor)
|
| 86 |
+
return h_bar, w_bar
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def _resize_frames_impl(
|
| 90 |
+
frames_np: np.ndarray,
|
| 91 |
+
sample_fps: float = 1.0,
|
| 92 |
+
**kwargs,
|
| 93 |
+
) -> tuple[npt.NDArray, dict[str, Any]]:
|
| 94 |
+
"""Resize pre-loaded frames with token budget constraints and return metadata.
|
| 95 |
+
|
| 96 |
+
This is the shared resize logic used by both load_frames_from_zip and
|
| 97 |
+
load_frames_from_images.
|
| 98 |
+
|
| 99 |
+
Args:
|
| 100 |
+
frames_np: (T, H, W, 3) uint8 numpy array of raw frames
|
| 101 |
+
sample_fps: Effective FPS for temporal alignment in prompts
|
| 102 |
+
**kwargs: Token budget args (min_pixels, max_pixels, total_pixels,
|
| 103 |
+
resized_height, resized_width)
|
| 104 |
+
|
| 105 |
+
Returns:
|
| 106 |
+
Tuple of (frames_array, metadata_dict)
|
| 107 |
+
where frames_array has shape (T, H, W, 3) as float32 [0, 1]
|
| 108 |
+
"""
|
| 109 |
+
actual_nframes = frames_np.shape[0]
|
| 110 |
+
video = torch.from_numpy(frames_np).permute(0, 3, 1, 2) # (T, C, H, W)
|
| 111 |
+
|
| 112 |
+
# Apply resizing with token budget constraints
|
| 113 |
+
ele = kwargs.copy()
|
| 114 |
+
image_factor = IMAGE_PATCH_SIZE * SPATIAL_MERGE_SIZE # 32
|
| 115 |
+
VIDEO_FRAME_MIN_PIXELS = VIDEO_MIN_TOKEN_NUM * image_factor * image_factor
|
| 116 |
+
VIDEO_FRAME_MAX_PIXELS = VIDEO_MAX_TOKEN_NUM * image_factor * image_factor
|
| 117 |
+
|
| 118 |
+
nframes_actual, _, height, width = video.shape
|
| 119 |
+
min_pixels = ele.get("min_pixels", VIDEO_FRAME_MIN_PIXELS)
|
| 120 |
+
total_pixels = ele.get(
|
| 121 |
+
"total_pixels",
|
| 122 |
+
MODEL_SEQ_LEN * image_factor * image_factor * 0.9,
|
| 123 |
+
)
|
| 124 |
+
max_pixels = max(
|
| 125 |
+
min(
|
| 126 |
+
VIDEO_FRAME_MAX_PIXELS,
|
| 127 |
+
total_pixels / nframes_actual * FRAME_FACTOR,
|
| 128 |
+
),
|
| 129 |
+
int(min_pixels * 1.05),
|
| 130 |
+
)
|
| 131 |
+
max_pixels_supposed = ele.get("max_pixels", max_pixels)
|
| 132 |
+
if max_pixels_supposed > max_pixels:
|
| 133 |
+
logger.warning(
|
| 134 |
+
"The given max_pixels[%s] exceeds limit[%s].",
|
| 135 |
+
max_pixels_supposed,
|
| 136 |
+
max_pixels,
|
| 137 |
+
)
|
| 138 |
+
max_pixels = min(max_pixels_supposed, max_pixels)
|
| 139 |
+
|
| 140 |
+
# Resize frames
|
| 141 |
+
if "resized_height" in ele and "resized_width" in ele:
|
| 142 |
+
resized_height, resized_width = smart_resize(
|
| 143 |
+
ele["resized_height"],
|
| 144 |
+
ele["resized_width"],
|
| 145 |
+
factor=image_factor,
|
| 146 |
+
)
|
| 147 |
+
else:
|
| 148 |
+
resized_height, resized_width = smart_resize(
|
| 149 |
+
height,
|
| 150 |
+
width,
|
| 151 |
+
factor=image_factor,
|
| 152 |
+
min_pixels=min_pixels,
|
| 153 |
+
max_pixels=max_pixels,
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
video = transforms.functional.resize(
|
| 157 |
+
video,
|
| 158 |
+
[resized_height, resized_width],
|
| 159 |
+
interpolation=InterpolationMode.BICUBIC,
|
| 160 |
+
antialias=True,
|
| 161 |
+
).float() # Normalize to [0, 1]
|
| 162 |
+
|
| 163 |
+
# Convert to (T, H, W, C) numpy
|
| 164 |
+
frames_array = video.permute(0, 2, 3, 1).numpy()
|
| 165 |
+
|
| 166 |
+
# Frame indices: all frames sequential
|
| 167 |
+
frame_indices = list(range(actual_nframes))
|
| 168 |
+
|
| 169 |
+
metadata = {
|
| 170 |
+
"fps": sample_fps,
|
| 171 |
+
"frames_indices": frame_indices,
|
| 172 |
+
"total_num_frames": actual_nframes,
|
| 173 |
+
"video_backend": "frames",
|
| 174 |
+
"do_sample_frames": False,
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
logger.info(
|
| 178 |
+
"Frames: %s frames @ %s fps, resized to %sx%s",
|
| 179 |
+
actual_nframes,
|
| 180 |
+
sample_fps,
|
| 181 |
+
resized_height,
|
| 182 |
+
resized_width,
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
return frames_array, metadata
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def load_zip_video(
|
| 189 |
+
zip_bytes: bytes,
|
| 190 |
+
sample_fps: float = 2.0,
|
| 191 |
+
num_frames: int | None = None,
|
| 192 |
+
**kwargs,
|
| 193 |
+
) -> tuple[npt.NDArray, dict[str, Any]]:
|
| 194 |
+
"""Load video frames from a ZIP archive containing image files.
|
| 195 |
+
|
| 196 |
+
ZIP should contain frames named in alphabetical order: 00000.jpg, 00001.jpg, etc.
|
| 197 |
+
Frames are resized to uniform dimensions before stacking.
|
| 198 |
+
|
| 199 |
+
Args:
|
| 200 |
+
zip_bytes: Raw bytes of ZIP file containing frame images
|
| 201 |
+
sample_fps: Effective frames per second for temporal alignment in prompts
|
| 202 |
+
num_frames: Positive requested count; None uses all frames up to the
|
| 203 |
+
effective deployment/request frame limit. Excess frames are sampled
|
| 204 |
+
uniformly, rather than keeping a prefix. Negative counts are errors.
|
| 205 |
+
**kwargs: Additional args for token budget (min_pixels, max_pixels, etc)
|
| 206 |
+
|
| 207 |
+
Returns:
|
| 208 |
+
Tuple of (frames_array, metadata_dict)
|
| 209 |
+
where frames_array has shape (num_frames, height, width, 3) as float32 [0,1]
|
| 210 |
+
and metadata_dict contains fps, total_num_frames, frames_indices, etc.
|
| 211 |
+
|
| 212 |
+
Raises:
|
| 213 |
+
RuntimeError: If ZIP is invalid or contains no image files
|
| 214 |
+
"""
|
| 215 |
+
import time
|
| 216 |
+
|
| 217 |
+
st = time.time()
|
| 218 |
+
if isinstance(sample_fps, bool) or not math.isfinite(float(sample_fps)) or float(sample_fps) <= 0:
|
| 219 |
+
raise ValueError("ZIP fps must be a positive finite number")
|
| 220 |
+
sample_fps = float(sample_fps)
|
| 221 |
+
|
| 222 |
+
# Extract frames from ZIP in sorted order
|
| 223 |
+
frames_list = []
|
| 224 |
+
frame_names = []
|
| 225 |
+
frame_sizes = [] # Track dimensions for normalization
|
| 226 |
+
|
| 227 |
+
try:
|
| 228 |
+
with zipfile.ZipFile(BytesIO(zip_bytes), "r") as zf:
|
| 229 |
+
# Get all file names, filter to image extensions
|
| 230 |
+
all_files = zf.namelist()
|
| 231 |
+
image_files = [
|
| 232 |
+
f
|
| 233 |
+
for f in sorted(all_files)
|
| 234 |
+
if f.lower().endswith((".jpg", ".jpeg", ".png", ".bmp", ".gif"))
|
| 235 |
+
and not f.startswith("__MACOSX/") # Skip Mac OS metadata
|
| 236 |
+
]
|
| 237 |
+
|
| 238 |
+
# Also extract audio files (WAV/MP3/FLAC) if bundled in ZIP
|
| 239 |
+
audio_files = [
|
| 240 |
+
f
|
| 241 |
+
for f in all_files
|
| 242 |
+
if f.lower().endswith((".wav", ".mp3", ".flac"))
|
| 243 |
+
and not f.startswith("__MACOSX/")
|
| 244 |
+
]
|
| 245 |
+
wav_bytes = None
|
| 246 |
+
if audio_files:
|
| 247 |
+
wav_bytes = zf.read(audio_files[0])
|
| 248 |
+
logger.info(
|
| 249 |
+
"Found bundled audio in ZIP: %s (%s bytes)",
|
| 250 |
+
audio_files[0],
|
| 251 |
+
len(wav_bytes),
|
| 252 |
+
)
|
| 253 |
+
|
| 254 |
+
if not image_files:
|
| 255 |
+
raise RuntimeError(
|
| 256 |
+
f"ZIP archive contains no image files. Files: {all_files[:10]}"
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
original_count = len(image_files)
|
| 260 |
+
selected_indices = zip_frame_indices(original_count, num_frames, **kwargs)
|
| 261 |
+
if len(selected_indices) < original_count:
|
| 262 |
+
logger.info("ZIP frame selection: %s -> %s, uniform across full archive",
|
| 263 |
+
original_count, len(selected_indices))
|
| 264 |
+
image_files = [image_files[index] for index in selected_indices]
|
| 265 |
+
|
| 266 |
+
# Load each frame and track sizes
|
| 267 |
+
for frame_file in image_files:
|
| 268 |
+
try:
|
| 269 |
+
frame_bytes = zf.read(frame_file)
|
| 270 |
+
img = Image.open(BytesIO(frame_bytes)).convert("RGB")
|
| 271 |
+
frame_array = np.array(img, dtype=np.uint8)
|
| 272 |
+
frames_list.append(frame_array)
|
| 273 |
+
frame_names.append(frame_file)
|
| 274 |
+
frame_sizes.append(frame_array.shape[:2]) # (H, W)
|
| 275 |
+
except Exception as e:
|
| 276 |
+
raise RuntimeError(f"Failed to decode selected ZIP frame {frame_file}: {e}") from e
|
| 277 |
+
|
| 278 |
+
except Exception as e:
|
| 279 |
+
raise RuntimeError(f"Failed to process ZIP: {e}") from e
|
| 280 |
+
|
| 281 |
+
if not frames_list:
|
| 282 |
+
raise RuntimeError("No valid frames could be extracted from ZIP")
|
| 283 |
+
|
| 284 |
+
actual_nframes = len(frames_list)
|
| 285 |
+
logger.info(
|
| 286 |
+
"Loaded %s frames from ZIP in %ss", actual_nframes, f"{time.time() - st:.3f}"
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
# CRITICAL FIX: Normalize frame sizes before stacking
|
| 290 |
+
# Multi-image ZIPs may have frames with different dimensions
|
| 291 |
+
# Calculate a common target size from the first frame
|
| 292 |
+
first_h, first_w = frame_sizes[0]
|
| 293 |
+
|
| 294 |
+
if not all(h == first_h and w == first_w for h, w in frame_sizes):
|
| 295 |
+
logger.warning(
|
| 296 |
+
(
|
| 297 |
+
"Frame size mismatch detected: %s. Resizing all frames to match first"
|
| 298 |
+
" frame: %sx%s"
|
| 299 |
+
),
|
| 300 |
+
set(frame_sizes),
|
| 301 |
+
first_h,
|
| 302 |
+
first_w,
|
| 303 |
+
)
|
| 304 |
+
# Resize mismatched frames to common size
|
| 305 |
+
normalized_frames = []
|
| 306 |
+
for i, frame_array in enumerate(frames_list):
|
| 307 |
+
if frame_array.shape[:2] != (first_h, first_w):
|
| 308 |
+
# Convert to PIL, resize, convert back
|
| 309 |
+
img = Image.fromarray(frame_array)
|
| 310 |
+
img_resized = img.resize((first_w, first_h), Image.BICUBIC)
|
| 311 |
+
frame_array = np.array(img_resized, dtype=np.uint8)
|
| 312 |
+
normalized_frames.append(frame_array)
|
| 313 |
+
frames_list = normalized_frames
|
| 314 |
+
|
| 315 |
+
# Now stack frames - all should have uniform shape
|
| 316 |
+
frames_np = np.stack(frames_list, axis=0) # (T, H, W, 3)
|
| 317 |
+
frames_array, metadata = _resize_frames_impl(
|
| 318 |
+
frames_np, sample_fps=sample_fps, **kwargs
|
| 319 |
+
)
|
| 320 |
+
metadata["video_backend"] = "zip"
|
| 321 |
+
metadata["wemm_pre_resized"] = True
|
| 322 |
+
metadata["width"] = int(frames_array.shape[2])
|
| 323 |
+
metadata["height"] = int(frames_array.shape[1])
|
| 324 |
+
metadata["frame_names"] = frame_names
|
| 325 |
+
metadata["frames_indices"] = selected_indices
|
| 326 |
+
metadata["total_num_frames"] = original_count
|
| 327 |
+
metadata["duration"] = original_count / sample_fps
|
| 328 |
+
metadata["zip_original_num_frames"] = original_count
|
| 329 |
+
metadata["zip_decoded_num_frames"] = actual_nframes
|
| 330 |
+
metadata["zip_frame_policy"] = "all" if actual_nframes == original_count else "uniform"
|
| 331 |
+
# Include bundled audio bytes if found in ZIP
|
| 332 |
+
if wav_bytes is not None:
|
| 333 |
+
metadata["audio_bytes"] = wav_bytes
|
| 334 |
+
|
| 335 |
+
return frames_array, metadata
|
wemm_zip_policy.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Frame-count policy for pre-sampled WeMM ZIP videos."""
|
| 2 |
+
import math
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def positive_frame_count(value, name="num_frames"):
|
| 6 |
+
if value is None:
|
| 7 |
+
return None
|
| 8 |
+
if isinstance(value, bool):
|
| 9 |
+
raise ValueError(f"{name} must be a positive integer")
|
| 10 |
+
try:
|
| 11 |
+
number = float(value)
|
| 12 |
+
except (TypeError, ValueError, OverflowError) as exc:
|
| 13 |
+
raise ValueError(f"{name} must be a positive integer") from exc
|
| 14 |
+
if not math.isfinite(number) or number <= 0 or not number.is_integer():
|
| 15 |
+
raise ValueError(f"{name} must be a positive integer; omit it for the bounded ZIP default")
|
| 16 |
+
return int(number)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def zip_frame_indices(total, num_frames=None, **options):
|
| 20 |
+
"""Keep all frames up to the limit; sample the whole timeline above it."""
|
| 21 |
+
total = positive_frame_count(total, "ZIP image count")
|
| 22 |
+
limits = [positive_frame_count(options.get("max_frames", 128), "max_frames")]
|
| 23 |
+
for key in ("max_allowed_frames", "wemm_zip_max_frames"):
|
| 24 |
+
if options.get(key) is not None:
|
| 25 |
+
limits.append(positive_frame_count(options[key], key))
|
| 26 |
+
limit = min(limits)
|
| 27 |
+
count = positive_frame_count(num_frames)
|
| 28 |
+
if count is None:
|
| 29 |
+
count = min(total, limit)
|
| 30 |
+
elif count > limit:
|
| 31 |
+
raise ValueError(f"Requested ZIP num_frames={count} exceeds frame limit {limit}")
|
| 32 |
+
elif count > total:
|
| 33 |
+
raise ValueError(f"Requested ZIP num_frames={count} exceeds available frames {total}")
|
| 34 |
+
if count == 1:
|
| 35 |
+
return [0]
|
| 36 |
+
# Integer form of truncated linspace; include both ends of the archive.
|
| 37 |
+
return [index * (total - 1) // (count - 1) for index in range(count)]
|