VCal commited on
Commit
cecbf37
·
verified ·
1 Parent(s): 426fd64

Upload PyTorch model

Browse files
1755067493/config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "scl_familyhistory_de",
3
+ "architectures": [
4
+ "BertForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 312,
11
+ "id2label": {
12
+ "0": "NOT_FAMILY",
13
+ "1": "FAMILY"
14
+ },
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 312,
17
+ "label2id": {
18
+ "FAMILY": 1,
19
+ "NOT_FAMILY": 0
20
+ },
21
+ "layer_norm_eps": 1e-12,
22
+ "max_position_embeddings": 512,
23
+ "model_type": "bert",
24
+ "num_attention_heads": 12,
25
+ "num_hidden_layers": 4,
26
+ "pad_token_id": 0,
27
+ "position_embedding_type": "absolute",
28
+ "pre_trained": "",
29
+ "problem_type": "single_label_classification",
30
+ "training": "",
31
+ "transformers_version": "4.45.1",
32
+ "type_vocab_size": 2,
33
+ "use_cache": true,
34
+ "vocab_size": 31102
35
+ }
1755067493/model.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ##############################################################
3
+ ## C O P Y R I G H T (c) 2024 ##
4
+ ## DH Healthcare GmbH and/or its affiliates ##
5
+ ## All Rights Reserved ##
6
+ ##############################################################
7
+ ## ##
8
+ ## THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ##
9
+ ## DH Healthcare GmbH and/or its affiliates. ##
10
+ ## The copyright notice above does not evidence any ##
11
+ ## actual or intended publication of such source code. ##
12
+ ## ##
13
+ ##############################################################
14
+
15
+ import os
16
+ import pathlib
17
+
18
+ import numpy as np
19
+ import triton_python_backend_utils as pb_utils
20
+ from nlpserving.family_history.serving.models.family_history_model import FamilyHistoryClassificationModel
21
+
22
+
23
+ class TritonPythonModel:
24
+ def initialize(self, args):
25
+ """Initialize the model with performance optimizations."""
26
+ PATH = os.path.join(pathlib.Path(__file__).parent.resolve(), '../')
27
+ self.model = FamilyHistoryClassificationModel(model_dir=PATH)
28
+
29
+ # Performance configuration
30
+ self.batch_size = int(os.environ.get('INFERENCE_BATCH_SIZE', 64))
31
+ self.max_sequence_length = int(
32
+ os.environ.get('MAX_SEQUENCE_LENGTH', 512)
33
+ )
34
+
35
+ # Pre-allocate common objects to reduce GC pressure
36
+ self._empty_response_cache = None
37
+
38
+ # Warmup the model with a dummy inference
39
+ try:
40
+ dummy_input = ['warmup text']
41
+ self.model(dummy_input, batch_size=1, top_k=1)
42
+ except Exception:
43
+ pass # Ignore warmup errors
44
+
45
+ def execute(self, requests):
46
+ """Perform optimized inference with adaptive batching."""
47
+ if not requests:
48
+ return []
49
+
50
+ # Collect all texts from all requests for better batching
51
+ all_texts = []
52
+ request_boundaries = []
53
+ current_idx = 0
54
+
55
+ for request in requests:
56
+ input_tensors = pb_utils.get_input_tensor_by_name(request, "text")
57
+ # Direct conversion avoiding intermediate list
58
+ texts = [
59
+ tensor.decode('utf-8') for tensor in input_tensors.as_numpy()
60
+ ]
61
+ all_texts.extend(texts)
62
+ request_boundaries.append((current_idx, current_idx + len(texts)))
63
+ current_idx += len(texts)
64
+
65
+ if not all_texts:
66
+ return []
67
+
68
+ # Use adaptive batch size based on text characteristics
69
+ total_chars = sum(len(text) for text in all_texts)
70
+ avg_chars = total_chars / len(all_texts) if all_texts else 0
71
+
72
+ # Adjust batch size based on text length
73
+ if avg_chars > 1000:
74
+ effective_batch_size = min(len(all_texts), self.batch_size // 2)
75
+ elif avg_chars < 200:
76
+ effective_batch_size = min(len(all_texts), self.batch_size * 2)
77
+ else:
78
+ effective_batch_size = min(len(all_texts), self.batch_size)
79
+
80
+ # Process all texts together for better efficiency
81
+ all_outputs = self.model(
82
+ all_texts,
83
+ batch_size=effective_batch_size,
84
+ top_k=1
85
+ )
86
+
87
+ # Split outputs back to individual responses
88
+ responses = []
89
+ for start_idx, end_idx in request_boundaries:
90
+ request_outputs = all_outputs[start_idx:end_idx]
91
+ # Pre-allocate array for better performance
92
+ output = np.array([
93
+ str(output_dict).encode('utf-8')
94
+ for output_dict in request_outputs
95
+ ], dtype=object)
96
+
97
+ response = pb_utils.InferenceResponse(
98
+ output_tensors=[pb_utils.Tensor("output", output)]
99
+ )
100
+ responses.append(response)
101
+
102
+ return responses
103
+
104
+ def finalize(self):
105
+ """Clean up model resources."""
106
+ if hasattr(self, 'model'):
107
+ del self.model
1755067493/special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
1755067493/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
1755067493/tokenizer_config.json ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "101": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "102": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "103": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "104": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": true,
45
+ "cls_token": "[CLS]",
46
+ "do_lower_case": true,
47
+ "mask_token": "[MASK]",
48
+ "max_length": 256,
49
+ "model_max_length": 1000000000000000019884624838656,
50
+ "pad_to_multiple_of": null,
51
+ "pad_token": "[PAD]",
52
+ "pad_token_type_id": 0,
53
+ "padding_side": "right",
54
+ "sep_token": "[SEP]",
55
+ "stride": 0,
56
+ "strip_accents": null,
57
+ "tokenize_chinese_chars": true,
58
+ "tokenizer_class": "BertTokenizer",
59
+ "truncation_side": "right",
60
+ "truncation_strategy": "longest_first",
61
+ "unk_token": "[UNK]"
62
+ }
1755067493/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:78d7bde3be46debb8c44f9a2e0c0fcf939497216bea33667edf23e380c47ff31
3
+ size 5240
1755067493/vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
config_cpu.pbtxt ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "tinybert-familyhistory-de"
2
+ backend: "python"
3
+ max_batch_size: 0
4
+
5
+ input [
6
+ {
7
+ name: "text"
8
+ data_type: TYPE_STRING
9
+ dims: [-1]
10
+ }
11
+ ]
12
+ output [
13
+ {
14
+ name: "output"
15
+ data_type: TYPE_STRING
16
+ dims: [-1]
17
+ }
18
+ ]
19
+
20
+ instance_group [
21
+ {
22
+ count: 1
23
+ kind: KIND_CPU
24
+ }
25
+ ]
26
+
27
+ # CPU-specific optimizations
28
+ optimization {
29
+ execution_accelerators {
30
+ cpu_execution_accelerator: [{
31
+ name: "openvino"
32
+ }]
33
+ }
34
+ }
35
+
36
+ # Performance tuning parameters
37
+ parameters: {
38
+ key: "INFERENCE_BATCH_SIZE"
39
+ value: {
40
+ string_value: "96"
41
+ }
42
+ }
43
+ parameters: {
44
+ key: "MAX_SEQUENCE_LENGTH"
45
+ value: {
46
+ string_value: "512"
47
+ }
48
+ }
config_gpu.pbtxt ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "tinybert-familyhistory-de"
2
+ backend: "python"
3
+ input [
4
+ {
5
+ name: "text"
6
+ data_type: TYPE_STRING
7
+ dims: [-1]
8
+ }
9
+ ]
10
+ output [
11
+ {
12
+ name: "output"
13
+ data_type: TYPE_STRING
14
+ dims: [-1]
15
+ }
16
+ ]
17
+
18
+ instance_group [
19
+ {
20
+ kind: KIND_GPU
21
+ }
22
+ ]
23
+
24
+ dynamic_batching {
25
+ default_queue_policy: {
26
+ default_timeout_microseconds: 60000000
27
+ }
28
+ }
model_info.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_version": 1768930002,
3
+ "model_name": "bert-demo-de",
4
+ "model_type": "bert",
5
+ "model_platform": "pytorch",
6
+ "model_architecture": "BERT",
7
+ "model_description": "Retrieve named entities from text.",
8
+ "model_date": "2026-01-20T18:26:42.445432+01:00",
9
+ "clinalytix_version": "unknown",
10
+ "model_objective": "RECOGNITION",
11
+ "use_case": "demo",
12
+ "build_number": null,
13
+ "revision_number": null,
14
+ "language_code": "de",
15
+ "language_codes_multilingual": null,
16
+ "target": null,
17
+ "ner_config": {
18
+ "max_length": 256,
19
+ "stride": 16
20
+ },
21
+ "nen_config": null,
22
+ "negation_config": null,
23
+ "temporality_config": null,
24
+ "familyhistory_config": null,
25
+ "rer_config": null,
26
+ "git_info": {
27
+ "commit_hash": null,
28
+ "branch": null,
29
+ "tag": null,
30
+ "description": null,
31
+ "remote_url": null
32
+ }
33
+ }