result.txt 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. (base) [root@localhost ~]# docker exec finetune-trainer bash -c 'sed -n "1400,1450p" /opt/conda/lib/python3.10/site-packages/trl/trainer/dpo_trainer.py'
  2. warnings.warn(
  3. "compute_loss is only implemented for DPODataCollatorWithPadding, and you passed a datacollator that is different than "
  4. "DPODataCollatorWithPadding - you might see unexpected behavior. Alternatively, you can implement your own prediction_step method if you are using a custom data collator"
  5. )
  6. compute_loss_context_manager = torch.cuda.amp.autocast if self._peft_has_been_casted_to_bf16 else nullcontext
  7. with compute_loss_context_manager():
  8. loss, metrics = self.get_batch_loss_metrics(model, inputs, train_eval="train")
  9. # Make sure to move the loss to the device the original accumulating loss is at back in the `Trainer` class:
  10. loss = loss.to(self.args.device)
  11. # force log the metrics
  12. self.store_metrics(metrics, train_eval="train")
  13. if return_outputs:
  14. return (loss, metrics)
  15. return loss
  16. def get_batch_samples(self, model, batch: Dict[str, torch.LongTensor]) -> Tuple[str, str]:
  17. """Generate samples from the model and reference model for the given batch of inputs."""
  18. # If one uses `generate_during_eval` with peft + bf16, we need to explicitly call generate with
  19. # the torch cuda amp context manager as some hidden states are silently casted to full precision.
  20. generate_context_manager = nullcontext if not self._peft_has_been_casted_to_bf16 else torch.cuda.amp.autocast
  21. with generate_context_manager():
  22. policy_output = model.generate(
  23. input_ids=batch["prompt_input_ids"],
  24. attention_mask=batch["prompt_attention_mask"],
  25. max_length=self.max_length,
  26. do_sample=True,
  27. pad_token_id=self.tokenizer.pad_token_id,
  28. )
  29. # if reference_output in batch use that otherwise use the reference model
  30. if "reference_output" in batch:
  31. reference_output = batch["reference_output"]
  32. else:
  33. if self.ref_model is None:
  34. with self.null_ref_context():
  35. reference_output = self.model.generate(
  36. input_ids=batch["prompt_input_ids"],
  37. attention_mask=batch["prompt_attention_mask"],
  38. max_length=self.max_length,
  39. do_sample=True,
  40. pad_token_id=self.tokenizer.pad_token_id,
  41. )
  42. else:
  43. reference_output = self.ref_model.generate(
  44. input_ids=batch["prompt_input_ids"],