Buckets:
| # スケジューラー | |
| スケジューラは、デノイジングループにおいて各ステップでどの程度のノイズを除去するかを指示します。スケジューラによって、速度と品質のトレードオフが異なります。 | |
| このガイドでは、スケジューラーを読み込み、そのタイムステップスケジュール、間隔、シグマをカスタマイズする方法を示します。 | |
| ## スケジューラーの選択 | |
| チェックポイントのデフォルトから開始してください。速度と品質のトレードオフを変更する必要がある場合のみ、切り替えてください。 | |
| - DPM++ 2M SDE Karras は、多くの潜在拡散チェックポイントにおいて強力な汎用オプションです。 | |
| - [TCDScheduler](/docs/diffusers/v0.43.0/ja/api/schedulers/tcd#diffusers.TCDScheduler) は蒸留モデルに効果的です。 | |
| - FlowMatchモデル(Qwen-Image、Fluxなど)には、[FlowMatchEulerDiscreteScheduler](/docs/diffusers/v0.43.0/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)または[FlowMatchHeunDiscreteScheduler](/docs/diffusers/v0.43.0/ja/api/schedulers/flow_match_heun_discrete#diffusers.FlowMatchHeunDiscreteScheduler)を使用してください。 | |
| - アニメ風の画像には、[EulerDiscreteScheduler](/docs/diffusers/v0.43.0/ja/api/schedulers/euler#diffusers.EulerDiscreteScheduler) または [EulerAncestralDiscreteScheduler](/docs/diffusers/v0.43.0/ja/api/schedulers/euler_ancestral#diffusers.EulerAncestralDiscreteScheduler) がよく機能します。 | |
| - チェックポイントが対応している場合、少数ステップでの生成のために、LCM UNet または LoRA と組み合わせた [LCMScheduler](/docs/diffusers/v0.43.0/ja/api/schedulers/lcm#diffusers.LCMScheduler)。 | |
| ## スケジューラーの読み込み | |
| > [!TIP] | |
| > Qwen-Image や Flux などの Flow-matching モデルでは、デフォルトとして [FlowMatchEulerDiscreteScheduler](/docs/diffusers/v0.43.0/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler) が同梱されています。意図的に実験を行わない限り、このスケジューラーを維持してください。代替のスケジューラーがチェックポイントと互換性がある場合のみ、[from_config()](/docs/diffusers/v0.43.0/ja/api/configuration#diffusers.ConfigMixin.from_config) を使用して切り替えてください。 | |
| Scheduler は設定のみで構成され、重みテンソルは含まれません。パイプラインの `.scheduler` 属性にアクセスして、読み込まれた設定を確認できます。 | |
| ```py | |
| import torch | |
| from diffusers import DiffusionPipeline | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16, device_map="cuda" # or "mps", "xpu", "cpu" | |
| ) | |
| pipeline.scheduler | |
| ``` | |
| 読み込まれたパイプラインでスケジューラを切り替える場合は、既存のスケジューラ設定を [from_config()](/docs/diffusers/v0.43.0/ja/api/configuration#diffusers.ConfigMixin.from_config) に渡して使用し、`num_train_timesteps` および関連するフィールドが整合した状態を維持してください。FlowMatch チェックポイント(Qwen-Image、Flux など)では、互換性のある代替スケジューラを意図的に実験する場合を除き、[FlowMatchEulerDiscreteScheduler](/docs/diffusers/v0.43.0/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler) を維持してください。 | |
| ```py | |
| from diffusers import DPMSolverMultistepScheduler | |
| pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config) | |
| ``` | |
| [from_pretrained()](/docs/diffusers/v0.43.0/ja/api/schedulers/overview#diffusers.SchedulerMixin.from_pretrained) を使用して Hub からスケジューラーの設定を読み込み、`scheduler` を通じて [from_pretrained()](/docs/diffusers/v0.43.0/ja/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained) に渡すこともできます。 | |
| ```py | |
| from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler | |
| dpm = DPMSolverMultistepScheduler.from_pretrained( | |
| "stabilityai/stable-diffusion-xl-base-1.0", subfolder="scheduler" | |
| ) | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| "stabilityai/stable-diffusion-xl-base-1.0", | |
| scheduler=dpm, | |
| dtype=torch.float16, | |
| device_map="cuda", # or "mps", "xpu", "cpu" | |
| ) | |
| pipeline.scheduler | |
| ``` | |
| ## タイムステップスケジュール | |
| Timestep or noise schedule は、デノイジングプロセスにおけるノイズの分布を決定します。スケジュールは線形である場合もあれば、開始時または終了時に集中するよう設計されている場合もあります。これはスケジューラーのデフォルト設定から生成されるノイズレベルの事前計算されたシーケンスですが、他のスケジュールを使用するようにカスタマイズすることもできます。 | |
| ```text | |
| linear (even steps) AYS (denser where it matters) | |
| noise noise | |
| ^ ^ | |
| | * | * | |
| | * | * | |
| | * | ** | |
| | * | *** | |
| | * | ** | |
| | * | * | |
| | * | * | |
| +-----------------> step +-----------------> step | |
| ``` | |
| > [!TIP] | |
| > カスタムの`timesteps`は、そのスケジューラの`set_timesteps`が引数を受け入れる場合にのみ機能します(パイプラインは`retrieve_timesteps`経由でシグネチャを確認し、受け入れられない場合は`ValueError`を送出します)。渡す前に、スケジューラのAPIページまたは`set_timesteps`のシグネチャを確認してください。 | |
| 以下の例では、[Align Your Steps (AYS)](https://research.nvidia.com/labs/toronto-ai/AlignYourSteps/)スケジュールを使用しています。このスケジュールは10ステップで高品質な画像を生成でき、生成を大幅に高速化し、計算時間を短縮します。 | |
| スケジュールをインポートし、パイプラインの`timesteps`引数に渡します。 | |
| ```py | |
| import torch | |
| from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler | |
| from diffusers.schedulers import AysSchedules | |
| sampling_schedule = AysSchedules["StableDiffusionXLTimesteps"] | |
| print(sampling_schedule) | |
| # [999, 845, 730, 587, 443, 310, 193, 116, 53, 13] | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| "SG161222/RealVisXL_V4.0", | |
| dtype=torch.float16, | |
| device_map="cuda" # or "mps", "xpu", "cpu" | |
| ) | |
| pipeline.scheduler = DPMSolverMultistepScheduler.from_config( | |
| pipeline.scheduler.config, algorithm_type="sde-dpmsolver++" | |
| ) | |
| prompt = "A cinematic shot of a cute little rabbit wearing a jacket and doing a thumbs up" | |
| image = pipeline( | |
| prompt=prompt, | |
| negative_prompt="", | |
| timesteps=sampling_schedule, | |
| ).images[0] | |
| ``` | |
| AYSタイムステップスケジュール 10ステップ | |
| 等間隔のタイムステップスケジュール 10ステップ | |
| 等間隔のタイムステップスケジュール 25ステップ | |
| 旧チェックポイントにおけるv-prediction/zero-SNRリスケールについては、[Legacy checkpoints](./legacy_checkpoints#rescaling-schedules)を参照してください。 | |
| ## タイムステップ間隔 | |
| Timestep spacingとは、スケジュールからサンプリングする特定のステップ*t*を指します。Diffusersでは、以下に示す3つのspacingタイプが提供されています。 | |
| | 間隔戦略 | 間隔の計算 | 例のタイムステップ | | |
| |---|---|---| | |
| | `leading` | 等間隔のステップ | `[900, 800, 700, ..., 100, 0]` | | |
| | `linspace` | 最初のステップと最後のステップを含み、残りの中間ステップを均等に分割します | `[1000, 888.89, 777.78, ..., 111.11, 0]` | | |
| | `trailing` | 最終ステップを含み、残りの中間ステップを末尾から均等に分割します | `[999, 899, 799, 699, 599, 499, 399, 299, 199, 99]` | | |
| スケジューラの `timestep_spacing` 引数に、間隔戦略を渡します。 | |
| > [!TIP] | |
| > `trailing`戦略は、より少ないステップ数で、より多くの詳細を含む高品質な画像を生成する傾向がありますが、より標準的なステップ数では、品質の差はそれほど明白ではありません。 | |
| ```py | |
| import torch | |
| from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| "SG161222/RealVisXL_V4.0", | |
| dtype=torch.float16, | |
| device_map="cuda" # or "mps", "xpu", "cpu" | |
| ) | |
| pipeline.scheduler = DPMSolverMultistepScheduler.from_config( | |
| pipeline.scheduler.config, timestep_spacing="trailing" | |
| ) | |
| prompt = "A cinematic shot of a cute little black cat sitting on a pumpkin at night" | |
| image = pipeline( | |
| prompt=prompt, | |
| negative_prompt="", | |
| num_inference_steps=5, | |
| ).images[0] | |
| image | |
| ``` | |
| 5ステップ後の末尾スペース | |
| 5ステップ後の先行スペース | |
| ## シグマ | |
| Sigmas は、スケジュールによって定義される特定のステップにおけるサンプルのノイズ量を表す指標です。カスタムの `sigmas` を使用する場合、`timesteps` はデフォルトのスケジューラ設定ではなく、これらの値から計算されます。 | |
| ```text | |
| step: 0 1 2 3 4 | |
| sigma: σ0 > σ1 > σ2 > σ3 > σ4 ≈ 0 | |
| high noise ---> clean sample | |
| ``` | |
| > [!TIP] | |
| > カスタム `sigmas` は、そのスケジューラの `set_timesteps` が引数を受け入れる場合にのみ機能します(パイプラインは `retrieve_timesteps` を介してシグネチャを確認し、受け入れられない場合は `ValueError` を送出します)。渡す前に、スケジューラの API ページまたは `set_timesteps` のシグネチャを確認してください。 | |
| カスタムシグマをパイプラインの`sigmas`引数に渡します。以下の例では、10ステップAYSスケジュールの[sigmas](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_utils.py)を使用しています。 | |
| ```py | |
| import torch | |
| from diffusers import DiffusionPipeline, EulerDiscreteScheduler | |
| from diffusers.schedulers import AysSchedules | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| "SG161222/RealVisXL_V4.0", | |
| dtype=torch.float16, | |
| device_map="cuda", # or "mps", "xpu", "cpu" | |
| ) | |
| pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config) | |
| sigmas = AysSchedules["StableDiffusionXLSigmas"] | |
| prompt = "A cinematic shot of a cute little rabbit wearing a jacket and doing a thumbs up" | |
| image = pipeline( | |
| prompt=prompt, | |
| negative_prompt="", | |
| sigmas=sigmas, | |
| ).images[0] | |
| ``` | |
| ### Karrasシグマ | |
| [Karras sigmas](https://huggingface.co/papers/2206.00364) は、シグマをシーケンスの中央(構造の再構築が重要となる部分)に高密度に集約し、ノイズの変化の影響が小さいシーケンスの前後ではシグマを少なくすることで、ノイズスケジュールを再サンプリングし、より効率的なサンプリングを実現します。これにより、生成画像の詳細レベルを向上させることができます。 | |
| ```text | |
| default σ: * * * * * * * * even-ish | |
| Karras σ: * * * * * * * denser mid, sparser ends | |
| |---structure---| | |
| ``` | |
| スケジューラで`use_karras_sigmas=True`を設定して有効にします。 | |
| ```py | |
| import torch | |
| from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| "SG161222/RealVisXL_V4.0", | |
| dtype=torch.float16, | |
| device_map="cuda" # or "mps", "xpu", "cpu" | |
| ) | |
| pipeline.scheduler = DPMSolverMultistepScheduler.from_config( | |
| pipeline.scheduler.config, | |
| algorithm_type="sde-dpmsolver++", | |
| use_karras_sigmas=True, | |
| ) | |
| prompt = "A cinematic shot of a cute little rabbit wearing a jacket and doing a thumbs up" | |
| image = pipeline( | |
| prompt=prompt, | |
| negative_prompt="", | |
| num_inference_steps=20, | |
| ).images[0] | |
| ``` | |
| Karrasシグマが有効 | |
| Karras sigmas が無効化されました | |
| Karras sigmasをサポートするスケジューラーの一覧については、スケジューラーAPIの[概要](../api/schedulers/overview)を参照してください。Karras sigmasで学習されたモデルでのみ使用すべきです。 | |
| ## 次のステップ | |
| - Read the [Common Diffusion Noise Schedules and Sample Steps are Flawed](https://huggingface.co/papers/2305.08891) paper for more details about rescaling the noise schedule to enforce zero SNR. | |
Xet Storage Details
- Size:
- 13.1 kB
- Xet hash:
- 50fb666e5ea2f6ae23597cab46ec4e869c65a65f5b9cfe024cfab621746516b6
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.