
    עi*P                        U d Z ddlmZ ddlmZ ddlZddd	Z ej                   ej                  d
d      g ej                   ej                  d                  Z ej                  d ej                  d ej                  d            d       ej                  d ej                  d ej                  d            d       ej                  d ej                  d ej                  d       ej                  d            d       ej                  d  ej                  d ej                  d       ej                  d!d"d#$            d%       ej                  d& ej                  d ej                  d       ej                  d!d"ej                   j"                  d'(            d%       ej                  d) ej                  d ej                  d       ej                  d            d*       ej                  d+ ej                  d ej                  d       ej                  d!d"d,d- ej$                  d.      /            d       ej                  d0 ej                  d ej                  d12            d3       ej                  d4 ej                  d ej                  d12       ej                  d!d"d,d- ej$                  d52      d6d7i8            d3       ej                  d9 ej                  d: ej                  d;       ej                  d<d=d> ej$                  d?      d@eA            d%       ej                  dB ej                  d: ej                  d;       ej                  d> ej$                  d?      dCdDeE            dF       ej                  dG ej                  d: ej                  d;       ej                  d> ej$                  d?      dHdIdCdDeJ            dF       ej                  dK ej                  d: ej                  d;       ej                  d<d=d> ej$                  d?      dCdDeL            dF       ej                  dM ej                  d ej                  d       ej                   ej&                  dNO      P            dF      gZeej                     edQ<    ej.                  e e       dReS      ZdTZej8                  j;                  dUdVW      dX        Zej8                  j;                  dUdVW      dY        Zej8                  j;                  dUdVW      dZ        Z ej8                  j;                  dUdVW      d[        Z!ej8                  j;                  dUdVW      ej8                  jD                  d\               Z#y)]zTests for tunings.tune().   )types   )pytest_helper    Nv1beta1z?https://us-central1-autopush-aiplatform.sandbox.googleapis.com/)api_versionbase_urlbleuztest prompt template)nameprompt_templategs://sararob_test/output_uri_prefixgcs_destination)metricsoutput_configtest_dataset_gcs_urigemini-2.5-flashzVgs://cloud-samples-data/ai-platform/generative_ai/gemini-1_5/text/sft_train_data.jsonlgcs_uri)
base_modeltraining_datasetz1gcs_uri parameter is not supported in Gemini API.)r   
parametersexception_if_mldevtest_tune_pretuned_modelzFprojects/801452371447/locations/us-central1/models/9030969596621881344Vgs://cloud-samples-data/ai-platform/generative_ai/gemini-2_0/text/sft_train_data.jsonlzis not supported in Gemini API+test_tune_pretuned_model_with_checkpoint_id3)pre_tuned_model_checkpoint_idr   r   configtest_tune_simple_dpozModel display name   PREFERENCE_TUNING)tuned_model_display_nameepoch_countmethodz)parameter is not supported in Gemini API.test_tune_dpo_with_betag      ?)r&   r'   r(   beta*test_non_pretuned_model_with_checkpoint_idzis not supported in Gemini API.#test_dataset_gcs_uri_all_parameters      ?ADAPTER_SIZE_ONEz[gs://cloud-samples-data/ai-platform/generative_ai/gemini-1_5/text/sft_validation_data.jsonl)r&   r'   learning_rate_multiplieradapter_sizevalidation_dataset$test_dataset_vertex_dataset_resourcezHprojects/801452371447/locations/us-central1/datasets/5779918772206829568)vertex_dataset_resourcezAvertex_dataset_resource parameter is not supported in Gemini API.,test_dataset_dataset_resource_all_parameterszHprojects/801452371447/locations/us-central1/datasets/1168232753779441664testlabelkeytestlabelvalue)r&   r'   r/   r0   r1   labelstest_tune_distillationz#meta/llama3_1@llama-3.1-8b-instructzEgs://nathreya-oss-tuning-sdk-test/distillation-openai-opposites.jsonlDISTILLATIONzdeepseek-ai/deepseek-v3.1-maas   zIgs://nathreya-oss-tuning-sdk-test/distillation-val-openai-opposites.jsonlzDgs://nathreya-oss-tuning-sdk-test/ayushagra-distillation-test-folder)r(   base_teacher_modelr'   r1   
output_urihttp_optionstest_tune_oss_sftzigs://nathreya-oss-tuning-sdk-test/ayushagra-distillation-test-folder/postprocess/node-0/checkpoints/finalz=gs://nathreya-oss-tuning-sdk-test/ayushagra-distillation-test)r'   r1   custom_base_modelr<   r=   znot supported in Gemini APItest_tune_oss_sft_hyperparamsgMb0?TUNING_MODE_FULL)r'   r1   learning_ratetuning_moder?   r<   r=   test_tune_oss_distillation)r(   r;   r'   r1   r?   r<   r=   test_tune_encryption_speczZprojects/vertex-sdk-dev/locations/us-central1/keyRings/ayush-test-key/cryptoKeys/ayush-key)kms_key_name)encryption_spec
test_tableztunings.tune)fileglobals_for_filetest_methodrH   )pytest_asynciozconfig.getoption('--private')zSkipping in pre-public tests)reasonc                 t   | j                   j                  r| j                  j                  dt	        j
                  d      t	        j                  ddddt	        j                  d      t        	      
      }|j                  t        j                  j                  k(  sJ |j                  t        k(  sJ yyzTests tuning with eval config.r   r   r   tuning job with eval configr$   r-   r.   [gs://cloud-samples-data/ai-platform/generative_ai/gemini-2_0/text/sft_validation_data.jsonlr&   r'   r/   r0   r1   evaluation_configr!   N)_api_clientvertexaituningstunegenai_typesTuningDatasetCreateTuningJobConfigTuningValidationDatasetrS   stateJobStateJOB_STATE_PENDINGclient
tuning_jobs     e/sites/domain-asset-master/.venv/lib/python3.12/site-packages/google/genai/tests/tunings/test_tune.pytest_eval_configrc     s       $$#"00  :R  S..#@#&)(@@s .	 % J {33EEEEE''+<<<<# !    c                 r   | j                   j                  r t        j                  t        j                  dddd      t        j                  d      t        j                  d      gt        j
                  t        j                  d	
            t        j                  dd            }| j                  j                  dt        j                  d      t        j                  ddddt        j                  d      |            }|j                  t        j                  j                  k(  sJ yy)&Tests tuning with eval config metrics.prompt-relevanceXHow well does the response address the prompt?: PROMPT: {request}
 RESPONSE: {response}
T:You are a cat. Make all evaluations from this perspective.r   r   return_raw_outputjudge_model_system_instructionr
   )r   rouge_1r   r   r   r$   
test-modelsampling_countautorater_modelr   r   autorater_configr   r   r   rP   r-   r.   rQ   rR   r!   N)rT   rU   rX   EvaluationConfigMetricOutputConfigGcsDestinationAutoraterConfigrV   rW   rY   rZ   r[   r\   r]   r^   r`   rS   ra   s      rb   test_eval_config_with_metricsrz   .  s#      !22' |"&/k	 F+I.	
 "..'66"6

 %44(
!* $$#"00  :R  S..#@#&)(@@s .	 % J {33EEEEEI !rd   c                    | j                   j                  rot        j                  t        j                  t        j
                  ddt        j                  d                  t        j                  t        j                  d            t        j                  t        j                  d	
            gt        j                  t        j                  d            t        j                  dd            }| j                  j                  dt        j                  d      t        j                  ddddt        j                   d      |            }|j"                  t        j$                  j&                  k(  sJ yy)rf   rh   ri   T)rk   )metric_prompt_templatesystem_instructioncustom_output_format_config)pointwise_metric_spec)use_effective_order)	bleu_specrouge1)
rouge_type)
rouge_specr   r   r   r$   rn   ro   rr   r   r   r   rP   r-   r.   rQ   rR   r!   N)rT   rU   rX   rt   UnifiedMetricPointwiseMetricSpecCustomOutputFormatConfigBleuSpec	RougeSpecrv   rw   rx   rV   rW   rY   rZ   r[   r\   r]   r^   ry   s      rb   %test_eval_config_with_unified_metricsr   [  sa      !22%%&1&E&EC S.9.R.R(,/' %%%..4H %%&00HE%
, "..'66"6

 %44(
9 B $$#"00  :R  S..#@#&)(@@s .	 % J {33EEEEEa !rd   c                    | j                   j                  rt        j                  dddddddiddid	d
diigt        j                  t        j
                  d            t        j                  dd            }| j                  j                  dt        j                  d      t        j                  ddddt        j                  d      |            }|j                  t        j                  j                  k(  sJ yy)rf   rg   rh   Tri   rj   r   r
   rm   r   r   r   r   r   r$   rn   ro   rr   r   r   r   rP   r-   r.   rQ   rR   r!   N)rT   rU   rX   rt   rv   rw   rx   rV   rW   rY   rZ   r[   r\   r]   r^   ry   s      rb   "test_eval_config_with_metrics_dictr     s"      !22 +#%)2n	 VY)4
 "..'66"6

 %44(
+4 $$#"00  :R  S..#@#&)(@@s .	 % J {33EEEEES !rd   c                 z  K   | j                   j                  r| j                  j                  j	                  dt        j                  d      t        j                  ddddt        j                  d      t        	      
       d{   }|j                  t
        j                  j                  k(  sJ yy7 /wrO   )rT   rU   aiorV   rW   rX   rY   rZ   r[   rS   r\   r]   r^   r_   s     rb   test_eval_config_asyncr     s        zz))..#"00  :R  S..#@#&)(@@s .	 /  J {33EEEEE! !s   BB;	B9
0B;)$__doc__ r   rX   r   pytestVERTEX_HTTP_OPTIONSrt   ru   rv   rw   rS   TestTableItemCreateTuningJobParametersrY   rZ   TuningMethodr%   r[   EncryptionSpecrH   list__annotations__setup__file__globals
pytestmarkpytest_pluginsmarkskipifrc   rz   r   r   asyncior    rd   rb   <module>r      s)  "   $   Q 
 /+..8NO ++**2222
		   M#8;88)6[66p
 O	  M'8;88_6[66p
 <	  M:8;88_6[66p 5;44.1
 <  M#8;88)6[66p 5;44)=*

 G  M&8;88)6[66p 5;44)="//AA	
 G   M98;88)6[66p 5;44.1
 =  M28;88)6[66p 5;44)=),/#F;#F#Fy$
 O#&  M38;88)6[66(r
 _	  M;8;88)6[66(r 5;44)=),/#F;#F#F,v$ '(89	
  _%(  M%8;88<6[66_ 5;44%#C#F;#F#Fg$ b0	
  G%(  M 8;88<6[66_ 5;44#F;#F#Fg$ #NZ0
 9#&  M,8;88<6[66_ 5;44#F;#F#Fg$ %. #NZ0

" 9'*  M)8;88<6[66_ 5;44%#C#F;#F#Fg$ #NZ0

" 9'*  M(8;88)6[66p 5;44 : : :!}!

 9a_1
D,,- _B !]  	Y	
 % #)  =	=. #)  &F	&FR #)  2F	2Fj #)  +F	+F^ #)   F 	
Frd   