jefffffff9 Claude Sonnet 4.6 commited on
Commit
c3a3cb7
·
1 Parent(s): a481b98

Fix Cell 2: restart kernel after torchvision reinstall using sentinel file

Browse files

Reinstalling torchvision in-session fixes disk but not memory -- the
mismatched CUDA 12.8 build stays loaded until kernel restart.

Cell 2 now:
1. Detects if sentinel /kaggle/working/.torchvision_fixed exists
2. If not: installs correct torchvision + all packages, creates
sentinel, restarts kernel via IPython.kernel.do_shutdown(restart=True)
3. If yes: skips restart (already fixed), prints torch/CUDA version

The sentinel persists in /kaggle/working for the session so the
restart only happens once -- re-running the cell is safe.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

notebooks/kaggle_master_trainer.ipynb CHANGED
@@ -33,7 +33,7 @@
33
  "id": "cell-install",
34
  "metadata": {},
35
  "outputs": [],
36
- "source": "# -- Cell 2: Install dependencies ---------------------------------------------\nimport subprocess, sys, torch\n\n# Reinstall torchvision to match the exact torch+CUDA version Kaggle provides.\n# torchvision compiled against a different CUDA major version breaks any import\n# that touches torchvision (including WhisperProcessor via image_utils).\ntorch_ver = torch.__version__.split('+')[0] # e.g. \"2.6.0\"\ncuda_tag = 'cu' + torch.version.cuda.replace('.', '')[:3] # e.g. \"cu130\"\ntv_wheel = f'torchvision --index-url https://download.pytorch.org/whl/{cuda_tag}'\nprint(f'Reinstalling torchvision for torch={torch_ver}, cuda={cuda_tag} ...')\nsubprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q',\n '--upgrade', 'torchvision',\n '--index-url', f'https://download.pytorch.org/whl/{cuda_tag}'])\nprint('torchvision reinstalled.')\n\npkgs = [\n 'transformers==5.5.0',\n 'datasets==4.8.4',\n 'accelerate==1.13.0',\n 'evaluate==0.4.2',\n 'huggingface-hub==1.9.0',\n 'peft==0.18.1',\n 'bitsandbytes==0.49.2',\n 'librosa==0.10.2',\n 'soundfile==0.12.1',\n 'jiwer==3.0.4',\n 'numpy==2.2.4',\n 'scipy==1.15.2',\n]\nsubprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', *pkgs])\nprint('All packages installed.')\nprint(f'torch : {torch.__version__}')\nprint(f'CUDA : {torch.version.cuda}')\nprint(f'GPU : {torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"none\"}')"
37
  },
38
  {
39
  "cell_type": "code",
 
33
  "id": "cell-install",
34
  "metadata": {},
35
  "outputs": [],
36
+ "source": "# -- Cell 2: Install dependencies + fix torchvision CUDA mismatch -------------\n# Kaggle ships torchvision built against CUDA 12.8 but torch uses CUDA 13.0.\n# Any import touching torchvision (WhisperProcessor, WhisperForConditionalGeneration)\n# raises RuntimeError. The fix requires reinstalling torchvision AND restarting\n# the kernel so the new version is loaded from scratch.\n#\n# This cell uses a sentinel file so it only restarts once:\n# First run -> installs correct torchvision -> restarts kernel\n# Second run -> sentinel exists -> skips restart -> continues normally\n\nimport subprocess, sys, os\nfrom pathlib import Path\n\nSENTINEL = Path('/kaggle/working/.torchvision_fixed')\n\nif not SENTINEL.exists():\n import torch\n cuda_tag = 'cu' + torch.version.cuda.replace('.', '')[:3] # e.g. cu130\n print(f'Fixing torchvision for CUDA {cuda_tag} (will restart kernel) ...')\n\n subprocess.check_call([\n sys.executable, '-m', 'pip', 'install', '-q', '--upgrade',\n 'torchvision',\n '--index-url', f'https://download.pytorch.org/whl/{cuda_tag}',\n ])\n\n pkgs = [\n 'transformers==5.5.0', 'datasets==4.8.4', 'accelerate==1.13.0',\n 'evaluate==0.4.2', 'huggingface-hub==1.9.0', 'peft==0.18.1',\n 'bitsandbytes==0.49.2', 'librosa==0.10.2', 'soundfile==0.12.1',\n 'jiwer==3.0.4', 'numpy==2.2.4', 'scipy==1.15.2',\n ]\n subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', *pkgs])\n\n SENTINEL.touch()\n print('Packages installed. Restarting kernel to load new torchvision ...')\n import IPython\n IPython.Application.instance().kernel.do_shutdown(restart=True)\n\nelse:\n print('torchvision already fixed (sentinel exists) -- skipping restart.')\n import torch\n print(f'torch : {torch.__version__}')\n print(f'CUDA : {torch.version.cuda}')\n print(f'GPU : {torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"none\"}')\n print('Ready.')"
37
  },
38
  {
39
  "cell_type": "code",