Spaces:
Sleeping
Sleeping
jefffffff9 Claude Sonnet 4.6 commited on
Commit ·
3ed28bd
1
Parent(s): 829fd3d
Fix Cell 14: cast input_features to fp16 in collator
Browse filesModel is loaded in fp16 but the feature extractor returns float32.
Whisper's conv1 layer raises RuntimeError on the dtype mismatch.
Cast batch['input_features'] to torch.float16 in the collator.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
notebooks/kaggle_master_trainer.ipynb
CHANGED
|
@@ -149,7 +149,7 @@
|
|
| 149 |
"id": "cell-collator",
|
| 150 |
"metadata": {},
|
| 151 |
"outputs": [],
|
| 152 |
-
"source": "# -- Cell 14: Data collator + WER metric --------------------------------------\
|
| 153 |
},
|
| 154 |
{
|
| 155 |
"cell_type": "markdown",
|
|
|
|
| 149 |
"id": "cell-collator",
|
| 150 |
"metadata": {},
|
| 151 |
"outputs": [],
|
| 152 |
+
"source": "# -- Cell 14: Data collator + WER metric --------------------------------------\nimport jiwer\nfrom dataclasses import dataclass\nfrom typing import Any, Dict, List\n\ntransform = jiwer.Compose([\n jiwer.ToLowerCase(),\n jiwer.RemoveMultipleSpaces(),\n jiwer.Strip(),\n jiwer.RemovePunctuation(),\n jiwer.ReduceToListOfListOfWords(),\n])\n\n\n@dataclass\nclass DataCollatorSpeechSeq2SeqWithPadding:\n processor: Any\n\n def __call__(self, features: List[Dict]) -> Dict:\n import torch\n input_feats = [{'input_features': f['input_features']} for f in features]\n batch = self.processor.feature_extractor.pad(input_feats, return_tensors='pt')\n\n # Cast to fp16 to match the model -- avoids dtype mismatch in conv1\n batch['input_features'] = batch['input_features'].to(torch.float16)\n\n label_feats = [{'input_ids': f['labels']} for f in features]\n labels_batch = self.processor.tokenizer.pad(label_feats, return_tensors='pt')\n labels = labels_batch['input_ids'].masked_fill(\n labels_batch.attention_mask.ne(1), -100\n )\n if (labels[:, 0] == self.processor.tokenizer.bos_token_id).all().item():\n labels = labels[:, 1:]\n batch['labels'] = labels\n return batch\n\n\ndef compute_metrics(pred):\n pred_ids = pred.predictions\n label_ids = pred.label_ids\n label_ids[label_ids == -100] = processor.tokenizer.pad_token_id\n\n pred_str = processor.tokenizer.batch_decode(pred_ids, skip_special_tokens=True)\n label_str = processor.tokenizer.batch_decode(label_ids, skip_special_tokens=True)\n\n wer = jiwer.wer(label_str, pred_str,\n hypothesis_transform=transform,\n reference_transform=transform)\n return {'wer': round(wer, 4)}\n\n\ncollator = DataCollatorSpeechSeq2SeqWithPadding(processor=processor)\nprint('Collator and WER metric ready')"
|
| 153 |
},
|
| 154 |
{
|
| 155 |
"cell_type": "markdown",
|