diff --git a/trl/trainer/bco_trainer.py b/trl/trainer/bco_trainer.py index 91f6859656..a836e3b928 100644 --- a/trl/trainer/bco_trainer.py +++ b/trl/trainer/bco_trainer.py @@ -699,16 +699,6 @@ def make_inputs_require_grad(module, input, output): embeddings.cpu().float().numpy(), labels.cpu().numpy() ) - # Hot fix to avoid error when setting tokenizer after https://github.com/huggingface/transformers/pull/32385 - # Should be removed when fixed in transformers, or whenhttps://github.com/huggingface/trl/pull/2162 is merged. - @property - def tokenizer(self): - return self.processing_class - - @tokenizer.setter - def tokenizer(self, tokenizer): - self.processing_class = tokenizer - @property def match_underlying_distribution(self): return self.embedding_func is not None and self.embedding_tokenizer is not None diff --git a/trl/trainer/cpo_trainer.py b/trl/trainer/cpo_trainer.py index a5b0d0c28e..738f563323 100644 --- a/trl/trainer/cpo_trainer.py +++ b/trl/trainer/cpo_trainer.py @@ -330,16 +330,6 @@ def make_inputs_require_grad(module, input, output): "Your `Trainer` does not have an `accelerator` object. Consider upgrading `transformers`." ) - # Hot fix to avoid error when setting tokenizer after https://github.com/huggingface/transformers/pull/32385 - # Should be removed when fixed in transformers, or whenhttps://github.com/huggingface/trl/pull/2162 is merged. - @property - def tokenizer(self): - return self.processing_class - - @tokenizer.setter - def tokenizer(self, tokenizer): - self.processing_class = tokenizer - def build_tokenized_answer(self, prompt, answer): """ Llama tokenizer does satisfy `enc(a + b) = enc(a) + enc(b)`. diff --git a/trl/trainer/dpo_trainer.py b/trl/trainer/dpo_trainer.py index 12282856f8..bc17ffdf39 100644 --- a/trl/trainer/dpo_trainer.py +++ b/trl/trainer/dpo_trainer.py @@ -907,16 +907,6 @@ def make_inputs_require_grad(module, input, output): if self.loss_type == "bco_pair": self.running = RunningMoments(self.accelerator) - # Hot fix to avoid error when setting tokenizer after https://github.com/huggingface/transformers/pull/32385 - # Should be removed when fixed in transformers, or whenhttps://github.com/huggingface/trl/pull/2162 is merged. - @property - def tokenizer(self): - return self.processing_class - - @tokenizer.setter - def tokenizer(self, tokenizer): - self.processing_class = tokenizer - def _prepare_deepspeed(self, model: PreTrainedModelWrapper): # Adapted from accelerate: https://github.com/huggingface/accelerate/blob/739b135f8367becb67ffaada12fe76e3aa60fefd/src/accelerate/accelerator.py#L1473 deepspeed_plugin = self.accelerator.state.deepspeed_plugin diff --git a/trl/trainer/iterative_sft_trainer.py b/trl/trainer/iterative_sft_trainer.py index 8961197f15..0e0d19f08e 100644 --- a/trl/trainer/iterative_sft_trainer.py +++ b/trl/trainer/iterative_sft_trainer.py @@ -163,16 +163,6 @@ def __init__( PPODecorators.optimize_device_cache = self.optimize_device_cache - # Hot fix to avoid error when setting tokenizer after https://github.com/huggingface/transformers/pull/32385 - # Should be removed when fixed in transformers, or whenhttps://github.com/huggingface/trl/pull/2162 is merged. - @property - def tokenizer(self): - return self.processing_class - - @tokenizer.setter - def tokenizer(self, tokenizer): - self.processing_class = tokenizer - def prepare_model_inputs(self, input_ids: torch.Tensor, attention_mask: torch.Tensor, labels: torch.Tensor): if attention_mask is None: attention_mask = [torch.ones_like(ids) for ids in input_ids] diff --git a/trl/trainer/kto_trainer.py b/trl/trainer/kto_trainer.py index 8f9b44eb46..b670db9c6e 100644 --- a/trl/trainer/kto_trainer.py +++ b/trl/trainer/kto_trainer.py @@ -720,16 +720,6 @@ def make_inputs_require_grad(module, input, output): else: self.ref_model = self.accelerator.prepare_model(self.ref_model, evaluation_mode=True) - # Hot fix to avoid error when setting tokenizer after https://github.com/huggingface/transformers/pull/32385 - # Should be removed when fixed in transformers, or whenhttps://github.com/huggingface/trl/pull/2162 is merged. - @property - def tokenizer(self): - return self.processing_class - - @tokenizer.setter - def tokenizer(self, tokenizer): - self.processing_class = tokenizer - def _prepare_deepspeed(self, model: PreTrainedModelWrapper): # Adapted from accelerate: https://github.com/huggingface/accelerate/blob/739b135f8367becb67ffaada12fe76e3aa60fefd/src/accelerate/accelerator.py#L1473 deepspeed_plugin = self.accelerator.state.deepspeed_plugin diff --git a/trl/trainer/orpo_trainer.py b/trl/trainer/orpo_trainer.py index d2adece16f..7aa991ad93 100644 --- a/trl/trainer/orpo_trainer.py +++ b/trl/trainer/orpo_trainer.py @@ -351,16 +351,6 @@ def _prepare_deepspeed(self, model: PreTrainedModelWrapper): model.eval() return model - # Hot fix to avoid error when setting tokenizer after https://github.com/huggingface/transformers/pull/32385 - # Should be removed when fixed in transformers, or whenhttps://github.com/huggingface/trl/pull/2162 is merged. - @property - def tokenizer(self): - return self.processing_class - - @tokenizer.setter - def tokenizer(self, tokenizer): - self.processing_class = tokenizer - def build_tokenized_answer(self, prompt, answer): """ Llama tokenizer does satisfy `enc(a + b) = enc(a) + enc(b)`. diff --git a/trl/trainer/ppov2_trainer.py b/trl/trainer/ppov2_trainer.py index 2fb311e15b..e6fb9d70ef 100644 --- a/trl/trainer/ppov2_trainer.py +++ b/trl/trainer/ppov2_trainer.py @@ -243,16 +243,6 @@ def __init__( self.ref_policy = self.ref_policy.to(self.accelerator.device) self.reward_model = self.reward_model.to(self.accelerator.device) - # Hot fix to avoid error when setting tokenizer after https://github.com/huggingface/transformers/pull/32385 - # Should be removed when fixed in transformers, or whenhttps://github.com/huggingface/trl/pull/2162 is merged. - @property - def tokenizer(self): - return self.processing_class - - @tokenizer.setter - def tokenizer(self, tokenizer): - self.processing_class = tokenizer - def get_train_dataloader(self) -> DataLoader: return self.dataloader diff --git a/trl/trainer/rloo_trainer.py b/trl/trainer/rloo_trainer.py index dcd060ff05..516eeb4dfb 100644 --- a/trl/trainer/rloo_trainer.py +++ b/trl/trainer/rloo_trainer.py @@ -216,16 +216,6 @@ def __init__( self.ref_policy = self.ref_policy.to(self.accelerator.device) self.reward_model = self.reward_model.to(self.accelerator.device) - # Hot fix to avoid error when setting tokenizer after https://github.com/huggingface/transformers/pull/32385 - # Should be removed when fixed in transformers, or whenhttps://github.com/huggingface/trl/pull/2162 is merged. - @property - def tokenizer(self): - return self.processing_class - - @tokenizer.setter - def tokenizer(self, tokenizer): - self.processing_class = tokenizer - def get_train_dataloader(self) -> DataLoader: return self.dataloader