This code should work:
a  = torch.Tensor([-1,4,6,3,-1,-1])
valid_idx = (a!=-1).nonzero().view(-1)
choice = torch.multinomial(valid_idx.float(), 1)
a[valid_idx[choice]]

I’m not sure if it’s more efficient than just calling torch.randint(0, a.size(0), (1,)) in a while loop to skip the -1 entries. It might depend on the ratio between valid and invalid entries.