Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Hugging Face Jobs","local":"hugging-face-jobs","sections":[{"title":"JobsでLoRAを学習","local":"train-a-lora-on-jobs","sections":[],"depth":2},{"title":"ジョブの管理","local":"managing-a-job","sections":[],"depth":2},{"title":"自分の画像で学習","local":"train-on-your-own-images","sections":[],"depth":2},{"title":"FP8で学習","local":"train-in-fp8","sections":[],"depth":2},{"title":"依存関係ヘッダーなしでスクリプトを実行する","local":"run-a-script-without-a-dependency-header","sections":[],"depth":2},{"title":"長時間の実行用にチェックポイントを保存する","local":"save-checkpoints-for-long-runs","sections":[],"depth":2},{"title":"次のステップ","local":"next-steps","sections":[],"depth":2}],"depth":1}"/> | |
| <link href="/docs/diffusers/main/en/_app/immutable/entry/start.0S0_iEoG.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/I9eooN77.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/Bupkjr9f.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/entry/app.CPdOxCbw.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/CyvZ3FS5.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/l0QnnOED.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.DteTvmQZ.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/CoSrdQax.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/nodes/371.mqOHi8TH.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DSPDl1gz.js" rel="modulepreload"> | |
| <!--1ffuigs--><meta name="hf:doc:metadata" content="{"title":"Hugging Face Jobs","local":"hugging-face-jobs","sections":[{"title":"Train a LoRA on Jobs","local":"train-a-lora-on-jobs","sections":[],"depth":2},{"title":"Managing a Job","local":"managing-a-job","sections":[],"depth":2},{"title":"Train on your own images","local":"train-on-your-own-images","sections":[],"depth":2},{"title":"Train in FP8","local":"train-in-fp8","sections":[],"depth":2},{"title":"Run a script without a dependency header","local":"run-a-script-without-a-dependency-header","sections":[],"depth":2},{"title":"Save checkpoints for long runs","local":"save-checkpoints-for-long-runs","sections":[],"depth":2},{"title":"Next steps","local":"next-steps","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="hugging-face-jobs" 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="#hugging-face-jobs"><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><!---->Hugging Face Jobs<!----></span></h1><!--]--><!----> <p><a href="https://huggingface.co/docs/hub/jobs" rel="nofollow">Hugging Face Jobs</a> は Hugging Face の GPU で実行されるため、マシンのセットアップは不要です。また、ターミナルを閉じても実行は継続されます。Diffusers の学習スクリプトは、リポジトリをクローンしたりローカルに何かをインストールしたりすることなく、GitHub の URL からそのまま Jobs で実行できます。</p> <p>開始する前に、<a href="https://huggingface.co/docs/hub/jobs-quickstart" rel="nofollow">Jobs クイックスタート</a>に従って、<code>hf</code> CLI をインストールし、ログインして、アカウントにクレジットを追加してください。</p> <!--[1--><h2 class="relative group"><a id="train-a-lora-on-jobs" 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="#train-a-lora-on-jobs"><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><!---->JobsでLoRAを学習<!----></span></h2><!--]--><!----> <p>以下のコマンドは、<a href="https://huggingface.co/datasets/diffusers/dog-example" rel="nofollow">diffusers/dog-example</a> にある5枚の犬の写真で <a href="https://huggingface.co/black-forest-labs/FLUX.2-klein-4B" rel="nofollow">FLUX.2-klein-4B</a> の LoRA を学習します。単一の A10G で実行でき、学習した LoRA を 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 "><!----><span class="hljs-comment"># 20 steps is a test run. For a real run, raise --max_train_steps</span> | |
| <span class="hljs-comment"># (the FLUX.2 README uses 500) and --timeout to match.</span> | |
| hf <span class="hljs-built_in">jobs</span> uv run --flavor a10g-small --<span class="hljs-built_in">timeout</span> 30m -s HF_TOKEN -- \ | |
| https://raw.githubusercontent.com/huggingface/diffusers/main/examples/dreambooth/train_dreambooth_lora_flux2_klein.py \ | |
| --pretrained_model_name_or_path black-forest-labs/FLUX.2-klein-4B \ | |
| --dataset_name diffusers/dog-example \ | |
| --instance_prompt <span class="hljs-string">"a photo of sks dog"</span> \ | |
| --resolution 512 --mixed_precision bf16 --guidance_scale 1 \ | |
| --gradient_checkpointing --cache_latents \ | |
| --optimizer adamW --use_8bit_adam --learning_rate 1e-4 \ | |
| --max_train_steps 20 --seed 0 \ | |
| --output_dir /tmp/out \ | |
| --push_to_hub --hub_model_id your-username/klein-dog-lora<!----></pre></div><!----> <p><code>uv</code> は、スクリプトの <code># /// script</code> ヘッダーに列挙された依存関係をインストールします。これには <code>main</code> からの Diffusers も含まれます。ジョブにはデフォルトで Hugging Face トークンが与えられないため、<code>-s HF_TOKEN</code> を使用してトークンをスクリプトに渡し、LoRA をプッシュできるようにします。ジョブのディスクはジョブ終了時に破棄されるため、プッシュしなかったデータは失われます。<a href="./dreambooth">DreamBooth</a> と <a href="./lora">LoRA</a> のガイドでは、トレーニング引数について説明しています。</p> <!--[1--><h2 class="relative group"><a id="managing-a-job" 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="#managing-a-job"><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>Jobの実行中、トレーニングログはターミナルに出力されます。ターミナルを閉じたり<code>Ctrl+C</code>を押したりしても、JobはHugging Faceのマシン上で実行されるため、トレーニングは停止しません。ターミナルを占有せずに長時間の実行を開始するには、<code>--</code>の前に<code>-d</code>を追加します。すると、コマンドはJob IDを出力して返ります。</p> <p>Job ID を使用して、ログに再接続したり、モデルの学習中に GPU メモリと使用率を確認したり、実行を停止したりできます。</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 <span class="hljs-built_in">jobs</span> logs -f <job_id> | |
| hf <span class="hljs-built_in">jobs</span> stats <job_id> | |
| hf <span class="hljs-built_in">jobs</span> cancel <job_id><!----></pre></div><!----> <p>実行が失敗した場合、<code>hf jobs inspect <job_id></code> でエラーメッセージが表示されます。その他のコマンドについては、<a href="https://huggingface.co/docs/hub/jobs-manage" rel="nofollow">ジョブの管理</a>を参照してください。</p> <!--[1--><h2 class="relative group"><a id="train-on-your-own-images" 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="#train-on-your-own-images"><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>画像で学習するには、<code>-v</code> を使用してそのフォルダを Job にマウントし、<code>--dataset_name</code> の代わりにマウントパスを <code>--instance_data_dir</code> に渡します。Jobs は Job の開始前にフォルダをプライベートバケットにアップロードし、読み取り専用でマウントします。同じフォルダを再度アップロードしても、新規または変更されたファイルのみが送信されます。</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 <span class="hljs-built_in">jobs</span> uv run --flavor a10g-small --<span class="hljs-built_in">timeout</span> 30m -s HF_TOKEN \ | |
| -v ./my-dog:/data -- \ | |
| https://raw.githubusercontent.com/huggingface/diffusers/main/examples/dreambooth/train_dreambooth_lora_flux2_klein.py \ | |
| --pretrained_model_name_or_path black-forest-labs/FLUX.2-klein-4B \ | |
| --instance_data_dir /data \ | |
| --instance_prompt <span class="hljs-string">"a photo of sks dog"</span> \ | |
| --resolution 512 --mixed_precision bf16 --guidance_scale 1 \ | |
| --gradient_checkpointing --cache_latents \ | |
| --optimizer adamW --use_8bit_adam --learning_rate 1e-4 \ | |
| --max_train_steps 20 --seed 0 \ | |
| --output_dir /tmp/out \ | |
| --push_to_hub --hub_model_id your-username/klein-dog-lora<!----></pre></div><!----> <p>スクリプトは<code>--instance_data_dir</code>内のすべてのファイルを画像として開くため、フォルダには画像のみを保存してください。<code>.DS_Store</code>のような隠しファイルがあると実行が失敗します。フォルダのマウントに関する詳細は、<a href="https://huggingface.co/docs/hub/jobs-configuration#local-directories" rel="nofollow">ローカルディレクトリ</a>を参照してください。</p> <p><code>--with_prior_preservation</code> を使用すると、スクリプトは学習開始前にクラス画像を <code>--class_data_dir</code> に生成します。Job が書き込み可能なパスを指定してください。後続の実行でクラス画像を再利用するには、<a href="#save-checkpoints-for-long-runs">長時間実行用のチェックポイントの保存</a> に記載されているような読み書き可能なバケットマウントに配置してください。</p> <!--[1--><h2 class="relative group"><a id="train-in-fp8" 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="#train-in-fp8"><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><!---->FP8で学習<!----></span></h2><!--]--><!----> <p>FLUX.2、Z-Image、Ideogram 4、および Krea 2 の DreamBooth LoRA スクリプトは、<code>--do_fp8_training</code> を指定することで <a href="https://github.com/pytorch/ao" rel="nofollow">torchao</a> を使用して FP8 で学習し、メモリ使用量を削減できます。スクリプトのヘッダーには torchao が含まれていないため、<code>--</code> の前に <code>--with torchao</code> を追加してください。また、FP8 には L4 (<code>l4x1</code>) や L40S (<code>l40sx1</code>) のような、コンピュート能力 8.9 以上の GPU が必要です。A10G (8.6) と A100 (8.0) はサポートされていません。</p> <!--[1--><h2 class="relative group"><a id="run-a-script-without-a-dependency-header" 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="#run-a-script-without-a-dependency-header"><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><a href="https://github.com/huggingface/diffusers/tree/main/examples/dreambooth" rel="nofollow">examples/dreambooth</a> と <a href="https://github.com/huggingface/diffusers/tree/main/examples/advanced_diffusion_training" rel="nofollow">examples/advanced_diffusion_training</a> にあるスクリプトのみ、ファイルの先頭に <code># /// script</code> ブロックを宣言しています。これらのフォルダ内の <code>train_dreambooth_lora_sdxl.py</code> などのスクリプトには、このブロックが含まれていません。</p> <p>ヘッダーのないスクリプトでは、各依存関係を<code>--with</code>で渡します。学習スクリプトは開発版を必要とするため、Diffusersはソースからインストールしてください。その他の依存関係は、スクリプトの<code>requirements.txt</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-bash "><!---->hf <span class="hljs-built_in">jobs</span> uv run --flavor a10g-small --<span class="hljs-built_in">timeout</span> 30m -s HF_TOKEN \ | |
| --with <span class="hljs-string">"diffusers @ git+https://github.com/huggingface/diffusers.git"</span> \ | |
| --with torch --with torchvision --with accelerate --with transformers \ | |
| --with peft --with datasets --with bitsandbytes \ | |
| --with ftfy --with tensorboard --with Jinja2 -- \ | |
| https://raw.githubusercontent.com/huggingface/diffusers/main/examples/dreambooth/train_dreambooth_lora_sdxl.py \ | |
| --pretrained_model_name_or_path stabilityai/stable-diffusion-xl-base-1.0 \ | |
| --pretrained_vae_model_name_or_path madebyollin/sdxl-vae-fp16-fix \ | |
| --dataset_name diffusers/dog-example \ | |
| --instance_prompt <span class="hljs-string">"a photo of sks dog"</span> \ | |
| --resolution 1024 --mixed_precision fp16 \ | |
| --gradient_checkpointing --use_8bit_adam --learning_rate 1e-4 \ | |
| --max_train_steps 20 --seed 0 \ | |
| --output_dir /tmp/out \ | |
| --push_to_hub --hub_model_id your-username/sdxl-dog-lora<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="save-checkpoints-for-long-runs" 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="#save-checkpoints-for-long-runs"><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>数時間かかる実行は、完了前にタイムアウトやクラッシュが発生する可能性があります。進捗を保持するには、<code>-v</code> を使用してジョブに <a href="https://huggingface.co/docs/hub/storage-buckets" rel="nofollow">Storage Bucket</a> をマウントし、<code>--output_dir</code> をそのバケットに向けます。まず、<code>hf buckets create</code> でバケットを作成してください。</p> <p>スクリプトは、<code>--checkpointing_steps</code> ステップ(デフォルトは 500)ごとに <code>checkpoint-<step></code> フォルダを <code>--output_dir</code> に保存するため、学習が進むにつれてチェックポイントがバケットに格納されます。<code>--checkpoints_total_limit</code> で保持するチェックポイントの最大数を制限できます。<code>--resume_from_checkpoint latest</code> を使用すると、<code>--output_dir</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-bash "><!---->hf <span class="hljs-built_in">jobs</span> uv run --flavor a10g-small --<span class="hljs-built_in">timeout</span> 8h -s HF_TOKEN \ | |
| -v hf://buckets/your-username/checkpoints:/ckpt -- \ | |
| https://raw.githubusercontent.com/huggingface/diffusers/main/examples/dreambooth/train_dreambooth_lora_flux2_klein.py \ | |
| --pretrained_model_name_or_path black-forest-labs/FLUX.2-klein-4B \ | |
| --dataset_name diffusers/dog-example \ | |
| --instance_prompt <span class="hljs-string">"a photo of sks dog"</span> \ | |
| --resolution 1024 --mixed_precision bf16 --guidance_scale 1 \ | |
| --gradient_checkpointing --cache_latents \ | |
| --optimizer adamW --use_8bit_adam --learning_rate 1e-4 \ | |
| --max_train_steps 5000 --seed 0 \ | |
| --checkpointing_steps 500 --checkpoints_total_limit 3 \ | |
| --resume_from_checkpoint latest \ | |
| --output_dir /ckpt/klein-dog<!----></pre></div><!----> <p>トレーニングが終了すると、LoRA はバケットに <code>pytorch_lora_weights.safetensors</code> として保存されます。マウントオプションについては、<a href="https://huggingface.co/docs/hub/jobs-configuration#volumes" rel="nofollow">ボリューム</a>を参照してください。</p> <blockquote class="note"><p><code>--output_dir</code> にチェックポイントが含まれている場合、<code>--push_to_hub</code> を追加しないでください。アップロードは <code>step_*</code> と <code>epoch_*</code> フォルダーのみをスキップするため、<code>checkpoint-<step></code> フォルダーは LoRA と一緒にモデルリポジトリにプッシュされてしまいます。代わりに、<code>pytorch_lora_weights.safetensors</code> を自分でモデルリポジトリにアップロードしてください。</p></blockquote> <!--[1--><h2 class="relative group"><a id="next-steps" 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="#next-steps"><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><!--]--><!----> <ul><li>Hub のドキュメントにある <a href="https://huggingface.co/docs/hub/jobs-training" rel="nofollow">Train Models on Jobs</a> を参照し、長時間のジョブ実行前に実施すべきチェック項目や、失敗したジョブの読み取り方法を確認してください。</li> <li><a href="../tutorials/using_peft_for_inference">LoRA</a>ガイドに従って、学習済みのLoRAを読み込んで推論を実行してください。</li> <li>モデル固有のコマンドやメモリオプションについては、<a href="https://github.com/huggingface/diffusers/tree/main/examples/dreambooth" rel="nofollow">DreamBoothのREADMEファイル</a>を参照してください。</li></ul> <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/jobs.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_1qsdbwf = { | |
| 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.0S0_iEoG.js"), | |
| import("/docs/diffusers/main/en/_app/immutable/entry/app.CPdOxCbw.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 371], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 34.9 kB
- Xet hash:
- 297f2c54496229cb220a17cc4d5e4d0a6c5ad182c455ce7d1730c6de495c4f70
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.