:param x: :param rate: :param noise_shape: int scalar :return:
(x, rate, noise_shape)
| 456 | |
| 457 | |
| 458 | def 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 | |
| 478 | def dot(x, y, sparse=False): |
nothing calls this directly
no outgoing calls
no test coverage detected