-
Notifications
You must be signed in to change notification settings - Fork 51
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
Lazy model connection & x-route-info #363
Conversation
Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
There was a problem hiding this 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]>
Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
031f5cc
to
d5893d9
Compare
Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
There was a problem hiding this 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: |
There was a problem hiding this comment.
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.
ok, route_info = get_route_info(context) | ||
if ok: |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
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. | ||
""" |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the citation link: https://github.com/grpc/grpc/blob/master/src/python/grpcio/grpc/__init__.py#L1128
Co-authored-by: Gabe Goodhart <[email protected]> Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]>
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. Thex-route-info
header/metadata is read from the context arg.Additionally:
TextGenerationTGIS._tgis_backend
property was added to be consistent withPeftPromptTuningTGIS
. TheTextGenerationTGIS.tgis_backend
property is conditional on thetgis_backend
argument to be True, which made accessingTextGenerationTGIS.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