eacortes commited on
Commit
8ff51f3
·
verified ·
1 Parent(s): 0cc12bf

Upload folder using huggingface_hub

Browse files
Files changed (9) hide show
  1. .gitattributes +1 -0
  2. README.md +135 -0
  3. config.json +72 -0
  4. model.rknn +3 -0
  5. rknn.json +47 -0
  6. special_tokens_map.json +37 -0
  7. tokenizer.json +0 -0
  8. tokenizer_config.json +60 -0
  9. vocab.txt +0 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model.rknn filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: ehdwns1516/bert-base-uncased_SWAG
3
+ library_name: rk-transformers
4
+ model_name: bert-base-uncased_SWAG
5
+ tags:
6
+ - rknn
7
+ - rockchip
8
+ - npu
9
+ - rk-transformers
10
+ - rk3588
11
+ ---
12
+ # bert-base-uncased_SWAG (RKNN2)
13
+
14
+ > This is an RKNN-compatible version of the [ehdwns1516/bert-base-uncased_SWAG](https://huggingface.co/ehdwns1516/bert-base-uncased_SWAG) model. It has been optimized for Rockchip NPUs using the [rk-transformers](https://github.com/emapco/rk-transformers) library.
15
+
16
+ <details><summary>Click to see the RKNN model details and usage examples</summary>
17
+
18
+ ## Model Details
19
+
20
+ - **Original Model:** [ehdwns1516/bert-base-uncased_SWAG](https://huggingface.co/ehdwns1516/bert-base-uncased_SWAG)
21
+ - **Target Platform:** rk3588
22
+ - **rknn-toolkit2 Version:** 2.3.2
23
+ - **rk-transformers Version:** 0.3.0
24
+
25
+ ### Available Model Files
26
+
27
+ | Model File | Optimization Level | Quantization | File Size |
28
+ | :--------- | :----------------- | :----------- | :-------- |
29
+ | [model.rknn](./model.rknn) | 0 | float16 | 235.4 MB |
30
+
31
+ ## Usage
32
+
33
+ ### Installation
34
+
35
+ Install `rk-transformers` with inference dependencies to use this model:
36
+
37
+ ```bash
38
+ pip install rk-transformers[inference]
39
+ ```
40
+
41
+ #### RK-Transformers API
42
+
43
+ ```python
44
+ import numpy as np
45
+ from rktransformers import RKModelForMultipleChoice
46
+ from transformers import AutoTokenizer
47
+
48
+ tokenizer = AutoTokenizer.from_pretrained("rk-transformers/bert-base-uncased_SWAG")
49
+ model = RKModelForMultipleChoice.from_pretrained(
50
+ "rk-transformers/bert-base-uncased_SWAG",
51
+ platform="rk3588",
52
+ core_mask="auto",
53
+ )
54
+
55
+ prompt = "In Italy, pizza is served in slices."
56
+ choice0 = "It is eaten with a fork and knife."
57
+ choice1 = "It is eaten while held in the hand."
58
+ choice2 = "It is blended into a smoothie."
59
+ choice3 = "It is folded into a taco."
60
+
61
+ encoding = tokenizer(
62
+ [prompt, prompt, prompt, prompt], [choice0, choice1, choice2, choice3], return_tensors="np", padding=True
63
+ )
64
+ inputs = {k: np.expand_dims(v, 0) for k, v in encoding.items()}
65
+
66
+ outputs = model(**inputs)
67
+ logits = outputs.logits
68
+ print(logits.shape)
69
+ ```
70
+
71
+ ## Configuration
72
+
73
+ The full configuration for all exported RKNN models is available in the [config.json](./config.json) file.
74
+
75
+ </details>
76
+
77
+ ---
78
+ # ehdwns1516/bert-base-uncased_SWAG
79
+
80
+ * This model has been trained as a [SWAG dataset](https://huggingface.co/ehdwns1516/bert-base-uncased_SWAG).
81
+
82
+ * Sentence Inference Multiple Choice DEMO: [Ainize DEMO](https://main-sentence-inference-multiple-choice-ehdwns1516.endpoint.ainize.ai/)
83
+
84
+ * Sentence Inference Multiple Choice API: [Ainize API](https://ainize.web.app/redirect?git_repo=https://github.com/ehdwns1516/sentence_inference_multiple_choice)
85
+
86
+ ## Overview
87
+
88
+ Language model: [bert-base-uncased](https://huggingface.co/bert-base-uncased)
89
+
90
+ Language: English
91
+
92
+ Training data: [SWAG dataset](https://huggingface.co/datasets/swag)
93
+
94
+ Code: See [Ainize Workspace](https://ainize.ai/workspace/create?imageId=hnj95592adzr02xPTqss&git=https://github.com/ehdwns1516/Multiple_choice_SWAG_finetunning)
95
+
96
+ ## Usage
97
+ ## In Transformers
98
+
99
+ ```
100
+ from transformers import AutoTokenizer, AutoModelForMultipleChoice
101
+
102
+ tokenizer = AutoTokenizer.from_pretrained("ehdwns1516/bert-base-uncased_SWAG")
103
+
104
+ model = AutoModelForMultipleChoice.from_pretrained("ehdwns1516/bert-base-uncased_SWAG")
105
+
106
+ def run_model(candicates_count, context: str, candicates: list[str]):
107
+ assert len(candicates) == candicates_count, "you need " + candicates_count + " candidates"
108
+ choices_inputs = []
109
+ for c in candicates:
110
+ text_a = "" # empty context
111
+ text_b = context + " " + c
112
+ inputs = tokenizer(
113
+ text_a,
114
+ text_b,
115
+ add_special_tokens=True,
116
+ max_length=128,
117
+ padding="max_length",
118
+ truncation=True,
119
+ return_overflowing_tokens=True,
120
+ )
121
+ choices_inputs.append(inputs)
122
+
123
+ input_ids = torch.LongTensor([x["input_ids"] for x in choices_inputs])
124
+ output = model(input_ids=input_ids)
125
+
126
+ return {"result": candicates[torch.argmax(output.logits).item()]}
127
+
128
+ items = list()
129
+ count = 4 # candicates count
130
+ context = "your context"
131
+ for i in range(int(count)):
132
+ items.append("sentence")
133
+
134
+ result = run_model(count, context, items)
135
+ ```
config.json ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertForMultipleChoice"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "gradient_checkpointing": false,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 768,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 3072,
13
+ "layer_norm_eps": 1e-12,
14
+ "max_position_embeddings": 512,
15
+ "model_type": "bert",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 12,
18
+ "pad_token_id": 0,
19
+ "position_embedding_type": "absolute",
20
+ "rknn": {
21
+ "model.rknn": {
22
+ "batch_size": 1,
23
+ "custom_string": null,
24
+ "dynamic_input": null,
25
+ "float_dtype": "float16",
26
+ "inputs_yuv_fmt": null,
27
+ "max_seq_length": 512,
28
+ "mean_values": null,
29
+ "model_input_names": [
30
+ "input_ids",
31
+ "attention_mask",
32
+ "token_type_ids"
33
+ ],
34
+ "opset": 19,
35
+ "optimization": {
36
+ "compress_weight": false,
37
+ "enable_flash_attention": true,
38
+ "model_pruning": false,
39
+ "optimization_level": 0,
40
+ "remove_reshape": false,
41
+ "remove_weight": false,
42
+ "sparse_infer": false
43
+ },
44
+ "quantization": {
45
+ "auto_hybrid_cos_thresh": 0.98,
46
+ "auto_hybrid_euc_thresh": null,
47
+ "dataset_columns": null,
48
+ "dataset_name": null,
49
+ "dataset_size": 128,
50
+ "dataset_split": null,
51
+ "dataset_subset": null,
52
+ "do_quantization": false,
53
+ "quant_img_RGB2BGR": false,
54
+ "quantized_algorithm": "normal",
55
+ "quantized_dtype": "w8a8",
56
+ "quantized_hybrid_level": 0,
57
+ "quantized_method": "channel"
58
+ },
59
+ "rktransformers_version": "0.3.0",
60
+ "single_core_mode": false,
61
+ "std_values": null,
62
+ "target_platform": "rk3588",
63
+ "task": "multiple-choice",
64
+ "task_kwargs": null
65
+ }
66
+ },
67
+ "torch_dtype": "float32",
68
+ "transformers_version": "4.55.4",
69
+ "type_vocab_size": 2,
70
+ "use_cache": true,
71
+ "vocab_size": 30522
72
+ }
model.rknn ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0676ec0732cec396f32659ac0e4060778791cb4e9647a482d52ab7c7da9612cc
3
+ size 246809028
rknn.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model.rknn": {
3
+ "rktransformers_version": "0.2.0",
4
+ "model_input_names": [
5
+ "input_ids",
6
+ "attention_mask",
7
+ "token_type_ids"
8
+ ],
9
+ "batch_size": 1,
10
+ "max_seq_length": 512,
11
+ "num_choices": 4,
12
+ "float_dtype": "float16",
13
+ "target_platform": "rk3588",
14
+ "single_core_mode": false,
15
+ "mean_values": null,
16
+ "std_values": null,
17
+ "custom_string": null,
18
+ "inputs_yuv_fmt": null,
19
+ "dynamic_input": null,
20
+ "opset": 19,
21
+ "task": "multiple-choice",
22
+ "quantization": {
23
+ "do_quantization": false,
24
+ "dataset_name": null,
25
+ "dataset_subset": null,
26
+ "dataset_size": 128,
27
+ "dataset_split": null,
28
+ "dataset_columns": null,
29
+ "quantized_dtype": "w8a8",
30
+ "quantized_algorithm": "normal",
31
+ "quantized_method": "channel",
32
+ "quantized_hybrid_level": 0,
33
+ "quant_img_RGB2BGR": false,
34
+ "auto_hybrid_cos_thresh": 0.98,
35
+ "auto_hybrid_euc_thresh": null
36
+ },
37
+ "optimization": {
38
+ "optimization_level": 0,
39
+ "enable_flash_attention": true,
40
+ "remove_weight": false,
41
+ "compress_weight": false,
42
+ "remove_reshape": false,
43
+ "sparse_infer": false,
44
+ "model_pruning": false
45
+ }
46
+ }
47
+ }
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
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
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": false,
45
+ "cls_token": "[CLS]",
46
+ "do_lower_case": true,
47
+ "extra_special_tokens": {},
48
+ "mask_token": "[MASK]",
49
+ "max_length": 512,
50
+ "model_max_length": 512,
51
+ "pad_token": "[PAD]",
52
+ "sep_token": "[SEP]",
53
+ "stride": 0,
54
+ "strip_accents": null,
55
+ "tokenize_chinese_chars": true,
56
+ "tokenizer_class": "BertTokenizer",
57
+ "truncation_side": "right",
58
+ "truncation_strategy": "longest_first",
59
+ "unk_token": "[UNK]"
60
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff