One tricky idea has come up. However this is not smart and not effective.
import torch

n_dim0, n_dim1 = 4, 100
threshold = 0.5

storage = torch.rand((n_dim0, n_dim1))
mask = (threshold < storage)

print('storage:', storage.shape)  # [4, 100]
print('mask:   ', mask.shape)     # [4, 100]

mask_lens = torch.sum(mask, axis=1)   # [4]
max_mask_lens = torch.max(mask_lens)  # [1]

# Create mask indices
mask_idxs = torch.nonzero(mask)  # [X, 2]  (2 == storage.ndim)

# Append padding to `mask_idxs`
pad_sizes = max_mask_lens - mask_lens
pads = []
for row_idx, pad_size in enumerate(pad_sizes):
    pad = torch.zeros((pad_size, storage.ndim), dtype=torch.long)
    pad[:, 0] = row_idx
    pads.append(pad)
mask_idxs = torch.cat([mask_idxs] + pads, axis=0)

# Sort `mask_idxs` by first element
mask_idxs_argssort = torch.argsort(mask_idxs[:, 0])
mask_idxs = mask_idxs[mask_idxs_argssort]

# Masking
masked = storage[mask_idxs[:, 0], mask_idxs[:, 1]]

# Restore original dimension
masked = masked.reshape(n_dim0, -1)

print('masked: ', masked.shape)  # [4, X]  (X is around 50)