远程推理
远程推理提供对 Inference Endpoint 的访问,以便将解码和编码的本地生成需求卸载出去。
remote_decode
diffusers.utils.remote_decode
< source >( 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,则输入必须已应用缩放后传入。
- Flux: 0.1159
如果为
- 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 returnsbytesof video.“pil”: Supported by image and video models. Image models: Endpoint returnsbytesof an image inimage_format. Video models: Endpoint returnstorch.Tensorwith partialpostprocessingapplied. Requiresprocessoras a flag (anyNonevalue will work).“pt”: Support by image and video models. Endpoint returnstorch.Tensor. Withpartial_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 returnsbytesof video.“pil”: Function returnsPIL.Image.Image. Withoutput_type=“pil” no further processing is applied. Withoutput_type="pt" aPIL.Image.Imageis created.partial_postprocess=Falseprocessoris required.partial_postprocess=Trueprocessoris **not** required.“pt”: Function returnstorch.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
< source >( 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,则输入必须已应用缩放后传入。
- Flux: 0.1159
如果为
Hugging Face 混合推理,支持远程运行 VAE 编码。