Diffusers documentation

远程推理

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

远程推理

远程推理提供对 Inference Endpoint 的访问,以便将解码和编码的本地生成需求卸载出去。

remote_decode

diffusers.utils.remote_decode

< >

( endpoint: strtensor: 'torch.Tensor'processor: 'VaeImageProcessor' | 'VideoProcessor' | None = Nonedo_scaling: bool = Truescaling_factor: float | None = Noneshift_factor: float | None = Noneoutput_type: Literal['mp4', 'pil', 'pt'] = 'pil'return_type: Literal['mp4', 'pil', 'pt'] = 'pil'image_format: Literal['png', 'jpg'] = 'jpg'partial_postprocess: bool = Falseinput_tensor_type: Literal['binary'] = 'binary'output_tensor_type: Literal['binary'] = 'binary'height: int | None = Nonewidth: int | None = None )

参数

  • endpoint (str) — Remote Decode 的端点。
  • 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, 可选) — 传入时会应用 Shift,例如 latents + self.vae.config.shift_factor.
    • Flux: 0.1159 如果为 None,则输入必须已应用缩放后传入。
  • output_type ("mp4" or "pil" or "pt", default “pil”) — Endpoint output type. Subject to change. Report feedback on preferred type.

    "mp4": Supported by video models. Endpoint returns bytesof video.“pil”: Supported by image and video models. Image models: Endpoint returns bytesof an image inimage_format. Video models: Endpoint returns torch.Tensorwith partialpostprocessingapplied. Requiresprocessoras a flag (anyNonevalue will work).“pt”: Support by image and video models. Endpoint returns torch.Tensor. With partial_postprocess=Truethe tensor is postprocesseduint8` image tensor.

    建议: "pt" 配合 partial_postprocess=True 是保持完整质量的最小传输方式。"pt" 配合 partial_postprocess=False 与第三方代码的兼容性最好。"pil" 配合 image_format="jpg" 是整体最小的传输方式。

  • return_type ("mp4" 或 "pil" 或 "pt", default “) — 函数的 返回类型。

    "mp4": Function returns bytesof video.“pil”: Function returns PIL.Image.Image. With output_type=“pil” no further processing is applied. With output_type="pt" a PIL.Image.Imageis created.partial_postprocess=False processoris required.partial_postprocess=True processoris **not** required.“pt”: Function returns torch.Tensor. processoris **not** required.partial_postprocess=Falsetensor isfloat16orbfloat16, without denormalization. partial_postprocess=Truetensor isuint8`, denormalized.

  • 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 解码。

remote_encode

diffusers.utils.remote_utils.remote_encode

< >

( endpoint: strimage: 'torch.Tensor' | Image.Imagescaling_factor: float | None = Noneshift_factor: float | None = None )

参数

  • endpoint (str) — Remote Decode 的端点。
  • 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, 可选) — 传入时会应用 Shift,例如 latents - self.vae.config.shift_factor.
    • Flux: 0.1159 如果为 None,则输入必须已应用缩放后传入。

Hugging Face 混合推理,支持远程运行 VAE 编码。

Update on GitHub