starling.models.transformer.SinusoidalPosEmb
- class SinusoidalPosEmb[source]
Bases:
ModuleMethods
Generates sinusoidal positional embeddings that are used in the denoising-diffusion models to encode the timestep information.
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.Forward pass of the positional (timestep) embeddings.
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.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.
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.
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__(dim: int, theta: int = 10000)[source]
Generates sinusoidal positional embeddings that are used in the denoising-diffusion models to encode the timestep information. The positional embeddings are generated using sine and cosine functions. It takes in time in the shape of (batch_size, 1) and returns the positional embeddings in the shape of (batch_size, dim). The positional encodings are later used in each of the ResNet blocks to encode the timestep information.
- forward(time: Tensor) Tensor[source]
Forward pass of the positional (timestep) embeddings.
- Parameters:
time (torch.Tensor) – Timestep information in the shape of (batch_size, 1).
- Returns:
Positional (timestep) embeddings in the shape of (batch_size, dim).
- Return type: