2020 the huggingface team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license args sortishsampler bool optional defaults to false whether to use a sortish sampler or not only possible if the underlying datasets are seq2seqdataset for now but will become generally available in the near future it sorts the inputs according to lengths in order to minimize the padding size with a bit of randomness for the training set predictwithgenerate bool optional defaults to false whether to use generate to calculate generative metrics rouge bleu generationmaxlength int optional the maxlength to use on each evaluation loop when predictwithgeneratetrue will default to the maxlength value of the model configuration generationnumbeams int optional the numbeams to use on each evaluation loop when predictwithgeneratetrue will default to the numbeams value of the model configuration generationconfig str or path or generation generationconfig optional allows to load a generation generationconfig from the frompretrained method this can be either a string the model id of a pretrained model configuration hosted inside a model repo on huggingface co valid model ids can be located at the rootlevel like bertbaseuncased or namespaced under a user or organization name like dbmdzbertbasegermancased a path to a directory containing a configuration file saved using the generationconfig savepretrained method e g mymodeldirectory a generation generationconfig object serializes this instance while replace enum by their values and generationconfig by dictionaries for json serialization support it obfuscates the token values by removing their value filter out fields that are defined as fieldinitfalse 2020 the huggingface team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license args sortish_sampler bool optional defaults to false whether to use a sortish sampler or not only possible if the underlying datasets are seq2seqdataset for now but will become generally available in the near future it sorts the inputs according to lengths in order to minimize the padding size with a bit of randomness for the training set predict_with_generate bool optional defaults to false whether to use generate to calculate generative metrics rouge bleu generation_max_length int optional the max_length to use on each evaluation loop when predict_with_generate true will default to the max_length value of the model configuration generation_num_beams int optional the num_beams to use on each evaluation loop when predict_with_generate true will default to the num_beams value of the model configuration generation_config str or path or generation generationconfig optional allows to load a generation generationconfig from the from_pretrained method this can be either a string the model id of a pretrained model configuration hosted inside a model repo on huggingface co valid model ids can be located at the root level like bert base uncased or namespaced under a user or organization name like dbmdz bert base german cased a path to a directory containing a configuration file saved using the generationconfig save_pretrained method e g my_model_directory a generation generationconfig object serializes this instance while replace enum by their values and generationconfig by dictionaries for json serialization support it obfuscates the token values by removing their value filter out fields that are defined as field init false
import logging
from dataclasses import dataclass, field
from pathlib import Path
from typing import Optional, Union

from .generation.configuration_utils import GenerationConfig
from .training_args import TrainingArguments
from .utils import add_start_docstrings


logger = logging.getLogger(__name__)


@dataclass
@add_start_docstrings(TrainingArguments.__doc__)
class Seq2SeqTrainingArguments(TrainingArguments):
    

    sortish_sampler: bool = field(default=False, metadata={"help": "Whether to use SortishSampler or not."})
    predict_with_generate: bool = field(
        default=False, metadata={"help": "Whether to use generate to calculate generative metrics (ROUGE, BLEU)."}
    )
    generation_max_length: Optional[int] = field(
        default=None,
        metadata={
            "help": (
                "The `max_length` to use on each evaluation loop when `predict_with_generate=True`. Will default "
                "to the `max_length` value of the model configuration."
            )
        },
    )
    generation_num_beams: Optional[int] = field(
        default=None,
        metadata={
            "help": (
                "The `num_beams` to use on each evaluation loop when `predict_with_generate=True`. Will default "
                "to the `num_beams` value of the model configuration."
            )
        },
    )
    generation_config: Optional[Union[str, Path, GenerationConfig]] = field(
        default=None,
        metadata={
            "help": "Model id, file path or url pointing to a GenerationConfig json file, to use during prediction."
        },
    )

    def to_dict(self):
        
        
        d = super().to_dict()
        for k, v in d.items():
            if isinstance(v, GenerationConfig):
                d[k] = v.to_dict()
        return d