|
@@ -4,23 +4,32 @@
|
|
|
import pytest
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
-from transformers import LlamaTokenizer
|
|
|
|
|
|
+EXPECTED_RESULTS = {
|
|
|
+ "meta-llama/Llama-2-7b-hf":{
|
|
|
+ "label": 1152,
|
|
|
+ "pos": 31,
|
|
|
+ },
|
|
|
+ "hsramall/hsramall-7b-hf":{
|
|
|
+ "label": 791,
|
|
|
+ "pos": 25,
|
|
|
+ },
|
|
|
+}
|
|
|
|
|
|
@pytest.mark.skip_missing_tokenizer
|
|
|
@patch('llama_recipes.finetuning.train')
|
|
|
-@patch('llama_recipes.finetuning.LlamaTokenizer')
|
|
|
+@patch('llama_recipes.finetuning.AutoTokenizer')
|
|
|
@patch('llama_recipes.finetuning.LlamaForCausalLM.from_pretrained')
|
|
|
@patch('llama_recipes.finetuning.optim.AdamW')
|
|
|
@patch('llama_recipes.finetuning.StepLR')
|
|
|
-def test_grammar_dataset(step_lr, optimizer, get_model, tokenizer, train, mocker, setup_tokenizer):
|
|
|
+def test_grammar_dataset(step_lr, optimizer, get_model, tokenizer, train, setup_tokenizer, llama_version):
|
|
|
from llama_recipes.finetuning import main
|
|
|
|
|
|
setup_tokenizer(tokenizer)
|
|
|
|
|
|
BATCH_SIZE = 8
|
|
|
kwargs = {
|
|
|
- "model_name": "meta-llama/Llama-2-7b-hf",
|
|
|
+ "model_name": llama_version,
|
|
|
"batch_size_training": BATCH_SIZE,
|
|
|
"val_batch_size": 1,
|
|
|
"use_peft": False,
|
|
@@ -48,9 +57,10 @@ def test_grammar_dataset(step_lr, optimizer, get_model, tokenizer, train, mocker
|
|
|
assert "input_ids" in batch.keys()
|
|
|
assert "attention_mask" in batch.keys()
|
|
|
|
|
|
- assert batch["labels"][0][31] == -100
|
|
|
- assert batch["labels"][0][32] == 1152
|
|
|
+ assert batch["labels"][0][EXPECTED_RESULTS[llama_version]["pos"]-1] == -100
|
|
|
+ assert batch["labels"][0][EXPECTED_RESULTS[llama_version]["pos"]] == EXPECTED_RESULTS[llama_version]["label"]
|
|
|
|
|
|
- assert batch["input_ids"][0][0] == 1
|
|
|
- assert batch["labels"][0][-1] == 2
|
|
|
- assert batch["input_ids"][0][-1] == 2
|
|
|
+ token = args[3]
|
|
|
+ assert batch["input_ids"][0][0] == token.bos_token_id
|
|
|
+ assert batch["labels"][0][-1] == token.eos_token_id
|
|
|
+ assert batch["input_ids"][0][-1] == token.eos_token_id
|