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: allow custom callback in clip_client #849

Merged
merged 9 commits into from Nov 4, 2022
Merged

feat: allow custom callback in clip_client #849

merged 9 commits into from Nov 4, 2022

Conversation

ZiniuYu
Copy link
Member

@ZiniuYu ZiniuYu commented Oct 28, 2022

clip_client by default collects all the results and returns them to users. In this pr, we enable the user to override this behavior by providing custom callbacks: on_done, on_error, and on_always. The usage of custom callbacks follows that of Jina client.

We move all results collection logic to a default on_done callback, with or without async.
We also move the code that updates the progress bar to a default on_always callback, which wraps the user-defined on_always callback.
We do not provide a default on_error callback.

This PR also fixes a small bug that unboxes empty input for the rank endpoint to unify the behavior of all endpoints.

  • All custom callback in clip_client
  • Add test cases
  • Add documentation
  • Bug fix: not unboxing empty input for ranking

@codecov
Copy link

codecov bot commented Oct 28, 2022

Codecov Report

Merging #849 (d2ac2c1) into main (9aa8c22) will decrease coverage by 2.26%.
The diff coverage is 94.80%.

@@            Coverage Diff             @@
##             main     #849      +/-   ##
==========================================
- Coverage   81.58%   79.32%   -2.27%     
==========================================
  Files          21       21              
  Lines        1575     1596      +21     
==========================================
- Hits         1285     1266      -19     
- Misses        290      330      +40     
Flag Coverage Δ
cas 79.32% <94.80%> (-2.27%) ⬇️

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

Impacted Files Coverage Δ
client/clip_client/client.py 87.38% <94.80%> (-1.40%) ⬇️
server/clip_server/model/trt_utils.py 56.04% <0.00%> (-27.48%) ⬇️
server/clip_server/model/clip_trt.py 69.38% <0.00%> (-16.33%) ⬇️

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

@ZiniuYu ZiniuYu changed the title feat: allow custom on_done callback feat: allow custom callback Oct 31, 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.

Please always document new feature like this.

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.

And please add unitest

@jemmyshin
Copy link
Member

please add description for this pr

)
return results.embeddings if unbox else results
def _unboxed_result(results: Optional['DocumentArray'] = None, unbox: bool = False):
if results is not None:
Copy link
Member

Choose a reason for hiding this comment

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

why remove this raise ValueError?

Copy link
Member Author

Choose a reason for hiding this comment

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

ok i will restore

class ErrorExec(Executor):
@requests
def foo(self, docs, **kwargs):
1 / 0
Copy link
Member

Choose a reason for hiding this comment

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

raise an error here, do not do like this

Copy link
Member Author

Choose a reason for hiding this comment

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

hahahaha

'inputs',
[
[],
DocumentArray([]),
Copy link
Member

Choose a reason for hiding this comment

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

DocumentArray()

@ZiniuYu ZiniuYu changed the title feat: allow custom callback feat: allow custom callback in clip_client Nov 2, 2022
@ZiniuYu ZiniuYu marked this pull request as ready for review November 2, 2022 06:58
@github-actions
Copy link

github-actions bot commented Nov 2, 2022

📝 Docs are deployed on https://ft-callback--jina-docs.netlify.app 🎉

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 4fcbf68 into main Nov 4, 2022
@numb3r3 numb3r3 deleted the callback branch November 4, 2022 04:44
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.

None yet

3 participants