Instructions to use AEmotionStudio/yue2-models with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AEmotionStudio/yue2-models with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-to-audio", model="AEmotionStudio/yue2-models")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("AEmotionStudio/yue2-models", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add lm lane (byte-identical mirror of the upstream release)
Browse files- lm/LICENSE +429 -0
- lm/THIRD_PARTY_NOTICES.md +15 -0
- lm/config.json +38 -0
- lm/generation_config.json +11 -0
- lm/licenses/SnakeBeta-NVIDIA-MIT.txt +21 -0
- lm/licenses/stable-audio-tools-MIT.txt +21 -0
- lm/model.safetensors +3 -0
- lm/modeling_yue2.py +705 -0
- lm/qwen.tiktoken +0 -0
- lm/weights_manifest.json +9 -0
- lm/yue2_generation_config.json +24 -0
lm/LICENSE
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
YuE2 model-weight license
|
| 2 |
+
|
| 3 |
+
The YuE2-3B, YuE2-Vae and YuE2-Vae-legacy checkpoint weights are
|
| 4 |
+
licensed under Creative Commons Attribution-NonCommercial 4.0 International
|
| 5 |
+
(CC BY-NC 4.0): https://creativecommons.org/licenses/by-nc/4.0/
|
| 6 |
+
|
| 7 |
+
Scope: the YuE2 checkpoint weights in model.safetensors, or the corresponding
|
| 8 |
+
models/<model-name>/model.safetensors files in the inference kit.
|
| 9 |
+
For attribution, identify YuE2, the model name and its source repository:
|
| 10 |
+
https://huggingface.co/m-a-p/YuE2-3B
|
| 11 |
+
https://huggingface.co/m-a-p/YuE2-Vae
|
| 12 |
+
https://huggingface.co/m-a-p/YuE2-Vae-legacy
|
| 13 |
+
|
| 14 |
+
This weight license does not replace separately applicable licenses for code,
|
| 15 |
+
text tokenization files, evaluation assets or other bundled material.
|
| 16 |
+
Third-party source notices and their original license texts are preserved in
|
| 17 |
+
THIRD_PARTY_NOTICES.md and licenses/.
|
| 18 |
+
|
| 19 |
+
The official license text follows without modification.
|
| 20 |
+
Source: https://creativecommons.org/licenses/by-nc/4.0/legalcode.txt
|
| 21 |
+
|
| 22 |
+
Attribution-NonCommercial 4.0 International
|
| 23 |
+
|
| 24 |
+
=======================================================================
|
| 25 |
+
|
| 26 |
+
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
| 27 |
+
does not provide legal services or legal advice. Distribution of
|
| 28 |
+
Creative Commons public licenses does not create a lawyer-client or
|
| 29 |
+
other relationship. Creative Commons makes its licenses and related
|
| 30 |
+
information available on an "as-is" basis. Creative Commons gives no
|
| 31 |
+
warranties regarding its licenses, any material licensed under their
|
| 32 |
+
terms and conditions, or any related information. Creative Commons
|
| 33 |
+
disclaims all liability for damages resulting from their use to the
|
| 34 |
+
fullest extent possible.
|
| 35 |
+
|
| 36 |
+
Using Creative Commons Public Licenses
|
| 37 |
+
|
| 38 |
+
Creative Commons public licenses provide a standard set of terms and
|
| 39 |
+
conditions that creators and other rights holders may use to share
|
| 40 |
+
original works of authorship and other material subject to copyright
|
| 41 |
+
and certain other rights specified in the public license below. The
|
| 42 |
+
following considerations are for informational purposes only, are not
|
| 43 |
+
exhaustive, and do not form part of our licenses.
|
| 44 |
+
|
| 45 |
+
Considerations for licensors: Our public licenses are
|
| 46 |
+
intended for use by those authorized to give the public
|
| 47 |
+
permission to use material in ways otherwise restricted by
|
| 48 |
+
copyright and certain other rights. Our licenses are
|
| 49 |
+
irrevocable. Licensors should read and understand the terms
|
| 50 |
+
and conditions of the license they choose before applying it.
|
| 51 |
+
Licensors should also secure all rights necessary before
|
| 52 |
+
applying our licenses so that the public can reuse the
|
| 53 |
+
material as expected. Licensors should clearly mark any
|
| 54 |
+
material not subject to the license. This includes other CC-
|
| 55 |
+
licensed material, or material used under an exception or
|
| 56 |
+
limitation to copyright. More considerations for licensors:
|
| 57 |
+
wiki.creativecommons.org/Considerations_for_licensors
|
| 58 |
+
|
| 59 |
+
Considerations for the public: By using one of our public
|
| 60 |
+
licenses, a licensor grants the public permission to use the
|
| 61 |
+
licensed material under specified terms and conditions. If
|
| 62 |
+
the licensor's permission is not necessary for any reason--for
|
| 63 |
+
example, because of any applicable exception or limitation to
|
| 64 |
+
copyright--then that use is not regulated by the license. Our
|
| 65 |
+
licenses grant only permissions under copyright and certain
|
| 66 |
+
other rights that a licensor has authority to grant. Use of
|
| 67 |
+
the licensed material may still be restricted for other
|
| 68 |
+
reasons, including because others have copyright or other
|
| 69 |
+
rights in the material. A licensor may make special requests,
|
| 70 |
+
such as asking that all changes be marked or described.
|
| 71 |
+
Although not required by our licenses, you are encouraged to
|
| 72 |
+
respect those requests where reasonable. More considerations
|
| 73 |
+
for the public:
|
| 74 |
+
wiki.creativecommons.org/Considerations_for_licensees
|
| 75 |
+
|
| 76 |
+
=======================================================================
|
| 77 |
+
|
| 78 |
+
Creative Commons Attribution-NonCommercial 4.0 International Public
|
| 79 |
+
License
|
| 80 |
+
|
| 81 |
+
By exercising the Licensed Rights (defined below), You accept and agree
|
| 82 |
+
to be bound by the terms and conditions of this Creative Commons
|
| 83 |
+
Attribution-NonCommercial 4.0 International Public License ("Public
|
| 84 |
+
License"). To the extent this Public License may be interpreted as a
|
| 85 |
+
contract, You are granted the Licensed Rights in consideration of Your
|
| 86 |
+
acceptance of these terms and conditions, and the Licensor grants You
|
| 87 |
+
such rights in consideration of benefits the Licensor receives from
|
| 88 |
+
making the Licensed Material available under these terms and
|
| 89 |
+
conditions.
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
Section 1 -- Definitions.
|
| 93 |
+
|
| 94 |
+
a. Adapted Material means material subject to Copyright and Similar
|
| 95 |
+
Rights that is derived from or based upon the Licensed Material
|
| 96 |
+
and in which the Licensed Material is translated, altered,
|
| 97 |
+
arranged, transformed, or otherwise modified in a manner requiring
|
| 98 |
+
permission under the Copyright and Similar Rights held by the
|
| 99 |
+
Licensor. For purposes of this Public License, where the Licensed
|
| 100 |
+
Material is a musical work, performance, or sound recording,
|
| 101 |
+
Adapted Material is always produced where the Licensed Material is
|
| 102 |
+
synched in timed relation with a moving image.
|
| 103 |
+
|
| 104 |
+
b. Adapter's License means the license You apply to Your Copyright
|
| 105 |
+
and Similar Rights in Your contributions to Adapted Material in
|
| 106 |
+
accordance with the terms and conditions of this Public License.
|
| 107 |
+
|
| 108 |
+
c. Copyright and Similar Rights means copyright and/or similar rights
|
| 109 |
+
closely related to copyright including, without limitation,
|
| 110 |
+
performance, broadcast, sound recording, and Sui Generis Database
|
| 111 |
+
Rights, without regard to how the rights are labeled or
|
| 112 |
+
categorized. For purposes of this Public License, the rights
|
| 113 |
+
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
| 114 |
+
Rights.
|
| 115 |
+
d. Effective Technological Measures means those measures that, in the
|
| 116 |
+
absence of proper authority, may not be circumvented under laws
|
| 117 |
+
fulfilling obligations under Article 11 of the WIPO Copyright
|
| 118 |
+
Treaty adopted on December 20, 1996, and/or similar international
|
| 119 |
+
agreements.
|
| 120 |
+
|
| 121 |
+
e. Exceptions and Limitations means fair use, fair dealing, and/or
|
| 122 |
+
any other exception or limitation to Copyright and Similar Rights
|
| 123 |
+
that applies to Your use of the Licensed Material.
|
| 124 |
+
|
| 125 |
+
f. Licensed Material means the artistic or literary work, database,
|
| 126 |
+
or other material to which the Licensor applied this Public
|
| 127 |
+
License.
|
| 128 |
+
|
| 129 |
+
g. Licensed Rights means the rights granted to You subject to the
|
| 130 |
+
terms and conditions of this Public License, which are limited to
|
| 131 |
+
all Copyright and Similar Rights that apply to Your use of the
|
| 132 |
+
Licensed Material and that the Licensor has authority to license.
|
| 133 |
+
|
| 134 |
+
h. Licensor means the individual(s) or entity(ies) granting rights
|
| 135 |
+
under this Public License.
|
| 136 |
+
|
| 137 |
+
i. NonCommercial means not primarily intended for or directed towards
|
| 138 |
+
commercial advantage or monetary compensation. For purposes of
|
| 139 |
+
this Public License, the exchange of the Licensed Material for
|
| 140 |
+
other material subject to Copyright and Similar Rights by digital
|
| 141 |
+
file-sharing or similar means is NonCommercial provided there is
|
| 142 |
+
no payment of monetary compensation in connection with the
|
| 143 |
+
exchange.
|
| 144 |
+
|
| 145 |
+
j. Share means to provide material to the public by any means or
|
| 146 |
+
process that requires permission under the Licensed Rights, such
|
| 147 |
+
as reproduction, public display, public performance, distribution,
|
| 148 |
+
dissemination, communication, or importation, and to make material
|
| 149 |
+
available to the public including in ways that members of the
|
| 150 |
+
public may access the material from a place and at a time
|
| 151 |
+
individually chosen by them.
|
| 152 |
+
|
| 153 |
+
k. Sui Generis Database Rights means rights other than copyright
|
| 154 |
+
resulting from Directive 96/9/EC of the European Parliament and of
|
| 155 |
+
the Council of 11 March 1996 on the legal protection of databases,
|
| 156 |
+
as amended and/or succeeded, as well as other essentially
|
| 157 |
+
equivalent rights anywhere in the world.
|
| 158 |
+
|
| 159 |
+
l. You means the individual or entity exercising the Licensed Rights
|
| 160 |
+
under this Public License. Your has a corresponding meaning.
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
Section 2 -- Scope.
|
| 164 |
+
|
| 165 |
+
a. License grant.
|
| 166 |
+
|
| 167 |
+
1. Subject to the terms and conditions of this Public License,
|
| 168 |
+
the Licensor hereby grants You a worldwide, royalty-free,
|
| 169 |
+
non-sublicensable, non-exclusive, irrevocable license to
|
| 170 |
+
exercise the Licensed Rights in the Licensed Material to:
|
| 171 |
+
|
| 172 |
+
a. reproduce and Share the Licensed Material, in whole or
|
| 173 |
+
in part, for NonCommercial purposes only; and
|
| 174 |
+
|
| 175 |
+
b. produce, reproduce, and Share Adapted Material for
|
| 176 |
+
NonCommercial purposes only.
|
| 177 |
+
|
| 178 |
+
2. Exceptions and Limitations. For the avoidance of doubt, where
|
| 179 |
+
Exceptions and Limitations apply to Your use, this Public
|
| 180 |
+
License does not apply, and You do not need to comply with
|
| 181 |
+
its terms and conditions.
|
| 182 |
+
|
| 183 |
+
3. Term. The term of this Public License is specified in Section
|
| 184 |
+
6(a).
|
| 185 |
+
|
| 186 |
+
4. Media and formats; technical modifications allowed. The
|
| 187 |
+
Licensor authorizes You to exercise the Licensed Rights in
|
| 188 |
+
all media and formats whether now known or hereafter created,
|
| 189 |
+
and to make technical modifications necessary to do so. The
|
| 190 |
+
Licensor waives and/or agrees not to assert any right or
|
| 191 |
+
authority to forbid You from making technical modifications
|
| 192 |
+
necessary to exercise the Licensed Rights, including
|
| 193 |
+
technical modifications necessary to circumvent Effective
|
| 194 |
+
Technological Measures. For purposes of this Public License,
|
| 195 |
+
simply making modifications authorized by this Section 2(a)
|
| 196 |
+
(4) never produces Adapted Material.
|
| 197 |
+
|
| 198 |
+
5. Downstream recipients.
|
| 199 |
+
|
| 200 |
+
a. Offer from the Licensor -- Licensed Material. Every
|
| 201 |
+
recipient of the Licensed Material automatically
|
| 202 |
+
receives an offer from the Licensor to exercise the
|
| 203 |
+
Licensed Rights under the terms and conditions of this
|
| 204 |
+
Public License.
|
| 205 |
+
|
| 206 |
+
b. No downstream restrictions. You may not offer or impose
|
| 207 |
+
any additional or different terms or conditions on, or
|
| 208 |
+
apply any Effective Technological Measures to, the
|
| 209 |
+
Licensed Material if doing so restricts exercise of the
|
| 210 |
+
Licensed Rights by any recipient of the Licensed
|
| 211 |
+
Material.
|
| 212 |
+
|
| 213 |
+
6. No endorsement. Nothing in this Public License constitutes or
|
| 214 |
+
may be construed as permission to assert or imply that You
|
| 215 |
+
are, or that Your use of the Licensed Material is, connected
|
| 216 |
+
with, or sponsored, endorsed, or granted official status by,
|
| 217 |
+
the Licensor or others designated to receive attribution as
|
| 218 |
+
provided in Section 3(a)(1)(A)(i).
|
| 219 |
+
|
| 220 |
+
b. Other rights.
|
| 221 |
+
|
| 222 |
+
1. Moral rights, such as the right of integrity, are not
|
| 223 |
+
licensed under this Public License, nor are publicity,
|
| 224 |
+
privacy, and/or other similar personality rights; however, to
|
| 225 |
+
the extent possible, the Licensor waives and/or agrees not to
|
| 226 |
+
assert any such rights held by the Licensor to the limited
|
| 227 |
+
extent necessary to allow You to exercise the Licensed
|
| 228 |
+
Rights, but not otherwise.
|
| 229 |
+
|
| 230 |
+
2. Patent and trademark rights are not licensed under this
|
| 231 |
+
Public License.
|
| 232 |
+
|
| 233 |
+
3. To the extent possible, the Licensor waives any right to
|
| 234 |
+
collect royalties from You for the exercise of the Licensed
|
| 235 |
+
Rights, whether directly or through a collecting society
|
| 236 |
+
under any voluntary or waivable statutory or compulsory
|
| 237 |
+
licensing scheme. In all other cases the Licensor expressly
|
| 238 |
+
reserves any right to collect such royalties, including when
|
| 239 |
+
the Licensed Material is used other than for NonCommercial
|
| 240 |
+
purposes.
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
Section 3 -- License Conditions.
|
| 244 |
+
|
| 245 |
+
Your exercise of the Licensed Rights is expressly made subject to the
|
| 246 |
+
following conditions.
|
| 247 |
+
|
| 248 |
+
a. Attribution.
|
| 249 |
+
|
| 250 |
+
1. If You Share the Licensed Material (including in modified
|
| 251 |
+
form), You must:
|
| 252 |
+
|
| 253 |
+
a. retain the following if it is supplied by the Licensor
|
| 254 |
+
with the Licensed Material:
|
| 255 |
+
|
| 256 |
+
i. identification of the creator(s) of the Licensed
|
| 257 |
+
Material and any others designated to receive
|
| 258 |
+
attribution, in any reasonable manner requested by
|
| 259 |
+
the Licensor (including by pseudonym if
|
| 260 |
+
designated);
|
| 261 |
+
|
| 262 |
+
ii. a copyright notice;
|
| 263 |
+
|
| 264 |
+
iii. a notice that refers to this Public License;
|
| 265 |
+
|
| 266 |
+
iv. a notice that refers to the disclaimer of
|
| 267 |
+
warranties;
|
| 268 |
+
|
| 269 |
+
v. a URI or hyperlink to the Licensed Material to the
|
| 270 |
+
extent reasonably practicable;
|
| 271 |
+
|
| 272 |
+
b. indicate if You modified the Licensed Material and
|
| 273 |
+
retain an indication of any previous modifications; and
|
| 274 |
+
|
| 275 |
+
c. indicate the Licensed Material is licensed under this
|
| 276 |
+
Public License, and include the text of, or the URI or
|
| 277 |
+
hyperlink to, this Public License.
|
| 278 |
+
|
| 279 |
+
2. You may satisfy the conditions in Section 3(a)(1) in any
|
| 280 |
+
reasonable manner based on the medium, means, and context in
|
| 281 |
+
which You Share the Licensed Material. For example, it may be
|
| 282 |
+
reasonable to satisfy the conditions by providing a URI or
|
| 283 |
+
hyperlink to a resource that includes the required
|
| 284 |
+
information.
|
| 285 |
+
|
| 286 |
+
3. If requested by the Licensor, You must remove any of the
|
| 287 |
+
information required by Section 3(a)(1)(A) to the extent
|
| 288 |
+
reasonably practicable.
|
| 289 |
+
|
| 290 |
+
4. If You Share Adapted Material You produce, the Adapter's
|
| 291 |
+
License You apply must not prevent recipients of the Adapted
|
| 292 |
+
Material from complying with this Public License.
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
Section 4 -- Sui Generis Database Rights.
|
| 296 |
+
|
| 297 |
+
Where the Licensed Rights include Sui Generis Database Rights that
|
| 298 |
+
apply to Your use of the Licensed Material:
|
| 299 |
+
|
| 300 |
+
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
| 301 |
+
to extract, reuse, reproduce, and Share all or a substantial
|
| 302 |
+
portion of the contents of the database for NonCommercial purposes
|
| 303 |
+
only;
|
| 304 |
+
|
| 305 |
+
b. if You include all or a substantial portion of the database
|
| 306 |
+
contents in a database in which You have Sui Generis Database
|
| 307 |
+
Rights, then the database in which You have Sui Generis Database
|
| 308 |
+
Rights (but not its individual contents) is Adapted Material; and
|
| 309 |
+
|
| 310 |
+
c. You must comply with the conditions in Section 3(a) if You Share
|
| 311 |
+
all or a substantial portion of the contents of the database.
|
| 312 |
+
|
| 313 |
+
For the avoidance of doubt, this Section 4 supplements and does not
|
| 314 |
+
replace Your obligations under this Public License where the Licensed
|
| 315 |
+
Rights include other Copyright and Similar Rights.
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
| 319 |
+
|
| 320 |
+
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
| 321 |
+
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
| 322 |
+
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
| 323 |
+
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
| 324 |
+
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
| 325 |
+
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
| 326 |
+
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
| 327 |
+
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
| 328 |
+
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
| 329 |
+
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
| 330 |
+
|
| 331 |
+
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
| 332 |
+
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
| 333 |
+
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
| 334 |
+
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
| 335 |
+
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
| 336 |
+
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
| 337 |
+
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
| 338 |
+
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
| 339 |
+
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
| 340 |
+
|
| 341 |
+
c. The disclaimer of warranties and limitation of liability provided
|
| 342 |
+
above shall be interpreted in a manner that, to the extent
|
| 343 |
+
possible, most closely approximates an absolute disclaimer and
|
| 344 |
+
waiver of all liability.
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
Section 6 -- Term and Termination.
|
| 348 |
+
|
| 349 |
+
a. This Public License applies for the term of the Copyright and
|
| 350 |
+
Similar Rights licensed here. However, if You fail to comply with
|
| 351 |
+
this Public License, then Your rights under this Public License
|
| 352 |
+
terminate automatically.
|
| 353 |
+
|
| 354 |
+
b. Where Your right to use the Licensed Material has terminated under
|
| 355 |
+
Section 6(a), it reinstates:
|
| 356 |
+
|
| 357 |
+
1. automatically as of the date the violation is cured, provided
|
| 358 |
+
it is cured within 30 days of Your discovery of the
|
| 359 |
+
violation; or
|
| 360 |
+
|
| 361 |
+
2. upon express reinstatement by the Licensor.
|
| 362 |
+
|
| 363 |
+
For the avoidance of doubt, this Section 6(b) does not affect any
|
| 364 |
+
right the Licensor may have to seek remedies for Your violations
|
| 365 |
+
of this Public License.
|
| 366 |
+
|
| 367 |
+
c. For the avoidance of doubt, the Licensor may also offer the
|
| 368 |
+
Licensed Material under separate terms or conditions or stop
|
| 369 |
+
distributing the Licensed Material at any time; however, doing so
|
| 370 |
+
will not terminate this Public License.
|
| 371 |
+
|
| 372 |
+
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
| 373 |
+
License.
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
Section 7 -- Other Terms and Conditions.
|
| 377 |
+
|
| 378 |
+
a. The Licensor shall not be bound by any additional or different
|
| 379 |
+
terms or conditions communicated by You unless expressly agreed.
|
| 380 |
+
|
| 381 |
+
b. Any arrangements, understandings, or agreements regarding the
|
| 382 |
+
Licensed Material not stated herein are separate from and
|
| 383 |
+
independent of the terms and conditions of this Public License.
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
Section 8 -- Interpretation.
|
| 387 |
+
|
| 388 |
+
a. For the avoidance of doubt, this Public License does not, and
|
| 389 |
+
shall not be interpreted to, reduce, limit, restrict, or impose
|
| 390 |
+
conditions on any use of the Licensed Material that could lawfully
|
| 391 |
+
be made without permission under this Public License.
|
| 392 |
+
|
| 393 |
+
b. To the extent possible, if any provision of this Public License is
|
| 394 |
+
deemed unenforceable, it shall be automatically reformed to the
|
| 395 |
+
minimum extent necessary to make it enforceable. If the provision
|
| 396 |
+
cannot be reformed, it shall be severed from this Public License
|
| 397 |
+
without affecting the enforceability of the remaining terms and
|
| 398 |
+
conditions.
|
| 399 |
+
|
| 400 |
+
c. No term or condition of this Public License will be waived and no
|
| 401 |
+
failure to comply consented to unless expressly agreed to by the
|
| 402 |
+
Licensor.
|
| 403 |
+
|
| 404 |
+
d. Nothing in this Public License constitutes or may be interpreted
|
| 405 |
+
as a limitation upon, or waiver of, any privileges and immunities
|
| 406 |
+
that apply to the Licensor or You, including from the legal
|
| 407 |
+
processes of any jurisdiction or authority.
|
| 408 |
+
|
| 409 |
+
=======================================================================
|
| 410 |
+
|
| 411 |
+
Creative Commons is not a party to its public
|
| 412 |
+
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
| 413 |
+
its public licenses to material it publishes and in those instances
|
| 414 |
+
will be considered the “Licensor.” The text of the Creative Commons
|
| 415 |
+
public licenses is dedicated to the public domain under the CC0 Public
|
| 416 |
+
Domain Dedication. Except for the limited purpose of indicating that
|
| 417 |
+
material is shared under a Creative Commons public license or as
|
| 418 |
+
otherwise permitted by the Creative Commons policies published at
|
| 419 |
+
creativecommons.org/policies, Creative Commons does not authorize the
|
| 420 |
+
use of the trademark "Creative Commons" or any other trademark or logo
|
| 421 |
+
of Creative Commons without its prior written consent including,
|
| 422 |
+
without limitation, in connection with any unauthorized modifications
|
| 423 |
+
to any of its public licenses or any other arrangements,
|
| 424 |
+
understandings, or agreements concerning use of licensed material. For
|
| 425 |
+
the avoidance of doubt, this paragraph does not form part of the
|
| 426 |
+
public licenses.
|
| 427 |
+
|
| 428 |
+
Creative Commons may be contacted at creativecommons.org.
|
| 429 |
+
|
lm/THIRD_PARTY_NOTICES.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Third-party code notices
|
| 2 |
+
|
| 3 |
+
The Oobleck VAE and SnakeBeta implementation in `modeling_vae.py` is derived
|
| 4 |
+
from stable-audio-tools commit `a6ae0cdf8b2eb1567a4b42ceadddec3712d99d45`.
|
| 5 |
+
The module hierarchy, weight normalization and activation equations preserve
|
| 6 |
+
the checkpoint's original inference implementation.
|
| 7 |
+
|
| 8 |
+
- Oobleck / stable-audio-tools: Copyright (c) 2023 Stability AI, MIT.
|
| 9 |
+
Full text: `licenses/stable-audio-tools-MIT.txt`.
|
| 10 |
+
- SnakeBeta / BigVGAN: Copyright (c) 2022 NVIDIA CORPORATION, MIT.
|
| 11 |
+
Full text: `licenses/SnakeBeta-NVIDIA-MIT.txt`.
|
| 12 |
+
|
| 13 |
+
These notices cover the identified source code and retain its original licenses.
|
| 14 |
+
The YuE2 model checkpoint weights are separately licensed under CC BY-NC 4.0;
|
| 15 |
+
see LICENSE for the scope and full terms. This does not relicense third-party code.
|
lm/config.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"return_dict": true,
|
| 3 |
+
"output_hidden_states": false,
|
| 4 |
+
"torchscript": false,
|
| 5 |
+
"dtype": "bfloat16",
|
| 6 |
+
"tie_word_embeddings": false,
|
| 7 |
+
"is_encoder_decoder": false,
|
| 8 |
+
"is_decoder": false,
|
| 9 |
+
"add_cross_attention": false,
|
| 10 |
+
"architectures": [
|
| 11 |
+
"YuE2ForCausalLM"
|
| 12 |
+
],
|
| 13 |
+
"bos_token_id": null,
|
| 14 |
+
"pad_token_id": null,
|
| 15 |
+
"eos_token_id": null,
|
| 16 |
+
"decoder_start_token_id": null,
|
| 17 |
+
"transformers_version": "4.57.6",
|
| 18 |
+
"auto_map": {
|
| 19 |
+
"AutoConfig": "modeling_yue2.YuE2Config",
|
| 20 |
+
"AutoModelForCausalLM": "modeling_yue2.YuE2ForCausalLM"
|
| 21 |
+
},
|
| 22 |
+
"model_type": "yue2",
|
| 23 |
+
"hidden_size": 2048,
|
| 24 |
+
"num_hidden_layers": 28,
|
| 25 |
+
"num_attention_heads": 16,
|
| 26 |
+
"num_key_value_heads": 8,
|
| 27 |
+
"head_dim": 128,
|
| 28 |
+
"intermediate_size": 6144,
|
| 29 |
+
"vocab_size": 184704,
|
| 30 |
+
"rms_norm_eps": 1e-06,
|
| 31 |
+
"rope_theta": 1000000,
|
| 32 |
+
"max_position_embeddings": 24576,
|
| 33 |
+
"latent_type": "vae",
|
| 34 |
+
"latent_dim": 64,
|
| 35 |
+
"max_latent_frames": 24576,
|
| 36 |
+
"timestep_shift": 1.0,
|
| 37 |
+
"output_attentions": false
|
| 38 |
+
}
|
lm/generation_config.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token_id": 151643,
|
| 3 |
+
"eos_token_id": 151852,
|
| 4 |
+
"pad_token_id": 151643,
|
| 5 |
+
"do_sample": true,
|
| 6 |
+
"temperature": 1.0,
|
| 7 |
+
"top_p": 0.95,
|
| 8 |
+
"top_k": 100,
|
| 9 |
+
"max_new_tokens": 9000,
|
| 10 |
+
"use_cache": true
|
| 11 |
+
}
|
lm/licenses/SnakeBeta-NVIDIA-MIT.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2022 NVIDIA CORPORATION.
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
lm/licenses/stable-audio-tools-MIT.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2023 Stability AI
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
lm/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1d55c42c1a9875c34f5d736e15078449992b044e807ce2a138e6cf289a1e59e9
|
| 3 |
+
size 7261441640
|
lm/modeling_yue2.py
ADDED
|
@@ -0,0 +1,705 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""YuE2 AR–NAR Mixture-of-Transformers, with checkpoint-compatible names.
|
| 2 |
+
|
| 3 |
+
This module is self contained for Transformers ``trust_remote_code`` loading.
|
| 4 |
+
It imports no CUDA extension and implements the released model architecture.
|
| 5 |
+
``generate`` returns token IDs; the package pipeline supplies song generation.
|
| 6 |
+
"""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import math
|
| 10 |
+
from typing import List, Optional, Tuple, Union
|
| 11 |
+
|
| 12 |
+
import torch
|
| 13 |
+
import torch.nn as nn
|
| 14 |
+
import torch.nn.functional as F
|
| 15 |
+
from transformers import GenerationMixin, PretrainedConfig, PreTrainedModel
|
| 16 |
+
from transformers.cache_utils import DynamicCache
|
| 17 |
+
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def sdpa(query, key, value, *, attn_mask=None, is_causal=False):
|
| 21 |
+
"""Use native grouped-query attention, including a portable MPS fallback."""
|
| 22 |
+
grouped = query.shape[1] != key.shape[1]
|
| 23 |
+
if grouped and query.device.type == "mps":
|
| 24 |
+
# PyTorch's MPS attention does not implement enable_gqa on every release.
|
| 25 |
+
groups = query.shape[1] // key.shape[1]
|
| 26 |
+
key = key.repeat_interleave(groups, dim=1)
|
| 27 |
+
value = value.repeat_interleave(groups, dim=1)
|
| 28 |
+
grouped = False
|
| 29 |
+
return F.scaled_dot_product_attention(
|
| 30 |
+
query, key, value, attn_mask=attn_mask, is_causal=is_causal,
|
| 31 |
+
enable_gqa=grouped,
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def _causal_mask(attention_mask, cache_position, key_length, batch_size):
|
| 36 |
+
"""Physical cache slots are causal; RoPE positions may exclude padding."""
|
| 37 |
+
device = cache_position.device
|
| 38 |
+
visible = torch.arange(key_length, device=device)[None, :] <= cache_position[:, None]
|
| 39 |
+
visible = visible[None, None].expand(batch_size, 1, -1, -1)
|
| 40 |
+
if attention_mask is None:
|
| 41 |
+
return visible
|
| 42 |
+
mask = attention_mask.to(device=device)
|
| 43 |
+
if mask.ndim == 2:
|
| 44 |
+
if mask.shape[0] != batch_size or mask.shape[1] > key_length:
|
| 45 |
+
raise ValueError("attention_mask must cover the batch and used cache slots")
|
| 46 |
+
# Static cache has unused capacity after the supplied 2D padding mask.
|
| 47 |
+
if mask.shape[1] < key_length:
|
| 48 |
+
mask = F.pad(mask, (0, key_length - mask.shape[1]), value=0)
|
| 49 |
+
return visible & mask[:, None, None, :].bool()
|
| 50 |
+
if mask.ndim != 4 or mask.shape[-2:] != visible.shape[-2:]:
|
| 51 |
+
raise ValueError("Expected a 2D padding mask or a matching 4D attention mask")
|
| 52 |
+
if mask.dtype == torch.bool:
|
| 53 |
+
return visible & mask
|
| 54 |
+
return mask.masked_fill(~visible, float("-inf"))
|
| 55 |
+
|
| 56 |
+
# ══════════════════════════════════════════════════════════════════════════════
|
| 57 |
+
# Config
|
| 58 |
+
# ══════════════════════════════════════════════════════════════════════════════
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class YuE2Config(PretrainedConfig):
|
| 62 |
+
model_type = "yue2"
|
| 63 |
+
|
| 64 |
+
_hf_fields = frozenset({
|
| 65 |
+
"model_type", "architectures", "auto_map", "transformers_version",
|
| 66 |
+
"dtype", "torch_dtype", "return_dict", "output_hidden_states",
|
| 67 |
+
"output_attentions", "use_cache", "tie_word_embeddings", "torchscript",
|
| 68 |
+
"is_decoder", "is_encoder_decoder", "add_cross_attention",
|
| 69 |
+
"bos_token_id", "eos_token_id", "pad_token_id", "decoder_start_token_id",
|
| 70 |
+
"attn_implementation",
|
| 71 |
+
})
|
| 72 |
+
|
| 73 |
+
def to_dict(self):
|
| 74 |
+
return {key: value for key, value in super().to_dict().items()
|
| 75 |
+
if key in self._hf_fields or key in self._inference_fields}
|
| 76 |
+
|
| 77 |
+
_inference_fields = frozenset(['hidden_size', 'num_hidden_layers', 'num_attention_heads', 'num_key_value_heads', 'head_dim', 'intermediate_size', 'vocab_size', 'rms_norm_eps', 'rope_theta', 'max_position_embeddings', 'tie_word_embeddings', 'latent_type', 'latent_dim', 'max_latent_frames', 'timestep_shift'])
|
| 78 |
+
|
| 79 |
+
def __init__(
|
| 80 |
+
self,
|
| 81 |
+
hidden_size: int = 2048,
|
| 82 |
+
num_hidden_layers: int = 28,
|
| 83 |
+
num_attention_heads: int = 16,
|
| 84 |
+
num_key_value_heads: int = 8,
|
| 85 |
+
head_dim: int = 128,
|
| 86 |
+
intermediate_size: int = 6144,
|
| 87 |
+
vocab_size: int = 184704,
|
| 88 |
+
rms_norm_eps: float = 1e-6,
|
| 89 |
+
rope_theta: float = 1000000.0,
|
| 90 |
+
max_position_embeddings: int = 24576,
|
| 91 |
+
tie_word_embeddings: bool = False,
|
| 92 |
+
# Acoustic inference architecture
|
| 93 |
+
latent_type: str = "vae",
|
| 94 |
+
latent_dim: int = 64,
|
| 95 |
+
max_latent_frames: int = 24576,
|
| 96 |
+
timestep_shift: float = 1.0,
|
| 97 |
+
**kwargs,
|
| 98 |
+
):
|
| 99 |
+
if latent_type != "vae":
|
| 100 |
+
raise ValueError("YuE2 inference supports only latent_type='vae'")
|
| 101 |
+
# Serialize only the documented model and Transformers configuration.
|
| 102 |
+
kwargs = {key: value for key, value in kwargs.items() if key in self._hf_fields}
|
| 103 |
+
super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs)
|
| 104 |
+
self.hidden_size = hidden_size
|
| 105 |
+
self.num_hidden_layers = num_hidden_layers
|
| 106 |
+
self.num_attention_heads = num_attention_heads
|
| 107 |
+
self.num_key_value_heads = num_key_value_heads
|
| 108 |
+
self.head_dim = head_dim
|
| 109 |
+
self.intermediate_size = intermediate_size
|
| 110 |
+
self.vocab_size = vocab_size
|
| 111 |
+
self.rms_norm_eps = rms_norm_eps
|
| 112 |
+
self.rope_theta = rope_theta
|
| 113 |
+
self.max_position_embeddings = max_position_embeddings
|
| 114 |
+
self.latent_type = latent_type
|
| 115 |
+
self.latent_dim = latent_dim
|
| 116 |
+
self.max_latent_frames = max_latent_frames
|
| 117 |
+
self.timestep_shift = timestep_shift
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
# ══════════════════════════════════════════════════════════════════════════════
|
| 121 |
+
# Building blocks
|
| 122 |
+
# ══════════════════════════════════════════════════════════════════════════════
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
class RMSNorm(nn.Module):
|
| 126 |
+
def __init__(self, dim: int, eps: float = 1e-6):
|
| 127 |
+
super().__init__()
|
| 128 |
+
self.weight = nn.Parameter(torch.ones(dim))
|
| 129 |
+
self.eps = eps
|
| 130 |
+
|
| 131 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 132 |
+
return x * torch.rsqrt(x.float().pow(2).mean(-1, keepdim=True) + self.eps).to(x.dtype) * self.weight
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
class RotaryEmbedding(nn.Module):
|
| 136 |
+
def __init__(self, head_dim: int, base: float = 1000000.0):
|
| 137 |
+
super().__init__()
|
| 138 |
+
self.head_dim = head_dim
|
| 139 |
+
self.base = base
|
| 140 |
+
self._inv_freq: Optional[torch.Tensor] = None
|
| 141 |
+
|
| 142 |
+
def forward(self, position_ids: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
|
| 143 |
+
if self._inv_freq is None or self._inv_freq.device != position_ids.device:
|
| 144 |
+
self._inv_freq = 1.0 / (self.base ** (
|
| 145 |
+
torch.arange(0, self.head_dim, 2, dtype=torch.float32, device=position_ids.device) / self.head_dim
|
| 146 |
+
))
|
| 147 |
+
pos = position_ids.float().unsqueeze(-1)
|
| 148 |
+
angles = pos * self._inv_freq
|
| 149 |
+
return angles.cos(), angles.sin()
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def _apply_rotary(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor) -> torch.Tensor:
|
| 153 |
+
half = x.shape[-1] // 2
|
| 154 |
+
x1, x2 = x[..., :half], x[..., half:]
|
| 155 |
+
cos, sin = cos.to(x.dtype), sin.to(x.dtype)
|
| 156 |
+
return torch.cat([x1 * cos - x2 * sin, x2 * cos + x1 * sin], dim=-1)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
class Attention(nn.Module):
|
| 160 |
+
def __init__(self, config: YuE2Config):
|
| 161 |
+
super().__init__()
|
| 162 |
+
self.num_heads = config.num_attention_heads
|
| 163 |
+
self.num_kv_heads = config.num_key_value_heads
|
| 164 |
+
self.head_dim = config.head_dim
|
| 165 |
+
self.num_kv_groups = self.num_heads // self.num_kv_heads
|
| 166 |
+
|
| 167 |
+
self.q_proj = nn.Linear(config.hidden_size, self.num_heads * self.head_dim, bias=False)
|
| 168 |
+
self.k_proj = nn.Linear(config.hidden_size, self.num_kv_heads * self.head_dim, bias=False)
|
| 169 |
+
self.v_proj = nn.Linear(config.hidden_size, self.num_kv_heads * self.head_dim, bias=False)
|
| 170 |
+
self.o_proj = nn.Linear(self.num_heads * self.head_dim, config.hidden_size, bias=False)
|
| 171 |
+
self.q_norm = RMSNorm(self.head_dim, config.rms_norm_eps)
|
| 172 |
+
self.k_norm = RMSNorm(self.head_dim, config.rms_norm_eps)
|
| 173 |
+
|
| 174 |
+
def project_qkv(
|
| 175 |
+
self, x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor,
|
| 176 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 177 |
+
"""Project, normalize, and apply RoPE. No SDPA, no KV cache, no O proj.
|
| 178 |
+
|
| 179 |
+
Returns Q [B,T,num_heads,hd], K [B,T,num_kv_heads,hd], V [B,T,num_kv_heads,hd].
|
| 180 |
+
"""
|
| 181 |
+
B, T, _ = x.shape
|
| 182 |
+
q = self.q_proj(x).view(B, T, self.num_heads, self.head_dim)
|
| 183 |
+
k = self.k_proj(x).view(B, T, self.num_kv_heads, self.head_dim)
|
| 184 |
+
v = self.v_proj(x).view(B, T, self.num_kv_heads, self.head_dim)
|
| 185 |
+
q, k = self.q_norm(q), self.k_norm(k)
|
| 186 |
+
rc, rs = cos.unsqueeze(2), sin.unsqueeze(2)
|
| 187 |
+
q = _apply_rotary(q, rc, rs)
|
| 188 |
+
k = _apply_rotary(k, rc, rs)
|
| 189 |
+
return q, k, v
|
| 190 |
+
|
| 191 |
+
def forward(
|
| 192 |
+
self,
|
| 193 |
+
x: torch.Tensor,
|
| 194 |
+
cos: torch.Tensor,
|
| 195 |
+
sin: torch.Tensor,
|
| 196 |
+
past_key_value: Optional[DynamicCache] = None,
|
| 197 |
+
layer_idx: int = 0,
|
| 198 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 199 |
+
cache_position: Optional[torch.Tensor] = None,
|
| 200 |
+
) -> torch.Tensor:
|
| 201 |
+
B, T, _ = x.shape
|
| 202 |
+
q, k, v = self.project_qkv(x, cos, sin)
|
| 203 |
+
|
| 204 |
+
q, k, v = q.transpose(1, 2), k.transpose(1, 2), v.transpose(1, 2)
|
| 205 |
+
|
| 206 |
+
if past_key_value is not None:
|
| 207 |
+
k, v = past_key_value.update(k, v, layer_idx, {"cache_position": cache_position})
|
| 208 |
+
|
| 209 |
+
if attention_mask is not None:
|
| 210 |
+
out = sdpa(q, k, v, attn_mask=attention_mask[..., :k.shape[2]])
|
| 211 |
+
else:
|
| 212 |
+
out = sdpa(q, k, v, is_causal=(T > 1 and k.shape[2] == T))
|
| 213 |
+
return self.o_proj(out.transpose(1, 2).reshape(B, T, -1))
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
class MLP(nn.Module):
|
| 217 |
+
def __init__(self, config: YuE2Config):
|
| 218 |
+
super().__init__()
|
| 219 |
+
self.gate_proj = nn.Linear(config.hidden_size, config.intermediate_size, bias=False)
|
| 220 |
+
self.up_proj = nn.Linear(config.hidden_size, config.intermediate_size, bias=False)
|
| 221 |
+
self.down_proj = nn.Linear(config.intermediate_size, config.hidden_size, bias=False)
|
| 222 |
+
|
| 223 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 224 |
+
return self.down_proj(F.silu(self.gate_proj(x)) * self.up_proj(x))
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
class DecoderLayer(nn.Module):
|
| 228 |
+
"""Transformer layer with full MoT: dual attention projections + dual MLP."""
|
| 229 |
+
|
| 230 |
+
def __init__(self, config: YuE2Config):
|
| 231 |
+
super().__init__()
|
| 232 |
+
# AR attention path
|
| 233 |
+
self.input_layernorm = RMSNorm(config.hidden_size, config.rms_norm_eps)
|
| 234 |
+
self.self_attn = Attention(config)
|
| 235 |
+
# NAR attention path (separate Q/K/V/O + layernorms)
|
| 236 |
+
self.nar_input_layernorm = RMSNorm(config.hidden_size, config.rms_norm_eps)
|
| 237 |
+
self.nar_self_attn = Attention(config)
|
| 238 |
+
# AR MLP path
|
| 239 |
+
self.post_attention_layernorm = RMSNorm(config.hidden_size, config.rms_norm_eps)
|
| 240 |
+
self.mlp = MLP(config)
|
| 241 |
+
# NAR MLP path
|
| 242 |
+
self.nar_pre_mlp_layernorm = RMSNorm(config.hidden_size, config.rms_norm_eps)
|
| 243 |
+
self.nar_mlp = MLP(config)
|
| 244 |
+
|
| 245 |
+
def forward(
|
| 246 |
+
self,
|
| 247 |
+
x: torch.Tensor,
|
| 248 |
+
cos: torch.Tensor,
|
| 249 |
+
sin: torch.Tensor,
|
| 250 |
+
past_key_value: Optional[DynamicCache] = None,
|
| 251 |
+
layer_idx: int = 0,
|
| 252 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 253 |
+
ar_mask: Optional[torch.Tensor] = None,
|
| 254 |
+
cache_position: Optional[torch.Tensor] = None,
|
| 255 |
+
) -> torch.Tensor:
|
| 256 |
+
if ar_mask is not None:
|
| 257 |
+
mask_3d = ar_mask.unsqueeze(-1) # [B, S, 1]
|
| 258 |
+
mask_4d = ar_mask.unsqueeze(-1).unsqueeze(-1) # [B, S, 1, 1]
|
| 259 |
+
|
| 260 |
+
# Per-type input layernorm
|
| 261 |
+
ln_ar = self.input_layernorm(x)
|
| 262 |
+
ln_nar = self.nar_input_layernorm(x)
|
| 263 |
+
|
| 264 |
+
# Per-type QKV projection (both process all tokens)
|
| 265 |
+
q_ar, k_ar, v_ar = self.self_attn.project_qkv(ln_ar, cos, sin)
|
| 266 |
+
q_nar, k_nar, v_nar = self.nar_self_attn.project_qkv(ln_nar, cos, sin)
|
| 267 |
+
|
| 268 |
+
# Merge Q/K/V per-position: AR positions use AR projections, NAR use NAR
|
| 269 |
+
query = torch.where(mask_4d, q_ar, q_nar) # [B, S, num_heads, hd]
|
| 270 |
+
# K/V have num_kv_heads (fewer), same mask broadcast works
|
| 271 |
+
key = torch.where(mask_4d, k_ar, k_nar) # [B, S, num_kv_heads, hd]
|
| 272 |
+
value = torch.where(mask_4d, v_ar, v_nar)
|
| 273 |
+
|
| 274 |
+
# Transpose to [B, H, S, D] for SDPA
|
| 275 |
+
B, S = x.shape[:2]
|
| 276 |
+
query = query.transpose(1, 2)
|
| 277 |
+
key = key.transpose(1, 2)
|
| 278 |
+
value = value.transpose(1, 2)
|
| 279 |
+
|
| 280 |
+
# Shared attention with hybrid mask
|
| 281 |
+
if attention_mask is not None and attention_mask.dtype != torch.bool:
|
| 282 |
+
attention_mask = attention_mask.to(query.dtype)
|
| 283 |
+
core_out = sdpa(query, key, value, attn_mask=attention_mask)
|
| 284 |
+
core_out = core_out.transpose(1, 2).reshape(B, S, -1)
|
| 285 |
+
|
| 286 |
+
# Per-type O projection, merge by mask
|
| 287 |
+
o_ar = self.self_attn.o_proj(core_out)
|
| 288 |
+
o_nar = self.nar_self_attn.o_proj(core_out)
|
| 289 |
+
h = torch.where(mask_3d, o_ar, o_nar)
|
| 290 |
+
x = x + h
|
| 291 |
+
|
| 292 |
+
# Per-type MLP
|
| 293 |
+
ar_out = self.mlp(self.post_attention_layernorm(x))
|
| 294 |
+
nar_out = self.nar_mlp(self.nar_pre_mlp_layernorm(x))
|
| 295 |
+
mlp_out = torch.where(mask_3d, ar_out, nar_out)
|
| 296 |
+
else:
|
| 297 |
+
# AR-only mode (generation): use AR path only
|
| 298 |
+
h = self.self_attn(self.input_layernorm(x), cos, sin, past_key_value, layer_idx,
|
| 299 |
+
attention_mask, cache_position)
|
| 300 |
+
x = x + h
|
| 301 |
+
mlp_out = self.mlp(self.post_attention_layernorm(x))
|
| 302 |
+
|
| 303 |
+
x = x + mlp_out
|
| 304 |
+
return x
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
# ══════════════════════════════════════════════════════════════════════════════
|
| 308 |
+
# NAR auxiliary modules
|
| 309 |
+
# ══════════════════════════════════════════════════════════════════════════════
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
class TimestepEmbedder(nn.Module):
|
| 313 |
+
"""Sinusoidal timestep → MLP → hidden_size (same as modules.py)."""
|
| 314 |
+
|
| 315 |
+
def __init__(self, hidden_size: int, frequency_embedding_size: int = 256):
|
| 316 |
+
super().__init__()
|
| 317 |
+
self.mlp = nn.Sequential(
|
| 318 |
+
nn.Linear(frequency_embedding_size, hidden_size),
|
| 319 |
+
nn.SiLU(),
|
| 320 |
+
nn.Linear(hidden_size, hidden_size),
|
| 321 |
+
)
|
| 322 |
+
self.frequency_embedding_size = frequency_embedding_size
|
| 323 |
+
|
| 324 |
+
def forward(self, t):
|
| 325 |
+
half = self.frequency_embedding_size // 2
|
| 326 |
+
freqs = torch.exp(
|
| 327 |
+
-math.log(10000) * torch.arange(half, device=t.device, dtype=torch.float32) / half
|
| 328 |
+
)
|
| 329 |
+
args = t.float().unsqueeze(-1) * freqs.unsqueeze(0)
|
| 330 |
+
emb = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
|
| 331 |
+
return self.mlp(emb.to(next(self.parameters()).dtype))
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
class AudioPositionEmbedding(nn.Module):
|
| 335 |
+
"""Non-learnable 1D sinusoidal PE for audio latent frames."""
|
| 336 |
+
|
| 337 |
+
def __init__(self, max_frames: int, hidden_size: int):
|
| 338 |
+
super().__init__()
|
| 339 |
+
pe = torch.zeros(max_frames, hidden_size)
|
| 340 |
+
position = torch.arange(0, max_frames, dtype=torch.float32).unsqueeze(1)
|
| 341 |
+
div_term = torch.exp(
|
| 342 |
+
torch.arange(0, hidden_size, 2, dtype=torch.float32) * (-math.log(10000.0) / hidden_size)
|
| 343 |
+
)
|
| 344 |
+
pe[:, 0::2] = torch.sin(position * div_term)
|
| 345 |
+
pe[:, 1::2] = torch.cos(position * div_term)
|
| 346 |
+
self.register_buffer("pe", pe)
|
| 347 |
+
|
| 348 |
+
def forward(self, position_ids):
|
| 349 |
+
return self.pe[position_ids]
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
# ══════════════════════════════════════════════════════════════════════════════
|
| 353 |
+
# Static KV Cache
|
| 354 |
+
# ══════════════════════════════════════════════════════════════════════════════
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
class StaticKVCache:
|
| 358 |
+
"""Bounded, append-only cache for the explicit single-request AR loop.
|
| 359 |
+
|
| 360 |
+
Returns views of the used prefix and never reallocates/copies its history.
|
| 361 |
+
Standard HF ``generate`` also supports Transformers' own StaticCache.
|
| 362 |
+
"""
|
| 363 |
+
|
| 364 |
+
def __init__(
|
| 365 |
+
self, num_layers: int, batch_size: int, num_kv_heads: int,
|
| 366 |
+
max_seq_len: int, head_dim: int, dtype: torch.dtype, device: torch.device,
|
| 367 |
+
):
|
| 368 |
+
self.num_layers = num_layers
|
| 369 |
+
self.max_seq_len = max_seq_len
|
| 370 |
+
self._seen_tokens = 0
|
| 371 |
+
self.key_cache: List[torch.Tensor] = [
|
| 372 |
+
torch.zeros(batch_size, num_kv_heads, max_seq_len, head_dim, dtype=dtype, device=device)
|
| 373 |
+
for _ in range(num_layers)
|
| 374 |
+
]
|
| 375 |
+
self.value_cache: List[torch.Tensor] = [
|
| 376 |
+
torch.zeros(batch_size, num_kv_heads, max_seq_len, head_dim, dtype=dtype, device=device)
|
| 377 |
+
for _ in range(num_layers)
|
| 378 |
+
]
|
| 379 |
+
|
| 380 |
+
def get_seq_length(self, layer_idx=0) -> int:
|
| 381 |
+
return self._seen_tokens
|
| 382 |
+
|
| 383 |
+
def update(self, key_states, value_states, layer_idx, cache_kwargs=None):
|
| 384 |
+
T = key_states.shape[2]
|
| 385 |
+
pos = self._seen_tokens
|
| 386 |
+
end = pos + T
|
| 387 |
+
if end > self.max_seq_len:
|
| 388 |
+
raise ValueError(f"KV cache capacity {self.max_seq_len} exceeded by {end}; generation was not shortened")
|
| 389 |
+
self.key_cache[layer_idx][:, :, pos:end] = key_states
|
| 390 |
+
self.value_cache[layer_idx][:, :, pos:end] = value_states
|
| 391 |
+
if layer_idx == self.num_layers - 1:
|
| 392 |
+
self._seen_tokens = end
|
| 393 |
+
return self.key_cache[layer_idx][:, :, :end], self.value_cache[layer_idx][:, :, :end]
|
| 394 |
+
|
| 395 |
+
def reset(self):
|
| 396 |
+
self._seen_tokens = 0
|
| 397 |
+
|
| 398 |
+
def reorder_cache(self, beam_idx):
|
| 399 |
+
self.key_cache = [v.index_select(0, beam_idx.to(v.device)) for v in self.key_cache]
|
| 400 |
+
self.value_cache = [v.index_select(0, beam_idx.to(v.device)) for v in self.value_cache]
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
# ══════════════════════════════════════════════════════════════════════════════
|
| 404 |
+
# Model
|
| 405 |
+
# ══════════════════════════════════════════════════════════════════════════════
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
class Backbone(nn.Module):
|
| 409 |
+
"""Transformer backbone with MoT dual MLP."""
|
| 410 |
+
|
| 411 |
+
def __init__(self, config: YuE2Config):
|
| 412 |
+
super().__init__()
|
| 413 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size)
|
| 414 |
+
self.layers = nn.ModuleList([DecoderLayer(config) for _ in range(config.num_hidden_layers)])
|
| 415 |
+
self.norm = RMSNorm(config.hidden_size, config.rms_norm_eps)
|
| 416 |
+
self.rotary_emb = RotaryEmbedding(config.head_dim, config.rope_theta)
|
| 417 |
+
|
| 418 |
+
def forward(
|
| 419 |
+
self,
|
| 420 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 421 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 422 |
+
past_key_values=None,
|
| 423 |
+
use_cache: bool = True,
|
| 424 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 425 |
+
ar_mask: Optional[torch.Tensor] = None,
|
| 426 |
+
inputs_embeds: Optional[torch.Tensor] = None,
|
| 427 |
+
cache_position: Optional[torch.Tensor] = None,
|
| 428 |
+
) -> Tuple[torch.Tensor, ...]:
|
| 429 |
+
if inputs_embeds is not None:
|
| 430 |
+
x = inputs_embeds
|
| 431 |
+
else:
|
| 432 |
+
x = self.embed_tokens(input_ids)
|
| 433 |
+
cos, sin = self.rotary_emb(position_ids)
|
| 434 |
+
|
| 435 |
+
if use_cache and past_key_values is None:
|
| 436 |
+
past_key_values = DynamicCache()
|
| 437 |
+
|
| 438 |
+
for i, layer in enumerate(self.layers):
|
| 439 |
+
x = layer(x, cos, sin, past_key_values if use_cache else None,
|
| 440 |
+
layer_idx=i, attention_mask=attention_mask, ar_mask=ar_mask,
|
| 441 |
+
cache_position=cache_position)
|
| 442 |
+
|
| 443 |
+
return self.norm(x), past_key_values
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
class YuE2PreTrainedModel(PreTrainedModel):
|
| 447 |
+
config_class = YuE2Config
|
| 448 |
+
base_model_prefix = "model"
|
| 449 |
+
supports_gradient_checkpointing = True
|
| 450 |
+
_no_split_modules = ["DecoderLayer"]
|
| 451 |
+
_supports_sdpa = True
|
| 452 |
+
|
| 453 |
+
def _init_weights(self, module):
|
| 454 |
+
if isinstance(module, nn.Linear):
|
| 455 |
+
nn.init.normal_(module.weight, std=0.01)
|
| 456 |
+
if module.bias is not None:
|
| 457 |
+
nn.init.zeros_(module.bias)
|
| 458 |
+
elif isinstance(module, nn.Embedding):
|
| 459 |
+
nn.init.normal_(module.weight, std=0.01)
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
class YuE2ForCausalLM(YuE2PreTrainedModel, GenerationMixin):
|
| 463 |
+
"""YuE2 model: AR causal LM (generate) + NAR flow matching (ODE)."""
|
| 464 |
+
|
| 465 |
+
def __init__(self, config: YuE2Config):
|
| 466 |
+
super().__init__(config)
|
| 467 |
+
self.model = Backbone(config)
|
| 468 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 469 |
+
|
| 470 |
+
# NAR auxiliary
|
| 471 |
+
self.llm2vae = nn.Linear(config.hidden_size, config.latent_dim)
|
| 472 |
+
self.vae2llm = nn.Linear(config.latent_dim, config.hidden_size)
|
| 473 |
+
self.time_embedder = TimestepEmbedder(config.hidden_size)
|
| 474 |
+
self.latent_pos_embed = AudioPositionEmbedding(config.max_latent_frames, config.hidden_size)
|
| 475 |
+
|
| 476 |
+
self.post_init()
|
| 477 |
+
|
| 478 |
+
def get_input_embeddings(self):
|
| 479 |
+
return self.model.embed_tokens
|
| 480 |
+
|
| 481 |
+
def set_input_embeddings(self, value):
|
| 482 |
+
self.model.embed_tokens = value
|
| 483 |
+
|
| 484 |
+
def get_output_embeddings(self):
|
| 485 |
+
return self.lm_head
|
| 486 |
+
|
| 487 |
+
def set_output_embeddings(self, new_embeddings):
|
| 488 |
+
self.lm_head = new_embeddings
|
| 489 |
+
|
| 490 |
+
# ── AR forward (standard causal LM, KV cached) ───────────────────
|
| 491 |
+
|
| 492 |
+
def forward(
|
| 493 |
+
self,
|
| 494 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 495 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 496 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 497 |
+
past_key_values=None,
|
| 498 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 499 |
+
labels: Optional[torch.LongTensor] = None,
|
| 500 |
+
use_cache: Optional[bool] = None,
|
| 501 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 502 |
+
logits_to_keep: Union[int, torch.Tensor] = 0,
|
| 503 |
+
return_dict: Optional[bool] = None,
|
| 504 |
+
**kwargs,
|
| 505 |
+
) -> Union[Tuple, CausalLMOutputWithPast]:
|
| 506 |
+
if (input_ids is None) == (inputs_embeds is None):
|
| 507 |
+
raise ValueError("Supply exactly one of input_ids or inputs_embeds")
|
| 508 |
+
use_cache = use_cache if use_cache is not None else getattr(self.config, "use_cache", True)
|
| 509 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 510 |
+
tensor = input_ids if input_ids is not None else inputs_embeds
|
| 511 |
+
batch_size, seq_len = tensor.shape[:2]
|
| 512 |
+
if not seq_len:
|
| 513 |
+
raise ValueError("Input must contain at least one token")
|
| 514 |
+
device = tensor.device
|
| 515 |
+
past_len = past_key_values.get_seq_length() if past_key_values is not None and use_cache else 0
|
| 516 |
+
if cache_position is None:
|
| 517 |
+
cache_position = torch.arange(past_len, past_len + seq_len, device=device)
|
| 518 |
+
else:
|
| 519 |
+
cache_position = cache_position.to(device=device, dtype=torch.long)
|
| 520 |
+
if cache_position.ndim != 1 or cache_position.numel() != seq_len:
|
| 521 |
+
raise ValueError("cache_position must identify each current token's physical cache slot")
|
| 522 |
+
if position_ids is None:
|
| 523 |
+
if attention_mask is not None and attention_mask.ndim == 2:
|
| 524 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
| 525 |
+
position_ids.masked_fill_(attention_mask == 0, 0)
|
| 526 |
+
position_ids = position_ids[:, -seq_len:].to(device)
|
| 527 |
+
else:
|
| 528 |
+
position_ids = cache_position[None]
|
| 529 |
+
else:
|
| 530 |
+
position_ids = position_ids.to(device=device, dtype=torch.long)
|
| 531 |
+
if position_ids.shape[-1] != seq_len:
|
| 532 |
+
raise ValueError("position_ids must cover the current input tokens")
|
| 533 |
+
|
| 534 |
+
key_length = past_len + seq_len
|
| 535 |
+
if use_cache and past_key_values is not None and hasattr(past_key_values, "get_max_cache_shape"):
|
| 536 |
+
capacity = past_key_values.get_max_cache_shape()
|
| 537 |
+
if capacity is not None and capacity > 0:
|
| 538 |
+
key_length = capacity
|
| 539 |
+
# No explicit mask is needed for unpadded prefill or single-token dynamic
|
| 540 |
+
# decode. Chunked prefill needs bottom-right causal alignment; a full
|
| 541 |
+
# static cache additionally needs to hide all unfilled slots.
|
| 542 |
+
needs_mask = attention_mask is not None or key_length != past_len + seq_len or (past_len > 0 and seq_len > 1)
|
| 543 |
+
causal_mask = _causal_mask(attention_mask, cache_position, key_length, batch_size) if needs_mask else None
|
| 544 |
+
hidden_states, past_key_values = self.model(
|
| 545 |
+
input_ids=input_ids, position_ids=position_ids,
|
| 546 |
+
past_key_values=past_key_values, use_cache=use_cache,
|
| 547 |
+
attention_mask=causal_mask, inputs_embeds=inputs_embeds,
|
| 548 |
+
cache_position=cache_position,
|
| 549 |
+
)
|
| 550 |
+
|
| 551 |
+
if isinstance(logits_to_keep, int):
|
| 552 |
+
if logits_to_keep < 0:
|
| 553 |
+
raise ValueError("logits_to_keep must be nonnegative")
|
| 554 |
+
selected = hidden_states[:, -logits_to_keep:, :] if logits_to_keep else hidden_states
|
| 555 |
+
else:
|
| 556 |
+
selected = hidden_states[:, logits_to_keep.to(device), :]
|
| 557 |
+
if labels is not None and selected.shape[1] != hidden_states.shape[1]:
|
| 558 |
+
raise ValueError("Loss computation requires logits_to_keep=0")
|
| 559 |
+
logits = self.lm_head(selected)
|
| 560 |
+
|
| 561 |
+
loss = None
|
| 562 |
+
if labels is not None:
|
| 563 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
| 564 |
+
shift_labels = labels[..., 1:].contiguous()
|
| 565 |
+
loss = F.cross_entropy(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1))
|
| 566 |
+
|
| 567 |
+
if not return_dict:
|
| 568 |
+
output = (logits, past_key_values) if use_cache else (logits,)
|
| 569 |
+
return ((loss,) + output) if loss is not None else output
|
| 570 |
+
return CausalLMOutputWithPast(loss=loss, logits=logits, past_key_values=past_key_values if use_cache else None)
|
| 571 |
+
|
| 572 |
+
def prepare_inputs_for_generation(
|
| 573 |
+
self, input_ids, past_key_values=None, attention_mask=None,
|
| 574 |
+
inputs_embeds=None, cache_position=None, position_ids=None, **kwargs,
|
| 575 |
+
):
|
| 576 |
+
"""Keep physical cache slots separate from padding-aware RoPE positions."""
|
| 577 |
+
past_len = past_key_values.get_seq_length() if past_key_values is not None else 0
|
| 578 |
+
if cache_position is None:
|
| 579 |
+
total = inputs_embeds.shape[1] if inputs_embeds is not None and past_len == 0 else input_ids.shape[1]
|
| 580 |
+
count = max(total - past_len, 1) if past_len else total
|
| 581 |
+
cache_position = torch.arange(past_len, past_len + count, device=input_ids.device)
|
| 582 |
+
count = cache_position.numel()
|
| 583 |
+
use_embeds = inputs_embeds is not None and past_len == 0
|
| 584 |
+
if use_embeds:
|
| 585 |
+
current_ids, current_embeds = None, inputs_embeds[:, -count:]
|
| 586 |
+
else:
|
| 587 |
+
current_ids, current_embeds = input_ids[:, -count:].contiguous(), None
|
| 588 |
+
if position_ids is None and attention_mask is not None and attention_mask.ndim == 2:
|
| 589 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
| 590 |
+
position_ids.masked_fill_(attention_mask == 0, 0)
|
| 591 |
+
if position_ids is not None:
|
| 592 |
+
position_ids = position_ids[:, -count:].contiguous()
|
| 593 |
+
return {
|
| 594 |
+
"input_ids": current_ids, "inputs_embeds": current_embeds,
|
| 595 |
+
"past_key_values": past_key_values, "attention_mask": attention_mask,
|
| 596 |
+
"position_ids": position_ids, "cache_position": cache_position,
|
| 597 |
+
"use_cache": kwargs.get("use_cache", True),
|
| 598 |
+
"logits_to_keep": kwargs.get("logits_to_keep", 1),
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
# ── NAR velocity (flow matching, no KV cache) ────────────────────
|
| 602 |
+
|
| 603 |
+
def _shift_t_value(self, t_value: float, device: torch.device, dtype: torch.dtype) -> torch.Tensor:
|
| 604 |
+
t_sig = torch.sigmoid(torch.tensor(t_value, dtype=dtype, device=device))
|
| 605 |
+
shift = self.config.timestep_shift
|
| 606 |
+
return shift * t_sig / (1 + (shift - 1) * t_sig)
|
| 607 |
+
|
| 608 |
+
@torch.no_grad()
|
| 609 |
+
def nar_velocity(
|
| 610 |
+
self,
|
| 611 |
+
tokens: torch.LongTensor,
|
| 612 |
+
ar_mask: torch.BoolTensor,
|
| 613 |
+
nar_mask: torch.BoolTensor,
|
| 614 |
+
nar_content_mask: torch.BoolTensor,
|
| 615 |
+
x_t: torch.Tensor,
|
| 616 |
+
t_value: float,
|
| 617 |
+
nar_cond_end: int = 0,
|
| 618 |
+
) -> torch.Tensor:
|
| 619 |
+
"""Compute v_theta(x_t, t) — flow-matching velocity field.
|
| 620 |
+
|
| 621 |
+
Args:
|
| 622 |
+
tokens: [1, S] full sequence (AR + NAR tokens)
|
| 623 |
+
ar_mask: [1, S] True for AR positions
|
| 624 |
+
nar_mask: [1, S] True for NAR positions
|
| 625 |
+
nar_content_mask: [1, S] True for actual latent positions (not LATENT_START/END)
|
| 626 |
+
x_t: [T_lat, D] current ODE state
|
| 627 |
+
t_value: raw timestep (will be sigmoid-shifted)
|
| 628 |
+
nar_cond_end: if > 0, NAR only sees positions < nar_cond_end (text-only mode)
|
| 629 |
+
Returns:
|
| 630 |
+
v_pred: [T_lat, D] predicted velocity
|
| 631 |
+
"""
|
| 632 |
+
device = tokens.device
|
| 633 |
+
dtype = next(self.parameters()).dtype
|
| 634 |
+
B, S = tokens.shape
|
| 635 |
+
|
| 636 |
+
# 1. Token embeddings
|
| 637 |
+
token_emb = self.model.embed_tokens(tokens) # [B, S, H]
|
| 638 |
+
|
| 639 |
+
# 2. Build latent hidden for ALL NAR positions (START + content + END)
|
| 640 |
+
# Training injects vae2llm(x_t) + time_emb + pos_emb at ALL NAR positions,
|
| 641 |
+
# including LATENT_START (clean=0) and LATENT_END (clean=0).
|
| 642 |
+
# NAR position IDs via cumsum: START=0, content=[1..T_lat], END=T_lat+1.
|
| 643 |
+
t_shifted = self._shift_t_value(t_value, device, dtype)
|
| 644 |
+
T_lat = x_t.shape[0]
|
| 645 |
+
|
| 646 |
+
nar_indices = nar_mask[0].nonzero(as_tuple=True)[0] # all NAR positions
|
| 647 |
+
content_indices = nar_content_mask[0].nonzero(as_tuple=True)[0]
|
| 648 |
+
N_nar = nar_indices.shape[0] # START + T_lat + END
|
| 649 |
+
|
| 650 |
+
# Build x_t for all NAR positions: zeros for START/END, actual x_t for content
|
| 651 |
+
x_nar = torch.zeros(N_nar, x_t.shape[1], device=device, dtype=dtype)
|
| 652 |
+
x_nar[1:1 + T_lat] = x_t.to(dtype) # content frames at positions [1, T_lat]
|
| 653 |
+
|
| 654 |
+
latent_hidden_nar = self.vae2llm(x_nar.unsqueeze(0)) # [1, N_nar, H]
|
| 655 |
+
|
| 656 |
+
# Timestep embedding (same t for all NAR positions)
|
| 657 |
+
time_emb = self.time_embedder(t_shifted.expand(N_nar)).unsqueeze(0)
|
| 658 |
+
latent_hidden_nar = latent_hidden_nar + time_emb
|
| 659 |
+
|
| 660 |
+
# Position embedding: cumsum-style [0, 1, 2, ..., N_nar-1]
|
| 661 |
+
pos_ids = torch.arange(N_nar, device=device).clamp(max=self.config.max_latent_frames - 1)
|
| 662 |
+
pos_emb = self.latent_pos_embed(pos_ids).unsqueeze(0)
|
| 663 |
+
latent_hidden_nar = latent_hidden_nar + pos_emb
|
| 664 |
+
|
| 665 |
+
# Inject at ALL NAR positions (matching training's torch.where)
|
| 666 |
+
token_emb[0, nar_indices] = latent_hidden_nar[0]
|
| 667 |
+
|
| 668 |
+
# 3. Build hybrid attention mask [B, 1, S, S]
|
| 669 |
+
# AR→AR: causal, NAR→AR: full, NAR→NAR: bidirectional, AR→NAR: blocked
|
| 670 |
+
ar_q = ar_mask.unsqueeze(2).float() # [B, S, 1]
|
| 671 |
+
ar_k = ar_mask.unsqueeze(1).float() # [B, 1, S]
|
| 672 |
+
nar_q = nar_mask.unsqueeze(2).float()
|
| 673 |
+
nar_k = nar_mask.unsqueeze(1).float()
|
| 674 |
+
causal = torch.tril(torch.ones(S, S, device=device))
|
| 675 |
+
|
| 676 |
+
if nar_cond_end > 0:
|
| 677 |
+
# Codec dropout: NAR only sees positions < nar_cond_end (text) + NAR
|
| 678 |
+
text_k = torch.zeros(1, 1, S, device=device)
|
| 679 |
+
text_k[0, 0, :nar_cond_end] = 1.0
|
| 680 |
+
mask = (ar_q * ar_k * causal) + (nar_q * text_k) + (nar_q * nar_k)
|
| 681 |
+
else:
|
| 682 |
+
mask = (ar_q * ar_k * causal) + (nar_q * ar_k) + (nar_q * nar_k)
|
| 683 |
+
# Convert to additive: 0 → attend, -inf → block
|
| 684 |
+
attn_mask = mask.unsqueeze(1) # [B, 1, S, S]
|
| 685 |
+
attn_mask = attn_mask.masked_fill(attn_mask == 0, float("-inf")).masked_fill(attn_mask > 0, 0.0)
|
| 686 |
+
|
| 687 |
+
# 4. Position IDs + RoPE
|
| 688 |
+
position_ids = torch.arange(S, device=device).unsqueeze(0)
|
| 689 |
+
|
| 690 |
+
# 5. Forward through decoder (with MoT routing)
|
| 691 |
+
ar_mask_bt = ar_mask # [B, S] bool for MoT routing
|
| 692 |
+
hidden_states, _ = self.model(
|
| 693 |
+
inputs_embeds=token_emb, position_ids=position_ids,
|
| 694 |
+
use_cache=False, attention_mask=attn_mask, ar_mask=ar_mask_bt,
|
| 695 |
+
)
|
| 696 |
+
|
| 697 |
+
# 6. NAR head at content positions
|
| 698 |
+
nar_pred = self.llm2vae(hidden_states) # [B, S, D]
|
| 699 |
+
v_pred = nar_pred[0, content_indices] # [T_lat, D]
|
| 700 |
+
return v_pred
|
| 701 |
+
|
| 702 |
+
# Keep custom code + auto_map when a local user calls save_pretrained as well
|
| 703 |
+
# as when the release builder creates a Hub repository.
|
| 704 |
+
YuE2Config.register_for_auto_class()
|
| 705 |
+
YuE2ForCausalLM.register_for_auto_class("AutoModelForCausalLM")
|
lm/qwen.tiktoken
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
lm/weights_manifest.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": 1,
|
| 3 |
+
"files": {
|
| 4 |
+
"model.safetensors": {
|
| 5 |
+
"bytes": 7261441640,
|
| 6 |
+
"sha256": "1d55c42c1a9875c34f5d736e15078449992b044e807ce2a138e6cf289a1e59e9"
|
| 7 |
+
}
|
| 8 |
+
}
|
| 9 |
+
}
|
lm/yue2_generation_config.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"abc": {
|
| 3 |
+
"temperature": 0.7,
|
| 4 |
+
"top_p": 0.9,
|
| 5 |
+
"top_k": 30,
|
| 6 |
+
"repetition_penalty": 1.005,
|
| 7 |
+
"penalty_window": 100,
|
| 8 |
+
"min_tokens": 32,
|
| 9 |
+
"max_tokens": 4096
|
| 10 |
+
},
|
| 11 |
+
"semantic": {
|
| 12 |
+
"temperature": 1.0,
|
| 13 |
+
"top_p": 0.95,
|
| 14 |
+
"top_k": 100,
|
| 15 |
+
"repetition_penalty": 1.2,
|
| 16 |
+
"penalty_window": 50,
|
| 17 |
+
"min_tokens": 200,
|
| 18 |
+
"max_tokens": 9000
|
| 19 |
+
},
|
| 20 |
+
"ode_steps": 32,
|
| 21 |
+
"ode_method": "midpoint",
|
| 22 |
+
"context": 24576,
|
| 23 |
+
"version": "yue2-native-v1"
|
| 24 |
+
}
|