Skip to content
Advertisement

Is there an efficient way to create a random bit mask in Pytorch?

I want to have a random bit mask that has some specified percent of 0s. The function I devised is:

JavaScript

To illustrate:

JavaScript

The main issue I have with this method is it requires the rate to divide the shape. I want a function that accepts an arbitrary decimal and gives approximately rate percent of 0s in the bitmask. Furthermore, I am trying to find a relatively efficient way of doing so. Hence, I would rather not move a numpy array from the CPU to the GPU. Is there an effiecient way of doing so that allows for a decimal rate?

Advertisement

Answer

For anyone running into this, this will create a bitmask with approximately 80% zero’s directly on GPU. (PyTorch 0.3)

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement