By cavitating you create a disturbance in the water that may interfere with torpedos passive sonar.
Torpedos don't need to make contact with the hull to detonate. They are set to a range and an EM field will detect the metal hull and detonate.
So don't let them get too close. You can't out 'scissor'' them like a Spitfire..
By going deep you pass through thermal layers (water layers of different density and temperature). You need to get as fast as possible and dive. Instead of a sharp turn into the the torpedo turn away. You may be able to out run it.
Turning into them may work but if the torpedo passes close it wont matter. They just need to be close to kill you so I would turn away and run deep to out run them rather then 'avoid them'.
The best defense against torpedos is to not get spotted. Run silent, run deep...