LogosAccessibleExpression commited on
Commit
612fdf9
·
verified ·
1 Parent(s): f7e00cd

Upload logos_reward_ft_job.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. logos_reward_ft_job.py +17 -2
logos_reward_ft_job.py CHANGED
@@ -44,7 +44,6 @@ from transformers import (
44
  WhisperForConditionalGeneration,
45
  Seq2SeqTrainer,
46
  Seq2SeqTrainingArguments,
47
- DataCollatorForSeq2Seq,
48
  )
49
  from peft import LoraConfig, get_peft_model, TaskType
50
  from huggingface_hub import login
@@ -297,7 +296,23 @@ class RewardWeightedTrainer(Seq2SeqTrainer):
297
 
298
  return (weighted_loss, outputs) if return_outputs else weighted_loss
299
 
300
- collator = DataCollatorForSeq2Seq(processor.tokenizer, model=model, padding=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
 
302
  training_args = Seq2SeqTrainingArguments(
303
  output_dir = OUTPUT_DIR,
 
44
  WhisperForConditionalGeneration,
45
  Seq2SeqTrainer,
46
  Seq2SeqTrainingArguments,
 
47
  )
48
  from peft import LoraConfig, get_peft_model, TaskType
49
  from huggingface_hub import login
 
296
 
297
  return (weighted_loss, outputs) if return_outputs else weighted_loss
298
 
299
+ class WhisperRewardCollator:
300
+ """Stack input_features, pad labels with -100, pass reward_weight through."""
301
+ def __call__(self, features):
302
+ input_features = torch.tensor(
303
+ np.array([f["input_features"] for f in features]), dtype=torch.float32
304
+ )
305
+ max_len = max(len(f["labels"]) for f in features)
306
+ labels = torch.full((len(features), max_len), -100, dtype=torch.long)
307
+ for i, f in enumerate(features):
308
+ ids = torch.tensor(f["labels"], dtype=torch.long)
309
+ labels[i, :len(ids)] = ids
310
+ reward_weight = torch.tensor(
311
+ [f["reward_weight"] for f in features], dtype=torch.float32
312
+ )
313
+ return {"input_features": input_features, "labels": labels, "reward_weight": reward_weight}
314
+
315
+ collator = WhisperRewardCollator()
316
 
317
  training_args = Seq2SeqTrainingArguments(
318
  output_dir = OUTPUT_DIR,