o
    1 iu                     @   s   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlm	Z	 dd Z
d	d
 ZdddZedkrWddlZe Zejdddd e \ZZejdd eejd dS dS )a2  This example demonstrates the usage of Optuna with Ray Tune.

It also checks that it is usable with a separate scheduler.

Requires the Optuna library to be installed (`pip install optuna`).

For an example of using an Optuna define-by-run function, see
:doc:`/tune/examples/optuna_define_by_run_example`.
    N)tune)AsyncHyperBandScheduler)ConcurrencyLimiter)OptunaSearchc                 C   s   d||  d  d |d  S )N皙?d    )stepwidthheightr	   r	   l/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/ray/tune/examples/optuna_example.pyevaluation_fn   s   r   c                 C   sN   | d | d }}t | d D ]}t|||}t||d td qd S )Nr   r   steps)Z
iterations	mean_lossr   )ranger   r   reporttimesleep)configr   r   r
   Zintermediate_scorer	   r	   r   easy_objective   s   r   Fc              
   C   s   t  }t|dd}t }tjttjdd||| rdndddtdd	td
dtddgdd}|	 }t
d| j d S )N   )Zmax_concurrentr   min
   r   )ZmetricmodeZ
search_alg	schedulerZnum_samplesr      iZrelutanh)r   r   r   Z
activation)Ztune_configZparam_spacez!Best hyperparameters found were: )r   r   r   r   ZTunerr   Z
TuneConfiguniformchoicefitprintZget_best_resultr   )
smoke_testalgor   Ztunerresultsr	   r	   r   run_optuna_tune$   s(   


r%   __main__z--smoke-test
store_truezFinish quickly for testing)actionhelp)Zconfigure_logging)r"   )F)__doc__r   Zrayr   Zray.tune.schedulersr   Zray.tune.searchr   Zray.tune.search.optunar   r   r   r%   __name__argparseArgumentParserparseradd_argumentparse_known_argsargs_initr"   r	   r	   r	   r   <module>   s(    

