Buckets:
| # Consistency Models | |
| Consistency Models は、Yang Song、Prafulla Dhariwal、Mark Chen、Ilya Sutskever による [Consistency Models](https://huggingface.co/papers/2303.01469) で提案されました。 | |
| 論文の抄録は以下の通りです: | |
| *Diffusionモデルは画像・音声・動画生成の分野を大きく前進させましたが、反復的なサンプリングプロセスに依存しているため、生成が遅いという課題があります。この制約を克服するために、ノイズをデータへ直接マッピングすることで高品質なサンプルを生成する新しいモデルファミリーであるconsistencyモデルを提案します。consistencyモデルは設計上、1ステップでの高速生成をサポートしつつ、計算量とサンプル品質のトレードオフを可能にするマルチステップサンプリングにも対応します。また、これらのタスクに対する明示的なトレーニングを必要とせずに、画像インペインティング、カラー化、スーパーリゾリューションなどのゼロショットデータ編集にも対応します。consistencyモデルは、事前学習済みDiffusionモデルからの蒸留によって学習することも、完全に独立した生成モデルとして学習することも可能です。広範な実験を通じて、1ステップおよび少数ステップのサンプリングにおいて、既存のDiffusionモデル向け蒸留手法を上回ることを示しました。1ステップ生成において、CIFAR-10でFID 3.55、ImageNet 64x64で6.20という新たなSOTAを達成しています。独立して学習された場合、consistencyモデルは、CIFAR-10、ImageNet 64x64、LSUN 256x256といった標準ベンチマークにおいて、既存の1ステップ・非敵対的生成モデルを上回る性能を発揮する、新しい生成モデルファミリーとなります。* | |
| 元のコードベースは[openai/consistency_models](https://github.com/openai/consistency_models)で確認でき、追加のチェックポイントは[openai](https://huggingface.co/openai)で利用できます。 | |
| このパイプラインは、[dg845](https://github.com/dg845) と [ayushtues](https://huggingface.co/ayushtues) によって貢献されました。❤️ | |
| ## ヒント | |
| さらに高速化するために、`torch.compile` を使用して1秒未満で複数の画像を生成できます: | |
| ```diff | |
| import torch | |
| from diffusers import ConsistencyModelPipeline | |
| device = "cuda" # or "mps", "xpu", "cpu" | |
| # Load the cd_bedroom256_lpips checkpoint. | |
| model_id_or_path = "openai/diffusers-cd_bedroom256_lpips" | |
| pipe = ConsistencyModelPipeline.from_pretrained(model_id_or_path, dtype=torch.float16) | |
| pipe.to(device) | |
| + pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True) | |
| # Multistep sampling | |
| # Timesteps can be explicitly specified; the particular timesteps below are from the original GitHub repo: | |
| # https://github.com/openai/consistency_models/blob/main/scripts/launch.sh#L83 | |
| for _ in range(10): | |
| image = pipe(timesteps=[17, 0]).images[0] | |
| image.show() | |
| ``` | |
| ## ConsistencyModelPipeline[[diffusers.ConsistencyModelPipeline]] | |
| #### diffusers.ConsistencyModelPipeline[[diffusers.ConsistencyModelPipeline]] | |
| ```python | |
| diffusers.ConsistencyModelPipeline(unet: UNet2DModel, scheduler: CMStochasticIterativeScheduler) | |
| ``` | |
| [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/consistency_models/pipeline_consistency_models.py#L67) | |
| **パラメータ:** | |
| unet ([UNet2DModel](/docs/diffusers/main/ja/api/models/unet2d#diffusers.UNet2DModel)) : エンコードされた画像の潜在変数をノイズ除去するための`UNet2DModel`。 | |
| scheduler ([SchedulerMixin](/docs/diffusers/main/ja/api/schedulers/overview#diffusers.SchedulerMixin)) : `unet` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラ。現在、[CMStochasticIterativeScheduler](/docs/diffusers/main/ja/api/schedulers/cm_stochastic_iterative#diffusers.CMStochasticIterativeScheduler) のみ対応しています。 | |
| 無条件またはクラス条件付きの画像生成を行うPipelineです。 | |
| このモデルは [DiffusionPipeline](/docs/diffusers/main/ja/api/pipelines/overview#diffusers.DiffusionPipeline) を継承しています。すべてのパイプラインに実装されている汎用的なメソッド(ダウンロード、保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。 | |
| #### __call__[[diffusers.ConsistencyModelPipeline.__call__]] | |
| ```python | |
| __call__(batch_size: int = 1, class_labels: typing.Union[torch.Tensor, list[int], int, NoneType] = None, num_inference_steps: int = 1, timesteps: list[int] = None, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback: typing.Optional[typing.Callable[[int, int, torch.Tensor], NoneType]] = None, callback_steps: int = 1) | |
| ``` | |
| [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/consistency_models/pipeline_consistency_models.py#L171) | |
| **パラメータ:** | |
| batch_size (`int`、*任意*、デフォルトは 1) : 生成する画像の数。 | |
| class_labels (`torch.Tensor` または `list[int]` または `int`、*任意*) : クラス条件付き一致性モデルの条件付けに使用する任意のクラスラベルです。モデルがクラス条件付きでない場合は使用されません。 | |
| num_inference_steps (`int`、*optional*、デフォルトは 1) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。 | |
| timesteps (`list[int]`、*任意*) : デノイジングプロセスに使用するカスタムタイムステップ。未定義の場合、等間隔の`num_inference_steps`個のタイムステップが使用されます。降順で指定する必要があります。 | |
| generator (`torch.Generator`, *任意*) : 生成を決定論的にするための [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html)。 | |
| latents (`torch.Tensor`, *任意*) : 画像生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダム`generator`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。 | |
| output_type (`str`、*任意*、デフォルトは`"pil"`) : 生成された画像の出力形式。`PIL.Image`または`np.array`から選択します。 | |
| return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく、[ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#diffusers.ImagePipelineOutput)を返すかどうか。 | |
| callback (`Callable`、*任意*) : 推論中に`callback_steps`ステップごとに呼び出される関数です。この関数は、以下の引数とともに呼び出されます: `callback(step: int, timestep: int, latents: torch.Tensor)`。 | |
| callback_steps (`int`、*optional*、デフォルトは 1) : `callback` 関数が呼び出される頻度です。指定しない場合、callback はすべてのステップで呼び出されます。 | |
| **戻り値:** [ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#diffusers.ImagePipelineOutput) または `tuple` | |
| `return_dict` が `True` の場合、[ImagePipelineOutput](/docs/diffusers/main/ja/api/pipelines/consistency_models#diffusers.ImagePipelineOutput) が返され、それ以外の場合は `tuple` が返されます。このとき、最初の要素は生成された画像のリストです。 | |
| 例: | |
| ```py | |
| >>> import torch | |
| >>> from diffusers import ConsistencyModelPipeline | |
| >>> device = "cuda" | |
| >>> # Load the cd_imagenet64_l2 checkpoint. | |
| >>> model_id_or_path = "openai/diffusers-cd_imagenet64_l2" | |
| >>> pipe = ConsistencyModelPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16) | |
| >>> pipe.to(device) | |
| >>> # Onestep Sampling | |
| >>> image = pipe(num_inference_steps=1).images[0] | |
| >>> image.save("cd_imagenet64_l2_onestep_sample.png") | |
| >>> # Onestep sampling, class-conditional image generation | |
| >>> # ImageNet-64 class label 145 corresponds to king penguins | |
| >>> image = pipe(num_inference_steps=1, class_labels=145).images[0] | |
| >>> image.save("cd_imagenet64_l2_onestep_sample_penguin.png") | |
| >>> # Multistep sampling, class-conditional image generation | |
| >>> # Timesteps can be explicitly specified; the particular timesteps below are from the original GitHub repo: | |
| >>> # https://github.com/openai/consistency_models/blob/main/scripts/launch.sh#L77 | |
| >>> image = pipe(num_inference_steps=None, timesteps=[22, 0], class_labels=145).images[0] | |
| >>> image.save("cd_imagenet64_l2_multistep_sample_penguin.png") | |
| ``` | |
| ## ImagePipelineOutput[[diffusers.ImagePipelineOutput]] | |
| #### diffusers.ImagePipelineOutput[[diffusers.ImagePipelineOutput]] | |
| ```python | |
| diffusers.ImagePipelineOutput(images: list[PIL.Image.Image] | numpy.ndarray) | |
| ``` | |
| [ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L135) | |
| **パラメータ:** | |
| images (`List[PIL.Image.Image]` または `np.ndarray`) : 長さ `batch_size` のデノイズ済み PIL 画像のリスト、または形状 `(batch_size, height, width, num_channels)` の NumPy 配列。 | |
| 画像パイプライン用の出力クラス。 | |
Xet Storage Details
- Size:
- 9.9 kB
- Xet hash:
- f44bad7076e379b72f5c5799059db44436a0aa12ee32cb209e62fd790b0e7594
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.