clip-as-service icon indicating copy to clipboard operation
clip-as-service copied to clipboard

When using prebuilt docker images and demo code, problems raised

Open Vision0220 opened this issue 2 years ago โ€ข 1 comments

When using prebuilt docker images and demo code, such problems raised:

code:

from clip_client import Client clip_client = Client('grpc://0.0.0.0:51009') r = clip_client.encode(['First do it', 'then do it right', 'then do it better']) # this will lead to errors print(r.shape) # [3, 512]

docker command: docker run -p 51009:51000 -v $HOME/.cache:/home/cas/.cache --gpus all jinaai/clip-server (seems working good, but cannot function

And the error looks like this:

ERROR clip_ t/rep-0@44 RuntimeError('expected scalar type [08/05/22 13:57:27] Float but found Half')
add "--quiet-error" to suppress the exception
details
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Traceback (most recent call last) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ /usr/local/lib/python3.8/dist-packages/jina/servโ€ฆ โ”‚
โ”‚ in process_data โ”‚
โ”‚ โ”‚
โ”‚ 161 โ”‚ โ”‚ โ”‚ โ”‚ if self.logger.debug_enable โ”‚
โ”‚ 162 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ self._log_data_request( โ”‚
โ”‚ 163 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ โฑ 164 โ”‚ โ”‚ โ”‚ โ”‚ return await self._data_req โ”‚
โ”‚ 165 โ”‚ โ”‚ โ”‚ except (RuntimeError, Exception โ”‚
โ”‚ 166 โ”‚ โ”‚ โ”‚ โ”‚ self.logger.error( โ”‚
โ”‚ 167 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ f'{ex!r}' โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/jina/servโ€ฆ โ”‚
โ”‚ in handle โ”‚
โ”‚ โ”‚
โ”‚ 152 โ”‚ โ”‚ ) โ”‚
โ”‚ 153 โ”‚ โ”‚ โ”‚
โ”‚ 154 โ”‚ โ”‚ # executor logic โ”‚
โ”‚ โฑ 155 โ”‚ โ”‚ return_data = await self._executor. โ”‚
โ”‚ 156 โ”‚ โ”‚ โ”‚ req_endpoint=requests[0].header โ”‚
โ”‚ 157 โ”‚ โ”‚ โ”‚ docs=docs, โ”‚
โ”‚ 158 โ”‚ โ”‚ โ”‚ parameters=params, โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/jina/servโ€ฆ โ”‚
โ”‚ in acall โ”‚
โ”‚ โ”‚
โ”‚ 288 โ”‚ โ”‚ if req_endpoint in self.requests: โ”‚
โ”‚ 289 โ”‚ โ”‚ โ”‚ return await self.__acall_endpo โ”‚
โ”‚ 290 โ”‚ โ”‚ elif default_endpoint in self.r โ”‚
โ”‚ โฑ 291 โ”‚ โ”‚ โ”‚ return await self._acall_endpo โ”‚
โ”‚ 292 โ”‚ โ”‚
โ”‚ 293 โ”‚ async def acall_endpoint(self, req
โ”‚
โ”‚ 294 โ”‚ โ”‚ func = self.requests[req_endpoint] โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/jina/servโ€ฆ โ”‚
โ”‚ in acall_endpoint โ”‚
โ”‚ โ”‚
โ”‚ 307 โ”‚ โ”‚ โ”‚
โ”‚ 308 โ”‚ โ”‚ with _summary: โ”‚
โ”‚ 309 โ”‚ โ”‚ โ”‚ if iscoroutinefunction(func): โ”‚
โ”‚ โฑ 310 โ”‚ โ”‚ โ”‚ โ”‚ return await func(self, **k โ”‚
โ”‚ 311 โ”‚ โ”‚ โ”‚ else: โ”‚
โ”‚ 312 โ”‚ โ”‚ โ”‚ โ”‚ return func(self, **kwargs) โ”‚
โ”‚ 313 โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/jina/servโ€ฆ โ”‚
โ”‚ in arg_wrapper โ”‚
โ”‚ โ”‚
โ”‚ 204 โ”‚ โ”‚ โ”‚ โ”‚ async def arg_wrapper( โ”‚
โ”‚ 205 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ executor_instance, *arg โ”‚
โ”‚ 206 โ”‚ โ”‚ โ”‚ โ”‚ ): # we need to get the su โ”‚
โ”‚ the self โ”‚
โ”‚ โฑ 207 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ return await fn(executo โ”‚
โ”‚ 208 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ 209 โ”‚ โ”‚ โ”‚ โ”‚ self.fn = arg_wrapper โ”‚
โ”‚ 210 โ”‚ โ”‚ โ”‚ else: โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/clip_servโ€ฆ โ”‚
โ”‚ in encode โ”‚
โ”‚ โ”‚
โ”‚ 138 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ documentation='text โ”‚
โ”‚ 139 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ ): โ”‚
โ”‚ 140 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ minibatch.embedding โ”‚
โ”‚ โฑ 141 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ self._model.enc โ”‚
โ”‚ 142 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ .cpu() โ”‚
โ”‚ 143 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ .numpy() โ”‚
โ”‚ 144 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ .astype(np.floa โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/clip_servโ€ฆ โ”‚
โ”‚ in encode_text โ”‚
โ”‚ โ”‚
โ”‚ 45 โ”‚ โ”‚ return model_name.replace('/', '-') โ”‚
โ”‚ 46 โ”‚ โ”‚
โ”‚ 47 โ”‚ def encode_text(self, input_ids: 'torch. โ”‚
โ”‚ โฑ 48 โ”‚ โ”‚ return self._model.encode_text(input โ”‚
โ”‚ 49 โ”‚ โ”‚
โ”‚ 50 โ”‚ def encode_image(self, pixel_values: 'to โ”‚
โ”‚ 51 โ”‚ โ”‚ return self._model.encode_image(pixe โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/clip_servโ€ฆ โ”‚
โ”‚ in encode_text โ”‚
โ”‚ โ”‚
โ”‚ 570 โ”‚ โ”‚ โ”‚
โ”‚ 571 โ”‚ โ”‚ x = x + self.positional_embedding.t โ”‚
โ”‚ 572 โ”‚ โ”‚ x = x.permute(1, 0, 2) # NLD -> LN โ”‚
โ”‚ โฑ 573 โ”‚ โ”‚ x = self.transformer(x, attn_mask=s โ”‚
โ”‚ 574 โ”‚ โ”‚ x = x.permute(1, 0, 2) # LND -> NL โ”‚
โ”‚ 575 โ”‚ โ”‚ x = self.ln_final(x).type(self.dtyp โ”‚
โ”‚ 576 โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/torch/nn/โ€ฆ โ”‚
โ”‚ in _call_impl โ”‚
โ”‚ โ”‚
โ”‚ 1127 โ”‚ โ”‚ # this function, and just call for โ”‚
โ”‚ 1128 โ”‚ โ”‚ if not (self._backward_hooks or se โ”‚
โ”‚ or _global_backward_hooks โ”‚
โ”‚ 1129 โ”‚ โ”‚ โ”‚ โ”‚ or _global_forward_hooks o โ”‚
โ”‚ โฑ 1130 โ”‚ โ”‚ โ”‚ return forward_call(*input, ** โ”‚
โ”‚ 1131 โ”‚ โ”‚ # Do not call functions when jit i โ”‚
โ”‚ 1132 โ”‚ โ”‚ full_backward_hooks, non_full_back โ”‚
โ”‚ 1133 โ”‚ โ”‚ if self._backward_hooks or _global โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/clip_servโ€ฆ โ”‚
โ”‚ in forward โ”‚
โ”‚ โ”‚
โ”‚ 325 โ”‚ โ”‚ โ”‚ if self.grad_checkpointing and โ”‚
โ”‚ 326 โ”‚ โ”‚ โ”‚ โ”‚ x = checkpoint(r, x, attn_m โ”‚
โ”‚ 327 โ”‚ โ”‚ โ”‚ else: โ”‚
โ”‚ โฑ 328 โ”‚ โ”‚ โ”‚ โ”‚ x = r(x, attn_mask=attn_mas โ”‚
โ”‚ 329 โ”‚ โ”‚ return x โ”‚
โ”‚ 330 โ”‚
โ”‚ 331 โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/torch/nn/โ€ฆ โ”‚
โ”‚ in _call_impl โ”‚
โ”‚ โ”‚
โ”‚ 1127 โ”‚ โ”‚ # this function, and just call for โ”‚
โ”‚ 1128 โ”‚ โ”‚ if not (self._backward_hooks or se โ”‚
โ”‚ or _global_backward_hooks โ”‚
โ”‚ 1129 โ”‚ โ”‚ โ”‚ โ”‚ or _global_forward_hooks o โ”‚
โ”‚ โฑ 1130 โ”‚ โ”‚ โ”‚ return forward_call(*input, ** โ”‚
โ”‚ 1131 โ”‚ โ”‚ # Do not call functions when jit i โ”‚
โ”‚ 1132 โ”‚ โ”‚ full_backward_hooks, non_full_back โ”‚
โ”‚ 1133 โ”‚ โ”‚ if self._backward_hooks or _global โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/clip_servโ€ฆ โ”‚
โ”‚ in forward โ”‚
โ”‚ โ”‚
โ”‚ 294 โ”‚ โ”‚ return self.attn(x, x, x, need_weig โ”‚
โ”‚ 295 โ”‚ โ”‚
โ”‚ 296 โ”‚ def forward(self, x: torch.Tensor, attn โ”‚
โ”‚ โฑ 297 โ”‚ โ”‚ x = x + self.attention(self.ln_1(x) โ”‚
โ”‚ 298 โ”‚ โ”‚ x = x + self.mlp(self.ln_2(x)) โ”‚
โ”‚ 299 โ”‚ โ”‚ return x โ”‚
โ”‚ 300 โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/clip_servโ€ฆ โ”‚
โ”‚ in attention โ”‚
โ”‚ โ”‚
โ”‚ 291 โ”‚ โ”‚ self.ln_2 = LayerNorm(d_model) โ”‚
โ”‚ 292 โ”‚ โ”‚
โ”‚ 293 โ”‚ def attention(self, x: torch.Tensor, at โ”‚
โ”‚ โฑ 294 โ”‚ โ”‚ return self.attn(x, x, x, need_weig โ”‚
โ”‚ 295 โ”‚ โ”‚
โ”‚ 296 โ”‚ def forward(self, x: torch.Tensor, attn โ”‚
โ”‚ 297 โ”‚ โ”‚ x = x + self.attention(self.ln_1(x) โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/torch/nn/โ€ฆ โ”‚
โ”‚ in _call_impl โ”‚
โ”‚ โ”‚
โ”‚ 1127 โ”‚ โ”‚ # this function, and just call for โ”‚
โ”‚ 1128 โ”‚ โ”‚ if not (self._backward_hooks or se โ”‚
โ”‚ or _global_backward_hooks โ”‚
โ”‚ 1129 โ”‚ โ”‚ โ”‚ โ”‚ or _global_forward_hooks o โ”‚
โ”‚ โฑ 1130 โ”‚ โ”‚ โ”‚ return forward_call(*input, ** โ”‚
โ”‚ 1131 โ”‚ โ”‚ # Do not call functions when jit i โ”‚
โ”‚ 1132 โ”‚ โ”‚ full_backward_hooks, non_full_back โ”‚
โ”‚ 1133 โ”‚ โ”‚ if self.backward_hooks or global โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/torch/nn/โ€ฆ โ”‚
โ”‚ in forward โ”‚
โ”‚ โ”‚
โ”‚ 1150 โ”‚ โ”‚ โ”‚ โ”‚ q_proj_weight=self.q_proj
โ”‚
โ”‚ 1151 โ”‚ โ”‚ โ”‚ โ”‚ v_proj_weight=self.v_proj
โ”‚
โ”‚ average_attn_weights=average_attn_weights) โ”‚
โ”‚ 1152 โ”‚ โ”‚ else: โ”‚
โ”‚ โฑ 1153 โ”‚ โ”‚ โ”‚ attn_output, attn_output_weigh โ”‚
โ”‚ 1154 โ”‚ โ”‚ โ”‚ โ”‚ query, key, value, self.em โ”‚
โ”‚ 1155 โ”‚ โ”‚ โ”‚ โ”‚ self.in_proj_weight, self. โ”‚
โ”‚ 1156 โ”‚ โ”‚ โ”‚ โ”‚ self.bias_k, self.bias_v, โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/torch/nn/โ€ฆ โ”‚
โ”‚ in multi_head_attention_forward โ”‚
โ”‚ โ”‚
โ”‚ 5176 โ”‚ # โ”‚
โ”‚ 5177 โ”‚ # (deep breath) calculate attention an โ”‚
โ”‚ 5178 โ”‚ # โ”‚
โ”‚ โฑ 5179 โ”‚ attn_output, attn_output_weights = sc โ”‚
โ”‚ dropout_p) โ”‚
โ”‚ 5180 โ”‚ attn_output = attn_output.transpose(0, โ”‚
โ”‚ embed_dim) โ”‚
โ”‚ 5181 โ”‚ attn_output = linear(attn_output, out
โ”‚
โ”‚ 5182 โ”‚ attn_output = attn_output.view(tgt_len โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/torch/nn/โ€ฆ โ”‚
โ”‚ in _scaled_dot_product_attention โ”‚
โ”‚ โ”‚
โ”‚ 4849 โ”‚ q = q / math.sqrt(E) โ”‚
โ”‚ 4850 โ”‚ # (B, Nt, E) x (B, E, Ns) -> (B, Nt, N โ”‚
โ”‚ 4851 โ”‚ if attn_mask is not None: โ”‚
โ”‚ โฑ 4852 โ”‚ โ”‚ attn = torch.baddbmm(attn_mask, q, โ”‚
โ”‚ 4853 โ”‚ else: โ”‚
โ”‚ 4854 โ”‚ โ”‚ attn = torch.bmm(q, k.transpose(-2 โ”‚
โ”‚ 4855 โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
RuntimeError: expected scalar type Float but found
Half

Vision0220 avatar Aug 05 '22 14:08 Vision0220

Thanks @Vision0220 for pointing it out. Fixed in #790. Pleas try it again.

numb3r3 avatar Aug 08 '22 05:08 numb3r3