Diffusers 文档
混合推理API参考
并获得增强的文档体验
开始使用
混合推理API参考
远程解码
diffusers.utils.remote_decode
< 来源 >( endpoint: str tensor: torch.Tensor processor: typing.Union[ForwardRef('VaeImageProcessor'), ForwardRef('VideoProcessor'), NoneType] = None do_scaling: bool = True scaling_factor: typing.Optional[float] = None shift_factor: typing.Optional[float] = None output_type: typing.Literal['mp4', 'pil', 'pt'] = 'pil' return_type: typing.Literal['mp4', 'pil', 'pt'] = 'pil' image_format: typing.Literal['png', 'jpg'] = 'jpg' partial_postprocess: bool = False input_tensor_type: typing.Literal['binary'] = 'binary' output_tensor_type: typing.Literal['binary'] = 'binary' height: typing.Optional[int] = None width: typing.Optional[int] = None )
参数
- endpoint (
str) — 远程解码的端点。 - tensor (
torch.Tensor) — 要解码的张量。 - processor (
VaeImageProcessor或VideoProcessor, 可选) — 与return_type="pt"以及视频模型的return_type="pil"一起使用。 - do_scaling (
bool, 默认为True, 可选) — 已弃用。请改用scaling_factor/shift_factor。在选项被移除之前,仍需设置 do_scaling=None/do_scaling=False 以禁用缩放 当True时,缩放(例如latents / self.vae.config.scaling_factor)会在远程应用。如果为False,输入必须经过缩放处理。 - scaling_factor (
float, 可选) — 缩放应用于传递时,例如latents / self.vae.config.scaling_factor。- SD v1: 0.18215
- SD XL: 0.13025
- Flux: 0.3611 如果为
None,则输入必须经过缩放处理。
- shift_factor (
float, 可选) — 移位应用于传递时,例如latents + self.vae.config.shift_factor。- Flux: 0.1159 如果为
None,则输入必须经过缩放处理。
- Flux: 0.1159 如果为
- output_type (
"mp4"或"pil"或"pt", 默认为“pil”) — 端点输出类型。可能会更改。请反馈首选类型。"mp4":视频模型支持。端点返回视频的bytes。"pil":图像和视频模型支持。图像模型:端点返回image_format中的图像bytes。视频模型:端点返回应用了部分postprocessing的torch.Tensor。需要processor标志(任何None值都可以)。"pt":图像和视频模型支持。端点返回torch.Tensor。当partial_postprocess=True时,张量是经过后处理的uint8图像张量。建议:
"pt"且partial_postprocess=True时传输的数据量最小,质量最高。"pt"且partial_postprocess=False时与第三方代码兼容性最佳。"pil"且image_format="jpg"时总体传输数据量最小。 - return_type (
"mp4"或"pil"或"pt", 默认为“pil”) — 函数返回类型。"mp4":函数返回视频的bytes。"pil":函数返回PIL.Image.Image。当output_type="pil"时,不进行进一步处理。当output_type="pt"时,创建PIL.Image.Image。当partial_postprocess=False时,需要processor。当partial_postprocess=True时,不需要processor。"pt":函数返回torch.Tensor。不需要processor。当partial_postprocess=False时,张量为float16或bfloat16,未经去范化。当partial_postprocess=True时,张量为uint8,已去范化。 - image_format (
"png"或"jpg", 默认为jpg) — 与output_type="pil"一起使用。端点返回jpg或png。 - partial_postprocess (
bool, 默认为False) — 与output_type="pt"一起使用。当partial_postprocess=False时,张量为float16或bfloat16,未经去范化。当partial_postprocess=True时,张量为uint8,已去范化。 - input_tensor_type (
"binary", 默认为"binary") — 张量传输类型。 - output_tensor_type (
"binary", 默认为"binary") — 张量传输类型。 - height (
int, 可选) —"packed"潜在空间所需。 - width (
int, 可选) —"packed"潜在空间所需。
Hugging Face 混合推理,允许远程运行 VAE 解码。
远程编码
diffusers.utils.remote_utils.remote_encode
< 来源 >( endpoint: str image: typing.Union[ForwardRef('torch.Tensor'), PIL.Image.Image] scaling_factor: typing.Optional[float] = None shift_factor: typing.Optional[float] = None )
参数
- endpoint (
str) — 远程解码的端点。 - image (
torch.Tensor或PIL.Image.Image) — 要编码的图像。 - scaling_factor (
float, 可选) — 缩放应用于传递时,例如latents * self.vae.config.scaling_factor。- SD v1: 0.18215
- SD XL: 0.13025
- Flux: 0.3611 如果为
None,则输入必须经过缩放处理。
- shift_factor (
float, 可选) — 移位应用于传递时,例如latents - self.vae.config.shift_factor。- Flux: 0.1159 如果为
None,则输入必须经过缩放处理。
- Flux: 0.1159 如果为
Hugging Face 混合推理,允许远程运行 VAE 编码。