Diffusers documentation
PRX Pixel
PRX Pixel
PRXPixel 是 Photoroom 推出的像素空间文本生成图像模型。一个约 7B 参数的 PRXTransformer2DModel 直接对原始 RGB 图像进行去噪——无需 VAE。该模型以 Qwen3-VL 文本编码器作为条件,并采用 flow matching,其中 transformer 在每一步预测干净图像(x-prediction)。生成分辨率会被输入到时间步调制中,使模型能够感知目标尺寸。
可用模型
| 模型 | 分辨率 | 描述 | 建议参数 | 推荐的 dtype |
|---|---|---|---|---|
Photoroom/prxpixel-t2i | 1024 | 采用 Qwen3-VL 文本编码器的像素空间 ~7B 模型 | 28 步,cfg=5.0 | torch.bfloat16 |
加载 pipeline
PRXPixelPipeline 需要 transformers >= 4.57(即引入 Qwen3VLTextModel 的版本)。请使用 from_pretrained() 加载:
import torch
from diffusers import PRXPixelPipeline
pipe = PRXPixelPipeline.from_pretrained("Photoroom/prxpixel-t2i", dtype=torch.bfloat16)
pipe.to("cuda") # or "mps", "xpu", "cpu"
prompt = "A front-facing portrait of a lion in the golden savanna at sunset."
image = pipe(prompt, num_inference_steps=28, guidance_scale=5.0).images[0]
image.save("prxpixel_output.png")内存优化
对于内存受限的环境:
import torch
from diffusers import PRXPixelPipeline
pipe = PRXPixelPipeline.from_pretrained("Photoroom/prxpixel-t2i", dtype=torch.bfloat16)
pipe.enable_model_cpu_offload()
# Or use sequential CPU offload for even lower memory
pipe.enable_sequential_cpu_offload()PRXPixelPipeline
class diffusers.PRXPixelPipeline
< source >( transformer: PRXTransformer2DModelscheduler: FlowMatchEulerDiscreteSchedulertext_encoder: PreTrainedModeltokenizer: transformers.models.auto.tokenization_auto.AutoTokenizer | transformers.tokenization_utils_base.PreTrainedTokenizerBasedefault_sample_size: int | None = 1024prompt_max_tokens: int = 256noise_scale: float = 2.0 )
参数
- transformer (
PRXTransformer2DModel) — 约 70 亿参数的 PRX 去噪器。对于 PRXPixel,该模型以in_channels=3构建,包含一个瓶颈层img_in,并设置resolution_embeds=True,其训练目标是预测干净图像x0。 - scheduler (FlowMatchEulerDiscreteScheduler) — 用于对(像素空间)潜变量进行去噪的 Flow-matching 调度器。
- text_encoder (
PreTrainedModel) — 用于编码提示词的 Qwen3-VL 文本主干(视觉塔将被丢弃)。必须返回last_hidden_state。 - tokenizer (
PreTrainedTokenizerBase) —text_encoder的分词器(通常通过AutoTokenizer加载)。 - default_sample_size (
int,可选,默认为 1024) — 当未向__call__提供高度/宽度时使用的默认高度/宽度。 - prompt_max_tokens (
int,可选,默认为 256) — 在编码之前,提示词被填充或截断到的文本 token 数量。 - noise_scale (
float,可选,默认值为 2.0) — 应用于初始高斯噪声的缩放系数。PRXPixel 使用非单位初始噪声尺度进行训练,因此采样必须从randn * noise_scale开始。
用于使用 PRXPixel 模型进行文本到图像生成的 Pipeline。
PRXPixel 是一个独立的像素空间文生图流水线。它直接使用约 70 亿参数的 PRXTransformer2DModel 对原始 RGB 进行去噪,且不包含 VAE(生成过程完全在像素空间中进行,因此去噪后的输出就是图像)。提示词通过 Qwen3-VL 文本编码器进行编码(视觉塔会被丢弃)。与 PRXPipeline 不同,该 Transformer 采用 x-prediction 进行训练:在每一步中,它预测干净图像 x0,然后将其转换为 flow-matching 速度,再执行调度器步骤。采样从 randn * noise_scale 开始(默认 noise_scale=2.0),默认分辨率为 1024px。
该模型继承自 DiffusionPipeline。有关该库为所有流水线实现的通用方法(例如下载或保存、在特定设备上运行等),请参阅父类文档。
示例:
>>> import torch
>>> from diffusers import PRXPixelPipeline
>>> pipe = PRXPixelPipeline.from_pretrained("Photoroom/prxpixel-t2i", torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")
>>> prompt = "A front-facing portrait of a lion in the golden savanna at sunset."
>>> image = pipe(prompt, num_inference_steps=28, guidance_scale=5.0).images[0]
>>> image.save("prxpixel_output.png")__call__
< source >( prompt: str | list[str] = Nonenegative_prompt: str = ''height: int | None = Nonewidth: int | None = Nonenum_inference_steps: int = 28timesteps: list = Noneguidance_scale: float = 4.0num_images_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.FloatTensor] = Nonenegative_prompt_embeds: typing.Optional[torch.FloatTensor] = Noneprompt_attention_mask: typing.Optional[torch.BoolTensor] = Nonenegative_prompt_attention_mask: typing.Optional[torch.BoolTensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueuse_resolution_binning: bool = Truecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents'] ) → PRXPipelineOutput or tuple
参数
- prompt (
str或list[str],可选) — 用于引导图像生成的提示词或提示词列表。如果未定义,则必须改为传入prompt_embeds。 - negative_prompt (
str,可选,默认为"") — 用于引导图像生成的负面提示词。当未使用引导时会被忽略(即当guidance_scale小于1时会被忽略)。 - height (
int,可选,默认为default_sample_size) — 生成图像的高度(以像素为单位)。 - width (
int,可选,默认为default_sample_size) — 生成图像的宽度(以像素为单位)。 - num_inference_steps (
int,可选,默认为 28) — 去噪步数。更多的去噪步数通常能生成更高质量的图像,但推理速度会更慢。 - timesteps (
list[int], 可选) — 用于支持timesteps参数的调度器去噪过程的自定义时间步,该参数位于其set_timesteps方法中。如果未定义,则使用传入num_inference_steps时的默认行为。必须按降序排列。 - guidance_scale (
float,可选,默认为 4.0) — Classifier-Free Diffusion Guidance 中定义的引导尺度。guidance_scale定义为 Imagen Paper 中公式 2 的w。通过设置guidance_scale > 1来启用引导尺度。较高的引导尺度会促使生成与文本prompt紧密关联的图像,通常以牺牲图像质量为代价。 - num_images_per_prompt (
int,可选,默认为 1) — 每个提示词生成的图像数量。 - generator (
torch.Generator或list[torch.Generator],可选) — 一个或一组 torch 生成器,用于使生成过程具有确定性。 - latents (
torch.Tensor, 可选) — 预先生成的噪声潜变量,从高斯分布中采样得到,用作图像生成的输入。可用于使用不同的提示词对同一生成过程进行微调。如果未提供,将通过使用提供的随机generator进行采样来生成一个潜变量张量。 - prompt_embeds (
torch.FloatTensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入,例如 提示词加权。如果未提供,文本嵌入将从prompt输入参数生成。 - negative_prompt_embeds (
torch.FloatTensor, 可选) — 预生成的负向文本嵌入。可用于轻松调整文本输入,例如 提示词权重。如果未提供且guidance_scale > 1,将从空字符串生成负向嵌入。 - prompt_attention_mask (
torch.BoolTensor, 可选) —prompt_embeds的预生成注意力掩码。如果未提供,则会根据prompt输入参数生成注意力掩码。 - negative_prompt_attention_mask (
torch.BoolTensor, 可选) —negative_prompt_embeds的预生成注意力掩码。如果未提供且guidance_scale > 1, 注意力掩码将从空字符串生成。 - output_type (
str,可选,默认为"pil") — 生成图像的输出格式。可选值为 PIL:PIL.Image.Image或np.array。 - return_dict (
bool,可选,默认为True) — 是否返回 PRXPipelineOutput 而不是普通元组。 - use_resolution_binning (
bool,可选,默认为True) — 如果设置为True,请求的高度和宽度会先通过预定义的宽高比分箱映射到最接近的分辨率。在生成的潜在变量解码为图像后,它们会被重新调整回请求的分辨率。适用于以最佳分辨率生成非正方形图像。 - callback_on_step_end (
Callable, 可选) — 在推理过程中,每个去噪步骤结束时调用的函数。该函数以以下参数被调用:callback_on_step_end(self, step, timestep, callback_kwargs)。callback_kwargs将包含由callback_on_step_end_tensor_inputs指定的所有张量列表。 - callback_on_step_end_tensor_inputs (
list,可选) —callback_on_step_end函数的张量输入列表。列表中指定的张量将作为callback_kwargs参数传入。您只能包含在._callback_tensor_inputs属性中列出的张量。
返回值
PRXPipelineOutput 或 tuple
如果 return_dict 为 True,则返回 PRXPipelineOutput,否则返回一个 `tuple。当返回元组时,第一个元素是一个包含生成图像的列表。
调用生成 pipeline 时调用的函数。
示例:
>>> import torch
>>> from diffusers import PRXPixelPipeline
>>> pipe = PRXPixelPipeline.from_pretrained("Photoroom/prxpixel-t2i", torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")
>>> prompt = "A front-facing portrait of a lion in the golden savanna at sunset."
>>> image = pipe(prompt, num_inference_steps=28, guidance_scale=5.0).images[0]
>>> image.save("prxpixel_output.png")check_inputs
< source >( prompt: str | list[str]height: intwidth: intguidance_scale: floatcallback_on_step_end_tensor_inputs: list[str] | None = Noneprompt_embeds: typing.Optional[torch.FloatTensor] = Nonenegative_prompt_embeds: typing.Optional[torch.FloatTensor] = None )
检查所有输入是否处于正确的格式。
encode_prompt
< source >( prompt: str | list[str]device: typing.Optional[torch.device] = Nonedo_classifier_free_guidance: bool = Truenegative_prompt: str = ''num_images_per_prompt: int = 1prompt_embeds: typing.Optional[torch.FloatTensor] = Nonenegative_prompt_embeds: typing.Optional[torch.FloatTensor] = Noneprompt_attention_mask: typing.Optional[torch.BoolTensor] = Nonenegative_prompt_attention_mask: typing.Optional[torch.BoolTensor] = Nonetokenizer_max_length: int | None = Noneskip_text_cleaning: bool = False )
使用标准文本编码器和分词器对文本提示进行编码,或使用预计算的嵌入。
prepare_latents
< source >( batch_size: intnum_channels_latents: intheight: intwidth: intdtype: dtypedevice: devicegenerator: typing.Optional[torch.Generator] = Nonelatents: typing.Optional[torch.Tensor] = None )
为扩散过程准备初始潜变量。
PRXPixel 使用非单位初始噪声尺度进行训练,因此采样的噪声会乘以 self.config.noise_scale。
PRXPipelineOutput
class diffusers.pipelines.prx.PRXPipelineOutput
< source >( images: list[PIL.Image.Image] | numpy.ndarray )
PRX 流水线的输出类。