Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
[FIX] Fix exception handling in alpa serve (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
merrymercy committed Jan 14, 2023
1 parent cd1afee commit 2c5164f
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 17 deletions.
9 changes: 5 additions & 4 deletions alpa/serve/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ async def handle_asgi(self, scope, receive, send):

response = await manager.handle_request.remote(
name, request_wrapper)
if isinstance(response, Exception):
raise response

status_code = 200
if isinstance(response, RelayException):
response = make_error_response(response)
status_code = 400
else:
status_code = 200
except Exception as e: # pylint: disable=broad-except
response = make_error_response(e)
status_code = 400
Expand Down
3 changes: 1 addition & 2 deletions alpa/serve/http_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ def __init__(self, e):
def make_error_response(e):
if isinstance(e, RelayException):
msg = str(e.e)
stacktrace = "".join(traceback.format_tb(
e.__traceback__)) + e.stacktrace
stacktrace = e.stacktrace
else:
msg = str(e)
stacktrace = "".join(traceback.format_tb(e.__traceback__))
Expand Down
2 changes: 1 addition & 1 deletion examples/llm_serving/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import requests

DEFAULT_URL = "https://opt.alpa.ai"
DEFAULT_URL = "https://api.alpa.ai"

headers = {"User-Agent": "Alpa Client"}

Expand Down
4 changes: 0 additions & 4 deletions examples/llm_serving/launch_model_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ def normalize_prompts(self, prompts):
async def completions(self, args, request):
logger = self.logger

if "redirect_logprobs" in args:
# A redirection to workaround some security settings.
return await self.logprobs(args, request)

# Normalize prompts
prompts = args["prompt"]
prompts = self.normalize_prompts(prompts)
Expand Down
4 changes: 2 additions & 2 deletions examples/llm_serving/launch_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def log_scope(request):
import pickle
import time

from alpa.serve.http_util import HTTPRequestWrapper, make_error_response
from alpa.serve.http_util import HTTPRequestWrapper, make_error_response, RelayException
import ray
from starlette.responses import JSONResponse
ray.init(address="auto", namespace="alpa_serve")
Expand Down Expand Up @@ -69,7 +69,7 @@ async def redirect(request):
ret = await manager.handle_request.remote("default", request)
except ray.exceptions.RayActorError:
manager = None
if isinstance(ret, Exception):
if isinstance(ret, RelayException):
ret = make_error_response(ret)
ret = JSONResponse(ret, status_code=400)
return ret
Expand Down
4 changes: 2 additions & 2 deletions examples/llm_serving/service/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@
msg.includes("is not registered") ||
msg.includes("object has no attribute")) {
msg += "\nThe server is probably under regular maintenance. " +
"Please come back 10 minutes later.";
"Please come back later.";
}
$("#error").text(msg);
} else {
$("#error").text(
"Cannot connect to the server due to unknown errors. " +
"\nThe server is probably under regular maintenance. " +
"Please come back 10 minutes later.");
"Please come back later.");
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion examples/llm_serving/test_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Usage:
python3 test_completions.py --url http://localhost:20001
python3 test_completions.py --url https://opt.alpa.ai --api-key YOUR_KEY
python3 test_completions.py --url https://api.alpa.ai --api-key YOUR_KEY
"""
import argparse

Expand Down
2 changes: 1 addition & 1 deletion examples/llm_serving/test_logprobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Usage:
python3 test_logprobs.py --url http://localhost:20001
python3 test_logprobs.py --url https://opt.alpa.ai --api-key YOUR_KEY
python3 test_logprobs.py --url https://api.alpa.ai --api-key YOUR_KEY
"""
import argparse
import time
Expand Down

0 comments on commit 2c5164f

Please sign in to comment.