AEmotionStudio commited on
Commit
bf6d13d
·
verified ·
1 Parent(s): 751e667

Add vae_legacy lane (byte-identical mirror of the upstream release)

Browse files
vae_legacy/LICENSE ADDED
@@ -0,0 +1,429 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
vae_legacy/config.json ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "return_dict": true,
3
+ "output_hidden_states": false,
4
+ "torchscript": false,
5
+ "dtype": "float32",
6
+ "tie_word_embeddings": true,
7
+ "is_encoder_decoder": false,
8
+ "is_decoder": false,
9
+ "add_cross_attention": false,
10
+ "architectures": [
11
+ "YuE2VAE"
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_vae.YuE2VAEConfig",
20
+ "AutoModel": "modeling_vae.YuE2VAE"
21
+ },
22
+ "model_type": "yue2_vae",
23
+ "encoder_config": {
24
+ "c_mults": [
25
+ 1,
26
+ 2,
27
+ 4,
28
+ 8,
29
+ 16,
30
+ 32
31
+ ],
32
+ "channels": 64,
33
+ "in_channels": 2,
34
+ "latent_dim": 128,
35
+ "strides": [
36
+ 2,
37
+ 2,
38
+ 4,
39
+ 4,
40
+ 5,
41
+ 6
42
+ ],
43
+ "use_snake": true
44
+ },
45
+ "decoder_config": {
46
+ "c_mults": [
47
+ 1,
48
+ 2,
49
+ 4,
50
+ 8,
51
+ 16,
52
+ 32
53
+ ],
54
+ "channels": 64,
55
+ "final_tanh": false,
56
+ "latent_dim": 64,
57
+ "out_channels": 2,
58
+ "snake_type": "vanilla",
59
+ "strides": [
60
+ 2,
61
+ 2,
62
+ 4,
63
+ 4,
64
+ 5,
65
+ 6
66
+ ],
67
+ "use_filter": false,
68
+ "use_snake": true
69
+ },
70
+ "sample_rate": 48000,
71
+ "latent_dim": 64,
72
+ "downsampling_ratio": 1920,
73
+ "audio_channels": 2,
74
+ "release_variant": "legacy",
75
+ "decode_core_frames": 1024,
76
+ "decode_halo_frames": 16,
77
+ "output_attentions": false
78
+ }
vae_legacy/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.
vae_legacy/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.
vae_legacy/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b6d283628913bb41145ba99e2314eef613905ee95f690eb70e8212d5f4965044
3
+ size 530512720
vae_legacy/modeling_vae.py ADDED
@@ -0,0 +1,589 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Portable FP32 YuE2 Oobleck VAE with exact-boundary tiled decoding.
2
+
3
+ Oobleck and SnakeBeta derived from stable-audio-tools a6ae0cdf8b2eb1567a4b42ceadddec3712d99d45.
4
+ Copyright (c) 2023 Stability AI; Copyright (c) 2022 NVIDIA CORPORATION.
5
+ MIT: see THIRD_PARTY_NOTICES.md shipped with this module/model repository.
6
+ """
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ import math
11
+ from pathlib import Path
12
+ from typing import Callable, Literal
13
+
14
+ import torch
15
+ from torch import nn
16
+ from torch.nn.utils import weight_norm
17
+ from transformers import PretrainedConfig, PreTrainedModel
18
+
19
+
20
+ def checkpoint(function, *args, **kwargs):
21
+ from torch.utils.checkpoint import checkpoint as torch_checkpoint
22
+ kwargs.setdefault("use_reentrant", False)
23
+ return torch_checkpoint(function, *args, **kwargs)
24
+
25
+
26
+ def WNConv1d(*args, **kwargs):
27
+ return weight_norm(nn.Conv1d(*args, **kwargs))
28
+
29
+
30
+ def WNConvTranspose1d(*args, **kwargs):
31
+ return weight_norm(nn.ConvTranspose1d(*args, **kwargs))
32
+
33
+
34
+ def snake_beta(x, alpha, beta):
35
+ return x + (1.0 / (beta + 0.000000001)) * torch.pow(
36
+ torch.sin(x * alpha), 2
37
+ )
38
+
39
+
40
+ class SnakeBeta(nn.Module):
41
+ def __init__(
42
+ self,
43
+ in_features,
44
+ alpha=1.0,
45
+ alpha_trainable=True,
46
+ alpha_logscale=True,
47
+ ):
48
+ super().__init__()
49
+ self.in_features = in_features
50
+ self.alpha_logscale = alpha_logscale
51
+ if self.alpha_logscale:
52
+ self.alpha = nn.Parameter(torch.zeros(in_features) * alpha)
53
+ self.beta = nn.Parameter(torch.zeros(in_features) * alpha)
54
+ else:
55
+ self.alpha = nn.Parameter(torch.ones(in_features) * alpha)
56
+ self.beta = nn.Parameter(torch.ones(in_features) * alpha)
57
+ self.alpha.requires_grad = alpha_trainable
58
+ self.beta.requires_grad = alpha_trainable
59
+ self.no_div_by_zero = 0.000000001
60
+
61
+ def forward(self, x):
62
+ alpha = self.alpha.unsqueeze(0).unsqueeze(-1)
63
+ beta = self.beta.unsqueeze(0).unsqueeze(-1)
64
+ if self.alpha_logscale:
65
+ alpha = torch.exp(alpha)
66
+ beta = torch.exp(beta)
67
+ return snake_beta(x, alpha, beta)
68
+
69
+
70
+ def get_activation(
71
+ activation: Literal["elu", "snake", "none"], channels=None
72
+ ) -> nn.Module:
73
+ if activation == "elu":
74
+ return nn.ELU()
75
+ if activation == "snake":
76
+ return SnakeBeta(channels)
77
+ if activation == "none":
78
+ return nn.Identity()
79
+ raise ValueError(f"Unknown activation {activation}")
80
+
81
+
82
+ class ResidualUnit(nn.Module):
83
+ def __init__(self, in_channels, out_channels, dilation, act_type):
84
+ super().__init__()
85
+ self.dilation = dilation
86
+ padding = (dilation * (7 - 1)) // 2
87
+ self.layers = nn.Sequential(
88
+ get_activation(act_type, channels=out_channels),
89
+ WNConv1d(
90
+ in_channels=in_channels,
91
+ out_channels=out_channels,
92
+ kernel_size=7,
93
+ dilation=dilation,
94
+ padding=padding,
95
+ ),
96
+ get_activation(act_type, channels=out_channels),
97
+ WNConv1d(
98
+ in_channels=out_channels,
99
+ out_channels=out_channels,
100
+ kernel_size=1,
101
+ ),
102
+ )
103
+
104
+ def forward(self, x):
105
+ residual = x
106
+ if self.training:
107
+ x = checkpoint(self.layers, x)
108
+ else:
109
+ x = self.layers(x)
110
+ return x + residual
111
+
112
+
113
+ class EncoderBlock(nn.Module):
114
+ def __init__(self, in_channels, out_channels, stride, act_type):
115
+ super().__init__()
116
+ self.layers = nn.Sequential(
117
+ ResidualUnit(in_channels, in_channels, 1, act_type),
118
+ ResidualUnit(in_channels, in_channels, 3, act_type),
119
+ ResidualUnit(in_channels, in_channels, 9, act_type),
120
+ get_activation(act_type, channels=in_channels),
121
+ WNConv1d(
122
+ in_channels=in_channels,
123
+ out_channels=out_channels,
124
+ kernel_size=2 * stride,
125
+ stride=stride,
126
+ padding=math.ceil(stride / 2),
127
+ ),
128
+ )
129
+
130
+ def forward(self, x):
131
+ return self.layers(x)
132
+
133
+
134
+ class DecoderBlock(nn.Module):
135
+ def __init__(self, in_channels, out_channels, stride, act_type):
136
+ super().__init__()
137
+ upsample_layer = WNConvTranspose1d(
138
+ in_channels=in_channels,
139
+ out_channels=out_channels,
140
+ kernel_size=2 * stride,
141
+ stride=stride,
142
+ padding=math.ceil(stride / 2),
143
+ )
144
+ self.layers = nn.Sequential(
145
+ get_activation(act_type, channels=in_channels),
146
+ upsample_layer,
147
+ ResidualUnit(out_channels, out_channels, 1, act_type),
148
+ ResidualUnit(out_channels, out_channels, 3, act_type),
149
+ ResidualUnit(out_channels, out_channels, 9, act_type),
150
+ )
151
+
152
+ def forward(self, x):
153
+ return self.layers(x)
154
+
155
+
156
+ class OobleckEncoder(nn.Module):
157
+ def __init__(
158
+ self,
159
+ in_channels=2,
160
+ channels=128,
161
+ latent_dim=32,
162
+ c_mults=(1, 2, 4, 8),
163
+ strides=(2, 4, 8, 8),
164
+ use_snake=False,
165
+ antialias_activation=False,
166
+ ):
167
+ super().__init__()
168
+ if antialias_activation:
169
+ raise ValueError("The released encoder does not use antialias_activation")
170
+ self.in_channels = in_channels
171
+ c_mults = [1] + list(c_mults)
172
+ self.depth = len(c_mults)
173
+ layers = [
174
+ WNConv1d(
175
+ in_channels=in_channels,
176
+ out_channels=c_mults[0] * channels,
177
+ kernel_size=7,
178
+ padding=3,
179
+ )
180
+ ]
181
+ act_type = "snake" if use_snake else "elu"
182
+ for i in range(self.depth - 1):
183
+ layers.append(
184
+ EncoderBlock(
185
+ in_channels=c_mults[i] * channels,
186
+ out_channels=c_mults[i + 1] * channels,
187
+ stride=strides[i],
188
+ act_type=act_type,
189
+ )
190
+ )
191
+ layers.extend(
192
+ [
193
+ get_activation(act_type, channels=c_mults[-1] * channels),
194
+ WNConv1d(
195
+ in_channels=c_mults[-1] * channels,
196
+ out_channels=latent_dim,
197
+ kernel_size=3,
198
+ padding=1,
199
+ ),
200
+ ]
201
+ )
202
+ self.layers = nn.Sequential(*layers)
203
+
204
+ def forward(self, x):
205
+ return self.layers(x)
206
+
207
+
208
+ class OobleckDecoder(nn.Module):
209
+ def __init__(
210
+ self,
211
+ out_channels=2,
212
+ channels=128,
213
+ latent_dim=32,
214
+ c_mults=(1, 2, 4, 8),
215
+ strides=(2, 4, 8, 8),
216
+ use_snake=False,
217
+ snake_type="vanilla",
218
+ antialias_activation=False,
219
+ use_nearest_upsample=False,
220
+ use_filter=False,
221
+ final_tanh=True,
222
+ ):
223
+ super().__init__()
224
+ if antialias_activation or use_nearest_upsample or use_filter:
225
+ raise ValueError("Unsupported option for the released decoder")
226
+ if use_snake and snake_type != "vanilla":
227
+ raise ValueError("The released decoder uses vanilla SnakeBeta")
228
+ self.out_channels = out_channels
229
+ c_mults = [1] + list(c_mults)
230
+ self.depth = len(c_mults)
231
+ layers = [
232
+ WNConv1d(
233
+ in_channels=latent_dim,
234
+ out_channels=c_mults[-1] * channels,
235
+ kernel_size=7,
236
+ padding=3,
237
+ )
238
+ ]
239
+ act_type = "snake" if use_snake else "elu"
240
+ for i in range(self.depth - 1, 0, -1):
241
+ layers.append(
242
+ DecoderBlock(
243
+ in_channels=c_mults[i] * channels,
244
+ out_channels=c_mults[i - 1] * channels,
245
+ stride=strides[i - 1],
246
+ act_type=act_type,
247
+ )
248
+ )
249
+ layers.extend(
250
+ [
251
+ get_activation(act_type, channels=c_mults[0] * channels),
252
+ WNConv1d(
253
+ in_channels=c_mults[0] * channels,
254
+ out_channels=out_channels,
255
+ kernel_size=7,
256
+ padding=3,
257
+ bias=False,
258
+ ),
259
+ nn.Tanh() if final_tanh else nn.Identity(),
260
+ ]
261
+ )
262
+ self.layers = nn.Sequential(*layers)
263
+
264
+ def forward(self, x):
265
+ return self.layers(x)
266
+
267
+
268
+ class YuE2VAEConfig(PretrainedConfig):
269
+ """Configuration shared by YuE2-Vae and YuE2-Vae-legacy.
270
+
271
+ Use ``standard`` for listening and ``legacy`` for the paper metric baseline.
272
+ """
273
+
274
+ model_type = "yue2_vae"
275
+
276
+ _hf_fields = frozenset({
277
+ "model_type", "architectures", "auto_map", "transformers_version",
278
+ "dtype", "torch_dtype", "return_dict", "output_hidden_states",
279
+ "output_attentions", "use_cache", "tie_word_embeddings", "torchscript",
280
+ "is_decoder", "is_encoder_decoder", "add_cross_attention",
281
+ "bos_token_id", "eos_token_id", "pad_token_id", "decoder_start_token_id",
282
+ "attn_implementation",
283
+ })
284
+
285
+ def to_dict(self):
286
+ return {key: value for key, value in super().to_dict().items()
287
+ if key in self._hf_fields or key in self._inference_fields}
288
+
289
+ _inference_fields = frozenset(['encoder_config', 'decoder_config', 'sample_rate', 'latent_dim', 'downsampling_ratio', 'audio_channels', 'release_variant', 'decode_core_frames', 'decode_halo_frames'])
290
+
291
+ def __init__(self, encoder_config=None, decoder_config=None,
292
+ sample_rate=48000, latent_dim=64, downsampling_ratio=1920,
293
+ audio_channels=2, release_variant="standard",
294
+ decode_core_frames=1024, decode_halo_frames=16,
295
+ **kwargs):
296
+ kwargs = {key: value for key, value in kwargs.items() if key in self._hf_fields}
297
+ kwargs.setdefault("architectures", ["YuE2VAE"])
298
+ kwargs.setdefault("auto_map", {
299
+ "AutoConfig": "modeling_vae.YuE2VAEConfig",
300
+ "AutoModel": "modeling_vae.YuE2VAE",
301
+ })
302
+ super().__init__(**kwargs)
303
+ self.encoder_config = encoder_config or dict(
304
+ in_channels=2, channels=64, c_mults=[1, 2, 4, 8, 16, 32],
305
+ strides=[2, 2, 4, 4, 5, 6], latent_dim=128, use_snake=True)
306
+ self.decoder_config = decoder_config or dict(
307
+ out_channels=2, channels=64, c_mults=[1, 2, 4, 8, 16, 32],
308
+ strides=[2, 2, 4, 4, 5, 6], latent_dim=64, use_snake=True,
309
+ snake_type="vanilla", use_filter=False, final_tanh=False)
310
+ encoder_fields = {"in_channels", "channels", "latent_dim", "c_mults", "strides",
311
+ "use_snake", "antialias_activation"}
312
+ decoder_fields = {"out_channels", "channels", "latent_dim", "c_mults", "strides",
313
+ "use_snake", "snake_type", "antialias_activation",
314
+ "use_nearest_upsample", "use_filter", "final_tanh"}
315
+ self.encoder_config = {key: value for key, value in self.encoder_config.items() if key in encoder_fields}
316
+ self.decoder_config = {key: value for key, value in self.decoder_config.items() if key in decoder_fields}
317
+ self.sample_rate = int(sample_rate)
318
+ self.latent_dim = int(latent_dim)
319
+ self.downsampling_ratio = int(downsampling_ratio)
320
+ self.audio_channels = int(audio_channels)
321
+ self.release_variant = release_variant
322
+ self.decode_core_frames = int(decode_core_frames)
323
+ self.decode_halo_frames = int(decode_halo_frames)
324
+ if self.decode_core_frames < 1 or self.decode_halo_frames < 0:
325
+ raise ValueError("Invalid VAE core/halo configuration")
326
+ if math.prod(self.decoder_config["strides"]) != self.downsampling_ratio:
327
+ raise ValueError("Decoder strides do not match downsampling_ratio")
328
+ if self.decoder_config["latent_dim"] != self.latent_dim:
329
+ raise ValueError("Decoder input channels do not match latent_dim")
330
+
331
+
332
+ def _dependency_interval(module, low, high):
333
+ """Inclusive input support of an output interval; no waveform blending."""
334
+ if isinstance(module, (nn.Sequential, OobleckDecoder, DecoderBlock)):
335
+ layers = module if isinstance(module, nn.Sequential) else module.layers
336
+ for child in reversed(list(layers)):
337
+ low, high = _dependency_interval(child, low, high)
338
+ return low, high
339
+ if isinstance(module, ResidualUnit):
340
+ a, b = _dependency_interval(module.layers, low, high)
341
+ return min(a, low), max(b, high)
342
+ if isinstance(module, nn.ConvTranspose1d):
343
+ s, p, d, k = (module.stride[0], module.padding[0],
344
+ module.dilation[0], module.kernel_size[0])
345
+ return -(-(low + p - d * (k - 1)) // s), (high + p) // s
346
+ if isinstance(module, nn.Conv1d):
347
+ s, p, d, k = (module.stride[0], module.padding[0],
348
+ module.dilation[0], module.kernel_size[0])
349
+ return low * s - p, high * s - p + d * (k - 1)
350
+ if isinstance(module, (SnakeBeta, nn.ELU, nn.Identity, nn.Tanh)):
351
+ return low, high
352
+ raise TypeError(f"No audited support rule for {type(module).__name__}")
353
+
354
+
355
+ def _output_length(module, length):
356
+ if isinstance(module, (nn.Sequential, OobleckDecoder, DecoderBlock)):
357
+ layers = module if isinstance(module, nn.Sequential) else module.layers
358
+ for child in layers:
359
+ length = _output_length(child, length)
360
+ return length
361
+ if isinstance(module, nn.ConvTranspose1d):
362
+ return ((length - 1) * module.stride[0] - 2 * module.padding[0]
363
+ + module.dilation[0] * (module.kernel_size[0] - 1)
364
+ + module.output_padding[0] + 1)
365
+ if isinstance(module, nn.Conv1d):
366
+ return ((length + 2 * module.padding[0]
367
+ - module.dilation[0] * (module.kernel_size[0] - 1) - 1)
368
+ // module.stride[0] + 1)
369
+ if isinstance(module, (ResidualUnit, SnakeBeta, nn.ELU, nn.Identity, nn.Tanh)):
370
+ return length
371
+ raise TypeError(f"No audited length rule for {type(module).__name__}")
372
+
373
+
374
+ class YuE2VAE(PreTrainedModel):
375
+ """Strict EMA model; only the decoder needs to reside on an accelerator.
376
+
377
+ ``decode_tiled`` preserves finite receptive-field context and writes cropped
378
+ cores to CPU. The mathematical waveform is the full decoder's waveform;
379
+ convolution kernel choices may cause small FP32 rounding differences.
380
+ """
381
+
382
+ config_class = YuE2VAEConfig
383
+ base_model_prefix = ""
384
+ main_input_name = "audio"
385
+
386
+ def __init__(self, config, decoder_only=False):
387
+ super().__init__(config)
388
+ self.decoder_only = bool(decoder_only)
389
+ if not self.decoder_only:
390
+ self.encoder = OobleckEncoder(**config.encoder_config)
391
+ self.decoder = OobleckDecoder(**config.decoder_config)
392
+ self.eval().requires_grad_(False)
393
+
394
+ @classmethod
395
+ def from_pretrained(cls, pretrained_model_name_or_path, *model_args,
396
+ config=None, decoder_only=False, device="cpu",
397
+ torch_dtype=None, dtype=None, revision=None, token=None,
398
+ cache_dir=None, local_files_only=False,
399
+ force_download=False, subfolder="", **kwargs):
400
+ """Load a local export or Hub repository, selecting decoder tensors.
401
+
402
+ Complete exports use unprefixed EMA keys. ``decoder_only=True`` avoids
403
+ constructing the encoder or loading encoder tensors into RAM/GPU.
404
+ """
405
+ from safetensors import safe_open
406
+ requested_dtype = dtype if dtype is not None else torch_dtype
407
+ if requested_dtype not in (None, "auto", "float32", torch.float32):
408
+ raise ValueError("The validated VAE requires FP32; quantize the LM separately")
409
+ device_map = kwargs.pop("device_map", None)
410
+ if device_map is not None:
411
+ if device_map == "auto":
412
+ device = "cuda" if torch.cuda.is_available() else "cpu"
413
+ elif isinstance(device_map, str):
414
+ device = device_map
415
+ elif isinstance(device_map, dict) and set(device_map) == {""}:
416
+ device = device_map[""]
417
+ else:
418
+ raise ValueError("Use decoder_only=True and a single device for the VAE")
419
+ for name in ("trust_remote_code", "low_cpu_mem_usage", "_from_auto",
420
+ "_from_pipeline", "_commit_hash", "adapter_kwargs",
421
+ "_fast_init", "weights_only", "use_safetensors"):
422
+ kwargs.pop(name, None)
423
+ output_loading_info = kwargs.pop("output_loading_info", False)
424
+ if kwargs or model_args:
425
+ raise TypeError(f"Unsupported VAE loading options: {sorted(kwargs)}")
426
+ path = Path(pretrained_model_name_or_path).expanduser()
427
+ if not path.is_dir():
428
+ from huggingface_hub import snapshot_download
429
+ path = Path(snapshot_download(
430
+ str(pretrained_model_name_or_path), revision=revision, token=token,
431
+ cache_dir=cache_dir, local_files_only=local_files_only,
432
+ force_download=force_download,
433
+ allow_patterns=[f"{subfolder + '/' if subfolder else ''}{pattern}"
434
+ for pattern in ("config.json", "*.safetensors",
435
+ "*.safetensors.index.json")]))
436
+ path = path / subfolder
437
+ if config is None:
438
+ config = YuE2VAEConfig.from_pretrained(path, local_files_only=True)
439
+ model = cls(config, decoder_only=decoder_only)
440
+ index = path / "model.safetensors.index.json"
441
+ if index.exists():
442
+ mapping = json.loads(index.read_text())["weight_map"]
443
+ files = sorted({name for key, name in mapping.items()
444
+ if not decoder_only or key.startswith("decoder.")})
445
+ else:
446
+ files = ["model.safetensors"]
447
+ state = {}
448
+ for name in files:
449
+ with safe_open(path / name, framework="pt", device="cpu") as handle:
450
+ for key in handle.keys():
451
+ if not decoder_only or key.startswith("decoder."):
452
+ if key in state:
453
+ raise ValueError(f"Duplicate VAE tensor: {key}")
454
+ state[key] = handle.get_tensor(key)
455
+ expected = set(model.state_dict())
456
+ if set(state) != expected:
457
+ raise ValueError(f"VAE tensor mismatch: missing={sorted(expected-set(state))}, "
458
+ f"unexpected={sorted(set(state)-expected)}")
459
+ if any(value.dtype != torch.float32 for value in state.values()):
460
+ raise ValueError("VAE export contains tensors that are not FP32")
461
+ model.load_state_dict(state, strict=True)
462
+ model.to(device=device, dtype=torch.float32).eval().requires_grad_(False)
463
+ if output_loading_info:
464
+ return model, dict(missing_keys=[], unexpected_keys=[], mismatched_keys=[],
465
+ error_msgs=[])
466
+ return model
467
+
468
+ def save_pretrained(self, save_directory, *args, **kwargs):
469
+ if self.decoder_only:
470
+ raise ValueError("Reload decoder_only=False to save a complete VAE repository")
471
+ if kwargs.get("safe_serialization", True) is False:
472
+ raise ValueError("YuE2 VAE release exports require safetensors")
473
+ return super().save_pretrained(save_directory, *args, **kwargs)
474
+
475
+ @property
476
+ def decoder_device(self):
477
+ return next(self.decoder.parameters()).device
478
+
479
+ def _latent(self, latent):
480
+ latent = torch.as_tensor(latent)
481
+ if (latent.ndim != 3 or latent.shape[1] != self.config.latent_dim
482
+ or latent.shape[0] < 1 or latent.shape[-1] < 1):
483
+ raise ValueError(f"Expected nonempty [B,{self.config.latent_dim},T] latents")
484
+ if not torch.isfinite(latent).all():
485
+ raise ValueError("VAE latents contain non-finite values")
486
+ if next(self.decoder.parameters()).dtype != torch.float32:
487
+ raise ValueError("VAE decoder weights must remain FP32")
488
+ return latent
489
+
490
+ @torch.inference_mode()
491
+ def encode(self, audio, sample=False, generator=None, return_info=False):
492
+ """Encode FP32 stereo audio; posterior mean by default.
493
+
494
+ Set ``sample=True`` with a per-request ``torch.Generator`` to reproduce
495
+ stochastic posterior sampling. This audio VAE is not the unreleased
496
+ semantic audio tokenizer semantic tokenizer.
497
+ """
498
+ if self.decoder_only:
499
+ raise RuntimeError("Encoder not loaded; reload with decoder_only=False")
500
+ audio = torch.as_tensor(audio)
501
+ if (audio.ndim != 3 or audio.shape[1] != self.config.audio_channels
502
+ or audio.shape[-1] < self.config.downsampling_ratio):
503
+ raise ValueError("Expected audio [B,2,S] with at least one latent frame")
504
+ if not torch.isfinite(audio).all():
505
+ raise ValueError("Audio contains non-finite values")
506
+ device = next(self.encoder.parameters()).device
507
+ pre = self.encoder(audio.to(device=device, dtype=torch.float32))
508
+ mean, scale = pre.chunk(2, dim=1)
509
+ stdev = torch.nn.functional.softplus(scale) + 1e-4
510
+ if sample:
511
+ noise = torch.randn(mean.shape, dtype=mean.dtype,
512
+ device=device, generator=generator)
513
+ latent = noise * stdev + mean
514
+ else:
515
+ latent = mean
516
+ if return_info:
517
+ return latent, dict(mean=mean, scale=scale, stdev=stdev)
518
+ return latent
519
+
520
+ @torch.inference_mode()
521
+ def decode(self, latent):
522
+ """Full waveform, FP32 [B,2,1920*T-64], without clipping."""
523
+ latent = self._latent(latent)
524
+ with torch.autocast(device_type=self.decoder_device.type, enabled=False):
525
+ return self.decoder(latent.to(device=self.decoder_device, dtype=torch.float32))
526
+
527
+ def natural_output_length(self, frames):
528
+ if int(frames) < 1:
529
+ raise ValueError("frames must be positive")
530
+ return _output_length(self.decoder, int(frames))
531
+
532
+ def required_halo(self, core_frames=None):
533
+ core_frames = self.config.decode_core_frames if core_frames is None else core_frames
534
+ ratio = self.config.downsampling_ratio
535
+ low, high = _dependency_interval(self.decoder, 0, core_frames * ratio - 1)
536
+ return max(0, -low, high - core_frames + 1)
537
+
538
+ @torch.inference_mode()
539
+ def decode_tiled(self, latent, core_frames=None, halo_frames=None,
540
+ output_device="cpu",
541
+ on_progress: Callable[[int, int], None] | None = None):
542
+ """Decode bounded tiles, retaining exact cores with natural end length.
543
+
544
+ Each crop has enough left/right context for every dependency. There is
545
+ no crossfade or boundary smoothing, and no zero padding of final audio.
546
+ CPU output prevents an entire song from accumulating on the GPU.
547
+ ``on_progress(completed, total)`` runs after each existing crop copy;
548
+ no extra synchronization is added. With a CUDA output device, queued
549
+ work may still be executing. Callback exceptions propagate.
550
+ """
551
+ latent = self._latent(latent)
552
+ core_frames = self.config.decode_core_frames if core_frames is None else core_frames
553
+ halo_frames = self.config.decode_halo_frames if halo_frames is None else halo_frames
554
+ if not isinstance(core_frames, int) or core_frames < 1:
555
+ raise ValueError("core_frames must be a positive integer")
556
+ required = self.required_halo(core_frames)
557
+ if not isinstance(halo_frames, int) or halo_frames < required:
558
+ raise ValueError(f"halo_frames must be at least {required} for this decoder")
559
+ frames = latent.shape[-1]
560
+ ratio = self.config.downsampling_ratio
561
+ total = self.natural_output_length(frames)
562
+ audio = torch.empty((latent.shape[0], self.config.audio_channels, total),
563
+ dtype=torch.float32, device=output_device)
564
+ tiles = (frames + core_frames - 1) // core_frames
565
+ for tile_index, start in enumerate(range(0, frames, core_frames)):
566
+ end = min(frames, start + core_frames)
567
+ left = max(0, start - halo_frames)
568
+ right = min(frames, end + halo_frames)
569
+ tile = self.decode(latent[..., left:right])
570
+ out_start, out_end = start * ratio, min(end * ratio, total)
571
+ crop_start = (start - left) * ratio
572
+ crop = tile[..., crop_start:crop_start + out_end - out_start]
573
+ if crop.shape[-1] != out_end - out_start:
574
+ raise RuntimeError("VAE tile did not cover its requested output core")
575
+ audio[..., out_start:out_end].copy_(crop.to(output_device))
576
+ del tile, crop
577
+ if on_progress is not None:
578
+ on_progress(tile_index + 1, tiles)
579
+ return audio
580
+
581
+ def decode_audio(self, latent, chunked=True, **kwargs):
582
+ return self.decode_tiled(latent, **kwargs) if chunked else self.decode(latent)
583
+
584
+ def forward(self, audio, sample=False, generator=None):
585
+ return self.decode(self.encode(audio, sample=sample, generator=generator))
586
+
587
+
588
+ YuE2VAEConfig.register_for_auto_class("AutoConfig")
589
+ YuE2VAE.register_for_auto_class("AutoModel")
vae_legacy/weights_manifest.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "schema": 1,
3
+ "files": {
4
+ "model.safetensors": {
5
+ "bytes": 530512720,
6
+ "sha256": "b6d283628913bb41145ba99e2314eef613905ee95f690eb70e8212d5f4965044"
7
+ }
8
+ }
9
+ }