Datasets:
Upload train_ears_granite.py with huggingface_hub
Browse files- train_ears_granite.py +25 -8
train_ears_granite.py
CHANGED
|
@@ -96,9 +96,23 @@ class Collator:
|
|
| 96 |
pids[i, :l] = a; plab[i, :l] = b; pattn[i, :l] = c
|
| 97 |
r = {"input_ids": pids, "attention_mask": pattn, "labels": plab}
|
| 98 |
if feat_b:
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
return r
|
| 103 |
|
| 104 |
|
|
@@ -111,13 +125,16 @@ def main():
|
|
| 111 |
|
| 112 |
epochs = EPOCHS
|
| 113 |
if SMOKE > 0:
|
| 114 |
-
#
|
| 115 |
-
#
|
| 116 |
-
|
| 117 |
-
|
|
|
|
| 118 |
"audio", Audio(decode=False))
|
| 119 |
-
|
| 120 |
"audio", Audio(decode=False))
|
|
|
|
|
|
|
| 121 |
epochs = 1
|
| 122 |
print(f"[smoke] train={len(train)} val={len(val)} (1 epoch)")
|
| 123 |
else:
|
|
|
|
| 96 |
pids[i, :l] = a; plab[i, :l] = b; pattn[i, :l] = c
|
| 97 |
r = {"input_ids": pids, "attention_mask": pattn, "labels": plab}
|
| 98 |
if feat_b:
|
| 99 |
+
# Mel features are variable-length [T, n_mels] — pad to batch max along
|
| 100 |
+
# time and carry a frame mask; granite-speech uses the mask to ignore
|
| 101 |
+
# padded frames and to size each example's audio-token count.
|
| 102 |
+
fmax = max(f.shape[0] for f in feat_b)
|
| 103 |
+
fdim = feat_b[0].shape[-1]
|
| 104 |
+
pf = torch.zeros((len(feat_b), fmax, fdim), dtype=feat_b[0].dtype)
|
| 105 |
+
pm = torch.zeros((len(feat_b), fmax), dtype=torch.long)
|
| 106 |
+
for i, f in enumerate(feat_b):
|
| 107 |
+
t = f.shape[0]
|
| 108 |
+
pf[i, :t] = f
|
| 109 |
+
if i < len(fmask_b):
|
| 110 |
+
m = fmask_b[i].reshape(-1)
|
| 111 |
+
pm[i, : m.shape[0]] = m.to(torch.long)
|
| 112 |
+
else:
|
| 113 |
+
pm[i, :t] = 1
|
| 114 |
+
r["input_features"] = pf
|
| 115 |
+
r["input_features_mask"] = pm
|
| 116 |
return r
|
| 117 |
|
| 118 |
|
|
|
|
| 125 |
|
| 126 |
epochs = EPOCHS
|
| 127 |
if SMOKE > 0:
|
| 128 |
+
# Stream just the first rows — genuinely avoids the full 25.6GB pull
|
| 129 |
+
# (datasets 2.21 split-slicing still downloads every shard first).
|
| 130 |
+
from datasets import Dataset
|
| 131 |
+
print(f"[load] dataset {DATASET} (smoke stream {SMOKE})")
|
| 132 |
+
st = load_dataset(DATASET, split="train", streaming=True).cast_column(
|
| 133 |
"audio", Audio(decode=False))
|
| 134 |
+
sv = load_dataset(DATASET, split="validation", streaming=True).cast_column(
|
| 135 |
"audio", Audio(decode=False))
|
| 136 |
+
train = Dataset.from_list(list(st.take(SMOKE)))
|
| 137 |
+
val = Dataset.from_list(list(sv.take(64)))
|
| 138 |
epochs = 1
|
| 139 |
print(f"[smoke] train={len(train)} val={len(val)} (1 epoch)")
|
| 140 |
else:
|