Skip to content

Commit

Permalink
Address CodeQL warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rmccorm4 committed Aug 22, 2024
1 parent fc4c15a commit 1ca9889
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ artifacts

# Test exclusions
qa/L0_openai/openai
qa/L0_openai/tensorrtllm_models
tensorrtllm_models
2 changes: 1 addition & 1 deletion python/openai/openai/src/utils/triton.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def get_output(response):
if "text_output" in response.outputs:
try:
return response.outputs["text_output"].to_string_array()[0]
except:
except Exception:
return str(response.outputs["text_output"].to_bytes_array()[0])
return ""

Expand Down
6 changes: 4 additions & 2 deletions python/openai/openai/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@
TEST_PROMPT = "What is machine learning?"
TEST_MESSAGES = [{"role": "user", "content": TEST_PROMPT}]
TEST_TOKENIZER = "meta-llama/Meta-Llama-3.1-8B-Instruct"

# Infer the test environment for simplicity in local dev/testing.
try:
import vllm as _

TEST_BACKEND = "vllm"
TEST_MODEL = "llama-3.1-8b-instruct"
except ImportError:
pass
print("No vllm installation found.")

try:
import tensorrt_llm as _

TEST_BACKEND = "tensorrtllm"
TEST_MODEL = "tensorrt_llm_bls"
except ImportError:
pass
print("No tensorrt_llm installation found.")

if not TEST_BACKEND or not TEST_MODEL:
raise Exception("Unknown test environment")
Expand Down
2 changes: 1 addition & 1 deletion python/openai/openai/tests/test_chat_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_chat_completions_defaults(self, client, model: str, messages: List[dict
assert message["content"].strip()
assert message["role"] == "assistant"
# "usage" currently not supported
assert response.json()["usage"] == None
assert not response.json()["usage"]

def test_chat_completions_system_prompt(self, client, model: str):
# NOTE: Currently just sanity check that there are no issues when a
Expand Down
2 changes: 1 addition & 1 deletion python/openai/openai/tests/test_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_completions_defaults(self, client, model: str, prompt: str):
# or tested with dummy identity model.
assert response.json()["choices"][0]["text"].strip()
# "usage" currently not supported
assert response.json()["usage"] == None
assert not response.json()["usage"]

@pytest.mark.parametrize(
"sampling_parameter, value",
Expand Down
22 changes: 13 additions & 9 deletions python/openai/openai/tests/test_observability.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ def test_startup_success(self, client):
response = client.get("/health")
assert response.status_code == 200

def test_startup_fail(self):
os.environ["TRITON_MODEL_REPOSITORY"] = "/does/not/exist"
with pytest.raises(Exception):
# Test that FastAPI lifespan startup fails when initializing Triton
# with unknown model repository.
app = init_app()
with TestClient(app):
pass

### Metrics ###
def test_startup_metrics(self, client):
response = client.get("/metrics")
Expand Down Expand Up @@ -96,3 +87,16 @@ def test_models_get(self, client, model):
assert model_resp["object"] == "model"
assert model_resp["created"] > 0
assert model_resp["owned_by"] == "Triton Inference Server"


# For tests that won't use the same pytest fixture for server startup across
# the whole class test suite.
class TestObservabilityCustomFixture:
def test_startup_fail(self):
os.environ["TRITON_MODEL_REPOSITORY"] = "/does/not/exist"
with pytest.raises(Exception):
# Test that FastAPI lifespan startup fails when initializing Triton
# with unknown model repository.
app = init_app()
with TestClient(app):
pass

0 comments on commit 1ca9889

Please sign in to comment.