trainer_utils

Utilities for the Trainer class.

class TrainOutput(global_step, training_loss, metrics)[source]

Bases: tuple

global_step: int

Alias for field number 0

training_loss: float

Alias for field number 1

metrics: Dict[str, float]

Alias for field number 2

class PredictionOutput(predictions, label_ids, metrics)[source]

Bases: tuple

predictions: Union[numpy.ndarray, Tuple[numpy.ndarray]]

Alias for field number 0

label_ids: Optional[Union[numpy.ndarray, Tuple[numpy.ndarray]]]

Alias for field number 1

metrics: Optional[Dict[str, float]]

Alias for field number 2

class EvalPrediction(predictions: Union[numpy.ndarray, Tuple[numpy.ndarray]], label_ids: Union[numpy.ndarray, Tuple[numpy.ndarray]])[source]

Bases: tuple

Evaluation output (always contains labels), to be used to compute metrics.

Parameters
  • predictions (np.ndarray) – Predictions of the model.

  • label_ids (np.ndarray) – Targets to be matched.

predictions: Union[numpy.ndarray, Tuple[numpy.ndarray]]

Alias for field number 0

label_ids: Union[numpy.ndarray, Tuple[numpy.ndarray]]

Alias for field number 1

class IntervalStrategy(value)[source]

Bases: paddlenlp.trainer.trainer_utils.ExplicitEnum

An enumeration.

class SchedulerType(value)[source]

Bases: paddlenlp.trainer.trainer_utils.ExplicitEnum

An enumeration.

speed_metrics(split, start_time, num_samples=None, num_steps=None)[source]

Measure and return speed performance metrics.

This function requires a time snapshot start_time before the operation to be measured starts and this function should be run immediately after the operation to be measured has completed.

Args:

  • split: name to prefix metric (like train, eval, test…)

  • start_time: operation start time

  • num_samples: number of samples processed

get_scheduler(name: Union[str, paddlenlp.trainer.trainer_utils.SchedulerType], learning_rate: float, num_warmup_steps: Optional[int] = None, num_training_steps: Optional[int] = None)[source]

Unified API to get any scheduler from its name. :param name: The name of the scheduler to use. :type name: str or SchedulerType :param learning_rate: The initial learning rate. It is a python float number. :type learning_rate: float :param num_warmup_steps: The number of warmup steps to do. This is not required by all schedulers (hence the argument being

optional), the function will raise an error if it’s unset and the scheduler type requires it.

Parameters

num_training_steps (int`, optional) – The number of training steps to do. This is not required by all schedulers (hence the argument being optional), the function will raise an error if it’s unset and the scheduler type requires it.