Skip to content

Commit 5fd8277

Browse files
Update test config to get postmerge tests running correctly (#359)
* Add OPAL_PREFIX to passenv in test-gpu-postmerge This is required for horovod init to work correctly * Move merlin-models dependency to test.txt * Trigger postmerge on pull_request to check they run sucessfully * Skip test_transformer_model if tritonserver not found * Use match_representations for example input matching input schema * Update formatting of conversions.py * Add noqa to match_representations import * Try setting LD_LIBRARY_PATH for pytorch tests * Move LD_LIBRARY_PATH config to setenv * Add OPAL_PREFIX passenv to test-gpu tox environment * Restore tensorflow constraint on test-cpu.txt * Remove pull_request trigger from postmerge workflows
1 parent 7c19072 commit 5fd8277

File tree

7 files changed

+56
-8
lines changed

7 files changed

+56
-8
lines changed

merlin/systems/triton/conversions.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

2727
import itertools
28+
from functools import singledispatch
2829
from typing import Any, Dict, List
2930

3031
import numpy as np
@@ -33,6 +34,7 @@
3334
import merlin.dtypes as md
3435
from merlin.core.compat import cudf
3536
from merlin.core.compat import cupy as cp
37+
from merlin.core.compat.torch import torch
3638
from merlin.core.dispatch import build_cudf_list_column, is_list_dtype
3739
from merlin.dag import Supports
3840
from merlin.schema import Schema
@@ -135,19 +137,24 @@ def _from_values_offsets(values, offsets, shape):
135137
return values.reshape(new_shape)
136138

137139

138-
def _to_values_offsets(array):
140+
@singledispatch
141+
def _to_values_offsets(values):
139142
"""Convert array to values/offsets representation
140143
141144
Parameters
142145
----------
143-
array : numpy.ndarray or cupy.ndarray
144-
Array to convert
146+
values : array or tensor
147+
Array or tensor to convert
145148
146149
Returns
147150
-------
148151
values, offsets
149152
Tuple of values and offsets
150153
"""
154+
raise NotImplementedError(f"_to_values_offsets not implemented for {type(values)}")
155+
156+
157+
def _to_values_offsets_array(array):
151158
num_rows = array.shape[0]
152159
row_lengths = [array.shape[1]] * num_rows
153160
offsets = [0] + list(itertools.accumulate(row_lengths))
@@ -157,6 +164,30 @@ def _to_values_offsets(array):
157164
return values, offsets
158165

159166

167+
@_to_values_offsets.register(np.ndarray)
168+
def _(array):
169+
return _to_values_offsets_array(array)
170+
171+
172+
if cp:
173+
174+
@_to_values_offsets.register(cp.ndarray)
175+
def _(array):
176+
return _to_values_offsets_array(array)
177+
178+
179+
if torch:
180+
181+
@_to_values_offsets.register(torch.Tensor)
182+
def _(tensor):
183+
num_rows = tensor.shape[0]
184+
row_lengths = [tensor.shape[1]] * num_rows
185+
offsets = [0] + list(itertools.accumulate(row_lengths))
186+
offsets = torch.tensor(offsets, dtype=torch.int32, device=tensor.device)
187+
values = tensor.reshape(-1, *tensor.shape[2:])
188+
return values, offsets
189+
190+
160191
def triton_request_to_tensor_table(request, schema):
161192
"""
162193
Turns a Triton request into a TensorTable by extracting individual tensors

requirements/test-cpu.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
-r test.txt
22

3-
merlin-models>=0.6.0
43
faiss-cpu==1.7.2
54
tensorflow<=2.9.0
65
treelite==2.4.0

requirements/test-gpu.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
-r test.txt
22

3-
tensorflow
43
faiss-gpu==1.7.2

requirements/test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ feast==0.31
1818
xgboost==1.6.2
1919
implicit==0.6.0
2020

21+
merlin-models[tensorflow,pytorch,transformers]@git+https://github.com/NVIDIA-Merlin/models.git
22+
2123
# TODO: do we need more of these?
2224
# https://github.com/NVIDIA-Merlin/Merlin/blob/a1cc48fe23c4dfc627423168436f26ef7e028204/ci/dockerfile.ci#L13-L18

tests/integration/t4r/test_pytorch_backend.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# limitations under the License.
1515
#
1616

17+
import shutil
18+
1719
import pytest
1820

1921
np = pytest.importorskip("numpy")
@@ -30,9 +32,13 @@
3032
from merlin.core.dispatch import make_df # noqa
3133
from merlin.systems.dag import Ensemble # noqa
3234
from merlin.systems.dag.ops.pytorch import PredictPyTorch # noqa
35+
from merlin.systems.triton.conversions import match_representations # noqa
3336
from merlin.systems.triton.utils import run_ensemble_on_tritonserver # noqa
3437

38+
TRITON_SERVER_PATH = shutil.which("tritonserver")
39+
3540

41+
@pytest.mark.skipif(not TRITON_SERVER_PATH, reason="triton server not found")
3642
def test_serve_t4r_with_torchscript(tmpdir):
3743
# ===========================================
3844
# Generate training data
@@ -69,11 +75,12 @@ def test_serve_t4r_with_torchscript(tmpdir):
6975

7076
model.eval()
7177

72-
traced_model = torch.jit.trace(model, torch_yoochoose_like, strict=True)
78+
example_inputs = match_representations(model.input_schema, torch_yoochoose_like)
79+
traced_model = torch.jit.trace(model, example_inputs, strict=True)
7380
assert isinstance(traced_model, torch.jit.TopLevelTracedModule)
7481
assert torch.allclose(
75-
model(torch_yoochoose_like),
76-
traced_model(torch_yoochoose_like),
82+
model(example_inputs),
83+
traced_model(example_inputs),
7784
)
7885

7986
# ===========================================

tests/integration/tf/test_transformer_model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# limitations under the License.
1515
#
1616

17+
import shutil
18+
1719
import pytest
1820

1921
tf = pytest.importorskip("tensorflow")
@@ -31,7 +33,10 @@
3133
from merlin.systems.dag.ops.tensorflow import PredictTensorflow # noqa
3234
from merlin.systems.triton.utils import run_ensemble_on_tritonserver # noqa
3335

36+
TRITON_SERVER_PATH = shutil.which("tritonserver")
37+
3438

39+
@pytest.mark.skipif(not TRITON_SERVER_PATH, reason="triton server not found")
3540
def test_serve_tf_session_based_with_libtensorflow(tmpdir):
3641

3742
# ===========================================

tox.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ sitepackages=true
4747
; need to add some back.
4848
setenv =
4949
TF_GPU_ALLOCATOR=cuda_malloc_async
50+
passenv =
51+
OPAL_PREFIX
5052
deps =
5153
-rrequirements/test-gpu.txt
5254
pytest
@@ -71,6 +73,9 @@ sitepackages=true
7173
; need to add some back.
7274
setenv =
7375
TF_GPU_ALLOCATOR=cuda_malloc_async
76+
LD_LIBRARY_PATH=/opt/tritonserver/backends/pytorch
77+
passenv =
78+
OPAL_PREFIX
7479
deps =
7580
pytest
7681
pytest-cov

0 commit comments

Comments
 (0)