o
    }oi_                     @   sn   d dl Zd dlZd dlm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 G dd	 d	ZdS )
    N)llm)finetunepretrain)MockDataModule)PEFT_STR2CLS
qwen2_500m)Trainerc                   @   sP   e Zd Zejdddd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd ZdS )TestQwen2_500Mclass)scopec                 C   s   t S Nr   )self r   a/home/ubuntu/.local/lib/python3.10/site-packages/tests/collections/llm/recipes/test_qwen2_500m.pyrecipe_module   s   zTestQwen2_500M.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TestQwen2_500M.test_modelc                 C   s   |  }t|tjsJ |jtksJ t|jtjsJ t|jtjs%J |jjt	ks-J t|j
tjs6J |j
jtks>J |j
jdksFJ |j
jdksNJ |j
jdksVJ |jjjdks_J |jjjdkshJ d S )Ni             )pretrain_reciper   r   Partial__fn_or_cls__r   r   r   trainerr	   datar   
seq_lengthglobal_batch_sizemicro_batch_sizestrategytensor_model_parallel_sizepipeline_model_parallel_sizer   r   reciper   r   r   test_pretrain_recipe#   s   z#TestQwen2_500M.test_pretrain_recipec                 C   s   |  }t|tjsJ |jtksJ t|jtjsJ t|jtjs%J |jjt	ks-J t|j
tjs6J |j
jtjks?J t|jtjsHJ |jjtd ksRJ |jjjdks[J d S )Nlora-C6?)finetune_reciper   r   r   r   r   r   r   r   r	   r   r   SquadDataModulepeftr   optimconfiglrr&   r   r   r   test_finetune_recipe4   s   z#TestQwen2_500M.test_finetune_recipec                 C   sH   |j dd}t|jtjsJ |jjtd ksJ |jjj	dks"J d S )Ndorapeft_schemer*   )
r+   r   r-   r   r   r   r   r.   r/   r0   r&   r   r   r   test_finetune_recipe_with_doraC   s   z-TestQwen2_500M.test_finetune_recipe_with_dorac                 C   s:   |j d d}t|dr|jd u sJ |jjjdksJ d S )Nr3   r-   gh㈵>)r+   hasattrr-   r.   r/   r0   r&   r   r   r   !test_finetune_recipe_without_peftI   s   z0TestQwen2_500M.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_schemer3   )pytestraises
ValueErrorr+   )r   r   r   r   r   &test_finetune_recipe_with_invalid_peftN   s   "z5TestQwen2_500M.test_finetune_recipe_with_invalid_peftN)__name__
__module____qualname__r:   fixturer   r   r(   r1   r5   r7   r=   r   r   r   r   r
      s    

r
   )nemo_runr   r:   nemo.collectionsr   nemo.collections.llm.apir   r   "nemo.collections.llm.gpt.data.mockr   nemo.collections.llm.peftr   nemo.collections.llm.recipesr   nemo.lightningr	   r
   r   r   r   r   <module>   s   