Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"CogVideoX","local":"cogvideox","sections":[{"title":"Chuẩn bị dữ liệu","local":"data-preparation","sections":[{"title":"Định dạng nhỏ","local":"small-format","sections":[],"depth":3},{"title":"Định dạng luồng","local":"stream-format","sections":[],"depth":3}],"depth":2},{"title":"Huấn luyện","local":"training","sections":[],"depth":2},{"title":"Suy luận","local":"inference","sections":[],"depth":2},{"title":"Giảm mức sử dụng bộ nhớ","local":"reduce-memory-usage","sections":[],"depth":2}],"depth":1}"/> | |
| <link href="/docs/diffusers/main/en/_app/immutable/entry/start.D3LnKZ4R.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/BF9UNEM9.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DPnyVmXs.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/entry/app.C0rBoMxR.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DSGUT_OW.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/C045MWWx.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DnVIJfC5.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/nodes/0.DTZsP_3B.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/IaDvMxLQ.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/nodes/314.Clt70fkN.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/bKdwVYpU.js" rel="modulepreload"> | |
| <!--26s02k--><meta name="hf:doc:metadata" content="{"title":"CogVideoX","local":"cogvideox","sections":[{"title":"Data Preparation","local":"data-preparation","sections":[{"title":"Small format","local":"small-format","sections":[],"depth":3},{"title":"Stream format","local":"stream-format","sections":[],"depth":3}],"depth":2},{"title":"Training","local":"training","sections":[],"depth":2},{"title":"Inference","local":"inference","sections":[],"depth":2},{"title":"Reduce memory usage","local":"reduce-memory-usage","sections":[],"depth":2}],"depth":1}"/><!----> | |
| <link href="/docs/diffusers/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"><div dir="ltr" class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----></span> <span dir="auto">Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="cogvideox" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#cogvideox"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->CogVideoX<!----></span></h1><!--]--><!----> <p>CogVideoX là một mô hình tạo video từ văn bản, tập trung vào việc tạo ra các video nhất quán hơn, bám sát theo prompt. Nó đạt được điều này bằng cách sử dụng một số phương pháp.</p> <ul><li><p>một autoencoder biến phân 3D nén video theo không gian và thời gian, cải thiện tỷ lệ nén và độ chính xác của video.</p></li> <li><p>một khối transformer chuyên gia để giúp căn chỉnh văn bản và video, cùng một module chú ý toàn phần 3D để nắm bắt và tạo ra các video chính xác về mặt không gian và thời gian.</p></li></ul> <p>Kết quả kiểm tra thực tế về chiều hướng dẫn video cho thấy CogVideoX đạt hiệu quả tốt ở các khía cạnh chủ đề nhất quán, thông tin động, nền nhất quán, thông tin đối tượng, chuyển động mượt mà, màu sắc, cảnh, phong cách ngoại hình và phong cách thời gian, nhưng không thể đạt kết quả tốt với hành động con người, quan hệ không gian và nhiều đối tượng.</p> <p>Việc tinh chỉnh với Diffusers có thể giúp bù đắp cho những kết quả kém này.</p> <!--[1--><h2 class="relative group"><a id="data-preparation" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#data-preparation"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Chuẩn bị dữ liệu<!----></span></h2><!--]--><!----> <p>Các script huấn luyện chấp nhận dữ liệu ở hai định dạng.</p> <p>Định dạng đầu tiên phù hợp cho huấn luyện quy mô nhỏ, còn định dạng thứ hai sử dụng định dạng CSV, phù hợp hơn cho việc truyền trực tiếp dữ liệu trong huấn luyện quy mô lớn. Trong tương lai, Diffusers sẽ hỗ trợ thẻ <code><Video></code>.</p> <!--[2--><h3 class="relative group"><a id="small-format" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#small-format"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Định dạng nhỏ<!----></span></h3><!--]--><!----> <p>Hai tệp, trong đó một tệp chứa các prompt phân tách theo dòng và tệp còn lại chứa các đường dẫn đến dữ liệu video phân tách theo dòng (đường dẫn đến tệp video phải là đường dẫn tương đối so với đường dẫn bạn truyền khi chỉ định <code>--instance_data_root</code>). Hãy xem một ví dụ để hiểu rõ hơn!</p> <p>Giả sử bạn đã chỉ định <code>--instance_data_root</code> là <code>/dataset</code>, và thư mục này chứa các tệp: <code>prompts.txt</code> và <code>videos.txt</code>.</p> <p>Tệp <code>prompts.txt</code> nên chứa các prompt được phân tách bằng dòng:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class=" "><!---->A <span class="hljs-keyword">black </span><span class="hljs-keyword">and </span>white animated sequence featuring a rabbit, named Rabbity Ribfried, <span class="hljs-keyword">and </span>an anthropomorphic goat in a musical, playful environment, <span class="hljs-keyword">showcasing </span>their evolving interaction. | |
| A <span class="hljs-keyword">black </span><span class="hljs-keyword">and </span>white animated sequence on a <span class="hljs-keyword">ship's </span>deck features a <span class="hljs-keyword">bulldog </span>character, named <span class="hljs-keyword">Bully </span><span class="hljs-keyword">Bulldoger, </span><span class="hljs-keyword">showcasing </span>exaggerated facial expressions <span class="hljs-keyword">and </span><span class="hljs-keyword">body </span>language. The character progresses from confident to focused, then to strained <span class="hljs-keyword">and </span><span class="hljs-keyword">distressed, </span><span class="hljs-keyword">displaying </span>a range of emotions as it navigates challenges. The <span class="hljs-keyword">ship's </span>interior remains static in the <span class="hljs-keyword">background, </span>with minimalistic details such as a <span class="hljs-keyword">bell </span><span class="hljs-keyword">and </span>open door. The character<span class="hljs-string">'s dynamic movements and changing expressions drive the narrative, with no camera movement to distract from its evolving reactions and physical gestures. | |
| ...</span><!----></pre></div><!----> <p>Tệp <code>videos.txt</code> nên chứa các đường dẫn đến tệp video, mỗi đường dẫn trên một dòng. Lưu ý rằng đường dẫn phải là <em>tương đối</em> so với thư mục <code>--instance_data_root</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class=" "><!---->videos<span class="hljs-symbol">/00000.mp4</span> | |
| videos<span class="hljs-symbol">/00001.mp4</span> | |
| ...<!----></pre></div><!----> <p>Nhìn chung, đây là cách bộ dữ liệu của bạn sẽ trông như thế nào nếu bạn chạy lệnh <code>tree</code> trên thư mục gốc của bộ dữ liệu:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class=" "><!---->/dataset | |
| ├── prompts<span class="hljs-selector-class">.txt</span> | |
| ├── videos<span class="hljs-selector-class">.txt</span> | |
| ├── videos | |
| ├── videos/<span class="hljs-number">00000</span><span class="hljs-selector-class">.mp4</span> | |
| ├── videos/<span class="hljs-number">00001</span><span class="hljs-selector-class">.mp4</span> | |
| ├── ...<!----></pre></div><!----> <p>Khi sử dụng định dạng này, <code>--caption_column</code> phải là <code>prompts.txt</code> và <code>--video_column</code> phải là <code>videos.txt</code>.</p> <!--[2--><h3 class="relative group"><a id="stream-format" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#stream-format"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Định dạng luồng<!----></span></h3><!--]--><!----> <p>Bạn có thể sử dụng một tệp CSV duy nhất. Để phục vụ cho ví dụ này, giả sử bạn có tệp <code>metadata.csv</code>. Định dạng mong đợi là:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class=" "><!----><CAPTION_COLUMN>,<PATH_TO_VIDEO_COLUMN> | |
| <span class="hljs-string">"""A black and white animated sequence featuring a rabbit, named Rabbity Ribfried, and an anthropomorphic goat in a musical, playful environment, showcasing their evolving interaction."""</span>,<span class="hljs-string">"""00000.mp4"""</span> | |
| <span class="hljs-string">"""A black and white animated sequence on a ship's deck features a bulldog character, named Bully Bulldoger, showcasing exaggerated facial expressions and body language. The character progresses from confident to focused, then to strained and distressed, displaying a range of emotions as it navigates challenges. The ship's interior remains static in the background, with minimalistic details such as a bell and open door. The character's dynamic movements and changing expressions drive the narrative, with no camera movement to distract from its evolving reactions and physical gestures."""</span>,<span class="hljs-string">"""00001.mp4"""</span> | |
| ...<!----></pre></div><!----> <p>Trong trường hợp này, <code>--instance_data_root</code> phải là vị trí lưu trữ các video và <code>--dataset_name</code> phải là đường dẫn đến thư mục cục bộ hoặc một dataset tương thích với <a href="https://huggingface.co/docs/datasets/main/en/package_reference/loading_methods#datasets.load_dataset" rel="nofollow">load_dataset</a> được lưu trữ trên Hub. Giả sử bạn có các video gameplay Minecraft tại <code>https://huggingface.co/datasets/my-awesome-username/minecraft-videos</code>, bạn sẽ phải chỉ định <code>my-awesome-username/minecraft-videos</code>.</p> <p>Khi sử dụng định dạng này, <code>--caption_column</code> phải là <code><CAPTION_COLUMN></code> và <code>--video_column</code> phải là <code><PATH_TO_VIDEO_COLUMN></code>.</p> <p>Bạn không bị giới hạn cứng nhắc ở định dạng CSV. Bất kỳ định dạng nào cũng được, miễn là phương thức <code>load_dataset</code> hỗ trợ định dạng tệp để nạp một <code><PATH_TO_VIDEO_COLUMN></code> và <code><CAPTION_COLUMN></code> cơ bản. Lý do phải sắp xếp dữ liệu theo cách này khi nạp dữ liệu video là vì <code>load_dataset</code> không hỗ trợ đầy đủ mọi loại định dạng video.</p> <blockquote class="note"><p>CogVideoX hoạt động tốt nhất với các prompt dài và mô tả chi tiết, được tăng cường bằng LLM, cho việc tạo video. Chúng tôi khuyến nghị tiền xử lý video của bạn bằng cách đầu tiên tạo một bản tóm tắt sử dụng VLM, sau đó tăng cường các prompt bằng LLM. Để tạo các chú thích ở trên, chúng tôi sử dụng <a href="https://huggingface.co/openbmb/MiniCPM-V-2_6" rel="nofollow">MiniCPM-V-26</a> và <a href="https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct" rel="nofollow">Llama-3.1-8B-Instruct</a>. Một ví dụ rất tối giản và không rườm rà cho quy trình này có sẵn <a href="https://gist.github.com/a-r-r-o-w/4dee20250e82f4e44690a02351324a4a" rel="nofollow">tại đây</a>. Khuyến nghị chính thức để tăng cường prompt là <a href="https://huggingface.co/THUDM?search_models=chatglm" rel="nofollow">ChatGLM</a> và độ dài 50-100 từ được coi là tốt.</p></blockquote> <blockquote><p>![NOTE] | |
| Bộ dữ liệu của bạn được kỳ vọng đã được tiền xử lý. Nếu chưa, một số tiền xử lý cơ bản có thể được thực hiện bằng cách điều chỉnh các tham số sau: <code>--height</code>, <code>--width</code>, <code>--fps</code>, <code>--max_num_frames</code>, <code>--skip_frames_start</code> và <code>--skip_frames_end</code>. | |
| Hiện tại, tất cả các video trong bộ dữ liệu của bạn phải chứa cùng một số lượng khung hình khi sử dụng kích thước batch huấn luyện > 1.</p></blockquote> <!--[1--><h2 class="relative group"><a id="training" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#training"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Huấn luyện<!----></span></h2><!--]--><!----> <p>Bạn cần thiết lập môi trường phát triển bằng cách cài đặt các yêu cầu cần thiết. Các gói sau là bắt buộc:</p> <ul><li>Torch 2.0 trở lên dựa trên các tính năng huấn luyện mà bạn đang sử dụng (có thể yêu cầu phiên bản mới nhất hoặc nightly cho huấn luyện quantized/deepspeed)</li> <li><code>pip install diffusers transformers accelerate peft huggingface_hub</code> cho mọi thứ liên quan đến mô hình hóa và huấn luyện</li> <li><code>pip install datasets decord</code> để nạp dữ liệu huấn luyện video</li> <li><code>pip install bitsandbytes</code> để sử dụng các bộ tối ưu hóa Adam hoặc AdamW 8-bit cho việc huấn luyện tối ưu bộ nhớ</li> <li><code>pip install wandb</code> tùy chọn để theo dõi nhật ký huấn luyện</li> <li><code>pip install deepspeed</code> tùy chọn để huấn luyện <a href="https://github.com/microsoft/DeepSpeed" rel="nofollow">DeepSpeed</a></li> <li><code>pip install prodigyopt</code> tùy chọn nếu bạn muốn sử dụng trình tối ưu Prodigy cho việc huấn luyện</li></ul> <p>Để đảm bảo bạn có thể chạy thành công các phiên bản mới nhất của các script mẫu, chúng tôi rất khuyến khích <strong>cài đặt từ mã nguồn</strong> và giữ cho bản cài đặt luôn được cập nhật, vì chúng tôi thường xuyên cập nhật các script mẫu và cài đặt một số yêu cầu riêng cho từng script. Để thực hiện điều này, hãy thực hiện các bước sau trong một môi trường ảo mới:</p> <p>Trước khi chạy script, hãy đảm bảo bạn cài đặt thư viện từ mã nguồn:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-bash "><!---->git <span class="hljs-built_in">clone</span> https://github.com/huggingface/diffusers | |
| <span class="hljs-built_in">cd</span> diffusers | |
| pip install -e .<!----></pre></div><!----> <p>Sau đó, điều hướng đến thư mục ví dụ chứa script huấn luyện và cài đặt các phụ thuộc cần thiết cho script bạn đang sử dụng:</p> <ul><li>PyTorch</li></ul> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-bash "><!----><span class="hljs-built_in">cd</span> examples/cogvideo | |
| pip install -r requirements.txt<!----></pre></div><!----> <p>Và khởi tạo một môi trường <a href="https://github.com/huggingface/accelerate/" rel="nofollow">🤗 Accelerate</a> với:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-bash "><!---->accelerate config<!----></pre></div><!----> <p>Hoặc để có một cấu hình accelerate mặc định mà không cần trả lời các câu hỏi về môi trường của bạn</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-bash "><!---->accelerate config default<!----></pre></div><!----> <p>Hoặc nếu môi trường của bạn không hỗ trợ shell tương tác (ví dụ: notebook)</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> accelerate.utils <span class="hljs-keyword">import</span> write_basic_config | |
| write_basic_config()<!----></pre></div><!----> <p>Khi chạy <code>accelerate config</code>, nếu bạn sử dụng torch.compile, có thể đạt được tốc độ tăng lên đáng kể. Thư viện PEFT được dùng làm backend cho việc huấn luyện LoRA, vì vậy hãy đảm bảo rằng <code>peft>=0.6.0</code> đã được cài đặt trong môi trường của bạn.</p> <p>Nếu bạn muốn đẩy mô hình của mình lên Hub sau khi huấn luyện hoàn tất với một model card gọn gàng, hãy đảm bảo bạn đã đăng nhập:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-bash "><!---->hf auth login | |
| <span class="hljs-comment"># Alternatively, you could upload your model manually using:</span> | |
| <span class="hljs-comment"># hf upload my-cool-account-name/my-cool-lora-name /path/to/awesome/lora</span><!----></pre></div><!----> <p>Hãy đảm bảo dữ liệu của bạn đã được chuẩn bị như mô tả trong <a href="#data-preparation">Chuẩn bị dữ liệu</a>. Khi sẵn sàng, bạn có thể bắt đầu huấn luyện!</p> <p>Giả sử bạn đang huấn luyện trên 50 video có cùng một khái niệm, chúng tôi nhận thấy 1500-2000 bước hoạt động tốt. Tuy nhiên, khuyến nghị chính thức là 100 video với tổng cộng 4000 bước. Giả sử bạn đang huấn luyện trên một GPU duy nhất với <code>--train_batch_size</code> là <code>1</code>:</p> <ul><li>1500 bước trên 50 video sẽ tương ứng với <code>30</code> epoch huấn luyện</li> <li>4000 bước trên 100 video sẽ tương ứng với <code>40</code> epoch huấn luyện</li></ul> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-bash "><!----><span class="hljs-meta">#!/bin/bash</span> | |
| GPU_IDS=<span class="hljs-string">"0"</span> | |
| accelerate launch --gpu_ids <span class="hljs-variable">$GPU_IDS</span> examples/cogvideo/train_cogvideox_lora.py \ | |
| --pretrained_model_name_or_path THUDM/CogVideoX-2b \ | |
| --cache_dir <CACHE_DIR> \ | |
| --instance_data_root <PATH_TO_WHERE_VIDEO_FILES_ARE_STORED> \ | |
| --dataset_name my-awesome-name/my-awesome-dataset \ | |
| --caption_column <CAPTION_COLUMN> \ | |
| --video_column <PATH_TO_VIDEO_COLUMN> \ | |
| --id_token <ID_TOKEN> \ | |
| --validation_prompt <span class="hljs-string">"<ID_TOKEN> Spiderman swinging over buildings:::A panda, dressed in a small, red jacket and a tiny hat, sits on a wooden stool in a serene bamboo forest. The panda's fluffy paws strum a miniature acoustic guitar, producing soft, melodic tunes. Nearby, a few other pandas gather, watching curiously and some clapping in rhythm. Sunlight filters through the tall bamboo, casting a gentle glow on the scene. The panda's face is expressive, showing concentration and joy as it plays. The background includes a small, flowing stream and vibrant green foliage, enhancing the peaceful and magical atmosphere of this unique musical performance"</span> \ | |
| --validation_prompt_separator ::: \ | |
| --num_validation_videos 1 \ | |
| --validation_epochs 10 \ | |
| --seed 42 \ | |
| --rank 64 \ | |
| --lora_alpha 64 \ | |
| --mixed_precision fp16 \ | |
| --output_dir /raid/aryan/cogvideox-lora \ | |
| --height 480 --width 720 --fps 8 --max_num_frames 49 --skip_frames_start 0 --skip_frames_end 0 \ | |
| --train_batch_size 1 \ | |
| --num_train_epochs 30 \ | |
| --checkpointing_steps 1000 \ | |
| --gradient_accumulation_steps 1 \ | |
| --learning_rate 1e-3 \ | |
| --lr_scheduler cosine_with_restarts \ | |
| --lr_warmup_steps 200 \ | |
| --lr_num_cycles 1 \ | |
| --enable_slicing \ | |
| --enable_tiling \ | |
| --optimizer Adam \ | |
| --adam_beta1 0.9 \ | |
| --adam_beta2 0.95 \ | |
| --max_grad_norm 1.0 \ | |
| --report_to wandb<!----></pre></div><!----> <p>Để theo dõi tốt hơn các thí nghiệm huấn luyện của chúng ta, chúng tôi sử dụng các cờ sau trong lệnh ở trên:</p> <ul><li><code>--report_to wandb</code> sẽ đảm bảo các phiên chạy huấn luyện được theo dõi trên Weights and Biases. Để sử dụng, hãy chắc chắn cài đặt <code>wandb</code> bằng <code>pip install wandb</code>.</li> <li><code>validation_prompt</code> và <code>validation_epochs</code> để cho phép script thực hiện một vài lần suy luận kiểm tra. Điều này cho phép chúng ta kiểm tra định tính xem quá trình huấn luyện có đang diễn ra như mong đợi hay không.</li></ul> <p>Việc đặt <code><ID_TOKEN></code> không bắt buộc. Từ một số thử nghiệm giới hạn, chúng tôi nhận thấy nó hoạt động tốt hơn (vì nó giống với quá trình huấn luyện <a href="./dreambooth">Dreambooth</a>) so với khi không có. Khi được cung cấp, <code><ID_TOKEN></code> sẽ được thêm vào đầu mỗi prompt. Vì vậy, nếu <code><ID_TOKEN></code> của bạn là <code>"DISNEY"</code> và prompt của bạn là <code>"Spiderman swinging over buildings"</code>, prompt hiệu quả được sử dụng trong huấn luyện sẽ là <code>"DISNEY Spiderman swinging over buildings"</code>. Khi không được cung cấp, bạn sẽ huấn luyện mà không có token bổ sung nào hoặc có thể bổ sung cho bộ dữ liệu của mình để áp dụng token vào vị trí mong muốn trước khi bắt đầu huấn luyện.</p> <blockquote class="note"><p>Bạn có thể truyền <code>--use_8bit_adam</code> để giảm yêu cầu về bộ nhớ khi huấn luyện.</p></blockquote> <blockquote class="important"><p>Các cài đặt sau đã được kiểm tra tại thời điểm thêm hỗ trợ huấn luyện LoRA cho CogVideoX:</p> <ul><li>Quá trình kiểm thử của chúng tôi chủ yếu được thực hiện trên CogVideoX-2b. Chúng tôi sẽ sớm làm việc với CogVideoX-5b và CogVideoX-5b-I2V</li> <li>Một tập dữ liệu gồm 70 video huấn luyện có độ phân giải <code>200 x 480 x 720</code> (F x H x W). Từ đó, bằng cách sử dụng bỏ qua khung hình trong tiền xử lý dữ liệu, chúng tôi đã tạo ra hai tập dữ liệu nhỏ hơn gồm 49 khung hình và 16 khung hình để thử nghiệm nhanh hơn và vì giới hạn tối đa được đội ngũ CogVideoX khuyến nghị là 49 khung hình. Trong số 70 video, chúng tôi đã tạo ra ba nhóm gồm 10, 25 và 50 video. Tất cả các video đều có tính chất tương tự nhau về khái niệm đang được huấn luyện.</li> <li>25+ video hoạt động tốt nhất cho việc huấn luyện các khái niệm và phong cách mới.</li> <li>Chúng tôi nhận thấy rằng việc huấn luyện với một token định danh có thể được chỉ định bằng <code>--id_token</code> là tốt hơn. Điều này tương tự như huấn luyện kiểu Dreambooth, nhưng việc finetuning thông thường mà không có token như vậy cũng hoạt động được.</li> <li>Khái niệm đã được huấn luyện dường như hoạt động khá tốt khi kết hợp với các prompt hoàn toàn không liên quan. Chúng tôi kỳ vọng sẽ đạt được kết quả tốt hơn nữa nếu CogVideoX-5B được tinh chỉnh (finetune).</li> <li>Kho lưu trữ gốc sử dụng <code>lora_alpha</code> là <code>1</code>. Chúng tôi nhận thấy giá trị này không phù hợp trong nhiều lần chạy, có thể do sự khác biệt về backend mô hình hóa và cài đặt huấn luyện. Khuyến nghị của chúng tôi là đặt <code>lora_alpha</code> bằng <code>rank</code> hoặc <code>rank // 2</code>.</li> <li>Nếu bạn đang huấn luyện trên dữ liệu có chú thích tạo ra kết quả kém với mô hình gốc, một <code>rank</code> từ 64 trở lên là tốt và cũng là khuyến nghị của nhóm đứng sau CogVideoX. Nếu các kết quả tạo ra đã khá ổn trên các chú thích huấn luyện của bạn, một <code>rank</code> là 16/32 nên hoạt động tốt. Chúng tôi nhận thấy rằng việc đặt rank quá thấp, ví dụ <code>4</code>, là không lý tưởng và không tạo ra kết quả hứa hẹn.</li> <li>Các tác giả của CogVideoX khuyến nghị 4000 bước huấn luyện và 100 video huấn luyện tổng thể để đạt được kết quả tốt nhất. Mặc dù điều đó có thể mang lại kết quả tối ưu, nhưng từ những thử nghiệm hạn chế của chúng tôi, chúng tôi nhận thấy rằng 2000 bước và 25 video cũng có thể là đủ.</li> <li>Khi sử dụng trình tối ưu Prodigy để huấn luyện, bạn có thể làm theo các khuyến nghị từ blog <a href="https://huggingface.co/blog/sdxl_lora_advanced_script" rel="nofollow">này</a>. Prodigy có xu hướng overfit nhanh. Từ những thử nghiệm rất hạn chế của tôi, tôi thấy rằng tốc độ học <code>0.5</code> là phù hợp, kết hợp với <code>--prodigy_use_bias_correction</code>, <code>prodigy_safeguard_warmup</code> và <code>--prodigy_decouple</code>.</li> <li>Tốc độ học được các tác giả của CogVideoX khuyến nghị và từ quá trình thử nghiệm của chúng tôi với Adam/AdamW nằm trong khoảng từ <code>1e-3</code> đến <code>1e-4</code> cho một bộ dữ liệu gồm 25+ video.</li></ul> <p>Lưu ý rằng việc kiểm thử của chúng tôi không mang tính toàn diện do thời gian khám phá có hạn. Khuyến nghị của chúng tôi là hãy thử nghiệm với các tùy chỉnh khác nhau để tìm ra cấu hình tối ưu nhất cho dữ liệu của bạn.</p></blockquote> <!--[1--><h2 class="relative group"><a id="inference" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#inference"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Suy luận<!----></span></h2><!--]--><!----> <p>Sau khi bạn đã huấn luyện một mô hình lora, việc suy luận có thể được thực hiện đơn giản bằng cách nạp trọng số lora vào <code>CogVideoXPipeline</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXPipeline | |
| <span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> export_to_video | |
| pipe = CogVideoXPipeline.from_pretrained(<span class="hljs-string">"THUDM/CogVideoX-2b"</span>, dtype=torch.float16) | |
| <span class="hljs-comment"># pipe.load_lora_weights("/path/to/lora/weights", adapter_name="cogvideox-lora") # Or,</span> | |
| pipe.load_lora_weights(<span class="hljs-string">"my-awesome-hf-username/my-awesome-lora-name"</span>, adapter_name=<span class="hljs-string">"cogvideox-lora"</span>) <span class="hljs-comment"># If loading from the HF Hub</span> | |
| pipe.to(<span class="hljs-string">"cuda"</span>) <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| <span class="hljs-comment"># Assuming lora_alpha=32 and rank=64 for training. If different, set accordingly</span> | |
| pipe.set_adapters([<span class="hljs-string">"cogvideox-lora"</span>], [<span class="hljs-number">32</span> / <span class="hljs-number">64</span>]) | |
| prompt = <span class="hljs-string">"A vast, shimmering ocean flows gracefully under a twilight sky, its waves undulating in a mesmerizing dance of blues and greens. The surface glints with the last rays of the setting sun, casting golden highlights that ripple across the water. Seagulls soar above, their cries blending with the gentle roar of the waves. The horizon stretches infinitely, where the ocean meets the sky in a seamless blend of hues. Close-ups reveal the intricate patterns of the waves, capturing the fluidity and dynamic beauty of the sea in motion."</span> | |
| frames = pipe(prompt, guidance_scale=<span class="hljs-number">6</span>, use_dynamic_cfg=<span class="hljs-literal">True</span>).frames[<span class="hljs-number">0</span>] | |
| export_to_video(frames, <span class="hljs-string">"output.mp4"</span>, fps=<span class="hljs-number">8</span>)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="reduce-memory-usage" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#reduce-memory-usage"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Giảm mức sử dụng bộ nhớ<!----></span></h2><!--]--><!----> <p>Trong quá trình kiểm thử sử dụng thư viện diffusers, tất cả các tối ưu hóa có trong thư viện diffusers đều được bật. Phương án này chưa được kiểm thử về mức sử dụng bộ nhớ thực tế trên các thiết bị ngoài kiến trúc <strong>NVIDIA A100 / H100</strong>. Nhìn chung, phương án này có thể được áp dụng cho tất cả các thiết bị có <strong>kiến trúc NVIDIA Ampere</strong> trở lên. Nếu tắt các tối ưu hóa, mức tiêu thụ bộ nhớ sẽ tăng lên, với bộ nhớ đỉnh khoảng 3 lần so với giá trị trong bảng. Tuy nhiên, tốc độ sẽ tăng khoảng 3-4 lần. Bạn có thể tắt chọn lọc một số tối ưu hóa, bao gồm:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class=" "><!---->pipe<span class="hljs-selector-class">.enable_sequential_cpu_offload</span>() | |
| pipe<span class="hljs-selector-class">.vae</span><span class="hljs-selector-class">.enable_slicing</span>() | |
| pipe<span class="hljs-selector-class">.vae</span><span class="hljs-selector-class">.enable_tiling</span>()<!----></pre></div><!----> <ul><li>Đối với suy luận đa GPU, tối ưu hóa <code>enable_sequential_cpu_offload()</code> cần phải được tắt.</li> <li>Việc sử dụng các mô hình INT8 sẽ làm chậm quá trình suy luận, điều này được thực hiện để phù hợp với các GPU có bộ nhớ thấp hơn trong khi vẫn duy trì mức mất chất lượng video tối thiểu, mặc dù tốc độ suy luận sẽ giảm đáng kể.</li> <li>Mô hình CogVideoX-2B được huấn luyện ở độ chính xác <code>FP16</code>, và tất cả các mô hình CogVideoX-5B được huấn luyện ở độ chính xác <code>BF16</code>. | |
| Chúng tôi khuyến nghị sử dụng độ chính xác mà mô hình đã được huấn luyện để suy luận.</li> <li><a href="https://github.com/pytorch/ao" rel="nofollow">PytorchAO</a> và <a href="https://github.com/huggingface/optimum-quanto/" rel="nofollow">Optimum-quanto</a> có thể được sử dụng để lượng tử hóa các module text encoder, transformer và VAE nhằm giảm yêu cầu bộ nhớ của CogVideoX. Điều này cho phép mô hình chạy trên các Colab T4 miễn phí hoặc các GPU có bộ nhớ nhỏ hơn! Ngoài ra, hãy lưu ý rằng lượng tử hóa TorchAO tương thích hoàn toàn với <code>torch.compile</code>, có thể cải thiện đáng kể tốc độ suy luận. Độ chính xác FP8 phải được sử dụng trên các thiết bị từ NVIDIA H100 trở lên, yêu cầu cài đặt từ mã nguồn các gói Python <code>torch</code>, <code>torchao</code>, <code>diffusers</code> và <code>accelerate</code>. Khuyến nghị sử dụng CUDA 12.4.</li> <li>Các bài kiểm tra tốc độ suy luận cũng sử dụng phương án tối ưu hóa bộ nhớ nêu trên. Nếu không có tối ưu hóa bộ nhớ, tốc độ suy luận tăng khoảng 10%. Chỉ phiên bản <code>diffusers</code> của mô hình mới hỗ trợ lượng tử hóa.</li> <li>Mô hình chỉ hỗ trợ đầu vào tiếng Anh; các ngôn ngữ khác có thể được dịch sang tiếng Anh để sử dụng thông qua tinh chỉnh bằng mô hình lớn.</li> <li>Lượng bộ nhớ sử dụng khi tinh chỉnh mô hình được kiểm tra trong môi trường <code>8 * H100</code>, và chương trình tự động | |
| sử dụng tối ưu hóa <code>Zero 2</code>. Nếu một số lượng GPU cụ thể được đánh dấu trong bảng, thì phải sử dụng số lượng GPU đó hoặc nhiều hơn | |
| để tinh chỉnh.</li></ul> <table><thead><tr><th><strong>Thuộc tính</strong></th><th><strong>CogVideoX-2B</strong></th><th><strong>CogVideoX-5B</strong></th></tr></thead><tbody><tr><td><strong>Tên mô hình</strong></td><td>CogVideoX-2B</td><td>CogVideoX-5B</td></tr><tr><td><strong>Độ chính xác suy luận</strong></td><td>FP16<em>(Đề xuất), BF16, FP32, FP8</em>, INT8, INT4 không được hỗ trợ</td><td>BF16 (Đề xuất), FP16, FP32, FP8*, INT8, INT4 không được hỗ trợ</td></tr><tr><td><strong>VRAM suy luận trên GPU đơn</strong></td><td>FP16: Sử dụng diffusers 12.5GB<em>INT8: Sử dụng diffusers với torchao 7.8GB</em></td><td>BF16: Sử dụng diffusers 20.7GB<em>INT8: Sử dụng diffusers với torchao 11.4GB</em></td></tr><tr><td><strong>VRAM suy luận đa GPU</strong></td><td>FP16: Sử dụng diffusers 10GB*</td><td>BF16: Sử dụng diffusers 15GB*</td></tr><tr><td><strong>Tốc độ suy luận</strong></td><td>Một A100: ~90 giây, Một H100: ~45 giây</td><td>Một A100: ~180 giây, Một H100: ~90 giây</td></tr><tr><td><strong>Độ chính xác tinh chỉnh</strong></td><td>FP16</td><td>BF16</td></tr><tr><td><strong>Tiêu thụ VRAM khi tinh chỉnh</strong></td><td>47 GB (bs=1, LORA) 61 GB (bs=2, LORA) 62GB (bs=1, SFT)</td><td>63 GB (bs=1, LORA) 80 GB (bs=2, LORA) 75GB (bs=1, SFT)</td></tr></tbody></table> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/diffusers/blob/main/docs/source/en/training/cogvideox.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg><!----> <span><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]--> | |
| <script> | |
| { | |
| __sveltekit_g37pnb = { | |
| base: "/docs/diffusers/main/en", | |
| assets: "/docs/diffusers/main/en" | |
| }; | |
| const element = document.currentScript.parentElement; | |
| Promise.all([ | |
| import("/docs/diffusers/main/en/_app/immutable/entry/start.D3LnKZ4R.js"), | |
| import("/docs/diffusers/main/en/_app/immutable/entry/app.C0rBoMxR.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 314], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 59.2 kB
- Xet hash:
- 6127a1b60773c5372a319aac660084ec4dd03fc39f5694485f62b147c5507f04
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.