Fix the the gradient on W.  Finally.
Fix the crash on exit with pycuda.