�
%�g� � �b � d dl Z d dlZd dlZddlmZ G d� dej � � Zd dedefd�ZdS )
� N� )�PartialStatec �` � e Zd ZdZed� � � Zd� Z ej d� � d� � � Z dS )�MultiProcessAdaptera@
An adapter to assist with logging in multiprocess.
`log` takes in an additional `main_process_only` kwarg, which dictates whether it should be called on all processes
or only the main executed one. Default is `main_process_only=True`.
Does not require an `Accelerator` object to be created first.
c �6 � t � � }| p| o|j S )z Check if log should be performed)r �is_main_process)�main_process_only�states �b/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/accelerate/logging.py�_should_logzMultiProcessAdapter._should_log s$ � � ����$�$�U�):�)T�u�?T�U� c �t � t j i k rt d� � �|� dd� � }|� dd� � }|� dd� � | � |� � r�| � |� � r2| � ||� � \ }} | j j ||g|�R i |�� dS |rvt � � }t |j � � D ]U}||j k r0| � ||� � \ }} | j j ||g|�R i |�� |�
� � �RdS dS dS ) a\
Delegates logger call after checking if we should log.
Accepts a new kwarg of `main_process_only`, which will dictate whether it will be logged across all processes
or only the main executed one. Default is `True` if not passed
Also accepts "in_order", which if `True` makes the processes log one by one, in order. This is much easier to
read, but comes at the cost of sometimes needing to wait for the other processes. Default is `False` to not
break with the previous behavior.
`in_order` is ignored if `main_process_only` is passed.
z�You must initialize the accelerate state by calling either `PartialState()` or `Accelerator()` before using the logging utility.r T�in_orderF�
stacklevel� N)r �
_shared_state�RuntimeError�pop�
setdefault�isEnabledForr �process�logger�log�range�
num_processes�
process_index�wait_for_everyone) �self�level�msg�args�kwargsr r r
�is r r zMultiProcessAdapter.log&