Unverified Commit a3d46840 authored by KrishnanPrash's avatar KrishnanPrash Committed by GitHub
Browse files

ci: TRTLLM & SGLang Unit Tests (for --custom-jinja-template) (#3472)


Signed-off-by: default avatarKrishnan Prashanth <kprashanth@nvidia.com>
parent 0e0218ff
...@@ -137,7 +137,14 @@ jobs: ...@@ -137,7 +137,14 @@ jobs:
azure_acr_hostname: ${{ secrets.AZURE_ACR_HOSTNAME }} azure_acr_hostname: ${{ secrets.AZURE_ACR_HOSTNAME }}
azure_acr_user: ${{ secrets.AZURE_ACR_USER }} azure_acr_user: ${{ secrets.AZURE_ACR_USER }}
azure_acr_password: ${{ secrets.AZURE_ACR_PASSWORD }} azure_acr_password: ${{ secrets.AZURE_ACR_PASSWORD }}
- name: Run tests - name: Run unit tests
# OPS-1140: Uncomment the below line
# if: ${{ matrix.platform.arch != 'arm64' }}
uses: ./.github/actions/pytest
with:
image_tag: ${{ steps.build-image.outputs.image_tag }}
pytest_marks: "unit and sglang and gpu_1"
- name: Run e2e tests
# OPS-1140: Uncomment the below line # OPS-1140: Uncomment the below line
# if: ${{ matrix.platform.arch != 'arm64' }} # if: ${{ matrix.platform.arch != 'arm64' }}
uses: ./.github/actions/pytest uses: ./.github/actions/pytest
...@@ -185,7 +192,13 @@ jobs: ...@@ -185,7 +192,13 @@ jobs:
azure_acr_hostname: ${{ secrets.AZURE_ACR_HOSTNAME }} azure_acr_hostname: ${{ secrets.AZURE_ACR_HOSTNAME }}
azure_acr_user: ${{ secrets.AZURE_ACR_USER }} azure_acr_user: ${{ secrets.AZURE_ACR_USER }}
azure_acr_password: ${{ secrets.AZURE_ACR_PASSWORD }} azure_acr_password: ${{ secrets.AZURE_ACR_PASSWORD }}
- name: Run tests - name: Run unit tests
if: ${{ matrix.platform.arch != 'arm64' }}
uses: ./.github/actions/pytest
with:
image_tag: ${{ steps.build-image.outputs.image_tag }}
pytest_marks: "unit and trtllm_marker and gpu_1"
- name: Run e2e tests
if: ${{ matrix.platform.arch != 'arm64' }} if: ${{ matrix.platform.arch != 'arm64' }}
uses: ./.github/actions/pytest uses: ./.github/actions/pytest
with: with:
......
...@@ -316,6 +316,11 @@ def parse_args(args: list[str]) -> Config: ...@@ -316,6 +316,11 @@ def parse_args(args: list[str]) -> Config:
expanded_template_path = os.path.expandvars( expanded_template_path = os.path.expandvars(
os.path.expanduser(parsed_args.custom_jinja_template) os.path.expanduser(parsed_args.custom_jinja_template)
) )
# Validate custom Jinja template file exists
if not os.path.isfile(expanded_template_path):
raise FileNotFoundError(
f"Custom Jinja template file not found: {expanded_template_path}"
)
dynamo_args = DynamoArgs( dynamo_args = DynamoArgs(
namespace=parsed_namespace, namespace=parsed_namespace,
......
...@@ -385,6 +385,11 @@ def cmd_line_args(): ...@@ -385,6 +385,11 @@ def cmd_line_args():
expanded_template_path = os.path.expandvars( expanded_template_path = os.path.expandvars(
os.path.expanduser(args.custom_jinja_template) os.path.expanduser(args.custom_jinja_template)
) )
# Validate custom Jinja template file exists
if not os.path.isfile(expanded_template_path):
raise FileNotFoundError(
f"Custom Jinja template file not found: {expanded_template_path}"
)
config.custom_jinja_template = expanded_template_path config.custom_jinja_template = expanded_template_path
else: else:
config.custom_jinja_template = None config.custom_jinja_template = None
......
...@@ -166,6 +166,10 @@ filterwarnings = [ ...@@ -166,6 +166,10 @@ filterwarnings = [
"ignore:.*unclosed event loop.*:ResourceWarning", # Ignore unclosed event loop warnings "ignore:.*unclosed event loop.*:ResourceWarning", # Ignore unclosed event loop warnings
"ignore:.*Exception ignored in.*:pytest.PytestUnraisableExceptionWarning", # Ignore unraisable exception warnings "ignore:.*Exception ignored in.*:pytest.PytestUnraisableExceptionWarning", # Ignore unraisable exception warnings
"ignore:The pynvml package is deprecated.*:FutureWarning", # Ignore pynvml deprecation warning, temporary until upstream library updates to nvidia-ml-py "ignore:The pynvml package is deprecated.*:FutureWarning", # Ignore pynvml deprecation warning, temporary until upstream library updates to nvidia-ml-py
# Pydantic V2 deprecation warnings from TRTLLM dependencies (raised at import time during collection)
"ignore:Support for class-based `config`.*:pydantic.warnings.PydanticDeprecatedSince20",
"ignore:Using extra keyword arguments on `Field`.*:pydantic.warnings.PydanticDeprecatedSince20",
"ignore:The `schema` method is deprecated.*:pydantic.warnings.PydanticDeprecatedSince20",
] ]
......
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Unit tests for SGLang backend components."""
import re
import sys
from pathlib import Path
import pytest
from dynamo.sglang.args import parse_args
# Get path relative to this test file
TEST_DIR = Path(__file__).parent.parent
JINJA_TEMPLATE_PATH = str(TEST_DIR / "serve" / "fixtures" / "custom_template.jinja")
pytestmark = [
pytest.mark.unit,
pytest.mark.sglang,
pytest.mark.gpu_1,
]
def test_custom_jinja_template_invalid_path(monkeypatch):
"""Test that invalid file path raises FileNotFoundError."""
invalid_path = "/nonexistent/path/to/template.jinja"
monkeypatch.setattr(
sys,
"argv",
[
"dynamo.sglang",
"--model-path",
"Qwen/Qwen3-0.6B",
"--custom-jinja-template",
invalid_path,
],
)
with pytest.raises(
FileNotFoundError,
match=re.escape(f"Custom Jinja template file not found: {invalid_path}"),
):
parse_args(sys.argv[1:])
def test_custom_jinja_template_valid_path(monkeypatch):
"""Test that valid absolute path is stored correctly."""
monkeypatch.setattr(
sys,
"argv",
[
"dynamo.sglang",
"--model-path",
"Qwen/Qwen3-0.6B",
"--custom-jinja-template",
JINJA_TEMPLATE_PATH,
],
)
config = parse_args(sys.argv[1:])
assert config.dynamo_args.custom_jinja_template == JINJA_TEMPLATE_PATH, (
f"Expected custom_jinja_template value to be {JINJA_TEMPLATE_PATH}, "
f"got {config.dynamo_args.custom_jinja_template}"
)
def test_custom_jinja_template_env_var_expansion(monkeypatch):
"""Test that environment variables in paths are expanded by Python code."""
jinja_dir = str(TEST_DIR / "serve" / "fixtures")
monkeypatch.setenv("JINJA_DIR", jinja_dir)
cli_path = "$JINJA_DIR/custom_template.jinja"
monkeypatch.setattr(
sys,
"argv",
[
"dynamo.sglang",
"--model-path",
"Qwen/Qwen3-0.6B",
"--custom-jinja-template",
cli_path,
],
)
config = parse_args(sys.argv[1:])
assert "$JINJA_DIR" not in config.dynamo_args.custom_jinja_template
assert config.dynamo_args.custom_jinja_template == JINJA_TEMPLATE_PATH, (
f"Expected custom_jinja_template value to be {JINJA_TEMPLATE_PATH}, "
f"got {config.dynamo_args.custom_jinja_template}"
)
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Unit tests for TRTLLM backend components."""
import re
import sys
from pathlib import Path
import pytest
from dynamo.trtllm.utils.trtllm_utils import cmd_line_args
# Get path relative to this test file
TEST_DIR = Path(__file__).parent.parent
JINJA_TEMPLATE_PATH = str(TEST_DIR / "serve" / "fixtures" / "custom_template.jinja")
pytestmark = [
pytest.mark.unit,
pytest.mark.trtllm_marker,
pytest.mark.gpu_1,
]
def test_custom_jinja_template_invalid_path(monkeypatch):
"""Test that invalid file path raises FileNotFoundError."""
invalid_path = "/nonexistent/path/to/template.jinja"
monkeypatch.setattr(
sys,
"argv",
[
"dynamo.trtllm",
"--model-path",
"Qwen/Qwen3-0.6B",
"--custom-jinja-template",
invalid_path,
],
)
with pytest.raises(
FileNotFoundError,
match=re.escape(f"Custom Jinja template file not found: {invalid_path}"),
):
cmd_line_args()
def test_custom_jinja_template_valid_path(monkeypatch):
"""Test that valid absolute path is stored correctly."""
monkeypatch.setattr(
sys,
"argv",
[
"dynamo.trtllm",
"--model-path",
"Qwen/Qwen3-0.6B",
"--custom-jinja-template",
JINJA_TEMPLATE_PATH,
],
)
config = cmd_line_args()
assert config.custom_jinja_template == JINJA_TEMPLATE_PATH, (
f"Expected custom_jinja_template value to be {JINJA_TEMPLATE_PATH}, "
f"got {config.custom_jinja_template}"
)
def test_custom_jinja_template_env_var_expansion(monkeypatch):
"""Test that environment variables in paths are expanded by Python code."""
jinja_dir = str(TEST_DIR / "serve" / "fixtures")
monkeypatch.setenv("JINJA_DIR", jinja_dir)
cli_path = "$JINJA_DIR/custom_template.jinja"
monkeypatch.setattr(
sys,
"argv",
[
"dynamo.trtllm",
"--model-path",
"Qwen/Qwen3-0.6B",
"--custom-jinja-template",
cli_path,
],
)
config = cmd_line_args()
assert "$JINJA_DIR" not in config.custom_jinja_template
assert config.custom_jinja_template == JINJA_TEMPLATE_PATH, (
f"Expected custom_jinja_template value to be {JINJA_TEMPLATE_PATH}, "
f"got {config.custom_jinja_template}"
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment