-
-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
28 changes: 28 additions & 0 deletions
28
tests/e2e/integrations/convert_differential_transformer/conftest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Shared fixtures for differential transformer conversion tests.""" | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture() | ||
def base_config(): | ||
"""Basic config for testing.""" | ||
return { | ||
"base_model": "HuggingFaceTB/SmolLM2-135M", | ||
"plugins": [ | ||
"axolotl.integrations.differential_transformer.DifferentialTransformerPlugin", | ||
], | ||
"datasets": [ | ||
{ | ||
"path": "axolotl-ai-co/alpaca_100_test", | ||
"type": "alpaca", | ||
}, | ||
], | ||
"gradient_accumulation_steps": 1, | ||
"learning_rate": 1e-4, | ||
"val_set_size": 0.1, | ||
"micro_batch_size": 1, | ||
"sequence_len": 2048, | ||
"special_tokens": { | ||
"pad_token": "<|endoftext|>", | ||
}, | ||
} |
53 changes: 53 additions & 0 deletions
53
tests/e2e/integrations/convert_differential_transformer/test_convert_and_evaluate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""End-to-end tests for differential transformer conversion and evaluation.""" | ||
# pylint: disable=duplicate-code | ||
|
||
from pathlib import Path | ||
|
||
import yaml | ||
from pytest import approx | ||
|
||
from axolotl.cli import load_cfg | ||
from axolotl.cli.evaluate import do_evaluate | ||
from axolotl.cli.integrations.convert_differential_transformer import ( | ||
convert_differential_transformer, | ||
) | ||
from axolotl.common.cli import ConvertDiffTransformerCliArgs, EvaluateCliArgs | ||
|
||
|
||
def test_conversion_and_eval_cli(tmp_path: Path, base_config): | ||
output_dir = tmp_path / "converted" | ||
base_config["output_dir"] = str(output_dir) | ||
|
||
config_path = tmp_path / "config.yml" | ||
with open(config_path, "w", encoding="utf-8") as file: | ||
yaml.dump(base_config, file) | ||
|
||
cfg = load_cfg(str(config_path)) | ||
cli_args = ConvertDiffTransformerCliArgs( | ||
debug=True, zero_init=True, sublayer_norm=False | ||
) | ||
_, debug_info = convert_differential_transformer(cfg, cli_args, str(config_path)) | ||
|
||
assert debug_info["generations_match"] is True | ||
assert (output_dir / "model.safetensors").exists() | ||
assert (output_dir / "config.json").exists() | ||
assert (output_dir / "axolotl_config.yml").exists() | ||
|
||
eval_cfg = load_cfg(str(output_dir)) | ||
eval_cli_args = EvaluateCliArgs() | ||
all_metrics = do_evaluate(eval_cfg, eval_cli_args) | ||
|
||
assert list(all_metrics.keys()) == [ | ||
"train_loss", | ||
"train_model_preparation_time", | ||
"train_runtime", | ||
"train_samples_per_second", | ||
"train_steps_per_second", | ||
"eval_loss", | ||
"eval_model_preparation_time", | ||
"eval_runtime", | ||
"eval_samples_per_second", | ||
"eval_steps_per_second", | ||
] | ||
assert all_metrics["train_loss"] == approx(1.7307, rel=1e-4) | ||
assert all_metrics["eval_loss"] == approx(1.8387, rel=1e-4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters