With Ray Remote Task and Jobs, we can easily access the distributed computing capabilities of Ray framework to boost our workloads. When performing model training, Ray native trainers are optimized even further. Thus, the Fiat Copilot trainer module provides utilities to help users define Ray Native trainers.
XGBoost Utils
from ray.air import Resultfrom ray.data import Preprocessordefdefine_xgb_trainer_and_fit(dataset:dict,# {"train": ..., "test": ...}label_col:str,scaling_conf:dict,boost_round:int,training_params:dict,preprocess_pipeline: Preprocessor,)-> Result
You can use the util function define_xgb_trainer_and_fit to get a Ray trained Result object. It has the following attributes -
# metrics dictresult.metrics# metrics Pandas dataframeresult.metrics_dataframe# Ray AIR checkpointresult.checkpoint
You can also directly convert a pre-trained Booster model into XGBoostCheckpoint -
With checkpoints, you can easily define your Predictor object -
Here is a complete example -
XGBoost Example
PyTorch Lightning Utils
PyTorch is one of the most popular Deep Learning framework in AI field. Fiat Copilot also provides some utilities of Torch Lightning module.
You can first define your lightning config by calling the build_lightning_config function -
Then, you can define your Ray Lightning Trainer by invoking the form_lightning_trainer function -
You can also easily define your Hyperparameter Tuner with the form_lightning_tuner function. With SyncConfig, we can syncing with external storage to persist our tuning experiments' results -
from ray.air import ScalingConfig, RunConfig, Checkpoint
def form_lightning_trainer(
ptl_config: dict[str, any],
scaling_conf: ScalingConfig,
runing_conf: RunConfig,
checkpoint: Checkpoint | None = None # Resume from a Ray AIR checkpoint or not
)