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

moved all triton tests into runtime triton folder #260

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import pytest

pytest.importorskip("faiss")
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

import pytest

pytest.importorskip("implicit")
85 changes: 85 additions & 0 deletions tests/unit/systems/dag/runtimes/triton/ops/implicit/test_op.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#
# Copyright (c) 2022, NVIDIA CORPORATION.
#
# 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.
#
from distutils.spawn import find_executable

import implicit
import numpy as np
import pytest
from scipy.sparse import csr_matrix
from tritonclient import grpc as grpcclient

from merlin.schema import ColumnSchema, Schema
from merlin.systems.dag.ensemble import Ensemble
from merlin.systems.dag.ops.implicit import PredictImplicit
from merlin.systems.dag.runtimes.triton import TritonExecutorRuntime
from merlin.systems.triton.utils import run_triton_server

TRITON_SERVER_PATH = find_executable("tritonserver")

triton = pytest.importorskip("merlin.systems.triton")


@pytest.mark.skipif(not TRITON_SERVER_PATH, reason="triton server not found")
@pytest.mark.parametrize("runtime", [None, TritonExecutorRuntime()])
@pytest.mark.parametrize(
"model_cls",
[
implicit.bpr.BayesianPersonalizedRanking,
implicit.als.AlternatingLeastSquares,
implicit.lmf.LogisticMatrixFactorization,
],
)
def test_ensemble(model_cls, runtime, tmpdir):
model = model_cls()
n = 100
user_items = csr_matrix(np.random.choice([0, 1], size=n * n, p=[0.9, 0.1]).reshape(n, n))
model.fit(user_items)

num_to_recommend = np.random.randint(1, n)

user_items = None
ids, scores = model.recommend(
[0, 1], user_items, N=num_to_recommend, filter_already_liked_items=False
)

implicit_op = PredictImplicit(model, num_to_recommend=num_to_recommend)

input_schema = Schema([ColumnSchema("user_id", dtype="int64")])

triton_chain = input_schema.column_names >> implicit_op

triton_ens = Ensemble(triton_chain, input_schema)
ensemble_config, _ = triton_ens.export(tmpdir, runtime=runtime)

input_user_id = np.array([[0], [1]], dtype=np.int64)
inputs = [
grpcclient.InferInput(
"user_id", input_user_id.shape, triton.np_to_triton_dtype(input_user_id.dtype)
),
]
inputs[0].set_data_from_numpy(input_user_id)
outputs = [grpcclient.InferRequestedOutput("scores"), grpcclient.InferRequestedOutput("ids")]

response = None

with run_triton_server(tmpdir) as client:
response = client.infer(ensemble_config.name, inputs, outputs=outputs)

response_ids = response.as_numpy("ids")
response_scores = response.as_numpy("scores")

np.testing.assert_array_equal(ids, response_ids)
np.testing.assert_array_equal(scores, response_scores)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022, NVIDIA CORPORATION.
# Copyright (c) 2021, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,3 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

import pytest

pytest.importorskip("tensorflow")
File renamed without changes.
3 changes: 0 additions & 3 deletions tests/unit/systems/dag/test_executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.
#
import random
from distutils.spawn import find_executable

import numpy as np
import pandas as pd
Expand All @@ -28,8 +27,6 @@
from merlin.systems.dag.ensemble import Ensemble
from merlin.systems.dag.ops.session_filter import FilterCandidates

TRITON_SERVER_PATH = find_executable("tritonserver")


def test_run_dag_on_dictarray_with_local_executor():
request_schema = Schema(
Expand Down
64 changes: 1 addition & 63 deletions tests/unit/systems/ops/implicit/test_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,14 @@
# limitations under the License.
#
import json
from distutils.spawn import find_executable

import implicit
import numpy as np
import pytest
from scipy.sparse import csr_matrix
from tritonclient import grpc as grpcclient

from merlin.schema import ColumnSchema, Schema
from merlin.systems.dag.ensemble import Ensemble
from merlin.schema import Schema
from merlin.systems.dag.ops.implicit import PredictImplicit
from merlin.systems.dag.runtimes.triton import TritonExecutorRuntime
from merlin.systems.triton.utils import run_triton_server

TRITON_SERVER_PATH = find_executable("tritonserver")

triton = pytest.importorskip("merlin.systems.triton")


@pytest.mark.parametrize(
Expand Down Expand Up @@ -73,56 +64,3 @@ def test_reload_from_config(model_cls, tmpdir):

np.testing.assert_array_equal(ids, reloaded_ids)
np.testing.assert_array_equal(scores, reloaded_scores)


@pytest.mark.skipif(not TRITON_SERVER_PATH, reason="triton server not found")
@pytest.mark.parametrize("runtime", [None, TritonExecutorRuntime()])
@pytest.mark.parametrize(
"model_cls",
[
implicit.bpr.BayesianPersonalizedRanking,
implicit.als.AlternatingLeastSquares,
implicit.lmf.LogisticMatrixFactorization,
],
)
def test_ensemble(model_cls, runtime, tmpdir):
model = model_cls()
n = 100
user_items = csr_matrix(np.random.choice([0, 1], size=n * n, p=[0.9, 0.1]).reshape(n, n))
model.fit(user_items)

num_to_recommend = np.random.randint(1, n)

user_items = None
ids, scores = model.recommend(
[0, 1], user_items, N=num_to_recommend, filter_already_liked_items=False
)

implicit_op = PredictImplicit(model, num_to_recommend=num_to_recommend)

input_schema = Schema([ColumnSchema("user_id", dtype="int64")])

triton_chain = input_schema.column_names >> implicit_op

triton_ens = Ensemble(triton_chain, input_schema)
ensemble_config, _ = triton_ens.export(tmpdir, runtime=runtime)

input_user_id = np.array([[0], [1]], dtype=np.int64)
inputs = [
grpcclient.InferInput(
"user_id", input_user_id.shape, triton.np_to_triton_dtype(input_user_id.dtype)
),
]
inputs[0].set_data_from_numpy(input_user_id)
outputs = [grpcclient.InferRequestedOutput("scores"), grpcclient.InferRequestedOutput("ids")]

response = None

with run_triton_server(tmpdir) as client:
response = client.infer(ensemble_config.name, inputs, outputs=outputs)

response_ids = response.as_numpy("ids")
response_scores = response.as_numpy("scores")

np.testing.assert_array_equal(ids, response_ids)
np.testing.assert_array_equal(scores, response_scores)