Skip to content

Commit

Permalink
Merge branch 'main' into torch/dlrm
Browse files Browse the repository at this point in the history
  • Loading branch information
edknv committed Jun 30, 2023
2 parents c9d43da + 94f74b5 commit 9610618
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
if [[ "${{ github.ref }}" != 'refs/heads/main' ]]; then
extra_pytest_markers="and changed"
fi
cd ${{ github.workspace }}; PYTEST_MARKERS="unit and not (examples or integration or notebook) $extra_pytest_markers" MERLIN_BRANCH=$branch COMPARE_BRANCH=${{ github.base_ref }} tox -e py38-gpu
cd ${{ github.workspace }}; PYTEST_MARKERS="unit and not (examples or integration or notebook) $extra_pytest_markers" MERLIN_BRANCH=$branch COMPARE_BRANCH=${{ github.base_ref }} tox -e py310-gpu
tests-examples:
runs-on: 1GPU
Expand All @@ -55,4 +55,4 @@ jobs:
if [[ "${{ github.ref }}" != 'refs/heads/main' ]]; then
extra_pytest_markers="and changed"
fi
cd ${{ github.workspace }}; PYTEST_MARKERS="(examples or notebook) $extra_pytest_markers" MERLIN_BRANCH=$branch COMPARE_BRANCH=${{ github.base_ref }} tox -e py38-gpu
cd ${{ github.workspace }}; PYTEST_MARKERS="(examples or notebook) $extra_pytest_markers" MERLIN_BRANCH=$branch COMPARE_BRANCH=${{ github.base_ref }} tox -e py310-gpu
16 changes: 7 additions & 9 deletions merlin/models/torch/outputs/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,22 @@ class BinaryOutput(ModelOutput):
The metrics used for evaluation. Default includes Accuracy, AUROC, Precision, and Recall.
"""

DEFAULT_LOSS_CLS = nn.BCEWithLogitsLoss
DEFAULT_METRICS_CLS = (Accuracy, AUROC, Precision, Recall)

def __init__(
self,
schema: Optional[ColumnSchema] = None,
loss: nn.Module = nn.BCEWithLogitsLoss(),
metrics: Sequence[Metric] = (
Accuracy(task="binary"),
AUROC(task="binary"),
Precision(task="binary"),
Recall(task="binary"),
),
loss: Optional[nn.Module] = None,
metrics: Sequence[Metric] = (),
):
"""Initializes a BinaryOutput object."""
super().__init__(
nn.LazyLinear(1),
nn.Sigmoid(),
schema=schema,
loss=loss,
metrics=metrics,
loss=loss or self.DEFAULT_LOSS_CLS(),
metrics=metrics or [m(task="binary") for m in self.DEFAULT_METRICS_CLS],
)

def setup_schema(self, target: Optional[Union[ColumnSchema, Schema]]):
Expand Down
11 changes: 7 additions & 4 deletions merlin/models/torch/outputs/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ class RegressionOutput(ModelOutput):
The metrics used for evaluation. Default is MeanSquaredError.
"""

DEFAULT_LOSS_CLS = nn.MSELoss
DEFAULT_METRICS_CLS = (MeanSquaredError,)

def __init__(
self,
schema: Optional[ColumnSchema] = None,
loss: nn.Module = nn.MSELoss(),
metrics: Sequence[Metric] = (MeanSquaredError(),),
loss: Optional[nn.Module] = None,
metrics: Sequence[Metric] = (),
):
"""Initializes a RegressionOutput object."""
super().__init__(
nn.LazyLinear(1),
schema=schema,
loss=loss,
metrics=metrics,
loss=loss or self.DEFAULT_LOSS_CLS(),
metrics=metrics or [m() for m in self.DEFAULT_METRICS_CLS],
)

def setup_schema(self, target: Optional[Union[ColumnSchema, Schema]]):
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/torch/outputs/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def test_init(self):

assert isinstance(binary_output, mm.BinaryOutput)
assert isinstance(binary_output.loss, nn.BCEWithLogitsLoss)
assert binary_output.metrics == (
assert binary_output.metrics == [
Accuracy(task="binary"),
AUROC(task="binary"),
Precision(task="binary"),
Recall(task="binary"),
)
]
assert binary_output.output_schema == Schema()

def test_identity(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/torch/outputs/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_init(self):

assert isinstance(reg_output, mm.RegressionOutput)
assert isinstance(reg_output.loss, nn.MSELoss)
assert reg_output.metrics == (MeanSquaredError,)
assert reg_output.metrics == [MeanSquaredError()]
assert reg_output.output_schema == Schema()

def test_identity(self):
Expand Down
16 changes: 8 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
; .github/workflows/cpu-ci.yml for the workflow definition.

[tox]
envlist = py38-gpu,py38-multi-gpu
envlist = py310-gpu,py310-multi-gpu

[testenv]
commands =
pip install --upgrade pip
pip install -e .[all]

[testenv:py38-gpu]
[testenv:py310-gpu]
; Runs in: Github Actions
; Runs GPU-based tests.
allowlist_externals =
Expand All @@ -28,7 +28,7 @@ commands =
python -m pip install --upgrade git+https://github.com/NVIDIA-Merlin/systems.git@{env:MERLIN_BRANCH:main}
bash -c 'python -m pytest --cov-report term --cov merlin -m "{env:PYTEST_MARKERS}" -rxs tests/ || ([ $? = 5 ] && exit 0 || exit $?)'

[testenv:py38-multi-gpu]
[testenv:py310-multi-gpu]
; Runs in: Github Actions
; Runs GPU-based tests.
allowlist_externals =
Expand All @@ -40,7 +40,7 @@ passenv =
setenv =
TF_GPU_ALLOCATOR=cuda_malloc_async
CPATH={env:CPATH}{:}{envdir}/hugectr/include
LD_LIBRARY_PATH=${envdir}/hugectr/include/lib{:}/usr/local/lib/python3.8/dist-packages/tensorflow{:}{env:LD_LIBRARY_PATH}
LD_LIBRARY_PATH=${envdir}/hugectr/include/lib{:}/usr/local/lib/python3.10/dist-packages/tensorflow{:}{env:LD_LIBRARY_PATH}
LIBRARY_PATH=${envdir}/hugectr/lib{:}{env:LIBRARY_PATH}
sitepackages=true
commands =
Expand All @@ -50,7 +50,7 @@ commands =
sh examples/usecases/multi-gpu/install_sparse_operation_kit.sh {envdir}
bash -c 'horovodrun -np 2 sh examples/usecases/multi-gpu/hvd_wrapper.sh python -m pytest -m "horovod {env:EXTRA_PYTEST_MARKERS}" -rxs tests/unit || ([ $? = 5 ] && exit 0 || exit $?)'

[testenv:py38-horovod-cpu]
[testenv:py310-horovod-cpu]
setenv =
HOROVOD_WITH_MPI=1
HOROVOD_WITH_TENSORFLOW=1
Expand All @@ -66,7 +66,7 @@ commands =
{envdir}/env/bin/python -m pip install --upgrade git+https://github.com/NVIDIA-Merlin/nvtabular.git@{env:MERLIN_BRANCH:main}
{envdir}/env/bin/horovodrun -np 2 sh examples/usecases/multi-gpu/hvd_wrapper.sh pytest -m "horovod {env:EXTRA_PYTEST_MARKERS}" -rxs tests/unit

[testenv:py38-nvtabular-cpu]
[testenv:py310-nvtabular-cpu]
passenv=GIT_COMMIT
allowlist_externals = git
deps =
Expand All @@ -82,7 +82,7 @@ commands =
python -m pip install .
python -m pytest nvtabular-{env:GIT_COMMIT}/tests/unit

[testenv:py38-systems-cpu]
[testenv:py310-systems-cpu]
passenv=GIT_COMMIT
allowlist_externals = git
deps =
Expand All @@ -99,7 +99,7 @@ commands =
python -m pip install .
python -m pytest -m "not notebook" systems-{env:GIT_COMMIT}/tests/unit

[testenv:py38-transformers4rec-cpu]
[testenv:py310-transformers4rec-cpu]
passenv=GIT_COMMIT
allowlist_externals = git
commands =
Expand Down

0 comments on commit 9610618

Please sign in to comment.