Solved by KFrank in post #2 
              
              
                Hi Pro! 

At the cost of generating a full random tensor, you could use a sentinel 
value and torch.where(): 
>>> torch.__version__
'1.7.1'
>>> t = torch.ones ((2, 1, 3, 3))
>>> sentinel = 999.9
>>> p = torch.nn.ConstantPad2d (1, sentinel)(t)
>>> torch.where (p == sentinel, torch.randn (p.shape), p)…