Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversational dataset support for KTOTrainer #2248

Merged
merged 19 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
get_batch_sample -> generate_from_model[_and_ref]
qgallouedec committed Oct 18, 2024
commit 979c5c5e171fd1280d311e38ab36937622e64cc9
4 changes: 2 additions & 2 deletions trl/trainer/bco_trainer.py
Original file line number Diff line number Diff line change
@@ -1290,7 +1290,7 @@ def _get_train_sampler(self) -> Optional[torch.utils.data.Sampler]:
return None
return SequentialSampler(self.train_dataset)

def get_batch_samples(self, model, batch: Dict[str, torch.LongTensor]) -> Tuple[str, str]:
def generate_from_model_and_ref(self, model, batch: Dict[str, torch.LongTensor]) -> Tuple[str, str]:
"""Generate samples from the model and reference model for the given batch of inputs."""

# If one uses `generate_during_eval` with peft + bf16, we need to explicitly call generate with
@@ -1407,7 +1407,7 @@ def evaluation_loop(
"prompt_attention_mask": itemgetter(*target_indicies)(random_batch["prompt_attention_mask"]),
"prompt": itemgetter(*target_indicies)(random_batch["prompt"]),
}
policy_output_decoded, ref_output_decoded = self.get_batch_samples(self.model, target_batch)
policy_output_decoded, ref_output_decoded = self.generate_from_model_and_ref(self.model, target_batch)

self.log(
{
4 changes: 2 additions & 2 deletions trl/trainer/cpo_trainer.py
Original file line number Diff line number Diff line change
@@ -847,7 +847,7 @@ def compute_loss(
return (loss, metrics)
return loss

def get_batch_samples(self, model, batch: Dict[str, torch.LongTensor]) -> Tuple[str, str]:
def generate_from_model(self, model, batch: Dict[str, torch.LongTensor]) -> Tuple[str, str]:
"""Generate samples from the model and reference model for the given batch of inputs."""

# If one uses `generate_during_eval` with peft + bf16, we need to explicitly call generate with
@@ -938,7 +938,7 @@ def evaluation_loop(
random_batch = self.data_collator(random_batch_dataset)
random_batch = self._prepare_inputs(random_batch)

policy_output_decoded = self.get_batch_samples(self.model, random_batch)
policy_output_decoded = self.generate_from_model(self.model, random_batch)

self.log(
{
4 changes: 2 additions & 2 deletions trl/trainer/dpo_trainer.py
Original file line number Diff line number Diff line change
@@ -1561,7 +1561,7 @@ def compute_loss(
return (loss, metrics)
return loss

def get_batch_samples(self, model, batch: Dict[str, torch.LongTensor]) -> Tuple[str, str]:
def generate_from_model_and_ref(self, model, batch: Dict[str, torch.LongTensor]) -> Tuple[str, str]:
"""Generate samples from the model and reference model for the given batch of inputs."""

# If one uses `generate_during_eval` with peft + bf16, we need to explicitly call generate with
@@ -1672,7 +1672,7 @@ def evaluation_loop(
random_batch = self.data_collator(random_batch_dataset)
random_batch = self._prepare_inputs(random_batch)

policy_output_decoded, ref_output_decoded = self.get_batch_samples(self.model, random_batch)
policy_output_decoded, ref_output_decoded = self.generate_from_model_and_ref(self.model, random_batch)

self.log(
{
4 changes: 2 additions & 2 deletions trl/trainer/kto_trainer.py
Original file line number Diff line number Diff line change
@@ -1264,7 +1264,7 @@ def _get_train_sampler(self) -> Optional[torch.utils.data.Sampler]:
return None
return SequentialSampler(self.train_dataset)

def get_batch_samples(self, model, batch: Dict[str, torch.LongTensor]) -> Tuple[str, str]:
def generate_from_model_and_ref(self, model, batch: Dict[str, torch.LongTensor]) -> Tuple[str, str]:
"""Generate samples from the model and reference model for the given batch of inputs."""

# If one uses `generate_during_eval` with peft + bf16, we need to explicitly call generate with
@@ -1383,7 +1383,7 @@ def evaluation_loop(
"prompt_attention_mask": random_batch["prompt_attention_mask"][target_indicies],
"prompt": itemgetter(*target_indicies)(random_batch["prompt"]),
}
policy_output_decoded, ref_output_decoded = self.get_batch_samples(self.model, target_batch)
policy_output_decoded, ref_output_decoded = self.generate_from_model_and_ref(self.model, target_batch)

self.log(
{
4 changes: 2 additions & 2 deletions trl/trainer/orpo_trainer.py
Original file line number Diff line number Diff line change
@@ -866,7 +866,7 @@ def compute_loss(
return (loss, metrics)
return loss

def get_batch_samples(self, model, batch: Dict[str, torch.LongTensor]) -> Tuple[str, str]:
def generate_from_model(self, model, batch: Dict[str, torch.LongTensor]) -> Tuple[str, str]:
"""Generate samples from the model and reference model for the given batch of inputs."""

# If one uses `generate_during_eval` with peft + bf16, we need to explicitly call generate with
@@ -957,7 +957,7 @@ def evaluation_loop(
random_batch = self.data_collator(random_batch_dataset)
random_batch = self._prepare_inputs(random_batch)

policy_output_decoded = self.get_batch_samples(self.model, random_batch)
policy_output_decoded = self.generate_from_model(self.model, random_batch)

self.log(
{