Optimized Torch Code a bit