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

feat: do not send blob from server when it is loaded in client #804

Merged
merged 9 commits into from
Aug 15, 2022

Conversation

ZiniuYu
Copy link
Member

@ZiniuYu ZiniuYu commented Aug 10, 2022

If the user encodes a document with uri and no blob, the current implementation will load the blob in the client and send it to the server.
This pr saves the bandwidth by not sending back blob from the server

I ran some tests to see the benefit we have from this change.

from clip_client import Client
from jina import Document, DocumentArray

c = Client('grpc://0.0.0.0:5001')

def data_gen():
    for _ in range(80):
        yield Document(uri='toy.png')

r = c.encode(data_gen(), batch_size=8, show_progress=True)
r.summary()
  • Server config: default minibatch_size=32, model: Vit-L/14@336px, replicas: 3

  • Client config: default batch_size=8, input DocumentArray size=80 with each Document having a URI of an image of size ~1.5MB

  • Before: send 90MB, recv 90MB, cost 3-13min (Server hosted on Beijing GPU 3-7min/Berlin GPU 6-13min)

  • After: send 90MB, recv 250KB, cost 1-3min

In general, the time varies because of remote network communications, but the recv package sizes substantially drops

server/clip_server/executors/helper.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 10, 2022

Codecov Report

Merging #804 (05786c8) into main (b4fb0dd) will increase coverage by 2.57%.
The diff coverage is 95.65%.

@@            Coverage Diff             @@
##             main     #804      +/-   ##
==========================================
+ Coverage   81.52%   84.10%   +2.57%     
==========================================
  Files          21       21              
  Lines        1440     1466      +26     
==========================================
+ Hits         1174     1233      +59     
+ Misses        266      233      -33     
Flag Coverage Δ
cas 84.10% <95.65%> (+2.57%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
client/clip_client/client.py 87.33% <95.00%> (+1.54%) ⬆️
server/clip_server/executors/helper.py 97.05% <100.00%> (+0.08%) ⬆️
server/clip_server/model/clip_trt.py 85.71% <0.00%> (+16.32%) ⬆️
server/clip_server/model/trt_utils.py 83.51% <0.00%> (+27.47%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@ZiniuYu ZiniuYu marked this pull request as ready for review August 11, 2022 04:57
server/clip_server/executors/helper.py Outdated Show resolved Hide resolved
server/clip_server/executors/helper.py Outdated Show resolved Hide resolved
@ZiniuYu ZiniuYu force-pushed the no-blob-from-server branch from 6edbfde to 4d61e28 Compare August 11, 2022 07:15
@ZiniuYu ZiniuYu requested a review from numb3r3 August 12, 2022 09:07
@@ -119,6 +121,11 @@ def encode(self, content, **kwargs):
**self._get_post_payload(content, kwargs),
on_done=partial(self._gather_result, results=results),
)

for c in content:
if isinstance(c, Document) and c.tags.pop('__loaded_by_CAS__', False):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if isinstance(c, Document) and c.tags.pop('__loaded_by_CAS__', False):
if hasattr(c, 'tags') and c.tags.pop('__loaded_by_CAS__', False):

Copy link
Member

Choose a reason for hiding this comment

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

This is a broken change

Copy link
Member

@numb3r3 numb3r3 Aug 12, 2022

Choose a reason for hiding this comment

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

The benefits from change above:

  1. reduce the memory footprint (to address OOM when processing a large number of documents);
  2. keep the inputs not updated;

Copy link
Member

Choose a reason for hiding this comment

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

The future better way is to support in-place update in encode(docs)

Copy link
Member

@numb3r3 numb3r3 left a comment

Choose a reason for hiding this comment

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

add unittest to check server-side

@github-actions github-actions bot added size/m and removed size/s labels Aug 12, 2022
Copy link
Member

@numb3r3 numb3r3 left a comment

Choose a reason for hiding this comment

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

LGTM

@numb3r3 numb3r3 merged commit 3c43eed into main Aug 15, 2022
@numb3r3 numb3r3 deleted the no-blob-from-server branch August 15, 2022 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants