-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1315 from dagardner-nv/david-fea-sherlock-nemo-se…
…rvice Docstrings & Tests for NeMoLLMService
- Loading branch information
Showing
10 changed files
with
362 additions
and
24 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# 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. | ||
|
||
import pytest | ||
|
||
from _utils import import_or_skip | ||
from _utils import require_env_variable | ||
|
||
|
||
@pytest.fixture(name="nemollm", autouse=True, scope='session') | ||
def nemollm_fixture(fail_missing: bool): | ||
""" | ||
All of the tests in this subdir require nemollm | ||
""" | ||
skip_reason = ("Tests for the NeMoLLMService require the nemollm package to be installed, to install this run:\n" | ||
"`mamba env update -n ${CONDA_DEFAULT_ENV} --file docker/conda/environments/cuda11.8_examples.yml`") | ||
yield import_or_skip("nemollm", reason=skip_reason, fail_missing=fail_missing) | ||
|
||
|
||
@pytest.fixture(name="ngc_api_key", scope='session') | ||
def ngc_api_key_fixture(fail_missing: bool): | ||
""" | ||
Integration tests require an NGC API key. | ||
""" | ||
yield require_env_variable( | ||
varname="NGC_API_KEY", | ||
reason="nemo integration tests require the `NGC_API_KEY` environment variavble to be defined.", | ||
fail_missing=fail_missing) |
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,56 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# 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 unittest import mock | ||
|
||
from morpheus.llm.services.nemo_llm_service import NeMoLLMClient | ||
|
||
|
||
def _make_mock_nemo_llm(): | ||
mock_nemo_llm = mock.MagicMock() | ||
mock_nemo_llm.return_value = mock_nemo_llm | ||
mock_nemo_llm.generate_multiple.return_value = ["test_output"] | ||
return mock_nemo_llm | ||
|
||
|
||
def _make_mock_nemo_service(): | ||
mock_nemo_llm = _make_mock_nemo_llm() | ||
mock_nemo_service = mock.MagicMock() | ||
mock_nemo_service.return_value = mock_nemo_service | ||
mock_nemo_service._conn = mock_nemo_llm | ||
return (mock_nemo_service, mock_nemo_llm) | ||
|
||
|
||
def test_generate(): | ||
(mock_nemo_service, mock_nemo_llm) = _make_mock_nemo_service() | ||
|
||
client = NeMoLLMClient(mock_nemo_service, "test_model", additional_arg="test_arg") | ||
assert client.generate("test_prompt") == "test_output" | ||
mock_nemo_llm.generate_multiple.assert_called_once_with(model="test_model", | ||
prompts=["test_prompt"], | ||
return_type="text", | ||
additional_arg="test_arg") | ||
|
||
|
||
def test_generate_batch(): | ||
(mock_nemo_service, mock_nemo_llm) = _make_mock_nemo_service() | ||
mock_nemo_llm.generate_multiple.return_value = ["output1", "output2"] | ||
|
||
client = NeMoLLMClient(mock_nemo_service, "test_model", additional_arg="test_arg") | ||
assert client.generate_batch(["prompt1", "prompt2"]) == ["output1", "output2"] | ||
mock_nemo_llm.generate_multiple.assert_called_once_with(model="test_model", | ||
prompts=["prompt1", "prompt2"], | ||
return_type="text", | ||
additional_arg="test_arg") |
Oops, something went wrong.