Diffusers documentation
Bria 3.2
Bria 3.2
Bria 3.2는 차세대 상용화 가능한 텍스트-이미지 생성 모델입니다. 단 40억 개의 파라미터로 뛰어난 미적 품질과 텍스트 렌더링을 제공하며, 주요 오픈소스 모델과 동등한 결과를 내는 것으로 평가받고 있고, 다른 라이선스 기반 모델보다 우수한 성능을 보입니다. 전적으로 라이선스된 데이터로 구축된 것 외에도, 3.2는 엔터프라이즈 및 상업적 사용에 다음과 같은 여러 이점을 제공합니다:
- Efficient Compute - 해당 모델은 시장에서 동등한 모델보다 X3배 더 작습니다(다른 오픈 소스 모델의 12B 파라미터 대비 4B 파라미터)
- Architecture Consistency: 3.1과 동일한 아키텍처—중단 없이 업그레이드를 원하는 사용자에게 이상적입니다.
- Fine-tuning 속도 향상: L40S 및 A100에서 2배 빠른 fine-tuning.
Bria 3.2의 원본 모델 체크포인트는 여기에서 찾을 수 있습니다. Bria 3.2의 Github 저장소는 여기에서 찾을 수 있습니다.
Bria 플랫폼에 대해 더 자세히 알고 싶으시거나 무료 트라이얼 액세스를 원하시면 bria.ai를 방문하세요.
사용
모델이 게이트가 설정되어 있으므로, diffusers와 함께 사용하기 전에 먼저 Bria 3.2 Hugging Face 페이지로 이동하여 양식을 작성하고 게이트를 수락해야 합니다. 접근 권한이 부여된 후에는 시스템이 게이트 수락을 인식할 수 있도록 로그인해야 합니다.
아래 명령을 사용하여 로그인하세요:
hf auth login
BriaPipeline
class diffusers.BriaPipeline
< source >( 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) — 인코딩된 이미지 latents의 노이즈를 제거하기 위한 조건부 Transformer (MMDiT) 아키텍처.
- scheduler (FlowMatchEulerDiscreteScheduler) —
transformer와 함께 사용하여 인코딩된 이미지 latents의 노이즈를 제거하는 데 사용되는 스케줄러. - vae (AutoencoderKL) — 이미지를 잠재 표현으로 인코딩하고 디코딩하는 Variational Auto-Encoder (VAE) 모델.
- text_encoder (
T5EncoderModel) — 동결된 텍스트 인코더. Bria는 T5, 구체적으로 t5-v1_1-xxl 변형을 사용합니다. - tokenizer (
T5TokenizerFast) — T5Tokenizer 클래스의 토크나이저.
여러 가지 변경 사항이 적용된 FluxPipeline 기반:
- 풀링된 임베딩 없음
- 프롬프트에는 zero padding을 사용합니다
- 이것은 증류된 버전이 아니므로 guidance embedding이 없습니다
__call__
< source >( 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인수를 지원하는 스케줄러의 디노이징 과정에 사용할 커스텀 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입니다. guidance_scale은 Imagen Paper의 방정식 2의 w로 정의됩니다. guidance_scale > 1로 설정하면 Guidance scale이 활성화됩니다. Guidance scale이 높을수록 prompt와 밀접하게 연결된 이미지를 생성하도록 장려하지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다.
negative_prompt ( str 또는 list[str], 선택 사항):
Classifier-Free Diffusion Guidance에서 정의된 Guidance scale입니다. guidance_scale은 Imagen Paper의 2번 식의 w로 정의됩니다. guidance_scale > 1로 설정하면 Guidance scale이 활성화됩니다. Guidance scale이 높을수록 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 generator입니다. latents (torch.FloatTensor, 선택 사항): 가우시안 분포에서 샘플링하여 이미지 생성의 입력으로 사용할 사전 생성된 노이즈 latents입니다. 다른 프롬프트로 동일한 생성을 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 무작위generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다. prompt_embeds (torch.FloatTensor, 선택 사항): 사전 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 사용할 수 있습니다. 제공되지 않으면,prompt입력 인자로부터 텍스트 임베딩이 생성됩니다. negative_prompt_embeds (torch.FloatTensor, 선택 사항): 사전 생성된 부정 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 사용할 수 있습니다. 제공되지 않으면, negative_prompt_embeds가negative_prompt입력 인자로부터 생성됩니다. 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
< source >( 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 device - num_images_per_prompt (
int) — 프롬프트당 생성할 이미지 수 - 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, optional) — 미리 생성된 부정 텍스트 임베딩입니다. 프롬프트 가중치와 같은 텍스트 입력을 쉽게 조정하는 데 사용할 수 있습니다. e.g. 제공되지 않으면negative_prompt입력 인수에서 negative_prompt_embeds가 생성됩니다.