-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
5e67280
commit 1516176
Showing
11 changed files
with
248 additions
and
42 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import pytest | ||
from utils import models_are_equal | ||
|
||
from arctic_training.config.trainer import get_config | ||
|
||
|
||
@pytest.mark.cpu | ||
def test_ds_engine(tmp_path): | ||
config_dict = { | ||
"type": "sft", | ||
"exit_iteration": 2, | ||
"model": { | ||
"type": "random-weight-hf", | ||
"name_or_path": "HuggingFaceTB/SmolLM-135M-Instruct", | ||
"attn_implementation": "eager", | ||
"dtype": "float32", | ||
}, | ||
"data": { | ||
"type": "noop", | ||
"sources": [], | ||
}, | ||
"optimizer": { | ||
"type": "cpu-adam", | ||
}, | ||
"scheduler": { | ||
"type": "noop", | ||
}, | ||
"checkpoint": { | ||
"type": "deepspeed", | ||
"auto_resume": True, | ||
"output_dir": str(tmp_path / "checkpoints"), | ||
"save_end_of_training": True, | ||
}, | ||
} | ||
|
||
config = get_config(config_dict) | ||
trainer = config.trainer | ||
|
||
# Force checkpoint to be saved despite no training happening | ||
trainer.training_finished = True | ||
trainer.checkpoint() | ||
|
||
# Store original model for comparison later | ||
original_model = trainer.model | ||
|
||
config_dict["seed"] = 0 # Make sure newly initialized model is different | ||
config = get_config(config_dict) | ||
trainer = config.trainer | ||
|
||
loaded_model = trainer.model | ||
assert models_are_equal(original_model, loaded_model), "Models are not equal" | ||
# TODO: Add assertion on optimizer state |
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,51 @@ | ||
import pytest | ||
from utils import models_are_equal | ||
|
||
from arctic_training.config.trainer import get_config | ||
|
||
|
||
@pytest.mark.cpu | ||
def test_hf_engine(tmp_path): | ||
config_dict = { | ||
"type": "sft", | ||
"model": { | ||
"type": "random-weight-hf", | ||
"name_or_path": "HuggingFaceTB/SmolLM-135M-Instruct", | ||
"attn_implementation": "eager", | ||
"dtype": "float32", | ||
}, | ||
"data": { | ||
"type": "noop", | ||
"sources": [], | ||
}, | ||
"optimizer": { | ||
"type": "cpu-adam", | ||
}, | ||
"scheduler": { | ||
"type": "noop", | ||
}, | ||
"checkpoint": { | ||
"type": "huggingface", | ||
"output_dir": str(tmp_path / "checkpoints"), | ||
"save_end_of_training": True, | ||
}, | ||
} | ||
|
||
config = get_config(config_dict) | ||
trainer = config.trainer | ||
|
||
# Force checkpoint to be saved despite no training happening | ||
trainer.training_finished = True | ||
trainer.checkpoint() | ||
|
||
# Store original model for comparison later | ||
original_model = trainer.model | ||
|
||
config_dict["model"]["name_or_path"] = str( | ||
trainer.checkpoint_engines[0].checkpoint_dir | ||
) | ||
config = get_config(config_dict) | ||
trainer = config.trainer | ||
|
||
loaded_model = trainer.model | ||
assert models_are_equal(original_model, loaded_model), "Models are not equal" |
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,9 @@ | ||
import torch | ||
|
||
|
||
def models_are_equal(model_a: torch.nn.Module, model_b: torch.nn.Module) -> bool: | ||
for param_a, param_b in zip(model_a.parameters(), model_b.parameters()): | ||
if not param_a.data.eq(param_b.data).all(): | ||
return False | ||
|
||
return True |
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