From 5f9dfadb19e32ab6a433b9766db0349d827f7760 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Thu, 5 Feb 2026 06:35:10 -0800 Subject: [PATCH] Fix RuntimeError not caught when torchcodec fails to load (#3987) When datasets library has torchcodec installed but FFmpeg libraries are missing, torchcodec raises a RuntimeError during import. The exception handler only caught ImportError and AttributeError, causing the error to propagate and crash Unsloth imports in environments like Colab where FFmpeg may not be installed. Co-authored-by: Daniel Han --- unsloth/import_fixes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unsloth/import_fixes.py b/unsloth/import_fixes.py index 4fbab6a94c..3def7e7e8b 100644 --- a/unsloth/import_fixes.py +++ b/unsloth/import_fixes.py @@ -1051,5 +1051,5 @@ def patch_torchcodec_audio_decoder(): from unsloth_zoo.dataset_utils import patch_torchcodec_audio_decoder as _patch _patch() - except (ImportError, AttributeError): + except (ImportError, AttributeError, RuntimeError): pass