forked from foundation-model-stack/fms-hf-tuning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sample unit tests (foundation-model-stack#61)
* add sample unit test Signed-off-by: ted chang <[email protected]> * Update tests/utils/test_data_type_utils.py Co-authored-by: Sukriti Sharma <[email protected]> Signed-off-by: ted chang <[email protected]> * Update tests/utils/test_data_type_utils.py Co-authored-by: Sukriti Sharma <[email protected]> Signed-off-by: ted chang <[email protected]> * re-raise valueError instead of exit Signed-off-by: ted chang <[email protected]> --------- Signed-off-by: ted chang <[email protected]> Co-authored-by: Sukriti Sharma <[email protected]>
- Loading branch information
Showing
4 changed files
with
67 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.9 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install -r setup_requirements.txt | ||
- name: Run unit tests | ||
run: tox -e 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,35 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# https://spdx.dev/learn/handling-license-info/ | ||
|
||
# Third Party | ||
import pytest | ||
import torch | ||
|
||
# Local | ||
from tuning.utils import data_type_utils | ||
|
||
dtype_dict = { | ||
"bool": torch.bool, | ||
"double": torch.double, | ||
"float32": torch.float32, | ||
"int64": torch.int64, | ||
"long": torch.long, | ||
} | ||
|
||
|
||
def test_str_to_torch_dtype(): | ||
for t in dtype_dict.keys(): | ||
assert data_type_utils.str_to_torch_dtype(t) == dtype_dict.get(t) | ||
|
||
|
||
def test_str_to_torch_dtype_exit(): | ||
with pytest.raises(ValueError): | ||
data_type_utils.str_to_torch_dtype("foo") | ||
|
||
|
||
def test_get_torch_dtype(): | ||
for t in dtype_dict.keys(): | ||
# When passed a string, it gets converted to torch.dtype | ||
assert data_type_utils.get_torch_dtype(t) == dtype_dict.get(t) | ||
# When passed a torch.dtype, we get the same torch.dtype returned | ||
assert data_type_utils.get_torch_dtype(dtype_dict.get(t)) == dtype_dict.get(t) |
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