random

Random number generator with a deterministic, synchronized seed for sampling.

Functions

centroid

Reduce each element of the seq via torch.prod() and then return seq element closest.

choice

Return a random element from the sequence using a synchronized seed.

original

Return an indicator (None) that can be recognized internally to sample the original choice.

random

Generate a random number from [0, 1) with a deterministic seed.

sample

Sample elements from a given population with a deterministic seed.

shuffle

Shuffle the sequence in-place with a deterministic seed.

centroid(seq)

Reduce each element of the seq via torch.prod() and then return seq element closest.

Parameters:

seq (Sequence[T]) – Sequence to determine centroid.

Returns:

Centroid of the sequence.

Return type:

T

This function can be used to sample the centroid subnet of an search space via mtn.sample(). The centroid subnet aims to cheaply approximate the median of the search space defined by the model.

Example: .. code-block:: python

from modelopt.torch.nas import random import modelopt.torch.nas as mtn

# Sample the centroid subnet of a converted model config = mtn.sample(model, random.centroid)

choice(seq)

Return a random element from the sequence using a synchronized seed.

Parameters:

seq (Sequence[T]) – Sequence to sample from.

Returns:

Random element from the sequence.

Return type:

T

This function is synchronized across all GPUs and can be used to sample a random subnet from a search space via mtn.sample() such that the resulting subnet/configuration is the same across all GPUs.

Example: .. code-block:: python

from modelopt.torch.nas import random import modelopt.torch.nas as mtn

# Sample a random subnet of a converted model config = mtn.sample(model, random.choice)

# random.choice is also the default option for sample config = mtn.sample(model)

original(seq)

Return an indicator (None) that can be recognized internally to sample the original choice.

Parameters:

seq (Sequence[T]) – Sequence of choices from which we want to “choose” original choice.

Returns:

None indicating to internally select the original choice from the sequence.

Return type:

None

This function can be used to sample the original subnet of a search space via mtn.sample(). The original subnet corresponds to the model architecture before the conversion process.

Example: .. code-block:: python

from modelopt.torch.nas import random import modelopt.torch.nas as mtn

# Sample the original subnet of a converted model config = mtn.sample(model, random.original)

random()

Generate a random number from [0, 1) with a deterministic seed.

Return type:

float

sample(*args, **kwargs)

Sample elements from a given population with a deterministic seed.

shuffle(seq)

Shuffle the sequence in-place with a deterministic seed.

Parameters:

seq (MutableSequence[Any]) –