# FlowMatchEulerDiscreteScheduler

`FlowMatchEulerDiscreteScheduler` dựa trên phương pháp lấy mẫu flow-matching được giới thiệu trong [Stable Diffusion 3](https://huggingface.co/papers/2403.03206).

## FlowMatchEulerDiscreteScheduler[[diffusers.FlowMatchEulerDiscreteScheduler]]

#### diffusers.FlowMatchEulerDiscreteScheduler[[diffusers.FlowMatchEulerDiscreteScheduler]]

```python
diffusers.FlowMatchEulerDiscreteScheduler(num_train_timesteps: int = 1000, shift: float = 1.0, use_dynamic_shifting: bool = False, base_shift: float | None = 0.5, max_shift: float | None = 1.15, base_image_seq_len: int = 256, max_image_seq_len: int = 4096, invert_sigmas: bool = False, shift_terminal: float = None, use_karras_sigmas: bool = False, use_exponential_sigmas: bool = False, use_beta_sigmas: bool = False, time_shift_type: typing.Literal['exponential', 'linear'] = 'exponential', stochastic_sampling: bool = False)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L48)

**Tham số:**

num_train_timesteps (`int`, mặc định là 1000) : Số bước khuếch tán để huấn luyện mô hình.

shift (`float`, mặc định là 1.0) : Giá trị dịch cho lịch bước thời gian.

use_dynamic_shifting (`bool`, mặc định là False) : Có áp dụng việc dịch chuyển bước thời gian (timestep shifting) theo thời gian thực dựa trên độ phân giải của hình ảnh hay không.

base_shift (`float`, mặc định là 0.5) : Giá trị để ổn định quá trình tạo ảnh. Tăng `base_shift` sẽ giảm sự biến đổi và ảnh sẽ nhất quán hơn với đầu ra mong muốn.

max_shift (`float`, mặc định là 1.15) : Mức thay đổi được phép cho các vector tiềm ẩn. Tăng `max_shift` sẽ khuyến khích nhiều biến đổi hơn và hình ảnh có thể trở nên phóng đại hoặc mang tính cách điệu hơn.

base_image_seq_len (`int`, mặc định là 256) : Độ dài chuỗi hình ảnh cơ sở.

max_image_seq_len (`int`, mặc định là 4096) : Độ dài tối đa của chuỗi hình ảnh.

invert_sigmas (`bool`, mặc định là False) : Có đảo ngược các sigma hay không.

shift_terminal (`float`, mặc định là None) : Giá trị cuối của lịch trình bước thời gian đã dịch chuyển.

use_karras_sigmas (`bool`, mặc định là False) : Có sử dụng Karras sigmas cho kích thước bước trong lịch trình nhiễu khi lấy mẫu hay không.

use_exponential_sigmas (`bool`, mặc định là False) : Có sử dụng sigma mũ cho kích thước bước trong lịch trình nhiễu khi lấy mẫu hay không.

use_beta_sigmas (`bool`, mặc định là False) : Có sử dụng beta sigmas cho kích thước bước trong lịch trình nhiễu khi lấy mẫu hay không.

time_shift_type (`str`, mặc định là "exponential") : Loại dịch chuyển bước thời gian phụ thuộc vào độ phân giải động cần áp dụng. Có thể là "exponential" hoặc "linear".

stochastic_sampling (`bool`, mặc định là False) : Có sử dụng lấy mẫu ngẫu nhiên hay không.

Trình lập lịch Euler.

Mô hình này kế thừa từ [SchedulerMixin](/docs/diffusers/main/vi/api/schedulers/overview#diffusers.SchedulerMixin) và [ConfigMixin](/docs/diffusers/main/vi/api/configuration#diffusers.ConfigMixin). Xem tài liệu của lớp cha để biết các phương thức chung mà thư viện triển khai cho tất cả các scheduler, chẳng hạn như tải và lưu.

#### index_for_timestep[[diffusers.FlowMatchEulerDiscreteScheduler.index_for_timestep]]

```python
index_for_timestep(timestep: typing.Union[float, torch.FloatTensor], schedule_timesteps: typing.Optional[torch.FloatTensor] = None)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L393)

**Tham số:**

timestep (`float` hoặc `torch.FloatTensor`) : Bước thời gian để tìm chỉ số tương ứng.

schedule_timesteps (`torch.FloatTensor`, *tùy chọn*) : Các bước thời gian (timesteps) của lịch trình để kiểm tra. Nếu là `None`, các bước thời gian của trình lập lịch (scheduler) sẽ được sử dụng.

**Trả về:** `int`

Chỉ số của bước thời gian.

Lấy chỉ số cho bước thời gian đã cho.

#### scale_noise[[diffusers.FlowMatchEulerDiscreteScheduler.scale_noise]]

```python
scale_noise(sample: FloatTensor, timestep: typing.Union[float, torch.FloatTensor], noise: typing.Optional[torch.FloatTensor] = None)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L188)

**Tham số:**

sample (`torch.FloatTensor`) : Mẫu đầu vào.

timestep (`torch.FloatTensor`) : Bước thời gian hiện tại trong chuỗi khuếch tán.

noise (`torch.FloatTensor`) : Tensor nhiễu.

**Trả về:** `torch.FloatTensor`

Một mẫu đầu vào đã được chuẩn hóa.

Quá trình tiến trong flow-matching

#### set_begin_index[[diffusers.FlowMatchEulerDiscreteScheduler.set_begin_index]]

```python
set_begin_index(begin_index: int = 0)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L168)

**Tham số:**

begin_index (`int`, mặc định là `0`) : Chỉ số bắt đầu cho trình lập lịch.

Đặt chỉ số bắt đầu cho trình lập lịch. Hàm này nên được chạy từ pipeline trước khi suy luận.

#### set_shift[[diffusers.FlowMatchEulerDiscreteScheduler.set_shift]]

```python
set_shift(shift: float)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L178)

**Tham số:**

shift (`float`) : Giá trị dịch cần được thiết lập.

Đặt giá trị dịch chuyển cho trình lập lịch.

#### set_timesteps[[diffusers.FlowMatchEulerDiscreteScheduler.set_timesteps]]

```python
set_timesteps(num_inference_steps: int | None = None, device: typing.Union[str, torch.device] = None, sigmas: list[float] | None = None, mu: float | None = None, timesteps: list[float] | None = None)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L283)

**Tham số:**

num_inference_steps (`int`, *tuỳ chọn*) : Số bước khuếch tán được sử dụng khi tạo mẫu bằng một mô hình đã được huấn luyện trước.

device (`str` hoặc `torch.device`, *tuỳ chọn*) : Thiết bị mà các bước thời gian (timesteps) sẽ được chuyển đến. Nếu là `None`, các bước thời gian sẽ không được chuyển.

sigmas (`list[float]`, *optional*) : Các giá trị tùy chỉnh cho sigmas được sử dụng cho mỗi bước khuếch tán. Nếu `None`, các sigmas sẽ được tính toán tự động.

mu (`float`, *tùy chọn*) : Xác định mức độ dịch chuyển được áp dụng cho sigmas khi thực hiện dịch chuyển bước thời gian phụ thuộc vào độ phân giải.

timesteps (`list[float]`, *optional*) : Các giá trị tùy chỉnh cho timesteps được sử dụng cho mỗi bước khuếch tán. Nếu `None`, các timesteps sẽ được tính toán tự động.

Đặt các bước thời gian rời rạc được sử dụng cho chuỗi khuếch tán (cần chạy trước khi suy luận).

#### bước[[diffusers.FlowMatchEulerDiscreteScheduler.step]]

```python
step(model_output: FloatTensor, timestep: typing.Union[float, torch.FloatTensor], sample: FloatTensor, s_churn: float = 0.0, s_tmin: float = 0.0, s_tmax: float = inf, s_noise: float = 1.0, generator: typing.Optional[torch.Generator] = None, per_token_timesteps: typing.Optional[torch.Tensor] = None, return_dict: bool = True)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L432)

**Tham số:**

model_output (`torch.FloatTensor`) : Đầu ra trực tiếp từ mô hình khuếch tán đã học.

timestep (`float`) : Bước thời gian rời rạc hiện tại trong chuỗi khuếch tán.

sample (`torch.FloatTensor`) : Một bản sao mẫu hiện tại được tạo ra bởi quá trình khuếch tán.

s_churn (`float`) --

s_tmin  (`float`) --

s_tmax  (`float`) --

s_noise (`float`, mặc định là 1.0) : Hệ số tỷ lệ cho nhiễu được thêm vào mẫu.

generator (`torch.Generator`, *tùy chọn*) : Bộ tạo số ngẫu nhiên.

per_token_timesteps (`torch.Tensor`, *tùy chọn*) : Các bước thời gian (timesteps) cho từng token trong mẫu.

return_dict (`bool`, mặc định là `True`) : Có nên trả về `FlowMatchEulerDiscreteSchedulerOutput` hay tuple hay không.

**Trả về:** `FlowMatchEulerDiscreteSchedulerOutput` hoặc `tuple`

If return_dict is `True`, `FlowMatchEulerDiscreteSchedulerOutput` is returned, otherwise a tuple is returned where the first element is the sample tensor.

Dự đoán mẫu từ bước thời gian trước đó bằng cách đảo ngược SDE. Hàm này lan truyền quá trình khuếch tán từ các đầu ra của mô hình đã học (thường nhất là nhiễu được dự đoán).

#### stretch_shift_to_terminal[[diffusers.FlowMatchEulerDiscreteScheduler.stretch_shift_to_terminal]]

```python
stretch_shift_to_terminal(t: Tensor)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L262)

**Tham số:**

t (`torch.Tensor`) : Một tensor chứa các bước thời gian (timesteps) cần được kéo dài và dịch chuyển.

**Trả về:** `torch.Tensor`

Một tensor chứa các bước thời gian đã điều chỉnh sao cho giá trị cuối cùng bằng `self.config.shift_terminal`.

Kéo giãn và dịch lịch trình bước thời gian để đảm bảo nó kết thúc tại giá trị cấu hình `shift_terminal` đã được thiết lập.

Tham khảo: https://github.com/Lightricks/LTX-Video/blob/a01a171f8fe3d99dce2728d60a73fecf4d4238ae/ltx_video/schedulers/rf.py#L51

#### time_shift[[diffusers.FlowMatchEulerDiscreteScheduler.time_shift]]

```python
time_shift(mu: float, sigma: float, t: Tensor)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L241)

**Tham số:**

mu (`float`) : Tham số mu cho việc dịch chuyển thời gian.

sigma (`float`) : Tham số sigma cho phép dịch chuyển thời gian.

t (`torch.Tensor`) : Các bước thời gian đầu vào.

**Trả về:** `torch.Tensor`

Các bước thời gian đã dịch chuyển.

Áp dụng dịch chuyển thời gian vào các sigma.

