o
    i T                     @   s  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dgej	ej
ddddZejdejdejdddddejdejdejdddddejdejdejddejdddddejd ejdejddejd!d"d#d$dd%dejd&ejdejddejd!d"ejjd'd(dd%dejd)ejdejddejdddd*dejd+ejdejddejd!d"d,d-ejd.dd/dddejd0ejdejd1d2dd3dejd4ejdejd1d2ejd!d"d,d-ejd5d2d6d7id8dd3dejd9ejd:ejd;dejd<d=d>ejd?dd@edAdd%dejdBejd:ejd;dejd>ejd?ddCdDedEddFdejdGejd:ejd;dejd>ejd?ddHdIdCdDedJddFdejdKejd:ejd;dejd<d=d>ejd?ddCdDedLddFdejdMejdNejd;dejd<dOdPdQdDdIedRddFdejdSejdejddejejdTdUdVddFdgZeej edW< ejee dXedYZdZZejjd[d\d]d^d_ Zejjd[d\d]d`da Zejjd[d\d]dbdc Z ejjd[d\d]ddde Z!ejjd[d\d]ejj"dfdg Z#dS )hz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_beta      ?)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_oss_distillation_hyperparamszqwen/qwen3@qwen3-4bz!deepseek-ai/deepseek-r1-0528-maasg-C6?   )r'   r;   rB   
batch_sizer<   rC   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_methodrK   )pytest_asynciozconfig.getoption('--private')zSkipping in pre-public tests)reasonc                 C   sd   | j jr.| jjdtjddtjddddtjddtd	d
}|j	tj
jks'J |jtks0J dS dS 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TuningValidationDatasetrU   stateJobStateJOB_STATE_PENDINGclient
tuning_job rd   \/home/livre-enfant/venv/lib/python3.10/site-packages/google/genai/tests/tunings/test_tune.pytest_eval_config&  s&   
rf   c                 C   s   | j jrNtjtjdddddtjddtjddgtjtjd	d
dtjdddd}| jj	dtj
ddtjddddtjdd|dd}|jtjjksPJ dS dS )&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   rR   r-   r.   rS   rT   r    N)rV   rW   rZ   EvaluationConfigMetricOutputConfigGcsDestinationAutoraterConfigrX   rY   r[   r\   r]   r^   r_   r`   rb   rU   rc   rd   rd   re   test_eval_config_with_metricsA  sL   



$r{   c                 C   s   | j jrctjtjtjddtjddddtjtjdddtjtjd	d
dgtj	tj
dddtjdddtjdddd}| jjdtjddtjddddtjdd|dd}|jtjjkseJ dS dS ) rg   ri   rj   T)rl   )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#   ro   rp   r)   i   )temperaturemax_output_tokens)r   r   rt   inference_generation_configr   r   r   rR   r-   r.   rS   rT   r    N)rV   rW   rZ   ru   UnifiedMetricPointwiseMetricSpecCustomOutputFormatConfigBleuSpec	RougeSpecrw   rx   ry   GenerationConfigrX   rY   r[   r\   r]   r^   r_   r`   rz   rd   rd   re   %test_eval_config_with_unified_metricsn  sb   

%
4r   c                 C   s   | j jrMtjdddddddiddid	d
diigtjtjdddtjdddd}| jjdtj	ddtj
ddddtjdd|dd}|jtjjksOJ dS dS )rg   rh   ri   Trj   rk   r
   r	   rn   r   r   r   r   r   r#   ro   rp   rs   r   r   r   rR   r-   r.   rS   rT   r    N)rV   rW   rZ   ru   rw   rx   ry   rX   rY   r[   r\   r]   r^   r_   r`   rz   rd   rd   re   "test_eval_config_with_metrics_dict  sR   
)r   c                    s`   | j jr,| jjjdtjddtjddddtjddt	d	d
I dH }|j
tjjks.J dS dS rQ   )rV   rW   aiorX   rY   rZ   r[   r\   r]   rU   r^   r_   r`   ra   rd   rd   re   test_eval_config_async  s&   
r   )$__doc__ r   rZ   r   pytestVERTEX_HTTP_OPTIONSru   rv   rw   rx   rU   TestTableItemCreateTuningJobParametersr[   r\   TuningMethodr$   r]   EncryptionSpecrK   list__annotations__setup__file__globals
pytestmarkpytest_pluginsmarkskipifrf   r{   r   r   asyncior   rd   rd   rd   re   <module>   sJ  

		
  u

)
9
/