Skip to content

Internal deploy python client functionality - #218

Merged
seanshi-scale merged 8 commits into
hmi-releasefrom
seanshi/deploy-internal-python-client
Feb 21, 2022
Merged

Internal deploy python client functionality#218
seanshi-scale merged 8 commits into
hmi-releasefrom
seanshi/deploy-internal-python-client

Conversation

@seanshi-scale

@seanshi-scale seanshi-scale commented Feb 10, 2022

Copy link
Copy Markdown
Contributor

The client operates in two modes, external mode (default) and self-hosted mode.

Also add a few extra functions for the missing API calls (e.g. delete bundle/endpoint, put endpoint)

For uploading model bundles in self-hosted mode, there is an upload_bundle_fn that needs to be passed to the client. This allows clients to specify their own model bundle storage backends. An example implementation is

def upload_bundle_fn(serialized_bundle, bundle_url):
    transport_params = {"session": Session(profile_name="ml-worker")}
    with smart_open.open(bundle_url, "wb", transport_params=transport_params) as f:
        f.write(serialized_bundle)

n.b. the code assumes that the REST APIs for the public route and the internal route are nearly identical, e.g. creating a model bundle is always at POST /model_bundle/ for example, and it takes in a JSON with a key url.

Testing:

Ran a testing script that

  • creates a model bundle
  • creates a model endpoint
  • sends a task through
  • deletes the endpoint
  • deletes the bundle

using the client in internal and external mode. Calls all succeed, the task doesn't return a result because of some other bug though.

Comment thread nucleus/deploy/client.py
def __eq__(self, other):
return self.connection == other.connection

def register_upload_bundle_fn(

@seanshi-scale seanshi-scale Feb 15, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is the best way of allowing users to use their own backend for storing model bundles (in internal mode). Think this is better than hardcoding any stuff with smart_open/boto3, since I don't want to introduce another dependency.

@seanshi-scale seanshi-scale self-assigned this Feb 15, 2022
@seanshi-scale
seanshi-scale marked this pull request as ready for review February 15, 2022 01:39
Comment thread nucleus/deploy/client.py
"""
self.connection = Connection(api_key, endpoint)
self.is_internal = is_internal
self.upload_bundle_fn: Optional[Callable[[str, str], None]] = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line 47 should be deleted?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It gets set elsewhere, but I think people (and my IDE) say it's good to initialize all instance variables inside init

Comment thread nucleus/deploy/client.py Outdated
)
if self.is_internal:
payload.update(
aws_role=aws_role, results_s3_bucket=results_s3_bucket

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should check aws_role and results_s3_bucket are not None

@Tianwei-She Tianwei-She left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not sure if this is the best design, but I think it's ok to merge for now

Comment thread nucleus/deploy/client.py
def __init__(
self,
api_key: str,
endpoint: str = SCALE_DEPLOY_ENDPOINT,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm should we have this as a default? won't this not work if it's wrong

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think in the long term we'd want it to be a default, i.e. have SCALE_DEPLOY_ENDPOINT equal to api.scale.com/v1/deploy or whatever it turns out to be. Think users would be more wrong specifying endpoint than us.

Comment thread nucleus/deploy/client.py Outdated
self,
api_key: str,
endpoint: str = SCALE_DEPLOY_ENDPOINT,
is_internal: bool = False,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm didn't we say we weren't gonna have an internal / external split so we don't commit this to a public repo?

ok with it i guess

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think having this flag by itself isn't the end of the world. The critical thing is to ensure that we're not leaking secrets. Less critical but still important is to ensure we're not leaking too many implementation details, which I think other parts of this PR are.

Comment thread nucleus/deploy/client.py Outdated
Comment thread nucleus/deploy/client.py Outdated
self,
api_key: str,
endpoint: str = SCALE_DEPLOY_ENDPOINT,
is_internal: bool = False,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think having this flag by itself isn't the end of the world. The critical thing is to ensure that we're not leaking secrets. Less critical but still important is to ensure we're not leaking too many implementation details, which I think other parts of this PR are.

Comment thread nucleus/deploy/client.py Outdated
@seanshi-scale
seanshi-scale merged commit efc95bf into hmi-release Feb 21, 2022
@seanshi-scale
seanshi-scale deleted the seanshi/deploy-internal-python-client branch February 21, 2022 19:22
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.

4 participants