Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add batch timeout override #3501

Merged
merged 21 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
eb112d2
Update changelog
diondrapeck Jul 3, 2024
7fa3e7d
Expose batch timeout environment variable
diondrapeck Jul 3, 2024
d94ac65
Add test
diondrapeck Jul 3, 2024
a26d27a
Merge branch 'main' into batch-timeout
diondrapeck Jul 8, 2024
fe96132
Merge branch 'main' into batch-timeout
diondrapeck Jul 11, 2024
8440556
Change PF_BATCH_TIMEOUT_DEFAULT constant name to PF_BATCH_TIMEOUT_SEC…
diondrapeck Jul 11, 2024
ac0d64a
Change PF_BATCH_TIMEOUT_DEFAULT constant name to PF_BATCH_TIMEOUT_SEC…
diondrapeck Jul 11, 2024
1181b28
Copy get_int_env_var to promptflow-evals utils
diondrapeck Jul 12, 2024
6c109df
Remove timeout logic from proxy_client to batch_run_context
diondrapeck Jul 13, 2024
d00ceb4
Add tests for batch context
diondrapeck Jul 13, 2024
35c5c54
Merge branch 'main' into batch-timeout
diondrapeck Jul 13, 2024
0e6d5f6
Update __exit__ to only reset if environment variable is default
diondrapeck Jul 13, 2024
3953b38
Update CHANGELOG to use promptflow format
diondrapeck Jul 13, 2024
e274e90
Merge branch 'batch-timeout' of https://github.com/microsoft/promptfl…
diondrapeck Jul 13, 2024
fef7729
Lower test timeout value to be under limit
diondrapeck Jul 14, 2024
988aeed
Merge branch 'main' into batch-timeout
diondrapeck Jul 15, 2024
736b39f
Add flag and check if batch timeout was set by system
diondrapeck Jul 19, 2024
668d289
Resolve merge conflicts
diondrapeck Jul 19, 2024
bdb7fa7
Make changelog more clear
diondrapeck Jul 19, 2024
f9867bc
Replace set by system environment variable with class attribute
diondrapeck Jul 22, 2024
ba0ee3a
Merge branch 'main' into batch-timeout
diondrapeck Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/promptflow-evals/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Please insert change log into "Next Release" ONLY.

## Next release
- Exposed batch evaluation run timeout variable via "PF_BATCH_TIMEOUT_SEC" environment variable
diondrapeck marked this conversation as resolved.
Show resolved Hide resolved

## 0.0.1
- Introduced package
3 changes: 2 additions & 1 deletion src/promptflow-evals/promptflow/evals/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ class Prefixes:

CONTENT_SAFETY_DEFECT_RATE_THRESHOLD_DEFAULT = 4

BATCH_RUN_TIMEOUT = 3600
PF_BATCH_TIMEOUT_DEFAULT = 3600
diondrapeck marked this conversation as resolved.
Show resolved Hide resolved
PF_BATCH_TIMEOUT_SEC = "PF_BATCH_TIMEOUT_SEC"
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import pandas as pd

from promptflow._utils.utils import get_int_env_var
from promptflow.contracts.types import AttrDict
from promptflow.evals.evaluate._utils import _apply_column_mapping, _has_aggregator, load_jsonl
from promptflow.tracing import ThreadPoolExecutorWithContext as ThreadPoolExecutor

from ..._constants import BATCH_RUN_TIMEOUT
from ..._constants import PF_BATCH_TIMEOUT_DEFAULT, PF_BATCH_TIMEOUT_SEC

LOGGER = logging.getLogger(__name__)

Expand All @@ -24,15 +25,17 @@ def __init__(self, run, input_data, evaluator_name=None, aggregated_metrics=None
self.aggregated_metrics = aggregated_metrics

def get_result_df(self, exclude_inputs=False):
result_df = self.run.result(timeout=BATCH_RUN_TIMEOUT)
batch_run_timeout = get_int_env_var(PF_BATCH_TIMEOUT_SEC, PF_BATCH_TIMEOUT_DEFAULT)
result_df = self.run.result(timeout=batch_run_timeout)
if exclude_inputs:
result_df = result_df.drop(columns=[col for col in result_df.columns if col.startswith("inputs.")])
return result_df

def get_aggregated_metrics(self):
try:
batch_run_timeout = get_int_env_var(PF_BATCH_TIMEOUT_SEC, PF_BATCH_TIMEOUT_DEFAULT)
aggregated_metrics = (
self.aggregated_metrics.result(timeout=BATCH_RUN_TIMEOUT)
self.aggregated_metrics.result(timeout=batch_run_timeout)
if self.aggregated_metrics is not None
else None
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

import numpy as np

from promptflow._utils.utils import get_int_env_var
diondrapeck marked this conversation as resolved.
Show resolved Hide resolved
from promptflow.client import PFClient
from promptflow.tracing import ThreadPoolExecutorWithContext as ThreadPoolExecutor

from ..._constants import BATCH_RUN_TIMEOUT
from ..._constants import PF_BATCH_TIMEOUT_DEFAULT, PF_BATCH_TIMEOUT_SEC

LOGGER = logging.getLogger(__name__)

Expand All @@ -30,11 +31,13 @@ def run(self, flow, data, column_mapping=None, **kwargs):
return ProxyRun(run=eval_future)

def get_details(self, proxy_run, all_results=False):
run = proxy_run.run.result(timeout=BATCH_RUN_TIMEOUT)
batch_run_timeout = get_int_env_var(PF_BATCH_TIMEOUT_SEC, PF_BATCH_TIMEOUT_DEFAULT)
diondrapeck marked this conversation as resolved.
Show resolved Hide resolved
run = proxy_run.run.result(timeout=batch_run_timeout)
result_df = self._pf_client.get_details(run, all_results=all_results)
result_df.replace("(Failed)", np.nan, inplace=True)
return result_df

def get_metrics(self, proxy_run):
run = proxy_run.run.result(timeout=BATCH_RUN_TIMEOUT)
batch_run_timeout = get_int_env_var(PF_BATCH_TIMEOUT_SEC, PF_BATCH_TIMEOUT_DEFAULT)
run = proxy_run.run.result(timeout=batch_run_timeout)
return self._pf_client.get_metrics(run)
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import os
from unittest.mock import MagicMock

import pytest

from promptflow.client import PFClient
from promptflow.evals._constants import PF_BATCH_TIMEOUT_DEFAULT, PF_BATCH_TIMEOUT_SEC
from promptflow.evals._user_agent import USER_AGENT
from promptflow.evals.evaluate._batch_run_client import BatchRunContext, CodeClient
from promptflow.evals.evaluate._batch_run_client.code_client import CodeRun


@pytest.fixture
Expand All @@ -17,6 +20,11 @@ def pf_client_mock():
return MagicMock(spec=PFClient)


@pytest.fixture
def code_run_mock():
return MagicMock()


@pytest.mark.unittest
class TestBatchRunContext:
def test_with_codeclient(self, mocker, code_client_mock):
Expand Down Expand Up @@ -50,3 +58,14 @@ def test_with_pfclient(self, mocker, pf_client_mock):
pass

mock_recover_openai_api.assert_not_called()

def test_get_result_timeout(self, code_run_mock):
code_run_instance = CodeRun(run=code_run_mock, input_data={})
code_run_instance.get_result_df()

code_run_mock.result.assert_called_once_with(timeout=PF_BATCH_TIMEOUT_DEFAULT)

custom_timeout = "100000"
os.environ[PF_BATCH_TIMEOUT_SEC] = custom_timeout
code_run_instance.get_result_df()
code_run_mock.result.assert_called_with(timeout=int(custom_timeout))
Loading