# リモート推論

Remote inference は、デコードおよびエンコードのためのローカルでの生成要件をオフロードするために、[Inference Endpoint](https://huggingface.co/docs/inference-endpoints/index) へのアクセスを提供します。

## remote_decode[[diffusers.utils.remote_decode]]

#### diffusers.utils.remote_decode[[diffusers.utils.remote_decode]]

```python
diffusers.utils.remote_decode(endpoint: str, tensor: 'torch.Tensor', processor: 'VaeImageProcessor' | 'VideoProcessor' | None = None, do_scaling: bool = True, scaling_factor: float | None = None, shift_factor: float | None = None, output_type: Literal['mp4', 'pil', 'pt'] = 'pil', return_type: Literal['mp4', 'pil', 'pt'] = 'pil', image_format: Literal['png', 'jpg'] = 'jpg', partial_postprocess: bool = False, input_tensor_type: Literal['binary'] = 'binary', output_tensor_type: Literal['binary'] = 'binary', height: int | None = None, width: int | None = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/utils/remote_utils.py#L190)

**パラメータ:**

endpoint (`str`) : Remote Decode のエンドポイント。

tensor (`torch.Tensor`) : デコード対象のテンソル。

processor (`VaeImageProcessor` または `VideoProcessor`、*任意*) : `return_type="pt"` および Video モデルの `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`](https://github.com/huggingface/diffusers/blob/7007febae5cff000d4df9059d9cf35133e8b2ca9/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#L1083C37-L1083C77) のように渡された場合、スケーリングが適用されます。 - 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"` or `"pil"` or `"pt", default `"pil") : **Endpoint** output type. Subject to change. Report feedback on preferred type.  `"mp4": Supported by video models. Endpoint returns `bytes` of video. `"pil"`: Supported by image and video models. Image models: Endpoint returns `bytes` of an image in `image_format`. Video models: Endpoint returns `torch.Tensor` with partial `postprocessing` applied. Requires `processor` as a flag (any `None` value will work). `"pt"`: Support by image and video models. Endpoint returns `torch.Tensor`. With `partial_postprocess=True` the tensor is postprocessed `uint8` image tensor.  Recommendations: `"pt"` with `partial_postprocess=True` is the smallest transfer for full quality. `"pt"` with `partial_postprocess=False` is the most compatible with third party code. `"pil"` with `image_format="jpg"` is the smallest transfer overall.

return_type (`"mp4"` or `"pil"` or `"pt", default `"pil") : **Function** return type.  `"mp4": Function returns `bytes` of video. `"pil"`: Function returns `PIL.Image.Image`. With `output_type="pil" no further processing is applied. With `output_type="pt" a `PIL.Image.Image` is created. `partial_postprocess=False` `processor` is required. `partial_postprocess=True` `processor` is **not** required. `"pt"`: Function returns `torch.Tensor`. `processor` is **not** required. `partial_postprocess=False` tensor is `float16` or `bfloat16`, without denormalization. `partial_postprocess=True` tensor is `uint8`, 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"` 潜在変数に必要です。

**戻り値:**

output (`Image.Image` または `list[Image.Image]` または `bytes` または `torch.Tensor`)。

VAEのデコードをリモートで実行できるHugging Face Hybrid Inference。

## remote_encode[[diffusers.utils.remote_utils.remote_encode]]

#### diffusers.utils.remote_utils.remote_encode[[diffusers.utils.remote_utils.remote_encode]]

```python
diffusers.utils.remote_utils.remote_encode(endpoint: str, image: 'torch.Tensor' | Image.Image, scaling_factor: float | None = None, shift_factor: float | None = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/utils/remote_utils.py#L382)

**パラメータ:**

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`, *任意*) : 例として `latents - self.vae.config.shift_factor` のように渡された場合、シフトが適用されます。- Flux: 0.1159 `None` の場合、スケーリングを適用した状態で入力を受け渡す必要があります。

**戻り値:**

output (`torch.Tensor`).

VAEエンコードをリモートで実行できるHugging Face Hybrid Inference。

