Skip to content

Commit

Permalink
factor out log group funcs into utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
renxida committed Nov 17, 2024
1 parent cbe008a commit ba28a00
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
24 changes: 6 additions & 18 deletions app_tests/integration_tests/llm/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,13 @@
compile_model,
find_available_port,
start_llm_server,
start_log_group,
end_log_group,
)

logger = logging.getLogger(__name__)


def ghstartgroup(msg):
# check if we are in github ci
if os.environ.get("GITHUB_ACTIONS") != "true":
return ""
return f"\n::group::{msg}"


def ghendgroup():
# check if we are in github ci
if os.environ.get("GITHUB_ACTIONS") != "true":
return ""
return "\n::endgroup::"


@pytest.fixture(scope="module")
def model_test_dir(request, tmp_path_factory):
"""Prepare model artifacts for starting the LLM server.
Expand All @@ -55,7 +43,7 @@ def model_test_dir(request, tmp_path_factory):
Tuple[Path, Path]: The paths to the Hugging Face home and the temp dir.
"""
logger.info(
"Preparing model artifacts..." + ghstartgroup("Preparing model artifacts")
"Preparing model artifacts..." + start_log_group("Preparing model artifacts")
)

repo_id = request.param["repo_id"]
Expand Down Expand Up @@ -101,7 +89,7 @@ def model_test_dir(request, tmp_path_factory):
logger.info(f"Config: {json.dumps(config, indent=2)}")
with open(edited_config_path, "w") as f:
json.dump(config, f)
logger.info("Model artifacts setup successfully" + ghendgroup())
logger.info("Model artifacts setup successfully" + end_log_group())
yield hf_home, tmp_dir
finally:
shutil.rmtree(tmp_dir)
Expand All @@ -126,7 +114,7 @@ def llm_server(request, model_test_dir, available_port):
Yields:
subprocess.Popen: The server process that was started.
"""
logger.info("Starting LLM server..." + ghstartgroup("Starting LLM server"))
logger.info("Starting LLM server..." + start_log_group("Starting LLM server"))
hf_home, tmp_dir = model_test_dir
model_file = request.param["model_file"]
settings = request.param["settings"]
Expand All @@ -145,7 +133,7 @@ def llm_server(request, model_test_dir, available_port):
parameters_path,
settings,
)
logger.info("LLM server started!" + ghendgroup())
logger.info("LLM server started!" + end_log_group())
yield server_process
# Teardown: kill the server
server_process.terminate()
Expand Down
8 changes: 6 additions & 2 deletions app_tests/integration_tests/llm/cpu_llm_server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import requests
import uuid

from .utils import AccuracyValidationException
from .utils import AccuracyValidationException, start_log_group, end_log_group

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -84,7 +84,10 @@ def test_llm_server(llm_server, available_port):
assert llm_server.poll() is None
PROMPT = "1 2 3 4 5 "
expected_output_prefix = "6 7 8"
logger.info("::group::Sending HTTP Generation Request")
logger.info(
"Sending HTTP Generation Request"
+ start_log_group("Sending HTTP Generation Request")
)
output = do_generate(PROMPT, available_port)
# log to GITHUB_STEP_SUMMARY if we are in a GitHub Action
if "GITHUB_ACTION" in os.environ:
Expand All @@ -98,3 +101,4 @@ def test_llm_server(llm_server, available_port):
raise AccuracyValidationException(
f"Expected '{output}' to start with '{expected_output_prefix}'"
)
logger.info("HTTP Generation Request Successful" + end_log_group())
14 changes: 14 additions & 0 deletions app_tests/integration_tests/llm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,17 @@ def start_llm_server(
# Wait for server to start
wait_for_server(f"http://localhost:{port}", timeout)
return server_process


def start_log_group(headline):
# check if we are in github ci
if os.environ.get("GITHUB_ACTIONS") == "true":
return f"\n::group::{headline}"
return ""


def end_log_group():
# check if we are in github ci
if os.environ.get("GITHUB_ACTIONS") == "true":
return "\n::endgroup::"
return ""

0 comments on commit ba28a00

Please sign in to comment.