Diffusers documentation

Bria Fibo

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 Fibo

文本到图像模型已经掌握了想象力——但尚未掌握控制力。FIBO 改变了这一现状。

FIBO 基于结构化 JSON 描述进行训练,这些描述的长度可达 1,000 个词以上。该模型旨在理解和控制不同的视觉参数,例如光照、构图、色彩和相机设置,从而实现精确且可复现的输出。

FIBO 仅拥有 80 亿参数,却提供了全新的图像质量、提示词遵循度以及专业控制水平。

FIBO is trained exclusively on a structured prompt and will not work with freeform text prompts. you can use the FIBO-VLM-prompt-to-JSON model or the FIBO-gemini-prompt-to-JSON to convert your freeform text prompt to a structured JSON prompt.

避免在 FIBO 中直接使用自由文本提示,因为这无法产生最佳效果。

请参阅 Bria Fibo 的 Hugging Face 页面以了解更多信息。

用法

由于该模型受访问限制,在使用 diffusers 之前,您需要先前往 Bria Fibo Hugging Face 页面,填写表单并接受访问限制。进入后,您需要登录,以便系统确认您已接受该访问限制。

使用以下命令登录:

hf auth login

BriaFiboPipeline

class diffusers.BriaFiboPipeline

< >

( transformer: BriaFiboTransformer2DModelscheduler: diffusers.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler | diffusers.schedulers.scheduling_utils.KarrasDiffusionSchedulersvae: AutoencoderKLWantext_encoder: SmolLM3ForCausalLMtokenizer: AutoTokenizer )

参数

  • transformer (BriaFiboTransformer2DModel) — 用于 2D 扩散建模的 transformer 模型。
  • scheduler(FlowMatchEulerDiscreteScheduler 或 KarrasDiffusionSchedulers)— 与 transformer 配合使用,用于对编码后的潜变量进行去噪的调度器。
  • vae (AutoencoderKLWan) — 用于将图像编码为潜在表示并从中解码的变分自编码器。
  • text_encoder (SmolLM3ForCausalLM) — 用于处理输入提示的文本编码器。
  • tokenizer (AutoTokenizer) — 用于处理输入文本提示词以提供给 text_encoder 的 Tokenizer。

__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] = Noneoutput_type: str | None = 'pil'return_dict: bool = Truejoint_attention_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 = 3000do_patching = False ) → ~pipelines.flux.BriaFiboPipelineOutput or tuple

参数

  • prompt (str 或 list[str]) — 用于引导图像生成的提示词或提示词列表。
  • 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], 可选) — 用于支持 timesteps 参数的调度器去噪过程的自定义时间步,该参数位于其 set_timesteps 方法中。如果未定义,则使用传入 num_inference_steps 时的默认行为。必须按降序排列。
  • guidance_scale (float,可选,默认值为 5.0) — Classifier-Free Diffusion Guidance 中定义的引导尺度。guidance_scale 定义为 Imagen Paper 中公式 2 的 w。通过设置 guidance_scale > 1 来启用引导尺度。较高的引导尺度会促使生成与文本 prompt 紧密关联的图像,通常以牺牲图像质量为代价。
  • negative_prompt (str 或 list[str],可选) — 用于引导图像生成的反向提示词。当未使用引导时将被忽略(即当 guidance_scale 小于 1 时忽略)。
  • num_images_per_prompt (int,可选,默认为 1) — 每个提示词生成的图像数量。
  • generator (torch.Generator 或 list[torch.Generator],可选) — 一个或一组 torch 生成器,用于使生成过程具有确定性。
  • latents (torch.FloatTensor, 可选) — 预先生成的噪声潜变量,从高斯分布中采样,用作图像生成的输入。可用于使用不同的提示词对同一生成过程进行微调。如果未提供,将通过使用提供的随机generator进行采样来生成一个潜变量张量。
  • output_type (str,可选,默认为 "pil") — 生成图像的输出格式。可选值为 PIL:PIL.Image.Image 或 np.array。
  • return_dict (bool,可选,默认为 True) — 是否返回 ~pipelines.stable_diffusion_xl.StableDiffusionXLPipelineOutput 而不是普通元组。
  • joint_attention_kwargs (dict, 可选) — 一个 kwargs 字典,如果指定,将作为参数传递给 diffusers.models.attention_processor 中 self.processor 下定义的 AttentionProcessor。
  • 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,默认为 3000)— 与 prompt 配合使用的最大序列长度。
  • do_patching (bool,可选,默认为 False) — 是否使用 patching。

返回值

~pipelines.flux.BriaFiboPipelineOutput 或 tuple

如果 return_dict 为 True,则返回 ~pipelines.flux.BriaFiboPipelineOutput,否则返回 tuple。当返回元组时,第一个元素是一个包含生成图像的列表。

调用生成 pipeline 时调用的函数。

示例:

import torch
from diffusers import BriaFiboPipeline
from diffusers.modular_pipelines import ModularPipeline

torch.set_grad_enabled(False)
vlm_pipe = ModularPipeline.from_pretrained("briaai/FIBO-VLM-prompt-to-JSON", trust_remote_code=True)

pipe = BriaFiboPipeline.from_pretrained(
    "briaai/FIBO",
    trust_remote_code=True,
    torch_dtype=torch.bfloat16,
)
pipe.enable_model_cpu_offload()

with torch.inference_mode():
    # 1. Create a prompt to generate an initial image
    output = vlm_pipe(prompt="a beautiful dog")
    json_prompt_generate = output.values["json_prompt"]

    # Generate the image from the structured json prompt
    results_generate = pipe(prompt=json_prompt_generate, num_inference_steps=50, guidance_scale=5)
    results_generate.images[0].save("image_generate.png")

encode_prompt

< >

( prompt: str | list[str]device: typing.Optional[torch.device] = Nonenum_images_per_prompt: int = 1guidance_scale: float = 5negative_prompt: str | list[str] | None = Nonemax_sequence_length: int = 3000lora_scale: float | None = None )

参数

  • prompt (str 或 list[str],可选) — 要编码的提示
  • device — (torch.device): torch 设备
  • num_images_per_prompt (int) — 每个提示词应生成的图像数量
  • guidance_scale (float) — 无分类器引导的引导尺度。
  • negative_prompt (str 或 list[str],可选) — 用于引导图像生成的反向提示词。当未使用引导时将被忽略(即当 guidance_scale 小于 1 时忽略)。
Update on GitHub