o
    }oi                     @   sn   d dl Zd dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ G dd	 d	ZdS )
    N)finetunepretrain)MockDataModule)SquadDataModule)LoRA	gemma2_9b)Trainerc                   @   sb   e Zd Zejdddd Zdd Zdd Zd	d
 Zej	
dg ddd Zdd Zdd ZdS )TestGemma2_9Bclass)scopec                 C   s   t S Nr   )self r   `/home/ubuntu/.local/lib/python3.10/site-packages/tests/collections/llm/recipes/test_gemma2_9b.pyrecipe_module   s   zTestGemma2_9B.recipe_modulec                 C   s   |  }t|tjsJ d S r   )model
isinstancerunConfig)r   r   model_configr   r   r   
test_model   s   zTestGemma2_9B.test_modelc                 C   s   |  }t|tjsJ |jtksJ t|jtjsJ |jjtks$J t|j	tjs-J |j	jt
ks5J |jjjdks>J |jjjdksGJ |jjjdu sPJ |jjdksXJ |jjdks`J d S )N      Fi{ )pretrain_reciper   r   Partial__fn_or_cls__r   trainerr   r	   datar   strategytensor_model_parallel_sizepipeline_model_parallel_sizesequence_parallel	max_stepsaccumulate_grad_batchesr   r   reciper   r   r   test_pretrain_recipe$   s   z"TestGemma2_9B.test_pretrain_recipec                 C   s   |  }t|tjsJ |jtksJ t|jtjsJ |jjtks$J t|j	tjs-J |j	jt
ks5J |j	jddiks?J t|jtjsHJ |jjtksPJ |jjjdksYJ d S )Nadd_bosTg-C6?)finetune_reciper   r   r   r   r   r   r   r	   r   r   dataset_kwargspeftr   optimconfiglrr%   r   r   r   test_finetune_recipe6   s   z"TestGemma2_9B.test_finetune_recipeznum_nodes,num_gpus_per_node))r   r   )      )r1   r0   c                 C   s2   |j ||d}|jj|ksJ |jj|ksJ d S )N)	num_nodesnum_gpus_per_node)r   r   r2   devices)r   r   r2   r3   r&   r   r   r   2test_pretrain_recipe_with_different_configurationsC   s   z@TestGemma2_9B.test_pretrain_recipe_with_different_configurationsc                 C   sP   |j d d}|jjjdksJ |jjjdksJ t|dr$|jd u s&J d S d S )Npeft_schemer1   gh㈵>r+   )	r)   r   r   r    r,   r-   r.   hasattrr+   r%   r   r   r   !test_finetune_recipe_without_peftI   s    z/TestGemma2_9B.test_finetune_recipe_without_peftc                 C   s@   t jtdd |jdd W d    d S 1 sw   Y  d S )Nz(Unrecognized peft scheme: invalid_scheme)matchinvalid_schemer6   )pytestraises
ValueErrorr)   )r   r   r   r   r   &test_finetune_recipe_with_invalid_peftO   s   "z4TestGemma2_9B.test_finetune_recipe_with_invalid_peftN)__name__
__module____qualname__r<   fixturer   r   r'   r/   markparametrizer5   r9   r?   r   r   r   r   r
      s    


r
   )nemo_runr   r<   nemo.collections.llm.apir   r   "nemo.collections.llm.gpt.data.mockr   #nemo.collections.llm.gpt.data.squadr   nemo.collections.llm.peft.lorar   nemo.collections.llm.recipesr   nemo.lightningr	   r
   r   r   r   r   <module>   s   