Buckets:
Bria 3.2
Bria 3.2 is the next-generation commercial-ready text-to-image model. With just 4 billion parameters, it provides exceptional aesthetics and text rendering, evaluated to provide on par results to leading open-source models, and outperforming other licensed models. In addition to being built entirely on licensed data, 3.2 provides several advantages for enterprise and commercial use:
- Efficient Compute - the model is X3 smaller than the equivalent models in the market (4B parameters vs 12B parameters other open source models)
- Architecture Consistency: Same architecture as 3.1—ideal for users looking to upgrade without disruption.
- Fine-tuning Speedup: 2x faster fine-tuning on L40S and A100.
Original model checkpoints for Bria 3.2 can be found here. Github repo for Bria 3.2 can be found here.
If you want to learn more about the Bria platform, and get free traril access, please visit bria.ai.
Usage
As the model is gated, before using it with diffusers you first need to go to the Bria 3.2 Hugging Face page, fill in the form and accept the gate. Once you are in, you need to login so that your system knows you’ve accepted the gate.
Use the command below to log in:
hf auth login
BriaPipeline[[diffusers.BriaPipeline]]
diffusers.BriaPipeline[[diffusers.BriaPipeline]]
Based on FluxPipeline with several changes:
- no pooled embeddings
- We use zero padding for prompts
- No guidance embedding since this is not a distilled version
__call__diffusers.BriaPipeline.__call__https://github.com/huggingface/diffusers/blob/vr_12652/src/diffusers/pipelines/bria/pipeline_bria.py#L448[{"name": "prompt", "val": ": str | list[str] = None"}, {"name": "height", "val": ": int | None = None"}, {"name": "width", "val": ": int | None = None"}, {"name": "num_inference_steps", "val": ": int = 30"}, {"name": "timesteps", "val": ": list = None"}, {"name": "guidance_scale", "val": ": float = 5"}, {"name": "negative_prompt", "val": ": str | list[str] | None = None"}, {"name": "num_images_per_prompt", "val": ": int | None = 1"}, {"name": "generator", "val": ": torch._C.Generator | list[torch._C.Generator] | None = None"}, {"name": "latents", "val": ": torch.FloatTensor | None = None"}, {"name": "prompt_embeds", "val": ": torch.FloatTensor | None = None"}, {"name": "negative_prompt_embeds", "val": ": torch.FloatTensor | None = None"}, {"name": "output_type", "val": ": str | None = 'pil'"}, {"name": "return_dict", "val": ": bool = True"}, {"name": "attention_kwargs", "val": ": dict[str, typing.Any] | None = None"}, {"name": "callback_on_step_end", "val": ": typing.Optional[typing.Callable[[int, int], NoneType]] = None"}, {"name": "callback_on_step_end_tensor_inputs", "val": ": list = ['latents']"}, {"name": "max_sequence_length", "val": ": int = 128"}, {"name": "clip_value", "val": ": None | float = None"}, {"name": "normalize", "val": ": bool = False"}]- prompt (str or list[str], optional) --
The prompt or prompts to guide the image generation. If not defined, one has to pass
prompt_embeds. instead.
- height (
int, optional, defaults to self.unet.config.sample_size * self.vae_scale_factor) -- The height in pixels of the generated image. This is set to 1024 by default for the best results. - width (
int, optional, defaults to self.unet.config.sample_size * self.vae_scale_factor) -- The width in pixels of the generated image. This is set to 1024 by default for the best results. - num_inference_steps (
int, optional, defaults to 50) -- The number of denoising steps. More denoising steps usually lead to a higher quality image at the expense of slower inference. - timesteps (
list[int], optional) -- Custom timesteps to use for the denoising process with schedulers which support atimestepsargument in theirset_timestepsmethod. If not defined, the default behavior whennum_inference_stepsis passed will be used. Must be in descending order. - guidance_scale (
float, optional, defaults to 5.0) --0~pipelines.bria.BriaPipelineOutputortuple``~pipelines.bria.BriaPipelineOutputifreturn_dictis True, otherwise atuple. When returning a tuple, the first element is a list with the generated images.
Function invoked when calling the pipeline for generation.
1. Higher guidance scale encourages to generate images that are closely linked to the text prompt, usually at the expense of lower image quality. negative_prompt (strorlist[str]`, optional):
Guidance scale as defined in Classifier-Free Diffusion
Guidance. guidance_scale is defined as w of
equation 2. of Imagen Paper. Guidance scale is
enabled by setting guidance_scale > 1. Higher guidance scale encourages to generate images
that are closely linked to the text prompt, usually at the expense of lower image quality.
negative_prompt (str or list[str], optional):
main The prompt or prompts not to guide the image generation. If not defined, one has to pass
negative_prompt_embedsinstead. Ignored when not using guidance (i.e., ignored ifguidance_scaleis less than1). num_images_per_prompt (int, optional, defaults to 1): The number of images to generate per prompt. generator (torch.Generatororlist[torch.Generator], optional): One or a list of torch generator(s) to make generation deterministic. latents (torch.FloatTensor, optional): Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image generation. Can be used to tweak the same generation with different prompts. If not provided, a latents tensor will be generated by sampling using the supplied randomgenerator. prompt_embeds (torch.FloatTensor, optional): Pre-generated text embeddings. Can be used to easily tweak text inputs, e.g. prompt weighting. If not provided, text embeddings will be generated frompromptinput argument. negative_prompt_embeds (torch.FloatTensor, optional): Pre-generated negative text embeddings. Can be used to easily tweak text inputs, e.g. prompt weighting. If not provided, negative_prompt_embeds will be generated fromnegative_promptinput argument. output_type (str, optional, defaults to"pil"): The output format of the generate image. Choose between PIL:PIL.Image.Imageornp.array. return_dict (bool, optional, defaults toTrue): Whether or not to return a~pipelines.bria.BriaPipelineOutputinstead of a plain tuple. attention_kwargs (dict, optional): A kwargs dictionary that if specified is passed along to theAttentionProcessoras defined underself.processorin diffusers.models.attention_processor. callback_on_step_end (Callable, optional): A function that calls at the end of each denoising steps during the inference. The function is called with the following arguments:callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict).callback_kwargswill include a list of all tensors as specified bycallback_on_step_end_tensor_inputs. callback_on_step_end_tensor_inputs (list, optional): The list of tensor inputs for thecallback_on_step_endfunction. The tensors specified in the list will be passed ascallback_kwargsargument. You will only be able to include variables listed in the._callback_tensor_inputsattribute of your pipeline class. max_sequence_length (intdefaults to 256): Maximum sequence length to use with theprompt.
Examples:
>>> 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")
Parameters:
transformer (BriaTransformer2DModel) : Conditional Transformer (MMDiT) architecture to denoise the encoded image latents.
scheduler (FlowMatchEulerDiscreteScheduler) : A scheduler to be used in combination with transformer to denoise the encoded image latents.
vae (AutoencoderKL) : Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
text_encoder (T5EncoderModel) : Frozen text-encoder. Bria uses T5, specifically the t5-v1_1-xxl variant.
tokenizer (T5TokenizerFast) : Tokenizer of class T5Tokenizer.
Returns:
~pipelines.bria.BriaPipelineOutput` or `tuple
~pipelines.bria.BriaPipelineOutput if
return_dict is True, otherwise a tuple. When returning a tuple, the first element is a list
with the generated images.
encode_prompt[[diffusers.BriaPipeline.encode_prompt]]
Parameters:
prompt (str or list[str], optional) : prompt to be encoded
device : (torch.device): torch device
num_images_per_prompt (int) : number of images that should be generated per prompt
do_classifier_free_guidance (bool) : whether to use classifier free guidance or not
negative_prompt (str or list[str], optional) : The prompt or prompts not to guide the image generation. If not defined, one has to pass negative_prompt_embeds instead. Ignored when not using guidance (i.e., ignored if guidance_scale is less than 1).
prompt_embeds (torch.FloatTensor, optional) : Pre-generated text embeddings. Can be used to easily tweak text inputs, e.g. prompt weighting. If not provided, text embeddings will be generated from prompt input argument.
negative_prompt_embeds (torch.FloatTensor, optional) : Pre-generated negative text embeddings. Can be used to easily tweak text inputs, e.g. prompt weighting. If not provided, negative_prompt_embeds will be generated from negative_prompt input argument.
Xet Storage Details
- Size:
- 11.5 kB
- Xet hash:
- 26f440dc75be62f1e1a890852f26cc99611dfbae11eacc7d35401dd91fbb6662
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.