first commit
Browse files- README.md +110 -0
- added_tokens.json +5 -0
- config.json +44 -0
- configuration_fegeo_qwen2.py +202 -0
- generation_config.json +14 -0
- merges.txt +0 -0
- model.safetensors +3 -0
- modeling_fegeo_qwen2.py +0 -0
- sample/4927.png +0 -0
- special_tokens_map.json +20 -0
- tokenizer_config.json +44 -0
- vocab.json +0 -0
README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 基于FormalGeo7K的结构识别模型
|
| 2 |
+
|
| 3 |
+
## 快速开始
|
| 4 |
+
在运行脚本之前,首先安装如下必要的依赖。
|
| 5 |
+
|
| 6 |
+
```shell
|
| 7 |
+
pip install --upgrade pip
|
| 8 |
+
pip install torch transformers==4.40.0
|
| 9 |
+
pip install sentencepiece
|
| 10 |
+
pip install accelerate pillow
|
| 11 |
+
pip install ninja
|
| 12 |
+
pip install packaging
|
| 13 |
+
pip install flash-attn --no-build-isolation
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
```python
|
| 17 |
+
import torch
|
| 18 |
+
import transformers
|
| 19 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 20 |
+
from PIL import Image
|
| 21 |
+
import warnings
|
| 22 |
+
import numpy as np
|
| 23 |
+
|
| 24 |
+
# set device
|
| 25 |
+
device = 'cuda' # or cpu
|
| 26 |
+
torch.set_default_device(device)
|
| 27 |
+
|
| 28 |
+
# create model
|
| 29 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 30 |
+
'NaughtyDog97/GeoFormalizer',
|
| 31 |
+
torch_dtype=torch.float16, # float32 for cpu
|
| 32 |
+
device_map='auto',
|
| 33 |
+
trust_remote_code=True)
|
| 34 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 35 |
+
'NaughtyDog97/GeoFormalizer',
|
| 36 |
+
trust_remote_code=True)
|
| 37 |
+
|
| 38 |
+
# text prompt
|
| 39 |
+
img_path = 'sample/4927.png'
|
| 40 |
+
prompt = 'Based on the image, first describe what you see in the figure, then predict the construction_cdl and image_cdl and calibrate it.'
|
| 41 |
+
text = f"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n<image>\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
|
| 42 |
+
text_chunks = [tokenizer(chunk).input_ids for chunk in text.split('<image>')]
|
| 43 |
+
input_ids = torch.tensor(text_chunks[0] + [-200] + text_chunks[1][1:], dtype=torch.long).unsqueeze(0).to(device)
|
| 44 |
+
|
| 45 |
+
# image, sample images can be found in images folder
|
| 46 |
+
image = Image.open(img_path).convert('RGB')
|
| 47 |
+
|
| 48 |
+
image_tensor = model.process_images([image], model.config).to(dtype=model.dtype, device=device)
|
| 49 |
+
|
| 50 |
+
# generate
|
| 51 |
+
with torch.inference_mode():
|
| 52 |
+
output_ids = model.generate(
|
| 53 |
+
input_ids,
|
| 54 |
+
images=image_tensor,
|
| 55 |
+
do_sample=False,
|
| 56 |
+
temperature=None,
|
| 57 |
+
top_p=None,
|
| 58 |
+
top_k=None,
|
| 59 |
+
num_beams=1,
|
| 60 |
+
max_new_tokens=3500,
|
| 61 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 62 |
+
repetition_penalty=None,
|
| 63 |
+
use_cache=True
|
| 64 |
+
)[0]
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
respones = tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip()
|
| 68 |
+
print(respones)
|
| 69 |
+
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
我们的模型支持的识别方式有如下几种:
|
| 73 |
+
- 自然语言描述:
|
| 74 |
+
- Describe what you see in the figure.
|
| 75 |
+
- Tell me what you observe in the image.
|
| 76 |
+
- 使用自然语言描述这幅图像。
|
| 77 |
+
- 只预测construction_cdl
|
| 78 |
+
- Based on the image, predict the construction_cdl.
|
| 79 |
+
- 根据图像识别出construction_cdl。
|
| 80 |
+
- Based on the image, predict the construction_cdl and calibrate it.
|
| 81 |
+
- 根据图像识别出construction_cdl并进行矫正。
|
| 82 |
+
- Based on the image, first describe what you see in the figure, then predict the construction_cdl.
|
| 83 |
+
- 根据图像,首先描述图像,之后识别出construction_cdl。
|
| 84 |
+
- Based on the image, first describe what you see in the figure, then predict the construction_cdl and calibrate it.
|
| 85 |
+
- 根据图像,首先描述图像,之后识别出construction_cdl并进行矫正。
|
| 86 |
+
- 只预测image_cdl
|
| 87 |
+
- Based on the image, predict the image_cdl.
|
| 88 |
+
- 根据图像识别出image_cdl。
|
| 89 |
+
- Based on the image, predict the image_cdl and calibrate it.
|
| 90 |
+
- 根据图像识别出image_cdl并进行矫正。
|
| 91 |
+
- Based on the image, first describe what you see in the figure, then predict the image_cdl.
|
| 92 |
+
- 根据图像,首先描述图像,之后识别出image_cdl。
|
| 93 |
+
- Based on the image, first describe what you see in the figure, then predict the image_cdl and calibrate it.
|
| 94 |
+
- 根据图像,首先描述图像,之后识别出image_cdl并进行矫正。
|
| 95 |
+
- 同时预测construction_cdl和image_cdl
|
| 96 |
+
- Based on the image, predict the construction_cdl and image_cdl.
|
| 97 |
+
- 根据图像识别出construction_cdl和image_cdl。
|
| 98 |
+
- Based on the image, first predict the construction_cdl and image_cdl and calibrate it.
|
| 99 |
+
- 根据图像识别出construction_cdl和image_cdl并进行矫正。
|
| 100 |
+
- Based on the image, first describe what you see in the figure, then predict the construction_cdl and image_cdl.
|
| 101 |
+
- 根据图像,首先描述图像,之后识别出construction_cdl和image_cdl。
|
| 102 |
+
- Based on the image, first describe what you see in the figure, then predict the construction_cdl and image_cdl and calibrate it.
|
| 103 |
+
- 根据图像,首先描述图像,之后识别出construction_cdl和image_cdl并矫正。
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
## Performance
|
| 107 |
+
| | ConsCdlAcc | ConsCdlPerfect | ImgCdlAcc | ImgCdlPerfect | BothPerfect |
|
| 108 |
+
|-----|----------------|---------------------|---------------|-------------------|------------------|
|
| 109 |
+
| siglip-0.4B-qwen2-0.5B | 90.254 | 72.286 | 92.880 | 84.381 | 65.048 |
|
| 110 |
+
|
added_tokens.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"<|endoftext|>": 151643,
|
| 3 |
+
"<|im_end|>": 151645,
|
| 4 |
+
"<|im_start|>": 151644
|
| 5 |
+
}
|
config.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "NaughtyDog97/GeoFormalizer",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"FEGeoQwen2ForCausalLM"
|
| 5 |
+
],
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "configuration_fegeo_qwen2.FEGeoQwen2Config",
|
| 8 |
+
"AutoModelForCausalLM": "modeling_fegeo_qwen2.FEGeoQwen2ForCausalLM"
|
| 9 |
+
},
|
| 10 |
+
"attention_dropout": 0.0,
|
| 11 |
+
"eos_token_id": 151645,
|
| 12 |
+
"freeze_mm_mlp_adapter": false,
|
| 13 |
+
"freeze_vision_tower": true,
|
| 14 |
+
"hidden_act": "silu",
|
| 15 |
+
"hidden_size": 896,
|
| 16 |
+
"image_aspect_ratio": "pad",
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"intermediate_size": 4864,
|
| 19 |
+
"max_position_embeddings": 32768,
|
| 20 |
+
"max_window_layers": 24,
|
| 21 |
+
"mm_hidden_size": 1152,
|
| 22 |
+
"mm_projector_lr": 2e-06,
|
| 23 |
+
"mm_projector_type": "mlp2x_gelu",
|
| 24 |
+
"mm_vision_tower": "google/siglip-so400m-patch14-384",
|
| 25 |
+
"model_type": "fegeo-qwen2",
|
| 26 |
+
"num_attention_heads": 14,
|
| 27 |
+
"num_hidden_layers": 24,
|
| 28 |
+
"num_key_value_heads": 2,
|
| 29 |
+
"rms_norm_eps": 1e-06,
|
| 30 |
+
"rope_theta": 1000000.0,
|
| 31 |
+
"sliding_window": 32768,
|
| 32 |
+
"tie_word_embeddings": true,
|
| 33 |
+
"tokenizer_model_max_length": 4096,
|
| 34 |
+
"tokenizer_padding_side": "right",
|
| 35 |
+
"torch_dtype": "float16",
|
| 36 |
+
"transformers_version": "4.40.0",
|
| 37 |
+
"tune_mm_mlp_adapter": false,
|
| 38 |
+
"tune_vision_tower": false,
|
| 39 |
+
"use_cache": true,
|
| 40 |
+
"use_mm_proj": true,
|
| 41 |
+
"use_s2": false,
|
| 42 |
+
"use_sliding_window": false,
|
| 43 |
+
"vocab_size": 151646
|
| 44 |
+
}
|
configuration_fegeo_qwen2.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
"""Qwen2 model configuration"""
|
| 16 |
+
|
| 17 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 18 |
+
from transformers.utils import logging
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
logger = logging.get_logger(__name__)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Qwen2Config(PretrainedConfig):
|
| 25 |
+
r"""
|
| 26 |
+
This is the configuration class to store the configuration of a [`Qwen2Model`]. It is used to instantiate a
|
| 27 |
+
Qwen2 model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
| 28 |
+
with the defaults will yield a similar configuration to that of
|
| 29 |
+
Qwen2-7B-beta [Qwen/Qwen2-7B-beta](https://huggingface.co/Qwen/Qwen2-7B-beta).
|
| 30 |
+
|
| 31 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 32 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Args:
|
| 36 |
+
vocab_size (`int`, *optional*, defaults to 151936):
|
| 37 |
+
Vocabulary size of the Qwen2 model. Defines the number of different tokens that can be represented by the
|
| 38 |
+
`inputs_ids` passed when calling [`Qwen2Model`]
|
| 39 |
+
hidden_size (`int`, *optional*, defaults to 4096):
|
| 40 |
+
Dimension of the hidden representations.
|
| 41 |
+
intermediate_size (`int`, *optional*, defaults to 22016):
|
| 42 |
+
Dimension of the MLP representations.
|
| 43 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
| 44 |
+
Number of hidden layers in the Transformer encoder.
|
| 45 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
| 46 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
| 47 |
+
num_key_value_heads (`int`, *optional*, defaults to 32):
|
| 48 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
| 49 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
| 50 |
+
`num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
| 51 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
| 52 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
| 53 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `32`.
|
| 54 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 55 |
+
The non-linear activation function (function or string) in the decoder.
|
| 56 |
+
max_position_embeddings (`int`, *optional*, defaults to 32768):
|
| 57 |
+
The maximum sequence length that this model might ever be used with.
|
| 58 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 59 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 60 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
| 61 |
+
The epsilon used by the rms normalization layers.
|
| 62 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 63 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 64 |
+
relevant if `config.is_decoder=True`.
|
| 65 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 66 |
+
Whether the model's input and output word embeddings should be tied.
|
| 67 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
| 68 |
+
The base period of the RoPE embeddings.
|
| 69 |
+
use_sliding_window (`bool`, *optional*, defaults to `False`):
|
| 70 |
+
Whether to use sliding window attention.
|
| 71 |
+
sliding_window (`int`, *optional*, defaults to 4096):
|
| 72 |
+
Sliding window attention (SWA) window size. If not specified, will default to `4096`.
|
| 73 |
+
max_window_layers (`int`, *optional*, defaults to 28):
|
| 74 |
+
The number of layers that use SWA (Sliding Window Attention). The bottom layers use SWA while the top use full attention.
|
| 75 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 76 |
+
The dropout ratio for the attention probabilities.
|
| 77 |
+
|
| 78 |
+
```python
|
| 79 |
+
>>> from transformers import Qwen2Model, Qwen2Config
|
| 80 |
+
|
| 81 |
+
>>> # Initializing a Qwen2 style configuration
|
| 82 |
+
>>> configuration = Qwen2Config()
|
| 83 |
+
|
| 84 |
+
>>> # Initializing a model from the Qwen2-7B style configuration
|
| 85 |
+
>>> model = Qwen2Model(configuration)
|
| 86 |
+
|
| 87 |
+
>>> # Accessing the model configuration
|
| 88 |
+
>>> configuration = model.config
|
| 89 |
+
```"""
|
| 90 |
+
|
| 91 |
+
model_type = "qwen2"
|
| 92 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 93 |
+
|
| 94 |
+
def __init__(
|
| 95 |
+
self,
|
| 96 |
+
vocab_size=151936,
|
| 97 |
+
hidden_size=4096,
|
| 98 |
+
intermediate_size=22016,
|
| 99 |
+
num_hidden_layers=32,
|
| 100 |
+
num_attention_heads=32,
|
| 101 |
+
num_key_value_heads=32,
|
| 102 |
+
hidden_act="silu",
|
| 103 |
+
max_position_embeddings=32768,
|
| 104 |
+
initializer_range=0.02,
|
| 105 |
+
rms_norm_eps=1e-6,
|
| 106 |
+
use_cache=True,
|
| 107 |
+
tie_word_embeddings=False,
|
| 108 |
+
rope_theta=10000.0,
|
| 109 |
+
use_sliding_window=False,
|
| 110 |
+
sliding_window=4096,
|
| 111 |
+
max_window_layers=28,
|
| 112 |
+
attention_dropout=0.0,
|
| 113 |
+
**kwargs,
|
| 114 |
+
):
|
| 115 |
+
self.vocab_size = vocab_size
|
| 116 |
+
self.max_position_embeddings = max_position_embeddings
|
| 117 |
+
self.hidden_size = hidden_size
|
| 118 |
+
self.intermediate_size = intermediate_size
|
| 119 |
+
self.num_hidden_layers = num_hidden_layers
|
| 120 |
+
self.num_attention_heads = num_attention_heads
|
| 121 |
+
self.use_sliding_window = use_sliding_window
|
| 122 |
+
self.sliding_window = sliding_window
|
| 123 |
+
self.max_window_layers = max_window_layers
|
| 124 |
+
|
| 125 |
+
# for backward compatibility
|
| 126 |
+
if num_key_value_heads is None:
|
| 127 |
+
num_key_value_heads = num_attention_heads
|
| 128 |
+
|
| 129 |
+
self.num_key_value_heads = num_key_value_heads
|
| 130 |
+
self.hidden_act = hidden_act
|
| 131 |
+
self.initializer_range = initializer_range
|
| 132 |
+
self.rms_norm_eps = rms_norm_eps
|
| 133 |
+
self.use_cache = use_cache
|
| 134 |
+
self.rope_theta = rope_theta
|
| 135 |
+
self.attention_dropout = attention_dropout
|
| 136 |
+
|
| 137 |
+
super().__init__(
|
| 138 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 139 |
+
**kwargs,
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
"""Vision model configuration"""
|
| 145 |
+
from typing import Union
|
| 146 |
+
from transformers import PretrainedConfig
|
| 147 |
+
import os
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
class SigLipVisionConfig(PretrainedConfig):
|
| 151 |
+
model_type = "siglip_vision_model"
|
| 152 |
+
|
| 153 |
+
def __init__(
|
| 154 |
+
self,
|
| 155 |
+
hidden_size=1152,
|
| 156 |
+
image_mean=(0.5, 0.5, 0.5),
|
| 157 |
+
intermediate_size=4304,
|
| 158 |
+
num_hidden_layers=27,
|
| 159 |
+
num_attention_heads=16,
|
| 160 |
+
num_channels=3,
|
| 161 |
+
image_size=384,
|
| 162 |
+
patch_size=14,
|
| 163 |
+
hidden_act="gelu_pytorch_tanh",
|
| 164 |
+
layer_norm_eps=1e-6,
|
| 165 |
+
attention_dropout=0.0,
|
| 166 |
+
**kwargs,
|
| 167 |
+
):
|
| 168 |
+
super().__init__(**kwargs)
|
| 169 |
+
|
| 170 |
+
self.hidden_size = hidden_size
|
| 171 |
+
self.intermediate_size = intermediate_size
|
| 172 |
+
self.num_hidden_layers = num_hidden_layers
|
| 173 |
+
self.num_attention_heads = num_attention_heads
|
| 174 |
+
self.num_channels = num_channels
|
| 175 |
+
self.patch_size = patch_size
|
| 176 |
+
self.image_size = image_size
|
| 177 |
+
self.attention_dropout = attention_dropout
|
| 178 |
+
self.layer_norm_eps = layer_norm_eps
|
| 179 |
+
self.hidden_act = hidden_act
|
| 180 |
+
self.image_mean = image_mean
|
| 181 |
+
|
| 182 |
+
@classmethod
|
| 183 |
+
def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> "PretrainedConfig":
|
| 184 |
+
cls._set_token_in_kwargs(kwargs)
|
| 185 |
+
|
| 186 |
+
config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
|
| 187 |
+
|
| 188 |
+
# get the vision config dict if we are loading from SigLipConfig
|
| 189 |
+
if config_dict.get("model_type") == "siglip":
|
| 190 |
+
config_dict = config_dict["vision_config"]
|
| 191 |
+
|
| 192 |
+
if "model_type" in config_dict and hasattr(cls, "model_type") and config_dict["model_type"] != cls.model_type:
|
| 193 |
+
logger.warning(
|
| 194 |
+
f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
|
| 195 |
+
f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
return cls.from_dict(config_dict, **kwargs)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
class FEGeoQwen2Config(Qwen2Config):
|
| 202 |
+
model_type = "fegeo-qwen2"
|
generation_config.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token_id": 151643,
|
| 3 |
+
"do_sample": true,
|
| 4 |
+
"eos_token_id": [
|
| 5 |
+
151645,
|
| 6 |
+
151643
|
| 7 |
+
],
|
| 8 |
+
"pad_token_id": 151643,
|
| 9 |
+
"repetition_penalty": 1.1,
|
| 10 |
+
"temperature": 0.7,
|
| 11 |
+
"top_k": 20,
|
| 12 |
+
"top_p": 0.8,
|
| 13 |
+
"transformers_version": "4.40.0"
|
| 14 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:91b0207b797a1cf2481254edb3d8e29d35a6f51be4ccaf68b7d8e8ca7ff2f6c2
|
| 3 |
+
size 1786813056
|
modeling_fegeo_qwen2.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
sample/4927.png
ADDED
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"additional_special_tokens": [
|
| 3 |
+
"<|im_start|>",
|
| 4 |
+
"<|im_end|>"
|
| 5 |
+
],
|
| 6 |
+
"eos_token": {
|
| 7 |
+
"content": "<|im_end|>",
|
| 8 |
+
"lstrip": false,
|
| 9 |
+
"normalized": false,
|
| 10 |
+
"rstrip": false,
|
| 11 |
+
"single_word": false
|
| 12 |
+
},
|
| 13 |
+
"pad_token": {
|
| 14 |
+
"content": "<|endoftext|>",
|
| 15 |
+
"lstrip": false,
|
| 16 |
+
"normalized": false,
|
| 17 |
+
"rstrip": false,
|
| 18 |
+
"single_word": false
|
| 19 |
+
}
|
| 20 |
+
}
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"added_tokens_decoder": {
|
| 4 |
+
"151643": {
|
| 5 |
+
"content": "<|endoftext|>",
|
| 6 |
+
"lstrip": false,
|
| 7 |
+
"normalized": false,
|
| 8 |
+
"rstrip": false,
|
| 9 |
+
"single_word": false,
|
| 10 |
+
"special": true
|
| 11 |
+
},
|
| 12 |
+
"151644": {
|
| 13 |
+
"content": "<|im_start|>",
|
| 14 |
+
"lstrip": false,
|
| 15 |
+
"normalized": false,
|
| 16 |
+
"rstrip": false,
|
| 17 |
+
"single_word": false,
|
| 18 |
+
"special": true
|
| 19 |
+
},
|
| 20 |
+
"151645": {
|
| 21 |
+
"content": "<|im_end|>",
|
| 22 |
+
"lstrip": false,
|
| 23 |
+
"normalized": false,
|
| 24 |
+
"rstrip": false,
|
| 25 |
+
"single_word": false,
|
| 26 |
+
"special": true
|
| 27 |
+
}
|
| 28 |
+
},
|
| 29 |
+
"additional_special_tokens": [
|
| 30 |
+
"<|im_start|>",
|
| 31 |
+
"<|im_end|>"
|
| 32 |
+
],
|
| 33 |
+
"bos_token": null,
|
| 34 |
+
"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 %}",
|
| 35 |
+
"clean_up_tokenization_spaces": false,
|
| 36 |
+
"eos_token": "<|im_end|>",
|
| 37 |
+
"errors": "replace",
|
| 38 |
+
"model_max_length": 4096,
|
| 39 |
+
"pad_token": "<|endoftext|>",
|
| 40 |
+
"padding_side": "right",
|
| 41 |
+
"split_special_tokens": false,
|
| 42 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 43 |
+
"unk_token": null
|
| 44 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|