Solved by ptrblck in post #2 
              
              
                Your code generally seems to work after fixing some minor shape issue in a (removing the unnecessary dim1). 
I also tried to run your code with 10 random seeds and all seem to converge.