� %�g���b�ddlZddlZddlZddlmZGd�dej��Zd dedefd�ZdS) �N�)� PartialStatec�`�eZdZdZed���Zd�Zejd��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|jS)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�tjikrtd���|�dd��}|�dd��}|�dd��|�|��r�|�|��r2|�||��\}}|jj ||g|�Ri|��dS|rvt��}t|j ��D]U}||j kr0|�||��\}}|jj ||g|�Ri|��|� ���RdSdSdS) 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 rr �is r rzMultiProcessAdapter.log&s��� � %�� +� +��S��� �#�J�J�':�D�A�A���:�:�j�%�0�0�����,��*�*�*� � � �U� #� #� .���� 1�2�2� .�"�l�l�3��7�7� ��V��� ���s�<�T�<�<�<�V�<�<�<�<�<�� .�$�����u�2�3�3�.�.�A��E�/�/�/�&*�l�l�3��&?�&?� ��V�'�� ���s�D�T�D�D�D�V�D�D�D��+�+�-�-�-�-� .� .�  .� .�.�.r Nc� �|j|i|��dS)a� This method is identical to `logger.warning()`, but will emit the warning with the same message only once Note: The cache is for the function arguments, so 2 different callers using the same arguments will hit the cache. The assumption here is that all warning messages are unique across the code. If they aren't then need to switch to another type of cache that includes the caller frame information in the hashing function. N)�warning)rr!r"s r � warning_oncez MultiProcessAdapter.warning_onceIs!�� �� �d�%�f�%�%�%�%�%r ) �__name__� __module__� __qualname__�__doc__� staticmethodr r� functools� lru_cacher&�r r rrsu���������V�V��\�V� !.�!.�!.�F�Y�����&�&���&�&�&r r�name� log_levelc�8�|� tj�dd��}tj|��}|�S|�|�����|j�|�����t|i��S)a< Returns a `logging.Logger` for `name` that can handle multiprocessing. If a log should be called on all processes, pass `main_process_only=False` If a log should be called on all processes and in order, also pass `in_order=True` Args: name (`str`): The name for the logger, such as `__file__` log_level (`str`, *optional*): The log level to use. If not passed, will default to the `LOG_LEVEL` environment variable, or `INFO` if not Example: ```python >>> from accelerate.logging import get_logger >>> from accelerate import Accelerator >>> logger = get_logger(__name__) >>> accelerator = Accelerator() >>> logger.info("My log", main_process_only=False) >>> logger.debug("My log", main_process_only=True) >>> logger = get_logger(__name__, log_level="DEBUG") >>> logger.info("My log") >>> logger.debug("My second log") >>> array = ["a", "b", "c", "d"] >>> letter_at_rank = array[accelerator.process_index] >>> logger.info(letter_at_rank, in_order=True) ``` N�ACCELERATE_LOG_LEVEL) �os�environ�get�logging� getLogger�setLevel�upper�rootr)r/r0rs r � get_loggerr;Us���D���J�N�N�#9�4�@�@� � � �t� $� $�F������ ���)�)�*�*�*�� ���Y�_�_�.�.�/�/�/� �v�r� *� *�*r )N) r,r6r3r r� LoggerAdapterr�strr;r.r r �<module>r>s����������� � � � �������<&�<&�<&�<&�<&�'�/�<&�<&�<&�~(+�(+�S�(+�S�(+�(+�(+�(+�(+�(+r
Memory