|
30 | 30 | DataCollator, |
31 | 31 | PreTrainedModel, |
32 | 32 | PreTrainedTokenizerBase, |
33 | | - ProcessorMixin, |
34 | 33 | ) |
35 | 34 | from transformers.data.data_collator import DataCollatorMixin |
36 | 35 | from transformers.trainer_callback import TrainerCallback |
37 | 36 | from transformers.trainer_utils import EvalPrediction |
38 | 37 | from transformers.utils import is_peft_available |
39 | 38 |
|
40 | | -from ..data_utils import maybe_apply_chat_template |
41 | 39 | from ..models import prepare_peft_model |
42 | 40 | from .base_trainer import BaseTrainer |
43 | 41 | from .reward_config import RewardConfig |
44 | | -from .utils import ( |
45 | | - RewardDataCollatorWithPadding, |
46 | | - compute_accuracy, |
47 | | - decode_and_strip_padding, |
48 | | - disable_dropout_in_model, |
49 | | - log_table_to_comet_experiment, |
50 | | - print_rich_table, |
51 | | -) |
52 | | - |
| 42 | +from .utils import disable_dropout_in_model |
53 | 43 |
|
54 | 44 | if is_peft_available(): |
55 | 45 | from peft import PeftConfig, PeftModel |
@@ -260,6 +250,7 @@ class RewardTrainer(BaseTrainer): |
260 | 250 |
|
261 | 251 | _tag_names = ["trl", "reward-trainer"] |
262 | 252 | _name = "Reward" |
| 253 | + _template_file = "rm_model_card.md" |
263 | 254 |
|
264 | 255 | def __init__( |
265 | 256 | self, |
@@ -600,58 +591,3 @@ def _save_checkpoint(self, model, trial): |
600 | 591 | model_name = self.args.hub_model_id.split("/")[-1] |
601 | 592 | self.create_model_card(model_name=model_name) |
602 | 593 | super()._save_checkpoint(model, trial) |
603 | | - |
604 | | - def create_model_card( |
605 | | - self, |
606 | | - model_name: Optional[str] = None, |
607 | | - dataset_name: Optional[str] = None, |
608 | | - tags: Union[str, list[str], None] = None, |
609 | | - ): |
610 | | - """ |
611 | | - Creates a draft of a model card using the information available to the `Trainer`. |
612 | | -
|
613 | | - Args: |
614 | | - model_name (`str`, *optional*): |
615 | | - Name of the model. |
616 | | - dataset_name (`str`, *optional*): |
617 | | - Name of the dataset used for training. |
618 | | - tags (`str`, `list[str]`, *optional*): |
619 | | - Tags to be associated with the model card. |
620 | | - """ |
621 | | - if not self.is_world_process_zero(): |
622 | | - return |
623 | | - |
624 | | - if hasattr(self.model.config, "_name_or_path") and not os.path.isdir(self.model.config._name_or_path): |
625 | | - base_model = self.model.config._name_or_path |
626 | | - else: |
627 | | - base_model = None |
628 | | - |
629 | | - # normalize `tags` to a mutable set |
630 | | - if tags is None: |
631 | | - tags = set() |
632 | | - elif isinstance(tags, str): |
633 | | - tags = {tags} |
634 | | - else: |
635 | | - tags = set(tags) |
636 | | - |
637 | | - if hasattr(self.model.config, "unsloth_version"): |
638 | | - tags.add("unsloth") |
639 | | - |
640 | | - if "JOB_ID" in os.environ: |
641 | | - tags.add("hf_jobs") |
642 | | - |
643 | | - tags.update(self._tag_names) |
644 | | - |
645 | | - model_card = generate_model_card( |
646 | | - base_model=base_model, |
647 | | - model_name=model_name, |
648 | | - hub_model_id=self.hub_model_id, |
649 | | - dataset_name=dataset_name, |
650 | | - tags=list(tags), |
651 | | - wandb_url=wandb.run.url if is_wandb_available() and wandb.run is not None else None, |
652 | | - comet_url=get_comet_experiment_url(), |
653 | | - trainer_name="Reward", |
654 | | - template_file="rm_model_card.md", |
655 | | - ) |
656 | | - |
657 | | - model_card.save(os.path.join(self.args.output_dir, "README.md")) |
0 commit comments