ls_mlkit.util.base_class.base_time_class module

class ls_mlkit.util.base_class.base_time_class.BaseTimeScheduler(continuous_time_start: float = 0.0, continuous_time_end: float = 1.0, num_train_timesteps: int = 1000, num_inference_steps: int = None)[source]

Bases: ABC

continuous_time_to_discrete_time(continuous_time: Tensor) Tensor[source]

Convert a continuous time to a discrete time.

\[t =\]

ound( rac{t’}{T} cdot N - 1)

Args:

continuous_time (Tensor): the continuous time

Returns:

Tensor: the discrete time

discrete_time_to_continuous_time(discrete_time: Tensor) Tensor[source]

Convert a discrete time to a continuous time.

\[t' =\]

rac{(t + 1)}{N} cdot T

Args:

discrete_time (Tensor): the discrete time

Returns:

Tensor: the continuous time

get_continuous_timesteps_schedule() Tensor[source]

Get the continuous one-dimensional timesteps for sampling/inference.

Returns:

the continuous one-dimensional timesteps for sampling/inference

Return type:

Tensor

get_discrete_timesteps_schedule() Tensor[source]

Get the discrete one-dimensional timesteps for sampling/inference.

Returns:

the discrete one-dimensional timesteps for sampling/inference

Return type:

Tensor

abstractmethod initialize_timesteps_schedule() None[source]

initialize timesteps for sampling.

sample_a_continuous_time_step_uniformly(macro_shape: Tuple[int, ...], same_timesteps_for_all_samples: bool = False) Tensor[source]

Sample a continuous timestep in the range of [continuous_time_start, continuous_time_end] uniformly.

Parameters:
  • macro_shape (Tuple[int, ...]) – the macro shape of the samples

  • same_timesteps_for_all_samples (bool, optional) – whether to use the same timestep for all samples. Defaults to False.

Returns:

the continuous timestep

Return type:

Tensor

sample_a_discrete_time_step_uniformly(macro_shape: Tuple[int, ...], same_timesteps_for_all_samples: bool = False) Tensor[source]

Sample a discrete timestep in the range of [0, num_train_timesteps - 1] uniformly.

Parameters:
  • macro_shape (Tuple[int, ...]) – the macro shape of the samples

  • same_timesteps_for_all_samples (bool, optional) – whether to use the same timestep for all samples. Defaults to False.

Returns:

the discrete timestep

Return type:

Tensor

set_continuous_timesteps_schedule(continuous_timesteps: Tensor) None[source]

Set the continuous one-dimensional timesteps for sampling/inference.

Parameters:

continuous_timesteps (Tensor) – the continuous one-dimensional timesteps for sampling/inference.

set_discrete_timesteps_schedule(discrete_timesteps: Tensor) None[source]

Set the discrete one-dimensional timesteps for sampling/inference.

Parameters:

discrete_timesteps (Tensor) – the discrete one-dimensional timesteps for sampling/inference.