
    h              	       b    S SK JrJrJrJr  S SKJrJrJrJ	r	J
r
Jr      S	S\S\S\S\4S jjrg)
    )	TASK2DATATASK2METRICget_cfgget_save_dir)DEFAULT_CFGDEFAULT_CFG_DICTLOGGERNUM_THREADScheckscolorstrNspacegrace_periodgpu_per_trialmax_samplesc                 0	  ^^^ [         R                  " S5        Tc  0 m [        R                  " S5        SSKmSSKJn  SSKJn  SSKJ	n  SSK
Jn	   SSKn
[        U
S
5      (       d   e [        R"                  " TR$                  SS5        0 SUR'                  SS5      _SUR'                  SS5      _SUR'                  SS5      _SUR'                  SS5      _SUR'                  SS5      _SUR'                  SS5      _SUR'                  SS 5      _S!UR'                  S S"5      _S#UR'                  SS5      _S$UR'                  SS%5      _S&UR'                  SS%5      _S'UR'                  SS(5      _S)UR'                  SS%5      _S*UR'                  SS%5      _S+UR'                  SS,5      _S-UR'                  SS5      _S.UR'                  SS5      _UR'                  SS5      UR'                  SS5      UR'                  SS5      UR'                  SS5      UR'                  SS5      UR'                  SS5      S/.EnU R(                  nTR+                  U 5      mUUU4S0 jnU(       d.  TR-                  S15      (       d  Un[         R.                  " S25        TR-                  S3[0        U   5      nXS3'   S3T;  a  [         R.                  " S4U S535        UR3                  U[4        U=(       d    SS6.5      nU	" S7[6        U   S8TR-                  S95      =(       d    [8        S9   =(       d    S:US;S<9nU
(       a  U" S=S>9/O/ n[;        [=        [>        0 TES?TRA                  S1S5      0E5      TRA                  S@SA5      SB9nURC                  SCSCSD9  URD                  RG                  U5      (       aJ  [         R                  " [I        SE5       SFU SG35        URD                  RK                  [M        U5      USCSH9nO>URE                  UUURO                  UUSI SJ SK9U" UURP                  URR                  SL9SM9nURU                  5         URW                  5       nTRY                  5         U$ ! [         a    [        S	5      ef = f! [        [         4 a    Sn
 GN)f = f)NaV  
Run hyperparameter tuning using Ray Tune.

Args:
    model (YOLO): Model to run the tuner on.
    space (dict, optional): The hyperparameter search space. If not provided, uses default space.
    grace_period (int, optional): The grace period in epochs of the ASHA scheduler.
    gpu_per_trial (int, optional): The number of GPUs to allocate per trial.
    max_samples (int, optional): The maximum number of trials to run.
    **train_args (Any): Additional arguments to pass to the `train()` method.

Returns:
    (ray.tune.ResultGrid): A ResultGrid containing the results of the hyperparameter search.

Examples:
    >>> from ultralytics import YOLO
    >>> model = YOLO("yolo11n.pt")  # Load a YOLO11n model

    Start tuning hyperparameters for YOLO11n training on the COCO8 dataset
    >>> result_grid = model.tune(data="coco8.yaml", use_ray=True)
uN   💡 Learn about RayTune at https://docs.ultralytics.com/integrations/ray-tuneNz	ray[tune]r   )tune)	RunConfig)WandbLoggerCallback)ASHASchedulerzHRay Tune required but not found. To install run: pip install "ray[tune]"__version__Fz>=2.0.0raylr0gh㈵>g?lrfg{Gz?g      ?momentumg333333?g\(\?weight_decayg        gMbP?warmup_epochsg      @warmup_momentumgffffff?boxg{Gz?g?clsg      @hsv_hhsv_sg?hsv_vdegreesg     F@	translatescaleshearg      $@perspectiveflipud)fliplrbgrmosaicmixupcutmix
copy_pastec                    > TR                  T5      nUR                  5         U R                  T5        UR                  " S0 U D6nUR                  $ )zKTrain the YOLO model with the specified hyperparameters and return results. )getreset_callbacksupdatetrainresults_dict)configmodel_to_trainresultsmodel_in_storer   
train_argss      Q/home/james-whalen/.local/lib/python3.13/site-packages/ultralytics/utils/tuner.py_tunerun_ray_tune.<locals>._tuneZ   sH    0&&(j! &&00###    resumez6Search space not provided, using default search space.dataz'Data not provided, using default "data=z".)cpugpuepochmaxepochsd      )	time_attrmetricmodemax_tr   reduction_factorzYOLOv8-tune)projectexist_oknamer   )rO   T)parentsrN   zTuner: z Resuming tuning run z...)	trainableresume_erroredc                 8    U R                    SU R                   3$ N_trainable_nametrial_idtrials    r;   <lambda>run_ray_tune.<locals>.<lambda>   s    E4H4H3I5>>JZ1[r>   c                 8    U R                    SU R                   3$ rT   rV   rY   s    r;   r[   r\      s    u7K7K6LAennM]4^r>   )	schedulernum_samplestrial_name_creatortrial_dirname_creator)	callbacksstorage_pathrO   )param_spacetune_config
run_config)-r	   infor   check_requirementsr   r   ray.airr   ray.air.integrations.wandbr   ray.tune.schedulersr   ImportErrorModuleNotFoundErrorwandbhasattrAssertionErrorcheck_versionr   uniformtaskputr1   warningr   with_resourcesr
   r   r   r   r   r   popmkdirTunercan_restorer   restorestr
TuneConfigparentrO   fitget_resultsshutdown)modelr   r   r   r   r:   r   r   r   r   rn   default_spacers   r<   r@   trainable_with_resourcesasha_schedulertuner_callbackstune_dirtunerr8   r9   r   s        `               @@r;   run_ray_tuner      s   : KK`a
	n!!+.%B5um,,,, )U;t||D$' 	t||D#& 	DLLd+	
 	S%0 	c3/ 	4<<T2 	t||D#& 	t||C% 	c3' 	c3' 	c3' 	4<<T* 	T\\#s+ 	c3'  	c4(!" 	t||C/#$ 	$,,sC(%& ,,sC(||C%,,sC(c3',,sC(ll3,1M8 ::DWWU^N$ 11OP >>&)D/2D&MZ@bIJ  $225+VcVhgh:ij #4 nnX&K*:8*DK!N GL*=ABQSO KzKj*..5*IJK	
 ^^FF+H NN4$N/zzh''x	*++@
#NO

""3x=<Tei"j

$('#[&^	 (  !?_g_l_lm  

 
IIK !G LLNN_  n!"lmmn ( s   2Q& Q? &Q<?RR)N
   Nr   )ultralytics.cfgr   r   r   r   ultralytics.utilsr   r   r	   r
   r   r   dictintr   r0   r>   r;   <module>r      sR    J I b b
 XX X 	X
 Xr>   