tempor.models.utils module¶
Utilities for the models package directory.
-
tempor.models.utils.enable_reproducibility(random_seed: int =
0, torch_use_deterministic_algorithms: bool =False, torch_set_cudnn_deterministic: bool =False, torch_disable_cudnn_benchmark: bool =False, warn_cuda_env_vars: bool =True) None[source]¶ Attempt to enable reproducibility of results by removing sources of non-determinism (randomness) wherever possible. This function does not guarantee reproducible results, as there could be many other sources of randomness, e.g. data splitting, third party libraries etc.
The implementation is based on the information in PyTorch documentation here: https://pytorch.org/docs/stable/notes/randomness.html
- Parameters:¶
- random_seed : int, optional¶
The random seed to set. Defaults to 0.
- torch_use_deterministic_algorithms : bool, optional¶
Whether to set
torch.use_deterministic_algorithms(True). Defaults toFalse.- torch_set_cudnn_deterministic : bool, optional¶
Whether to set
torch.backends.cudnn.deterministic = True. Defaults toFalse.- torch_disable_cudnn_benchmark : bool, optional¶
Whether to set
torch.backends.cudnn.benchmark = False. Defaults toFalse.- warn_cuda_env_vars : bool, optional¶
Whether to raise a
RuntimeWarningin casetorchdeterministic algorithms are enabled but the"CUDA_LAUNCH_BLOCKING"/"CUBLAS_WORKSPACE_CONFIG"environment variable has not been set. More details at https://pytorch.org/docs/stable/generated/torch.nn.LSTM.html#torch.nn.LSTM. Defaults toTrue.
-
class tempor.models.utils.GumbelSoftmax(tau: float =
0.2, hard: bool =False, dim: int =-1)[source]¶ Bases:
ModuleGumbel-Softmax activation function implementation.
-
tempor.models.utils.NONLIN_MAP : dict[str, Module] =
{'elu': ELU(alpha=1.0), 'gumbel_softmax': GumbelSoftmax(), 'leaky_relu': LeakyReLU(negative_slope=0.01), 'none': Identity(), 'relu': ReLU(), 'selu': SELU(), 'sigmoid': Sigmoid(), 'softmax': Softmax(dim=-1), 'tanh': Tanh()}¶ A map of names (str, keys) to nonlinearity modules (
nn.Module, values).
- tempor.models.utils.get_nonlin(name: Literal[none] | Literal[elu] | Literal[relu] | Literal[leaky_relu] | Literal[selu] | Literal[tanh] | Literal[sigmoid] | Literal[softmax] | Literal[gumbel_softmax]) Module[source]¶
Get a nonlinearity
nn.Module(nonlinearity / activation function) by name.
-
tempor.models.utils.SAMPLER_MAP : dict[str, type[Sampler]] =
{'BatchSampler': <class 'torch.utils.data.sampler.BatchSampler'>, 'RandomSampler': <class 'torch.utils.data.sampler.RandomSampler'>, 'Sampler': <class 'torch.utils.data.sampler.Sampler'>, 'SequentialSampler': <class 'torch.utils.data.sampler.SequentialSampler'>, 'SubsetRandomSampler': <class 'torch.utils.data.sampler.SubsetRandomSampler'>, 'WeightedRandomSampler': <class 'torch.utils.data.sampler.WeightedRandomSampler'>}¶ A map of names (str, keys) to sampler classes (
Type[torch.utils.data.sampler.Sampler], values).