Diffusers 文档

混合推理API参考

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

混合推理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 (VaeImageProcessorVideoProcessor, 可选) — 与 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,则输入必须经过缩放处理。
  • output_type ("mp4""pil""pt", 默认为 “pil”) — 端点输出类型。可能会更改。请反馈首选类型。

    "mp4":视频模型支持。端点返回视频的 bytes"pil":图像和视频模型支持。图像模型:端点返回 image_format 中的图像 bytes。视频模型:端点返回应用了部分 postprocessingtorch.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 时,张量为 float16bfloat16,未经去范化。当 partial_postprocess=True 时,张量为 uint8,已去范化。

  • image_format ("png""jpg", 默认为 jpg) — 与 output_type="pil" 一起使用。端点返回 jpgpng
  • partial_postprocess (bool, 默认为 False) — 与 output_type="pt" 一起使用。当 partial_postprocess=False 时,张量为 float16bfloat16,未经去范化。当 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.TensorPIL.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,则输入必须经过缩放处理。

Hugging Face 混合推理,允许远程运行 VAE 编码。

< > 在 GitHub 上更新