This error ("Trying to backward through the graph a second time (or directly access saved tensors after they have already been freed)") is commonly caused by incompatibilities between Unsloth, transformers, and PyTorch versions, or by issues with gradient checkpointing and use_cache settings. Updating Unsloth and unsloth_zoo to the latest versions and ensuring transformers is compatible often resolves it. Also, make sure use_cache=False when using gradient checkpointing, as required by Unsloth's implementation for long context models like Llama-3.2-11B-Vision-Instruct-bnb-4bit. If the error persists, try reinstalling Unsloth and unsloth_zoo with --force-reinstall and --upgrade flags, and restart your environment before running your code again.
For more details and troubleshooting steps, see the guidance and solutions in these issues: Unsloth Issue #2866, Unsloth Issue #2434, and Unsloth Issue #2841. Would you like a step-by-step breakdown or code example for updating and configuring your environment?
Sources: