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

Lazy model connection & x-route-info #363

Merged
merged 14 commits into from
Jun 7, 2024

Conversation

mynhardtburger
Copy link
Contributor

@mynhardtburger mynhardtburger commented Jun 6, 2024

This PR adds support for respecting a TGIS hostname override (x-route-info header/metadata).

This is achieved by lazily registering the model connection with the TGISBackend when .run()/run_stream_out()/run_tokenizer() is called. The x-route-info header/metadata is read from the context arg.

Additionally:

  • a TextGenerationTGIS._tgis_backend property was added to be consistent with PeftPromptTuningTGIS. The TextGenerationTGIS.tgis_backend property is conditional on the tgis_backend argument to be True, which made accessing TextGenerationTGIS.tgis_backend risky as it might not exist. The additional _tgis_backend property is guaranteed to exist, making using it simpler and less risky.

Depends on caikit-tgis-backend>=0.1.33

Copy link
Contributor

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

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

Super close pending changes over in caikit-tgis-backend!

Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
@mynhardtburger mynhardtburger changed the title Lazy model connection Lazy model connection & x-route-info Jun 7, 2024
Signed-off-by: Mynhardt Burger <[email protected]>
@mynhardtburger mynhardtburger marked this pull request as ready for review June 7, 2024 16:28
@mynhardtburger mynhardtburger force-pushed the lazy-model-connection branch from 031f5cc to d5893d9 Compare June 7, 2024 16:33
Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
Copy link
Contributor

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

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

A couple of small cleanup suggestions and comment requests

@@ -221,6 +233,9 @@ def run(
self.enable_backend,
"Backend must be configured and loaded with this module before executing `run` call.",
)
if self._tgis_backend:
Copy link
Contributor

Choose a reason for hiding this comment

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

Total NIT, but since _register_model_connection_with_context is a member function, you could move the if self._tgis_backend line into the function and save a few duplicate lines in each of the inference methods.

Comment on lines 357 to 358
ok, route_info = get_route_info(context)
if ok:
Copy link
Contributor

Choose a reason for hiding this comment

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

I really want to be able to use := here and make it look more like go, but seems that you can't

self.base_model_name, {"hostname": route_info}, fill_with_defaults=True
)
else:
self._tgis_backend.register_model_connection(self.base_model_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we don't need to do this if there's no context because it will be done automatically with get_client

@@ -240,6 +249,9 @@ def run(
GeneratedTextResult
Generated text result produced by TGIS.
"""
if self._tgis_backend:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about burying the if self._tgis_backend

self.model_name, {"hostname": route_info}, fill_with_defaults=True
)
else:
self._tgis_backend.register_model_connection(self.model_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about not needing the else clause

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Comment on lines 692 to 701
def get_route_info(
context: Optional[RuntimeServerContextType],
) -> Tuple[bool, Optional[str]]:
"""
Returns a tuple `(True, x-route-info)` from context if "x-route-info" was found in
the headers/metadata.

Otherwise returns a tuple `(False, None)` if "x-route-info" was not found in the
context or if context is None.
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can collapse the return into a simple Optional[str]. Returning None is indicative of "no route info found." This would simplify the logic that uses it and allow us to get another walrus!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Now using walrus operator for good @gabe-l-hart karma.


class TestServicerContext:
"""
A dummy class for mimicking ServicerContext invocation metadata storage.
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. I was looking for a link to suggest as a citation of this interface and I found this instead. Makes me wonder if we should be using grpcio-testing for all of this in our tests!

Copy link
Contributor

Choose a reason for hiding this comment

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

mynhardtburger and others added 2 commits June 7, 2024 13:13
Co-authored-by: Gabe Goodhart <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
Copy link
Contributor

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

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

One list NIT, but I think this is also good as is. Thanks!

ValueError(f"context is of an unsupported type: {type(context)}"),
)

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.

NIT: this is both implicit and unreachable since else will raise. I'm guessing it's here because your IDE doesn't know that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Removed.

Signed-off-by: Mynhardt Burger <[email protected]>
@gabe-l-hart gabe-l-hart merged commit 3b2f8fd into caikit:main Jun 7, 2024
5 checks passed
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.

2 participants