Thytu commited on
Commit
097107d
1 Parent(s): 37e891c

feat: model

Browse files

Signed-off-by: Thytu <vdmatos@gladia.io>

bhadresh-savani_distilbert-base-uncased-emotion_onnx_inference/1/.gitkeep ADDED
File without changes
bhadresh-savani_distilbert-base-uncased-emotion_onnx_inference/config.pbtxt ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "bhadresh-savani_distilbert-base-uncased-emotion_onnx_inference"
2
+ max_batch_size: 0
3
+ platform: "ensemble"
4
+
5
+ input [
6
+ {
7
+ name: "TEXT"
8
+ data_type: TYPE_STRING
9
+ dims: [ -1 ]
10
+ }
11
+ ]
12
+
13
+ output {
14
+ name: "output"
15
+ data_type: TYPE_FP32
16
+ dims: [-1, 6]
17
+ }
18
+
19
+ ensemble_scheduling {
20
+ step [
21
+ {
22
+ model_name: "bhadresh-savani_distilbert-base-uncased-emotion_onnx_tokenize"
23
+ model_version: -1
24
+ input_map {
25
+ key: "TEXT"
26
+ value: "TEXT"
27
+ }
28
+ output_map [
29
+ {
30
+ key: "input_ids"
31
+ value: "input_ids"
32
+ },
33
+ {
34
+ key: "attention_mask"
35
+ value: "attention_mask"
36
+ }
37
+ ]
38
+ },
39
+ {
40
+ model_name: "bhadresh-savani_distilbert-base-uncased-emotion_onnx_model"
41
+ model_version: -1
42
+ input_map [
43
+ {
44
+ key: "input_ids"
45
+ value: "input_ids"
46
+ },
47
+ {
48
+ key: "attention_mask"
49
+ value: "attention_mask"
50
+ }
51
+ ]
52
+ output_map {
53
+ key: "output"
54
+ value: "output"
55
+ }
56
+ }
57
+ ]
58
+ }
bhadresh-savani_distilbert-base-uncased-emotion_onnx_model/1/model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:88da46062f1337aaa66c58d9529f8f4b5dd02b0410fe02d839f8d69441c9e929
3
+ size 139298114
bhadresh-savani_distilbert-base-uncased-emotion_onnx_model/config.pbtxt ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "bhadresh-savani_distilbert-base-uncased-emotion_onnx_model"
2
+ max_batch_size: 0
3
+ platform: "onnxruntime_onnx"
4
+ default_model_filename: "model.bin"
5
+
6
+ input [
7
+ {
8
+ name: "input_ids"
9
+ data_type: TYPE_INT32
10
+ dims: [-1, -1]
11
+ },
12
+ {
13
+ name: "attention_mask"
14
+ data_type: TYPE_INT32
15
+ dims: [-1, -1]
16
+ }
17
+ ]
18
+
19
+ output {
20
+ name: "output"
21
+ data_type: TYPE_FP32
22
+ dims: [-1, 6]
23
+ }
24
+
25
+ instance_group [
26
+ {
27
+ count: 1
28
+ kind: KIND_GPU
29
+ }
30
+ ]
bhadresh-savani_distilbert-base-uncased-emotion_onnx_tokenize/1/config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dbdd79309149fa1f33496a5fd1bc8b377e98e338539bc4868a7b66ee18f4d66a
3
+ size 808
bhadresh-savani_distilbert-base-uncased-emotion_onnx_tokenize/1/model.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022, Lefebvre Dalloz Services
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ This module is copy-pasted in generated Triton configuration folder to perform the tokenization step.
17
+ """
18
+
19
+ # noinspection DuplicatedCode
20
+ from pathlib import Path
21
+ from typing import Dict, List
22
+
23
+ import numpy as np
24
+
25
+
26
+ try:
27
+ # noinspection PyUnresolvedReferences
28
+ import triton_python_backend_utils as pb_utils
29
+ except ImportError:
30
+ pass # triton_python_backend_utils exists only inside Triton Python backend.
31
+
32
+ from transformers import AutoTokenizer, BatchEncoding, PreTrainedTokenizer, TensorType
33
+
34
+
35
+ class TritonPythonModel:
36
+ tokenizer: PreTrainedTokenizer
37
+
38
+ def initialize(self, args: Dict[str, str]) -> None:
39
+ """
40
+ Initialize the tokenization process
41
+ :param args: arguments from Triton config file
42
+ """
43
+ # more variables in https://github.com/triton-inference-server/python_backend/blob/main/src/python.cc
44
+
45
+ path: str = str(Path(args["model_repository"]).parent.absolute())
46
+ self.tokenizer = AutoTokenizer.from_pretrained(path)
47
+
48
+ def execute(self, requests) -> "List[List[pb_utils.Tensor]]":
49
+ """
50
+ Parse and tokenize each request
51
+ :param requests: 1 or more requests received by Triton server.
52
+ :return: text as input tensors
53
+ """
54
+ responses = []
55
+ # for loop for batch requests (disabled in our case)
56
+ for request in requests:
57
+ # binary data typed back to string
58
+ query = [t.decode("UTF-8") for t in pb_utils.get_input_tensor_by_name(request, "TEXT").as_numpy().tolist()]
59
+ tokens: BatchEncoding = self.tokenizer(
60
+ text=query, return_tensors=TensorType.NUMPY, padding=True, pad_to_multiple_of=8
61
+ )
62
+ # tensorrt uses int32 as input type, ort uses int64
63
+ tokens_dict = {k: v.astype(np.int32) for k, v in tokens.items()}
64
+ # communicate the tokenization results to Triton server
65
+ outputs = list()
66
+ for input_name in self.tokenizer.model_input_names:
67
+ tensor_input = pb_utils.Tensor(input_name, tokens_dict[input_name])
68
+ outputs.append(tensor_input)
69
+
70
+ inference_response = pb_utils.InferenceResponse(output_tensors=outputs)
71
+ responses.append(inference_response)
72
+
73
+ return responses
bhadresh-savani_distilbert-base-uncased-emotion_onnx_tokenize/1/special_tokens_map.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b6d346be366a7d1d48332dbc9fdf3bf8960b5d879522b7799ddba59e76237ee3
3
+ size 125
bhadresh-savani_distilbert-base-uncased-emotion_onnx_tokenize/1/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d241a60d5e8f04cc1b2b3e9ef7a4921b27bf526d9f6050ab90f9267a1f9e5c66
3
+ size 711396
bhadresh-savani_distilbert-base-uncased-emotion_onnx_tokenize/1/tokenizer_config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e5a3982826e0689e0698a39be0ad3c588562cec9b45594ed8c33b32e0cbb85a6
3
+ size 436
bhadresh-savani_distilbert-base-uncased-emotion_onnx_tokenize/1/vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
bhadresh-savani_distilbert-base-uncased-emotion_onnx_tokenize/config.pbtxt ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "bhadresh-savani_distilbert-base-uncased-emotion_onnx_tokenize"
2
+ max_batch_size: 0
3
+ backend: "python"
4
+
5
+ input [
6
+ {
7
+ name: "TEXT"
8
+ data_type: TYPE_STRING
9
+ dims: [ -1 ]
10
+ }
11
+ ]
12
+
13
+ output [
14
+ {
15
+ name: "input_ids"
16
+ data_type: TYPE_INT32
17
+ dims: [-1, -1]
18
+ },
19
+ {
20
+ name: "attention_mask"
21
+ data_type: TYPE_INT32
22
+ dims: [-1, -1]
23
+ }
24
+ ]
25
+
26
+ instance_group [
27
+ {
28
+ count: 1
29
+ kind: KIND_GPU
30
+ }
31
+ ]