Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"CogVideoX","local":"cogvideox","sections":[{"title":"تجهيز البيانات","local":"data-preparation","sections":[{"title":"تنسيق صغير","local":"small-format","sections":[],"depth":3},{"title":"تنسيق البث","local":"stream-format","sections":[],"depth":3}],"depth":2},{"title":"التدريب","local":"training","sections":[],"depth":2},{"title":"الاستدلال","local":"inference","sections":[],"depth":2},{"title":"تقليل استهلاك الذاكرة","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 هو نموذج لتوليد الفيديو من النص يركّز على إنشاء فيديوهات أكثر تماسكاً ومتوافقة مع الأمر النصي. وهو يحقق ذلك باستخدام عدة طرق.</p> <ul><li><p>تشفير ذاتي تبايني ثلاثي الأبعاد يضغط مقاطع الفيديو مكانيًا وزمنيًا، مما يحسّن معدل الضغط ودقة الفيديو.</p></li> <li><p>وحدة Transformer خبيرة تساعد في محاذاة النص مع الفيديو، ووحدة انتباه كاملة ثلاثية الأبعاد لالتقاط وإنشاء فيديوهات دقيقة مكانياً وزمنياً.</p></li></ul> <p>أظهر الاختبار الفعلي لبُعد تعليمات الفيديو أن CogVideoX يحقق نتائج جيدة فيما يتعلق بالاتساق في الموضوع، والمعلومات الديناميكية، واتساق الخلفية، ومعلومات الكائنات، وسلاسة الحركة، واللون، والمشهد، ونمط المظهر، والأسلوب الزمني، لكنه لا يحقق نتائج جيدة فيما يتعلق بالحركة البشرية، والعلاقات المكانية، والكائنات المتعددة.</p> <p>يمكن أن يساعد الضبط الدقيق باستخدام Diffusers في تعويض هذه النتائج الضعيفة.</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><!---->تجهيز البيانات<!----></span></h2><!--]--><!----> <p>تقبل سكربتات التدريب البيانات بصيغتين.</p> <p>يناسب التنسيق الأول التدريب على نطاق صغير، بينما يستخدم التنسيق الثاني تنسيق CSV، وهو أكثر ملاءمة لبث البيانات للتدريب على نطاق واسع. في المستقبل، سيدعم Diffusers وسم <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><!---->تنسيق صغير<!----></span></h3><!--]--><!----> <p>ملفان، أحدهما يحتوي على موجهات مفصولة بالسطور والآخر يحتوي على مسارات مفصولة بالسطور لبيانات الفيديو (يجب أن تكون المسارات إلى ملفات الفيديو نسبية بالنسبة للمسار الذي تمرره عند تحديد <code>--instance_data_root</code>). دعونا ننظر إلى مثال لفهم ذلك بشكل أفضل!</p> <p>افترض أنك حددت <code>--instance_data_root</code> على أنه <code>/dataset</code>، وأن هذا المجلد يحتوي على الملفات: <code>prompts.txt</code> و<code>videos.txt</code>.</p> <p>يجب أن يحتوي ملف <code>prompts.txt</code> على أوامر (prompts) مفصولة بسطور:</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> تم النسخ</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>يجب أن يحتوي ملف <code>videos.txt</code> على مسارات منفصلة بسطر لكل ملف فيديو. لاحظ أن المسار يجب أن يكون <em>نسبيًا</em> إلى مجلد <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> تم النسخ</div><!----></button><!----></div> <pre class=" "><!---->videos<span class="hljs-symbol">/00000.mp4</span> | |
| videos<span class="hljs-symbol">/00001.mp4</span> | |
| ...<!----></pre></div><!----> <p>بشكل عام، هذا هو شكل مجموعة البيانات الخاصة بك إذا قمت بتشغيل أمر <code>tree</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> تم النسخ</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>عند استخدام هذا التنسيق، يجب أن يكون <code>--caption_column</code> هو <code>prompts.txt</code> وأن يكون <code>--video_column</code> هو <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><!---->تنسيق البث<!----></span></h3><!--]--><!----> <p>يمكنك استخدام ملف CSV واحد. من أجل هذا المثال، افترض أن لديك ملف <code>metadata.csv</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> تم النسخ</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>في هذه الحالة، يجب أن يكون <code>--instance_data_root</code> هو الموقع الذي تُخزَّن فيه مقاطع الفيديو، وأن يكون <code>--dataset_name</code> إما مسارًا إلى مجلد محلي أو مجموعة بيانات متوافقة مع <a href="https://huggingface.co/docs/datasets/main/en/package_reference/loading_methods#datasets.load_dataset" rel="nofollow">load_dataset</a> مستضافة على Hub. بافتراض أن لديك مقاطع فيديو لألعاب ماينكرافت في <code>https://huggingface.co/datasets/my-awesome-username/minecraft-videos</code>، فستحتاج إلى تحديد <code>my-awesome-username/minecraft-videos</code>.</p> <p>عند استخدام هذا التنسيق، يجب أن يكون <code>--caption_column</code> هو <code><CAPTION_COLUMN></code> وأن يكون <code>--video_column</code> هو <code><PATH_TO_VIDEO_COLUMN></code>.</p> <p>لستَ مقيدًا بشكل صارم بتنسيق CSV. يعمل أي تنسيق طالما يدعم أسلوب <code>load_dataset</code> تنسيق الملف لتحميل عمود <code><PATH_TO_VIDEO_COLUMN></code> و<code><CAPTION_COLUMN></code> الأساسي. والسبب في المرور بهذه الخطوات المعقدة لتنظيم مجموعة البيانات عند تحميل بيانات الفيديو هو أن <code>load_dataset</code> لا يدعم جميع أنواع تنسيقات الفيديو بشكل كامل.</p> <blockquote class="note"><p>يعمل CogVideoX بشكل أفضل مع الأوامر النصية الطويلة والوصفية المعززة بنماذج اللغة الكبيرة (LLM) لتوليد الفيديو. ننصح بمعالجة مقاطع الفيديو مسبقاً من خلال توليد ملخص أولاً باستخدام نموذج لغة-رؤية (VLM)، ثم تعزيز الأوامر النصية باستخدام نموذج لغة كبير (LLM). ولتوليد التسميات المذكورة أعلاه، استخدمنا <a href="https://huggingface.co/openbmb/MiniCPM-V-2_6" rel="nofollow">MiniCPM-V-26</a> و <a href="https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct" rel="nofollow">Llama-3.1-8B-Instruct</a>. يتوفر مثال بسيط جداً وخالي من التعقيدات لهذا الإجراء <a href="https://gist.github.com/a-r-r-o-w/4dee20250e82f4e44690a02351324a4a" rel="nofollow">هنا</a>. والتوصية الرسمية لتعزيز الأوامر النصية هي استخدام <a href="https://huggingface.co/THUDM?search_models=chatglm" rel="nofollow">ChatGLM</a>، ويُعتبر طول الأمر بين 50 و100 كلمة مناسباً.</p></blockquote> <blockquote><p>![NOTE] | |
| من المتوقع أن يكون مجموعة بياناتك مُعالجة مسبقًا بالفعل. وإذا لم تكن كذلك، يمكن إجراء بعض المعالجة الأساسية الأولية عن طريق التلاعب بالمعاملات التالية: <code>--height</code>، <code>--width</code>، <code>--fps</code>، <code>--max_num_frames</code>، <code>--skip_frames_start</code> و<code>--skip_frames_end</code>. | |
| حاليًا، يجب أن تحتوي جميع مقاطع الفيديو في مجموعة بياناتك على نفس عدد إطارات الفيديو عند استخدام حجم دفعة تدريب > 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><!---->التدريب<!----></span></h2><!--]--><!----> <p>تحتاج إلى إعداد بيئة التطوير من خلال تثبيت المتطلبات اللازمة. الحزم التالية مطلوبة:</p> <ul><li>Torch 2.0 أو أحدث بناءً على ميزات التدريب التي تستخدمها (قد يتطلب ذلك أحدث إصدارات أو الإصدارات الليلية للتدريب باستخدام التكميم/deepspeed)</li> <li><code>pip install diffusers transformers accelerate peft huggingface_hub</code> لكل ما يتعلق بالنمذجة والتدريب</li> <li><code>pip install datasets decord</code> لتحميل بيانات التدريب الخاصة بالفيديو</li> <li><code>pip install bitsandbytes</code> لاستخدام مُحسِّنات Adam أو AdamW بدقة 8 بت للتدريب المُحسَّن من حيث الذاكرة</li> <li><code>pip install wandb</code> اختياريًا لمراقبة سجلات التدريب</li> <li><code>pip install deepspeed</code> اختياريًا لتدريب <a href="https://github.com/microsoft/DeepSpeed" rel="nofollow">DeepSpeed</a></li> <li><code>pip install prodigyopt</code> اختياريًا إذا كنت ترغب في استخدام مُحسِّن Prodigy للتدريب</li></ul> <p>لضمان قدرتك على تشغيل أحدث إصدارات سكربتات الأمثلة بنجاح، ننصح بشدة بـ<strong>التثبيت من المصدر</strong> والحفاظ على تحديث التثبيت، حيث نقوم بتحديث سكربتات الأمثلة بشكل متكرر ونثبّت بعض المتطلبات الخاصة بالأمثلة. للقيام بذلك، نفّذ الخطوات التالية في بيئة افتراضية جديدة:</p> <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> تم النسخ</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>ثم انتقل إلى مجلد المثال الذي يحتوي على سكربت التدريب وقم بتثبيت التبعيات المطلوبة للسكربت الذي تستخدمه:</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> تم النسخ</div><!----></button><!----></div> <pre class="language-bash "><!----><span class="hljs-built_in">cd</span> examples/cogvideo | |
| pip install -r requirements.txt<!----></pre></div><!----> <p>ومساحة عمل <a href="https://github.com/huggingface/accelerate/" rel="nofollow">🤗 Accelerate</a> مع:</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> تم النسخ</div><!----></button><!----></div> <pre class="language-bash "><!---->accelerate config<!----></pre></div><!----> <p>أو للحصول على إعداد accelerate افتراضي دون الإجابة على أسئلة حول بيئة التشغيل</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> تم النسخ</div><!----></button><!----></div> <pre class="language-bash "><!---->accelerate config default<!----></pre></div><!----> <p>أو إذا لم يدعم بيئتك shell تفاعليًا (مثل 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> تم النسخ</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>عند تشغيل <code>accelerate config</code>، إذا كنت تستخدم torch.compile، فقد تتحقق تسارعات هائلة. تُستخدم مكتبة PEFT كواجهة خلفية لتدريب LoRA، لذا تأكد من تثبيت <code>peft>=0.6.0</code> في بيئتك.</p> <p>إذا كنت ترغب في رفع نموذجك إلى Hub بعد اكتمال التدريب مع بطاقة نموذج أنيقة، فتأكد من تسجيل الدخول:</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> تم النسخ</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>تأكد من أن بياناتك مُعدّة كما هو موضح في <a href="#data-preparation">تجهيز البيانات</a>. عند الانتهاء، يمكنك البدء بالتدريب!</p> <p>بافتراض أنك تقوم بالتدريب على 50 فيديو لمفهوم مشابه، فقد وجدنا أن 1500-2000 خطوة تعمل بشكل جيد. ومع ذلك، فإن التوصية الرسمية هي 100 فيديو بإجمالي 4000 خطوة. بافتراض أنك تقوم بالتدريب على وحدة معالجة رسومية واحدة مع <code>--train_batch_size</code> بقيمة <code>1</code>:</p> <ul><li>1500 خطوة على 50 فيديو تتوافق مع <code>30</code> من فترات التدريب</li> <li>4000 خطوة على 100 فيديو تتوافق مع <code>40</code> من دورات التدريب</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> تم النسخ</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>لتتبع تجارب التدريب لدينا بشكل أفضل، نستخدم الأعلام التالية في الأمر أعلاه:</p> <ul><li><code>--report_to wandb</code> يضمن تتبع عمليات التدريب على Weights and Biases. لاستخدامه، تأكد من تثبيت <code>wandb</code> باستخدام <code>pip install wandb</code>.</li> <li><code>validation_prompt</code> و<code>validation_epochs</code> للسماح للسكريبت بإجراء بعض عمليات الاستدلال للتحقق. وهذا يتيح لنا التحقق النوعي من أن التدريب يتقدم كما هو متوقع.</li></ul> <p>لا يُشترط تعيين <code><ID_TOKEN></code>. فمن خلال بعض التجارب المحدودة، وجدنا أنه يعمل بشكل أفضل (لأنه يشبه تدريب <a href="./dreambooth">Dreambooth</a>) من دون تعيينه. عند توفيره، يُضاف <code><ID_TOKEN></code> إلى بداية كل موجه. لذا، إذا كان <code><ID_TOKEN></code> الخاص بك هو <code>"DISNEY"</code> وكان موجهك هو <code>"Spiderman swinging over buildings"</code>، فإن الموجه الفعّال المستخدم في التدريب سيكون <code>"DISNEY Spiderman swinging over buildings"</code>. عند عدم توفيره، يمكنك إما التدريب دون أي رمز إضافي، أو تعزيز مجموعة بياناتك لتطبيق الرمز في المكان الذي ترغب فيه قبل بدء التدريب.</p> <blockquote class="note"><p>يمكنك تمرير <code>--use_8bit_adam</code> لتقليل متطلبات الذاكرة أثناء التدريب.</p></blockquote> <blockquote class="important"><p>تم اختبار الإعدادات التالية عند إضافة دعم تدريب CogVideoX LoRA:</p> <ul><li>تم إجراء اختباراتنا بشكل أساسي على CogVideoX-2b. وسنعمل على CogVideoX-5b وCogVideoX-5b-I2V قريباً</li> <li>تتألف مجموعة بيانات واحدة من 70 فيديو تدريب بدقة <code>200 x 480 x 720</code> (F x H x W). ومن هذه المجموعة، باستخدام تخطي الإطارات في المعالجة المسبقة للبيانات، أنشأنا مجموعتي بيانات أصغر مكوّنتين من 49 إطارًا و16 إطارًا لتسريع التجارب، ولأن الحد الأقصى الموصى به من فريق CogVideoX هو 49 إطارًا. ومن بين الفيديوهات السبعين، أنشأنا ثلاث مجموعات مكوّنة من 10 و25 و50 فيديو. كانت جميع الفيديوهات متشابهة من حيث طبيعة المفهوم المُدرَّب.</li> <li>أظهرت أكثر من 25 فيديو أفضل النتائج عند تدريب مفاهيم وأنماط جديدة.</li> <li>وجدنا أنه من الأفضل التدريب باستخدام رمز تعريف يمكن تحديده عبر <code>--id_token</code>. يشبه هذا التدريب بأسلوب Dreambooth، لكن الضبط الدقيق العادي دون استخدام مثل هذا الرمز يعمل أيضاً.</li> <li>يبدو أن المفهوم المُدرَّب يعمل بشكل جيد إلى حد ما عند دمجه مع أوامر غير ذات صلة تمامًا. نتوقع الحصول على نتائج أفضل إذا تم ضبط نموذج CogVideoX-5B.</li> <li>يستخدم المستودع الأصلي قيمة <code>lora_alpha</code> تساوي <code>1</code>. وجدنا أن هذه القيمة غير مناسبة في العديد من التشغيلات، ربما بسبب اختلاف في محركات النمذجة وإعدادات التدريب. توصيتنا هي ضبط <code>lora_alpha</code> إما إلى <code>rank</code> أو <code>rank // 2</code>.</li> <li>إذا كنت تدرب على بيانات تُنتج عناوينها نتائج سيئة مع النموذج الأصلي، فإن قيمة <code>rank</code> تساوي 64 أو أعلى تكون مناسبة، وهي أيضاً التوصية من الفريق المطوّر لـ CogVideoX. إذا كانت النتائج المولّدة جيدة إلى حد ما مسبقاً على عناوين التدريب الخاصة بك، فيجب أن تعمل قيمة <code>rank</code> تساوي 16/32. وجدنا أن ضبط الرتبة على قيمة منخفضة جداً، مثل <code>4</code>، ليس مثالياً ولا يُنتج نتائج واعدة.</li> <li>يوصي مؤلفو CogVideoX بأداء 4000 خطوة تدريب و100 فيديو تدريب بشكل عام لتحقيق أفضل نتيجة. وعلى الرغم من أن ذلك قد يحقق أفضل النتائج، فقد وجدنا من تجاربنا المحدودة أن 2000 خطوة و25 فيديو قد تكون كافية أيضاً.</li> <li>عند استخدام مُحسِّن Prodigy للتدريب، يمكن اتباع التوصيات الواردة في <a href="https://huggingface.co/blog/sdxl_lora_advanced_script" rel="nofollow">هذا</a> المدونة. يميل Prodigy إلى الإفراط في التكيّف بسرعة. ومن اختبارات المحدودة جداً، وجدت أن معدل تعلّم قدره <code>0.5</code> مناسب بالإضافة إلى <code>--prodigy_use_bias_correction</code> و<code>prodigy_safeguard_warmup</code> و<code>--prodigy_decouple</code>.</li> <li>معدل التعلم الموصى به من قبل مؤلفي CogVideoX ومن خلال تجاربنا مع Adam/AdamW يتراوح بين <code>1e-3</code> و<code>1e-4</code> لمجموعة بيانات تتكون من 25 فيديو أو أكثر.</li></ul> <p>يرجى ملاحظة أن اختباراتنا ليست شاملة بسبب الوقت المحدود المخصص للاستكشاف. توصيتنا هي تجربة الإعدادات المختلفة للعثور على أفضل إعدادات لبياناتك.</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><!---->الاستدلال<!----></span></h2><!--]--><!----> <p>بمجرد تدريب نموذج lora، يمكن تنفيذ الاستدلال ببساطة عن طريق تحميل أوزان lora في <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> تم النسخ</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><!---->تقليل استهلاك الذاكرة<!----></span></h2><!--]--><!----> <p>أثناء الاختبار باستخدام مكتبة diffusers، تم تفعيل جميع التحسينات المضمنة في مكتبة diffusters. لم يتم اختبار هذا المخطط لاستخدام الذاكرة الفعلي على الأجهزة خارج معماريات <strong>NVIDIA A100 / H100</strong>. بشكل عام، يمكن تكييف هذا المخطط مع جميع الأجهزة التي تعمل بمعمارية <strong>NVIDIA Ampere architecture</strong> وما فوق. إذا تم تعطيل التحسينات، فستتضاعف استهلاك الذاكرة، حيث يكون ذروة استخدام الذاكرة حوالي 3 أضعاف القيمة المذكورة في الجدول. ومع ذلك، سيزداد السرعة بحوالي 3-4 أضعاف. يمكنك تعطيل بعض التحسينات بشكل انتقائي، بما في ذلك:</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> تم النسخ</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>للاستدلال متعدد وحدات معالجة الرسومات، يجب تعطيل تحسين <code>enable_sequential_cpu_offload()</code>.</li> <li>سيؤدي استخدام نماذج INT8 إلى إبطاء الاستدلال، وهو إجراء يُتّخذ لاستيعاب وحدات معالجة الرسومات ذات الذاكرة الأقل مع الحفاظ على فقدانٍ ضئيلٍ في جودة الفيديو، على الرغم من أن سرعة الاستدلال ستنخفض بشكل كبير.</li> <li>تم تدريب نموذج CogVideoX-2B بدقة <code>FP16</code>، وتم تدريب جميع نماذج CogVideoX-5B بدقة <code>BF16</code>. | |
| نوصي باستخدام الدقة التي تم بها تدريب النموذج عند الاستدلال.</li> <li>يمكن استخدام <a href="https://github.com/pytorch/ao" rel="nofollow">PytorchAO</a> و <a href="https://github.com/huggingface/optimum-quanto/" rel="nofollow">Optimum-quanto</a> لتكميم وحدات مُشفِّر النص، والتحويلي، وVAE لتقليل متطلبات الذاكرة الخاصة بـ CogVideoX. وهذا يتيح تشغيل النموذج على أجهزة Colabs المجانية من نوع T4 أو على وحدات معالجة رسومية ذات ذاكرة أصغر! كما لاحظ أن تكميم TorchAO متوافق تمامًا مع <code>torch.compile</code>، مما يمكن أن يحسّن سرعة الاستدلال بشكل كبير. يجب استخدام دقة FP8 على الأجهزة المزودة ببطاقات NVIDIA H100 أو أحدث، ويتطلب ذلك تثبيت حزم <code>torch</code> و <code>torchao</code> و <code>diffusers</code> و <code>accelerate</code> بلغة بايثون من المصدر. ويُوصى باستخدام CUDA 12.4.</li> <li>استخدمت اختبارات سرعة الاستدلال أيضًا مخطط تحسين الذاكرة المذكور أعلاه. بدون تحسين الذاكرة، تزداد سرعة الاستدلال بنسبة 10% تقريبًا. يدعم إصدار <code>diffusers</code> من النموذج فقط عملية التكميم.</li> <li>يدعم النموذج مدخلات باللغة الإنجليزية فقط؛ يمكن ترجمة اللغات الأخرى إلى الإنجليزية للاستخدام عبر تحسين النموذج الكبير.</li> <li>يتم اختبار استهلاك الذاكرة في ضبط نموذج في بيئة <code>8 * H100</code>، ويستخدم البرنامج تلقائيًا تحسين <code>Zero 2</code>. إذا تم تحديد عدد معين من وحدات معالجة الرسومات في الجدول، فيجب استخدام هذا العدد أو أكثر من وحدات معالجة الرسومات لضبط النموذج.</li></ul> <table><thead><tr><th><strong>الخاصية</strong></th><th><strong>CogVideoX-2B</strong></th><th><strong>CogVideoX-5B</strong></th></tr></thead><tbody><tr><td><strong>اسم النموذج</strong></td><td>CogVideoX-2B</td><td>CogVideoX-5B</td></tr><tr><td><strong>دقة الاستدلال</strong></td><td>FP16<em>(موصى به)، BF16، FP32، FP8</em>، INT8، INT4 غير مدعوم</td><td>BF16 (موصى به)، FP16، FP32، FP8*، INT8، INT4 غير مدعوم</td></tr><tr><td><strong>ذاكرة VRAM للاستدلال على GPU واحد</strong></td><td>FP16: استخدام diffusers 12.5GB<em>INT8: استخدام diffusers مع torchao 7.8GB</em></td><td>BF16: استخدام diffusers 20.7GB<em>INT8: استخدام diffusers مع torchao 11.4GB</em></td></tr><tr><td><strong>ذاكرة VRAM للاستدلال متعدد وحدات GPU</strong></td><td>FP16: باستخدام diffusers 10GB*</td><td>BF16: باستخدام diffusers 15GB*</td></tr><tr><td><strong>سرعة الاستدلال</strong></td><td>وحدة A100 واحدة: ~90 ثانية، وحدة H100 واحدة: ~45 ثانية</td><td>وحدة A100 واحدة: ~180 ثانية، وحدة H100 واحدة: ~90 ثانية</td></tr><tr><td><strong>دقة الضبط الدقيق</strong></td><td>FP16</td><td>BF16</td></tr><tr><td><strong>استهلاك ذاكرة VRAM أثناء الضبط الدقيق</strong></td><td>47 جيجابايت (bs=1, LORA) 61 جيجابايت (bs=2, LORA) 62 جيجابايت (bs=1, SFT)</td><td>63 جيجابايت (bs=1, LORA) 80 جيجابايت (bs=2, LORA) 75 جيجابايت (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:
- 60.9 kB
- Xet hash:
- f15bc1a093775f51cd9f883c497a6d336179ac8482de899ce1c9fcb4f8e8a195
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.