Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tuning/config/configs unit tests #85

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions tests/configs/test_configs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright The IBM Tuning Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Third Party
import torch

# Local
import tuning.config.configs as tuning_config

NEW_MODEL_NAME = "Maykeye/TinyLLama-v0"


def test_model_argument_configs_default():
data_arguments = tuning_config.DataArguments
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you add docstrings to these tests describing their goal and scope

model_arguments = tuning_config.ModelArguments
training_arguments = tuning_config.TrainingArguments
# test model arguments default
assert (
model_arguments.model_name_or_path == tuning_config.DEFAULT_MODEL_NAME_OR_PATH
)
assert model_arguments.use_flash_attn == True
assert isinstance(model_arguments.torch_dtype, torch.dtype)

# test data arguments default
assert data_arguments.data_path == None
assert data_arguments.response_template == None
assert data_arguments.dataset_text_field == None
assert data_arguments.validation_data_path == None

# test training arguments default
assert training_arguments.cache_dir == None
assert training_arguments.model_max_length == tuning_config.DEFAULT_CONTEXT_LENGTH
assert training_arguments.packing == False


def test_model_argument_configs_init():
# new data arguments
data_arguments = tuning_config.DataArguments(
data_path="/foo/bar",
response_template="\n### Label:",
dataset_text_field="output",
validation_data_path="/foo/bar",
)
assert data_arguments.data_path == "/foo/bar"
assert data_arguments.response_template == "\n### Label:"
assert data_arguments.validation_data_path == "/foo/bar"

# new model arguments
model_arguments = tuning_config.ModelArguments(
model_name_or_path=NEW_MODEL_NAME, use_flash_attn=False, torch_dtype=torch.int32
)
assert model_arguments.model_name_or_path == NEW_MODEL_NAME
assert model_arguments.use_flash_attn == False
assert model_arguments.torch_dtype == torch.int32

# new training arguments
training_arguments = tuning_config.TrainingArguments(
cache_dir="/tmp/cache",
model_max_length=1024,
packing=True,
output_dir="/tmp/output",
)
assert training_arguments.cache_dir == "/tmp/cache"
assert training_arguments.model_max_length == 1024
assert training_arguments.packing == True
assert training_arguments.output_dir == "/tmp/output"
3 changes: 2 additions & 1 deletion tuning/config/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

DEFAULT_CONTEXT_LENGTH = 4096
DEFAULT_OPTIMIZER = "adamw_torch"
DEFAULT_MODEL_NAME_OR_PATH = "facebook/opt-125m"

IGNORE_INDEX = -100
DEFAULT_PAD_TOKEN = "<PAD>"
Expand All @@ -32,7 +33,7 @@

@dataclass
class ModelArguments:
model_name_or_path: Optional[str] = field(default="facebook/opt-125m")
model_name_or_path: Optional[str] = field(default=DEFAULT_MODEL_NAME_OR_PATH)
use_flash_attn: bool = field(
default=True,
metadata={"help": "Use Flash attention v2 from transformers, default is True"},
Expand Down
Loading