CoolFace
Apppublic

DoruC/Grounded-Segment-Anything

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
training_args_seq2seq.py98 linesDownload Raw Back to transformers_4_35_0
1# Copyright 2020 The HuggingFace Team. All rights reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7#     http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14 15import logging16from dataclasses import dataclass, field17from pathlib import Path18from typing import Optional, Union19 20from .generation.configuration_utils import GenerationConfig21from .training_args import TrainingArguments22from .utils import add_start_docstrings23 24 25logger = logging.getLogger(__name__)26 27 28@dataclass29@add_start_docstrings(TrainingArguments.__doc__)30class Seq2SeqTrainingArguments(TrainingArguments):31    """32    Args:33        sortish_sampler (`bool`, *optional*, defaults to `False`):34            Whether to use a *sortish sampler* or not. Only possible if the underlying datasets are *Seq2SeqDataset*35            for now but will become generally available in the near future.36 37            It sorts the inputs according to lengths in order to minimize the padding size, with a bit of randomness38            for the training set.39        predict_with_generate (`bool`, *optional*, defaults to `False`):40            Whether to use generate to calculate generative metrics (ROUGE, BLEU).41        generation_max_length (`int`, *optional*):42            The `max_length` to use on each evaluation loop when `predict_with_generate=True`. Will default to the43            `max_length` value of the model configuration.44        generation_num_beams (`int`, *optional*):45            The `num_beams` to use on each evaluation loop when `predict_with_generate=True`. Will default to the46            `num_beams` value of the model configuration.47        generation_config (`str` or `Path` or [`~generation.GenerationConfig`], *optional*):48            Allows to load a [`~generation.GenerationConfig`] from the `from_pretrained` method. This can be either:49 50            - a string, the *model id* of a pretrained model configuration hosted inside a model repo on51              huggingface.co. Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced52              under a user or organization name, like `dbmdz/bert-base-german-cased`.53            - a path to a *directory* containing a configuration file saved using the54              [`~GenerationConfig.save_pretrained`] method, e.g., `./my_model_directory/`.55            - a [`~generation.GenerationConfig`] object.56    """57 58    sortish_sampler: bool = field(default=False, metadata={"help": "Whether to use SortishSampler or not."})59    predict_with_generate: bool = field(60        default=False, metadata={"help": "Whether to use generate to calculate generative metrics (ROUGE, BLEU)."}61    )62    generation_max_length: Optional[int] = field(63        default=None,64        metadata={65            "help": (66                "The `max_length` to use on each evaluation loop when `predict_with_generate=True`. Will default "67                "to the `max_length` value of the model configuration."68            )69        },70    )71    generation_num_beams: Optional[int] = field(72        default=None,73        metadata={74            "help": (75                "The `num_beams` to use on each evaluation loop when `predict_with_generate=True`. Will default "76                "to the `num_beams` value of the model configuration."77            )78        },79    )80    generation_config: Optional[Union[str, Path, GenerationConfig]] = field(81        default=None,82        metadata={83            "help": "Model id, file path or url pointing to a GenerationConfig json file, to use during prediction."84        },85    )86 87    def to_dict(self):88        """89        Serializes this instance while replace `Enum` by their values and `GenerationConfig` by dictionaries (for JSON90        serialization support). It obfuscates the token values by removing their value.91        """92        # filter out fields that are defined as field(init=False)93        d = super().to_dict()94        for k, v in d.items():95            if isinstance(v, GenerationConfig):96                d[k] = v.to_dict()97        return d98