Commit ·
1a96eca
0
Parent(s):
Release YuE2-3B
Browse files- .gitattributes +44 -0
- LICENSE +429 -0
- README.md +364 -0
- THIRD_PARTY_NOTICES.md +15 -0
- assets/architecture.png +3 -0
- assets/audio/auld-lang-syne-jazz-funk-cover.mp3 +3 -0
- assets/audio/cyber-metal.mp3 +3 -0
- assets/audio/examples.json +111 -0
- assets/audio/jingle-bells-heavy-metal-cover.mp3 +3 -0
- assets/audio/passion.mp3 +3 -0
- assets/audio/tonight-awake.mp3 +3 -0
- assets/audio/zuixuan-ballad-cover.mp3 +3 -0
- assets/figure1.png +3 -0
- assets/logo.png +0 -0
- config.json +38 -0
- examples/tonight-awake.json +11 -0
- generation_config.json +11 -0
- licenses/SnakeBeta-NVIDIA-MIT.txt +21 -0
- licenses/stable-audio-tools-MIT.txt +21 -0
- model.safetensors +3 -0
- modeling_yue2.py +705 -0
- qwen.tiktoken +0 -0
- weights_manifest.json +9 -0
- yue2_generation_config.json +24 -0
- yue2_infer-0.1.3-py3-none-any.whl +0 -0
- yue2_infer-0.1.5-py3-none-any.whl +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
assets/figure1.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
assets/architecture.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
assets/audio/no-tomorrow.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
assets/audio/passion.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
assets/audio/tonight-awake.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
assets/audio/auld-lang-syne-jazz-funk-cover.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
assets/audio/zuixuan-ballad-cover.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
assets/audio/jingle-bells-heavy-metal-cover.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
assets/audio/cyber-metal.mp3 filter=lfs diff=lfs merge=lfs -text
|
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 |
+
|
README.md
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-4.0
|
| 3 |
+
language:
|
| 4 |
+
- zh
|
| 5 |
+
- en
|
| 6 |
+
pipeline_tag: text-to-audio
|
| 7 |
+
tags:
|
| 8 |
+
- music-generation
|
| 9 |
+
- symbolic-planning
|
| 10 |
+
- agentic-editing
|
| 11 |
+
- custom_code
|
| 12 |
+
---
|
| 13 |
+
<p align="center">
|
| 14 |
+
<img src="assets/logo.png" alt="YuE logo" width="144" />
|
| 15 |
+
</p>
|
| 16 |
+
<h1 align="center">🤗 YuE2-3B</h1>
|
| 17 |
+
<p align="center"><strong>Frontier music generation with editable scores</strong></p>
|
| 18 |
+
|
| 19 |
+
<p align="center">
|
| 20 |
+
<a href="https://github.com/multimodal-art-projection/YuE"><img alt="GitHub" src="https://img.shields.io/badge/GitHub-YuE-181717?logo=github&logoColor=white" height="20" /></a>
|
| 21 |
+
|
| 22 |
+
<a href="https://discord.gg/ssAyWMnMzu"><img alt="Join Discord" src="https://img.shields.io/discord/842440537755353128?label=Discord&color=5865F2&logo=discord&logoColor=white" height="20" /></a>
|
| 23 |
+
</p>
|
| 24 |
+
<p align="center">
|
| 25 |
+
<a href="https://map-yue2.github.io/">🎧 Demo</a>
|
| 26 |
+
·
|
| 27 |
+
<a href="#quick-start">🚀 Quick start</a>
|
| 28 |
+
·
|
| 29 |
+
<a href="#cover-an-existing-song">🎙️ Cover</a>
|
| 30 |
+
·
|
| 31 |
+
<a href="#export-a-plan-edit-it-and-generate">🤖 Edit</a>
|
| 32 |
+
·
|
| 33 |
+
<a href="#speed-and-resources" title="Speed and resources">⚡ Speed</a>
|
| 34 |
+
·
|
| 35 |
+
<a href="#benchmarks">📊 Benchmarks</a>
|
| 36 |
+
·
|
| 37 |
+
<a href="#citation">📚 Citation</a>
|
| 38 |
+
</p>
|
| 39 |
+
<p align="center">
|
| 40 |
+
<a href="https://huggingface.co/m-a-p/YuE2-3B"><img alt="🤗 YuE2-3B" src="https://img.shields.io/badge/YuE2--3B-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 41 |
+
|
| 42 |
+
<a href="https://huggingface.co/m-a-p/YuE2-Vae"><img alt="🤗 YuE2-Vae" src="https://img.shields.io/badge/YuE2--Vae-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 43 |
+
|
| 44 |
+
<a href="https://huggingface.co/m-a-p/YuE2-Vae-legacy"><img alt="🤗 YuE2-Vae-legacy" src="https://img.shields.io/badge/YuE2--Vae--legacy-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 45 |
+
|
| 46 |
+
<a href="https://huggingface.co/m-a-p/MERT-v2-30s"><img alt="🤗 MERT-v2-30s" src="https://img.shields.io/badge/MERT--v2--30s-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 47 |
+
|
| 48 |
+
<a href="https://huggingface.co/m-a-p/MERT-v2-FullSong"><img alt="🤗 MERT-v2-FullSong" src="https://img.shields.io/badge/MERT--v2--FullSong-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 49 |
+
|
| 50 |
+
<a href="https://huggingface.co/datasets/m-a-p/WildSongBench"><img alt="🤗 WildSongBench" src="https://img.shields.io/badge/WildSongBench-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 51 |
+
|
| 52 |
+
<a href="https://huggingface.co/m-a-p/SheetSage2"><img alt="SheetSage2" src="https://img.shields.io/badge/SheetSage2-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 53 |
+
</p>
|
| 54 |
+
|
| 55 |
+
**YuE2 is an open music generation model that rivals Suno v5.** Turn lyrics and a style prompt into a complete song with vocals and accompaniment, then shape its melody and chords through an editable score.
|
| 56 |
+
|
| 57 |
+
**State-of-the-art results on WildSongBench.** YuE2 (best-of-8) achieves the highest SongBench average among all evaluated open and proprietary models: **6.9632**, compared with **6.8721** for Suno v5.
|
| 58 |
+
|
| 59 |
+

|
| 60 |
+
|
| 61 |
+
*Frontier song quality and text alignment on 192 WildSongBench prompts. YuE2 uses symbolic planning; Bo8 means best-of-8.*
|
| 62 |
+
|
| 63 |
+
- **Compose and edit:** melody + chords, melody-only, or direct generation; bring your own ABC score.
|
| 64 |
+
- **Edit with an agent:** turn musical feedback into score, style and lyric revisions, then let YuE2 render the next version. [Hear the editing process](https://map-yue2.github.io/#agentic-music-editing).
|
| 65 |
+
- **Run locally:** 48 kHz stereo songs on a 24GB GPU, without quantization.
|
| 66 |
+
- **Build on it:** Hugging Face loading, text guidance (CFG), and separate planning and synthesis APIs.
|
| 67 |
+
|
| 68 |
+

|
| 69 |
+
|
| 70 |
+
*One AR–NAR Mixture-of-Transformers backbone writes the score and semantic tokens, then generates acoustic latents through flow matching. The VAE turns them into stereo audio.*
|
| 71 |
+
|
| 72 |
+
<a id="listen"></a>
|
| 73 |
+
|
| 74 |
+
## 🎧 Listen to YuE2
|
| 75 |
+
|
| 76 |
+
<a id="text-to-music"></a>
|
| 77 |
+
|
| 78 |
+
### 🎶 Text-to-music
|
| 79 |
+
|
| 80 |
+
Original songs generated from lyrics and a style prompt.
|
| 81 |
+
|
| 82 |
+
**Cyber Metal · English · 5:00**
|
| 83 |
+
|
| 84 |
+
<audio controls preload="none" aria-label="Cyber Metal" src="https://huggingface.co/m-a-p/YuE2-3B/resolve/main/assets/audio/cyber-metal.mp3"></audio>
|
| 85 |
+
|
| 86 |
+
**今晚不眠 · Mandarin funk / nu-disco · 3:24**
|
| 87 |
+
|
| 88 |
+
<audio controls preload="none" aria-label="今晚不眠" src="https://huggingface.co/m-a-p/YuE2-3B/resolve/main/assets/audio/tonight-awake.mp3"></audio>
|
| 89 |
+
|
| 90 |
+
**Passion · English rock · 3:55**
|
| 91 |
+
|
| 92 |
+
<audio controls preload="none" aria-label="Passion" src="https://huggingface.co/m-a-p/YuE2-3B/resolve/main/assets/audio/passion.mp3"></audio>
|
| 93 |
+
|
| 94 |
+
*All three songs use [🤗 YuE2-Vae](https://huggingface.co/m-a-p/YuE2-Vae).*
|
| 95 |
+
|
| 96 |
+
<a id="cover-song"></a>
|
| 97 |
+
|
| 98 |
+
### 🎙️ Cover songs
|
| 99 |
+
|
| 100 |
+
Existing songs reimagined in a new style.
|
| 101 |
+
|
| 102 |
+
[Make your own cover →](#cover-an-existing-song)
|
| 103 |
+
|
| 104 |
+
**Auld Lang Syne · Jazz-funk cover · 3:10**
|
| 105 |
+
|
| 106 |
+
<audio controls preload="none" aria-label="Auld Lang Syne — Jazz-funk cover" src="https://huggingface.co/m-a-p/YuE2-3B/resolve/main/assets/audio/auld-lang-syne-jazz-funk-cover.mp3"></audio>
|
| 107 |
+
|
| 108 |
+
**最炫民族风 · Ballad cover · 4:45**
|
| 109 |
+
|
| 110 |
+
<audio controls preload="none" aria-label="最炫民族风 — Ballad cover" src="https://huggingface.co/m-a-p/YuE2-3B/resolve/main/assets/audio/zuixuan-ballad-cover.mp3"></audio>
|
| 111 |
+
|
| 112 |
+
**Jingle Bells · Heavy metal cover · 1:09**
|
| 113 |
+
|
| 114 |
+
<audio controls preload="none" aria-label="Jingle Bells — Heavy metal cover" src="https://huggingface.co/m-a-p/YuE2-3B/resolve/main/assets/audio/jingle-bells-heavy-metal-cover.mp3"></audio>
|
| 115 |
+
|
| 116 |
+
<a id="agentic-editing"></a>
|
| 117 |
+
|
| 118 |
+
### 🤖 Agentic editing
|
| 119 |
+
|
| 120 |
+
**[Explore the agentic editing demo →](https://map-yue2.github.io/#agentic-music-editing)**
|
| 121 |
+
|
| 122 |
+
Follow **The Last Train** through **9 steps and 14 versions**, from Mandarin pop to English jazz with modern harmony and a saxophone solo built around two complete statements of “Twinkle, Twinkle, Little Star.” Hear the full songs and inspect the conversation, scores, prompts and lyrics at each step.
|
| 123 |
+
|
| 124 |
+
[Try editing with an agent →](#export-a-plan-edit-it-and-generate)
|
| 125 |
+
|
| 126 |
+
<a id="quick-start"></a>
|
| 127 |
+
|
| 128 |
+
## 🚀 Quick start
|
| 129 |
+
|
| 130 |
+
Linux · Python 3.10+ · 24GB NVIDIA GPU with BF16 support. Install the inference package:
|
| 131 |
+
|
| 132 |
+
```bash
|
| 133 |
+
python -m pip install huggingface-hub==0.36.2
|
| 134 |
+
hf download m-a-p/YuE2-3B yue2_infer-0.1.5-py3-none-any.whl --local-dir .
|
| 135 |
+
python -m pip install ./yue2_infer-0.1.5-py3-none-any.whl
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
[Create](#generate-a-song) · [Cover](#cover-an-existing-song) · [Edit & agentic edit](#export-a-plan-edit-it-and-generate)
|
| 139 |
+
|
| 140 |
+
Load the pipeline once for the examples below:
|
| 141 |
+
|
| 142 |
+
```python
|
| 143 |
+
from pathlib import Path
|
| 144 |
+
from yue2 import YuE2Pipeline
|
| 145 |
+
|
| 146 |
+
pipe = YuE2Pipeline.from_pretrained("m-a-p/YuE2-3B", device="cuda")
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
<a id="generate-a-song"></a>
|
| 150 |
+
|
| 151 |
+
### 🎶 Create
|
| 152 |
+
|
| 153 |
+
Turn a style prompt and lyrics into a complete song with vocals and accompaniment.
|
| 154 |
+
|
| 155 |
+
Use the [style and full lyrics from 今晚不眠](examples/tonight-awake.json), the funk / nu-disco demo above.
|
| 156 |
+
|
| 157 |
+
```python
|
| 158 |
+
import json
|
| 159 |
+
from huggingface_hub import hf_hub_download
|
| 160 |
+
|
| 161 |
+
repo = "m-a-p/YuE2-3B"
|
| 162 |
+
prompt_path = hf_hub_download(repo, "examples/tonight-awake.json")
|
| 163 |
+
demo = json.loads(Path(prompt_path).read_text(encoding="utf-8"))
|
| 164 |
+
style, lyrics = demo["style"], demo["lyrics"]
|
| 165 |
+
|
| 166 |
+
song = pipe(style=style, lyrics=lyrics, cot="full", seed=demo["seed"])
|
| 167 |
+
song.save("song.flac")
|
| 168 |
+
song.save_artifacts("outputs/song") # ABC, tokens, latents, audio and settings
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
Defaults are ready to use: `cot="full"` and [🤗 YuE2-Vae](https://huggingface.co/m-a-p/YuE2-Vae).
|
| 172 |
+
|
| 173 |
+
| Option | What it does |
|
| 174 |
+
|---|---|
|
| 175 |
+
| `cot="full"` | Melody + chord planning (default) |
|
| 176 |
+
| `cot="melody"` | Melody-only planning; recommended for covers |
|
| 177 |
+
| `cot="off"` | Generate without a symbolic plan |
|
| 178 |
+
| `cfg_scale=1.2` | Experiment with stronger text guidance |
|
| 179 |
+
|
| 180 |
+
<a id="cover-an-existing-song"></a>
|
| 181 |
+
|
| 182 |
+
### 🎙️ Cover
|
| 183 |
+
|
| 184 |
+
Start from an existing recording and give it a new arrangement.
|
| 185 |
+
|
| 186 |
+
**For covers, we recommend melody-only mode (`cot="melody"`).**
|
| 187 |
+
|
| 188 |
+
1. **Get the score:** transcribe the existing song with [🤗 SheetSage2](https://huggingface.co/m-a-p/SheetSage2) and save its melody ABC **without chord symbols** as `melody.abc`.
|
| 189 |
+
2. **Get the lyrics:** ask an agent to find them online, or transcribe the singing with [Qwen3-ASR](https://huggingface.co/Qwen/Qwen3-ASR-1.7B) or the [Gemini API](https://ai.google.dev/gemini-api/docs/audio). Check the words, organize them into sections matching the recording, and save them as `cover_lyrics.txt`.
|
| 190 |
+
3. **Choose a target style and generate:** review or edit the score and lyrics, then supply them to YuE2 with `cot="melody"` and your target style prompt.
|
| 191 |
+
|
| 192 |
+
Run the transcription tools in their own environments, then use the YuE2 pipeline:
|
| 193 |
+
|
| 194 |
+
```python
|
| 195 |
+
cover = pipe(
|
| 196 |
+
style="Jazz-funk, warm lead vocal, Rhodes piano, electric bass, tight drums",
|
| 197 |
+
lyrics=Path("cover_lyrics.txt").read_text(encoding="utf-8"),
|
| 198 |
+
abc=Path("melody.abc").read_text(encoding="utf-8"),
|
| 199 |
+
cot="melody", seed=831001,
|
| 200 |
+
)
|
| 201 |
+
cover.save("cover.flac")
|
| 202 |
+
cover.save_artifacts("outputs/cover")
|
| 203 |
+
```
|
| 204 |
+
|
| 205 |
+
`cot="melody"` does not remove chord symbols automatically. Use `cot="full"` if you want to supply the original or edited harmony as well.
|
| 206 |
+
|
| 207 |
+
<a id="export-a-plan-edit-it-and-generate"></a>
|
| 208 |
+
|
| 209 |
+
### 🎼 Edit & agentic edit
|
| 210 |
+
|
| 211 |
+
Edit the ABC yourself, or give an agent the score, original prompt and lyrics, and your requested changes. The agent can reharmonize, develop a solo, or adapt the lyrics and style; YuE2 renders each revision. [Hear the multi-turn editing demo](https://map-yue2.github.io/#agentic-music-editing).
|
| 212 |
+
|
| 213 |
+
For the song from **Create**, copy `outputs/song/score.abc` to `edited.abc`. To obtain a plan before generating audio, use the same prompt and seed:
|
| 214 |
+
|
| 215 |
+
```python
|
| 216 |
+
plan = pipe.plan(style=style, lyrics=lyrics, cot="full", seed=demo["seed"])
|
| 217 |
+
plan.save("original_plan")
|
| 218 |
+
# Keep the original and edit a copy as edited.abc.
|
| 219 |
+
```
|
| 220 |
+
|
| 221 |
+
For strict reharmonization, ask the agent to preserve melody pitches and rhythm and check sustained notes against the new chords. Allow selected melody or lyric changes for a broader adaptation. After reviewing `edited.abc`, regenerate with the revised style; this example keeps the lyrics and seed from **Create**:
|
| 222 |
+
|
| 223 |
+
```python
|
| 224 |
+
edited_style = (
|
| 225 |
+
"Jazz, expressive lead vocal, piano, tenor saxophone, upright bass, "
|
| 226 |
+
"brushed drums, no guitar, spacious modern harmony"
|
| 227 |
+
)
|
| 228 |
+
song = pipe(style=edited_style, lyrics=lyrics, cot="full", seed=demo["seed"],
|
| 229 |
+
abc=Path("edited.abc").read_text(encoding="utf-8"))
|
| 230 |
+
song.save("edited.flac")
|
| 231 |
+
song.save_artifacts("outputs/edited")
|
| 232 |
+
```
|
| 233 |
+
|
| 234 |
+
<details>
|
| 235 |
+
<summary>⚙️ CFG, individual stages, and decoder selection</summary>
|
| 236 |
+
|
| 237 |
+
Generation shows English progress messages by default, including the current stage, elapsed time, and token throughput. To disable them, use `YuE2Pipeline.from_pretrained(repo, progress=False)` in Python or `yue2 generate --quiet` / `yue2 batch --quiet` on the command line.
|
| 238 |
+
|
| 239 |
+
Each CoT mode selects its native instruction. Semantic CFG defaults to 1.0 for full/melody and 1.01 for off; ABC sampling uses no CFG.
|
| 240 |
+
|
| 241 |
+
`pipe.plan()` → `pipe.generate_semantic(plan)` → `pipe.synthesize(semantic)` → `pipe.decode(latents)`. Call `pipe.close()` when finished. For the benchmark decoder, pass `vae="m-a-p/YuE2-Vae-legacy"` to `from_pretrained`.
|
| 242 |
+
|
| 243 |
+
</details>
|
| 244 |
+
|
| 245 |
+
<a id="speed-and-resources"></a>
|
| 246 |
+
|
| 247 |
+
## ⚡ Speed and resources
|
| 248 |
+
|
| 249 |
+
**A 3.6-minute song in 71 seconds on an RTX 4090.** The HF package uses PyTorch, CUDA graphs, and FlashAttention, with BF16 AR/NAR and FP32 VAE.
|
| 250 |
+
|
| 251 |
+
| GPU | CoT | Warm samples | LM tokens/s | Generation / audio | Peak VRAM |
|
| 252 |
+
|---|---|---:|---:|---:|---:|
|
| 253 |
+
| RTX 4090 24GB | full | 32 | 139.48 | 71.04 / 214.85 s | 11.18 GiB |
|
| 254 |
+
| RTX 4090 24GB | melody | 32 | 139.32 | 68.68 / 214.67 s | 11.02 GiB |
|
| 255 |
+
| RTX 4090 24GB | off | 32 | 121.07 | 57.91 / 196.88 s | 11.09 GiB |
|
| 256 |
+
| H800 80GB | full | 1 | 164.38 | 54.74 / 224.96 s | 10.34 GiB |
|
| 257 |
+
|
| 258 |
+
One song at a time. Use a **24GB GPU** and **24GB available host RAM**; maximum-context testing peaked at **14.08 GiB**.
|
| 259 |
+
|
| 260 |
+
**H800 server · vLLM 0.19 · full CoT.** This separate serving runtime handles concurrent requests:
|
| 261 |
+
|
| 262 |
+
| AR concurrency limit | LM system tokens/s | Songs/hour | Peak VRAM |
|
| 263 |
+
|---:|---:|---:|---:|
|
| 264 |
+
| 1 | 378.42 | 119.43 | 78.55 GiB |
|
| 265 |
+
| 16 | 2418.63 | 340.38 | 78.66 GiB |
|
| 266 |
+
| 32 | 3231.74 | 373.53 | 76.61 GiB |
|
| 267 |
+
|
| 268 |
+
<details>
|
| 269 |
+
<summary>🔎 Measurement details</summary>
|
| 270 |
+
|
| 271 |
+
HF: PyTorch 2.10, Transformers 4.57.6, no quantization, default YuE2-Vae. 4090 values average 32 warm requests per mode; H800 is a one-song HF download-and-generation check. Times are synchronized pipeline calls, excluding initial path resolution and saving. NVML records the full-run GPU peak.
|
| 272 |
+
|
| 273 |
+
Server: 32 songs per row; AR/NAR use PyTorch 2.10 and Triton 3.6, VAE uses PyTorch 2.6. Songs/hour is warm batch throughput through all stages, not request latency. TPS counts output tokens once, excluding prefixes, supplied ABC, and the second CFG branch. Memory includes reserved KV cache. This server is separate from the HF quick start.
|
| 274 |
+
|
| 275 |
+
</details>
|
| 276 |
+
|
| 277 |
+
<a id="benchmarks"></a>
|
| 278 |
+
|
| 279 |
+
## 📊 Benchmarks
|
| 280 |
+
|
| 281 |
+
<a id="wildsongbench--full-song-generation"></a>
|
| 282 |
+
|
| 283 |
+
### 🌍 WildSongBench · full-song generation
|
| 284 |
+
|
| 285 |
+
**🔓 Open models**
|
| 286 |
+
|
| 287 |
+
| Model | Musicality ↑ | SongBench Avg ↑ | MuLan ↑ | AllMusicCaps ↑ | Q3O ↑ | PER ↓ |
|
| 288 |
+
|---|---:|---:|---:|---:|---:|---:|
|
| 289 |
+
| YuE 1 | 4.0847 | 4.9165 | 0.2623 | 0.2882 | 3.7301 | 36.38% |
|
| 290 |
+
| SongBloom | 3.4493 | 4.2350 | 0.2697 | 0.1926 | 3.0287 | 19.19% |
|
| 291 |
+
| LeVo 2 | 5.4590 | 6.3247 | 0.3542 | 0.2680 | 3.9458 | 26.12% |
|
| 292 |
+
| ACE-Step 1.5 | 5.1588 | 6.0118 | 0.4372 | 0.3869 | 4.5809 | 7.46% |
|
| 293 |
+
| HeartMuLa | 5.4963 | 6.2483 | 0.3823 | 0.2786 | 3.4907 | 10.71% |
|
| 294 |
+
| DiffRhythm 2 | 4.4775 | 5.2428 | 0.3782 | 0.3255 | 4.0870 | 18.41% |
|
| 295 |
+
| Muse | 5.1692 | 6.0349 | 0.3937 | 0.3466 | 4.4038 | 33.42% |
|
| 296 |
+
| MiniMax Music 3 | 5.3482 | 6.2830 | 0.3928 | 0.3609 | 4.4362 | **6.27%** |
|
| 297 |
+
| **YuE2** | 5.9075 | 6.7316 | **0.5068** | **0.4054** | 4.6819 | 8.44% |
|
| 298 |
+
| **YuE2 (best-of-8)** | **6.2666** | **6.9632** | 0.5051 | 0.3980 | **4.7009** | 9.79% |
|
| 299 |
+
|
| 300 |
+
**🔒 Proprietary models**
|
| 301 |
+
|
| 302 |
+
| Model | Musicality ↑ | SongBench Avg ↑ | MuLan ↑ | AllMusicCaps ↑ | Q3O ↑ | PER ↓ |
|
| 303 |
+
|---|---:|---:|---:|---:|---:|---:|
|
| 304 |
+
| Suno v5 | 5.9918 | 6.8721 | **0.5428** | **0.4353** | 4.5907 | 8.10% |
|
| 305 |
+
| Suno v4.5 | 5.8317 | 6.6995 | 0.5022 | 0.3873 | 4.4149 | **5.80%** |
|
| 306 |
+
| Suno v5.5 | 5.8087 | 6.7150 | 0.5089 | 0.3917 | 4.5914 | 5.96% |
|
| 307 |
+
| MiniMax Music 2.6 | 5.4437 | 6.3222 | 0.4251 | 0.3670 | 4.5688 | 24.55% |
|
| 308 |
+
| Mureka 9 | 6.0488 | 6.9377 | 0.4394 | 0.4102 | 4.6368 | 11.69% |
|
| 309 |
+
| **YuE2** | 5.9075 | 6.7316 | 0.5068 | 0.4054 | 4.6819 | 8.44% |
|
| 310 |
+
| **YuE2 (best-of-8)** | **6.2666** | **6.9632** | 0.5051 | 0.3980 | **4.7009** | 9.79% |
|
| 311 |
+
|
| 312 |
+
*192 prompts. Both YuE2 settings use symbolic planning and [🤗 YuE2-Vae-legacy](https://huggingface.co/m-a-p/YuE2-Vae-legacy). Standard YuE2 selects from two candidates; best-of-8 selects from eight.*
|
| 313 |
+
|
| 314 |
+
<a id="shs100k--zero-shot-cover-generation"></a>
|
| 315 |
+
|
| 316 |
+
### 🎤 SHS100K · zero-shot cover generation
|
| 317 |
+
|
| 318 |
+
| Method | CLEWS mAP ↑ | CLEWS Hit@1 ↑ | VINet mAP ↑ | MuLan ↑ | Musicality ↑ |
|
| 319 |
+
|---|---:|---:|---:|---:|---:|
|
| 320 |
+
| SongEcho | 0.419 | 48.4% | 0.122 | 0.366 | 3.286 |
|
| 321 |
+
| ACE-Step 1.5 | 0.024 | 2.4% | 0.006 | 0.166 | 3.689 |
|
| 322 |
+
| **YuE2 (full score)** | **0.647** | **71.3%** | **0.288** | 0.382 | 5.104 |
|
| 323 |
+
| YuE2 (without chords) | 0.598 | 67.3% | 0.179 | 0.417 | 5.490 |
|
| 324 |
+
| YuE2 (without score) | 0.006 | 0.3% | 0.004 | **0.474** | **5.691** |
|
| 325 |
+
|
| 326 |
+
*948 works × two styles × two seeds: 3,792 songs per method, without candidate selection. The score-conditioned variants use supplied source scores; all YuE2 variants use YuE2-Vae-legacy.*
|
| 327 |
+
|
| 328 |
+
<details>
|
| 329 |
+
<summary>📐 Evaluation protocols and metric definitions</summary>
|
| 330 |
+
|
| 331 |
+
WSB: SongBench Avg averages seven dimensions; Q3O measures prompt adherence on a 0–5 scale; PER is phoneme error rate. YuE2 selects the lower-PER candidate from two. Best-of-8 selects by Musicality → Q3O → PER. Each candidate's PER uses the lowest-PER of four ASR passes. A pipeline call generates one candidate; selection is separate. Q3O weights differ on 10 of 192 prompts between the two YuE2 settings. Bold marks the best value within each table. Open baselines use two candidates and four ASR passes; proprietary systems retain their delivered-candidate protocols. MiniMax Music 3 uses its official caption rewriter. SongBloom uses a fixed audio prompt rather than a style-text input.
|
| 332 |
+
|
| 333 |
+
SHS100K: CLEWS and Discogs-VINet measure preserved song identity against 10,545 recordings after source exclusion. MuLan measures target-style similarity; Musicality is from SongBench. Identity and quality should be read together. Every displayed metric covers all 3,792 outputs per method; incomplete Q3O scores are omitted. Source-score extraction is separate from this kit.
|
| 334 |
+
|
| 335 |
+
The overview plot combines SongBench and SongEval for quality, and MuLan, AllMusicCaps, and Q3O for alignment. These are automatic benchmark results under the stated candidate-selection protocols.
|
| 336 |
+
|
| 337 |
+
</details>
|
| 338 |
+
|
| 339 |
+
<details>
|
| 340 |
+
<summary>🔊 Choosing a VAE</summary>
|
| 341 |
+
|
| 342 |
+
In our comparisons, [🤗 YuE2-Vae-legacy](https://huggingface.co/m-a-p/YuE2-Vae-legacy) achieves higher musicality scores on benchmarks, while [🤗 YuE2-Vae](https://huggingface.co/m-a-p/YuE2-Vae) delivers better perceptual audio quality. We recommend YuE2-Vae by default; use YuE2-Vae-legacy when reproducing the paper's benchmark results.
|
| 343 |
+
|
| 344 |
+
</details>
|
| 345 |
+
|
| 346 |
+
<a id="citation"></a>
|
| 347 |
+
|
| 348 |
+
## 📚 Citation
|
| 349 |
+
|
| 350 |
+
**Technical report coming soon.** For now, please cite [YuE](https://arxiv.org/abs/2503.08638) when using YuE2-3B in your research.
|
| 351 |
+
|
| 352 |
+
```bibtex
|
| 353 |
+
@article{yuan2025yue,
|
| 354 |
+
title = {{YuE}: Scaling Open Foundation Models for Long-Form Music Generation},
|
| 355 |
+
author = {Yuan, Ruibin and Lin, Hanfeng and Guo, Shuyue and Zhang, Ge and Pan, Jiahao and Zang, Yongyi and Liu, Haohe and Liang, Yiming and Ma, Wenye and Du, Xingjian and Du, Xinrun and Ye, Zhen and Zheng, Tianyu and Jiang, Zhengxuan and Ma, Yinghao and Liu, Minghao and Tian, Zeyue and Zhou, Ziya and Xue, Liumeng and Qu, Xingwei and Li, Yizhi and Wu, Shangda and Shen, Tianhao and Ma, Ziyang and Zhan, Jun and Wang, Chunhui and Wang, Yatian and Chi, Xiaowei and Zhang, Xinyue and Yang, Zhenzhu and Wang, Xiangzhou and Liu, Shansong and Mei, Lingrui and Li, Peng and Wang, Junjie and Yu, Jianwei and Pang, Guojian and Li, Xu and Wang, Zihao and Zhou, Xiaohuan and Yu, Lijun and Benetos, Emmanouil and Chen, Yong and Lin, Chenghua and Chen, Xie and Xia, Gus and Zhang, Zhaoxiang and Zhang, Chao and Chen, Wenhu and Zhou, Xinyu and Qiu, Xipeng and Dannenberg, Roger and Liu, Jiaheng and Yang, Jian and Huang, Wenhao and Xue, Wei and Tan, Xu and Guo, Yike},
|
| 356 |
+
journal = {arXiv preprint arXiv:2503.08638},
|
| 357 |
+
year = {2025},
|
| 358 |
+
eprint = {2503.08638},
|
| 359 |
+
archivePrefix = {arXiv},
|
| 360 |
+
url = {https://arxiv.org/abs/2503.08638}
|
| 361 |
+
}
|
| 362 |
+
```
|
| 363 |
+
|
| 364 |
+
Weights: [CC BY-NC 4.0](LICENSE). [Third-party code licenses](THIRD_PARTY_NOTICES.md).
|
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.
|
assets/architecture.png
ADDED
|
Git LFS Details
|
assets/audio/auld-lang-syne-jazz-funk-cover.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2920e32d6723181da2b26b766b11b34c78f162417229f7394a90a06d2db50141
|
| 3 |
+
size 4559660
|
assets/audio/cyber-metal.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:997171848c1fbabeece4885877dd4aa62374576042392e0583ba64b038c4af48
|
| 3 |
+
size 7215020
|
assets/audio/examples.json
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema": 1,
|
| 3 |
+
"description": "YuE2 listening examples: original songs and cover songs.",
|
| 4 |
+
"examples": [
|
| 5 |
+
{
|
| 6 |
+
"id": "cyber-metal",
|
| 7 |
+
"title": "Cyber Metal",
|
| 8 |
+
"title_source": "Genre Explorer display title (genre label).",
|
| 9 |
+
"language": "en",
|
| 10 |
+
"label": "English",
|
| 11 |
+
"task": "text-to-music",
|
| 12 |
+
"model": "YuE2 (earlier checkpoint)",
|
| 13 |
+
"source": "https://map-yue2.github.io/",
|
| 14 |
+
"source_id": "b82e55c7d22f58b5d89399bc",
|
| 15 |
+
"source_collection": "Selected Genre Explorer demos",
|
| 16 |
+
"vae": "m-a-p/YuE2-Vae",
|
| 17 |
+
"symbolic_planning": true,
|
| 18 |
+
"seed": 8984,
|
| 19 |
+
"style": "At 148 BPM, the synthwave-trap fusion kicks in with thick analog bass, neon pads, thumping 808s, and sharp gated snares. Verses blend electric guitar, rapid hi-hats, and bubbling synths. Choruses burst with double-time trap beats, soaring retro synth leads, lush riffs, cinematic strings, swirling arps, water FX, and fluid transitions beneath dynamic vocals. Breakdowns spotlight vintage strings, wavesynth layers, double-kicks, deep sub-bass, and overdriven guitar, evoking a liquid-wave vibe. Trap DJ drops, pulsing melodic guitar, and remix-ready edits inject extra retro-modern punch.",
|
| 20 |
+
"file": "cyber-metal.mp3",
|
| 21 |
+
"sample_rate": 48000,
|
| 22 |
+
"channels": 2,
|
| 23 |
+
"duration_seconds": 300.6,
|
| 24 |
+
"display_duration": "5:00",
|
| 25 |
+
"bytes": 7215020,
|
| 26 |
+
"sha256": "997171848c1fbabeece4885877dd4aa62374576042392e0583ba64b038c4af48"
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"id": "tonight-awake",
|
| 30 |
+
"title": "今晚不眠",
|
| 31 |
+
"title_source": "Display title taken from the chorus; the demo page labels the track Nu-Disco.",
|
| 32 |
+
"language": "zh",
|
| 33 |
+
"label": "Mandarin funk / nu-disco",
|
| 34 |
+
"model": "YuE2 (earlier checkpoint)",
|
| 35 |
+
"source": "https://map-yue2.github.io/",
|
| 36 |
+
"source_id": "383f774d73b0099f1b207c82",
|
| 37 |
+
"source_collection": "Liked Genre Explorer demos",
|
| 38 |
+
"vae": "m-a-p/YuE2-Vae",
|
| 39 |
+
"cot": "full",
|
| 40 |
+
"seed": 12300,
|
| 41 |
+
"style": "City Pop, upbeat, danceable, groovy bass, electric guitar, synth, energetic, joyful, neon city night",
|
| 42 |
+
"file": "tonight-awake.mp3",
|
| 43 |
+
"sample_rate": 48000,
|
| 44 |
+
"channels": 2,
|
| 45 |
+
"duration_seconds": 203.52,
|
| 46 |
+
"display_duration": "3:24",
|
| 47 |
+
"bytes": 4885100,
|
| 48 |
+
"sha256": "54f642933f796e4244f0a308d3d0603c09b4d87f04e0bc42fbcbb9df0bffbcf9"
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"id": "passion",
|
| 52 |
+
"title": "Passion",
|
| 53 |
+
"language": "en",
|
| 54 |
+
"label": "English rock",
|
| 55 |
+
"model": "m-a-p/YuE2-3B",
|
| 56 |
+
"vae": "m-a-p/YuE2-Vae",
|
| 57 |
+
"cot": "full",
|
| 58 |
+
"seed": 831054,
|
| 59 |
+
"style": "Energetic modern rock with emotional vocals, big guitars, cinematic drums, and a powerful chorus. Anthemic and passionate mood with dynamic build and heavy rhythm.",
|
| 60 |
+
"file": "passion.mp3",
|
| 61 |
+
"sample_rate": 48000,
|
| 62 |
+
"channels": 2,
|
| 63 |
+
"duration_seconds": 234.72,
|
| 64 |
+
"display_duration": "3:55",
|
| 65 |
+
"bytes": 5633900,
|
| 66 |
+
"sha256": "87fec41a160e430cfde543be76e1da81f7442ff3e0aca09455cf8fea9048cc63"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"id": "auld-lang-syne-jazz-funk-cover",
|
| 70 |
+
"title": "Auld Lang Syne",
|
| 71 |
+
"label": "Jazz-funk cover",
|
| 72 |
+
"task": "cover-generation",
|
| 73 |
+
"source": "User-provided audio",
|
| 74 |
+
"file": "auld-lang-syne-jazz-funk-cover.mp3",
|
| 75 |
+
"sample_rate": 48000,
|
| 76 |
+
"channels": 2,
|
| 77 |
+
"duration_seconds": 189.96,
|
| 78 |
+
"display_duration": "3:10",
|
| 79 |
+
"bytes": 4559660,
|
| 80 |
+
"sha256": "2920e32d6723181da2b26b766b11b34c78f162417229f7394a90a06d2db50141"
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"id": "zuixuan-ballad-cover",
|
| 84 |
+
"title": "最炫民族风",
|
| 85 |
+
"label": "Ballad cover",
|
| 86 |
+
"task": "cover-generation",
|
| 87 |
+
"source": "User-provided audio",
|
| 88 |
+
"file": "zuixuan-ballad-cover.mp3",
|
| 89 |
+
"sample_rate": 48000,
|
| 90 |
+
"channels": 2,
|
| 91 |
+
"duration_seconds": 284.904,
|
| 92 |
+
"display_duration": "4:45",
|
| 93 |
+
"bytes": 6838316,
|
| 94 |
+
"sha256": "fbd0cc2131924fee15c8f5e7519c577f8cd53005302508cc9d959461d31b935f"
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"id": "jingle-bells-heavy-metal-cover",
|
| 98 |
+
"title": "Jingle Bells",
|
| 99 |
+
"label": "Heavy metal cover",
|
| 100 |
+
"task": "cover-generation",
|
| 101 |
+
"source": "User-provided audio",
|
| 102 |
+
"file": "jingle-bells-heavy-metal-cover.mp3",
|
| 103 |
+
"sample_rate": 48000,
|
| 104 |
+
"channels": 2,
|
| 105 |
+
"duration_seconds": 69.024,
|
| 106 |
+
"display_duration": "1:09",
|
| 107 |
+
"bytes": 1657196,
|
| 108 |
+
"sha256": "44d15f0e04949207f44bbaf07c392012fbae84a1e4d89f44e4b055a0c21fa845"
|
| 109 |
+
}
|
| 110 |
+
]
|
| 111 |
+
}
|
assets/audio/jingle-bells-heavy-metal-cover.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:44d15f0e04949207f44bbaf07c392012fbae84a1e4d89f44e4b055a0c21fa845
|
| 3 |
+
size 1657196
|
assets/audio/passion.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:87fec41a160e430cfde543be76e1da81f7442ff3e0aca09455cf8fea9048cc63
|
| 3 |
+
size 5633900
|
assets/audio/tonight-awake.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:54f642933f796e4244f0a308d3d0603c09b4d87f04e0bc42fbcbb9df0bffbcf9
|
| 3 |
+
size 4885100
|
assets/audio/zuixuan-ballad-cover.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fbd0cc2131924fee15c8f5e7519c577f8cd53005302508cc9d959461d31b935f
|
| 3 |
+
size 6838316
|
assets/figure1.png
ADDED
|
Git LFS Details
|
assets/logo.png
ADDED
|
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 |
+
}
|
examples/tonight-awake.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"title": "今晚不眠",
|
| 3 |
+
"style": "City Pop, upbeat, danceable, groovy bass, electric guitar, synth, energetic, joyful, neon city night",
|
| 4 |
+
"lyrics": "[Intro]\n\n[Verse]\n路灯眨着眼睛 偷看谁的身影\n街道哼着小调 节奏多轻盈\n晚风染成霓虹 吹乱发际线\n脚步踩着鼓点 不需要终点\n\n[Pre-Chorus]\n旋转的唱片 划破了寂静\n气泡在上升 快乐在飞行\n把烦恼抛去 别再去在意\n这里的空气 充满了魔力\n\n[Chorus]\n今晚不眠 快乐无限\n城市在狂欢 我们在中间\n自由摇摆 光芒盛开\n跟着这节拍 把心打开\n\n今晚不眠 快乐无限\n城市在狂欢 我们在中间\n自由摇摆 光芒盛开\n跟着这节拍 把心打开\n\n[Interlude]\n\n[Pre-Chorus]\n旋转的唱片 划破了寂静\n气泡在上升 快乐在飞行\n把烦恼抛去 别再去在意\n这里的空气 充满了魔力\n\n[Chorus]\n今晚不眠 快乐无限\n城市在狂欢 我们在中间\n自由摇摆 光芒盛开\n跟着这节拍 把心打开\n\n今晚不眠 快乐无限\n城市在狂欢 我们在中间\n自由摇摆 光芒盛开\n跟着这节拍 把心打开\n\n[Bridge]\n像橘子汽水 充满了微醺的甜\n像流星划过 点亮了夜的天\n不需要理由 只要你感觉\n这一刻就是 永恒的瞬间\n\n[Chorus]\n今晚不眠 快乐无限\n城市在狂欢 我们在中间\n自由摇摆 光芒盛开\n跟着这节拍 把心打开\n\n今晚不眠 快乐无限\n城市在狂欢 我们在中间\n自由摇摆 光芒盛开\n跟着这节拍 把心打开\n\n[Outro]\n霓虹色的风 吹向那梦\n摇摆\n闪耀\nYeah",
|
| 5 |
+
"cot": "full",
|
| 6 |
+
"seed": 12300,
|
| 7 |
+
"source": {
|
| 8 |
+
"url": "https://map-yue2.github.io/",
|
| 9 |
+
"case_id": "383f774d73b0099f1b207c82"
|
| 10 |
+
}
|
| 11 |
+
}
|
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 |
+
}
|
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.
|
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.
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1d55c42c1a9875c34f5d736e15078449992b044e807ce2a138e6cf289a1e59e9
|
| 3 |
+
size 7261441640
|
modeling_yue2.py
ADDED
|
@@ -0,0 +1,705 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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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")
|
qwen.tiktoken
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
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 |
+
}
|
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 |
+
}
|
yue2_infer-0.1.3-py3-none-any.whl
ADDED
|
Binary file (60.9 kB). View file
|
|
|
yue2_infer-0.1.5-py3-none-any.whl
ADDED
|
Binary file (66.1 kB). View file
|
|
|