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

Patch: deberta success rate throttle #231

Merged
merged 6 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions cleanlab_studio/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ def __init__(self, message: str, status_code: int) -> None:
self.status_code = status_code


class TlmPartialSuccess(APIError):
"""TLM request partially succeeded. Still returns result to user."""

pass


class UnsupportedVersionError(HandledError):
def __init__(self) -> None:
super().__init__(
Expand Down
4 changes: 4 additions & 0 deletions cleanlab_studio/internal/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
InvalidProjectConfiguration,
RateLimitError,
TlmBadRequest,
TlmPartialSuccess,
TlmServerError,
)
from cleanlab_studio.internal.tlm.concurrency import TlmRateHandler
Expand Down Expand Up @@ -651,6 +652,9 @@ async def tlm_prompt(
await handle_tlm_client_error_from_resp(res, batch_index)
await handle_tlm_api_error_from_resp(res, batch_index)

if not res_json.get("deberta_success", True):
raise TlmPartialSuccess("Partial failure on deberta call -- slowdown request rate.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this raise result in the return not actually returning the results to the user / trigger retries? Not entirely certain of the logic behind how the errors are handled here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, not currently -- the context manager in the rate handler will swallow this type of exception, making it so that execution continues (returning the result to users)


finally:
if local_scoped_client:
await client_session.close()
Expand Down
10 changes: 8 additions & 2 deletions cleanlab_studio/internal/tlm/concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from types import TracebackType
from typing import Optional, Type

from cleanlab_studio.errors import RateLimitError, TlmServerError
from cleanlab_studio.errors import RateLimitError, TlmPartialSuccess, TlmServerError


class TlmRateHandler:
Expand Down Expand Up @@ -50,6 +50,8 @@ async def __aexit__(
If request failed due to 503, decrease congestion window.
Else if request failed for other reason, don't change congestion window, just exit.
"""
swallow_exception: bool = False

if exc_type is None:
await self._increase_congestion_window()

Expand All @@ -60,10 +62,14 @@ async def __aexit__(
):
await self._decrease_congestion_window()

elif isinstance(exc, TlmPartialSuccess):
await self._decrease_congestion_window()
swallow_exception = True

# release acquired send semaphore from aenter
self._send_semaphore.release()

return False
return swallow_exception

async def _increase_congestion_window(
self,
Expand Down
2 changes: 1 addition & 1 deletion cleanlab_studio/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Note to developers:
# Consider if backend's MIN_CLI_VERSION needs updating when pushing any changes to this file.

__version__ = "2.0.5"
__version__ = "2.0.6"

SCHEMA_VERSION = "0.2.0"
MIN_SCHEMA_VERSION = "0.1.0"
Expand Down
Loading