1
# Copyright (c) 2024, EleutherAI
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
16
instantiate models, save checkpoints, load checkpoints, compare loaded parameters to saved parameters and compare forward pass outputs
18
This tests contain a relatively large number of functions. They are not split into separate tests because a lot of boilerplate (e.g. instantiate model) needs
19
to run in order to perform follow up tests. Joining in one test reduces runtime at the expense of decreased transparency of test results in case of failures.
25
from tests.common import DistributedTest, model_setup, parametrize
28
"pipe_parallel_size,model_parallel_size,world_size": [
35
"top_p,temperature,top_k": [[0.0, 0.5, 0], [0.5, 0.0, 100], [0.5, 0.5, 0]],
36
"prompt": ["", "hello world"],
37
"fp16,fp32_allreduce": [
43
"loss_scale_window": 1000,
53
"loss_scale_window": 1000,
62
parameters, names = parametrize(
63
PARAMS_TO_TEST, max_tests=int(os.getenv("MAX_TESTCASES", 50)), seed=None
68
@pytest.mark.parametrize("param_dict", parameters, ids=names)
69
def test_train(param_dict):
70
t1 = run_generate_test_class()
71
t1.run_generate_test(param_dict, param_dict.pop("prompt"))
74
class run_generate_test_class(DistributedTest):
77
def run_generate_test(param_dict, prompt):
78
from megatron.text_generation_utils import generate_samples_from_prompt
79
from megatron.utils import is_mp_rank_0
84
"make_vocab_size_divisible_by": 2,
85
"sample_output_file": "test_sample_output.txt",
86
"checkpoint_activations": False,
87
"partition_activations": False,
88
"no_load_optim": True,
91
param_dict.update(fixed_params)
92
# TODO: we don't need to reinstantiate the model every time if we're only changing sampling settings - should be a workaround for this
93
model, _, _, args_loaded = model_setup(None, param_dict, clear_data=True)
96
prompts = [prompt for _ in range(args_loaded.num_samples)]
97
output = generate_samples_from_prompt(
98
neox_args=args_loaded,
101
maximum_tokens=args_loaded.maximum_tokens,
103
temperature=args_loaded.temperature,
104
top_k=args_loaded.top_k,
105
top_p=args_loaded.top_p,
108
# outputs only get generated on mp rank 0
110
assert len(output) == len(prompts)
111
for prompt, out in zip(prompts, output):
112
assert prompt == out["context"]
113
assert len(out["text"]) > 0