Diffusers documentation

Bria 3.2

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Bria 3.2

Bria 3.2 は、次世代の商用対応テキスト・トゥ・イメージモデルです。わずか40億パラメータながら、卓越した美観とテキストレンダリングを実現しており、評価では主要なオープンソースモデルと同等の結果を示し、他のライセンス付きモデルを上回る性能を発揮します。 完全にライセンス付きデータで構築されていることに加え、3.2 はエンタープライズおよび商用利用において以下の利点を提供します:

  • Efficient Compute - 本モデルは、市場の同等モデル(他のオープンソースモデルの12Bパラメータに対し、4Bパラメータ)と比較して、サイズがX分の1に小型化されています。
  • アーキテクチャの整合性: 3.1 と同じアーキテクチャを採用しており、中断なしでアップグレードしたいユーザーに最適です。
  • ファインチューニングの高速化: L40SおよびA100でのファインチューニングが2倍速くなります。

Bria 3.2の元のモデルチェックポイントはこちらで確認できます。 Bria 3.2のGithubリポジトリはこちらで確認できます。

Briaプラットフォームについてさらに詳しく知りたい場合や、無料のトライアルアクセスを取得したい場合は、bria.aiをご覧ください。

使用方法

このモデルはゲート付きであるため、diffusers で使用する前に、まず Bria 3.2 の Hugging Face ページ にアクセスしてフォームに記入し、ゲートの承認が必要です。承認が完了したら、システムがゲートの承認済みであることを認識できるよう、ログインしてください。

以下のコマンドを使用してログインします:

hf auth login

BriaPipeline

class diffusers.BriaPipeline

< >

( transformer: BriaTransformer2DModelscheduler: diffusers.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler | diffusers.schedulers.scheduling_utils.KarrasDiffusionSchedulersvae: AutoencoderKLtext_encoder: T5EncoderModeltokenizer: T5Tokenizerimage_encoder: CLIPVisionModelWithProjection = Nonefeature_extractor: CLIPImageProcessorPil = None )

パラメータ

  • transformer (BriaTransformer2DModel) — エンコードされた画像潜在変数からノイズを除去するための、条件付き Transformer (MMDiT) アーキテクチャ。
  • scheduler (FlowMatchEulerDiscreteScheduler) — transformer と組み合わせて、エンコードされた画像の潜在変数からノイズを除去するために使用するスケジューラ。
  • vae (AutoencoderKL) — 画像を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ (VAE) モデル。
  • text_encoder (T5EncoderModel) — 凍結されたテキストエンコーダー。Bria は T5、具体的には t5-v1_1-xxl バリアントを使用しています。
  • tokenizer (T5TokenizerFast) — T5Tokenizer クラスのトークナイザー。

いくつかの変更を加えたFluxPipelineをベースにしています:

  • プールの埋め込みはありません
  • プロンプトにはゼロパディングを使用します
  • これは蒸留版ではないため、ガイダンス埋め込みはありません

__call__

< >

( prompt: str | list[str] = Noneheight: int | None = Nonewidth: int | None = Nonenum_inference_steps: int = 30timesteps: list = Noneguidance_scale: float = 5negative_prompt: str | list[str] | None = Nonenum_images_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.FloatTensor] = Noneprompt_embeds: typing.Optional[torch.FloatTensor] = Nonenegative_prompt_embeds: typing.Optional[torch.FloatTensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 128clip_value: None | float = Nonenormalize: bool = False ) → ~pipelines.bria.BriaPipelineOutput or tuple

パラメータ

  • prompt (str または list[str]、省略可) — 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに prompt_embeds を渡す必要があります。
  • height (int、任意、デフォルトは self.unet.config.sample_size * self.vae_scale_factor)— 生成される画像のピクセル単位の縦幅です。最適な結果を得るため、デフォルトでは 1024 に設定されています。
  • width (int、任意、デフォルトは self.unet.config.sample_size * self.vae_scale_factor)— 生成される画像の幅(ピクセル単位)です。最適な結果を得るため、デフォルトでは 1024 に設定されています。
  • num_inference_steps (int、任意、デフォルト値は 50)— デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。
  • timesteps (list[int], 任意) — set_timesteps メソッドで timesteps 引数を受け付けるスケジューラーにおいて、デノイジングプロセスに使用するカスタムタイムステップ。未定義の場合、num_inference_steps が渡された際のデフォルトの動作が使用されます。降順で指定する必要があります。
  • guidance_scale (float、省略可、デフォルト値は 5.0) —

戻り値

~pipelines.bria.BriaPipelineOutput または tuple

return_dictがTrueの場合、~pipelines.bria.BriaPipelineOutput、それ以外の場合はtupleを返します。tupleを返す場合、最初の要素は生成された画像のリストです。

生成用のパイプラインを呼び出したときに実行される関数。

<<<<<<< HEAD Classifier-Free Diffusion Guidance で定義されているガイダンススケール。guidance_scale は、Imagen Paper の式 2 の w として定義されています。guidance_scale > 1 を設定することで、ガイダンススケールが有効になります。ガイダンススケールを高くすると、prompt のテキストと密接に関連する画像の生成が促されますが、通常は画像の品質が低下する傾向があります。

negative_prompt ( str or list[str] , 省略可 ):

Classifier-Free Diffusion Guidance で定義されているガイダンススケール。guidance_scale は、Imagen Paper の式 2 の w として定義されています。guidance_scale > 1 を設定することで、ガイダンススケールが有効になります。ガイダンススケールを高くすると、prompt のテキストと密接に関連する画像の生成が促されますが、通常は画像の品質が低下する傾向があります。 negative_prompt (str または list[str]、任意):

main 画像生成をガイドしないプロンプト、またはプロンプトのリストです。定義されていない場合、代わりにnegative_prompt_embedsを渡す必要があります。ガイダンスを使用していない場合は無視されます(つまり、guidance_scaleが1未満の場合は無視されます)。 num_images_per_prompt (int、任意、デフォルトは 1): 各プロンプトごとに生成する画像の数です。 generator (torch.Generatorまたはlist[torch.Generator]、任意): 生成を決定論的にするために使用するtorch ジェネレーター、またはそのリストです。 latents (torch.FloatTensor、任意): ガウス分布からサンプリングされた、画像生成の入力として使用する事前生成されたノイズ付き潜在変数です。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、提供されたランダムgeneratorを使用してサンプリングを行い、潜在変数テンソルが生成されます。 prompt_embeds (torch.FloatTensor、任意): 事前生成されたテキスト埋め込みです。テキスト入力の調整、例プロンプトの重み付けなどに簡単に使用できます。指定されない場合、prompt入力引数からテキスト埋め込みが生成されます。 negative_prompt_embeds (torch.FloatTensor、任意): 事前生成されたネガティブなテキスト埋め込みです。テキスト入力の調整、例プロンプトの重み付けなどに簡単に使用できます。指定されない場合、negative_prompt入力引数からnegative_prompt_embedsが生成されます。 output_type (str、任意、デフォルトは"pil"): 生成画像の出力形式です。PIL: PIL.Image.Imageまたはnp.arrayから選択します。 return_dict (bool、任意、デフォルトはTrue): プレーンなタプルではなく~pipelines.bria.BriaPipelineOutputを返すかどうかです。 attention_kwargs (dict、任意): 指定された場合、diffusers.models.attention_processorのself.processorで定義されているAttentionProcessorに渡されるkwargs辞書です。 callback_on_step_end (Callable、任意): 推論中の各デノイジングステップの終了時に呼び出される関数です。この関数は、以下の引数とともに呼び出されます: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)。 callback_kwargsには、callback_on_step_end_tensor_inputsで指定されたすべてのテンソルのリストが含まれます。 callback_on_step_end_tensor_inputs (list、任意): callback_on_step_end関数のためのテンソル入力のリストです。リストで指定されたテンソルはcallback_kwargs引数として渡されます。パイプラインクラスの._callback_tensor_inputs属性にリストされている変数のみを含めることができます。 max_sequence_length (int、デフォルトは 256): promptで使用される最大シーケンス長です。 clip_value (float、任意): 設定された場合、予測ノイズは各デノイジングステップで[-clip_value, clip_value]の範囲にクリップされます。 normalize (bool、任意、デフォルトはFalse): 各デノイジングステップで予測ノイズを正規化するかどうかです。

例:

>>> import torch
>>> from diffusers import BriaPipeline

>>> pipe = BriaPipeline.from_pretrained("briaai/BRIA-3.2", torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")
# BRIA's T5 text encoder is sensitive to precision. We need to cast it to bfloat16 and keep the final layer in float32.

>>> pipe.text_encoder = pipe.text_encoder.to(dtype=torch.bfloat16)
>>> for block in pipe.text_encoder.encoder.block:
...     block.layer[-1].DenseReluDense.wo.to(dtype=torch.float32)
# BRIA's VAE is not supported in mixed precision, so we use float32.

>>> if pipe.vae.config.shift_factor == 0:
...     pipe.vae.to(dtype=torch.float32)

>>> prompt = "Photorealistic food photography of a stack of fluffy pancakes on a white plate, with maple syrup being poured over them. On top of the pancakes are the words 'BRIA 3.2' in bold, yellow, 3D letters. The background is dark and out of focus."
>>> image = pipe(prompt).images[0]
>>> image.save("bria.png")

encode_prompt

< >

( prompt: str | list[str]device: typing.Optional[torch.device] = Nonenum_images_per_prompt: int = 1do_classifier_free_guidance: bool = Truenegative_prompt: str | list[str] | None = Noneprompt_embeds: typing.Optional[torch.FloatTensor] = Nonenegative_prompt_embeds: typing.Optional[torch.FloatTensor] = Nonemax_sequence_length: int = 128lora_scale: float | None = None )

パラメータ

  • prompt (str または list[str]、省略可能) — エンコードするプロンプト
  • device — (torch.device): torch デバイス
  • num_images_per_prompt (int) — 1つのプロンプトに対して生成する画像の数
  • do_classifier_free_guidance (bool) — classifier free guidance を使用するかどうか
  • negative_prompt (str または list[str]、省略可) — 画像生成をガイドしないプロンプトです。未定義の場合、代わりに negative_prompt_embeds を渡す必要があります。ガイダンスを使用していない場合は無視されます(guidance_scale が 1 未満の場合は無視されます)。
  • prompt_embeds (torch.FloatTensor, 任意) — 事前に生成されたテキスト埋め込み。テキスト入力の調整、例えばプロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、prompt 入力引数からテキスト埋め込みが生成されます。
  • negative_prompt_embeds (torch.FloatTensor, 任意) — 事前に生成されたネガティブなテキスト埋め込みです。テキスト入力の調整、例えばプロンプトの重み付けなどを簡単に実行できます。指定されない場合、negative_prompt 入力引数から negative_prompt_embeds が生成されます。
Update on GitHub