code: def lightgbm_ray_train_step(
      model: GBM,
      params: Dict[str, Any],
      lgb_train: "RayDMatrix",  # noqa: F821
      eval_sets: List["RayDMatrix"],  # noqa: F821
      eval_names: List[str],
      init_model: lgb.LGBMModel,
      boost_rounds_per_train_step: int,
      evals_result: Dict,
      ray_params: "RayParams",  # noqa
      evaluate_training_set: bool,
      device: Optional[str] = None,
  ) -> lgb.LGBMModel:
      # We need to add max_calls here to ensure that the Ray actors that get created by the LightGBM class
      # for each boosting round don't leave dangling resources in the object store memory.
      @ray.remote(max_calls=1)
      def lightgbm_ray_train_step_helper(
          model,
          params,
          lgb_train,
          eval_sets,
          eval_names,
          init_model,
          boost_rounds_per_train_step,
          evals_result,
          ray_params,
          evaluate_training_set,
          device,
      ) -> lgb.LGBMModel:
          """Trains a LightGBM model using ray.
  
          Args:
              model: Ludwig model
              params: parameters for LightGBM
              lgb_train: RayDMatrix dataset for training
              eval_sets: RayDMatrix datasets for evaluation
              eval_names: names of the evaluation datasets
              init_model: LightGBM model to initialize from
              boost_rounds_per_train_step: number of boosting rounds to train
              evals_result: dictionary to store evaluation results
              ray_params: RayParams object configured with num workers and resources
              evaluate_training_set: whether to evaluate the training set
              device: device to use for training
          Returns:
              gbm: LightGBM Booster model
              evals_result: dictionary containing evaluation results
          """
          from lightgbm_ray import RayLGBMClassifier, RayLGBMRegressor
  
          output_feature = get_single_output_feature(model)
          gbm_sklearn_cls = (
              RayLGBMRegressor
              if output_feature.type() == NUMBER
              else RayLGBMClassifier
          )
  
          additional_results = {}
          gbm = gbm_sklearn_cls(
              n_estimators=boost_rounds_per_train_step, **params
          ).fit(
              X=lgb_train,
              y=None,
              init_model=init_model,
              eval_set=[(s, n) for s, n in zip(eval_sets, eval_names)],
              eval_names=eval_names,
              callbacks=[
                  # add early stopping callback to populate best_iteration
                  lgb.early_stopping(boost_rounds_per_train_step),
                  store_predictions_ray(boost_rounds_per_train_step),
              ],
              additional_results=additional_results,
              ray_params=ray_params,
          )
          evals_result.update(gbm.evals_result_)
  
          if not evaluate_training_set:
              # Update evaluation metrics with current model params:
              # noisy but fast way to get metrics on the training set
  
              # Only use the first actor's predictions.
              actor_callback_return = next(
                  iter(additional_results["callback_returns"])
              )
              # Only a single TrainLogits is expected (final iteration).
              train_logits: TrainLogits = next(
                  iter(actor_callback_return)
              )
              predictions = logits_to_predictions(
                  model, train_logits.preds
              )
  
              targets = get_targets(
                  lgb_train, output_feature, device, actor_rank=0
              )
  
              # Return raw target and prediction tensors so we can update top-level
              # model metrics in the caller of the remote function.
              return gbm.to_local(), targets, predictions, evals_result
  
          return gbm.to_local(), evals_result
  
      return lightgbm_ray_train_step_helper.remote(
          model,
          params,
          lgb_train,
          eval_sets,
          eval_names,
          init_model,
          boost_rounds_per_train_step,
          evals_result,
          ray_params,
          evaluate_training_set,
          device,
      )
  
imports: import logging
  import os
  import re
  import signal
  import sys
  import threading
  import time
  from typing import Any, Dict, List, Optional, Tuple, Union
  import lightgbm
  import torch
  from torch.utils.tensorboard import SummaryWriter
  from ludwig.constants import BINARY, CATEGORY, MINIMIZE, MODEL_GBM, NUMBER, TEST, TRAINING, VALIDATION
  from ludwig.distributed import init_dist_strategy
  from ludwig.distributed.base import DistributedStrategy, LocalStrategy
  from ludwig.features.feature_utils import LudwigFeatureDict
  from ludwig.globals import is_progressbar_disabled, TRAINING_CHECKPOINTS_DIR_PATH, TRAINING_PROGRESS_TRACKER_FILE_NAME
  from ludwig.models.gbm import GBM
  from ludwig.models.predictor import Predictor
  from ludwig.modules.metric_modules import get_improved_fn, get_initial_validation_value
  from ludwig.modules.metric_registry import get_metric_objective
  from ludwig.progress_bar import LudwigProgressBar
  from ludwig.schema.trainer import BaseTrainerConfig, GBMTrainerConfig
  from ludwig.trainers.base import BaseTrainer
  from ludwig.trainers.registry import register_ray_trainer, register_trainer
  from ludwig.types import ModelConfigDict
  from ludwig.utils import time_utils
  from ludwig.utils.checkpoint_utils import CheckpointManager
  from ludwig.utils.defaults import default_random_seed
  from ludwig.utils.gbm_utils import get_single_output_feature, get_targets, log_loss_objective, logits_to_predictions, multiclass_objective, store_predictions, store_predictions_ray, TrainLogits
  from ludwig.utils.metric_utils import get_metric_names, TrainerMetric
  from ludwig.utils.metrics_printed_table import print_metrics_table
  from ludwig.utils.misc_utils import set_random_seed
  from ludwig.utils.trainer_utils import append_metrics, get_latest_metrics_dict, get_new_progress_tracker, ProgressTracker
label_desc: Use image node_id 2 for calling a global function with example usage: lightgbm_ray_train_step(model, params, lgb_train, eval_sets, eval_names, init_model, boost_rounds_per_train_step, evals_result, ray_params, evaluate_training_set, device) and returns: lightgbm_ray_train_step_helper, gbm,  evals_result, gbm,  targets,  predictions,  evals_result