models/README.md CHANGED
@@ -49,14 +49,21 @@ models
49
  ├── README.md
50
  └── TabRec
51
  ├── StructEqTable
52
-    ├── config.json
53
-    ├── generation_config.json
54
-    ├── model.safetensors
55
-    ├── preprocessor_config.json
56
-    ├── special_tokens_map.json
57
-    ├── spiece.model
58
-    ├── tokenizer.json
59
-    └── tokenizer_config.json
 
 
 
 
 
 
 
60
  └── TableMaster
61
  ├── ch_PP-OCRv3_det_infer
62
  │   ├── inference.pdiparams
 
49
  ├── README.md
50
  └── TabRec
51
  ├── StructEqTable
52
+ ├── added_tokens.json
53
+ ├── config.json
54
+ ├── configuration_intern_vit.py
55
+ ├── configuration_internvl_chat.py
56
+ ├── conversation.py
57
+ ├── generation_config.json
58
+ ├── merges.txt
59
+ ├── modeling_intern_vit.py
60
+ │ ├── modeling_internvl_chat.py
61
+ │ ├── model.safetensors
62
+ │ ├── preprocessor_config.json
63
+ │ ├── README.md
64
+ │ ├── special_tokens_map.json
65
+ │ ├── tokenizer_config.json
66
+ │ └── vocab.json
67
  └── TableMaster
68
  ├── ch_PP-OCRv3_det_infer
69
  │   ├── inference.pdiparams
models/TabRec/StructEqTable/README.md ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - zh
5
+ pipeline_tag: image-to-text
6
+ inference: false
7
+ license: apache-2.0
8
+ ---
9
+
10
+ <div align="center">
11
+ <h1>StructEqTable-Deploy: A High-efficiency Open-source Toolkit for Table-to-Latex Transformation</h1>
12
+
13
+
14
+ [[ Github Repo ]](https://github.com/UniModal4Reasoning/StructEqTable-Deploy) [[ Related Paper ]](https://arxiv.org/abs/2406.11633) [[ Website ]](https://unimodal4reasoning.github.io/DocGenome_page/)
15
+
16
+ [[ Dataset🤗 ]](https://huggingface.co/datasets/U4R/DocGenome/tree/main) [[ Models🤗 ]](https://huggingface.co/U4R/StructTable-InternVL2-1B/tree/main) [[ Demo💬 ]](https://www.modelscope.cn/studios/HongbinZhou/StructEqTable-Demo/)
17
+
18
+
19
+ </div>
20
+
21
+ Welcome to the official repository of StructEqTable-Deploy, a solution that converts images of Table into LaTeX/HTML/MarkDown, powered by scalable data from [DocGenome benchmark](https://unimodal4reasoning.github.io/DocGenome_page/).
22
+
23
+ ## Overview
24
+ Table is an effective way to represent structured data in scientific publications, financial statements, invoices, web pages, and many other scenarios. Extracting tabular data from a visual table image and performing the downstream reasoning tasks according to the extracted data is challenging, mainly due to that tables often present complicated column and row headers with spanning cell operation. To address these challenges, we present TableX, a large-scale multi-modal table benchmark extracted from [DocGenome benchmark](https://unimodal4reasoning.github.io/DocGenome_page/) for table pre-training, comprising more than 2 million high-quality Image-LaTeX pair data covering 156 disciplinary classes. Besides, benefiting from such large-scale data, we train an end-to-end model, StructEqTable, which provides the capability to precisely obtain the corresponding LaTeX description from a visual table image and perform multiple table-related reasoning tasks, including structural extraction and question answering, broadening its application scope and potential.
25
+
26
+ ## Changelog
27
+ - [2024/10/19] 🔥 We have released our **latest model [StructTable-InternVL2-1B](https://huggingface.co/U4R/StructTable-InternVL2-1B/tree/main)**!
28
+
29
+ Thanks to IntenrVL2 powerful foundational capabilities, and through fine-tuning on the synthetic tabular data and DocGenome dataset, StructTable can convert table image into various common table formats including LaTeX, HTML, and Markdown. Moreover, inference speed has been significantly improved compared to the v0.2 version.
30
+ - [2024/8/22] We have released our StructTable-base-v0.2, fine-tuned on the DocGenome dataset. This version features improved inference speed and robustness, achieved through data augmentation and reduced image token num.
31
+ - [2024/8/08] We have released the TensorRT accelerated version, which only takes about 1 second for most images on GPU A100. Please follow the tutorial to install the environment and compile the model weights.
32
+ - [2024/7/30] We have released the first version of StructEqTable.
33
+
34
+ ## TODO
35
+
36
+ - [x] Release inference code and checkpoints of StructEqTable.
37
+ - [x] Support Chinese version of StructEqTable.
38
+ - [x] Accelerated version of StructEqTable using TensorRT-LLM.
39
+ - [x] Expand more domains of table image to improve the model's general capabilities.
40
+ - [x] Efficient inference of StructTable-InternVL2-1B by [LMDeploy](https://github.com/InternLM/lmdeploy) Tookit.
41
+ - [ ] Release our table pre-training and fine-tuning code
42
+
43
+
44
+ ## Installation
45
+ ``` bash
46
+ conda create -n structeqtable python>=3.10
47
+ conda activate structeqtable
48
+
49
+ # Install from Source code (Suggested)
50
+ git clone https://github.com/UniModal4Reasoning/StructEqTable-Deploy.git
51
+ cd StructEqTable-Deploy
52
+ python setup develop
53
+
54
+ # or Install from Github repo
55
+ pip install "git+https://github.com/UniModal4Reasoning/StructEqTable-Deploy.git"
56
+
57
+ # or Install from PyPI
58
+ pip install struct-eqtable==0.3.0
59
+ ```
60
+
61
+ ## Model Zoo
62
+
63
+ | Base Model | Model Size | Training Data | Data Augmentation | LMDeploy | TensorRT | HuggingFace |
64
+ |---------------------|------------|------------------|-------------------|----------|----------|-------------------|
65
+ | InternVL2-1B | ~1B | DocGenome and Synthetic Data | ✔ | ✔ | | [StructTable v0.3](https://huggingface.co/U4R/StructTable-InternVL2-1B/tree/main) |
66
+ | Pix2Struct-base | ~300M | DocGenome | ✔ | | ✔ | [StructTable v0.2](https://huggingface.co/U4R/StructTable-base/tree/v0.2) |
67
+ | Pix2Struct-base | ~300M | DocGenome | | | ✔ | [StructTable v0.1](https://huggingface.co/U4R/StructTable-base/tree/v0.1) |
68
+
69
+
70
+
71
+ ## Quick Demo
72
+ - Run the demo/demo.py
73
+ ```shell script
74
+ cd tools/demo
75
+
76
+ python demo.py \
77
+ --image_path ./demo.png \
78
+ --ckpt_path U4R/StructTable-InternVL2-1B \
79
+ --output_format latex
80
+ ```
81
+
82
+ - HTML or Markdown format output (Only Supported by StructTable-InternVL2-1B)
83
+
84
+ ```shell script
85
+ python demo.py \
86
+ --image_path ./demo.png \
87
+ --ckpt_path U4R/StructTable-InternVL2-1B \
88
+ --output_format html markdown
89
+ ```
90
+
91
+ ## Efficient Inference
92
+ - Install LMDeploy Tookit
93
+ ```shell script
94
+ pip install lmdeploy
95
+ ```
96
+
97
+ - Run the demo/demo.py
98
+ ```shell script
99
+ cd tools/demo
100
+
101
+ python demo.py \
102
+ --image_path ./demo.png \
103
+ --ckpt_path U4R/StructTable-InternVL2-1B \
104
+ --output_format latex \
105
+ --lmdeploy
106
+ ```
107
+
108
+
109
+ - Visualization Result
110
+
111
+ You can copy the output LaTeX code into [demo.tex](../tools/demo/demo.tex), then use [Overleaf](https://www.overleaf.com/project) for table visualization.
112
+ ![](docs/imgs/output.png)
113
+
114
+
115
+ ## Acknowledgements
116
+ - [DocGenome](https://github.com/UniModal4Reasoning/DocGenome). An Open Large-scale Scientific Document Benchmark for Training and Testing Multi-modal Large Models.
117
+ - [ChartVLM](https://github.com/UniModal4Reasoning/ChartVLM). A Versatile Benchmark and Foundation Model for Complicated Chart Reasoning.
118
+ - [Pix2Struct](https://github.com/google-research/pix2struct). Screenshot Parsing as Pretraining for Visual Language Understanding.
119
+ - [InternVL Family](https://github.com/OpenGVLab/InternVL). A Series of Powerful Foundational Vision-Language Models.
120
+ - [LMDeploy](https://github.com/InternLM/lmdeploy). A toolkit for compressing, deploying, and serving LLM and MLLM.
121
+ - [UniMERNet](https://github.com/opendatalab/UniMERNet). A Universal Network for Real-World Mathematical Expression Recognition.
122
+ - [Donut](https://huggingface.co/naver-clova-ix/donut-base). The UniMERNet's Transformer Encoder-Decoder are referenced from Donut.
123
+ - [Nougat](https://github.com/facebookresearch/nougat). Data Augmentation follows Nougat.
124
+ - [TensorRT-LLM](https://github.com/NVIDIA/TensorRT-LLM). Model inference acceleration uses TensorRT-LLM.
125
+
126
+
127
+ ## License
128
+ StructEqTable is released under the [Apache License 2.0](LICENSE)
129
+
130
+ ## Citation
131
+ If you find our models / code / papers useful in your research, please consider giving ⭐ and citations 📝, thx :)
132
+ ```bibtex
133
+ @article{xia2024docgenome,
134
+ title={DocGenome: An Open Large-scale Scientific Document Benchmark for Training and Testing Multi-modal Large Language Models},
135
+ author={Xia, Renqiu and Mao, Song and Yan, Xiangchao and Zhou, Hongbin and Zhang, Bo and Peng, Haoyang and Pi, Jiahao and Fu, Daocheng and Wu, Wenjie and Ye, Hancheng and others},
136
+ journal={arXiv preprint arXiv:2406.11633},
137
+ year={2024}
138
+ }
139
+ ```
140
+
141
+ ## Contact Us
142
+ If you encounter any issues or have questions, please feel free to contact us via zhouhongbin@pjlab.org.cn.
models/TabRec/StructEqTable/added_tokens.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</box>": 151654,
3
+ "</img>": 151647,
4
+ "</quad>": 151650,
5
+ "</ref>": 151652,
6
+ "<IMG_CONTEXT>": 151648,
7
+ "<box>": 151653,
8
+ "<img>": 151646,
9
+ "<quad>": 151649,
10
+ "<ref>": 151651,
11
+ "<|endoftext|>": 151643,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644
14
+ }
models/TabRec/StructEqTable/config.json CHANGED
@@ -1,36 +1,193 @@
1
  {
2
- "_name_or_path": "/cpfs01/user/zhouhongbin/code/StructEqTable-deepspeed/ckpt/pretrained/pix2struct-base-zh",
 
3
  "architectures": [
4
- "Pix2StructForConditionalGeneration"
5
  ],
6
- "decoder_start_token_id": 0,
7
- "eos_token_id": 1,
8
- "initializer_factor": 1.0,
9
- "initializer_range": 0.02,
10
- "is_encoder_decoder": true,
11
- "is_vqa": false,
12
- "model_type": "pix2struct",
13
- "pad_token_id": 0,
14
- "text_config": {
15
- "dropout_rate": 0.2,
16
- "encoder_hidden_size": 768,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  "initializer_range": 0.02,
18
- "model_type": "pix2struct_text_model",
19
- "vocab_size": 77078
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  },
21
- "tie_word_embeddings": false,
22
- "torch_dtype": "float32",
23
- "transformers_version": "4.37.2",
 
 
 
 
 
 
24
  "use_cache": false,
 
 
25
  "vision_config": {
26
- "attention_dropout": 0.2,
27
- "dropout_rate": 0.2,
28
- "hidden_dropout_prob": 0.2,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  "initializer_range": 0.02,
30
- "layer_norm_bias": false,
31
- "model_type": "pix2struct_vision_model",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  "num_channels": 3,
33
- "patch_size": 16,
34
- "projection_dim": 768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  }
36
  }
 
1
  {
2
+ "_commit_hash": null,
3
+ "_name_or_path": "internvl2-1B",
4
  "architectures": [
5
+ "InternVLChatModel"
6
  ],
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_internvl_chat.InternVLChatConfig",
9
+ "AutoModel": "modeling_internvl_chat.InternVLChatModel",
10
+ "AutoModelForCausalLM": "modeling_internvl_chat.InternVLChatModel"
11
+ },
12
+ "downsample_ratio": 0.5,
13
+ "dynamic_image_size": true,
14
+ "force_image_size": 448,
15
+ "llm_config": {
16
+ "_name_or_path": "Qwen/Qwen2-0.5B-Instruct",
17
+ "add_cross_attention": false,
18
+ "architectures": [
19
+ "Qwen2ForCausalLM"
20
+ ],
21
+ "attention_dropout": 0.0,
22
+ "bad_words_ids": null,
23
+ "begin_suppress_tokens": null,
24
+ "bos_token_id": 151643,
25
+ "chunk_size_feed_forward": 0,
26
+ "cross_attention_hidden_size": null,
27
+ "decoder_start_token_id": null,
28
+ "diversity_penalty": 0.0,
29
+ "do_sample": false,
30
+ "early_stopping": false,
31
+ "encoder_no_repeat_ngram_size": 0,
32
+ "eos_token_id": 151645,
33
+ "exponential_decay_length_penalty": null,
34
+ "finetuning_task": null,
35
+ "forced_bos_token_id": null,
36
+ "forced_eos_token_id": null,
37
+ "hidden_act": "silu",
38
+ "hidden_size": 896,
39
+ "id2label": {
40
+ "0": "LABEL_0",
41
+ "1": "LABEL_1"
42
+ },
43
  "initializer_range": 0.02,
44
+ "intermediate_size": 4864,
45
+ "is_decoder": false,
46
+ "is_encoder_decoder": false,
47
+ "label2id": {
48
+ "LABEL_0": 0,
49
+ "LABEL_1": 1
50
+ },
51
+ "length_penalty": 1.0,
52
+ "max_length": 20,
53
+ "max_position_embeddings": 32768,
54
+ "max_window_layers": 24,
55
+ "min_length": 0,
56
+ "model_type": "qwen2",
57
+ "no_repeat_ngram_size": 0,
58
+ "num_attention_heads": 14,
59
+ "num_beam_groups": 1,
60
+ "num_beams": 1,
61
+ "num_hidden_layers": 24,
62
+ "num_key_value_heads": 2,
63
+ "num_return_sequences": 1,
64
+ "output_attentions": false,
65
+ "output_hidden_states": false,
66
+ "output_scores": false,
67
+ "pad_token_id": null,
68
+ "prefix": null,
69
+ "problem_type": null,
70
+ "pruned_heads": {},
71
+ "remove_invalid_values": false,
72
+ "repetition_penalty": 1.0,
73
+ "return_dict": true,
74
+ "return_dict_in_generate": false,
75
+ "rms_norm_eps": 1e-06,
76
+ "rope_theta": 1000000.0,
77
+ "sep_token_id": null,
78
+ "sliding_window": null,
79
+ "suppress_tokens": null,
80
+ "task_specific_params": null,
81
+ "temperature": 1.0,
82
+ "tf_legacy_loss": false,
83
+ "tie_encoder_decoder": false,
84
+ "tie_word_embeddings": true,
85
+ "tokenizer_class": null,
86
+ "top_k": 50,
87
+ "top_p": 1.0,
88
+ "torch_dtype": "bfloat16",
89
+ "torchscript": false,
90
+ "transformers_version": "4.44.0.dev0",
91
+ "typical_p": 1.0,
92
+ "use_bfloat16": true,
93
+ "use_cache": false,
94
+ "use_sliding_window": false,
95
+ "vocab_size": 151655
96
  },
97
+ "max_dynamic_patch": 12,
98
+ "min_dynamic_patch": 1,
99
+ "model_type": "internvl_chat",
100
+ "ps_version": "v2",
101
+ "select_layer": -1,
102
+ "template": "Hermes-2",
103
+ "torch_dtype": "bfloat16",
104
+ "transformers_version": null,
105
+ "use_backbone_lora": 0,
106
  "use_cache": false,
107
+ "use_llm_lora": 0,
108
+ "use_thumbnail": true,
109
  "vision_config": {
110
+ "_name_or_path": "",
111
+ "add_cross_attention": false,
112
+ "architectures": [
113
+ "InternVisionModel"
114
+ ],
115
+ "attention_dropout": 0.0,
116
+ "bad_words_ids": null,
117
+ "begin_suppress_tokens": null,
118
+ "bos_token_id": null,
119
+ "chunk_size_feed_forward": 0,
120
+ "cross_attention_hidden_size": null,
121
+ "decoder_start_token_id": null,
122
+ "diversity_penalty": 0.0,
123
+ "do_sample": false,
124
+ "drop_path_rate": 0.0,
125
+ "dropout": 0.0,
126
+ "early_stopping": false,
127
+ "encoder_no_repeat_ngram_size": 0,
128
+ "eos_token_id": null,
129
+ "exponential_decay_length_penalty": null,
130
+ "finetuning_task": null,
131
+ "forced_bos_token_id": null,
132
+ "forced_eos_token_id": null,
133
+ "hidden_act": "gelu",
134
+ "hidden_size": 1024,
135
+ "id2label": {
136
+ "0": "LABEL_0",
137
+ "1": "LABEL_1"
138
+ },
139
+ "image_size": 448,
140
+ "initializer_factor": 1.0,
141
  "initializer_range": 0.02,
142
+ "intermediate_size": 4096,
143
+ "is_decoder": false,
144
+ "is_encoder_decoder": false,
145
+ "label2id": {
146
+ "LABEL_0": 0,
147
+ "LABEL_1": 1
148
+ },
149
+ "layer_norm_eps": 1e-06,
150
+ "length_penalty": 1.0,
151
+ "max_length": 20,
152
+ "min_length": 0,
153
+ "model_type": "intern_vit_6b",
154
+ "no_repeat_ngram_size": 0,
155
+ "norm_type": "layer_norm",
156
+ "num_attention_heads": 16,
157
+ "num_beam_groups": 1,
158
+ "num_beams": 1,
159
  "num_channels": 3,
160
+ "num_hidden_layers": 24,
161
+ "num_return_sequences": 1,
162
+ "output_attentions": false,
163
+ "output_hidden_states": false,
164
+ "output_scores": false,
165
+ "pad_token_id": null,
166
+ "patch_size": 14,
167
+ "prefix": null,
168
+ "problem_type": null,
169
+ "pruned_heads": {},
170
+ "qk_normalization": false,
171
+ "qkv_bias": true,
172
+ "remove_invalid_values": false,
173
+ "repetition_penalty": 1.0,
174
+ "return_dict": true,
175
+ "return_dict_in_generate": false,
176
+ "sep_token_id": null,
177
+ "suppress_tokens": null,
178
+ "task_specific_params": null,
179
+ "temperature": 1.0,
180
+ "tf_legacy_loss": false,
181
+ "tie_encoder_decoder": false,
182
+ "tie_word_embeddings": true,
183
+ "tokenizer_class": null,
184
+ "top_k": 50,
185
+ "top_p": 1.0,
186
+ "torch_dtype": "bfloat16",
187
+ "torchscript": false,
188
+ "transformers_version": "4.44.0.dev0",
189
+ "typical_p": 1.0,
190
+ "use_bfloat16": true,
191
+ "use_flash_attn": true
192
  }
193
  }
models/TabRec/StructEqTable/configuration_intern_vit.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # --------------------------------------------------------
2
+ # InternVL
3
+ # Copyright (c) 2024 OpenGVLab
4
+ # Licensed under The MIT License [see LICENSE for details]
5
+ # --------------------------------------------------------
6
+ import os
7
+ from typing import Union
8
+
9
+ from transformers.configuration_utils import PretrainedConfig
10
+ from transformers.utils import logging
11
+
12
+ logger = logging.get_logger(__name__)
13
+
14
+
15
+ class InternVisionConfig(PretrainedConfig):
16
+ r"""
17
+ This is the configuration class to store the configuration of a [`InternVisionModel`]. It is used to
18
+ instantiate a vision encoder according to the specified arguments, defining the model architecture.
19
+
20
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
21
+ documentation from [`PretrainedConfig`] for more information.
22
+
23
+ Args:
24
+ num_channels (`int`, *optional*, defaults to 3):
25
+ Number of color channels in the input images (e.g., 3 for RGB).
26
+ patch_size (`int`, *optional*, defaults to 14):
27
+ The size (resolution) of each patch.
28
+ image_size (`int`, *optional*, defaults to 224):
29
+ The size (resolution) of each image.
30
+ qkv_bias (`bool`, *optional*, defaults to `False`):
31
+ Whether to add a bias to the queries and values in the self-attention layers.
32
+ hidden_size (`int`, *optional*, defaults to 3200):
33
+ Dimensionality of the encoder layers and the pooler layer.
34
+ num_attention_heads (`int`, *optional*, defaults to 25):
35
+ Number of attention heads for each attention layer in the Transformer encoder.
36
+ intermediate_size (`int`, *optional*, defaults to 12800):
37
+ Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
38
+ qk_normalization (`bool`, *optional*, defaults to `True`):
39
+ Whether to normalize the queries and keys in the self-attention layers.
40
+ num_hidden_layers (`int`, *optional*, defaults to 48):
41
+ Number of hidden layers in the Transformer encoder.
42
+ use_flash_attn (`bool`, *optional*, defaults to `True`):
43
+ Whether to use flash attention mechanism.
44
+ hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
45
+ The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
46
+ `"relu"`, `"selu"` and `"gelu_new"` ``"gelu"` are supported.
47
+ layer_norm_eps (`float`, *optional*, defaults to 1e-6):
48
+ The epsilon used by the layer normalization layers.
49
+ dropout (`float`, *optional*, defaults to 0.0):
50
+ The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
51
+ drop_path_rate (`float`, *optional*, defaults to 0.0):
52
+ Dropout rate for stochastic depth.
53
+ attention_dropout (`float`, *optional*, defaults to 0.0):
54
+ The dropout ratio for the attention probabilities.
55
+ initializer_range (`float`, *optional*, defaults to 0.02):
56
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
57
+ initializer_factor (`float`, *optional*, defaults to 0.1):
58
+ A factor for layer scale.
59
+ """
60
+
61
+ model_type = 'intern_vit_6b'
62
+
63
+ def __init__(
64
+ self,
65
+ num_channels=3,
66
+ patch_size=14,
67
+ image_size=224,
68
+ qkv_bias=False,
69
+ hidden_size=3200,
70
+ num_attention_heads=25,
71
+ intermediate_size=12800,
72
+ qk_normalization=True,
73
+ num_hidden_layers=48,
74
+ use_flash_attn=True,
75
+ hidden_act='gelu',
76
+ norm_type='rms_norm',
77
+ layer_norm_eps=1e-6,
78
+ dropout=0.0,
79
+ drop_path_rate=0.0,
80
+ attention_dropout=0.0,
81
+ initializer_range=0.02,
82
+ initializer_factor=0.1,
83
+ **kwargs,
84
+ ):
85
+ super().__init__(**kwargs)
86
+
87
+ self.hidden_size = hidden_size
88
+ self.intermediate_size = intermediate_size
89
+ self.dropout = dropout
90
+ self.drop_path_rate = drop_path_rate
91
+ self.num_hidden_layers = num_hidden_layers
92
+ self.num_attention_heads = num_attention_heads
93
+ self.num_channels = num_channels
94
+ self.patch_size = patch_size
95
+ self.image_size = image_size
96
+ self.initializer_range = initializer_range
97
+ self.initializer_factor = initializer_factor
98
+ self.attention_dropout = attention_dropout
99
+ self.layer_norm_eps = layer_norm_eps
100
+ self.hidden_act = hidden_act
101
+ self.norm_type = norm_type
102
+ self.qkv_bias = qkv_bias
103
+ self.qk_normalization = qk_normalization
104
+ self.use_flash_attn = use_flash_attn
105
+
106
+ @classmethod
107
+ def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> 'PretrainedConfig':
108
+ config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
109
+
110
+ if 'vision_config' in config_dict:
111
+ config_dict = config_dict['vision_config']
112
+
113
+ if 'model_type' in config_dict and hasattr(cls, 'model_type') and config_dict['model_type'] != cls.model_type:
114
+ logger.warning(
115
+ f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
116
+ f'{cls.model_type}. This is not supported for all configurations of models and can yield errors.'
117
+ )
118
+
119
+ return cls.from_dict(config_dict, **kwargs)
models/TabRec/StructEqTable/configuration_internvl_chat.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # --------------------------------------------------------
2
+ # InternVL
3
+ # Copyright (c) 2024 OpenGVLab
4
+ # Licensed under The MIT License [see LICENSE for details]
5
+ # --------------------------------------------------------
6
+
7
+ import copy
8
+
9
+ from transformers import AutoConfig, LlamaConfig, Qwen2Config
10
+ from transformers.configuration_utils import PretrainedConfig
11
+ from transformers.utils import logging
12
+
13
+ from .configuration_intern_vit import InternVisionConfig
14
+
15
+ logger = logging.get_logger(__name__)
16
+
17
+
18
+ class InternVLChatConfig(PretrainedConfig):
19
+ model_type = 'internvl_chat'
20
+ is_composition = True
21
+
22
+ def __init__(
23
+ self,
24
+ vision_config=None,
25
+ llm_config=None,
26
+ use_backbone_lora=0,
27
+ use_llm_lora=0,
28
+ select_layer=-1,
29
+ force_image_size=None,
30
+ downsample_ratio=0.5,
31
+ template=None,
32
+ dynamic_image_size=False,
33
+ use_thumbnail=False,
34
+ ps_version='v1',
35
+ min_dynamic_patch=1,
36
+ max_dynamic_patch=6,
37
+ **kwargs):
38
+ super().__init__(**kwargs)
39
+
40
+ if vision_config is None:
41
+ vision_config = {}
42
+ logger.info('vision_config is None. Initializing the InternVisionConfig with default values.')
43
+
44
+ if llm_config is None:
45
+ llm_config = {}
46
+ logger.info('llm_config is None. Initializing the LlamaConfig config with default values (`LlamaConfig`).')
47
+
48
+ self.vision_config = InternVisionConfig(**vision_config)
49
+ if llm_config['architectures'][0] == 'LlamaForCausalLM':
50
+ self.llm_config = LlamaConfig(**llm_config)
51
+ elif llm_config['architectures'][0] == 'Qwen2ForCausalLM':
52
+ self.llm_config = Qwen2Config(**llm_config)
53
+ else:
54
+ raise ValueError('Unsupported architecture: {}'.format(llm_config['architectures'][0]))
55
+ self.use_backbone_lora = use_backbone_lora
56
+ self.use_llm_lora = use_llm_lora
57
+ self.select_layer = select_layer
58
+ self.force_image_size = force_image_size
59
+ self.downsample_ratio = downsample_ratio
60
+ self.template = template
61
+ self.dynamic_image_size = dynamic_image_size
62
+ self.use_thumbnail = use_thumbnail
63
+ self.ps_version = ps_version # pixel shuffle version
64
+ self.min_dynamic_patch = min_dynamic_patch
65
+ self.max_dynamic_patch = max_dynamic_patch
66
+
67
+ logger.info(f'vision_select_layer: {self.select_layer}')
68
+ logger.info(f'ps_version: {self.ps_version}')
69
+ logger.info(f'min_dynamic_patch: {self.min_dynamic_patch}')
70
+ logger.info(f'max_dynamic_patch: {self.max_dynamic_patch}')
71
+
72
+ def to_dict(self):
73
+ """
74
+ Serializes this instance to a Python dictionary. Override the default [`~PretrainedConfig.to_dict`].
75
+
76
+ Returns:
77
+ `Dict[str, any]`: Dictionary of all the attributes that make up this configuration instance,
78
+ """
79
+ output = copy.deepcopy(self.__dict__)
80
+ output['vision_config'] = self.vision_config.to_dict()
81
+ output['llm_config'] = self.llm_config.to_dict()
82
+ output['model_type'] = self.__class__.model_type
83
+ output['use_backbone_lora'] = self.use_backbone_lora
84
+ output['use_llm_lora'] = self.use_llm_lora
85
+ output['select_layer'] = self.select_layer
86
+ output['force_image_size'] = self.force_image_size
87
+ output['downsample_ratio'] = self.downsample_ratio
88
+ output['template'] = self.template
89
+ output['dynamic_image_size'] = self.dynamic_image_size
90
+ output['use_thumbnail'] = self.use_thumbnail
91
+ output['ps_version'] = self.ps_version
92
+ output['min_dynamic_patch'] = self.min_dynamic_patch
93
+ output['max_dynamic_patch'] = self.max_dynamic_patch
94
+
95
+ return output
models/TabRec/StructEqTable/conversation.py ADDED
@@ -0,0 +1,394 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Conversation prompt templates.
3
+
4
+ We kindly request that you import fastchat instead of copying this file if you wish to use it.
5
+ If you have changes in mind, please contribute back so the community can benefit collectively and continue to maintain these valuable templates.
6
+ """
7
+
8
+ import dataclasses
9
+ from enum import IntEnum, auto
10
+ from typing import Any, Dict, List, Tuple, Union
11
+
12
+
13
+ class SeparatorStyle(IntEnum):
14
+ """Separator styles."""
15
+
16
+ ADD_COLON_SINGLE = auto()
17
+ ADD_COLON_TWO = auto()
18
+ ADD_COLON_SPACE_SINGLE = auto()
19
+ NO_COLON_SINGLE = auto()
20
+ NO_COLON_TWO = auto()
21
+ ADD_NEW_LINE_SINGLE = auto()
22
+ LLAMA2 = auto()
23
+ CHATGLM = auto()
24
+ CHATML = auto()
25
+ CHATINTERN = auto()
26
+ DOLLY = auto()
27
+ RWKV = auto()
28
+ PHOENIX = auto()
29
+ ROBIN = auto()
30
+ FALCON_CHAT = auto()
31
+ CHATGLM3 = auto()
32
+ INTERNVL_ZH = auto()
33
+ MPT = auto()
34
+
35
+
36
+ @dataclasses.dataclass
37
+ class Conversation:
38
+ """A class that manages prompt templates and keeps all conversation history."""
39
+
40
+ # The name of this template
41
+ name: str
42
+ # The template of the system prompt
43
+ system_template: str = '{system_message}'
44
+ # The system message
45
+ system_message: str = ''
46
+ # The names of two roles
47
+ roles: Tuple[str] = ('USER', 'ASSISTANT')
48
+ # All messages. Each item is (role, message).
49
+ messages: List[List[str]] = ()
50
+ # The number of few shot examples
51
+ offset: int = 0
52
+ # The separator style and configurations
53
+ sep_style: SeparatorStyle = SeparatorStyle.ADD_COLON_SINGLE
54
+ sep: str = '\n'
55
+ sep2: str = None
56
+ # Stop criteria (the default one is EOS token)
57
+ stop_str: Union[str, List[str]] = None
58
+ # Stops generation if meeting any token in this list
59
+ stop_token_ids: List[int] = None
60
+
61
+ def get_prompt(self) -> str:
62
+ """Get the prompt for generation."""
63
+ system_prompt = self.system_template.format(system_message=self.system_message)
64
+ if self.sep_style == SeparatorStyle.ADD_COLON_SINGLE:
65
+ ret = system_prompt + self.sep
66
+ for role, message in self.messages:
67
+ if message:
68
+ ret += role + ': ' + message + self.sep
69
+ else:
70
+ ret += role + ':'
71
+ return ret
72
+ elif self.sep_style == SeparatorStyle.ADD_COLON_TWO:
73
+ seps = [self.sep, self.sep2]
74
+ ret = system_prompt + seps[0]
75
+ for i, (role, message) in enumerate(self.messages):
76
+ if message:
77
+ ret += role + ': ' + message + seps[i % 2]
78
+ else:
79
+ ret += role + ':'
80
+ return ret
81
+ elif self.sep_style == SeparatorStyle.ADD_COLON_SPACE_SINGLE:
82
+ ret = system_prompt + self.sep
83
+ for role, message in self.messages:
84
+ if message:
85
+ ret += role + ': ' + message + self.sep
86
+ else:
87
+ ret += role + ': ' # must be end with a space
88
+ return ret
89
+ elif self.sep_style == SeparatorStyle.ADD_NEW_LINE_SINGLE:
90
+ ret = '' if system_prompt == '' else system_prompt + self.sep
91
+ for role, message in self.messages:
92
+ if message:
93
+ ret += role + '\n' + message + self.sep
94
+ else:
95
+ ret += role + '\n'
96
+ return ret
97
+ elif self.sep_style == SeparatorStyle.NO_COLON_SINGLE:
98
+ ret = system_prompt
99
+ for role, message in self.messages:
100
+ if message:
101
+ ret += role + message + self.sep
102
+ else:
103
+ ret += role
104
+ return ret
105
+ elif self.sep_style == SeparatorStyle.NO_COLON_TWO:
106
+ seps = [self.sep, self.sep2]
107
+ ret = system_prompt
108
+ for i, (role, message) in enumerate(self.messages):
109
+ if message:
110
+ ret += role + message + seps[i % 2]
111
+ else:
112
+ ret += role
113
+ return ret
114
+ elif self.sep_style == SeparatorStyle.RWKV:
115
+ ret = system_prompt
116
+ for i, (role, message) in enumerate(self.messages):
117
+ if message:
118
+ ret += (
119
+ role
120
+ + ': '
121
+ + message.replace('\r\n', '\n').replace('\n\n', '\n')
122
+ )
123
+ ret += '\n\n'
124
+ else:
125
+ ret += role + ':'
126
+ return ret
127
+ elif self.sep_style == SeparatorStyle.LLAMA2:
128
+ seps = [self.sep, self.sep2]
129
+ if self.system_message:
130
+ ret = system_prompt
131
+ else:
132
+ ret = '[INST] '
133
+ for i, (role, message) in enumerate(self.messages):
134
+ tag = self.roles[i % 2]
135
+ if message:
136
+ if i == 0:
137
+ ret += message + ' '
138
+ else:
139
+ ret += tag + ' ' + message + seps[i % 2]
140
+ else:
141
+ ret += tag
142
+ return ret
143
+ elif self.sep_style == SeparatorStyle.CHATGLM:
144
+ # source: https://huggingface.co/THUDM/chatglm-6b/blob/1d240ba371910e9282298d4592532d7f0f3e9f3e/modeling_chatglm.py#L1302-L1308
145
+ # source2: https://huggingface.co/THUDM/chatglm2-6b/blob/e186c891cf64310ac66ef10a87e6635fa6c2a579/modeling_chatglm.py#L926
146
+ round_add_n = 1 if self.name == 'chatglm2' else 0
147
+ if system_prompt:
148
+ ret = system_prompt + self.sep
149
+ else:
150
+ ret = ''
151
+
152
+ for i, (role, message) in enumerate(self.messages):
153
+ if i % 2 == 0:
154
+ ret += f'[Round {i//2 + round_add_n}]{self.sep}'
155
+
156
+ if message:
157
+ ret += f'{role}:{message}{self.sep}'
158
+ else:
159
+ ret += f'{role}:'
160
+ return ret
161
+ elif self.sep_style == SeparatorStyle.CHATML:
162
+ ret = '' if system_prompt == '' else system_prompt + self.sep + '\n'
163
+ for role, message in self.messages:
164
+ if message:
165
+ ret += role + '\n' + message + self.sep + '\n'
166
+ else:
167
+ ret += role + '\n'
168
+ return ret
169
+ elif self.sep_style == SeparatorStyle.CHATGLM3:
170
+ ret = ''
171
+ if self.system_message:
172
+ ret += system_prompt
173
+ for role, message in self.messages:
174
+ if message:
175
+ ret += role + '\n' + ' ' + message
176
+ else:
177
+ ret += role
178
+ return ret
179
+ elif self.sep_style == SeparatorStyle.CHATINTERN:
180
+ # source: https://huggingface.co/internlm/internlm-chat-7b-8k/blob/bd546fa984b4b0b86958f56bf37f94aa75ab8831/modeling_internlm.py#L771
181
+ seps = [self.sep, self.sep2]
182
+ ret = system_prompt
183
+ for i, (role, message) in enumerate(self.messages):
184
+ # if i % 2 == 0:
185
+ # ret += "<s>"
186
+ if message:
187
+ ret += role + ':' + message + seps[i % 2] + '\n'
188
+ else:
189
+ ret += role + ':'
190
+ return ret
191
+ elif self.sep_style == SeparatorStyle.DOLLY:
192
+ seps = [self.sep, self.sep2]
193
+ ret = system_prompt
194
+ for i, (role, message) in enumerate(self.messages):
195
+ if message:
196
+ ret += role + ':\n' + message + seps[i % 2]
197
+ if i % 2 == 1:
198
+ ret += '\n\n'
199
+ else:
200
+ ret += role + ':\n'
201
+ return ret
202
+ elif self.sep_style == SeparatorStyle.PHOENIX:
203
+ ret = system_prompt
204
+ for role, message in self.messages:
205
+ if message:
206
+ ret += role + ': ' + '<s>' + message + '</s>'
207
+ else:
208
+ ret += role + ': ' + '<s>'
209
+ return ret
210
+ elif self.sep_style == SeparatorStyle.ROBIN:
211
+ ret = system_prompt + self.sep
212
+ for role, message in self.messages:
213
+ if message:
214
+ ret += role + ':\n' + message + self.sep
215
+ else:
216
+ ret += role + ':\n'
217
+ return ret
218
+ elif self.sep_style == SeparatorStyle.FALCON_CHAT:
219
+ ret = ''
220
+ if self.system_message:
221
+ ret += system_prompt + self.sep
222
+ for role, message in self.messages:
223
+ if message:
224
+ ret += role + ': ' + message + self.sep
225
+ else:
226
+ ret += role + ':'
227
+
228
+ return ret
229
+ elif self.sep_style == SeparatorStyle.INTERNVL_ZH:
230
+ seps = [self.sep, self.sep2]
231
+ ret = self.system_message + seps[0]
232
+ for i, (role, message) in enumerate(self.messages):
233
+ if message:
234
+ ret += role + ': ' + message + seps[i % 2]
235
+ else:
236
+ ret += role + ':'
237
+ return ret
238
+ elif self.sep_style == SeparatorStyle.MPT:
239
+ ret = system_prompt + self.sep
240
+ for role, message in self.messages:
241
+ if message:
242
+ if type(message) is tuple:
243
+ message, _, _ = message
244
+ ret += role + message + self.sep
245
+ else:
246
+ ret += role
247
+ return ret
248
+ else:
249
+ raise ValueError(f'Invalid style: {self.sep_style}')
250
+
251
+ def set_system_message(self, system_message: str):
252
+ """Set the system message."""
253
+ self.system_message = system_message
254
+
255
+ def append_message(self, role: str, message: str):
256
+ """Append a new message."""
257
+ self.messages.append([role, message])
258
+
259
+ def update_last_message(self, message: str):
260
+ """Update the last output.
261
+
262
+ The last message is typically set to be None when constructing the prompt,
263
+ so we need to update it in-place after getting the response from a model.
264
+ """
265
+ self.messages[-1][1] = message
266
+
267
+ def to_gradio_chatbot(self):
268
+ """Convert the conversation to gradio chatbot format."""
269
+ ret = []
270
+ for i, (role, msg) in enumerate(self.messages[self.offset :]):
271
+ if i % 2 == 0:
272
+ ret.append([msg, None])
273
+ else:
274
+ ret[-1][-1] = msg
275
+ return ret
276
+
277
+ def to_openai_api_messages(self):
278
+ """Convert the conversation to OpenAI chat completion format."""
279
+ ret = [{'role': 'system', 'content': self.system_message}]
280
+
281
+ for i, (_, msg) in enumerate(self.messages[self.offset :]):
282
+ if i % 2 == 0:
283
+ ret.append({'role': 'user', 'content': msg})
284
+ else:
285
+ if msg is not None:
286
+ ret.append({'role': 'assistant', 'content': msg})
287
+ return ret
288
+
289
+ def copy(self):
290
+ return Conversation(
291
+ name=self.name,
292
+ system_template=self.system_template,
293
+ system_message=self.system_message,
294
+ roles=self.roles,
295
+ messages=[[x, y] for x, y in self.messages],
296
+ offset=self.offset,
297
+ sep_style=self.sep_style,
298
+ sep=self.sep,
299
+ sep2=self.sep2,
300
+ stop_str=self.stop_str,
301
+ stop_token_ids=self.stop_token_ids,
302
+ )
303
+
304
+ def dict(self):
305
+ return {
306
+ 'template_name': self.name,
307
+ 'system_message': self.system_message,
308
+ 'roles': self.roles,
309
+ 'messages': self.messages,
310
+ 'offset': self.offset,
311
+ }
312
+
313
+
314
+ # A global registry for all conversation templates
315
+ conv_templates: Dict[str, Conversation] = {}
316
+
317
+
318
+ def register_conv_template(template: Conversation, override: bool = False):
319
+ """Register a new conversation template."""
320
+ if not override:
321
+ assert (
322
+ template.name not in conv_templates
323
+ ), f'{template.name} has been registered.'
324
+
325
+ conv_templates[template.name] = template
326
+
327
+
328
+ def get_conv_template(name: str) -> Conversation:
329
+ """Get a conversation template."""
330
+ return conv_templates[name].copy()
331
+
332
+
333
+ # Both Hermes-2 and internlm2-chat are chatml-format conversation templates. The difference
334
+ # is that during training, the preprocessing function for the Hermes-2 template doesn't add
335
+ # <s> at the beginning of the tokenized sequence, while the internlm2-chat template does.
336
+ # Therefore, they are completely equivalent during inference.
337
+ register_conv_template(
338
+ Conversation(
339
+ name='Hermes-2',
340
+ system_template='<|im_start|>system\n{system_message}',
341
+ # note: The new system prompt was not used here to avoid changes in benchmark performance.
342
+ # system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室、清华大学及多家合作单位联合开发的多模态大语言模型。',
343
+ # system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
344
+ system_message='You are a Table Image to LaTeX/Markdown/HMTL Code converter.',
345
+ roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
346
+ sep_style=SeparatorStyle.MPT,
347
+ sep='<|im_end|>',
348
+ stop_token_ids=[
349
+ 2,
350
+ 6,
351
+ 7,
352
+ 8,
353
+ ],
354
+ stop_str='<|endoftext|>',
355
+ )
356
+ )
357
+
358
+
359
+ register_conv_template(
360
+ Conversation(
361
+ name='internlm2-chat',
362
+ system_template='<|im_start|>system\n{system_message}',
363
+ # note: The new system prompt was not used here to avoid changes in benchmark performance.
364
+ # system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室、清华大学及多家合作单位联合开发的多模态大语言模型。',
365
+ system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
366
+ roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
367
+ sep_style=SeparatorStyle.MPT,
368
+ sep='<|im_end|>',
369
+ stop_token_ids=[
370
+ 2,
371
+ 92543,
372
+ 92542
373
+ ]
374
+ )
375
+ )
376
+
377
+
378
+ register_conv_template(
379
+ Conversation(
380
+ name='phi3-chat',
381
+ system_template='<|system|>\n{system_message}',
382
+ # note: The new system prompt was not used here to avoid changes in benchmark performance.
383
+ # system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室、清华大学及多家合作单位联合开发的多模态大语言模型。',
384
+ system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
385
+ roles=('<|user|>\n', '<|assistant|>\n'),
386
+ sep_style=SeparatorStyle.MPT,
387
+ sep='<|end|>',
388
+ stop_token_ids=[
389
+ 2,
390
+ 32000,
391
+ 32007
392
+ ]
393
+ )
394
+ )
models/TabRec/StructEqTable/generation_config.json CHANGED
@@ -1,8 +1,8 @@
1
  {
2
  "_from_model_config": true,
3
- "decoder_start_token_id": 0,
4
- "eos_token_id": 1,
5
- "pad_token_id": 0,
6
- "transformers_version": "4.37.2",
7
- "use_cache": false
8
  }
 
1
  {
2
  "_from_model_config": true,
3
+ "eos_token_id": [
4
+ 151644,
5
+ 151645
6
+ ],
7
+ "transformers_version": "4.44.0.dev0"
8
  }
models/TabRec/StructEqTable/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
models/TabRec/StructEqTable/model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:66baeb5e3b8e13f7e30cdf998c6724af7a97e8a2a3c78ece70666b6e2af278ce
3
- size 1294046176
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e16caef36733e9f43421450f6d4d220017a40c4ac2e8a65f86407059a049c930
3
+ size 1876395376
models/TabRec/StructEqTable/modeling_intern_vit.py ADDED
@@ -0,0 +1,429 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # --------------------------------------------------------
2
+ # InternVL
3
+ # Copyright (c) 2024 OpenGVLab
4
+ # Licensed under The MIT License [see LICENSE for details]
5
+ # --------------------------------------------------------
6
+ from typing import Optional, Tuple, Union
7
+
8
+ import torch
9
+ import torch.nn.functional as F
10
+ import torch.utils.checkpoint
11
+ from einops import rearrange
12
+ from timm.models.layers import DropPath
13
+ from torch import nn
14
+ from transformers.activations import ACT2FN
15
+ from transformers.modeling_outputs import (BaseModelOutput,
16
+ BaseModelOutputWithPooling)
17
+ from transformers.modeling_utils import PreTrainedModel
18
+ from transformers.utils import logging
19
+
20
+ from .configuration_intern_vit import InternVisionConfig
21
+
22
+ try:
23
+ from flash_attn.bert_padding import pad_input, unpad_input
24
+ from flash_attn.flash_attn_interface import \
25
+ flash_attn_varlen_qkvpacked_func
26
+ has_flash_attn = True
27
+ except:
28
+ print('FlashAttention2 is not installed.')
29
+ has_flash_attn = False
30
+
31
+ logger = logging.get_logger(__name__)
32
+
33
+
34
+ class FlashAttention(nn.Module):
35
+ """Implement the scaled dot product attention with softmax.
36
+ Arguments
37
+ ---------
38
+ softmax_scale: The temperature to use for the softmax attention.
39
+ (default: 1/sqrt(d_keys) where d_keys is computed at
40
+ runtime)
41
+ attention_dropout: The dropout rate to apply to the attention
42
+ (default: 0.0)
43
+ """
44
+
45
+ def __init__(self, softmax_scale=None, attention_dropout=0.0, device=None, dtype=None):
46
+ super().__init__()
47
+ self.softmax_scale = softmax_scale
48
+ self.dropout_p = attention_dropout
49
+
50
+ def forward(self, qkv, key_padding_mask=None, causal=False, cu_seqlens=None,
51
+ max_s=None, need_weights=False):
52
+ """Implements the multihead softmax attention.
53
+ Arguments
54
+ ---------
55
+ qkv: The tensor containing the query, key, and value. (B, S, 3, H, D) if key_padding_mask is None
56
+ if unpadded: (nnz, 3, h, d)
57
+ key_padding_mask: a bool tensor of shape (B, S)
58
+ """
59
+ assert not need_weights
60
+ assert qkv.dtype in [torch.float16, torch.bfloat16]
61
+ assert qkv.is_cuda
62
+
63
+ if cu_seqlens is None:
64
+ batch_size = qkv.shape[0]
65
+ seqlen = qkv.shape[1]
66
+ if key_padding_mask is None:
67
+ qkv = rearrange(qkv, 'b s ... -> (b s) ...')
68
+ max_s = seqlen
69
+ cu_seqlens = torch.arange(0, (batch_size + 1) * seqlen, step=seqlen, dtype=torch.int32,
70
+ device=qkv.device)
71
+ output = flash_attn_varlen_qkvpacked_func(
72
+ qkv, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,
73
+ softmax_scale=self.softmax_scale, causal=causal
74
+ )
75
+ output = rearrange(output, '(b s) ... -> b s ...', b=batch_size)
76
+ else:
77
+ nheads = qkv.shape[-2]
78
+ x = rearrange(qkv, 'b s three h d -> b s (three h d)')
79
+ x_unpad, indices, cu_seqlens, max_s = unpad_input(x, key_padding_mask)
80
+ x_unpad = rearrange(x_unpad, 'nnz (three h d) -> nnz three h d', three=3, h=nheads)
81
+ output_unpad = flash_attn_varlen_qkvpacked_func(
82
+ x_unpad, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,
83
+ softmax_scale=self.softmax_scale, causal=causal
84
+ )
85
+ output = rearrange(pad_input(rearrange(output_unpad, 'nnz h d -> nnz (h d)'),
86
+ indices, batch_size, seqlen),
87
+ 'b s (h d) -> b s h d', h=nheads)
88
+ else:
89
+ assert max_s is not None
90
+ output = flash_attn_varlen_qkvpacked_func(
91
+ qkv, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,
92
+ softmax_scale=self.softmax_scale, causal=causal
93
+ )
94
+
95
+ return output, None
96
+
97
+
98
+ class InternRMSNorm(nn.Module):
99
+ def __init__(self, hidden_size, eps=1e-6):
100
+ super().__init__()
101
+ self.weight = nn.Parameter(torch.ones(hidden_size))
102
+ self.variance_epsilon = eps
103
+
104
+ def forward(self, hidden_states):
105
+ input_dtype = hidden_states.dtype
106
+ hidden_states = hidden_states.to(torch.float32)
107
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
108
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
109
+ return self.weight * hidden_states.to(input_dtype)
110
+
111
+
112
+ try:
113
+ from apex.normalization import FusedRMSNorm
114
+
115
+ InternRMSNorm = FusedRMSNorm # noqa
116
+
117
+ logger.info('Discovered apex.normalization.FusedRMSNorm - will use it instead of InternRMSNorm')
118
+ except ImportError:
119
+ # using the normal InternRMSNorm
120
+ pass
121
+ except Exception:
122
+ logger.warning('discovered apex but it failed to load, falling back to InternRMSNorm')
123
+ pass
124
+
125
+
126
+ NORM2FN = {
127
+ 'rms_norm': InternRMSNorm,
128
+ 'layer_norm': nn.LayerNorm,
129
+ }
130
+
131
+
132
+ class InternVisionEmbeddings(nn.Module):
133
+ def __init__(self, config: InternVisionConfig):
134
+ super().__init__()
135
+ self.config = config
136
+ self.embed_dim = config.hidden_size
137
+ self.image_size = config.image_size
138
+ self.patch_size = config.patch_size
139
+
140
+ self.class_embedding = nn.Parameter(
141
+ torch.randn(1, 1, self.embed_dim),
142
+ )
143
+
144
+ self.patch_embedding = nn.Conv2d(
145
+ in_channels=3, out_channels=self.embed_dim, kernel_size=self.patch_size, stride=self.patch_size
146
+ )
147
+
148
+ self.num_patches = (self.image_size // self.patch_size) ** 2
149
+ self.num_positions = self.num_patches + 1
150
+
151
+ self.position_embedding = nn.Parameter(torch.randn(1, self.num_positions, self.embed_dim))
152
+
153
+ def _get_pos_embed(self, pos_embed, H, W):
154
+ target_dtype = pos_embed.dtype
155
+ pos_embed = pos_embed.float().reshape(
156
+ 1, self.image_size // self.patch_size, self.image_size // self.patch_size, -1).permute(0, 3, 1, 2)
157
+ pos_embed = F.interpolate(pos_embed, size=(H, W), mode='bicubic', align_corners=False). \
158
+ reshape(1, -1, H * W).permute(0, 2, 1).to(target_dtype)
159
+ return pos_embed
160
+
161
+ def forward(self, pixel_values: torch.FloatTensor) -> torch.Tensor:
162
+ target_dtype = self.patch_embedding.weight.dtype
163
+ patch_embeds = self.patch_embedding(pixel_values) # shape = [*, channel, width, height]
164
+ batch_size, _, height, width = patch_embeds.shape
165
+ patch_embeds = patch_embeds.flatten(2).transpose(1, 2)
166
+ class_embeds = self.class_embedding.expand(batch_size, 1, -1).to(target_dtype)
167
+ embeddings = torch.cat([class_embeds, patch_embeds], dim=1)
168
+ position_embedding = torch.cat([
169
+ self.position_embedding[:, :1, :],
170
+ self._get_pos_embed(self.position_embedding[:, 1:, :], height, width)
171
+ ], dim=1)
172
+ embeddings = embeddings + position_embedding.to(target_dtype)
173
+ return embeddings
174
+
175
+
176
+ class InternAttention(nn.Module):
177
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
178
+
179
+ def __init__(self, config: InternVisionConfig):
180
+ super().__init__()
181
+ self.config = config
182
+ self.embed_dim = config.hidden_size
183
+ self.num_heads = config.num_attention_heads
184
+ self.use_flash_attn = config.use_flash_attn and has_flash_attn
185
+ if config.use_flash_attn and not has_flash_attn:
186
+ print('Warning: Flash Attention is not available, use_flash_attn is set to False.')
187
+ self.head_dim = self.embed_dim // self.num_heads
188
+ if self.head_dim * self.num_heads != self.embed_dim:
189
+ raise ValueError(
190
+ f'embed_dim must be divisible by num_heads (got `embed_dim`: {self.embed_dim} and `num_heads`:'
191
+ f' {self.num_heads}).'
192
+ )
193
+
194
+ self.scale = self.head_dim ** -0.5
195
+ self.qkv = nn.Linear(self.embed_dim, 3 * self.embed_dim, bias=config.qkv_bias)
196
+ self.attn_drop = nn.Dropout(config.attention_dropout)
197
+ self.proj_drop = nn.Dropout(config.dropout)
198
+
199
+ self.qk_normalization = config.qk_normalization
200
+
201
+ if self.qk_normalization:
202
+ self.q_norm = InternRMSNorm(self.embed_dim, eps=config.layer_norm_eps)
203
+ self.k_norm = InternRMSNorm(self.embed_dim, eps=config.layer_norm_eps)
204
+
205
+ if self.use_flash_attn:
206
+ self.inner_attn = FlashAttention(attention_dropout=config.attention_dropout)
207
+ self.proj = nn.Linear(self.embed_dim, self.embed_dim)
208
+
209
+ def _naive_attn(self, x):
210
+ B, N, C = x.shape
211
+ qkv = self.qkv(x).reshape(B, N, 3, self.num_heads, C // self.num_heads).permute(2, 0, 3, 1, 4)
212
+ q, k, v = qkv.unbind(0) # make torchscript happy (cannot use tensor as tuple)
213
+
214
+ if self.qk_normalization:
215
+ B_, H_, N_, D_ = q.shape
216
+ q = self.q_norm(q.transpose(1, 2).flatten(-2, -1)).view(B_, N_, H_, D_).transpose(1, 2)
217
+ k = self.k_norm(k.transpose(1, 2).flatten(-2, -1)).view(B_, N_, H_, D_).transpose(1, 2)
218
+
219
+ attn = ((q * self.scale) @ k.transpose(-2, -1))
220
+ attn = attn.softmax(dim=-1)
221
+ attn = self.attn_drop(attn)
222
+
223
+ x = (attn @ v).transpose(1, 2).reshape(B, N, C)
224
+ x = self.proj(x)
225
+ x = self.proj_drop(x)
226
+ return x
227
+
228
+ def _flash_attn(self, x, key_padding_mask=None, need_weights=False):
229
+ qkv = self.qkv(x)
230
+ qkv = rearrange(qkv, 'b s (three h d) -> b s three h d', three=3, h=self.num_heads)
231
+
232
+ if self.qk_normalization:
233
+ q, k, v = qkv.unbind(2)
234
+ q = self.q_norm(q.flatten(-2, -1)).view(q.shape)
235
+ k = self.k_norm(k.flatten(-2, -1)).view(k.shape)
236
+ qkv = torch.stack([q, k, v], dim=2)
237
+
238
+ context, _ = self.inner_attn(
239
+ qkv, key_padding_mask=key_padding_mask, need_weights=need_weights, causal=False
240
+ )
241
+ outs = self.proj(rearrange(context, 'b s h d -> b s (h d)'))
242
+ outs = self.proj_drop(outs)
243
+ return outs
244
+
245
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
246
+ x = self._naive_attn(hidden_states) if not self.use_flash_attn else self._flash_attn(hidden_states)
247
+ return x
248
+
249
+
250
+ class InternMLP(nn.Module):
251
+ def __init__(self, config: InternVisionConfig):
252
+ super().__init__()
253
+ self.config = config
254
+ self.act = ACT2FN[config.hidden_act]
255
+ self.fc1 = nn.Linear(config.hidden_size, config.intermediate_size)
256
+ self.fc2 = nn.Linear(config.intermediate_size, config.hidden_size)
257
+
258
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
259
+ hidden_states = self.fc1(hidden_states)
260
+ hidden_states = self.act(hidden_states)
261
+ hidden_states = self.fc2(hidden_states)
262
+ return hidden_states
263
+
264
+
265
+ class InternVisionEncoderLayer(nn.Module):
266
+ def __init__(self, config: InternVisionConfig, drop_path_rate: float):
267
+ super().__init__()
268
+ self.embed_dim = config.hidden_size
269
+ self.intermediate_size = config.intermediate_size
270
+ self.norm_type = config.norm_type
271
+
272
+ self.attn = InternAttention(config)
273
+ self.mlp = InternMLP(config)
274
+ self.norm1 = NORM2FN[self.norm_type](self.embed_dim, eps=config.layer_norm_eps)
275
+ self.norm2 = NORM2FN[self.norm_type](self.embed_dim, eps=config.layer_norm_eps)
276
+
277
+ self.ls1 = nn.Parameter(config.initializer_factor * torch.ones(self.embed_dim))
278
+ self.ls2 = nn.Parameter(config.initializer_factor * torch.ones(self.embed_dim))
279
+ self.drop_path1 = DropPath(drop_path_rate) if drop_path_rate > 0. else nn.Identity()
280
+ self.drop_path2 = DropPath(drop_path_rate) if drop_path_rate > 0. else nn.Identity()
281
+
282
+ def forward(
283
+ self,
284
+ hidden_states: torch.Tensor,
285
+ ) -> Tuple[torch.FloatTensor, Optional[torch.FloatTensor], Optional[Tuple[torch.FloatTensor]]]:
286
+ """
287
+ Args:
288
+ hidden_states (`Tuple[torch.FloatTensor, Optional[torch.FloatTensor]]`): input to the layer of shape `(batch, seq_len, embed_dim)`
289
+ """
290
+ hidden_states = hidden_states + self.drop_path1(self.attn(self.norm1(hidden_states).to(hidden_states.dtype)) * self.ls1)
291
+
292
+ hidden_states = hidden_states + self.drop_path2(self.mlp(self.norm2(hidden_states).to(hidden_states.dtype)) * self.ls2)
293
+
294
+ return hidden_states
295
+
296
+
297
+ class InternVisionEncoder(nn.Module):
298
+ """
299
+ Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
300
+ [`InternEncoderLayer`].
301
+
302
+ Args:
303
+ config (`InternConfig`):
304
+ The corresponding vision configuration for the `InternEncoder`.
305
+ """
306
+
307
+ def __init__(self, config: InternVisionConfig):
308
+ super().__init__()
309
+ self.config = config
310
+ # stochastic depth decay rule
311
+ dpr = [x.item() for x in torch.linspace(0, config.drop_path_rate, config.num_hidden_layers)]
312
+ self.layers = nn.ModuleList([
313
+ InternVisionEncoderLayer(config, dpr[idx]) for idx in range(config.num_hidden_layers)])
314
+ self.gradient_checkpointing = True
315
+
316
+ def forward(
317
+ self,
318
+ inputs_embeds,
319
+ output_hidden_states: Optional[bool] = None,
320
+ return_dict: Optional[bool] = None,
321
+ ) -> Union[Tuple, BaseModelOutput]:
322
+ r"""
323
+ Args:
324
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
325
+ Embedded representation of the inputs. Should be float, not int tokens.
326
+ output_hidden_states (`bool`, *optional*):
327
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
328
+ for more detail.
329
+ return_dict (`bool`, *optional*):
330
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
331
+ """
332
+ output_hidden_states = (
333
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
334
+ )
335
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
336
+
337
+ encoder_states = () if output_hidden_states else None
338
+ hidden_states = inputs_embeds
339
+
340
+ for idx, encoder_layer in enumerate(self.layers):
341
+ if output_hidden_states:
342
+ encoder_states = encoder_states + (hidden_states,)
343
+ if self.gradient_checkpointing and self.training:
344
+ layer_outputs = torch.utils.checkpoint.checkpoint(
345
+ encoder_layer,
346
+ hidden_states)
347
+ else:
348
+ layer_outputs = encoder_layer(
349
+ hidden_states,
350
+ )
351
+ hidden_states = layer_outputs
352
+
353
+ if output_hidden_states:
354
+ encoder_states = encoder_states + (hidden_states,)
355
+
356
+ if not return_dict:
357
+ return tuple(v for v in [hidden_states, encoder_states] if v is not None)
358
+ return BaseModelOutput(
359
+ last_hidden_state=hidden_states, hidden_states=encoder_states
360
+ )
361
+
362
+
363
+ class InternVisionModel(PreTrainedModel):
364
+ main_input_name = 'pixel_values'
365
+ _supports_flash_attn_2 = True
366
+ config_class = InternVisionConfig
367
+ _no_split_modules = ['InternVisionEncoderLayer']
368
+
369
+ def __init__(self, config: InternVisionConfig):
370
+ super().__init__(config)
371
+ self.config = config
372
+
373
+ self.embeddings = InternVisionEmbeddings(config)
374
+ self.encoder = InternVisionEncoder(config)
375
+
376
+ def resize_pos_embeddings(self, old_size, new_size, patch_size):
377
+ pos_emb = self.embeddings.position_embedding
378
+ _, num_positions, embed_dim = pos_emb.shape
379
+ cls_emb = pos_emb[:, :1, :]
380
+ pos_emb = pos_emb[:, 1:, :].reshape(1, old_size // patch_size, old_size // patch_size, -1).permute(0, 3, 1, 2)
381
+ pos_emb = F.interpolate(pos_emb.float(), size=new_size // patch_size, mode='bicubic', align_corners=False)
382
+ pos_emb = pos_emb.to(cls_emb.dtype).reshape(1, embed_dim, -1).permute(0, 2, 1)
383
+ pos_emb = torch.cat([cls_emb, pos_emb], dim=1)
384
+ self.embeddings.position_embedding = nn.Parameter(pos_emb)
385
+ self.embeddings.image_size = new_size
386
+ logger.info('Resized position embeddings from {} to {}'.format(old_size, new_size))
387
+
388
+ def get_input_embeddings(self):
389
+ return self.embeddings
390
+
391
+ def forward(
392
+ self,
393
+ pixel_values: Optional[torch.FloatTensor] = None,
394
+ output_hidden_states: Optional[bool] = None,
395
+ return_dict: Optional[bool] = None,
396
+ pixel_embeds: Optional[torch.FloatTensor] = None,
397
+ ) -> Union[Tuple, BaseModelOutputWithPooling]:
398
+ output_hidden_states = (
399
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
400
+ )
401
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
402
+
403
+ if pixel_values is None and pixel_embeds is None:
404
+ raise ValueError('You have to specify pixel_values or pixel_embeds')
405
+
406
+ if pixel_embeds is not None:
407
+ hidden_states = pixel_embeds
408
+ else:
409
+ if len(pixel_values.shape) == 4:
410
+ hidden_states = self.embeddings(pixel_values)
411
+ else:
412
+ raise ValueError(f'wrong pixel_values size: {pixel_values.shape}')
413
+ encoder_outputs = self.encoder(
414
+ inputs_embeds=hidden_states,
415
+ output_hidden_states=output_hidden_states,
416
+ return_dict=return_dict,
417
+ )
418
+ last_hidden_state = encoder_outputs.last_hidden_state
419
+ pooled_output = last_hidden_state[:, 0, :]
420
+
421
+ if not return_dict:
422
+ return (last_hidden_state, pooled_output) + encoder_outputs[1:]
423
+
424
+ return BaseModelOutputWithPooling(
425
+ last_hidden_state=last_hidden_state,
426
+ pooler_output=pooled_output,
427
+ hidden_states=encoder_outputs.hidden_states,
428
+ attentions=encoder_outputs.attentions,
429
+ )
models/TabRec/StructEqTable/modeling_internvl_chat.py ADDED
@@ -0,0 +1,355 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # --------------------------------------------------------
2
+ # InternVL
3
+ # Copyright (c) 2024 OpenGVLab
4
+ # Licensed under The MIT License [see LICENSE for details]
5
+ # --------------------------------------------------------
6
+ import warnings
7
+ from typing import Any, List, Optional, Tuple, Union
8
+
9
+ import torch.utils.checkpoint
10
+ import transformers
11
+ from torch import nn
12
+ from torch.nn import CrossEntropyLoss
13
+ from transformers import (AutoModel, GenerationConfig, LlamaForCausalLM,
14
+ Qwen2ForCausalLM)
15
+ from transformers.modeling_outputs import CausalLMOutputWithPast
16
+ from transformers.modeling_utils import PreTrainedModel
17
+ from transformers.utils import ModelOutput, logging
18
+
19
+ from .configuration_internvl_chat import InternVLChatConfig
20
+ from .conversation import get_conv_template
21
+ from .modeling_intern_vit import InternVisionModel, has_flash_attn
22
+
23
+ logger = logging.get_logger(__name__)
24
+
25
+
26
+ def version_cmp(v1, v2, op='eq'):
27
+ import operator
28
+
29
+ from packaging import version
30
+ op_func = getattr(operator, op)
31
+ return op_func(version.parse(v1), version.parse(v2))
32
+
33
+
34
+ class InternVLChatModel(PreTrainedModel):
35
+ config_class = InternVLChatConfig
36
+ main_input_name = 'pixel_values'
37
+ _supports_flash_attn_2 = True
38
+ _no_split_modules = ['InternVisionModel', 'LlamaDecoderLayer', 'Qwen2DecoderLayer']
39
+
40
+ def __init__(self, config: InternVLChatConfig, vision_model=None, language_model=None, use_flash_attn=True):
41
+ super().__init__(config)
42
+
43
+ assert version_cmp(transformers.__version__, '4.37.0', 'ge')
44
+ image_size = config.force_image_size or config.vision_config.image_size
45
+ patch_size = config.vision_config.patch_size
46
+ self.patch_size = patch_size
47
+ self.select_layer = config.select_layer
48
+ self.template = config.template
49
+ self.num_image_token = int((image_size // patch_size) ** 2 * (config.downsample_ratio ** 2))
50
+ self.downsample_ratio = config.downsample_ratio
51
+ self.ps_version = config.ps_version
52
+ use_flash_attn = use_flash_attn if has_flash_attn else False
53
+ config.vision_config.use_flash_attn = True if use_flash_attn else False
54
+ config.llm_config._attn_implementation = 'flash_attention_2' if use_flash_attn else 'eager'
55
+
56
+ logger.info(f'num_image_token: {self.num_image_token}')
57
+ logger.info(f'ps_version: {self.ps_version}')
58
+ if vision_model is not None:
59
+ self.vision_model = vision_model
60
+ else:
61
+ self.vision_model = InternVisionModel(config.vision_config)
62
+ if language_model is not None:
63
+ self.language_model = language_model
64
+ else:
65
+ if config.llm_config.architectures[0] == 'LlamaForCausalLM':
66
+ self.language_model = LlamaForCausalLM(config.llm_config)
67
+ elif config.llm_config.architectures[0] == 'Qwen2ForCausalLM':
68
+ self.language_model = Qwen2ForCausalLM(config.llm_config)
69
+ else:
70
+ raise NotImplementedError(f'{config.llm_config.architectures[0]} is not implemented.')
71
+
72
+ vit_hidden_size = config.vision_config.hidden_size
73
+ llm_hidden_size = config.llm_config.hidden_size
74
+
75
+ self.mlp1 = nn.Sequential(
76
+ nn.LayerNorm(vit_hidden_size * int(1 / self.downsample_ratio) ** 2),
77
+ nn.Linear(vit_hidden_size * int(1 / self.downsample_ratio) ** 2, llm_hidden_size),
78
+ nn.GELU(),
79
+ nn.Linear(llm_hidden_size, llm_hidden_size)
80
+ )
81
+
82
+ self.img_context_token_id = 151648
83
+ self.conv_template = get_conv_template(self.template)
84
+ self.system_message = self.conv_template.system_message
85
+
86
+ def forward(
87
+ self,
88
+ pixel_values: torch.FloatTensor,
89
+ input_ids: torch.LongTensor = None,
90
+ attention_mask: Optional[torch.Tensor] = None,
91
+ position_ids: Optional[torch.LongTensor] = None,
92
+ image_flags: Optional[torch.LongTensor] = None,
93
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
94
+ labels: Optional[torch.LongTensor] = None,
95
+ use_cache: Optional[bool] = None,
96
+ output_attentions: Optional[bool] = None,
97
+ output_hidden_states: Optional[bool] = None,
98
+ return_dict: Optional[bool] = None,
99
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
100
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
101
+
102
+ image_flags = image_flags.squeeze(0)
103
+ pixel_values = pixel_values.squeeze(0)
104
+
105
+ input_embeds = self.language_model.get_input_embeddings()(input_ids)
106
+
107
+ vit_embeds = self.extract_feature(pixel_values)
108
+ vit_embeds = vit_embeds[image_flags == 1]
109
+ vit_batch_size = pixel_values.shape[0]
110
+
111
+ B, N, C = input_embeds.shape
112
+ input_embeds = input_embeds.reshape(B * N, C)
113
+
114
+ # if torch.distributed.get_rank() == 0:
115
+ # print(f'dynamic ViT batch size: {vit_batch_size}, images per sample: {vit_batch_size / B}, dynamic token length: {N}')
116
+
117
+ input_ids = input_ids.reshape(B * N)
118
+ selected = (input_ids == self.img_context_token_id)
119
+
120
+ try:
121
+ input_embeds[selected] = input_embeds[selected] * 0.0 + vit_embeds.reshape(-1, C)
122
+ except Exception as e:
123
+ vit_embeds = vit_embeds.reshape(-1, C)
124
+ print(f'warning: {e}, input_embeds[selected].shape={input_embeds[selected].shape}, '
125
+ f'vit_embeds.shape={vit_embeds.shape}')
126
+ n_token = selected.sum()
127
+ input_embeds[selected] = input_embeds[selected] * 0.0 + vit_embeds[:n_token]
128
+
129
+ input_embeds = input_embeds.reshape(B, N, C)
130
+
131
+ outputs = self.language_model(
132
+ inputs_embeds=input_embeds,
133
+ attention_mask=attention_mask,
134
+ position_ids=position_ids,
135
+ past_key_values=past_key_values,
136
+ use_cache=use_cache,
137
+ output_attentions=output_attentions,
138
+ output_hidden_states=output_hidden_states,
139
+ return_dict=return_dict,
140
+ )
141
+ logits = outputs.logits
142
+
143
+ loss = None
144
+ if labels is not None:
145
+ # Shift so that tokens < n predict n
146
+ shift_logits = logits[..., :-1, :].contiguous()
147
+ shift_labels = labels[..., 1:].contiguous()
148
+ # Flatten the tokens
149
+ loss_fct = CrossEntropyLoss()
150
+ shift_logits = shift_logits.view(-1, self.language_model.config.vocab_size)
151
+ shift_labels = shift_labels.view(-1)
152
+ # Enable model parallelism
153
+ shift_labels = shift_labels.to(shift_logits.device)
154
+ loss = loss_fct(shift_logits, shift_labels)
155
+
156
+ if not return_dict:
157
+ output = (logits,) + outputs[1:]
158
+ return (loss,) + output if loss is not None else output
159
+
160
+ return CausalLMOutputWithPast(
161
+ loss=loss,
162
+ logits=logits,
163
+ past_key_values=outputs.past_key_values,
164
+ hidden_states=outputs.hidden_states,
165
+ attentions=outputs.attentions,
166
+ )
167
+
168
+ def pixel_shuffle(self, x, scale_factor=0.5):
169
+ n, w, h, c = x.size()
170
+ # N, W, H, C --> N, W, H * scale, C // scale
171
+ x = x.view(n, w, int(h * scale_factor), int(c / scale_factor))
172
+ # N, W, H * scale, C // scale --> N, H * scale, W, C // scale
173
+ x = x.permute(0, 2, 1, 3).contiguous()
174
+ # N, H * scale, W, C // scale --> N, H * scale, W * scale, C // (scale ** 2)
175
+ x = x.view(n, int(h * scale_factor), int(w * scale_factor),
176
+ int(c / (scale_factor * scale_factor)))
177
+ if self.ps_version == 'v1':
178
+ warnings.warn("In ps_version 'v1', the height and width have not been swapped back, "
179
+ 'which results in a transposed image.')
180
+ else:
181
+ x = x.permute(0, 2, 1, 3).contiguous()
182
+ return x
183
+
184
+ def extract_feature(self, pixel_values):
185
+ if self.select_layer == -1:
186
+ vit_embeds = self.vision_model(
187
+ pixel_values=pixel_values,
188
+ output_hidden_states=False,
189
+ return_dict=True).last_hidden_state
190
+ else:
191
+ vit_embeds = self.vision_model(
192
+ pixel_values=pixel_values,
193
+ output_hidden_states=True,
194
+ return_dict=True).hidden_states[self.select_layer]
195
+ vit_embeds = vit_embeds[:, 1:, :]
196
+
197
+ h = w = int(vit_embeds.shape[1] ** 0.5)
198
+ vit_embeds = vit_embeds.reshape(vit_embeds.shape[0], h, w, -1)
199
+ vit_embeds = self.pixel_shuffle(vit_embeds, scale_factor=self.downsample_ratio)
200
+ vit_embeds = vit_embeds.reshape(vit_embeds.shape[0], -1, vit_embeds.shape[-1])
201
+ vit_embeds = self.mlp1(vit_embeds)
202
+ return vit_embeds
203
+
204
+ def batch_chat(self, tokenizer, pixel_values, questions, generation_config, num_patches_list=None,
205
+ history=None, return_history=False, IMG_START_TOKEN='<img>', IMG_END_TOKEN='</img>',
206
+ IMG_CONTEXT_TOKEN='<IMG_CONTEXT>', verbose=False, image_counts=None):
207
+ if history is not None or return_history:
208
+ print('Now multi-turn chat is not supported in batch_chat.')
209
+ raise NotImplementedError
210
+
211
+ if image_counts is not None:
212
+ num_patches_list = image_counts
213
+ print('Warning: `image_counts` is deprecated. Please use `num_patches_list` instead.')
214
+
215
+ img_context_token_id = tokenizer.convert_tokens_to_ids(IMG_CONTEXT_TOKEN)
216
+ self.img_context_token_id = img_context_token_id
217
+
218
+ if verbose and pixel_values is not None:
219
+ image_bs = pixel_values.shape[0]
220
+ print(f'dynamic ViT batch size: {image_bs}')
221
+
222
+ queries = []
223
+ for idx, num_patches in enumerate(num_patches_list):
224
+ question = questions[idx]
225
+ if pixel_values is not None and '<image>' not in question:
226
+ question = '<image>\n' + question
227
+ template = get_conv_template(self.template)
228
+ template.system_message = self.system_message
229
+ template.append_message(template.roles[0], question)
230
+ template.append_message(template.roles[1], None)
231
+ query = template.get_prompt()
232
+
233
+ image_tokens = IMG_START_TOKEN + IMG_CONTEXT_TOKEN * self.num_image_token * num_patches + IMG_END_TOKEN
234
+ query = query.replace('<image>', image_tokens, 1)
235
+ queries.append(query)
236
+
237
+ tokenizer.padding_side = 'left'
238
+ model_inputs = tokenizer(queries, return_tensors='pt', padding=True)
239
+ input_ids = model_inputs['input_ids'].cuda()
240
+ attention_mask = model_inputs['attention_mask'].cuda()
241
+ eos_token_id = tokenizer.convert_tokens_to_ids(template.sep)
242
+ generation_config['eos_token_id'] = eos_token_id
243
+ generation_output = self.generate(
244
+ pixel_values=pixel_values,
245
+ input_ids=input_ids,
246
+ attention_mask=attention_mask,
247
+ **generation_config
248
+ )
249
+ responses = tokenizer.batch_decode(generation_output, skip_special_tokens=True)
250
+ responses = [response.split(template.sep)[0].strip() for response in responses]
251
+ return responses
252
+
253
+ def chat(self, tokenizer, pixel_values, question, generation_config, history=None, return_history=False,
254
+ num_patches_list=None, IMG_START_TOKEN='<img>', IMG_END_TOKEN='</img>', IMG_CONTEXT_TOKEN='<IMG_CONTEXT>',
255
+ verbose=False):
256
+
257
+ if history is None and pixel_values is not None and '<image>' not in question:
258
+ question = '<image>\n' + question
259
+
260
+ if num_patches_list is None:
261
+ num_patches_list = [pixel_values.shape[0]] if pixel_values is not None else []
262
+ assert pixel_values is None or len(pixel_values) == sum(num_patches_list)
263
+
264
+ img_context_token_id = tokenizer.convert_tokens_to_ids(IMG_CONTEXT_TOKEN)
265
+ self.img_context_token_id = img_context_token_id
266
+
267
+ template = get_conv_template(self.template)
268
+ template.system_message = self.system_message
269
+ eos_token_id = tokenizer.convert_tokens_to_ids(template.sep)
270
+
271
+ history = [] if history is None else history
272
+ for (old_question, old_answer) in history:
273
+ template.append_message(template.roles[0], old_question)
274
+ template.append_message(template.roles[1], old_answer)
275
+ template.append_message(template.roles[0], question)
276
+ template.append_message(template.roles[1], None)
277
+ query = template.get_prompt()
278
+
279
+ if verbose and pixel_values is not None:
280
+ image_bs = pixel_values.shape[0]
281
+ print(f'dynamic ViT batch size: {image_bs}')
282
+
283
+ for num_patches in num_patches_list:
284
+ image_tokens = IMG_START_TOKEN + IMG_CONTEXT_TOKEN * self.num_image_token * num_patches + IMG_END_TOKEN
285
+ query = query.replace('<image>', image_tokens, 1)
286
+
287
+ model_inputs = tokenizer(query, return_tensors='pt')
288
+ input_ids = model_inputs['input_ids'].cuda()
289
+ attention_mask = model_inputs['attention_mask'].cuda()
290
+ generation_config['eos_token_id'] = eos_token_id
291
+
292
+ generation_output = self.generate(
293
+ pixel_values=pixel_values,
294
+ input_ids=input_ids,
295
+ attention_mask=attention_mask,
296
+ **generation_config
297
+ )
298
+ response = tokenizer.batch_decode(generation_output, skip_special_tokens=True)[0]
299
+ response = response.split(template.sep)[0].strip()
300
+ history.append((question, response))
301
+ if return_history:
302
+ return response, history
303
+ else:
304
+ query_to_print = query.replace(IMG_CONTEXT_TOKEN, '')
305
+ query_to_print = query_to_print.replace(f'{IMG_START_TOKEN}{IMG_END_TOKEN}', '<image>')
306
+ if verbose:
307
+ print(query_to_print, response)
308
+ return response
309
+
310
+ @torch.no_grad()
311
+ def generate(
312
+ self,
313
+ pixel_values: Optional[torch.FloatTensor] = None,
314
+ input_ids: Optional[torch.FloatTensor] = None,
315
+ attention_mask: Optional[torch.LongTensor] = None,
316
+ visual_features: Optional[torch.FloatTensor] = None,
317
+ generation_config: Optional[GenerationConfig] = None,
318
+ output_hidden_states: Optional[bool] = None,
319
+ return_dict: Optional[bool] = None,
320
+ img_context_token_id: Optional[bool] = None,
321
+ **generate_kwargs,
322
+ ) -> torch.LongTensor:
323
+ if img_context_token_id is not None:
324
+ self.img_context_token_id = img_context_token_id
325
+
326
+ assert self.img_context_token_id is not None
327
+ if pixel_values is not None:
328
+ if visual_features is not None:
329
+ vit_embeds = visual_features
330
+ else:
331
+ vit_embeds = self.extract_feature(pixel_values)
332
+ input_embeds = self.language_model.get_input_embeddings()(input_ids)
333
+ B, N, C = input_embeds.shape
334
+ input_embeds = input_embeds.reshape(B * N, C)
335
+
336
+ input_ids = input_ids.reshape(B * N)
337
+ selected = (input_ids == self.img_context_token_id)
338
+ assert selected.sum() != 0
339
+ input_embeds[selected] = vit_embeds.reshape(-1, C).to(input_embeds.device)
340
+
341
+ input_embeds = input_embeds.reshape(B, N, C)
342
+ else:
343
+ input_embeds = self.language_model.get_input_embeddings()(input_ids)
344
+
345
+ outputs = self.language_model.generate(
346
+ inputs_embeds=input_embeds,
347
+ attention_mask=attention_mask,
348
+ generation_config=generation_config,
349
+ output_hidden_states=output_hidden_states,
350
+ return_dict=return_dict,
351
+ use_cache=True,
352
+ **generate_kwargs,
353
+ )
354
+
355
+ return outputs
models/TabRec/StructEqTable/preprocessor_config.json CHANGED
@@ -1,12 +1,19 @@
1
  {
2
- "do_convert_rgb": true,
 
3
  "do_normalize": true,
4
- "image_processor_type": "Pix2StructImageProcessor",
5
- "is_vqa": false,
6
- "max_patches": 4096,
7
- "patch_size": {
8
- "height": 16,
9
- "width": 16
10
- },
11
- "processor_class": "Pix2StructProcessor"
 
 
 
 
 
 
12
  }
 
1
  {
2
+ "crop_size": 448,
3
+ "do_center_crop": true,
4
  "do_normalize": true,
5
+ "do_resize": true,
6
+ "feature_extractor_type": "CLIPFeatureExtractor",
7
+ "image_mean": [
8
+ 0.485,
9
+ 0.456,
10
+ 0.406
11
+ ],
12
+ "image_std": [
13
+ 0.229,
14
+ 0.224,
15
+ 0.225
16
+ ],
17
+ "resample": 3,
18
+ "size": 448
19
  }
models/TabRec/StructEqTable/special_tokens_map.json CHANGED
@@ -1,122 +1,26 @@
1
  {
2
  "additional_special_tokens": [
3
- "<extra_id_0>",
4
- "<extra_id_1>",
5
- "<extra_id_2>",
6
- "<extra_id_3>",
7
- "<extra_id_4>",
8
- "<extra_id_5>",
9
- "<extra_id_6>",
10
- "<extra_id_7>",
11
- "<extra_id_8>",
12
- "<extra_id_9>",
13
- "<extra_id_10>",
14
- "<extra_id_11>",
15
- "<extra_id_12>",
16
- "<extra_id_13>",
17
- "<extra_id_14>",
18
- "<extra_id_15>",
19
- "<extra_id_16>",
20
- "<extra_id_17>",
21
- "<extra_id_18>",
22
- "<extra_id_19>",
23
- "<extra_id_20>",
24
- "<extra_id_21>",
25
- "<extra_id_22>",
26
- "<extra_id_23>",
27
- "<extra_id_24>",
28
- "<extra_id_25>",
29
- "<extra_id_26>",
30
- "<extra_id_27>",
31
- "<extra_id_28>",
32
- "<extra_id_29>",
33
- "<extra_id_30>",
34
- "<extra_id_31>",
35
- "<extra_id_32>",
36
- "<extra_id_33>",
37
- "<extra_id_34>",
38
- "<extra_id_35>",
39
- "<extra_id_36>",
40
- "<extra_id_37>",
41
- "<extra_id_38>",
42
- "<extra_id_39>",
43
- "<extra_id_40>",
44
- "<extra_id_41>",
45
- "<extra_id_42>",
46
- "<extra_id_43>",
47
- "<extra_id_44>",
48
- "<extra_id_45>",
49
- "<extra_id_46>",
50
- "<extra_id_47>",
51
- "<extra_id_48>",
52
- "<extra_id_49>",
53
- "<extra_id_50>",
54
- "<extra_id_51>",
55
- "<extra_id_52>",
56
- "<extra_id_53>",
57
- "<extra_id_54>",
58
- "<extra_id_55>",
59
- "<extra_id_56>",
60
- "<extra_id_57>",
61
- "<extra_id_58>",
62
- "<extra_id_59>",
63
- "<extra_id_60>",
64
- "<extra_id_61>",
65
- "<extra_id_62>",
66
- "<extra_id_63>",
67
- "<extra_id_64>",
68
- "<extra_id_65>",
69
- "<extra_id_66>",
70
- "<extra_id_67>",
71
- "<extra_id_68>",
72
- "<extra_id_69>",
73
- "<extra_id_70>",
74
- "<extra_id_71>",
75
- "<extra_id_72>",
76
- "<extra_id_73>",
77
- "<extra_id_74>",
78
- "<extra_id_75>",
79
- "<extra_id_76>",
80
- "<extra_id_77>",
81
- "<extra_id_78>",
82
- "<extra_id_79>",
83
- "<extra_id_80>",
84
- "<extra_id_81>",
85
- "<extra_id_82>",
86
- "<extra_id_83>",
87
- "<extra_id_84>",
88
- "<extra_id_85>",
89
- "<extra_id_86>",
90
- "<extra_id_87>",
91
- "<extra_id_88>",
92
- "<extra_id_89>",
93
- "<extra_id_90>",
94
- "<extra_id_91>",
95
- "<extra_id_92>",
96
- "<extra_id_93>",
97
- "<extra_id_94>",
98
- "<extra_id_95>",
99
- "<extra_id_96>",
100
- "<extra_id_97>",
101
- "<extra_id_98>",
102
- "<extra_id_99>"
103
  ],
104
  "eos_token": {
105
- "content": "</s>",
106
  "lstrip": false,
107
  "normalized": false,
108
  "rstrip": false,
109
  "single_word": false
110
  },
111
  "pad_token": {
112
- "content": "<pad>",
113
- "lstrip": false,
114
- "normalized": false,
115
- "rstrip": false,
116
- "single_word": false
117
- },
118
- "unk_token": {
119
- "content": "<unk>",
120
  "lstrip": false,
121
  "normalized": false,
122
  "rstrip": false,
 
1
  {
2
  "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<img>",
6
+ "</img>",
7
+ "<IMG_CONTEXT>",
8
+ "<quad>",
9
+ "</quad>",
10
+ "<ref>",
11
+ "</ref>",
12
+ "<box>",
13
+ "</box>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  ],
15
  "eos_token": {
16
+ "content": "<|im_end|>",
17
  "lstrip": false,
18
  "normalized": false,
19
  "rstrip": false,
20
  "single_word": false
21
  },
22
  "pad_token": {
23
+ "content": "<|endoftext|>",
 
 
 
 
 
 
 
24
  "lstrip": false,
25
  "normalized": false,
26
  "rstrip": false,
models/TabRec/StructEqTable/spiece.model DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:fad1d4fa991da128c14d040d1e3ed2722b9183bf25404b01de9a47b0581905a0
3
- size 1212407
 
 
 
 
models/TabRec/StructEqTable/tokenizer_config.json CHANGED
@@ -1,823 +1,97 @@
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
- "1": {
12
- "content": "</s>",
13
  "lstrip": false,
14
  "normalized": false,
15
  "rstrip": false,
16
  "single_word": false,
17
  "special": true
18
  },
19
- "3": {
20
- "content": "<unk>",
21
  "lstrip": false,
22
  "normalized": false,
23
  "rstrip": false,
24
  "single_word": false,
25
  "special": true
26
  },
27
- "76978": {
28
- "content": "<extra_id_99>",
29
  "lstrip": false,
30
  "normalized": false,
31
  "rstrip": false,
32
  "single_word": false,
33
  "special": true
34
  },
35
- "76979": {
36
- "content": "<extra_id_98>",
37
  "lstrip": false,
38
  "normalized": false,
39
  "rstrip": false,
40
  "single_word": false,
41
  "special": true
42
  },
43
- "76980": {
44
- "content": "<extra_id_97>",
45
  "lstrip": false,
46
  "normalized": false,
47
  "rstrip": false,
48
  "single_word": false,
49
  "special": true
50
  },
51
- "76981": {
52
- "content": "<extra_id_96>",
53
  "lstrip": false,
54
  "normalized": false,
55
  "rstrip": false,
56
  "single_word": false,
57
  "special": true
58
  },
59
- "76982": {
60
- "content": "<extra_id_95>",
61
  "lstrip": false,
62
  "normalized": false,
63
  "rstrip": false,
64
  "single_word": false,
65
  "special": true
66
  },
67
- "76983": {
68
- "content": "<extra_id_94>",
69
  "lstrip": false,
70
  "normalized": false,
71
  "rstrip": false,
72
  "single_word": false,
73
  "special": true
74
  },
75
- "76984": {
76
- "content": "<extra_id_93>",
77
  "lstrip": false,
78
  "normalized": false,
79
  "rstrip": false,
80
  "single_word": false,
81
  "special": true
82
  },
83
- "76985": {
84
- "content": "<extra_id_92>",
85
  "lstrip": false,
86
  "normalized": false,
87
  "rstrip": false,
88
  "single_word": false,
89
  "special": true
90
  },
91
- "76986": {
92
- "content": "<extra_id_91>",
93
- "lstrip": false,
94
- "normalized": false,
95
- "rstrip": false,
96
- "single_word": false,
97
- "special": true
98
- },
99
- "76987": {
100
- "content": "<extra_id_90>",
101
- "lstrip": false,
102
- "normalized": false,
103
- "rstrip": false,
104
- "single_word": false,
105
- "special": true
106
- },
107
- "76988": {
108
- "content": "<extra_id_89>",
109
- "lstrip": false,
110
- "normalized": false,
111
- "rstrip": false,
112
- "single_word": false,
113
- "special": true
114
- },
115
- "76989": {
116
- "content": "<extra_id_88>",
117
- "lstrip": false,
118
- "normalized": false,
119
- "rstrip": false,
120
- "single_word": false,
121
- "special": true
122
- },
123
- "76990": {
124
- "content": "<extra_id_87>",
125
- "lstrip": false,
126
- "normalized": false,
127
- "rstrip": false,
128
- "single_word": false,
129
- "special": true
130
- },
131
- "76991": {
132
- "content": "<extra_id_86>",
133
- "lstrip": false,
134
- "normalized": false,
135
- "rstrip": false,
136
- "single_word": false,
137
- "special": true
138
- },
139
- "76992": {
140
- "content": "<extra_id_85>",
141
- "lstrip": false,
142
- "normalized": false,
143
- "rstrip": false,
144
- "single_word": false,
145
- "special": true
146
- },
147
- "76993": {
148
- "content": "<extra_id_84>",
149
- "lstrip": false,
150
- "normalized": false,
151
- "rstrip": false,
152
- "single_word": false,
153
- "special": true
154
- },
155
- "76994": {
156
- "content": "<extra_id_83>",
157
- "lstrip": false,
158
- "normalized": false,
159
- "rstrip": false,
160
- "single_word": false,
161
- "special": true
162
- },
163
- "76995": {
164
- "content": "<extra_id_82>",
165
- "lstrip": false,
166
- "normalized": false,
167
- "rstrip": false,
168
- "single_word": false,
169
- "special": true
170
- },
171
- "76996": {
172
- "content": "<extra_id_81>",
173
- "lstrip": false,
174
- "normalized": false,
175
- "rstrip": false,
176
- "single_word": false,
177
- "special": true
178
- },
179
- "76997": {
180
- "content": "<extra_id_80>",
181
- "lstrip": false,
182
- "normalized": false,
183
- "rstrip": false,
184
- "single_word": false,
185
- "special": true
186
- },
187
- "76998": {
188
- "content": "<extra_id_79>",
189
- "lstrip": false,
190
- "normalized": false,
191
- "rstrip": false,
192
- "single_word": false,
193
- "special": true
194
- },
195
- "76999": {
196
- "content": "<extra_id_78>",
197
- "lstrip": false,
198
- "normalized": false,
199
- "rstrip": false,
200
- "single_word": false,
201
- "special": true
202
- },
203
- "77000": {
204
- "content": "<extra_id_77>",
205
- "lstrip": false,
206
- "normalized": false,
207
- "rstrip": false,
208
- "single_word": false,
209
- "special": true
210
- },
211
- "77001": {
212
- "content": "<extra_id_76>",
213
- "lstrip": false,
214
- "normalized": false,
215
- "rstrip": false,
216
- "single_word": false,
217
- "special": true
218
- },
219
- "77002": {
220
- "content": "<extra_id_75>",
221
- "lstrip": false,
222
- "normalized": false,
223
- "rstrip": false,
224
- "single_word": false,
225
- "special": true
226
- },
227
- "77003": {
228
- "content": "<extra_id_74>",
229
- "lstrip": false,
230
- "normalized": false,
231
- "rstrip": false,
232
- "single_word": false,
233
- "special": true
234
- },
235
- "77004": {
236
- "content": "<extra_id_73>",
237
- "lstrip": false,
238
- "normalized": false,
239
- "rstrip": false,
240
- "single_word": false,
241
- "special": true
242
- },
243
- "77005": {
244
- "content": "<extra_id_72>",
245
- "lstrip": false,
246
- "normalized": false,
247
- "rstrip": false,
248
- "single_word": false,
249
- "special": true
250
- },
251
- "77006": {
252
- "content": "<extra_id_71>",
253
- "lstrip": false,
254
- "normalized": false,
255
- "rstrip": false,
256
- "single_word": false,
257
- "special": true
258
- },
259
- "77007": {
260
- "content": "<extra_id_70>",
261
- "lstrip": false,
262
- "normalized": false,
263
- "rstrip": false,
264
- "single_word": false,
265
- "special": true
266
- },
267
- "77008": {
268
- "content": "<extra_id_69>",
269
- "lstrip": false,
270
- "normalized": false,
271
- "rstrip": false,
272
- "single_word": false,
273
- "special": true
274
- },
275
- "77009": {
276
- "content": "<extra_id_68>",
277
- "lstrip": false,
278
- "normalized": false,
279
- "rstrip": false,
280
- "single_word": false,
281
- "special": true
282
- },
283
- "77010": {
284
- "content": "<extra_id_67>",
285
- "lstrip": false,
286
- "normalized": false,
287
- "rstrip": false,
288
- "single_word": false,
289
- "special": true
290
- },
291
- "77011": {
292
- "content": "<extra_id_66>",
293
- "lstrip": false,
294
- "normalized": false,
295
- "rstrip": false,
296
- "single_word": false,
297
- "special": true
298
- },
299
- "77012": {
300
- "content": "<extra_id_65>",
301
- "lstrip": false,
302
- "normalized": false,
303
- "rstrip": false,
304
- "single_word": false,
305
- "special": true
306
- },
307
- "77013": {
308
- "content": "<extra_id_64>",
309
- "lstrip": false,
310
- "normalized": false,
311
- "rstrip": false,
312
- "single_word": false,
313
- "special": true
314
- },
315
- "77014": {
316
- "content": "<extra_id_63>",
317
- "lstrip": false,
318
- "normalized": false,
319
- "rstrip": false,
320
- "single_word": false,
321
- "special": true
322
- },
323
- "77015": {
324
- "content": "<extra_id_62>",
325
- "lstrip": false,
326
- "normalized": false,
327
- "rstrip": false,
328
- "single_word": false,
329
- "special": true
330
- },
331
- "77016": {
332
- "content": "<extra_id_61>",
333
- "lstrip": false,
334
- "normalized": false,
335
- "rstrip": false,
336
- "single_word": false,
337
- "special": true
338
- },
339
- "77017": {
340
- "content": "<extra_id_60>",
341
- "lstrip": false,
342
- "normalized": false,
343
- "rstrip": false,
344
- "single_word": false,
345
- "special": true
346
- },
347
- "77018": {
348
- "content": "<extra_id_59>",
349
- "lstrip": false,
350
- "normalized": false,
351
- "rstrip": false,
352
- "single_word": false,
353
- "special": true
354
- },
355
- "77019": {
356
- "content": "<extra_id_58>",
357
- "lstrip": false,
358
- "normalized": false,
359
- "rstrip": false,
360
- "single_word": false,
361
- "special": true
362
- },
363
- "77020": {
364
- "content": "<extra_id_57>",
365
- "lstrip": false,
366
- "normalized": false,
367
- "rstrip": false,
368
- "single_word": false,
369
- "special": true
370
- },
371
- "77021": {
372
- "content": "<extra_id_56>",
373
- "lstrip": false,
374
- "normalized": false,
375
- "rstrip": false,
376
- "single_word": false,
377
- "special": true
378
- },
379
- "77022": {
380
- "content": "<extra_id_55>",
381
- "lstrip": false,
382
- "normalized": false,
383
- "rstrip": false,
384
- "single_word": false,
385
- "special": true
386
- },
387
- "77023": {
388
- "content": "<extra_id_54>",
389
- "lstrip": false,
390
- "normalized": false,
391
- "rstrip": false,
392
- "single_word": false,
393
- "special": true
394
- },
395
- "77024": {
396
- "content": "<extra_id_53>",
397
- "lstrip": false,
398
- "normalized": false,
399
- "rstrip": false,
400
- "single_word": false,
401
- "special": true
402
- },
403
- "77025": {
404
- "content": "<extra_id_52>",
405
- "lstrip": false,
406
- "normalized": false,
407
- "rstrip": false,
408
- "single_word": false,
409
- "special": true
410
- },
411
- "77026": {
412
- "content": "<extra_id_51>",
413
- "lstrip": false,
414
- "normalized": false,
415
- "rstrip": false,
416
- "single_word": false,
417
- "special": true
418
- },
419
- "77027": {
420
- "content": "<extra_id_50>",
421
- "lstrip": false,
422
- "normalized": false,
423
- "rstrip": false,
424
- "single_word": false,
425
- "special": true
426
- },
427
- "77028": {
428
- "content": "<extra_id_49>",
429
- "lstrip": false,
430
- "normalized": false,
431
- "rstrip": false,
432
- "single_word": false,
433
- "special": true
434
- },
435
- "77029": {
436
- "content": "<extra_id_48>",
437
- "lstrip": false,
438
- "normalized": false,
439
- "rstrip": false,
440
- "single_word": false,
441
- "special": true
442
- },
443
- "77030": {
444
- "content": "<extra_id_47>",
445
- "lstrip": false,
446
- "normalized": false,
447
- "rstrip": false,
448
- "single_word": false,
449
- "special": true
450
- },
451
- "77031": {
452
- "content": "<extra_id_46>",
453
- "lstrip": false,
454
- "normalized": false,
455
- "rstrip": false,
456
- "single_word": false,
457
- "special": true
458
- },
459
- "77032": {
460
- "content": "<extra_id_45>",
461
- "lstrip": false,
462
- "normalized": false,
463
- "rstrip": false,
464
- "single_word": false,
465
- "special": true
466
- },
467
- "77033": {
468
- "content": "<extra_id_44>",
469
- "lstrip": false,
470
- "normalized": false,
471
- "rstrip": false,
472
- "single_word": false,
473
- "special": true
474
- },
475
- "77034": {
476
- "content": "<extra_id_43>",
477
- "lstrip": false,
478
- "normalized": false,
479
- "rstrip": false,
480
- "single_word": false,
481
- "special": true
482
- },
483
- "77035": {
484
- "content": "<extra_id_42>",
485
- "lstrip": false,
486
- "normalized": false,
487
- "rstrip": false,
488
- "single_word": false,
489
- "special": true
490
- },
491
- "77036": {
492
- "content": "<extra_id_41>",
493
- "lstrip": false,
494
- "normalized": false,
495
- "rstrip": false,
496
- "single_word": false,
497
- "special": true
498
- },
499
- "77037": {
500
- "content": "<extra_id_40>",
501
- "lstrip": false,
502
- "normalized": false,
503
- "rstrip": false,
504
- "single_word": false,
505
- "special": true
506
- },
507
- "77038": {
508
- "content": "<extra_id_39>",
509
- "lstrip": false,
510
- "normalized": false,
511
- "rstrip": false,
512
- "single_word": false,
513
- "special": true
514
- },
515
- "77039": {
516
- "content": "<extra_id_38>",
517
- "lstrip": false,
518
- "normalized": false,
519
- "rstrip": false,
520
- "single_word": false,
521
- "special": true
522
- },
523
- "77040": {
524
- "content": "<extra_id_37>",
525
- "lstrip": false,
526
- "normalized": false,
527
- "rstrip": false,
528
- "single_word": false,
529
- "special": true
530
- },
531
- "77041": {
532
- "content": "<extra_id_36>",
533
- "lstrip": false,
534
- "normalized": false,
535
- "rstrip": false,
536
- "single_word": false,
537
- "special": true
538
- },
539
- "77042": {
540
- "content": "<extra_id_35>",
541
- "lstrip": false,
542
- "normalized": false,
543
- "rstrip": false,
544
- "single_word": false,
545
- "special": true
546
- },
547
- "77043": {
548
- "content": "<extra_id_34>",
549
- "lstrip": false,
550
- "normalized": false,
551
- "rstrip": false,
552
- "single_word": false,
553
- "special": true
554
- },
555
- "77044": {
556
- "content": "<extra_id_33>",
557
- "lstrip": false,
558
- "normalized": false,
559
- "rstrip": false,
560
- "single_word": false,
561
- "special": true
562
- },
563
- "77045": {
564
- "content": "<extra_id_32>",
565
- "lstrip": false,
566
- "normalized": false,
567
- "rstrip": false,
568
- "single_word": false,
569
- "special": true
570
- },
571
- "77046": {
572
- "content": "<extra_id_31>",
573
- "lstrip": false,
574
- "normalized": false,
575
- "rstrip": false,
576
- "single_word": false,
577
- "special": true
578
- },
579
- "77047": {
580
- "content": "<extra_id_30>",
581
- "lstrip": false,
582
- "normalized": false,
583
- "rstrip": false,
584
- "single_word": false,
585
- "special": true
586
- },
587
- "77048": {
588
- "content": "<extra_id_29>",
589
- "lstrip": false,
590
- "normalized": false,
591
- "rstrip": false,
592
- "single_word": false,
593
- "special": true
594
- },
595
- "77049": {
596
- "content": "<extra_id_28>",
597
- "lstrip": false,
598
- "normalized": false,
599
- "rstrip": false,
600
- "single_word": false,
601
- "special": true
602
- },
603
- "77050": {
604
- "content": "<extra_id_27>",
605
- "lstrip": false,
606
- "normalized": false,
607
- "rstrip": false,
608
- "single_word": false,
609
- "special": true
610
- },
611
- "77051": {
612
- "content": "<extra_id_26>",
613
- "lstrip": false,
614
- "normalized": false,
615
- "rstrip": false,
616
- "single_word": false,
617
- "special": true
618
- },
619
- "77052": {
620
- "content": "<extra_id_25>",
621
- "lstrip": false,
622
- "normalized": false,
623
- "rstrip": false,
624
- "single_word": false,
625
- "special": true
626
- },
627
- "77053": {
628
- "content": "<extra_id_24>",
629
- "lstrip": false,
630
- "normalized": false,
631
- "rstrip": false,
632
- "single_word": false,
633
- "special": true
634
- },
635
- "77054": {
636
- "content": "<extra_id_23>",
637
- "lstrip": false,
638
- "normalized": false,
639
- "rstrip": false,
640
- "single_word": false,
641
- "special": true
642
- },
643
- "77055": {
644
- "content": "<extra_id_22>",
645
- "lstrip": false,
646
- "normalized": false,
647
- "rstrip": false,
648
- "single_word": false,
649
- "special": true
650
- },
651
- "77056": {
652
- "content": "<extra_id_21>",
653
- "lstrip": false,
654
- "normalized": false,
655
- "rstrip": false,
656
- "single_word": false,
657
- "special": true
658
- },
659
- "77057": {
660
- "content": "<extra_id_20>",
661
- "lstrip": false,
662
- "normalized": false,
663
- "rstrip": false,
664
- "single_word": false,
665
- "special": true
666
- },
667
- "77058": {
668
- "content": "<extra_id_19>",
669
- "lstrip": false,
670
- "normalized": false,
671
- "rstrip": false,
672
- "single_word": false,
673
- "special": true
674
- },
675
- "77059": {
676
- "content": "<extra_id_18>",
677
- "lstrip": false,
678
- "normalized": false,
679
- "rstrip": false,
680
- "single_word": false,
681
- "special": true
682
- },
683
- "77060": {
684
- "content": "<extra_id_17>",
685
- "lstrip": false,
686
- "normalized": false,
687
- "rstrip": false,
688
- "single_word": false,
689
- "special": true
690
- },
691
- "77061": {
692
- "content": "<extra_id_16>",
693
- "lstrip": false,
694
- "normalized": false,
695
- "rstrip": false,
696
- "single_word": false,
697
- "special": true
698
- },
699
- "77062": {
700
- "content": "<extra_id_15>",
701
- "lstrip": false,
702
- "normalized": false,
703
- "rstrip": false,
704
- "single_word": false,
705
- "special": true
706
- },
707
- "77063": {
708
- "content": "<extra_id_14>",
709
- "lstrip": false,
710
- "normalized": false,
711
- "rstrip": false,
712
- "single_word": false,
713
- "special": true
714
- },
715
- "77064": {
716
- "content": "<extra_id_13>",
717
- "lstrip": false,
718
- "normalized": false,
719
- "rstrip": false,
720
- "single_word": false,
721
- "special": true
722
- },
723
- "77065": {
724
- "content": "<extra_id_12>",
725
- "lstrip": false,
726
- "normalized": false,
727
- "rstrip": false,
728
- "single_word": false,
729
- "special": true
730
- },
731
- "77066": {
732
- "content": "<extra_id_11>",
733
- "lstrip": false,
734
- "normalized": false,
735
- "rstrip": false,
736
- "single_word": false,
737
- "special": true
738
- },
739
- "77067": {
740
- "content": "<extra_id_10>",
741
- "lstrip": false,
742
- "normalized": false,
743
- "rstrip": false,
744
- "single_word": false,
745
- "special": true
746
- },
747
- "77068": {
748
- "content": "<extra_id_9>",
749
- "lstrip": false,
750
- "normalized": false,
751
- "rstrip": false,
752
- "single_word": false,
753
- "special": true
754
- },
755
- "77069": {
756
- "content": "<extra_id_8>",
757
- "lstrip": false,
758
- "normalized": false,
759
- "rstrip": false,
760
- "single_word": false,
761
- "special": true
762
- },
763
- "77070": {
764
- "content": "<extra_id_7>",
765
- "lstrip": false,
766
- "normalized": false,
767
- "rstrip": false,
768
- "single_word": false,
769
- "special": true
770
- },
771
- "77071": {
772
- "content": "<extra_id_6>",
773
- "lstrip": false,
774
- "normalized": false,
775
- "rstrip": false,
776
- "single_word": false,
777
- "special": true
778
- },
779
- "77072": {
780
- "content": "<extra_id_5>",
781
- "lstrip": false,
782
- "normalized": false,
783
- "rstrip": false,
784
- "single_word": false,
785
- "special": true
786
- },
787
- "77073": {
788
- "content": "<extra_id_4>",
789
- "lstrip": false,
790
- "normalized": false,
791
- "rstrip": false,
792
- "single_word": false,
793
- "special": true
794
- },
795
- "77074": {
796
- "content": "<extra_id_3>",
797
- "lstrip": false,
798
- "normalized": false,
799
- "rstrip": false,
800
- "single_word": false,
801
- "special": true
802
- },
803
- "77075": {
804
- "content": "<extra_id_2>",
805
- "lstrip": false,
806
- "normalized": false,
807
- "rstrip": false,
808
- "single_word": false,
809
- "special": true
810
- },
811
- "77076": {
812
- "content": "<extra_id_1>",
813
- "lstrip": false,
814
- "normalized": false,
815
- "rstrip": false,
816
- "single_word": false,
817
- "special": true
818
- },
819
- "77077": {
820
- "content": "<extra_id_0>",
821
  "lstrip": false,
822
  "normalized": false,
823
  "rstrip": false,
@@ -826,115 +100,26 @@
826
  }
827
  },
828
  "additional_special_tokens": [
829
- "<extra_id_0>",
830
- "<extra_id_1>",
831
- "<extra_id_2>",
832
- "<extra_id_3>",
833
- "<extra_id_4>",
834
- "<extra_id_5>",
835
- "<extra_id_6>",
836
- "<extra_id_7>",
837
- "<extra_id_8>",
838
- "<extra_id_9>",
839
- "<extra_id_10>",
840
- "<extra_id_11>",
841
- "<extra_id_12>",
842
- "<extra_id_13>",
843
- "<extra_id_14>",
844
- "<extra_id_15>",
845
- "<extra_id_16>",
846
- "<extra_id_17>",
847
- "<extra_id_18>",
848
- "<extra_id_19>",
849
- "<extra_id_20>",
850
- "<extra_id_21>",
851
- "<extra_id_22>",
852
- "<extra_id_23>",
853
- "<extra_id_24>",
854
- "<extra_id_25>",
855
- "<extra_id_26>",
856
- "<extra_id_27>",
857
- "<extra_id_28>",
858
- "<extra_id_29>",
859
- "<extra_id_30>",
860
- "<extra_id_31>",
861
- "<extra_id_32>",
862
- "<extra_id_33>",
863
- "<extra_id_34>",
864
- "<extra_id_35>",
865
- "<extra_id_36>",
866
- "<extra_id_37>",
867
- "<extra_id_38>",
868
- "<extra_id_39>",
869
- "<extra_id_40>",
870
- "<extra_id_41>",
871
- "<extra_id_42>",
872
- "<extra_id_43>",
873
- "<extra_id_44>",
874
- "<extra_id_45>",
875
- "<extra_id_46>",
876
- "<extra_id_47>",
877
- "<extra_id_48>",
878
- "<extra_id_49>",
879
- "<extra_id_50>",
880
- "<extra_id_51>",
881
- "<extra_id_52>",
882
- "<extra_id_53>",
883
- "<extra_id_54>",
884
- "<extra_id_55>",
885
- "<extra_id_56>",
886
- "<extra_id_57>",
887
- "<extra_id_58>",
888
- "<extra_id_59>",
889
- "<extra_id_60>",
890
- "<extra_id_61>",
891
- "<extra_id_62>",
892
- "<extra_id_63>",
893
- "<extra_id_64>",
894
- "<extra_id_65>",
895
- "<extra_id_66>",
896
- "<extra_id_67>",
897
- "<extra_id_68>",
898
- "<extra_id_69>",
899
- "<extra_id_70>",
900
- "<extra_id_71>",
901
- "<extra_id_72>",
902
- "<extra_id_73>",
903
- "<extra_id_74>",
904
- "<extra_id_75>",
905
- "<extra_id_76>",
906
- "<extra_id_77>",
907
- "<extra_id_78>",
908
- "<extra_id_79>",
909
- "<extra_id_80>",
910
- "<extra_id_81>",
911
- "<extra_id_82>",
912
- "<extra_id_83>",
913
- "<extra_id_84>",
914
- "<extra_id_85>",
915
- "<extra_id_86>",
916
- "<extra_id_87>",
917
- "<extra_id_88>",
918
- "<extra_id_89>",
919
- "<extra_id_90>",
920
- "<extra_id_91>",
921
- "<extra_id_92>",
922
- "<extra_id_93>",
923
- "<extra_id_94>",
924
- "<extra_id_95>",
925
- "<extra_id_96>",
926
- "<extra_id_97>",
927
- "<extra_id_98>",
928
- "<extra_id_99>"
929
  ],
930
- "clean_up_tokenization_spaces": true,
931
- "eos_token": "</s>",
932
- "extra_ids": 100,
933
- "legacy": true,
934
- "model_max_length": 1000000000000000019884624838656,
935
- "pad_token": "<pad>",
936
- "processor_class": "Pix2StructProcessor",
937
- "sp_model_kwargs": {},
938
- "tokenizer_class": "T5Tokenizer",
939
- "unk_token": "<unk>"
940
  }
 
1
  {
2
+ "add_eos_token": false,
3
+ "add_prefix_space": false,
4
  "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
  "lstrip": false,
8
  "normalized": false,
9
  "rstrip": false,
10
  "single_word": false,
11
  "special": true
12
  },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
  "lstrip": false,
16
  "normalized": false,
17
  "rstrip": false,
18
  "single_word": false,
19
  "special": true
20
  },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
  "lstrip": false,
24
  "normalized": false,
25
  "rstrip": false,
26
  "single_word": false,
27
  "special": true
28
  },
29
+ "151646": {
30
+ "content": "<img>",
31
  "lstrip": false,
32
  "normalized": false,
33
  "rstrip": false,
34
  "single_word": false,
35
  "special": true
36
  },
37
+ "151647": {
38
+ "content": "</img>",
39
  "lstrip": false,
40
  "normalized": false,
41
  "rstrip": false,
42
  "single_word": false,
43
  "special": true
44
  },
45
+ "151648": {
46
+ "content": "<IMG_CONTEXT>",
47
  "lstrip": false,
48
  "normalized": false,
49
  "rstrip": false,
50
  "single_word": false,
51
  "special": true
52
  },
53
+ "151649": {
54
+ "content": "<quad>",
55
  "lstrip": false,
56
  "normalized": false,
57
  "rstrip": false,
58
  "single_word": false,
59
  "special": true
60
  },
61
+ "151650": {
62
+ "content": "</quad>",
63
  "lstrip": false,
64
  "normalized": false,
65
  "rstrip": false,
66
  "single_word": false,
67
  "special": true
68
  },
69
+ "151651": {
70
+ "content": "<ref>",
71
  "lstrip": false,
72
  "normalized": false,
73
  "rstrip": false,
74
  "single_word": false,
75
  "special": true
76
  },
77
+ "151652": {
78
+ "content": "</ref>",
79
  "lstrip": false,
80
  "normalized": false,
81
  "rstrip": false,
82
  "single_word": false,
83
  "special": true
84
  },
85
+ "151653": {
86
+ "content": "<box>",
87
  "lstrip": false,
88
  "normalized": false,
89
  "rstrip": false,
90
  "single_word": false,
91
  "special": true
92
  },
93
+ "151654": {
94
+ "content": "</box>",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  "lstrip": false,
96
  "normalized": false,
97
  "rstrip": false,
 
100
  }
101
  },
102
  "additional_special_tokens": [
103
+ "<|im_start|>",
104
+ "<|im_end|>",
105
+ "<img>",
106
+ "</img>",
107
+ "<IMG_CONTEXT>",
108
+ "<quad>",
109
+ "</quad>",
110
+ "<ref>",
111
+ "</ref>",
112
+ "<box>",
113
+ "</box>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  ],
115
+ "bos_token": null,
116
+ "chat_template": "{% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n' }}{% endif %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}",
117
+ "clean_up_tokenization_spaces": false,
118
+ "eos_token": "<|im_end|>",
119
+ "errors": "replace",
120
+ "model_max_length": 8192,
121
+ "pad_token": "<|endoftext|>",
122
+ "split_special_tokens": false,
123
+ "tokenizer_class": "Qwen2Tokenizer",
124
+ "unk_token": null
125
  }
models/TabRec/StructEqTable/{tokenizer.json → vocab.json} RENAMED
The diff for this file is too large to render. See raw diff