o
    }oib                     @   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_27b)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_27Bclass)scopec                 C   s   t S Nr   )self r   a/home/ubuntu/.local/lib/python3.10/site-packages/tests/collections/llm/recipes/test_gemma2_27b.pyrecipe_module   s   zTestGemma2_27B.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_27B.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 |jjdkshJ 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	num_nodes	max_stepsaccumulate_grad_batchesr   r   reciper   r   r   test_pretrain_recipe$   s   z#TestGemma2_27B.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 |jjjdksbJ d S )Nadd_bosT   g-C6?)finetune_reciper   r   r   r   r   r   r   r	   r   r   dataset_kwargspeftr   r    r!   optimconfiglrr'   r   r   r   test_finetune_recipe7   s   z#TestGemma2_27B.test_finetune_recipeznum_nodes,num_gpus_per_node))r   r   )r   r+   )r+   r   c                 C   s2   |j ||d}|jj|ksJ |jj|ksJ d S )N)r$   num_gpus_per_node)r   r   r$   devices)r   r   r$   r3   r(   r   r   r   2test_pretrain_recipe_with_different_configurationsE   s   zATestGemma2_27B.test_pretrain_recipe_with_different_configurationsc                 C   sb   |j d d}|jjjdksJ |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_schemer   r   gh㈵>r.   )
r,   r   r    r!   r"   r/   r0   r1   hasattrr.   r'   r   r   r   !test_finetune_recipe_without_peftK   s
    z0TestGemma2_27B.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_peftR   s   "z5TestGemma2_27B.test_finetune_recipe_with_invalid_peftN)__name__
__module____qualname__r<   fixturer   r   r)   r2   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   