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

[python] Refactor output formatter for rolling batch #916

Merged
merged 5 commits into from
Jul 7, 2023

Conversation

xyang16
Copy link
Contributor

@xyang16 xyang16 commented Jul 6, 2023

Description

Brief description of what this PR is about

  • If this change is a backward incompatible change, why must this change be made?
  • Interesting edge cases to note here

@xyang16 xyang16 requested review from zachgk, frankfliu and a team as code owners July 6, 2023 23:42
@xyang16 xyang16 force-pushed the lmi branch 2 times, most recently from f9abb7b to c43dab1 Compare July 6, 2023 23:56
@@ -173,8 +173,6 @@ def initialize(self, properties: dict):
self.device = int(os.getenv("LOCAL_RANK", 0))
_rolling_batch_cls = get_rolling_batch_class_from_str(
self.rolling_batch_type, is_mpi, self.model_config)

# TODO: Allow user to set output formatter
self.rolling_batch = _rolling_batch_cls(model_id_or_path,
Copy link
Contributor

Choose a reason for hiding this comment

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

you can make output formatter as part of the kwargs, user can pass in a function if needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

@@ -143,7 +143,13 @@ def _prefill_and_decode(self, new_requests):
for request_id, generated_token, request in zip(
request_ids, generated_tokens, self.pending_requests):
is_last_token = (request_id in exit_req_ids)
request.set_next_token(generated_token, last_token=is_last_token)
if self.output_formatter is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

request.set_next_token(generated_token, self.output_formatter, last_token=is_last_token)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

"""

self.device = device
self.pending_requests = []
self.req_id_counter = 0
if 'rolling_batch_output_formatter' in kwargs:
# TODO: Allow user to set custom output formatter
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

self.output_formatter = kwargs['rolling_batch_output_formatter']

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

# TODO: find a way to return content-type for custom output formatter
if self.output_formatter == _default_output_formatter:
return "application/jsonlines"
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

can be plain text?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe some other types

@xyang16 xyang16 closed this Jul 7, 2023
@xyang16 xyang16 reopened this Jul 7, 2023
@xyang16 xyang16 merged commit 040f653 into deepjavalibrary:master Jul 7, 2023
KexinFeng pushed a commit to KexinFeng/djl-serving-forked that referenced this pull request Aug 16, 2023
…#916)

* [python] Refactor output formatter for rolling batch

* Review changes

* Review changes

* Review changes

* Review changes
KexinFeng pushed a commit to KexinFeng/djl-serving-forked that referenced this pull request Aug 16, 2023
…#916)

* [python] Refactor output formatter for rolling batch

* Review changes

* Review changes

* Review changes

* Review changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants