# Suy luận từ xa

Remote inference cung cấp quyền truy cập vào [Inference Endpoint](https://huggingface.co/docs/inference-endpoints/index) để chuyển tải các yêu cầu tạo cục bộ cho việc giải mã và mã hóa.

## 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)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/utils/remote_utils.py#L190)

**Tham số:**

endpoint (`str`) : Điểm cuối cho Remote Decode.

tensor (`torch.Tensor`) : Tensor cần giải mã.

processor (`VaeImageProcessor` hoặc `VideoProcessor`, *tùy chọn*) : Được sử dụng với `return_type="pt"`, và `return_type="pil"` cho các mô hình Video.

do_scaling (`bool`, mặc định `True`, *tùy chọn*) : **ĐÃ BỊ LỖI THỜI**. **hãy truyền `scaling_factor`/`shift_factor` thay thế.** **vẫn đặt do_scaling=None/do_scaling=False để không áp dụng scaling cho đến khi tùy chọn này bị loại bỏ** Khi `True`, scaling, ví dụ `latents / self.vae.config.scaling_factor`, sẽ được áp dụng từ xa. Nếu `False`, đầu vào phải được truyền với scaling đã được áp dụng.

scaling_factor (`float`, *optional*) : Việc scale được áp dụng khi được truyền vào, ví dụ [`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 Nếu `None`, đầu vào phải được truyền với việc scale đã được áp dụng.

shift_factor (`float`, *optional*) : Shift được áp dụng khi được truyền vào, ví dụ `latents + self.vae.config.shift_factor`. - Flux: 0.1159 Nếu `None`, đầu vào phải được truyền với việc áp dụng scaling.

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"` hoặc `"jpg"`, mặc định `jpg`) : Được sử dụng với `output_type="pil"`. Endpoint trả về `jpg` hoặc `png`.

partial_postprocess (`bool`, mặc định `False`) : Được sử dụng cùng với `output_type="pt"`. `partial_postprocess=False` tensor là `float16` hoặc `bfloat16`, không được chuẩn hóa ngược. `partial_postprocess=True` tensor là `uint8`, đã được chuẩn hóa ngược.

input_tensor_type (`"binary"`, mặc định `"binary"`) : Kiểu chuyển tensor.

output_tensor_type (`"binary"`, mặc định `"binary"`) : Kiểu chuyển tensor.

height (`int`, **optional**) : Bắt buộc đối với latents `"packed"`.

width (`int`, **optional**) : Bắt buộc đối với latents `"packed"`.

**Trả về:**

output (`Image.Image` hoặc `list[Image.Image]` hoặc `bytes` hoặc `torch.Tensor`).

Hugging Face Hybrid Inference cho phép chạy VAE decode từ xa.

## 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)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/utils/remote_utils.py#L382)

**Tham số:**

endpoint (`str`) : Điểm cuối cho Remote Decode.

image (`torch.Tensor` hoặc `PIL.Image.Image`) : Ảnh cần được mã hóa.

scaling_factor (`float`, *optional*) : Việc scale được áp dụng khi được truyền vào, ví dụ `latents * self.vae.config.scaling_factor`. - SD v1: 0.18215 - SD XL: 0.13025 - Flux: 0.3611 Nếu là `None`, đầu vào phải được truyền với việc scale đã được áp dụng.

shift_factor (`float`, *optional*) : Shift được áp dụng khi được truyền vào, ví dụ `latents - self.vae.config.shift_factor`. - Flux: 0.1159 Nếu `None`, đầu vào phải được truyền với việc áp dụng scaling.

**Trả về:**

output (`torch.Tensor`).

Hugging Face Hybrid Inference cho phép chạy VAE encode từ xa.

