MCPcopy Create free account
hub / github.com/HKUDS/PromptMM / sparse_dropout

Function sparse_dropout

codes/Models.py:458–475  ·  view source on GitHub ↗

:param x: :param rate: :param noise_shape: int scalar :return:

(x, rate, noise_shape)

Source from the content-addressed store, hash-verified

456
457
458def sparse_dropout(x, rate, noise_shape):
459 """
460 :param x:
461 :param rate:
462 :param noise_shape: int scalar
463 :return:
464 """
465 random_tensor = 1 - rate
466 random_tensor += torch.rand(noise_shape).to(x.device)
467 dropout_mask = torch.floor(random_tensor).byte()
468 i = x._indices() # [2, 49216]
469 v = x._values() # [49216]
470 # [2, 4926] => [49216, 2] => [remained node, 2] => [2, remained node]
471 i = i[:, dropout_mask]
472 v = v[dropout_mask]
473 out = torch.sparse.FloatTensor(i, v, x.shape).to(x.device)
474 out = out * (1./ (1-rate))
475 return out
476
477
478def dot(x, y, sparse=False):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected