Solved by ptrblck in post #2 
              
              
                Your code works for me in 1.11.0.dev20211101+cu113. Which PyTorch version are you using? 
If an older one, could you update to the latest nightly binary and check if this issue might have been already fixed?