starling.samplers.ddim_sampler.DDIMSampler
- class DDIMSampler[source]
Bases:
ModuleMethods
An efficient sampler that generates samples 10x to 100x faster than the DDPM model.
add_moduleAdd a child module to the current module.
applyApply
fnrecursively to every submodule (as returned by.children()) as well as self.bfloat16Casts all floating point parameters and buffers to
bfloat16datatype.buffersReturn an iterator over module buffers.
childrenReturn an iterator over immediate children modules.
compileCompile this Module's forward using
torch.compile().cpuMove all model parameters and buffers to the CPU.
cudaMove all model parameters and buffers to the GPU.
doubleCasts all floating point parameters and buffers to
doubledatatype.evalSet the module in evaluation mode.
extra_reprReturn the extra representation of the module.
floatCasts all floating point parameters and buffers to
floatdatatype.forwardDefine the computation performed at every call.
Generate labels to condition the generative process on.
get_bufferReturn the buffer given by
targetif it exists, otherwise throw an error.get_extra_stateReturn any extra state to include in the module's state_dict.
get_parameterReturn the parameter given by
targetif it exists, otherwise throw an error.get_submoduleReturn the submodule given by
targetif it exists, otherwise throw an error.Remove the noise from the latent iteratively.
halfCasts all floating point parameters and buffers to
halfdatatype.ipuMove all model parameters and buffers to the IPU.
load_state_dictCopy parameters and buffers from
state_dictinto this module and its descendants.modulesReturn an iterator over all modules in the network.
mtiaMove all model parameters and buffers to the MTIA.
named_buffersReturn an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
named_childrenReturn an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modulesReturn an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
named_parametersReturn an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
Take one step in the generative process.
parametersReturn an iterator over module parameters.
register_backward_hookRegister a backward hook on the module.
register_bufferAdd a buffer to the module.
register_forward_hookRegister a forward hook on the module.
register_forward_pre_hookRegister a forward pre-hook on the module.
register_full_backward_hookRegister a backward hook on the module.
register_full_backward_pre_hookRegister a backward pre-hook on the module.
register_load_state_dict_post_hookRegister a post-hook to be run after module's
load_state_dict()is called.register_load_state_dict_pre_hookRegister a pre-hook to be run before module's
load_state_dict()is called.register_moduleAlias for
add_module().register_parameterAdd a parameter to the module.
register_state_dict_post_hookRegister a post-hook for the
state_dict()method.register_state_dict_pre_hookRegister a pre-hook for the
state_dict()method.requires_grad_Change if autograd should record operations on parameters in this module.
Sample the generative process using the DDIM model.
set_extra_stateSet extra state contained in the loaded state_dict.
set_submoduleSet the submodule given by
targetif it exists, otherwise throw an error.share_memorystate_dictReturn a dictionary containing references to the whole state of the module.
toMove and/or cast the parameters and buffers.
to_emptyMove the parameters and buffers to the specified device without copying storage.
trainSet the module in training mode.
typeCasts all parameters and buffers to
dst_type.xpuMove all model parameters and buffers to the XPU.
zero_gradReset gradients of all model parameters.
Attributes
T_destinationcall_super_initdump_patchestraining- __init__(ddpm_model, encoder_model, n_steps: int, ionic_strength: float = 150, ddim_discretize: str = 'uniform', ddim_eta: float = 0.0)[source]
An efficient sampler that generates samples 10x to 100x faster than the DDPM model. Denoising diffusion implicit models (DDIM) do not require sampling the entire diffusion process to generate samples. The forward process is parameterized using non-Markovian diffusion processes, leading to short generative Markov chains that can be simulated in fewer steps.
References
[1] Ho, J., Jaini, P., Hariharan, B., Abbeel, P., & Duan, Y. (2020). Denoising diffusion implicit models. arXiv preprint arXiv:2012.02142.
- Parameters:
ddpm_model (_type_) – The trained DDPM model.
n_steps (int) – The number of steps to simulate the generative process, smaller than the number of steps used to train the DDPM model.
ddim_discretize (str, optional) – The discretization method for the generative process, by default “uniform”.
ddim_eta (float, optional) – The noise level for the generative process, a number between 0.0 and 1.0. 0.0 adds no noise to the generative process, 1.0 adds the maximum noise. This number interpolates between deterministic and stochastic generative processes, by default 0.0.
- Raises:
NotImplementedError – If the discretization method is not implemented.
- generate_labels(labels: str) Tensor[source]
Generate labels to condition the generative process on.
- Parameters:
labels (str) – A sequence to generate labels from.
- Returns:
The labels to condition the generative process on.
- Return type:
- sample(num_conformations: int, labels: Tensor, repeat_noise: bool = False, temperature: float = 1.0, show_per_step_progress_bar: bool = True, batch_count: int = 1, max_batch_count: int = 1, constraint=None) Tensor[source]
Sample the generative process using the DDIM model.
- Parameters:
num_conformations (int) – Number of conformations to generate.
labels (torch.Tensor) – The labels to condition the generative process on.
repeat_noise (bool, optional) – _description_, by default False
temperature (float, optional) – _description_, by default 1.0
show_per_step_progress_bar (bool, optional) – whether to show progress bar per step.
batch_count (int, optional) – The batch count for the progress bar, by default 1
max_batch_count (int, optional) – The maximum batch count for the progress bar, by default 1
- Returns:
The generated distance maps.
- Return type:
- p_sample(x: Tensor, c: Tensor, t: Tensor, attention_mask: Tensor, step: int, index: int, repeat_noise: bool = False, temperature: float = 1.0) Tuple[Tensor, Tensor, Tensor][source]
Take one step in the generative process.
- Parameters:
x (torch.Tensor) – The tensor to remove noise from.
c (torch.Tensor) – The labels to condition the generative process on.
t (torch.Tensor) – The timestep to sample the generative process at.
step (int)
index (int) – _description_
repeat_noise (bool, optional) – _description_, by default False
temperature (float, optional) – _description_, by default 1.0
- Returns:
_description_
- Return type:
_type_
- get_x_prev_and_pred_x0(predicted_noise: Tensor, index: int, x: Tensor, temperature: float, repeat_noise: bool) Tuple[Tensor, Tensor][source]
Remove the noise from the latent iteratively.
- Parameters:
predicted_noise (torch.Tensor) – The noise predicted by the DDPM model.
index (int) – The index of the timestep.
x (torch.Tensor) – The latent to remove the noise from.
temperature (float) – The temperature to use for the generative process
repeat_noise (bool) – Whether to repeat the noise
- Returns:
The previous latent.
- Return type:
Tuple[torch.Tensor, torch.Tensor]