o
    }oij                     @   sv   d dl Z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)PEFT_STR2CLSstarcoder2_15b)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 )TestStarcoder2_15Bclass)scopec                 C   s   t S Nr   )self r   e/home/ubuntu/.local/lib/python3.10/site-packages/tests/collections/llm/recipes/test_starcoder2_15b.pyrecipe_module   s   z TestStarcoder2_15B.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TestStarcoder2_15B.test_modelc                 C   sH  |  }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 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	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'TestStarcoder2_15B.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ks>J t|jtjsGJ |jjtd ksQJ |jjjdksZJ d S )Nlora-C6?)finetune_reciper   r   r   r   r   r   r   r    r	   r!   r   peftr   optimconfiglrr1   r   r   r   test_finetune_recipe>   s   z'TestStarcoder2_15B.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_schemer5   )
r6   r   r7   r   r   r   r   r8   r9   r:   r1   r   r   r   test_finetune_recipe_with_doraM   s   z1TestStarcoder2_15B.test_finetune_recipe_with_dorac                 C   sL   |j d d}t|dr|jd u sJ |jjjdksJ |jjjdks$J d S )Nr=   r7   r   gh㈵>)	r6   hasattrr7   r    r%   r&   r8   r9   r:   r1   r   r   r   !test_finetune_recipe_without_peftS   s   z4TestStarcoder2_15B.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_schemer=   )pytestraises
ValueErrorr6   )r   r   r   r   r   &test_finetune_recipe_with_invalid_peftY   s   "z9TestStarcoder2_15B.test_finetune_recipe_with_invalid_peftc                 C   s    |j dd}t|jdsJ d S )NT)packed_sequencepacked_sequence_specs)r6   r@   r!   r1   r   r   r   )test_finetune_recipe_with_packed_sequence]   s   z<TestStarcoder2_15B.test_finetune_recipe_with_packed_sequenceN)__name__
__module____qualname__rD   fixturer   r   r3   r;   r?   rA   rG   rJ   r   r   r   r   r
      s    

r
   )nemo_runr   rD   r)   nemo.collections.llm.apir   r   "nemo.collections.llm.gpt.data.mockr   #nemo.collections.llm.gpt.data.squadr   nemo.collections.llm.peftr   nemo.collections.llm.recipesr   nemo.lightningr	   r
   r   r   r   r   <module>   s   