Skip to content

Commit

Permalink
↩️ Revert tokenizer hotfix #2163
Browse files Browse the repository at this point in the history
  • Loading branch information
qgallouedec authored Oct 3, 2024
1 parent 1be4d86 commit d4564b7
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 80 deletions.
10 changes: 0 additions & 10 deletions trl/trainer/bco_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions trl/trainer/cpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)`.
Expand Down
10 changes: 0 additions & 10 deletions trl/trainer/dpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions trl/trainer/iterative_sft_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 0 additions & 10 deletions trl/trainer/kto_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions trl/trainer/orpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)`.
Expand Down
10 changes: 0 additions & 10 deletions trl/trainer/ppov2_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 0 additions & 10 deletions trl/trainer/rloo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d4564b7

Please sign in to comment.