Doc styling (#8067)
* Important files * Styling them all * Revert "Styling them all" This reverts commit 7d029395fdae8513b8281cbc2a6c239f8093503e. * Syling them for realsies * Fix syntax error * Fix benchmark_utils * More fixes * Fix modeling auto and script * Remove new line * Fixes * More fixes * Fix more files * Style * Add FSMT * More fixes * More fixes * More fixes * More fixes * Fixes * More fixes * More fixes * Last fixes * Make sphinx happy
This commit is contained in:
@@ -156,8 +156,7 @@ logger = logging.get_logger(__name__)
|
||||
|
||||
class Trainer:
|
||||
"""
|
||||
Trainer is a simple but feature-complete training and eval loop for PyTorch,
|
||||
optimized for 🤗 Transformers.
|
||||
Trainer is a simple but feature-complete training and eval loop for PyTorch, optimized for 🤗 Transformers.
|
||||
|
||||
Args:
|
||||
model (:class:`~transformers.PreTrainedModel` or :obj:`torch.nn.Module`, `optional`):
|
||||
@@ -169,18 +168,19 @@ class Trainer:
|
||||
provided by the library. You can still use your own models defined as :obj:`torch.nn.Module` as long as
|
||||
they work the same way as the 🤗 Transformers models.
|
||||
args (:class:`~transformers.TrainingArguments`, `optional`):
|
||||
The arguments to tweak for training. Will default to a basic instance of :class:`~transformers.TrainingArguments`
|
||||
with the ``output_dir`` set to a directory named `tmp_trainer` in the current directory if not provided.
|
||||
The arguments to tweak for training. Will default to a basic instance of
|
||||
:class:`~transformers.TrainingArguments` with the ``output_dir`` set to a directory named `tmp_trainer` in
|
||||
the current directory if not provided.
|
||||
data_collator (:obj:`DataCollator`, `optional`):
|
||||
The function to use to form a batch from a list of elements of :obj:`train_dataset` or
|
||||
:obj:`eval_dataset`. Will default to :func:`~transformers.default_data_collator` if no ``tokenizer`` is
|
||||
provided, an instance of :func:`~transformers.DataCollatorWithPadding` otherwise.
|
||||
The function to use to form a batch from a list of elements of :obj:`train_dataset` or :obj:`eval_dataset`.
|
||||
Will default to :func:`~transformers.default_data_collator` if no ``tokenizer`` is provided, an instance of
|
||||
:func:`~transformers.DataCollatorWithPadding` otherwise.
|
||||
train_dataset (:obj:`torch.utils.data.dataset.Dataset`, `optional`):
|
||||
The dataset to use for training. If it is an :obj:`datasets.Dataset`, columns not accepted by the
|
||||
``model.forward()`` method are automatically removed.
|
||||
eval_dataset (:obj:`torch.utils.data.dataset.Dataset`, `optional`):
|
||||
The dataset to use for evaluation. If it is an :obj:`datasets.Dataset`, columns not accepted by the
|
||||
``model.forward()`` method are automatically removed.
|
||||
``model.forward()`` method are automatically removed.
|
||||
tokenizer (:class:`PreTrainedTokenizerBase`, `optional`):
|
||||
The tokenizer used to preprocess the data. If provided, will be used to automatically pad the inputs the
|
||||
maximum length when batching inputs, and it will be saved along the model to make it easier to rerun an
|
||||
@@ -189,22 +189,20 @@ class Trainer:
|
||||
A function that instantiates the model to be used. If provided, each call to
|
||||
:meth:`~transformers.Trainer.train` will start from a new instance of the model as given by this function.
|
||||
|
||||
The function may have zero argument, or a single one containing the optuna/Ray Tune trial object, to be able to choose
|
||||
different architectures according to hyper parameters (such as layer count, sizes of inner layers, dropout probabilities etc).
|
||||
compute_metrics (:obj:`Callable[[EvalPrediction], Dict]`, `optional`):
|
||||
The function may have zero argument, or a single one containing the optuna/Ray Tune trial object, to be
|
||||
able to choose different architectures according to hyper parameters (such as layer count, sizes of inner
|
||||
layers, dropout probabilities etc). compute_metrics (:obj:`Callable[[EvalPrediction], Dict]`, `optional`):
|
||||
The function that will be used to compute metrics at evaluation. Must take a
|
||||
:class:`~transformers.EvalPrediction` and return a dictionary string to metric values.
|
||||
callbacks (List of :obj:`~transformers.TrainerCallback`, `optional`):
|
||||
A list of callbacks to customize the training loop. Will add those to the list of default callbacks
|
||||
detailed in :doc:`here <callback>`.
|
||||
:class:`~transformers.EvalPrediction` and return a dictionary string to metric values. callbacks (List of
|
||||
:obj:`~transformers.TrainerCallback`, `optional`): A list of callbacks to customize the training loop. Will
|
||||
add those to the list of default callbacks detailed in :doc:`here <callback>`.
|
||||
|
||||
If you want to remove one of the default callbacks used, use the :meth:`Trainer.remove_callback` method.
|
||||
optimizers (:obj:`Tuple[torch.optim.Optimizer, torch.optim.lr_scheduler.LambdaLR`, `optional`):
|
||||
A tuple containing the optimizer and the scheduler to use. Will default to an instance of
|
||||
optimizers (:obj:`Tuple[torch.optim.Optimizer, torch.optim.lr_scheduler.LambdaLR`, `optional`): A tuple
|
||||
containing the optimizer and the scheduler to use. Will default to an instance of
|
||||
:class:`~transformers.AdamW` on your model and a scheduler given by
|
||||
:func:`~transformers.get_linear_schedule_with_warmup` controlled by :obj:`args`.
|
||||
kwargs:
|
||||
Deprecated keyword arguments.
|
||||
:func:`~transformers.get_linear_schedule_with_warmup` controlled by :obj:`args`. kwargs: Deprecated keyword
|
||||
arguments.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
@@ -395,8 +393,8 @@ class Trainer:
|
||||
"""
|
||||
Returns the training :class:`~torch.utils.data.DataLoader`.
|
||||
|
||||
Will use no sampler if :obj:`self.train_dataset` does not implement :obj:`__len__`, a random sampler
|
||||
(adapted to distributed training if necessary) otherwise.
|
||||
Will use no sampler if :obj:`self.train_dataset` does not implement :obj:`__len__`, a random sampler (adapted
|
||||
to distributed training if necessary) otherwise.
|
||||
|
||||
Subclass and override this method if you want to inject some custom behavior.
|
||||
"""
|
||||
@@ -985,8 +983,10 @@ class Trainer:
|
||||
Additional keyword arguments passed along to :obj:`optuna.create_study` or :obj:`ray.tune.run`. For
|
||||
more information see:
|
||||
|
||||
- the documentation of `optuna.create_study <https://optuna.readthedocs.io/en/stable/reference/alias_generated/optuna.create_study.html#optuna.create_study>`__
|
||||
- the documentation of `tune.run <https://docs.ray.io/en/latest/tune/api_docs/execution.html#tune-run>`__
|
||||
- the documentation of `optuna.create_study
|
||||
<https://optuna.readthedocs.io/en/stable/reference/alias_generated/optuna.create_study.html#optuna.create_study>`__
|
||||
- the documentation of `tune.run
|
||||
<https://docs.ray.io/en/latest/tune/api_docs/execution.html#tune-run>`__
|
||||
|
||||
Returns:
|
||||
:class:`transformers.trainer_utils.BestRun`: All the information about the best run.
|
||||
@@ -1124,8 +1124,8 @@ class Trainer:
|
||||
|
||||
def is_local_master(self) -> bool:
|
||||
"""
|
||||
Whether or not this process is the local (e.g., on one machine if training in a distributed fashion on
|
||||
several machines) main process.
|
||||
Whether or not this process is the local (e.g., on one machine if training in a distributed fashion on several
|
||||
machines) main process.
|
||||
|
||||
.. warning::
|
||||
|
||||
@@ -1136,8 +1136,8 @@ class Trainer:
|
||||
|
||||
def is_local_process_zero(self) -> bool:
|
||||
"""
|
||||
Whether or not this process is the local (e.g., on one machine if training in a distributed fashion on
|
||||
several machines) main process.
|
||||
Whether or not this process is the local (e.g., on one machine if training in a distributed fashion on several
|
||||
machines) main process.
|
||||
"""
|
||||
if is_torch_tpu_available():
|
||||
return xm.is_master_ordinal(local=True)
|
||||
@@ -1146,8 +1146,8 @@ class Trainer:
|
||||
|
||||
def is_world_master(self) -> bool:
|
||||
"""
|
||||
Whether or not this process is the global main process (when training in a distributed fashion on
|
||||
several machines, this is only going to be :obj:`True` for one process).
|
||||
Whether or not this process is the global main process (when training in a distributed fashion on several
|
||||
machines, this is only going to be :obj:`True` for one process).
|
||||
|
||||
.. warning::
|
||||
|
||||
@@ -1158,8 +1158,8 @@ class Trainer:
|
||||
|
||||
def is_world_process_zero(self) -> bool:
|
||||
"""
|
||||
Whether or not this process is the global main process (when training in a distributed fashion on
|
||||
several machines, this is only going to be :obj:`True` for one process).
|
||||
Whether or not this process is the global main process (when training in a distributed fashion on several
|
||||
machines, this is only going to be :obj:`True` for one process).
|
||||
"""
|
||||
if is_torch_tpu_available():
|
||||
return xm.is_master_ordinal(local=False)
|
||||
@@ -1267,16 +1267,16 @@ class Trainer:
|
||||
"""
|
||||
Run evaluation and returns metrics.
|
||||
|
||||
The calling script will be responsible for providing a method to compute metrics, as they are
|
||||
task-dependent (pass it to the init :obj:`compute_metrics` argument).
|
||||
The calling script will be responsible for providing a method to compute metrics, as they are task-dependent
|
||||
(pass it to the init :obj:`compute_metrics` argument).
|
||||
|
||||
You can also subclass and override this method to inject custom behavior.
|
||||
|
||||
Args:
|
||||
eval_dataset (:obj:`Dataset`, `optional`):
|
||||
Pass a dataset if you wish to override :obj:`self.eval_dataset`. If it is an :obj:`datasets.Dataset`,
|
||||
columns not accepted by the ``model.forward()`` method are automatically removed. It must implement
|
||||
the :obj:`__len__` method.
|
||||
columns not accepted by the ``model.forward()`` method are automatically removed. It must implement the
|
||||
:obj:`__len__` method.
|
||||
|
||||
Returns:
|
||||
A dictionary containing the evaluation loss and the potential metrics computed from the predictions.
|
||||
@@ -1301,22 +1301,20 @@ class Trainer:
|
||||
"""
|
||||
Run prediction and returns predictions and potential metrics.
|
||||
|
||||
Depending on the dataset and your use case, your test dataset may contain labels.
|
||||
In that case, this method will also return metrics, like in :obj:`evaluate()`.
|
||||
Depending on the dataset and your use case, your test dataset may contain labels. In that case, this method
|
||||
will also return metrics, like in :obj:`evaluate()`.
|
||||
|
||||
Args:
|
||||
test_dataset (:obj:`Dataset`):
|
||||
Dataset to run the predictions on. If it is an :obj:`datasets.Dataset`, columns not accepted by the
|
||||
``model.forward()`` method are automatically removed. Has to implement the method :obj:`__len__`
|
||||
|
||||
Returns:
|
||||
`NamedTuple`:
|
||||
predictions (:obj:`np.ndarray`):
|
||||
The predictions on :obj:`test_dataset`.
|
||||
label_ids (:obj:`np.ndarray`, `optional`):
|
||||
The labels (if the dataset contained some).
|
||||
metrics (:obj:`Dict[str, float]`, `optional`):
|
||||
The potential dictionary of metrics (if the dataset contained labels).
|
||||
Returns: `NamedTuple` A namedtuple with the following keys:
|
||||
|
||||
- predictions (:obj:`np.ndarray`): The predictions on :obj:`test_dataset`.
|
||||
- label_ids (:obj:`np.ndarray`, `optional`): The labels (if the dataset contained some).
|
||||
- metrics (:obj:`Dict[str, float]`, `optional`): The potential dictionary of metrics (if the dataset
|
||||
contained labels).
|
||||
"""
|
||||
if test_dataset is not None and not isinstance(test_dataset, collections.abc.Sized):
|
||||
raise ValueError("test_dataset must implement __len__")
|
||||
@@ -1465,8 +1463,8 @@ class Trainer:
|
||||
Whether or not to return the loss only.
|
||||
|
||||
Return:
|
||||
Tuple[Optional[float], Optional[torch.Tensor], Optional[torch.Tensor]]:
|
||||
A tuple with the loss, logits and labels (each being optional).
|
||||
Tuple[Optional[float], Optional[torch.Tensor], Optional[torch.Tensor]]: A tuple with the loss, logits and
|
||||
labels (each being optional).
|
||||
"""
|
||||
has_labels = all(inputs.get(k) is not None for k in self.label_names)
|
||||
inputs = self._prepare_inputs(inputs)
|
||||
@@ -1507,9 +1505,9 @@ class Trainer:
|
||||
|
||||
def floating_point_ops(self, inputs: Dict[str, Union[torch.Tensor, Any]]):
|
||||
"""
|
||||
For models that inherit from :class:`~transformers.PreTrainedModel`, uses
|
||||
that method to compute the number of floating point operations for every backward + forward pass. If using
|
||||
another model, either implement such a method in the model or subclass and override this method.
|
||||
For models that inherit from :class:`~transformers.PreTrainedModel`, uses that method to compute the number of
|
||||
floating point operations for every backward + forward pass. If using another model, either implement such a
|
||||
method in the model or subclass and override this method.
|
||||
|
||||
Args:
|
||||
model (:obj:`nn.Module`):
|
||||
|
||||
Reference in New Issue
Block a user