RuntimeError: Trying to backward through the graph a second time
#201
by
Sarwg
- opened
Hi all,
I was trainning my whisper model as always but i got this error, how can i fix this :
RuntimeError: Trying to backward through the graph a second time (or directly access saved tensors after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved tensors after calling backward
Btw it works when i use transformers==4.48.0
Thanks
You are a lifesaver. Love you man
Latest working release is just one version back transformers==4.52.0
So its a regression in 4.53
Confirming that I got this same runtime error today (2025-07-08). After finding this discussion, I did !pip install transformers==4.52.0 --quiet
. It started to work, but then it crashed during the first evaluation stage. I tried with version 4.48, too, as suggested above by Sarwg.