MOH749 commited on
Commit
dd8f4ca
·
verified ·
1 Parent(s): 81da544

Upload train_ears_granite.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. 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
- r["input_features"] = torch.stack(feat_b)
100
- if fmask_b:
101
- r["input_features_mask"] = torch.stack(fmask_b)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  return r
103
 
104
 
@@ -111,13 +125,16 @@ def main():
111
 
112
  epochs = EPOCHS
113
  if SMOKE > 0:
114
- # Slice-load only the rows we need — avoids pulling the whole 25.6GB corpus
115
- # just to validate the train+push path.
116
- print(f"[load] dataset {DATASET} (smoke slice {SMOKE})")
117
- train = load_dataset(DATASET, split=f"train[:{SMOKE}]").cast_column(
 
118
  "audio", Audio(decode=False))
119
- val = load_dataset(DATASET, split="validation[:64]").cast_column(
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: