Skip to content

Register now for

# Reference for `ultralytics/utils/callbacks/raytune.py`

Note

This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/callbacks/raytune.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!

## `` ultralytics.utils.callbacks.raytune.on_fit_epoch_end

    on_fit_epoch_end(trainer)

Report training metrics to Ray Tune at epoch end when a Ray session is active.

Captures metrics from the trainer object and sends them to Ray Tune with the current epoch number, enabling hyperparameter tuning optimization. Only executes when within an active Ray Tune session.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`trainer` | `BaseTrainer` | The Ultralytics trainer object containing metrics and epochs. | required

Examples:

    >>> # Called automatically by the Ultralytics training loop
    >>> on_fit_epoch_end(trainer)

References

Ray Tune docs: https://docs.ray.io/en/latest/tune/index.html

Source code in `ultralytics/utils/callbacks/raytune.py`

    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    def on_fit_epoch_end(trainer):
        """
        Report training metrics to Ray Tune at epoch end when a Ray session is active.

        Captures metrics from the trainer object and sends them to Ray Tune with the current epoch number,
        enabling hyperparameter tuning optimization. Only executes when within an active Ray Tune session.

        Args:
            trainer (ultralytics.engine.trainer.BaseTrainer): The Ultralytics trainer object containing metrics and epochs.

        Examples:
            >>> # Called automatically by the Ultralytics training loop
            >>> on_fit_epoch_end(trainer)

        References:
            Ray Tune docs: https://docs.ray.io/en/latest/tune/index.html
        """
        if ray.train._internal.session.get_session():  # check if Ray Tune session is active
            metrics = trainer.metrics
            session.report({**metrics, **{"epoch": trainer.epoch + 1}})

📅 Created 1 year ago ✏️ Updated 1 year ago