code: def test_loggers(ray_start_4_cpus):
      from composer.core.callback import Callback
      from composer.core.state import State
      from composer.loggers import Logger
      from composer.loggers.logger_destination import LoggerDestination
  
      from ray.train.mosaic import MosaicTrainer
  
      class _CallbackExistsError(ValueError):
          pass
  
      class DummyLogger(LoggerDestination):
          def fit_start(self, state: State, logger: Logger) -> None:
              raise ValueError
  
      class DummyCallback(Callback):
          def fit_start(self, state: State, logger: Logger) -> None:
              raise _CallbackExistsError
  
      class DummyMonitorCallback(Callback):
          def fit_start(self, state: State, logger: Logger) -> None:
              logger.log_metrics({"dummy_callback": "test"})
  
      # DummyLogger should not throw an error since it should be removed before `fit` call
      trainer_init_config = {
          "max_duration": "1ep",
          "loggers": DummyLogger(),
      }
  
      trainer = MosaicTrainer(
          trainer_init_per_worker=trainer_init_per_worker,
          trainer_init_config=trainer_init_config,
          scaling_config=scaling_config,
      )
  
      trainer.fit()
  
      # DummyCallback should throw an error since it's not removed automatically.
      trainer_init_config["callbacks"] = DummyCallback()
      trainer = MosaicTrainer(
          trainer_init_per_worker=trainer_init_per_worker,
          trainer_init_config=trainer_init_config,
          scaling_config=scaling_config,
      )
  
      with pytest.raises(TrainingFailedError) as exc_info:
          trainer.fit()
      assert isinstance(exc_info.value.__cause__, _CallbackExistsError)
  
      trainer_init_config["callbacks"] = DummyMonitorCallback()
      trainer = MosaicTrainer(
          trainer_init_per_worker=trainer_init_per_worker,
          trainer_init_config=trainer_init_config,
          scaling_config=scaling_config,
      )
  
      result = trainer.fit()
  
      assert "dummy_callback" in result.metrics
      assert result.metrics["dummy_callback"] == "test"
  
file_path: ray/python/ray/train/tests/test_mosaic_trainer.py
imports: import os
  import pytest
  import torch
  import torch.utils.data
  import torchvision
  from filelock import FileLock
  from torchvision import datasets, transforms
  import ray.train
  from ray.train import ScalingConfig
  from ray.train.trainer import TrainingFailedError
label_desc: Use image node_id 3 for calling a global function with example usage: test_loggers(ray_start_4_cpus) without return types