Fabrice-TIERCELIN commited on
Commit
d3091ae
·
verified ·
1 Parent(s): 984489e

Upload 7 files

Browse files
Files changed (7) hide show
  1. LICENSE.txt +77 -0
  2. Notice +233 -0
  3. README.md +497 -0
  4. README_zh.md +494 -0
  5. gradio_server.py +141 -0
  6. requirements.txt +14 -0
  7. sample_video.py +58 -0
LICENSE.txt ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT
2
+ Tencent HunyuanVideo Release Date: December 3, 2024
3
+ THIS LICENSE AGREEMENT DOES NOT APPLY IN THE EUROPEAN UNION, UNITED KINGDOM AND SOUTH KOREA AND IS EXPRESSLY LIMITED TO THE TERRITORY, AS DEFINED BELOW.
4
+ By clicking to agree or by using, reproducing, modifying, distributing, performing or displaying any portion or element of the Tencent Hunyuan Works, including via any Hosted Service, You will be deemed to have recognized and accepted the content of this Agreement, which is effective immediately.
5
+ 1. DEFINITIONS.
6
+ a. “Acceptable Use Policy” shall mean the policy made available by Tencent as set forth in the Exhibit A.
7
+ b. “Agreement” shall mean the terms and conditions for use, reproduction, distribution, modification, performance and displaying of Tencent Hunyuan Works or any portion or element thereof set forth herein.
8
+ c. “Documentation” shall mean the specifications, manuals and documentation for Tencent Hunyuan made publicly available by Tencent.
9
+ d. “Hosted Service” shall mean a hosted service offered via an application programming interface (API), web access, or any other electronic or remote means.
10
+ e. “Licensee,” “You” or “Your” shall mean a natural person or legal entity exercising the rights granted by this Agreement and/or using the Tencent Hunyuan Works for any purpose and in any field of use.
11
+ f. “Materials” shall mean, collectively, Tencent’s proprietary Tencent Hunyuan and Documentation (and any portion thereof) as made available by Tencent under this Agreement.
12
+ g. “Model Derivatives” shall mean all: (i) modifications to Tencent Hunyuan or any Model Derivative of Tencent Hunyuan; (ii) works based on Tencent Hunyuan or any Model Derivative of Tencent Hunyuan; or (iii) any other machine learning model which is created by transfer of patterns of the weights, parameters, operations, or Output of Tencent Hunyuan or any Model Derivative of Tencent Hunyuan, to that model in order to cause that model to perform similarly to Tencent Hunyuan or a Model Derivative of Tencent Hunyuan, including distillation methods, methods that use intermediate data representations, or methods based on the generation of synthetic data Outputs by Tencent Hunyuan or a Model Derivative of Tencent Hunyuan for training that model. For clarity, Outputs by themselves are not deemed Model Derivatives.
13
+ h. “Output” shall mean the information and/or content output of Tencent Hunyuan or a Model Derivative that results from operating or otherwise using Tencent Hunyuan or a Model Derivative, including via a Hosted Service.
14
+ i. “Tencent,” “We” or “Us” shall mean THL A29 Limited.
15
+ j. “Tencent Hunyuan” shall mean the large language models, text/image/video/audio/3D generation models, and multimodal large language models and their software and algorithms, including trained model weights, parameters (including optimizer states), machine-learning model code, inference-enabling code, training-enabling code, fine-tuning enabling code and other elements of the foregoing made publicly available by Us, including, without limitation to, Tencent HunyuanVideo released at [https://github.com/Tencent/HunyuanVideo].
16
+ k. “Tencent Hunyuan Works” shall mean: (i) the Materials; (ii) Model Derivatives; and (iii) all derivative works thereof.
17
+ l. “Territory” shall mean the worldwide territory, excluding the territory of the European Union, United Kingdom and South Korea.
18
+ m. “Third Party” or “Third Parties” shall mean individuals or legal entities that are not under common control with Us or You.
19
+ n. “including” shall mean including but not limited to.
20
+ 2. GRANT OF RIGHTS.
21
+ We grant You, for the Territory only, a non-exclusive, non-transferable and royalty-free limited license under Tencent’s intellectual property or other rights owned by Us embodied in or utilized by the Materials to use, reproduce, distribute, create derivative works of (including Model Derivatives), and make modifications to the Materials, only in accordance with the terms of this Agreement and the Acceptable Use Policy, and You must not violate (or encourage or permit anyone else to violate) any term of this Agreement or the Acceptable Use Policy.
22
+ 3. DISTRIBUTION.
23
+ You may, subject to Your compliance with this Agreement, distribute or make available to Third Parties the Tencent Hunyuan Works, exclusively in the Territory, provided that You meet all of the following conditions:
24
+ a. You must provide all such Third Party recipients of the Tencent Hunyuan Works or products or services using them a copy of this Agreement;
25
+ b. You must cause any modified files to carry prominent notices stating that You changed the files;
26
+ c. You are encouraged to: (i) publish at least one technology introduction blogpost or one public statement expressing Your experience of using the Tencent Hunyuan Works; and (ii) mark the products or services developed by using the Tencent Hunyuan Works to indicate that the product/service is “Powered by Tencent Hunyuan”; and
27
+ d. All distributions to Third Parties (other than through a Hosted Service) must be accompanied by a “Notice” text file that contains the following notice: “Tencent Hunyuan is licensed under the Tencent Hunyuan Community License Agreement, Copyright © 2024 Tencent. All Rights Reserved. The trademark rights of “Tencent Hunyuan” are owned by Tencent or its affiliate.”
28
+ You may add Your own copyright statement to Your modifications and, except as set forth in this Section and in Section 5, may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Model Derivatives as a whole, provided Your use, reproduction, modification, distribution, performance and display of the work otherwise complies with the terms and conditions of this Agreement (including as regards the Territory). If You receive Tencent Hunyuan Works from a Licensee as part of an integrated end user product, then this Section 3 of this Agreement will not apply to You.
29
+ 4. ADDITIONAL COMMERCIAL TERMS.
30
+ If, on the Tencent Hunyuan version release date, the monthly active users of all products or services made available by or for Licensee is greater than 100 million monthly active users in the preceding calendar month, You must request a license from Tencent, which Tencent may grant to You in its sole discretion, and You are not authorized to exercise any of the rights under this Agreement unless or until Tencent otherwise expressly grants You such rights.
31
+ 5. RULES OF USE.
32
+ a. Your use of the Tencent Hunyuan Works must comply with applicable laws and regulations (including trade compliance laws and regulations) and adhere to the Acceptable Use Policy for the Tencent Hunyuan Works, which is hereby incorporated by reference into this Agreement. You must include the use restrictions referenced in these Sections 5(a) and 5(b) as an enforceable provision in any agreement (e.g., license agreement, terms of use, etc.) governing the use and/or distribution of Tencent Hunyuan Works and You must provide notice to subsequent users to whom You distribute that Tencent Hunyuan Works are subject to the use restrictions in these Sections 5(a) and 5(b).
33
+ b. You must not use the Tencent Hunyuan Works or any Output or results of the Tencent Hunyuan Works to improve any other AI model (other than Tencent Hunyuan or Model Derivatives thereof).
34
+ c. You must not use, reproduce, modify, distribute, or display the Tencent Hunyuan Works, Output or results of the Tencent Hunyuan Works outside the Territory. Any such use outside the Territory is unlicensed and unauthorized under this Agreement.
35
+ 6. INTELLECTUAL PROPERTY.
36
+ a. Subject to Tencent’s ownership of Tencent Hunyuan Works made by or for Tencent and intellectual property rights therein, conditioned upon Your compliance with the terms and conditions of this Agreement, as between You and Tencent, You will be the owner of any derivative works and modifications of the Materials and any Model Derivatives that are made by or for You.
37
+ b. No trademark licenses are granted under this Agreement, and in connection with the Tencent Hunyuan Works, Licensee may not use any name or mark owned by or associated with Tencent or any of its affiliates, except as required for reasonable and customary use in describing and distributing the Tencent Hunyuan Works. Tencent hereby grants You a license to use “Tencent Hunyuan” (the “Mark”) in the Territory solely as required to comply with the provisions of Section 3(c), provided that You comply with any applicable laws related to trademark protection. All goodwill arising out of Your use of the Mark will inure to the benefit of Tencent.
38
+ c. If You commence a lawsuit or other proceedings (including a cross-claim or counterclaim in a lawsuit) against Us or any person or entity alleging that the Materials or any Output, or any portion of any of the foregoing, infringe any intellectual property or other right owned or licensable by You, then all licenses granted to You under this Agreement shall terminate as of the date such lawsuit or other proceeding is filed. You will defend, indemnify and hold harmless Us from and against any claim by any Third Party arising out of or related to Your or the Third Party’s use or distribution of the Tencent Hunyuan Works.
39
+ d. Tencent claims no rights in Outputs You generate. You and Your users are solely responsible for Outputs and their subsequent uses.
40
+ 7. DISCLAIMERS OF WARRANTY AND LIMITATIONS OF LIABILITY.
41
+ a. We are not obligated to support, update, provide training for, or develop any further version of the Tencent Hunyuan Works or to grant any license thereto.
42
+ b. UNLESS AND ONLY TO THE EXTENT REQUIRED BY APPLICABLE LAW, THE TENCENT HUNYUAN WORKS AND ANY OUTPUT AND RESULTS THEREFROM ARE PROVIDED “AS IS” WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES OF ANY KIND INCLUDING ANY WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, COURSE OF DEALING, USAGE OF TRADE, OR FITNESS FOR A PARTICULAR PURPOSE. YOU ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USING, REPRODUCING, MODIFYING, PERFORMING, DISPLAYING OR DISTRIBUTING ANY OF THE TENCENT HUNYUAN WORKS OR OUTPUTS AND ASSUME ANY AND ALL RISKS ASSOCIATED WITH YOUR OR A THIRD PARTY’S USE OR DISTRIBUTION OF ANY OF THE TENCENT HUNYUAN WORKS OR OUTPUTS AND YOUR EXERCISE OF RIGHTS AND PERMISSIONS UNDER THIS AGREEMENT.
43
+ c. TO THE FULLEST EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL TENCENT OR ITS AFFILIATES BE LIABLE UNDER ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, TORT, NEGLIGENCE, PRODUCTS LIABILITY, OR OTHERWISE, FOR ANY DAMAGES, INCLUDING ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, EXEMPLARY, CONSEQUENTIAL OR PUNITIVE DAMAGES, OR LOST PROFITS OF ANY KIND ARISING FROM THIS AGREEMENT OR RELATED TO ANY OF THE TENCENT HUNYUAN WORKS OR OUTPUTS, EVEN IF TENCENT OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF ANY OF THE FOREGOING.
44
+ 8. SURVIVAL AND TERMINATION.
45
+ a. The term of this Agreement shall commence upon Your acceptance of this Agreement or access to the Materials and will continue in full force and effect until terminated in accordance with the terms and conditions herein.
46
+ b. We may terminate this Agreement if You breach any of the terms or conditions of this Agreement. Upon termination of this Agreement, You must promptly delete and cease use of the Tencent Hunyuan Works. Sections 6(a), 6(c), 7 and 9 shall survive the termination of this Agreement.
47
+ 9. GOVERNING LAW AND JURISDICTION.
48
+ a. This Agreement and any dispute arising out of or relating to it will be governed by the laws of the Hong Kong Special Administrative Region of the People’s Republic of China, without regard to conflict of law principles, and the UN Convention on Contracts for the International Sale of Goods does not apply to this Agreement.
49
+ b. Exclusive jurisdiction and venue for any dispute arising out of or relating to this Agreement will be a court of competent jurisdiction in the Hong Kong Special Administrative Region of the People’s Republic of China, and Tencent and Licensee consent to the exclusive jurisdiction of such court with respect to any such dispute.
50
+
51
+ EXHIBIT A
52
+ ACCEPTABLE USE POLICY
53
+
54
+ Tencent reserves the right to update this Acceptable Use Policy from time to time.
55
+ Last modified: November 5, 2024
56
+
57
+ Tencent endeavors to promote safe and fair use of its tools and features, including Tencent Hunyuan. You agree not to use Tencent Hunyuan or Model Derivatives:
58
+ 1. Outside the Territory;
59
+ 2. In any way that violates any applicable national, federal, state, local, international or any other law or regulation;
60
+ 3. To harm Yourself or others;
61
+ 4. To repurpose or distribute output from Tencent Hunyuan or any Model Derivatives to harm Yourself or others;
62
+ 5. To override or circumvent the safety guardrails and safeguards We have put in place;
63
+ 6. For the purpose of exploiting, harming or attempting to exploit or harm minors in any way;
64
+ 7. To generate or disseminate verifiably false information and/or content with the purpose of harming others or influencing elections;
65
+ 8. To generate or facilitate false online engagement, including fake reviews and other means of fake online engagement;
66
+ 9. To intentionally defame, disparage or otherwise harass others;
67
+ 10. To generate and/or disseminate malware (including ransomware) or any other content to be used for the purpose of harming electronic systems;
68
+ 11. To generate or disseminate personal identifiable information with the purpose of harming others;
69
+ 12. To generate or disseminate information (including images, code, posts, articles), and place the information in any public context (including –through the use of bot generated tweets), without expressly and conspicuously identifying that the information and/or content is machine generated;
70
+ 13. To impersonate another individual without consent, authorization, or legal right;
71
+ 14. To make high-stakes automated decisions in domains that affect an individual’s safety, rights or wellbeing (e.g., law enforcement, migration, medicine/health, management of critical infrastructure, safety components of products, essential services, credit, employment, housing, education, social scoring, or insurance);
72
+ 15. In a manner that violates or disrespects the social ethics and moral standards of other countries or regions;
73
+ 16. To perform, facilitate, threaten, incite, plan, promote or encourage violent extremism or terrorism;
74
+ 17. For any use intended to discriminate against or harm individuals or groups based on protected characteristics or categories, online or offline social behavior or known or predicted personal or personality characteristics;
75
+ 18. To intentionally exploit any of the vulnerabilities of a specific group of persons based on their age, social, physical or mental characteristics, in order to materially distort the behavior of a person pertaining to that group in a manner that causes or is likely to cause that person or another person physical or psychological harm;
76
+ 19. For military purposes;
77
+ 20. To engage in the unauthorized or unlicensed practice of any profession including, but not limited to, financial, legal, medical/health, or other professional practices.
Notice ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Usage and Legal Notices:
2
+
3
+ Tencent is pleased to support the open source community by making Tencent HunyuanVideo available.
4
+
5
+ Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. The below software and/or models in this distribution may have been modified by THL A29 Limited ("Tencent Modifications"). All Tencent Modifications are Copyright (C) THL A29 Limited.
6
+
7
+ Tencent HunyuanVideo is licensed under the TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT except for the third-party components listed below. Tencent HunyuanVideo does not impose any additional limitations beyond what is outlined in the repsective licenses of these third-party components. Users must comply with all terms and conditions of original licenses of these third-party components and must ensure that the usage of the third party components adheres to all relevant laws and regulations.
8
+
9
+ For avoidance of doubts, Tencent HunyuanVideo means the large language models and their software and algorithms, including trained model weights, parameters (including optimizer states), machine-learning model code, inference-enabling code, training-enabling code, fine-tuning enabling code and other elements of the foregoing may be made publicly available by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
10
+
11
+
12
+ Other dependencies and licenses:
13
+
14
+
15
+ Open Source Model Licensed under the Apache License Version 2.0:
16
+ The below software in this distribution may have been modified by THL A29 Limited ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
17
+ --------------------------------------------------------------------
18
+ 1. diffusers
19
+ Copyright (c) diffusers original author and authors
20
+ Please note this software has been modified by Tencent in this distribution.
21
+
22
+ 2. transformers
23
+ Copyright (c) transformers original author and authors
24
+
25
+ 3. safetensors
26
+ Copyright (c) safetensors original author and authors
27
+
28
+ 4. flux
29
+ Copyright (c) flux original author and authors
30
+
31
+
32
+ Terms of the Apache License Version 2.0:
33
+ --------------------------------------------------------------------
34
+ Apache License
35
+
36
+ Version 2.0, January 2004
37
+
38
+ http://www.apache.org/licenses/
39
+
40
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
41
+ 1. Definitions.
42
+
43
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
44
+
45
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
46
+
47
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
48
+
49
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
50
+
51
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
52
+
53
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
54
+
55
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
56
+
57
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
58
+
59
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
60
+
61
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
64
+
65
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
66
+
67
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
68
+
69
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
70
+
71
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
72
+
73
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
74
+
75
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
76
+
77
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
78
+
79
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
80
+
81
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
82
+
83
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
84
+
85
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
86
+
87
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
88
+
89
+ END OF TERMS AND CONDITIONS
90
+
91
+
92
+
93
+ Open Source Software Licensed under the BSD 2-Clause License:
94
+ --------------------------------------------------------------------
95
+ 1. imageio
96
+ Copyright (c) 2014-2022, imageio developers
97
+ All rights reserved.
98
+
99
+
100
+ Terms of the BSD 2-Clause License:
101
+ --------------------------------------------------------------------
102
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
103
+
104
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
105
+
106
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
107
+
108
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
109
+
110
+
111
+
112
+ Open Source Software Licensed under the BSD 3-Clause License:
113
+ --------------------------------------------------------------------
114
+ 1. torchvision
115
+ Copyright (c) Soumith Chintala 2016,
116
+ All rights reserved.
117
+
118
+ 2. flash-attn
119
+ Copyright (c) 2022, the respective contributors, as shown by the AUTHORS file.
120
+ All rights reserved.
121
+
122
+
123
+ Terms of the BSD 3-Clause License:
124
+ --------------------------------------------------------------------
125
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
126
+
127
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
128
+
129
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
130
+
131
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
132
+
133
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
134
+
135
+
136
+
137
+ Open Source Software Licensed under the BSD 3-Clause License and Other Licenses of the Third-Party Components therein:
138
+ --------------------------------------------------------------------
139
+ 1. torch
140
+ Copyright (c) 2016- Facebook, Inc (Adam Paszke)
141
+ Copyright (c) 2014- Facebook, Inc (Soumith Chintala)
142
+ Copyright (c) 2011-2014 Idiap Research Institute (Ronan Collobert)
143
+ Copyright (c) 2012-2014 Deepmind Technologies (Koray Kavukcuoglu)
144
+ Copyright (c) 2011-2012 NEC Laboratories America (Koray Kavukcuoglu)
145
+ Copyright (c) 2011-2013 NYU (Clement Farabet)
146
+ Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston)
147
+ Copyright (c) 2006 Idiap Research Institute (Samy Bengio)
148
+ Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz)
149
+
150
+
151
+ A copy of the BSD 3-Clause is included in this file.
152
+
153
+ For the license of other third party components, please refer to the following URL:
154
+ https://github.com/pytorch/pytorch/tree/v2.1.1/third_party
155
+
156
+
157
+ Open Source Software Licensed under the BSD 3-Clause License and Other Licenses of the Third-Party Components therein:
158
+ --------------------------------------------------------------------
159
+ 1. pandas
160
+ Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
161
+ All rights reserved.
162
+
163
+ Copyright (c) 2011-2023, Open source contributors.
164
+
165
+
166
+ A copy of the BSD 3-Clause is included in this file.
167
+
168
+ For the license of other third party components, please refer to the following URL:
169
+ https://github.com/pandas-dev/pandas/tree/v2.0.3/LICENSES
170
+
171
+
172
+ Open Source Software Licensed under the BSD 3-Clause License and Other Licenses of the Third-Party Components therein:
173
+ --------------------------------------------------------------------
174
+ 1. numpy
175
+ Copyright (c) 2005-2022, NumPy Developers.
176
+ All rights reserved.
177
+
178
+
179
+ A copy of the BSD 3-Clause is included in this file.
180
+
181
+ For the license of other third party components, please refer to the following URL:
182
+ https://github.com/numpy/numpy/blob/v1.24.4/LICENSES_bundled.txt
183
+
184
+
185
+ Open Source Software Licensed under the MIT License:
186
+ --------------------------------------------------------------------
187
+ 1. einops
188
+ Copyright (c) 2018 Alex Rogozhnikov
189
+
190
+ 2. loguru
191
+ Copyright (c) 2017
192
+
193
+
194
+ Terms of the MIT License:
195
+ --------------------------------------------------------------------
196
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
197
+
198
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
199
+
200
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
201
+
202
+
203
+
204
+ Open Source Software Licensed under the MIT License and Other Licenses of the Third-Party Components therein:
205
+ --------------------------------------------------------------------
206
+ 1. tqdm
207
+ Copyright (c) 2013 noamraph
208
+
209
+
210
+ A copy of the MIT is included in this file.
211
+
212
+ For the license of other third party components, please refer to the following URL:
213
+ https://github.com/tqdm/tqdm/blob/v4.66.2/LICENCE
214
+
215
+
216
+
217
+ Open Source Model Licensed under the MIT License:
218
+ --------------------------------------------------------------------
219
+ 1. clip-large
220
+ Copyright (c) 2021 OpenAI
221
+
222
+
223
+ A copy of the MIT is included in this file.
224
+
225
+
226
+ --------------------------------------------------------------------
227
+ We may also use other third-party components:
228
+
229
+ 1. llava-llama3
230
+
231
+ Copyright (c) llava-llama3 original author and authors
232
+
233
+ URL: https://huggingface.co/xtuner/llava-llama-3-8b-v1_1-transformers#model
README.md ADDED
@@ -0,0 +1,497 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- ## **HunyuanVideo** -->
2
+
3
+ [中文阅读](./README_zh.md)
4
+
5
+ <p align="center">
6
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/logo.png" height=100>
7
+ </p>
8
+
9
+ # HunyuanVideo: A Systematic Framework For Large Video Generation Model
10
+
11
+ <div align="center">
12
+ <a href="https://github.com/Tencent/HunyuanVideo"><img src="https://img.shields.io/static/v1?label=HunyuanVideo Code&message=Github&color=blue"></a> &ensp;
13
+ <a href="https://aivideo.hunyuan.tencent.com"><img src="https://img.shields.io/static/v1?label=Project%20Page&message=Web&color=green"></a> &ensp;
14
+ <a href="https://video.hunyuan.tencent.com"><img src="https://img.shields.io/static/v1?label=Playground&message=Web&color=green"></a>
15
+ </div>
16
+ <div align="center">
17
+ <a href="https://arxiv.org/abs/2412.03603"><img src="https://img.shields.io/static/v1?label=Tech Report&message=Arxiv&color=red"></a> &ensp;
18
+ <a href="https://aivideo.hunyuan.tencent.com/hunyuanvideo.pdf"><img src="https://img.shields.io/static/v1?label=Tech Report&message=High-Quality Version (~350M)&color=red"></a>
19
+ </div>
20
+ <div align="center">
21
+ <a href="https://huggingface.co/tencent/HunyuanVideo"><img src="https://img.shields.io/static/v1?label=HunyuanVideo&message=HuggingFace&color=yellow"></a> &ensp;
22
+ <a href="https://huggingface.co/docs/diffusers/main/api/pipelines/hunyuan_video"><img src="https://img.shields.io/static/v1?label=HunyuanVideo&message=Diffusers&color=yellow"></a> &ensp;
23
+ <a href="https://huggingface.co/tencent/HunyuanVideo-PromptRewrite"><img src="https://img.shields.io/static/v1?label=HunyuanVideo-PromptRewrite&message=HuggingFace&color=yellow"></a>
24
+
25
+
26
+ [![Replicate](https://replicate.com/zsxkib/hunyuan-video/badge)](https://replicate.com/zsxkib/hunyuan-video)
27
+ </div>
28
+
29
+ <p align="center">
30
+ 👋 Join our <a href="assets/WECHAT.md" target="_blank">WeChat</a> and <a href="https://discord.gg/V8V6JK4f" target="_blank">Discord</a>
31
+ </p>
32
+ <p align="center">
33
+
34
+ -----
35
+
36
+ This repo contains PyTorch model definitions, pre-trained weights and inference/sampling code for our paper exploring HunyuanVideo. You can find more visualizations on our [project page](https://aivideo.hunyuan.tencent.com).
37
+
38
+ > [**HunyuanVideo: A Systematic Framework For Large Video Generation Model**](https://arxiv.org/abs/2412.03603) <be>
39
+
40
+
41
+
42
+ ## 🔥🔥🔥 News!!
43
+
44
+ * Dec 18, 2024: 🏃‍♂️ We release the [FP8 model weights](https://huggingface.co/tencent/HunyuanVideo/blob/main/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt) of HunyuanVideo to save more GPU memory.
45
+ * Dec 17, 2024: 🤗 HunyuanVideo has been integrated into [Diffusers](https://huggingface.co/docs/diffusers/main/api/pipelines/hunyuan_video).
46
+ * Dec 7, 2024: 🚀 We release the parallel inference code for HunyuanVideo powered by [xDiT](https://github.com/xdit-project/xDiT).
47
+ * Dec 3, 2024: 👋 We release the inference code and model weights of HunyuanVideo. [Download](https://github.com/Tencent/HunyuanVideo/blob/main/ckpts/README.md).
48
+
49
+
50
+
51
+ ## 🎥 Demo
52
+
53
+ <div align="center">
54
+ <video src="https://github.com/user-attachments/assets/22440764-0d7e-438e-a44d-d0dad1006d3d" width="70%" poster="./assets/video_poster.png"> </video>
55
+ </div>
56
+
57
+
58
+ ## 🧩 Community Contributions
59
+
60
+ If you develop/use HunyuanVideo in your projects, welcome to let us know.
61
+ - ComfyUI (FP8 Inference, V2V and IP2V Generation): [ComfyUI-HunyuanVideoWrapper](https://github.com/kijai/ComfyUI-HunyuanVideoWrapper) by [Kijai](https://github.com/kijai)
62
+ - FastVideo (Consistency Distilled Model): [FastVideo](https://github.com/hao-ai-lab/FastVideo) by [Hao AI Lab](https://hao-ai-lab.github.io/)
63
+ - HunyuanVideo-gguf (GGUF Version and Quantization): [HunyuanVideo-gguf](https://huggingface.co/city96/HunyuanVideo-gguf) by [city96](https://huggingface.co/city96)
64
+ - Enhance-A-Video (Better Generated Video for Free): [Enhance-A-Video](https://github.com/NUS-HPC-AI-Lab/Enhance-A-Video) by [NUS-HPC-AI-Lab](https://ai.comp.nus.edu.sg/)
65
+ - TeaCache (Cache-based Accelerate): [TeaCache](https://github.com/LiewFeng/TeaCache) by [Feng Liu](https://github.com/LiewFeng)
66
+
67
+
68
+
69
+
70
+ ## 📑 Open-source Plan
71
+
72
+ - HunyuanVideo (Text-to-Video Model)
73
+ - [x] Inference
74
+ - [x] Checkpoints
75
+ - [x] Multi-gpus Sequence Parallel inference (Faster inference speed on more gpus)
76
+ - [x] Web Demo (Gradio)
77
+ - [x] Diffusers
78
+ - [x] FP8 Quantified weight
79
+ - [ ] Penguin Video Benchmark
80
+ - [ ] ComfyUI
81
+ - [ ] Multi-gpus PipeFusion inference (Low memory requirements)
82
+ - HunyuanVideo (Image-to-Video Model)
83
+ - [ ] Inference
84
+ - [ ] Checkpoints
85
+
86
+
87
+
88
+ ## Contents
89
+ - [HunyuanVideo: A Systematic Framework For Large Video Generation Model](#hunyuanvideo-a-systematic-framework-for-large-video-generation-model)
90
+ - [🎥 Demo](#-demo)
91
+ - [🔥🔥🔥 News!!](#-news)
92
+ - [🧩 Community Contributions](#-community-contributions)
93
+ - [📑 Open-source Plan](#-open-source-plan)
94
+ - [Contents](#contents)
95
+ - [**Abstract**](#abstract)
96
+ - [**HunyuanVideo Overall Architecture**](#hunyuanvideo-overall-architecture)
97
+ - [🎉 **HunyuanVideo Key Features**](#-hunyuanvideo-key-features)
98
+ - [**Unified Image and Video Generative Architecture**](#unified-image-and-video-generative-architecture)
99
+ - [**MLLM Text Encoder**](#mllm-text-encoder)
100
+ - [**3D VAE**](#3d-vae)
101
+ - [**Prompt Rewrite**](#prompt-rewrite)
102
+ - [📈 Comparisons](#-comparisons)
103
+ - [📜 Requirements](#-requirements)
104
+ - [🛠️ Dependencies and Installation](#️-dependencies-and-installation)
105
+ - [Installation Guide for Linux](#installation-guide-for-linux)
106
+ - [🧱 Download Pretrained Models](#-download-pretrained-models)
107
+ - [🔑 Single-gpu Inference](#-single-gpu-inference)
108
+ - [Using Command Line](#using-command-line)
109
+ - [Run a Gradio Server](#run-a-gradio-server)
110
+ - [More Configurations](#more-configurations)
111
+ - [🚀 Parallel Inference on Multiple GPUs by xDiT](#-parallel-inference-on-multiple-gpus-by-xdit)
112
+ - [Using Command Line](#using-command-line-1)
113
+ - [🚀 FP8 Inference](#--fp8-inference)
114
+ - [Using Command Line](#using-command-line-2)
115
+ - [🔗 BibTeX](#-bibtex)
116
+ - [Acknowledgements](#acknowledgements)
117
+ - [Star History](#star-history)
118
+ ---
119
+
120
+ ## **Abstract**
121
+ We present HunyuanVideo, a novel open-source video foundation model that exhibits performance in video generation that is comparable to, if not superior to, leading closed-source models. In order to train HunyuanVideo model, we adopt several key technologies for model learning, including data curation, image-video joint model training, and an efficient infrastructure designed to facilitate large-scale model training and inference. Additionally, through an effective strategy for scaling model architecture and dataset, we successfully trained a video generative model with over 13 billion parameters, making it the largest among all open-source models.
122
+
123
+ We conducted extensive experiments and implemented a series of targeted designs to ensure high visual quality, motion diversity, text-video alignment, and generation stability. According to professional human evaluation results, HunyuanVideo outperforms previous state-of-the-art models, including Runway Gen-3, Luma 1.6, and 3 top-performing Chinese video generative models. By releasing the code and weights of the foundation model and its applications, we aim to bridge the gap between closed-source and open-source video foundation models. This initiative will empower everyone in the community to experiment with their ideas, fostering a more dynamic and vibrant video generation ecosystem.
124
+
125
+
126
+
127
+ ## **HunyuanVideo Overall Architecture**
128
+
129
+ HunyuanVideo is trained on a spatial-temporally
130
+ compressed latent space, which is compressed through a Causal 3D VAE. Text prompts are encoded
131
+ using a large language model, and used as the conditions. Taking Gaussian noise and the conditions as
132
+ input, our generative model produces a output latent, which is then decoded to images or videos through
133
+ the 3D VAE decoder.
134
+ <p align="center">
135
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/overall.png" height=300>
136
+ </p>
137
+
138
+
139
+ ## 🎉 **HunyuanVideo Key Features**
140
+
141
+ ### **Unified Image and Video Generative Architecture**
142
+ HunyuanVideo introduces the Transformer design and employs a Full Attention mechanism for unified image and video generation.
143
+ Specifically, we use a "Dual-stream to Single-stream" hybrid model design for video generation. In the dual-stream phase, video and text
144
+ tokens are processed independently through multiple Transformer blocks, enabling each modality to learn its own appropriate modulation mechanisms without interference. In the single-stream phase, we concatenate the video and text
145
+ tokens and feed them into subsequent Transformer blocks for effective multimodal information fusion.
146
+ This design captures complex interactions between visual and semantic information, enhancing
147
+ overall model performance.
148
+ <p align="center">
149
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/backbone.png" height=350>
150
+ </p>
151
+
152
+ ### **MLLM Text Encoder**
153
+ Some previous text-to-video models typically use pre-trained CLIP and T5-XXL as text encoders where CLIP uses Transformer Encoder and T5 uses an Encoder-Decoder structure. In contrast, we utilize a pre-trained Multimodal Large Language Model (MLLM) with a Decoder-Only structure as our text encoder, which has the following advantages: (i) Compared with T5, MLLM after visual instruction finetuning has better image-text alignment in the feature space, which alleviates the difficulty of the instruction following in diffusion models; (ii)
154
+ Compared with CLIP, MLLM has demonstrated superior ability in image detail description
155
+ and complex reasoning; (iii) MLLM can play as a zero-shot learner by following system instructions prepended to user prompts, helping text features pay more attention to key information. In addition, MLLM is based on causal attention while T5-XXL utilizes bidirectional attention that produces better text guidance for diffusion models. Therefore, we introduce an extra bidirectional token refiner to enhance text features.
156
+ <p align="center">
157
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/text_encoder.png" height=275>
158
+ </p>
159
+
160
+ ### **3D VAE**
161
+ HunyuanVideo trains a 3D VAE with CausalConv3D (Partially referred to [Open-Sora-Plan](https://github.com/PKU-YuanGroup/Open-Sora-Plan) ) to compress pixel-space videos and images into a compact latent space. We set the compression ratios of video length, space, and channel to 4, 8, and 16 respectively. This can significantly reduce the number of tokens for the subsequent diffusion transformer model, allowing us to train videos at the original resolution and frame rate.
162
+ <p align="center">
163
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/3dvae.png" height=150>
164
+ </p>
165
+
166
+ ### **Prompt Rewrite**
167
+ To address the variability in linguistic style and length of user-provided prompts, we fine-tune the [Hunyuan-Large model](https://github.com/Tencent/Tencent-Hunyuan-Large) as our prompt rewrite model to adapt the original user prompt to model-preferred prompt.
168
+
169
+ We provide two rewrite modes: Normal mode and Master mode, which can be called using different prompts. The prompts are shown [here](hyvideo/prompt_rewrite.py). The Normal mode is designed to enhance the video generation model's comprehension of user intent, facilitating a more accurate interpretation of the instructions provided. The Master mode enhances the description of aspects such as composition, lighting, and camera movement, which leans towards generating videos with a higher visual quality. However, this emphasis may occasionally result in the loss of some semantic details.
170
+
171
+ The Prompt Rewrite Model can be directly deployed and inferred using the [Hunyuan-Large original code](https://github.com/Tencent/Tencent-Hunyuan-Large). We release the weights of the Prompt Rewrite Model [here](https://huggingface.co/Tencent/HunyuanVideo-PromptRewrite).
172
+
173
+
174
+
175
+ ## 📈 Comparisons
176
+
177
+ To evaluate the performance of HunyuanVideo, we selected five strong baselines from closed-source video generation models. In total, we utilized 1,533 text prompts, generating an equal number of video samples with HunyuanVideo in a single run. For a fair comparison, we conducted inference only once, avoiding any cherry-picking of results. When comparing with the baseline methods, we maintained the default settings for all selected models, ensuring consistent video resolution. Videos were assessed based on three criteria: Text Alignment, Motion Quality, and Visual Quality. More than 60 professional evaluators performed the evaluation. Notably, HunyuanVideo demonstrated the best overall performance, particularly excelling in motion quality. Please note that the evaluation is based on Hunyuan Video's high-quality version. This is different from the currently released fast version.
178
+
179
+ <p align="center">
180
+ <table>
181
+ <thead>
182
+ <tr>
183
+ <th rowspan="2">Model</th> <th rowspan="2">Open Source</th> <th>Duration</th> <th>Text Alignment</th> <th>Motion Quality</th> <th rowspan="2">Visual Quality</th> <th rowspan="2">Overall</th> <th rowspan="2">Ranking</th>
184
+ </tr>
185
+ </thead>
186
+ <tbody>
187
+ <tr>
188
+ <td>HunyuanVideo (Ours)</td> <td> ✔ </td> <td>5s</td> <td>61.8%</td> <td>66.5%</td> <td>95.7%</td> <td>41.3%</td> <td>1</td>
189
+ </tr>
190
+ <tr>
191
+ <td>CNTopA (API)</td> <td> &#10008 </td> <td>5s</td> <td>62.6%</td> <td>61.7%</td> <td>95.6%</td> <td>37.7%</td> <td>2</td>
192
+ </tr>
193
+ <tr>
194
+ <td>CNTopB (Web)</td> <td> &#10008</td> <td>5s</td> <td>60.1%</td> <td>62.9%</td> <td>97.7%</td> <td>37.5%</td> <td>3</td>
195
+ </tr>
196
+ <tr>
197
+ <td>GEN-3 alpha (Web)</td> <td>&#10008</td> <td>6s</td> <td>47.7%</td> <td>54.7%</td> <td>97.5%</td> <td>27.4%</td> <td>4</td>
198
+ </tr>
199
+ <tr>
200
+ <td>Luma1.6 (API)</td><td>&#10008</td> <td>5s</td> <td>57.6%</td> <td>44.2%</td> <td>94.1%</td> <td>24.8%</td> <td>5</td>
201
+ </tr>
202
+ <tr>
203
+ <td>CNTopC (Web)</td> <td>&#10008</td> <td>5s</td> <td>48.4%</td> <td>47.2%</td> <td>96.3%</td> <td>24.6%</td> <td>6</td>
204
+ </tr>
205
+ </tbody>
206
+ </table>
207
+ </p>
208
+
209
+
210
+ ## 📜 Requirements
211
+
212
+ The following table shows the requirements for running HunyuanVideo model (batch size = 1) to generate videos:
213
+
214
+ | Model | Setting<br/>(height/width/frame) | GPU Peak Memory |
215
+ |:------------:|:--------------------------------:|:----------------:|
216
+ | HunyuanVideo | 720px1280px129f | 60GB |
217
+ | HunyuanVideo | 544px960px129f | 45GB |
218
+
219
+ * An NVIDIA GPU with CUDA support is required.
220
+ * The model is tested on a single 80G GPU.
221
+ * **Minimum**: The minimum GPU memory required is 60GB for 720px1280px129f and 45G for 544px960px129f.
222
+ * **Recommended**: We recommend using a GPU with 80GB of memory for better generation quality.
223
+ * Tested operating system: Linux
224
+
225
+
226
+
227
+ ## 🛠️ Dependencies and Installation
228
+
229
+ Begin by cloning the repository:
230
+ ```shell
231
+ git clone https://github.com/tencent/HunyuanVideo
232
+ cd HunyuanVideo
233
+ ```
234
+
235
+ ### Installation Guide for Linux
236
+
237
+ We recommend CUDA versions 12.4 or 11.8 for the manual installation.
238
+
239
+ Conda's installation instructions are available [here](https://docs.anaconda.com/free/miniconda/index.html).
240
+
241
+ ```shell
242
+ # 1. Create conda environment
243
+ conda create -n HunyuanVideo python==3.10.9
244
+
245
+ # 2. Activate the environment
246
+ conda activate HunyuanVideo
247
+
248
+ # 3. Install PyTorch and other dependencies using conda
249
+ # For CUDA 11.8
250
+ conda install pytorch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 pytorch-cuda=11.8 -c pytorch -c nvidia
251
+ # For CUDA 12.4
252
+ conda install pytorch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 pytorch-cuda=12.4 -c pytorch -c nvidia
253
+
254
+ # 4. Install pip dependencies
255
+ python -m pip install -r requirements.txt
256
+
257
+ # 5. Install flash attention v2 for acceleration (requires CUDA 11.8 or above)
258
+ python -m pip install ninja
259
+ python -m pip install git+https://github.com/Dao-AILab/[email protected]
260
+
261
+ # 6. Install xDiT for parallel inference (It is recommended to use torch 2.4.0 and flash-attn 2.6.3)
262
+ python -m pip install xfuser==0.4.0
263
+ ```
264
+
265
+ In case of running into float point exception(core dump) on the specific GPU type, you may try the following solutions:
266
+
267
+ ```shell
268
+ # Option 1: Making sure you have installed CUDA 12.4, CUBLAS>=12.4.5.8, and CUDNN>=9.00 (or simply using our CUDA 12 docker image).
269
+ pip install nvidia-cublas-cu12==12.4.5.8
270
+ export LD_LIBRARY_PATH=/opt/conda/lib/python3.8/site-packages/nvidia/cublas/lib/
271
+
272
+ # Option 2: Forcing to explictly use the CUDA 11.8 compiled version of Pytorch and all the other packages
273
+ pip uninstall -r requirements.txt # uninstall all packages
274
+ pip uninstall -y xfuser
275
+ pip install torch==2.4.0 --index-url https://download.pytorch.org/whl/cu118
276
+ pip install -r requirements.txt
277
+ pip install ninja
278
+ pip install git+https://github.com/Dao-AILab/[email protected]
279
+ pip install xfuser==0.4.0
280
+ ```
281
+
282
+ Additionally, HunyuanVideo also provides a pre-built Docker image. Use the following command to pull and run the docker image.
283
+
284
+ ```shell
285
+ # For CUDA 12.4 (updated to avoid float point exception)
286
+ docker pull hunyuanvideo/hunyuanvideo:cuda_12
287
+ docker run -itd --gpus all --init --net=host --uts=host --ipc=host --name hunyuanvideo --security-opt=seccomp=unconfined --ulimit=stack=67108864 --ulimit=memlock=-1 --privileged hunyuanvideo/hunyuanvideo:cuda_12
288
+
289
+ # For CUDA 11.8
290
+ docker pull hunyuanvideo/hunyuanvideo:cuda_11
291
+ docker run -itd --gpus all --init --net=host --uts=host --ipc=host --name hunyuanvideo --security-opt=seccomp=unconfined --ulimit=stack=67108864 --ulimit=memlock=-1 --privileged hunyuanvideo/hunyuanvideo:cuda_11
292
+ ```
293
+
294
+
295
+ ## 🧱 Download Pretrained Models
296
+
297
+ The details of download pretrained models are shown [here](ckpts/README.md).
298
+
299
+
300
+
301
+ ## 🔑 Single-gpu Inference
302
+
303
+ We list the height/width/frame settings we support in the following table.
304
+
305
+ | Resolution | h/w=9:16 | h/w=16:9 | h/w=4:3 | h/w=3:4 | h/w=1:1 |
306
+ |:---------------------:|:----------------------------:|:---------------:|:---------------:|:---------------:|:---------------:|
307
+ | 540p | 544px960px129f | 960px544px129f | 624px832px129f | 832px624px129f | 720px720px129f |
308
+ | 720p (recommended) | 720px1280px129f | 1280px720px129f | 1104px832px129f | 832px1104px129f | 960px960px129f |
309
+
310
+ ### Using Command Line
311
+
312
+ ```bash
313
+ cd HunyuanVideo
314
+
315
+ python3 sample_video.py \
316
+ --video-size 720 1280 \
317
+ --video-length 129 \
318
+ --infer-steps 50 \
319
+ --prompt "A cat walks on the grass, realistic style." \
320
+ --flow-reverse \
321
+ --use-cpu-offload \
322
+ --save-path ./results
323
+ ```
324
+
325
+ ### Run a Gradio Server
326
+ ```bash
327
+ python3 gradio_server.py --flow-reverse
328
+
329
+ # set SERVER_NAME and SERVER_PORT manually
330
+ # SERVER_NAME=0.0.0.0 SERVER_PORT=8081 python3 gradio_server.py --flow-reverse
331
+ ```
332
+
333
+ ### More Configurations
334
+
335
+ We list some more useful configurations for easy usage:
336
+
337
+ | Argument | Default | Description |
338
+ |:----------------------:|:---------:|:-----------------------------------------:|
339
+ | `--prompt` | None | The text prompt for video generation |
340
+ | `--video-size` | 720 1280 | The size of the generated video |
341
+ | `--video-length` | 129 | The length of the generated video |
342
+ | `--infer-steps` | 50 | The number of steps for sampling |
343
+ | `--embedded-cfg-scale` | 6.0 | Embedded Classifier free guidance scale |
344
+ | `--flow-shift` | 7.0 | Shift factor for flow matching schedulers |
345
+ | `--flow-reverse` | False | If reverse, learning/sampling from t=1 -> t=0 |
346
+ | `--seed` | None | The random seed for generating video, if None, we init a random seed |
347
+ | `--use-cpu-offload` | False | Use CPU offload for the model load to save more memory, necessary for high-res video generation |
348
+ | `--save-path` | ./results | Path to save the generated video |
349
+
350
+
351
+
352
+ ## 🚀 Parallel Inference on Multiple GPUs by xDiT
353
+
354
+ [xDiT](https://github.com/xdit-project/xDiT) is a Scalable Inference Engine for Diffusion Transformers (DiTs) on multi-GPU Clusters.
355
+ It has successfully provided low-latency parallel inference solutions for a variety of DiTs models, including mochi-1, CogVideoX, Flux.1, SD3, etc. This repo adopted the [Unified Sequence Parallelism (USP)](https://arxiv.org/abs/2405.07719) APIs for parallel inference of the HunyuanVideo model.
356
+
357
+ ### Using Command Line
358
+
359
+ For example, to generate a video with 8 GPUs, you can use the following command:
360
+
361
+ ```bash
362
+ cd HunyuanVideo
363
+
364
+ torchrun --nproc_per_node=8 sample_video.py \
365
+ --video-size 1280 720 \
366
+ --video-length 129 \
367
+ --infer-steps 50 \
368
+ --prompt "A cat walks on the grass, realistic style." \
369
+ --flow-reverse \
370
+ --seed 42 \
371
+ --ulysses-degree 8 \
372
+ --ring-degree 1 \
373
+ --save-path ./results
374
+ ```
375
+
376
+ You can change the `--ulysses-degree` and `--ring-degree` to control the parallel configurations for the best performance. The valid parallel configurations are shown in the following table.
377
+
378
+ <details>
379
+ <summary>Supported Parallel Configurations (Click to expand)</summary>
380
+
381
+ | --video-size | --video-length | --ulysses-degree x --ring-degree | --nproc_per_node |
382
+ |----------------------|----------------|----------------------------------|------------------|
383
+ | 1280 720 or 720 1280 | 129 | 8x1,4x2,2x4,1x8 | 8 |
384
+ | 1280 720 or 720 1280 | 129 | 1x5 | 5 |
385
+ | 1280 720 or 720 1280 | 129 | 4x1,2x2,1x4 | 4 |
386
+ | 1280 720 or 720 1280 | 129 | 3x1,1x3 | 3 |
387
+ | 1280 720 or 720 1280 | 129 | 2x1,1x2 | 2 |
388
+ | 1104 832 or 832 1104 | 129 | 4x1,2x2,1x4 | 4 |
389
+ | 1104 832 or 832 1104 | 129 | 3x1,1x3 | 3 |
390
+ | 1104 832 or 832 1104 | 129 | 2x1,1x2 | 2 |
391
+ | 960 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |
392
+ | 960 960 | 129 | 4x1,2x2,1x4 | 4 |
393
+ | 960 960 | 129 | 3x1,1x3 | 3 |
394
+ | 960 960 | 129 | 1x2,2x1 | 2 |
395
+ | 960 544 or 544 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |
396
+ | 960 544 or 544 960 | 129 | 4x1,2x2,1x4 | 4 |
397
+ | 960 544 or 544 960 | 129 | 3x1,1x3 | 3 |
398
+ | 960 544 or 544 960 | 129 | 1x2,2x1 | 2 |
399
+ | 832 624 or 624 832 | 129 | 4x1,2x2,1x4 | 4 |
400
+ | 624 832 or 624 832 | 129 | 3x1,1x3 | 3 |
401
+ | 832 624 or 624 832 | 129 | 2x1,1x2 | 2 |
402
+ | 720 720 | 129 | 1x5 | 5 |
403
+ | 720 720 | 129 | 3x1,1x3 | 3 |
404
+
405
+ </details>
406
+
407
+
408
+ <p align="center">
409
+ <table align="center">
410
+ <thead>
411
+ <tr>
412
+ <th colspan="4">Latency (Sec) for 1280x720 (129 frames 50 steps) on 8xGPU</th>
413
+ </tr>
414
+ <tr>
415
+ <th>1</th>
416
+ <th>2</th>
417
+ <th>4</th>
418
+ <th>8</th>
419
+ </tr>
420
+ </thead>
421
+ <tbody>
422
+ <tr>
423
+ <th>1904.08</th>
424
+ <th>934.09 (2.04x)</th>
425
+ <th>514.08 (3.70x)</th>
426
+ <th>337.58 (5.64x)</th>
427
+ </tr>
428
+
429
+ </tbody>
430
+ </table>
431
+ </p>
432
+
433
+
434
+
435
+ ## 🚀 FP8 Inference
436
+
437
+ Using HunyuanVideo with FP8 quantized weights, which saves about 10GB of GPU memory. You can download the [weights](https://huggingface.co/tencent/HunyuanVideo/blob/main/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt) and [weight scales](https://huggingface.co/tencent/HunyuanVideo/blob/main/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8_map.pt) from Huggingface.
438
+
439
+ ### Using Command Line
440
+
441
+ Here, you must explicitly specify the FP8 weight path. For example, to generate a video with fp8 weights, you can use the following command:
442
+
443
+ ```bash
444
+ cd HunyuanVideo
445
+
446
+ DIT_CKPT_PATH={PATH_TO_FP8_WEIGHTS}/{WEIGHT_NAME}_fp8.pt
447
+
448
+ python3 sample_video.py \
449
+ --dit-weight ${DIT_CKPT_PATH} \
450
+ --video-size 1280 720 \
451
+ --video-length 129 \
452
+ --infer-steps 50 \
453
+ --prompt "A cat walks on the grass, realistic style." \
454
+ --seed 42 \
455
+ --embedded-cfg-scale 6.0 \
456
+ --flow-shift 7.0 \
457
+ --flow-reverse \
458
+ --use-cpu-offload \
459
+ --use-fp8 \
460
+ --save-path ./results
461
+ ```
462
+
463
+
464
+
465
+ ## 🔗 BibTeX
466
+
467
+ If you find [HunyuanVideo](https://arxiv.org/abs/2412.03603) useful for your research and applications, please cite using this BibTeX:
468
+
469
+ ```BibTeX
470
+ @misc{kong2024hunyuanvideo,
471
+ title={HunyuanVideo: A Systematic Framework For Large Video Generative Models},
472
+ author={Weijie Kong, Qi Tian, Zijian Zhang, Rox Min, Zuozhuo Dai, Jin Zhou, Jiangfeng Xiong, Xin Li, Bo Wu, Jianwei Zhang, Kathrina Wu, Qin Lin, Aladdin Wang, Andong Wang, Changlin Li, Duojun Huang, Fang Yang, Hao Tan, Hongmei Wang, Jacob Song, Jiawang Bai, Jianbing Wu, Jinbao Xue, Joey Wang, Junkun Yuan, Kai Wang, Mengyang Liu, Pengyu Li, Shuai Li, Weiyan Wang, Wenqing Yu, Xinchi Deng, Yang Li, Yanxin Long, Yi Chen, Yutao Cui, Yuanbo Peng, Zhentao Yu, Zhiyu He, Zhiyong Xu, Zixiang Zhou, Zunnan Xu, Yangyu Tao, Qinglin Lu, Songtao Liu, Daquan Zhou, Hongfa Wang, Yong Yang, Di Wang, Yuhong Liu, and Jie Jiang, along with Caesar Zhong},
473
+ year={2024},
474
+ archivePrefix={arXiv preprint arXiv:2412.03603},
475
+ primaryClass={cs.CV},
476
+ url={https://arxiv.org/abs/2412.03603},
477
+ }
478
+ ```
479
+
480
+
481
+
482
+ ## Acknowledgements
483
+
484
+ We would like to thank the contributors to the [SD3](https://huggingface.co/stabilityai/stable-diffusion-3-medium), [FLUX](https://github.com/black-forest-labs/flux), [Llama](https://github.com/meta-llama/llama), [LLaVA](https://github.com/haotian-liu/LLaVA), [Xtuner](https://github.com/InternLM/xtuner), [diffusers](https://github.com/huggingface/diffusers) and [HuggingFace](https://huggingface.co) repositories, for their open research and exploration.
485
+ Additionally, we also thank the Tencent Hunyuan Multimodal team for their help with the text encoder.
486
+
487
+
488
+
489
+ ## Star History
490
+
491
+ <a href="https://star-history.com/#Tencent/HunyuanVideo&Date">
492
+ <picture>
493
+ <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=Tencent/HunyuanVideo&type=Date&theme=dark" />
494
+ <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=Tencent/HunyuanVideo&type=Date" />
495
+ <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=Tencent/HunyuanVideo&type=Date" />
496
+ </picture>
497
+ </a>
README_zh.md ADDED
@@ -0,0 +1,494 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- ## **HunyuanVideo** -->
2
+
3
+ [English](./README.md)
4
+
5
+ <p align="center">
6
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/logo.png" height=100>
7
+ </p>
8
+
9
+ # HunyuanVideo: A Systematic Framework For Large Video Generation Model
10
+
11
+ <div align="center">
12
+ <a href="https://github.com/Tencent/HunyuanVideo"><img src="https://img.shields.io/static/v1?label=HunyuanVideo Code&message=Github&color=blue"></a> &ensp;
13
+ <a href="https://aivideo.hunyuan.tencent.com"><img src="https://img.shields.io/static/v1?label=Project%20Page&message=Web&color=green"></a> &ensp;
14
+ <a href="https://video.hunyuan.tencent.com"><img src="https://img.shields.io/static/v1?label=Playground&message=Web&color=green"></a>
15
+ </div>
16
+ <div align="center">
17
+ <a href="https://arxiv.org/abs/2412.03603"><img src="https://img.shields.io/static/v1?label=Tech Report&message=Arxiv&color=red"></a> &ensp;
18
+ <a href="https://aivideo.hunyuan.tencent.com/hunyuanvideo.pdf"><img src="https://img.shields.io/static/v1?label=Tech Report&message=High-Quality Version (~350M)&color=red"></a>
19
+ </div>
20
+ <div align="center">
21
+ <a href="https://huggingface.co/tencent/HunyuanVideo"><img src="https://img.shields.io/static/v1?label=HunyuanVideo&message=HuggingFace&color=yellow"></a> &ensp;
22
+ <a href="https://huggingface.co/docs/diffusers/main/api/pipelines/hunyuan_video"><img src="https://img.shields.io/static/v1?label=HunyuanVideo&message=Diffusers&color=yellow"></a> &ensp;
23
+ <a href="https://huggingface.co/tencent/HunyuanVideo-PromptRewrite"><img src="https://img.shields.io/static/v1?label=HunyuanVideo-PromptRewrite&message=HuggingFace&color=yellow"></a>
24
+
25
+
26
+ [![Replicate](https://replicate.com/zsxkib/hunyuan-video/badge)](https://replicate.com/zsxkib/hunyuan-video)
27
+ </div>
28
+
29
+
30
+ <p align="center">
31
+ 👋 加入我们的 <a href="assets/WECHAT.md" target="_blank">WeChat</a> 和 <a href="https://discord.gg/GpARqvrh" target="_blank">Discord</a>
32
+ </p>
33
+
34
+
35
+
36
+ -----
37
+
38
+ 本仓库包含了 HunyuanVideo 项目的 PyTorch 模型定义、预训练权重和推理/采样代码。参考我们的项目页面 [project page](https://aivideo.hunyuan.tencent.com) 查看更多内容。
39
+
40
+ > [**HunyuanVideo: A Systematic Framework For Large Video Generation Model**](https://arxiv.org/abs/2412.03603) <br>
41
+
42
+
43
+
44
+ ## 🔥🔥🔥 更新!!
45
+
46
+ * 2024年12月18日: 🏃‍♂️ 开源 HunyuanVideo [FP8 模型权重](https://huggingface.co/tencent/HunyuanVideo/blob/main/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt),节省更多 GPU 显存。
47
+ * 2024年12月17日: 🤗 HunyuanVideo已经集成到[Diffusers](https://huggingface.co/docs/diffusers/main/api/pipelines/hunyuan_video)中。
48
+ * 2024年12月03日: 🚀 开源 HunyuanVideo 多卡并行推理代码,由[xDiT](https://github.com/xdit-project/xDiT)提供。
49
+ * 2024年12月03日: 👋 开源 HunyuanVideo 文生视频的推理代码和模型权重。
50
+
51
+
52
+
53
+ ## 🎥 作品展示
54
+
55
+ <div align="center">
56
+ <video width="70%" src="https://github.com/user-attachments/assets/22440764-0d7e-438e-a44d-d0dad1006d3d" poster="./assets/video_poster.png"> </video>
57
+ </div>
58
+
59
+
60
+ ## 🧩 社区贡献
61
+
62
+ 如果您的项目中有开发或使用 HunyuanVideo,欢迎告知我们。
63
+
64
+ - ComfyUI (支持FP8推理、V2V和IP2V生成): [ComfyUI-HunyuanVideoWrapper](https://github.com/kijai/ComfyUI-HunyuanVideoWrapper) by [Kijai](https://github.com/kijai)
65
+
66
+ - FastVideo (一致性蒸馏模型): [FastVideo](https://github.com/hao-ai-lab/FastVideo) by [Hao AI Lab](https://hao-ai-lab.github.io/)
67
+
68
+ - HunyuanVideo-gguf (GGUF、量化): [HunyuanVideo-gguf](https://huggingface.co/city96/HunyuanVideo-gguf) by [city96](https://huggingface.co/city96)
69
+
70
+ - Enhance-A-Video (生成更高质量的视频): [Enhance-A-Video](https://github.com/NUS-HPC-AI-Lab/Enhance-A-Video) by [NUS-HPC-AI-Lab](https://ai.comp.nus.edu.sg/)
71
+
72
+ - TeaCache (基于缓存的加速采样): [TeaCache](https://github.com/LiewFeng/TeaCache) by [Feng Liu](https://github.com/LiewFeng)
73
+
74
+
75
+
76
+ ## 📑 开源计划
77
+
78
+ - HunyuanVideo (文生视频模型)
79
+ - [x] 推理代码
80
+ - [x] 模型权重
81
+ - [x] 多GPU序列并行推理(GPU 越多,推理速度越快)
82
+ - [x] Web Demo (Gradio)
83
+ - [x] Diffusers
84
+ - [x] FP8 量化版本
85
+ - [ ] Penguin Video 基准测试集
86
+ - [ ] ComfyUI
87
+ - [ ] 多GPU PipeFusion并行推理 (更低显存需求)
88
+ - HunyuanVideo (图生视频模型)
89
+ - [ ] 推理代码
90
+ - [ ] 模型权重
91
+
92
+
93
+
94
+ ## 目录
95
+
96
+ - [HunyuanVideo: A Systematic Framework For Large Video Generation Model](#hunyuanvideo-a-systematic-framework-for-large-video-generation-model)
97
+ - [🎥 作品展示](#-作品展示)
98
+ - [🔥🔥🔥 更新!!](#-更新)
99
+ - [🧩 社区贡献](#-社区贡献)
100
+ - [📑 开源计划](#-开源计划)
101
+ - [目录](#目录)
102
+ - [**摘要**](#摘要)
103
+ - [**HunyuanVideo 的架构**](#hunyuanvideo-的架构)
104
+ - [🎉 **亮点**](#-亮点)
105
+ - [**统一的图视频生成架构**](#统一的图视频生成架构)
106
+ - [**MLLM 文本编码器**](#mllm-文本编码器)
107
+ - [**3D VAE**](#3d-vae)
108
+ - [**Prompt 改写**](#prompt-改写)
109
+ - [📈 能力评估](#-能力评估)
110
+ - [📜 运行配置](#-运行配置)
111
+ - [🛠️ 安装和依赖](#️-安装和依赖)
112
+ - [Linux 安装指引](#linux-安装指引)
113
+ - [🧱 下载预训练模型](#-下载预训练模型)
114
+ - [🔑 单卡推理](#-单卡推理)
115
+ - [使用命令行](#使用命令行)
116
+ - [运行gradio服务](#运行gradio服务)
117
+ - [更多配置](#更多配置)
118
+ - [🚀 使用 xDiT 实现多卡并行推理](#-使用-xdit-实现多卡并行推理)
119
+ - [使用命令行](#使用命令行-1)
120
+ - [🚀 FP8 Inference](#---fp8-inference)
121
+ - [Using Command Line](#using-command-line)
122
+ - [🔗 BibTeX](#-bibtex)
123
+ - [致谢](#致谢)
124
+ - [Star 趋势](#star-趋势)
125
+ ---
126
+
127
+
128
+
129
+ ## **摘要**
130
+
131
+ HunyuanVideo 是一个全新的开源视频生成大模型,具有与领先的闭源模型相媲美甚至更优的视频生成表现。为了训练 HunyuanVideo,我们采用了一个全面的框架,集成了数据整理、图像-视频联合模型训练和高效的基础设施以支持大规模模型训练和推理。此外,通过有效的模型架构和数据集扩展策略,我们成功地训练了一个拥有超过 130 亿参数的视频生成模型,使其成为最大的开源视频生成模型之一。
132
+
133
+ 我们在模型结构的设计上做了大量的实验以确保其能拥有高质量的视觉效果、多样的运动、文本-视频对齐和生成稳定性。根据专业人员的评估结果,HunyuanVideo 在综合指标上优于以往的最先进模型,包括 Runway Gen-3、Luma 1.6 和 3 个中文社区表现最好的视频生成模型。**通过开源基础模型和应用模型的代码和权重,我们旨在弥合闭源和开源视频基础模型之间的差距,帮助社区中的每个人都能够尝试自己的想法,促进更加动态和活跃的视频生成生态。**
134
+
135
+
136
+
137
+ ## **HunyuanVideo 的架构**
138
+
139
+ HunyuanVideo 是一个隐空间模型,训练时它采用了 3D VAE 压缩时间维度和空间维度的特征。文本提示通过一个大语言模型编码后作为条件输入模型,引导模型通过对高斯噪声的多步去噪,输出一个视频的隐空间表示。最后,推理时通过 3D VAE 解码器将隐空间表示解码为视频。
140
+ <p align="center">
141
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/overall.png" height=300>
142
+ </p>
143
+
144
+
145
+ ## 🎉 **亮点**
146
+
147
+ ### **统一的图视频生成架构**
148
+
149
+ HunyuanVideo 采用了 Transformer 和 Full Attention 的设计用于视频生成。具体来说,我们使用了一个“双流到单流”的混合模型设计用于视频生成。在双流阶段,视频和文本 token 通过并行的 Transformer Block 独立处理,使得每个模态可以学习适合自己的调制机制而不会相互干扰。在单流阶段,我们将视频和文本 token 连接起来并将它们输入到后续的 Transformer Block 中进行有效的多模态信息融合。这种设计捕捉了视觉和语义信息之间的复杂交互,增强了整体模型性能。
150
+ <p align="center">
151
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/backbone.png" height=350>
152
+ </p>
153
+
154
+ ### **MLLM 文本编码器**
155
+ 过去的视频生成模型通常使用预训练的 CLIP 和 T5-XXL 作为文本编码器,其中 CLIP 使用 Transformer Encoder,T5 使用 Encoder-Decoder 结构。HunyuanVideo 使用了一个预训练的 Multimodal Large Language Model (MLLM) 作为文本编码器,它具有以下优势:
156
+ * 与 T5 相比,MLLM 基于图文数据指令微调后在特征空间中具有更好的图像-文本对齐能力,这减轻了扩散模型中的图文对齐的难度;
157
+ * 与 CLIP 相比,MLLM 在图像的细节描述和复杂推理方面表现出更强的能力;
158
+ * MLLM 可以通过遵循系统指令实现零样本生成,帮助文本特征更多地关注关键信息。
159
+
160
+ 由于 MLLM 是基于 Causal Attention 的,而 T5-XXL 使用了 Bidirectional Attention 为扩散模型提供更好的文本引导。因此,我们引入了一个额外的 token 优化器来增强文本特征。
161
+ <p align="center">
162
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/text_encoder.png" height=275>
163
+ </p>
164
+
165
+ ### **3D VAE**
166
+ 我们的 VAE 采用了 CausalConv3D 作为 HunyuanVideo 的编码器和解码器,用于压缩视频的时间维度和空间维度,其中时间维度压缩 4 倍,空间维度压缩 8 倍,压缩为 16 channels。这样可以显著减少后续 Transformer 模型的 token 数量,使我们能够在原始分辨率和帧率下训练视频生成模型。
167
+ <p align="center">
168
+ <img src="https://raw.githubusercontent.com/Tencent/HunyuanVideo/refs/heads/main/assets/3dvae.png" height=150>
169
+ </p>
170
+
171
+ ### **Prompt 改写**
172
+ 为了解决用户输入文本提示的多样性和不一致性的困难,我们微调了 [Hunyuan-Large model](https://github.com/Tencent/Tencent-Hunyuan-Large) 模型作为我们的 prompt 改写模���,将用户输入的提示词改写为更适合模型偏好的写法。
173
+
174
+ 我们提供了两个改写模式:正常模式和导演模式。两种模式的提示词见[这里](hyvideo/prompt_rewrite.py)。正常模式旨在增强视频生成模型对用户意图的理解,从而更准确地解释提供的指令。导演模式增强了诸如构图、光照和摄像机移动等方面的描述,倾向于生成视觉质量更高的视频。注意,这种增强有时可能会导致一些语义细节的丢失。
175
+
176
+ Prompt 改写模型可以直接使用 [Hunyuan-Large](https://github.com/Tencent/Tencent-Hunyuan-Large) 部署和推理. 我们开源了 prompt 改写模型的权重,见[这里](https://huggingface.co/Tencent/HunyuanVideo-PromptRewrite).
177
+
178
+
179
+
180
+ ## 📈 能力评估
181
+
182
+ 为了评估 HunyuanVideo 的能力,我们选择了四个闭源视频生成模型作为对比。我们总共使用了 1,533 个 prompt,每个 prompt 通过一次推理生成了相同数量的视频样本。为了公平比较,我们只进行了一次推理以避免任何挑选。在与其他方法比较时,我们保持了所有选择模型的默认设置,并确保了视频分辨率的一致性。视频根据三个标准进行评估:文本对齐、运动质量和视觉质量。在 60 多名专业评估人员评估后,HunyuanVideo 在综合指标上表现最好,特别是在运动质量方面表现较为突出。
183
+
184
+ <p align="center">
185
+ <table>
186
+ <thead>
187
+ <tr>
188
+ <th rowspan="2">模型</th> <th rowspan="2">是否开源</th> <th>时长</th> <th>文本对齐</th> <th>运动质量</th> <th rowspan="2">视觉质量</th> <th rowspan="2">综合评价</th> <th rowspan="2">排序</th>
189
+ </tr>
190
+ </thead>
191
+ <tbody>
192
+ <tr>
193
+ <td>HunyuanVideo (Ours)</td> <td> ✔ </td> <td>5s</td> <td>61.8%</td> <td>66.5%</td> <td>95.7%</td> <td>41.3%</td> <td>1</td>
194
+ </tr>
195
+ <tr>
196
+ <td>国内模型 A (API)</td> <td> &#10008 </td> <td>5s</td> <td>62.6%</td> <td>61.7%</td> <td>95.6%</td> <td>37.7%</td> <td>2</td>
197
+ </tr>
198
+ <tr>
199
+ <td>国内模型 B (Web)</td> <td> &#10008</td> <td>5s</td> <td>60.1%</td> <td>62.9%</td> <td>97.7%</td> <td>37.5%</td> <td>3</td>
200
+ </tr>
201
+ <tr>
202
+ <td>GEN-3 alpha (Web)</td> <td>&#10008</td> <td>6s</td> <td>47.7%</td> <td>54.7%</td> <td>97.5%</td> <td>27.4%</td> <td>4</td>
203
+ </tr>
204
+ <tr>
205
+ <td>Luma1.6 (API)</td><td>&#10008</td> <td>5s</td> <td>57.6%</td> <td>44.2%</td> <td>94.1%</td> <td>24.8%</td> <td>5</td>
206
+ </tr>
207
+ </tbody>
208
+ </table>
209
+ </p>
210
+
211
+
212
+ ## 📜 运行配置
213
+
214
+ 下表列出了运行 HunyuanVideo 模型使用文本生成视频的推荐配置(batch size = 1):
215
+
216
+ | 模型 | 分辨率<br/>(height/width/frame) | 峰值显存 |
217
+ |:--------------:|:--------------------------------:|:----------------:|
218
+ | HunyuanVideo | 720px1280px129f | 60G |
219
+ | HunyuanVideo | 544px960px129f | 45G |
220
+
221
+ * 本项目适用于使用 NVIDIA GPU 和支持 CUDA 的设备
222
+ * 模型在单张 80G GPU 上测试
223
+ * 运行 720px1280px129f 的最小显存要求是 60GB,544px960px129f 的最小显存要求是 45GB。
224
+ * 测试操作系统:Linux
225
+
226
+
227
+
228
+ ## 🛠️ 安装和依赖
229
+
230
+ 首先克隆 git 仓库:
231
+ ```shell
232
+ git clone https://github.com/tencent/HunyuanVideo
233
+ cd HunyuanVideo
234
+ ```
235
+
236
+ ### Linux 安装指引
237
+
238
+ 我们推荐使用 CUDA 12.4 或 11.8 的版本。
239
+
240
+ Conda 的安装指南可以参考[这里](https://docs.anaconda.com/free/miniconda/index.html)。
241
+
242
+ ```shell
243
+ # 1. Create conda environment
244
+ conda create -n HunyuanVideo python==3.10.9
245
+
246
+ # 2. Activate the environment
247
+ conda activate HunyuanVideo
248
+
249
+ # 3. Install PyTorch and other dependencies using conda
250
+ # For CUDA 11.8
251
+ conda install pytorch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 pytorch-cuda=11.8 -c pytorch -c nvidia
252
+ # For CUDA 12.4
253
+ conda install pytorch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 pytorch-cuda=12.4 -c pytorch -c nvidia
254
+
255
+ # 4. Install pip dependencies
256
+ python -m pip install -r requirements.txt
257
+
258
+ # 5. Install flash attention v2 for acceleration (requires CUDA 11.8 or above)
259
+ python -m pip install ninja
260
+ python -m pip install git+https://github.com/Dao-AILab/[email protected]
261
+
262
+ # 6. Install xDiT for parallel inference (It is recommended to use torch 2.4.0 and flash-attn 2.6.3)
263
+ python -m pip install xfuser==0.4.0
264
+ ```
265
+
266
+ 如果在特定 GPU 型号上遭遇 float point exception(core dump) 问题,可尝试以下方案修复:
267
+
268
+ ```shell
269
+ #选项1:确保已正确安装 CUDA 12.4, CUBLAS>=12.4.5.8, 和 CUDNN>=9.00 (或直接使用我们提供的CUDA12镜像)
270
+ pip install nvidia-cublas-cu12==12.4.5.8
271
+ export LD_LIBRARY_PATH=/opt/conda/lib/python3.8/site-packages/nvidia/cublas/lib/
272
+
273
+ #选项2:强制显式使用 CUDA11.8 编译的 Pytorch 版本以及其他所有软件包
274
+ pip uninstall -r requirements.txt # 确保卸载所有依赖包
275
+ pip uninstall -y xfuser
276
+ pip install torch==2.4.0 --index-url https://download.pytorch.org/whl/cu118
277
+ pip install -r requirements.txt
278
+ pip install ninja
279
+ pip install git+https://github.com/Dao-AILab/[email protected]
280
+ pip install xfuser==0.4.0
281
+ ```
282
+
283
+ 另外,我们提供了一个预构建的 Docker 镜像,可以使用如下命令进行拉取和运行。
284
+ ```shell
285
+ # 用于 CUDA 12.4 (已更新避免 float point exception)
286
+ docker pull hunyuanvideo/hunyuanvideo:cuda_12
287
+ docker run -itd --gpus all --init --net=host --uts=host --ipc=host --name hunyuanvideo --security-opt=seccomp=unconfined --ulimit=stack=67108864 --ulimit=memlock=-1 --privileged hunyuanvideo/hunyuanvideo:cuda_12
288
+
289
+ # 用于 CUDA 11.8
290
+ docker pull hunyuanvideo/hunyuanvideo:cuda_11
291
+ docker run -itd --gpus all --init --net=host --uts=host --ipc=host --name hunyuanvideo --security-opt=seccomp=unconfined --ulimit=stack=67108864 --ulimit=memlock=-1 --privileged hunyuanvideo/hunyuanvideo:cuda_11
292
+ ```
293
+
294
+ ## 🧱 下载预训练模型
295
+
296
+ 下载预训练模型参考[这里](ckpts/README.md)。
297
+
298
+
299
+
300
+ ## 🔑 单卡推理
301
+
302
+ 我们在下表中列出了支持的高度/宽度/帧数设置。
303
+
304
+ | 分辨率 | h/w=9:16 | h/w=16:9 | h/w=4:3 | h/w=3:4 | h/w=1:1 |
305
+ |:---------------------:|:----------------------------:|:---------------:|:---------------:|:---------------:|:---------------:|
306
+ | 540p | 544px960px129f | 960px544px129f | 624px832px129f | 832px624px129f | 720px720px129f |
307
+ | 720p (推荐) | 720px1280px129f | 1280px720px129f | 1104px832px129f | 832px1104px129f | 960px960px129f |
308
+
309
+ ### 使用命令行
310
+
311
+ ```bash
312
+ cd HunyuanVideo
313
+
314
+ python3 sample_video.py \
315
+ --video-size 720 1280 \
316
+ --video-length 129 \
317
+ --infer-steps 50 \
318
+ --prompt "A cat walks on the grass, realistic style." \
319
+ --flow-reverse \
320
+ --use-cpu-offload \
321
+ --save-path ./results
322
+ ```
323
+
324
+ ### 运行gradio服务
325
+ ```bash
326
+ python3 gradio_server.py --flow-reverse
327
+
328
+ # set SERVER_NAME and SERVER_PORT manually
329
+ # SERVER_NAME=0.0.0.0 SERVER_PORT=8081 python3 gradio_server.py --flow-reverse
330
+ ```
331
+
332
+ ### 更多配置
333
+
334
+ 下面列出了更多关键配置项:
335
+
336
+ | 参数 | 默认值 | 描述 |
337
+ |:----------------------:|:---------:|:-----------------------------------------:|
338
+ | `--prompt` | None | 用于生成视频的 prompt |
339
+ | `--video-size` | 720 1280 | 生成视频的高度和宽度 |
340
+ | `--video-length` | 129 | 生成视频的帧数 |
341
+ | `--infer-steps` | 50 | 生成时采样的步数 |
342
+ | `--embedded-cfg-scale` | 6.0 | 文本的控制强度 |
343
+ | `--flow-shift` | 7.0 | 推理时 timestep 的 shift 系数,值越大,高噪区域采样步数越多 |
344
+ | `--flow-reverse` | False | If reverse, learning/sampling from t=1 -> t=0 |
345
+ | `--neg-prompt` | None | 负向词 |
346
+ | `--seed` | 0 | 随机种子 |
347
+ | `--use-cpu-offload` | False | 启用 CPU offload,可以节省显存 |
348
+ | `--save-path` | ./results | 保存路径 |
349
+
350
+
351
+
352
+ ## 🚀 使用 xDiT 实现多卡并行推理
353
+
354
+ [xDiT](https://github.com/xdit-project/xDiT) 是一个针对多 GPU 集群的扩展推理引擎,用于扩展 Transformers(DiTs)。
355
+ 它成功为各种 DiT 模型(包括 mochi-1、CogVideoX、Flux.1、SD3 等)提供了低延迟的并行推理解决方案。该存储库采用了 [Unified Sequence Parallelism (USP)](https://arxiv.org/abs/2405.07719) API 用于混元视频模型的并行推理。
356
+
357
+ ### 使用命令行
358
+
359
+ 例如,可用如下命令使用8张GPU卡完成推理
360
+
361
+ ```bash
362
+ cd HunyuanVideo
363
+
364
+ torchrun --nproc_per_node=8 sample_video_parallel.py \
365
+ --video-size 1280 720 \
366
+ --video-length 129 \
367
+ --infer-steps 50 \
368
+ --prompt "A cat walks on the grass, realistic style." \
369
+ --flow-reverse \
370
+ --seed 42 \
371
+ --ulysses_degree 8 \
372
+ --ring_degree 1 \
373
+ --save-path ./results
374
+ ```
375
+
376
+ 可以配置`--ulysses-degree`和`--ring-degree`来控制并行配置,可选参数如下。
377
+
378
+ <details>
379
+ <summary>支持的并行配置 (点击查看详情)</summary>
380
+
381
+ | --video-size | --video-length | --ulysses-degree x --ring-degree | --nproc_per_node |
382
+ |----------------------|----------------|----------------------------------|------------------|
383
+ | 1280 720 或 720 1280 | 129 | 8x1,4x2,2x4,1x8 | 8 |
384
+ | 1280 720 或 720 1280 | 129 | 1x5 | 5 |
385
+ | 1280 720 或 720 1280 | 129 | 4x1,2x2,1x4 | 4 |
386
+ | 1280 720 或 720 1280 | 129 | 3x1,1x3 | 3 |
387
+ | 1280 720 或 720 1280 | 129 | 2x1,1x2 | 2 |
388
+ | 1104 832 或 832 1104 | 129 | 4x1,2x2,1x4 | 4 |
389
+ | 1104 832 或 832 1104 | 129 | 3x1,1x3 | 3 |
390
+ | 1104 832 或 832 1104 | 129 | 2x1,1x2 | 2 |
391
+ | 960 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |
392
+ | 960 960 | 129 | 4x1,2x2,1x4 | 4 |
393
+ | 960 960 | 129 | 3x1,1x3 | 3 |
394
+ | 960 960 | 129 | 1x2,2x1 | 2 |
395
+ | 960 544 或 544 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |
396
+ | 960 544 或 544 960 | 129 | 4x1,2x2,1x4 | 4 |
397
+ | 960 544 或 544 960 | 129 | 3x1,1x3 | 3 |
398
+ | 960 544 或 544 960 | 129 | 1x2,2x1 | 2 |
399
+ | 832 624 或 624 832 | 129 | 4x1,2x2,1x4 | 4 |
400
+ | 624 832 或 624 832 | 129 | 3x1,1x3 | 3 |
401
+ | 832 624 或 624 832 | 129 | 2x1,1x2 | 2 |
402
+ | 720 720 | 129 | 1x5 | 5 |
403
+ | 720 720 | 129 | 3x1,1x3 | 3 |
404
+
405
+ </details>
406
+
407
+ <p align="center">
408
+ <table align="center">
409
+ <thead>
410
+ <tr>
411
+ <th colspan="4">在 8xGPU上生成1280x720 (129 帧 50 步)的时耗 (秒) </th>
412
+ </tr>
413
+ <tr>
414
+ <th>1</th>
415
+ <th>2</th>
416
+ <th>4</th>
417
+ <th>8</th>
418
+ </tr>
419
+ </thead>
420
+ <tbody>
421
+ <tr>
422
+ <th>1904.08</th>
423
+ <th>934.09 (2.04x)</th>
424
+ <th>514.08 (3.70x)</th>
425
+ <th>337.58 (5.64x)</th>
426
+ </tr>
427
+
428
+ </tbody>
429
+ </table>
430
+ </p>
431
+
432
+
433
+
434
+ ## 🚀 FP8 Inference
435
+
436
+ 使用FP8量化后的HunyuanVideo模型能够帮您节省大概10GB显存。 使用前需要从 Huggingface 下载[FP8权重](https://huggingface.co/tencent/HunyuanVideo/blob/main/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt)和每层量化权重的[scale参数](https://huggingface.co/tencent/HunyuanVideo/blob/main/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8_map.pt).
437
+
438
+ ### Using Command Line
439
+
440
+ 这里,您必须显示地指定FP8的权重路径。例如,可用如下命令使用FP8模型推理
441
+
442
+ ```bash
443
+ cd HunyuanVideo
444
+
445
+ DIT_CKPT_PATH={PATH_TO_FP8_WEIGHTS}/{WEIGHT_NAME}_fp8.pt
446
+
447
+ python3 sample_video.py \
448
+ --dit-weight ${DIT_CKPT_PATH} \
449
+ --video-size 1280 720 \
450
+ --video-length 129 \
451
+ --infer-steps 50 \
452
+ --prompt "A cat walks on the grass, realistic style." \
453
+ --seed 42 \
454
+ --embedded-cfg-scale 6.0 \
455
+ --flow-shift 7.0 \
456
+ --flow-reverse \
457
+ --use-cpu-offload \
458
+ --use-fp8 \
459
+ --save-path ./results
460
+ ```
461
+
462
+
463
+
464
+ ## 🔗 BibTeX
465
+
466
+ 如果您认为 [HunyuanVideo](https://arxiv.org/abs/2412.03603) 给您的研究和应用带来了一些帮助,可以通过下面的方式来引用:
467
+
468
+ ```BibTeX
469
+ @misc{kong2024hunyuanvideo,
470
+ title={HunyuanVideo: A Systematic Framework For Large Video Generative Models},
471
+ author={Weijie Kong, Qi Tian, Zijian Zhang, Rox Min, Zuozhuo Dai, Jin Zhou, Jiangfeng Xiong, Xin Li, Bo Wu, Jianwei Zhang, Kathrina Wu, Qin Lin, Aladdin Wang, Andong Wang, Changlin Li, Duojun Huang, Fang Yang, Hao Tan, Hongmei Wang, Jacob Song, Jiawang Bai, Jianbing Wu, Jinbao Xue, Joey Wang, Junkun Yuan, Kai Wang, Mengyang Liu, Pengyu Li, Shuai Li, Weiyan Wang, Wenqing Yu, Xinchi Deng, Yang Li, Yanxin Long, Yi Chen, Yutao Cui, Yuanbo Peng, Zhentao Yu, Zhiyu He, Zhiyong Xu, Zixiang Zhou, Zunnan Xu, Yangyu Tao, Qinglin Lu, Songtao Liu, Dax Zhou, Hongfa Wang, Yong Yang, Di Wang, Yuhong Liu, and Jie Jiang, along with Caesar Zhong},
472
+ year={2024},
473
+ archivePrefix={arXiv preprint arXiv:2412.03603},
474
+ primaryClass={cs.CV}
475
+ }
476
+ ```
477
+
478
+
479
+
480
+ ## 致谢
481
+
482
+ HunyuanVideo 的开源离不开诸多开源工作,这里我们特别感谢 [SD3](https://huggingface.co/stabilityai/stable-diffusion-3-medium), [FLUX](https://github.com/black-forest-labs/flux), [Llama](https://github.com/meta-llama/llama), [LLaVA](https://github.com/haotian-liu/LLaVA), [Xtuner](https://github.com/InternLM/xtuner), [diffusers](https://github.com/huggingface/diffusers) and [HuggingFace](https://huggingface.co) 的开源工作和探索。另外,我们也感谢腾讯混元多模态团队对 HunyuanVideo 适配多种文本编码器的支持。
483
+
484
+
485
+
486
+ ## Star 趋势
487
+
488
+ <a href="https://star-history.com/#Tencent/HunyuanVideo&Date">
489
+ <picture>
490
+ <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=Tencent/HunyuanVideo&type=Date&theme=dark" />
491
+ <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=Tencent/HunyuanVideo&type=Date" />
492
+ <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=Tencent/HunyuanVideo&type=Date" />
493
+ </picture>
494
+ </a>
gradio_server.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+ from pathlib import Path
4
+ from loguru import logger
5
+ from datetime import datetime
6
+ import gradio as gr
7
+ import random
8
+
9
+ from hyvideo.utils.file_utils import save_videos_grid
10
+ from hyvideo.config import parse_args
11
+ from hyvideo.inference import HunyuanVideoSampler
12
+ from hyvideo.constants import NEGATIVE_PROMPT
13
+
14
+ def initialize_model(model_path):
15
+ args = parse_args()
16
+ models_root_path = Path(model_path)
17
+ if not models_root_path.exists():
18
+ raise ValueError(f"`models_root` not exists: {models_root_path}")
19
+
20
+ hunyuan_video_sampler = HunyuanVideoSampler.from_pretrained(models_root_path, args=args)
21
+ return hunyuan_video_sampler
22
+
23
+ def generate_video(
24
+ model,
25
+ prompt,
26
+ resolution,
27
+ video_length,
28
+ seed,
29
+ num_inference_steps,
30
+ guidance_scale,
31
+ flow_shift,
32
+ embedded_guidance_scale
33
+ ):
34
+ seed = None if seed == -1 else seed
35
+ width, height = resolution.split("x")
36
+ width, height = int(width), int(height)
37
+ negative_prompt = "" # not applicable in the inference
38
+
39
+ outputs = model.predict(
40
+ prompt=prompt,
41
+ height=height,
42
+ width=width,
43
+ video_length=video_length,
44
+ seed=seed,
45
+ negative_prompt=negative_prompt,
46
+ infer_steps=num_inference_steps,
47
+ guidance_scale=guidance_scale,
48
+ num_videos_per_prompt=1,
49
+ flow_shift=flow_shift,
50
+ batch_size=1,
51
+ embedded_guidance_scale=embedded_guidance_scale
52
+ )
53
+
54
+ samples = outputs['samples']
55
+ sample = samples[0].unsqueeze(0)
56
+
57
+ save_path = os.path.join(os.getcwd(), "gradio_outputs")
58
+ os.makedirs(save_path, exist_ok=True)
59
+
60
+ time_flag = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d-%H:%M:%S")
61
+ video_path = f"{save_path}/{time_flag}_seed{outputs['seeds'][0]}_{outputs['prompts'][0][:100].replace('/','')}.mp4"
62
+ save_videos_grid(sample, video_path, fps=24)
63
+ logger.info(f'Sample saved to: {video_path}')
64
+
65
+ return video_path
66
+
67
+ def create_demo(model_path, save_path):
68
+ model = initialize_model(model_path)
69
+
70
+ with gr.Blocks() as demo:
71
+ gr.Markdown("# Hunyuan Video Generation")
72
+
73
+ with gr.Row():
74
+ with gr.Column():
75
+ prompt = gr.Textbox(label="Prompt", value="A cat walks on the grass, realistic style.")
76
+ with gr.Row():
77
+ resolution = gr.Dropdown(
78
+ choices=[
79
+ # 720p
80
+ ("1280x720 (16:9, 720p)", "1280x720"),
81
+ ("720x1280 (9:16, 720p)", "720x1280"),
82
+ ("1104x832 (4:3, 720p)", "1104x832"),
83
+ ("832x1104 (3:4, 720p)", "832x1104"),
84
+ ("960x960 (1:1, 720p)", "960x960"),
85
+ # 540p
86
+ ("960x544 (16:9, 540p)", "960x544"),
87
+ ("544x960 (9:16, 540p)", "544x960"),
88
+ ("832x624 (4:3, 540p)", "832x624"),
89
+ ("624x832 (3:4, 540p)", "624x832"),
90
+ ("720x720 (1:1, 540p)", "720x720"),
91
+ ],
92
+ value="1280x720",
93
+ label="Resolution"
94
+ )
95
+ video_length = gr.Dropdown(
96
+ label="Video Length",
97
+ choices=[
98
+ ("2s(65f)", 65),
99
+ ("5s(129f)", 129),
100
+ ],
101
+ value=129,
102
+ )
103
+ num_inference_steps = gr.Slider(1, 100, value=50, step=1, label="Number of Inference Steps")
104
+ show_advanced = gr.Checkbox(label="Show Advanced Options", value=False)
105
+ with gr.Row(visible=False) as advanced_row:
106
+ with gr.Column():
107
+ seed = gr.Number(value=-1, label="Seed (-1 for random)")
108
+ guidance_scale = gr.Slider(1.0, 20.0, value=1.0, step=0.5, label="Guidance Scale")
109
+ flow_shift = gr.Slider(0.0, 10.0, value=7.0, step=0.1, label="Flow Shift")
110
+ embedded_guidance_scale = gr.Slider(1.0, 20.0, value=6.0, step=0.5, label="Embedded Guidance Scale")
111
+ show_advanced.change(fn=lambda x: gr.Row(visible=x), inputs=[show_advanced], outputs=[advanced_row])
112
+ generate_btn = gr.Button("Generate")
113
+
114
+ with gr.Column():
115
+ output = gr.Video(label="Generated Video")
116
+
117
+ generate_btn.click(
118
+ fn=lambda *inputs: generate_video(model, *inputs),
119
+ inputs=[
120
+ prompt,
121
+ resolution,
122
+ video_length,
123
+ seed,
124
+ num_inference_steps,
125
+ guidance_scale,
126
+ flow_shift,
127
+ embedded_guidance_scale
128
+ ],
129
+ outputs=output
130
+ )
131
+
132
+ return demo
133
+
134
+ if __name__ == "__main__":
135
+ os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
136
+ server_name = os.getenv("SERVER_NAME", "0.0.0.0")
137
+ server_port = int(os.getenv("SERVER_PORT", "8081"))
138
+ args = parse_args()
139
+ print(args)
140
+ demo = create_demo(args.model_base, args.save_path)
141
+ demo.launch(server_name=server_name, server_port=server_port)
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ opencv-python==4.9.0.80
2
+ diffusers==0.31.0
3
+ transformers==4.46.3
4
+ tokenizers==0.20.3
5
+ accelerate==1.1.1
6
+ pandas==2.0.3
7
+ numpy==1.24.4
8
+ einops==0.7.0
9
+ tqdm==4.66.2
10
+ loguru==0.7.2
11
+ imageio==2.34.0
12
+ imageio-ffmpeg==0.5.1
13
+ safetensors==0.4.3
14
+ gradio==5.0.0
sample_video.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+ from pathlib import Path
4
+ from loguru import logger
5
+ from datetime import datetime
6
+
7
+ from hyvideo.utils.file_utils import save_videos_grid
8
+ from hyvideo.config import parse_args
9
+ from hyvideo.inference import HunyuanVideoSampler
10
+
11
+
12
+ def main():
13
+ args = parse_args()
14
+ print(args)
15
+ models_root_path = Path(args.model_base)
16
+ if not models_root_path.exists():
17
+ raise ValueError(f"`models_root` not exists: {models_root_path}")
18
+
19
+ # Create save folder to save the samples
20
+ save_path = args.save_path if args.save_path_suffix=="" else f'{args.save_path}_{args.save_path_suffix}'
21
+ if not os.path.exists(args.save_path):
22
+ os.makedirs(save_path, exist_ok=True)
23
+
24
+ # Load models
25
+ hunyuan_video_sampler = HunyuanVideoSampler.from_pretrained(models_root_path, args=args)
26
+
27
+ # Get the updated args
28
+ args = hunyuan_video_sampler.args
29
+
30
+ # Start sampling
31
+ # TODO: batch inference check
32
+ outputs = hunyuan_video_sampler.predict(
33
+ prompt=args.prompt,
34
+ height=args.video_size[0],
35
+ width=args.video_size[1],
36
+ video_length=args.video_length,
37
+ seed=args.seed,
38
+ negative_prompt=args.neg_prompt,
39
+ infer_steps=args.infer_steps,
40
+ guidance_scale=args.cfg_scale,
41
+ num_videos_per_prompt=args.num_videos,
42
+ flow_shift=args.flow_shift,
43
+ batch_size=args.batch_size,
44
+ embedded_guidance_scale=args.embedded_cfg_scale
45
+ )
46
+ samples = outputs['samples']
47
+
48
+ # Save samples
49
+ if 'LOCAL_RANK' not in os.environ or int(os.environ['LOCAL_RANK']) == 0:
50
+ for i, sample in enumerate(samples):
51
+ sample = samples[i].unsqueeze(0)
52
+ time_flag = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d-%H:%M:%S")
53
+ save_path = f"{save_path}/{time_flag}_seed{outputs['seeds'][i]}_{outputs['prompts'][i][:100].replace('/','')}.mp4"
54
+ save_videos_grid(sample, save_path, fps=24)
55
+ logger.info(f'Sample save to: {save_path}')
56
+
57
+ if __name__ == "__main__":
58
+ main()