MCPcopy Index your code
hub / github.com/MotrixLab/MotionDiffuse / sample

Method sample

text2motion/models/gaussian_diffusion.py:47–62  ·  view source on GitHub ↗

Importance-sample timesteps for a batch. :param batch_size: the number of timesteps. :param device: the torch device to save to. :return: a tuple (timesteps, weights): - timesteps: a tensor of timestep indices. - weights: a tensor of

(self, batch_size, device)

Source from the content-addressed store, hash-verified

45 """
46
47 def sample(self, batch_size, device):
48 """
49 Importance-sample timesteps for a batch.
50 :param batch_size: the number of timesteps.
51 :param device: the torch device to save to.
52 :return: a tuple (timesteps, weights):
53 - timesteps: a tensor of timestep indices.
54 - weights: a tensor of weights to scale the resulting losses.
55 """
56 w = self.weights()
57 p = w / np.sum(w)
58 indices_np = np.random.choice(len(p), size=(batch_size,), p=p)
59 indices = th.from_numpy(indices_np).long().to(device)
60 weights_np = 1 / (len(p) * p[indices_np])
61 weights = th.from_numpy(weights_np).float().to(device)
62 return indices, weights
63
64
65class UniformSampler(ScheduleSampler):

Callers 1

forwardMethod · 0.80

Calls 2

weightsMethod · 0.95
toMethod · 0.80

Tested by

no test coverage detected