Update files for compatibility with transformers

#13
by guarin HF Staff - opened
chat_template.jinja ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- for message in messages %}
2
+ {%- if message['content'] is string %}
3
+ {{- message['content'] }}
4
+ {%- else %}
5
+ {%- for content in message['content'] | selectattr('type', 'equalto', 'image') %}
6
+ {{- '<image>' }}
7
+ {%- endfor %}
8
+ {%- for content in message['content'] | selectattr('type', 'equalto', 'text') %}
9
+ {{- content['text'] }}
10
+ {%- endfor %}
11
+ {%- endif %}
12
+ {%- if message['role'] == 'assistant' %}
13
+ {{- eos_token }}
14
+ {%- endif %}
15
+ {%- endfor %}
config.json CHANGED
@@ -51,7 +51,7 @@
51
  "vocab_size": 129280,
52
  "sliding_window_size": 128
53
  },
54
- "model_type": "unlimited-ocr",
55
  "projector_config": {
56
  "input_dim": 2048,
57
  "model_type": "mlp_projector",
 
51
  "vocab_size": 129280,
52
  "sliding_window_size": 128
53
  },
54
+ "model_type": "unlimited_ocr",
55
  "projector_config": {
56
  "input_dim": 2048,
57
  "model_type": "mlp_projector",
generation_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 0,
3
+ "eos_token_id": 1,
4
+ "no_repeat_ngram_size": 35,
5
+ "no_repeat_ngram_window_size": 128,
6
+ "max_new_tokens": 32768,
7
+ "transformers_version": "5.14.0.dev0",
8
+ "use_cache": true
9
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2bc48a7a110061ea58fff65d3169367eebe3aee371ca6968dc2219c1b2855fc6
3
+ size 6672547120
modeling_unlimitedocr.py CHANGED
@@ -154,7 +154,6 @@ def process_image_with_refs(image, ref_texts, output_path, image_prefix=''):
154
 
155
 
156
 
157
-
158
  def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):
159
  best_ratio_diff = float('inf')
160
  best_ratio = (1, 1)
@@ -426,7 +425,7 @@ class TPSTextStreamer(TextStreamer):
426
 
427
 
428
  class UnlimitedOCRConfig(DeepseekV2Config):
429
- model_type = "unlimited-ocr"
430
 
431
  class UnlimitedOCRModel(DeepseekV2Model):
432
  config_class = UnlimitedOCRConfig
@@ -879,10 +878,6 @@ class UnlimitedOCRForCausalLM(DeepseekV2ForCausalLM):
879
  # elif base_size == 640:
880
  # valid_img_tokens += int(100 * ratio)
881
 
882
-
883
-
884
-
885
-
886
  images_list.append(image_transform(global_view).to(torch.bfloat16))
887
 
888
  # global_view_tensor = image_transform(global_view).to(torch.bfloat16)
@@ -1296,4 +1291,4 @@ class UnlimitedOCRForCausalLM(DeepseekV2ForCausalLM):
1296
  with open(f'{output_path}/result.md', 'w', encoding='utf-8') as afile:
1297
  afile.write(outputs)
1298
 
1299
- return outputs, output_tokens
 
154
 
155
 
156
 
 
157
  def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):
158
  best_ratio_diff = float('inf')
159
  best_ratio = (1, 1)
 
425
 
426
 
427
  class UnlimitedOCRConfig(DeepseekV2Config):
428
+ model_type = "unlimited_ocr"
429
 
430
  class UnlimitedOCRModel(DeepseekV2Model):
431
  config_class = UnlimitedOCRConfig
 
878
  # elif base_size == 640:
879
  # valid_img_tokens += int(100 * ratio)
880
 
 
 
 
 
881
  images_list.append(image_transform(global_view).to(torch.bfloat16))
882
 
883
  # global_view_tensor = image_transform(global_view).to(torch.bfloat16)
 
1291
  with open(f'{output_path}/result.md', 'w', encoding='utf-8') as afile:
1292
  afile.write(outputs)
1293
 
1294
+ return outputs, output_tokens
preprocessor_config.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_processor_type": "UnlimitedOcrImageProcessor",
3
+ "do_convert_rgb": true,
4
+ "do_resize": true,
5
+ "resample": 3,
6
+ "do_rescale": true,
7
+ "rescale_factor": 0.00392156862745098,
8
+ "do_normalize": true,
9
+ "crop_to_patches": true,
10
+ "min_patches": 2,
11
+ "max_patches": 32,
12
+ "tile_size": 640,
13
+ "background_color": [127, 127, 127],
14
+ "size": {
15
+ "height": 1024,
16
+ "width": 1024
17
+ },
18
+ "image_mean": [0.5, 0.5, 0.5],
19
+ "image_std": [0.5, 0.5, 0.5]
20
+ }
processor_config.json CHANGED
@@ -21,8 +21,8 @@
21
  "image_token": "<image>",
22
  "mask_prompt": false,
23
  "normalize": true,
24
- "pad_token": "<\uff5c\u2581pad\u2581\uff5c>",
25
  "patch_size": 16,
26
- "processor_class": "UnlimitedOCRHFProcessor",
27
  "sft_format": "unlimitedocr"
28
  }
 
21
  "image_token": "<image>",
22
  "mask_prompt": false,
23
  "normalize": true,
24
+ "pad_token": "<|▁pad▁|>",
25
  "patch_size": 16,
26
+ "processor_class": "UnlimitedOcrProcessor",
27
  "sft_format": "unlimitedocr"
28
  }