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

fix: monitor documentation #745

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions server/clip_server/executors/clip_hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ def __init__(
self._pool = ThreadPool(processes=num_worker_preprocess)

def _preproc_images(self, docs: 'DocumentArray'):
with self.monitor('preprocess_images_seconds'):
with self.monitor(
name='preprocess_images_seconds',
documentation='images preprocess time in seconds',
):
tensors_batch = []

for d in docs:
Expand Down Expand Up @@ -139,7 +142,10 @@ def _preproc_images(self, docs: 'DocumentArray'):
return docs, batch_data

def _preproc_texts(self, docs: 'DocumentArray'):
with self.monitor('preprocess_texts_seconds'):
with self.monitor(
name='preprocess_texts_seconds',
documentation='texts preprocess time in seconds',
):
batch_data = self._tokenizer(
docs.texts,
max_length=self._max_length,
Expand Down Expand Up @@ -189,7 +195,10 @@ async def encode(self, docs: DocumentArray, **kwargs):
batch_size=self._minibatch_size,
pool=self._pool,
):
with self.monitor('encode_images_seconds'):
with self.monitor(
name='encode_images_seconds',
documentation='images encode time in seconds',
):
minibatch.embeddings = (
self._model.get_image_features(**batch_data)
.cpu()
Expand All @@ -204,7 +213,10 @@ async def encode(self, docs: DocumentArray, **kwargs):
batch_size=self._minibatch_size,
pool=self._pool,
):
with self.monitor('encode_texts_seconds'):
with self.monitor(
name='encode_texts_seconds',
documentation='texts encode time in seconds',
):
minibatch.embeddings = (
self._model.get_text_features(**batch_data)
.cpu()
Expand Down
20 changes: 16 additions & 4 deletions server/clip_server/executors/clip_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,19 @@ def __init__(
self._model.start_sessions(sess_options=sess_options, providers=providers)

def _preproc_images(self, docs: 'DocumentArray'):
with self.monitor('preprocess_images_seconds'):
with self.monitor(
name='preprocess_images_seconds',
documentation='images preprocess time in seconds',
):
return preproc_image(
docs, preprocess_fn=self._preprocess_tensor, return_np=True
)

def _preproc_texts(self, docs: 'DocumentArray'):
with self.monitor('preprocess_texts_seconds'):
with self.monitor(
name='preprocess_texts_seconds',
documentation='texts preprocess time in seconds',
):
return preproc_text(docs, return_np=True)

@requests(on='/rank')
Expand All @@ -105,7 +111,10 @@ async def encode(self, docs: 'DocumentArray', **kwargs):
batch_size=self._minibatch_size,
pool=self._pool,
):
with self.monitor('encode_images_seconds'):
with self.monitor(
name='encode_images_seconds',
documentation='images encode time in seconds',
):
minibatch.embeddings = self._model.encode_image(minibatch.tensors)

# recover original content
Expand All @@ -123,7 +132,10 @@ async def encode(self, docs: 'DocumentArray', **kwargs):
batch_size=self._minibatch_size,
pool=self._pool,
):
with self.monitor('encode_texts_seconds'):
with self.monitor(
name='encode_texts_seconds',
documentation='texts encode time in seconds',
):
minibatch.embeddings = self._model.encode_text(minibatch.tensors)

# recover original content
Expand Down
20 changes: 16 additions & 4 deletions server/clip_server/executors/clip_tensorrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def __init__(
self._model.start_engines()

def _preproc_images(self, docs: 'DocumentArray'):
with self.monitor('preprocess_images_seconds'):
with self.monitor(
name='preprocess_images_seconds',
documentation='images preprocess time in seconds',
):
return preproc_image(
docs,
preprocess_fn=self._preprocess_tensor,
Expand All @@ -55,7 +58,10 @@ def _preproc_images(self, docs: 'DocumentArray'):
)

def _preproc_texts(self, docs: 'DocumentArray'):
with self.monitor('preprocess_texts_seconds'):
with self.monitor(
name='preprocess_texts_seconds',
documentation='texts preprocess time in seconds',
):
return preproc_text(docs, device=self._device, return_np=False)

@requests(on='/rank')
Expand All @@ -78,7 +84,10 @@ async def encode(self, docs: 'DocumentArray', **kwargs):
batch_size=self._minibatch_size,
pool=self._pool,
):
with self.monitor('encode_images_seconds'):
with self.monitor(
name='encode_images_seconds',
documentation='images encode time in seconds',
):
minibatch.embeddings = (
self._model.encode_image(minibatch.tensors)
.detach()
Expand All @@ -102,7 +111,10 @@ async def encode(self, docs: 'DocumentArray', **kwargs):
batch_size=self._minibatch_size,
pool=self._pool,
):
with self.monitor('encode_texts_seconds'):
with self.monitor(
name='encode_texts_seconds',
documentation='texts encode time in seconds',
):
minibatch.embeddings = (
self._model.encode_text(minibatch.tensors)
.detach()
Expand Down
20 changes: 16 additions & 4 deletions server/clip_server/executors/clip_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def __init__(
self._pool = ThreadPool(processes=num_worker_preprocess)

def _preproc_images(self, docs: 'DocumentArray'):
with self.monitor(name='preprocess_images_seconds'):
with self.monitor(
name='preprocess_images_seconds',
documentation='images preprocess time in seconds',
):
return preproc_image(
docs,
preprocess_fn=self._preprocess_tensor,
Expand All @@ -67,7 +70,10 @@ def _preproc_images(self, docs: 'DocumentArray'):
)

def _preproc_texts(self, docs: 'DocumentArray'):
with self.monitor(name='preprocess_texts_seconds'):
with self.monitor(
name='preprocess_texts_seconds',
documentation='texts preprocess time in seconds',
):
return preproc_text(docs, device=self._device, return_np=False)

@requests(on='/rank')
Expand All @@ -91,7 +97,10 @@ async def encode(self, docs: 'DocumentArray', **kwargs):
batch_size=self._minibatch_size,
pool=self._pool,
):
with self.monitor('encode_images_seconds'):
with self.monitor(
name='encode_images_seconds',
documentation='images encode time in seconds',
):
minibatch.embeddings = (
self._model.encode_image(minibatch.tensors)
.cpu()
Expand All @@ -114,7 +123,10 @@ async def encode(self, docs: 'DocumentArray', **kwargs):
batch_size=self._minibatch_size,
pool=self._pool,
):
with self.monitor('encode_texts_seconds'):
with self.monitor(
name='encode_texts_seconds',
documentation='texts encode time in seconds',
):
minibatch.embeddings = (
self._model.encode_text(minibatch.tensors)
.cpu()
Expand Down