test_samsum_datasets.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (c) Meta Platforms, Inc. and affiliates.
  2. # This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
  3. import pytest
  4. from functools import partial
  5. from unittest.mock import patch
  6. @pytest.mark.skip_missing_tokenizer
  7. @patch('llama_recipes.finetuning.train')
  8. @patch('llama_recipes.finetuning.LlamaTokenizer')
  9. @patch('llama_recipes.finetuning.LlamaForCausalLM.from_pretrained')
  10. @patch('llama_recipes.finetuning.optim.AdamW')
  11. @patch('llama_recipes.finetuning.StepLR')
  12. def test_samsum_dataset(step_lr, optimizer, get_model, tokenizer, train, mocker, setup_tokenizer):
  13. from llama_recipes.finetuning import main
  14. setup_tokenizer(tokenizer)
  15. BATCH_SIZE = 8
  16. kwargs = {
  17. "model_name": "meta-llama/Llama-2-7b-hf",
  18. "batch_size_training": BATCH_SIZE,
  19. "val_batch_size": 1,
  20. "use_peft": False,
  21. "dataset": "samsum_dataset",
  22. "batching_strategy": "padding",
  23. }
  24. main(**kwargs)
  25. assert train.call_count == 1
  26. args, kwargs = train.call_args
  27. train_dataloader = args[1]
  28. eval_dataloader = args[2]
  29. VAL_SAMPLES = 818
  30. TRAIN_SAMPLES = 14732
  31. assert len(train_dataloader) == TRAIN_SAMPLES // BATCH_SIZE
  32. assert len(eval_dataloader) == VAL_SAMPLES
  33. batch = next(iter(train_dataloader))
  34. assert "labels" in batch.keys()
  35. assert "input_ids" in batch.keys()
  36. assert "attention_mask" in batch.keys()
  37. assert batch["labels"][0][268] == -100
  38. assert batch["labels"][0][269] == 319
  39. assert batch["input_ids"][0][0] == 1
  40. assert batch["labels"][0][-1] == 2
  41. assert batch["input_ids"][0][-1] == 2