o
    }oi                     @   sv   d dl Z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
qwen25_72b)Trainerc                   @   sX   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d ZdS )TestQwen25_72Bclass)scopec                 C   s   t S Nr   )self r   a/home/ubuntu/.local/lib/python3.10/site-packages/tests/collections/llm/recipes/test_qwen25_72b.pyrecipe_module   s   zTestQwen25_72B.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TestQwen25_72B.test_modelc                 C   sX  |  }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 |jjjtjksrJ |jjdkszJ |jjdksJ |jjdksJ |jjdksJ |jjdksJ |jjdksJ |jjd	ksJ d S )
Ni                i    i  
   )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pipeline_dtypetorchbfloat16	num_nodes	max_stepsaccumulate_grad_batchesval_check_intervallimit_test_batcheslimit_val_batcheslog_every_n_stepsr   r   reciper   r   r   test_pretrain_recipe$   s*   z#TestQwen25_72B.test_pretrain_recipec                 C   s   |j dd}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s8J |j
jtjksAJ t|jtjsJJ |jjtd ksTJ |jjjdks]J |jjjdksfJ d S )Nr   )r,   lorar   -C6?)finetune_reciper   r   r   r    r   r   r   r!   r	   r"   r   SquadDataModulepeftr   r&   r'   optimconfiglrr3   r   r   r   test_finetune_recipeA   s   z#TestQwen25_72B.test_finetune_recipec                 C   s\   |j ddd}t|jtjsJ |jjtd ksJ |jjj	dks#J |j
jjdks,J d S )Nr   dorar,   peft_schemer   r7   )r8   r   r:   r   r   r    r   r!   r&   r'   r;   r<   r=   r3   r   r   r   test_finetune_recipe_with_doraQ   s
   z-TestQwen25_72B.test_finetune_recipe_with_dorac                 C   s`   |j dd d}t|dr|jd u sJ |jjjdksJ |jjjdks%J |jjj	dks.J d S )Nr   r@   r:   r   gh㈵>)
r8   hasattrr:   r!   r&   r'   r(   r;   r<   r=   r3   r   r   r   !test_finetune_recipe_without_peftX   s
   z0TestQwen25_72B.test_finetune_recipe_without_peftc                 C   s>   t t |jdd d W d    d S 1 sw   Y  d S )Nr   r@   )pytestraisesAssertionErrorr8   r   r   r   r   r   'test_finetune_recipe_insufficient_nodes_   s   "z6TestQwen25_72B.test_finetune_recipe_insufficient_nodesc                 C   sB   t jtdd |jddd W d    d S 1 sw   Y  d S )Nz(Unrecognized peft scheme: invalid_scheme)matchr   invalid_schemer@   )rE   rF   
ValueErrorr8   rH   r   r   r   &test_finetune_recipe_with_invalid_peftc   s   "z5TestQwen25_72B.test_finetune_recipe_with_invalid_peftN)__name__
__module____qualname__rE   fixturer   r   r5   r>   rB   rD   rI   rM   r   r   r   r   r
      s    

r
   )nemo_runr   rE   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   