From 752202f8b730d0ab8785a703fc719dacfbe2993b Mon Sep 17 00:00:00 2001 From: felix-wang <35718120+numb3r3@users.noreply.github.com> Date: Thu, 9 Jun 2022 21:38:26 +0800 Subject: [PATCH] fix: monitor documentation (#745) --- server/clip_server/executors/clip_hg.py | 20 +++++++++++++++---- server/clip_server/executors/clip_onnx.py | 20 +++++++++++++++---- server/clip_server/executors/clip_tensorrt.py | 20 +++++++++++++++---- server/clip_server/executors/clip_torch.py | 20 +++++++++++++++---- 4 files changed, 64 insertions(+), 16 deletions(-) diff --git a/server/clip_server/executors/clip_hg.py b/server/clip_server/executors/clip_hg.py index dee816438..6fe0fa953 100644 --- a/server/clip_server/executors/clip_hg.py +++ b/server/clip_server/executors/clip_hg.py @@ -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: @@ -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, @@ -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() @@ -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() diff --git a/server/clip_server/executors/clip_onnx.py b/server/clip_server/executors/clip_onnx.py index 7d6265847..8c50362ac 100644 --- a/server/clip_server/executors/clip_onnx.py +++ b/server/clip_server/executors/clip_onnx.py @@ -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') @@ -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 @@ -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 diff --git a/server/clip_server/executors/clip_tensorrt.py b/server/clip_server/executors/clip_tensorrt.py index a15f2df0a..a97c5385d 100644 --- a/server/clip_server/executors/clip_tensorrt.py +++ b/server/clip_server/executors/clip_tensorrt.py @@ -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, @@ -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') @@ -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() @@ -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() diff --git a/server/clip_server/executors/clip_torch.py b/server/clip_server/executors/clip_torch.py index c072fcbc5..c79af2f00 100644 --- a/server/clip_server/executors/clip_torch.py +++ b/server/clip_server/executors/clip_torch.py @@ -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, @@ -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') @@ -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() @@ -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()