Skip to content

Commit

Permalink
Protect against errors raised when adding a request to the engine (#230)
Browse files Browse the repository at this point in the history
* Protect against invalid request format

* add warning when a request fails to be added

* revert

* alternative suggested by lite

* revert async_connector change
  • Loading branch information
masahi authored Mar 15, 2024
1 parent 0caae1f commit fd4ea46
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions serve/mlc_serve/engine/staging_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
ScopedInferenceEngine,
SequenceOutput,
)
from .error import TextGenerationError
from .engine_common import get_new_request_state, prepare_output
from .model_module import ModelModule, TokenizerModule
from ..model.base import get_model_artifact_config
from .staging_engine_worker import (
AddRequestsCommand,
CancelRequestCommand,
Expand Down Expand Up @@ -119,13 +119,17 @@ def add(self, requests: list[Request]):
assert isinstance(req.stopping_criteria.stop_sequences, list)

# If the request violates the tokenization, this returns None, so skip.
state = get_new_request_state(
req,
self.conversation_template,
self.tokenizer,
self.model_artifact_config.vocab_size,
)
new_request_states.append(state)
try:
state = get_new_request_state(
req,
self.conversation_template,
self.tokenizer,
self.model_artifact_config.vocab_size,
)
new_request_states.append(state)
except Exception as e:
LOG.warn("Failed to add a request", request_id=req.request_id)
raise TextGenerationError(str(e))

self.command_queue.put(AddRequestsCommand(request_states=new_request_states))

Expand Down

0 comments on commit fd4ea46

Please sign in to comment.