Speeding up grad computation

Will this setup also be effective when I switch the interface to torch?