Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

fix(ci): avoid runner temp parse error (#314)

Artur Mullakhmetovf6d2e6071b55
diff --git a/.github/workflows/run-benchmark.yml b/.github/workflows/run-benchmark.yml
index fed4f884d..5ff03ae24 100644
--- a/.github/workflows/run-benchmark.yml
+++ b/.github/workflows/run-benchmark.yml
@@ -34,7 +34,6 @@ jobs:
environment: prefect-benchmarks
env:
- ARTIFACT_DIR: ${{ runner.temp }}/prefect-benchmark
BENCHMARK_ARGS_JSON: ${{ inputs.benchmark_args }}
GITHUB_ACTOR_NAME: ${{ github.actor }}
GITHUB_TRIGGERING_ACTOR_NAME: ${{ github.triggering_actor }}
@@ -52,6 +51,7 @@ jobs:
env:
PREFECT_API_KEY: ${{ secrets.PREFECT_API_KEY }}
run: |
+ ARTIFACT_DIR="$RUNNER_TEMP/prefect-benchmark"
python3 scripts/prefect_benchmark_run.py \
--api-url "$PREFECT_API_URL" \
--pool "$POOL_NAME" \
@@ -65,12 +65,13 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: prefect-benchmark-${{ github.run_id }}
- path: ${{ env.ARTIFACT_DIR }}
+ path: ${{ runner.temp }}/prefect-benchmark
if-no-files-found: warn
- name: Write workflow summary
if: ${{ always() }}
run: |
+ ARTIFACT_DIR="$RUNNER_TEMP/prefect-benchmark"
SUMMARY_PATH="$ARTIFACT_DIR/summary.md"
if [[ -f "$SUMMARY_PATH" ]]; then
cat "$SUMMARY_PATH" >> "$GITHUB_STEP_SUMMARY"
diff --git a/scripts/prefect_benchmark_run.py b/scripts/prefect_benchmark_run.py
index 08aa3833e..1c359fcb0 100644
--- a/scripts/prefect_benchmark_run.py
+++ b/scripts/prefect_benchmark_run.py
@@ -14,6 +14,9 @@ from pathlib import Path
from typing import Any, Callable, Protocol
+type LogSink = Callable[[str], None]
+
+
class PoolName(str, Enum):
MACOS_A18_PRO = "macos-a18-pro-pool"
MACOS_M1 = "macos-m1-pool"
@@ -63,6 +66,8 @@ POOL_DEPLOYMENTS: dict[PoolName, str] = {
PoolName.MACOS_M4_PRO: "run-benchmark-worker-flow/run-benchmark-m4-pro",
}
+PREFECT_LOG_PAGE_SIZE = 200
+
@dataclass(frozen=True)
class FlowRun:
@@ -273,6 +278,7 @@ def execute_benchmark_run(
sleep: Callable[[float], None] = time.sleep,
actor: str | None = None,
triggering_actor: str | None = None,
+ log_sink: LogSink | None = None,
) -> BenchmarkRunResult:
deployment_name = deployment_name_for_pool(pool)
deployment_id = client.read_deployment_id(deployment_name)
@@ -283,6 +289,7 @@ def execute_benchmark_run(
poll_interval_seconds=poll_interval_seconds,
timeout_seconds=timeout_seconds,
sleep=sleep,
+ log_sink=log_sink,
)
logs = read_all_logs(client, created_run.id)
failure_reason = None
@@ -317,26 +324,78 @@ def wait_for_terminal_flow_run(
poll_interval_seconds: int,
timeout_seconds: int,
sleep: Callable[[float], None],
+ log_sink: LogSink | None = None,
) -> FlowRun:
current_run = initial_run
+ next_log_offset = stream_new_logs(
+ client=client,
+ flow_run=current_run,
+ next_log_offset=0,
+ log_sink=log_sink,
+ )
deadline = time.monotonic() + timeout_seconds
while not current_run.state_type.is_terminal and time.monotonic() < deadline:
if poll_interval_seconds > 0:
sleep(poll_interval_seconds)
current_run = client.read_flow_run(current_run.id)
+ next_log_offset = stream_new_logs(
+ client=client,
+ flow_run=current_run,
+ next_log_offset=next_log_offset,
+ log_sink=log_sink,
+ )
+ stream_new_logs(
+ client=client,
+ flow_run=current_run,
+ next_log_offset=next_log_offset,
+ log_sink=log_sink,
+ )
return current_run
+def stream_new_logs(
+ client: PrefectClientProtocol,
+ flow_run: FlowRun,
+ next_log_offset: int,
+ log_sink: LogSink | None,
+) -> int:
+ if log_sink is None:
+ return next_log_offset
+
+ new_logs, updated_log_offset = read_logs_since_offset(
+ client=client,
+ flow_run_id=flow_run.id,
+ offset=next_log_offset,
+ )
+ for log in new_logs:
+ log_sink(format_log_line(flow_run, log))
+ return updated_log_offset
+
+
+def read_logs_since_offset(
+ client: PrefectClientProtocol,
+ flow_run_id: str,
+ offset: int,
+) -> tuple[tuple[PrefectLog, ...], int]:
+ next_log_offset = offset
+ new_logs: list[PrefectLog] = []
+ while True:
+ page = client.read_logs_page(flow_run_id, limit=PREFECT_LOG_PAGE_SIZE, offset=next_log_offset)
+ new_logs.extend(page)
+ next_log_offset += len(page)
+ if len(page) < PREFECT_LOG_PAGE_SIZE:
+ return tuple(new_logs), next_log_offset
+
+
def read_all_logs(client: PrefectClientProtocol, flow_run_id: str) -> tuple[PrefectLog, ...]:
offset = 0
- page_size = 200
all_logs: list[PrefectLog] = []
while True:
- page = client.read_logs_page(flow_run_id, limit=page_size, offset=offset)
+ page = client.read_logs_page(flow_run_id, limit=PREFECT_LOG_PAGE_SIZE, offset=offset)
all_logs.extend(page)
- if len(page) < page_size:
+ if len(page) < PREFECT_LOG_PAGE_SIZE:
return tuple(all_logs)
- offset += page_size
+ offset += PREFECT_LOG_PAGE_SIZE
def write_run_artifacts(output_dir: Path | str, result: BenchmarkRunResult) -> None:
@@ -383,14 +442,19 @@ def build_summary_markdown(result: BenchmarkRunResult) -> str:
return "\n".join(lines) + "\n"
+def format_log_line(flow_run: FlowRun, log: PrefectLog) -> str:
+ return f"{log.timestamp} | {logging.getLevelName(log.level):7s} | Flow run {flow_run.name!r} - {log.message}"
+
+
def format_logs(flow_run: FlowRun, logs: tuple[PrefectLog, ...]) -> str:
- lines = [
- f"{log.timestamp} | {logging.getLevelName(log.level):7s} | Flow run {flow_run.name!r} - {log.message}"
- for log in logs
- ]
+ lines = [format_log_line(flow_run, log) for log in logs]
return "\n".join(lines) + ("\n" if lines else "")
+def print_live_log_line(line: str) -> None:
+ print(line, flush=True)
+
+
def parse_cli_args(argv: list[str] | None = None) -> CliConfig:
parser = argparse.ArgumentParser(description="Trigger one Prefect benchmark worker deployment and fetch its logs.")
parser.add_argument("--api-url", required=True, help="Prefect API URL")
@@ -453,6 +517,7 @@ def main(argv: list[str] | None = None) -> int:
timeout_seconds=config.timeout_seconds,
actor=config.actor,
triggering_actor=config.triggering_actor,
+ log_sink=print_live_log_line,
)
write_run_artifacts(config.output_dir, result)
print(build_summary_markdown(result))