o
    ci                     @   s   U d dl Z d dlZd dlmZ d dlmZmZmZ d dlZd dl	m
Z
 d dlmZ d dlmZmZ e eZdaeeeef  ed< e Zdeeef fd	d
ZdededefddZeG dd deZG dd deZdS )    N)	dataclass)AnyDictOptional)get_address_and_port)WorkerGroup)BackendBackendConfig_lightgbm_network_paramsreturnc                   C   sP   t  tstd i W  d   S t W  d   S 1 s!w   Y  dS )zGReturns the network parameters to enable LightGBM distributed training.a  `ray.train.lightgbm.get_network_params` was called outside the context of a `ray.train.lightgbm.LightGBMTrainer`. The current process has no knowledge of the distributed training worker group, so this method will return an empty dict. Please call this within the training loop of a `ray.train.lightgbm.LightGBMTrainer`. If you are in fact calling this within a `LightGBMTrainer`, this is unexpected: please file a bug report to the Ray Team.N)_lightgbm_network_params_lockr
   loggerwarningcopy r   r   M/home/ubuntu/.local/lib/python3.10/site-packages/ray/train/lightgbm/config.pyget_network_params   s   
$r   num_machineslocal_listen_portmachinesc                 C   sH   t  td u sJ dt| ||daW d    d S 1 sw   Y  d S )Nz0LightGBM network params are already initialized.r   r   r   )r   r
   dictr   r   r   r   _set_network_params(   s   
"r   c                   @   s   e Zd ZdZedd ZdS )LightGBMConfiga
  Configuration for LightGBM distributed data-parallel training setup.

    See the LightGBM docs for more information on the "network parameters"
    that Ray Train sets up for you:
    https://lightgbm.readthedocs.io/en/latest/Parameters.html#network-parameters
    c                 C   s   t S )N)_LightGBMBackend)selfr   r   r   backend_clsC   s   zLightGBMConfig.backend_clsN)__name__
__module____qualname____doc__propertyr   r   r   r   r   r   :   s    r   c                   @   s   e Zd ZdedefddZdS )r   worker_groupbackend_configc                    s^    t}dd |D ddd |D  tt fddttD  d S )Nc                 S   s   g | ]\}}|qS r   r   ).0_portr   r   r   
<listcomp>M   s    z6_LightGBMBackend.on_training_start.<locals>.<listcomp>,c                 S   s   g | ]\}}| d | qS ):r   )r$   node_ipr&   r   r   r   r'   O   s    c              	      s"   g | ]} |t|  qS r   )execute_single_asyncr   )r$   rankr   r   portsr"   r   r   r'   S   s    )executer   joinlenraygetrange)r   r"   r#   node_ips_and_portsr   r-   r   on_training_startI   s   

z"_LightGBMBackend.on_training_startN)r   r   r   r   r   r6   r   r   r   r   r   H   s    r   )logging	threadingdataclassesr   typingr   r   r   r2   ray.train._internal.utilsr    ray.train._internal.worker_groupr   ray.train.backendr   r	   	getLoggerr   r   r
   str__annotations__Lockr   r   intr   r   r   r   r   r   r   <module>   s,   
 

