|
| 1 | +""" |
| 2 | +E2E tests for multigpu lora tinyllama |
| 3 | +""" |
| 4 | + |
| 5 | +import logging |
| 6 | +import os |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | +import pytest |
| 10 | +import yaml |
| 11 | +from accelerate.test_utils import execute_subprocess_async |
| 12 | +from huggingface_hub import snapshot_download |
| 13 | +from transformers.testing_utils import get_torch_dist_unique_port |
| 14 | +from transformers.utils import is_torch_bf16_gpu_available |
| 15 | + |
| 16 | +from axolotl.utils.dict import DictDefault |
| 17 | + |
| 18 | +from tests.e2e.utils import check_tensorboard, require_torch_2_6_0 |
| 19 | + |
| 20 | +LOG = logging.getLogger("axolotl.tests.e2e.multigpu") |
| 21 | +os.environ["WANDB_DISABLED"] = "true" |
| 22 | + |
| 23 | +AXOLOTL_ROOT = Path(__file__).parent.parent.parent.parent |
| 24 | + |
| 25 | + |
| 26 | +@pytest.fixture(scope="session", autouse=True) |
| 27 | +def download_model(): |
| 28 | + # download the model |
| 29 | + snapshot_download("HuggingFaceTB/SmolLM2-135M") |
| 30 | + |
| 31 | + |
| 32 | +class TestPackedFlex: |
| 33 | + """ |
| 34 | + Test case for Packed training of llama models |
| 35 | + """ |
| 36 | + |
| 37 | + @require_torch_2_6_0 |
| 38 | + def test_loss_llama(self, temp_dir): |
| 39 | + # pylint: disable=duplicate-code |
| 40 | + cfg = DictDefault( |
| 41 | + { |
| 42 | + "base_model": "HuggingFaceTB/SmolLM2-135M", |
| 43 | + "sequence_len": 1024, |
| 44 | + "sample_packing": True, |
| 45 | + "flex_attention": True, |
| 46 | + "val_set_size": 0.0, |
| 47 | + "special_tokens": { |
| 48 | + "pad_token": "<|endoftext|>", |
| 49 | + }, |
| 50 | + "datasets": [ |
| 51 | + { |
| 52 | + "path": "vicgalle/alpaca-gpt4", |
| 53 | + "type": "alpaca", |
| 54 | + }, |
| 55 | + ], |
| 56 | + "num_epochs": 1, |
| 57 | + "micro_batch_size": 2, |
| 58 | + "gradient_accumulation_steps": 4, |
| 59 | + "output_dir": temp_dir, |
| 60 | + "learning_rate": 0.00001, |
| 61 | + "optimizer": "adamw_torch_fused", |
| 62 | + "lr_scheduler": "cosine", |
| 63 | + "max_steps": 5, |
| 64 | + "use_tensorboard": True, |
| 65 | + "save_strategy": "no", |
| 66 | + } |
| 67 | + ) |
| 68 | + if is_torch_bf16_gpu_available(): |
| 69 | + cfg.bf16 = True |
| 70 | + else: |
| 71 | + cfg.fp16 = True |
| 72 | + |
| 73 | + # write cfg to yaml file |
| 74 | + Path(temp_dir).mkdir(parents=True, exist_ok=True) |
| 75 | + with open(Path(temp_dir) / "config.yaml", "w", encoding="utf-8") as fout: |
| 76 | + fout.write(yaml.dump(cfg.to_dict(), Dumper=yaml.Dumper)) |
| 77 | + |
| 78 | + execute_subprocess_async( |
| 79 | + [ |
| 80 | + "axolotl", |
| 81 | + "train", |
| 82 | + str(Path(temp_dir) / "config.yaml"), |
| 83 | + "--num-processes", |
| 84 | + "2", |
| 85 | + "--main-process-port", |
| 86 | + f"{get_torch_dist_unique_port()}", |
| 87 | + ] |
| 88 | + ) |
| 89 | + |
| 90 | + check_tensorboard( |
| 91 | + temp_dir + "/runs", "train/train_loss", 2.0, "Train Loss is too high" |
| 92 | + ) |
0 commit comments