� K�g����dZddlZddlZddlmZddlZddlmZddlmZm Z da d�Z Gd�d ej ��Z d �Z Gd �d ��Zd �Zdd�ZdS)zWCustomizations of :mod:`joblib` and :mod:`threadpoolctl` tools for scikit-learn usage. �N)�update_wrapper)�ThreadpoolController�)�config_context� get_configc��t|d��r|�|��Stjdt��|S)zFHelper function that intends to attach a config to a delayed function.� with_configz�`sklearn.utils.parallel.Parallel` needs to be used in conjunction with `sklearn.utils.parallel.delayed` instead of `joblib.delayed` to correctly propagate the scikit-learn configuration to the joblib workers.)�hasattrr �warnings�warn� UserWarning)� delayed_func�configs �f/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sklearn/utils/parallel.py� _with_configrsN���|�]�+�+� ��'�'��/�/�/�� �7� � � � ���c�"��eZdZdZ�fd�Z�xZS)�Parallela�Tweak of :class:`joblib.Parallel` that propagates the scikit-learn configuration. This subclass of :class:`joblib.Parallel` ensures that the active configuration (thread-local) of scikit-learn is propagated to the parallel workers for the duration of the execution of the parallel tasks. The API does not change and you can refer to :class:`joblib.Parallel` documentation for more details. .. versionadded:: 1.3 c����t����fd�|D��}t���|��S)aHDispatch the tasks and return the results. Parameters ---------- iterable : iterable Iterable containing tuples of (delayed_function, args, kwargs) that should be consumed. Returns ------- results : list List of results of the tasks. c3�F�K�|]\}}}t|���||fV��dS�N)r)�.0r�args�kwargsrs �r� <genexpr>z$Parallel.__call__.<locals>.<genexpr>IsN����� � �*� �d�F��,�� /� /��v� >� � � � � � r)r�super�__call__)�self�iterable�iterable_with_configr� __class__s @�rrzParallel.__call__6sS����$���� � � � �.6� � � ���w�w��� 4�5�5�5r)�__name__� __module__� __qualname__�__doc__r� __classcell__)r!s@rrr)sB������� � �6�6�6�6�6�6�6�6�6rrc�F��tj����fd���}|S)a^Decorator used to capture the arguments of a function. This alternative to `joblib.delayed` is meant to be used in conjunction with `sklearn.utils.parallel.Parallel`. The latter captures the scikit- learn configuration by calling `sklearn.get_config()` in the current thread, prior to dispatching the first task. The captured configuration is then propagated and enabled for the duration of the execution of the delayed function in the joblib workers. .. versionchanged:: 1.3 `delayed` was moved from `sklearn.utils.fixes` to `sklearn.utils.parallel` in scikit-learn 1.3. Parameters ---------- function : callable The function to be delayed. Returns ------- output: tuple Tuple containing the delayed function, the positional arguments, and the keyword arguments. c�(��t���||fSr)� _FuncWrapper)rr�functions �r�delayed_functionz!delayed.<locals>.delayed_functionks����H�%�%�t�V�3�3r�� functools�wraps)r*r+s` r�delayedr/Qs;���4�_�X���4�4�4�4���4� �rc�$�eZdZdZd�Zd�Zd�ZdS)r)z:Load the global configuration before calling the function.c�>�||_t||j��dSr)r*r)rr*s r�__init__z_FuncWrapper.__init__us!�� �� ��t�T�]�+�+�+�+�+rc��||_|Sr)r)rrs rr z_FuncWrapper.with_configys���� �� rc���t|dd��}|�tjdt��i}t di|��5|j|i|��cddd��S#1swxYwYdS)Nrz�`sklearn.utils.parallel.delayed` should be used with `sklearn.utils.parallel.Parallel` to make it possible to propagate the scikit-learn configuration of the current thread to the joblib workers.�)�getattrr r r rr*)rrrrs rrz_FuncWrapper.__call__}s�����x��.�.�� �>� �M�+� � � � ��F� � %� %�f� %� %� 2� 2� �4�=�$�1�&�1�1� 2� 2� 2� 2� 2� 2� 2� 2� 2� 2� 2� 2���� 2� 2� 2� 2� 2� 2s� A�A�AN)r"r#r$r%r2r rr5rrr)r)rsG������D�D�,�,�,����2�2�2�2�2rr)c�:�t�t��atS)z1Return the global threadpool controller instance.)�_threadpool_controllerrr5rr�_get_threadpool_controllerr9�s���%�!5�!7�!7�� !�!r��blasc������fd�}|S)aDecorator to limit the number of threads used at the function level. It should be prefered over `threadpoolctl.ThreadpoolController.wrap` because this one only loads the shared libraries when the function is called while the latter loads them at import time. c�L���tj������fd���}|S)Nc���t��}|������5�|i|��cddd��S#1swxYwYdS)N)�limits�user_api)r9�limit)rr� controller�funcr?r@s ���r�wrapperzD_threadpool_controller_decorator.<locals>.decorator.<locals>.wrapper�s����3�5�5�J��!�!��(�!�C�C� -� -��t�T�,�V�,�,� -� -� -� -� -� -� -� -� -� -� -� -���� -� -� -� -� -� -s�<�A�Ar,)rCrDr?r@s` ��r� decoratorz3_threadpool_controller_decorator.<locals>.decorator�sC���� ��� � � -� -� -� -� -� -� � � -� �rr5)r?r@rEs`` r� _threadpool_controller_decoratorrF�s*���������� �r)r:r;)r%r-r r�joblib� threadpoolctlr�_configrrr8rrr/r)r9rFr5rr�<module>rJs������������$�$�$�$�$�$� � � � �.�.�.�.�.�.�0�0�0�0�0�0�0�0� �����"$6�$6�$6�$6�$6�v��$6�$6�$6�P���B2�2�2�2�2�2�2�2�8"�"�"������r
Memory