Spaces:
Sleeping
Sleeping
jefffffff9 Claude Sonnet 4.6 commited on
Commit ·
0d6357e
1
Parent(s): 5a82441
Fix Cells 2+11: unpin torch, use direct WhisperProcessor import
Browse filesCell 2: remove torch==2.11.0 and torchaudio==2.11.0 pins. Kaggle
pre-installs torch matched to its CUDA/Python environment; forcing
2.11.0 causes a torchvision version mismatch that breaks the
torch._dynamo import chain on Python 3.12.
Cell 11: import WhisperProcessor via direct module path
(transformers.models.whisper.processing_whisper) instead of the
top-level lazy loader, which triggers torchvision->torch._dynamo
and raises ImportError: cannot import name 'is_opaque_value'.
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": "#
|
| 37 |
},
|
| 38 |
{
|
| 39 |
"cell_type": "code",
|
|
@@ -111,7 +111,7 @@
|
|
| 111 |
"id": "cell-prepare",
|
| 112 |
"metadata": {},
|
| 113 |
"outputs": [],
|
| 114 |
-
"source": "#
|
| 115 |
},
|
| 116 |
{
|
| 117 |
"cell_type": "code",
|
|
|
|
| 33 |
"id": "cell-install",
|
| 34 |
"metadata": {},
|
| 35 |
"outputs": [],
|
| 36 |
+
"source": "# -- Cell 2: Install dependencies ---------------------------------------------\n# torch and torchaudio are NOT pinned here -- Kaggle pre-installs them at a\n# version matched to the system CUDA/Python. Pinning torch==2.11.0 causes a\n# torchvision version mismatch that breaks the torch._dynamo import chain.\n# All other packages are pinned to match the HF Space exactly.\n\nimport subprocess, sys\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]\n\nsubprocess.check_call([\n sys.executable, '-m', 'pip', 'install', '-q', '--upgrade', *pkgs\n])\nprint('Packages installed.')\n\nimport torch\nprint(f'torch version : {torch.__version__}')\nprint(f'CUDA available: {torch.cuda.is_available()}')"
|
| 37 |
},
|
| 38 |
{
|
| 39 |
"cell_type": "code",
|
|
|
|
| 111 |
"id": "cell-prepare",
|
| 112 |
"metadata": {},
|
| 113 |
"outputs": [],
|
| 114 |
+
"source": "# -- Cell 11: Whisper processor + prepare_dataset -----------------------------\n# Use the direct module path to avoid the top-level transformers lazy loader\n# which triggers torchvision -> torch._dynamo and breaks on Kaggle Python 3.12.\nimport numpy as np\n\ntry:\n from transformers.models.whisper.processing_whisper import WhisperProcessor\nexcept ImportError:\n from transformers import WhisperProcessor\n\nprint(f'Loading processor: {WHISPER_MODEL_ID} ...')\nprocessor = WhisperProcessor.from_pretrained(WHISPER_MODEL_ID, token=HF_TOKEN)\nprint('Processor ready')\n\n\ndef prepare_dataset(batch, text_col='transcription', lang=TRAIN_LANG):\n \"\"\"\n Unified feature-extraction for all data sources.\n Resamples audio to 16 kHz, cleans text, returns Whisper input_features + labels.\n \"\"\"\n audio = batch['audio']\n audio_array = np.array(audio['array'], dtype=np.float32)\n orig_sr = audio['sampling_rate']\n\n if orig_sr != TARGET_SR:\n try:\n import torchaudio.functional as F_audio\n import torch\n audio_array = F_audio.resample(\n torch.from_numpy(audio_array).unsqueeze(0),\n orig_sr, TARGET_SR,\n ).squeeze(0).numpy()\n except Exception:\n import librosa\n audio_array = librosa.resample(audio_array, orig_sr=orig_sr, target_sr=TARGET_SR)\n\n batch['input_features'] = processor.feature_extractor(\n audio_array, sampling_rate=TARGET_SR\n ).input_features[0]\n\n raw_text = batch.get(text_col, '') or ''\n cleaned = clean_text(str(raw_text), lang=lang)\n batch['labels'] = processor.tokenizer(cleaned).input_ids\n return batch\n\n\nprint('prepare_dataset ready')"
|
| 115 |
},
|
| 116 |
{
|
| 117 |
"cell_type": "code",
|