Solved by martinr in post #2 
              
              
                OK, I have now solved the issue in a sense that I know what caused the issue and fixed it. I created a new tensor using .new_empty() which worked fine on CPU where I developed the code and also on the first iteration on GPU. But this was the source of the problem. When I changed the code to use .new…