NathanFradet commited on
Commit
92fcde6
·
verified ·
1 Parent(s): 6cd021f

Upload NuExtract3-mlx-5bits

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: mlx
3
+ base_model: numind/NuExtract3
4
+ base_model_relation: quantized
5
+ tags:
6
+ - mlx
7
+ - mlx-vlm
8
+ - quantized
9
+ ---
10
+
11
+ # numind/NuExtract3-mlx-5bits
12
+
13
+ MLX quantized version of `numind/NuExtract3`.
14
+
15
+ ## Quantization
16
+
17
+ - mode: `affine`
18
+ - group_size: `64`
19
+ - bits: `5`
20
+ - dtype: `source/default`
21
+ - quant_predicate: `none`
22
+
23
+ ## Usage
24
+
25
+ ```bash
26
+ pip install -U mlx-vlm
27
+ mlx_vlm.generate --model numind/NuExtract3-mlx-5bits --prompt "your prompt"
28
+ ```
chat_template.jinja ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if not messages %}
2
+ {{- raise_exception('No messages provided.') }}
3
+ {%- endif %}
4
+ {%- set image_count = namespace(value=0) %}
5
+ {%- set image_placeholder = '<|vision_start|><|image_pad|><|vision_end|>' -%}
6
+ {%- set mode = mode | default('content') -%}
7
+ {%- if template -%}{%- set mode = 'structured' -%}{%- endif -%}
8
+ {%- if not template and mode == 'structured' %}
9
+ {{- raise_exception('`structured` mode specified but no `template` provided.') }}
10
+ {%- endif %}
11
+ {%- if mode not in ['structured', 'content', 'template-generation', 'document-detection', 'markdown'] -%}{%- set mode = 'content' -%}{%- endif -%}
12
+ {%- if mode == 'markdown' %}{%- set mode = 'content' -%}{%- endif %}
13
+ {%- set enable_thinking = enable_thinking | default(False) -%}
14
+ {%- if mode not in ['structured', 'content'] and enable_thinking %}
15
+ {{- raise_exception('`enable_thinking` can only be `True` for `structured` and `content` modes.') }}
16
+ {%- endif %}
17
+ {%- set has_examples = namespace(flag=false) -%}
18
+ {%- if mode != 'structured' -%}{%- set has_examples = false -%}{%- endif -%}
19
+ {# MACRO TO RENDER MESSAGE CONTENT #}
20
+ {%- macro render_content(content, do_vision_count, is_system_content=false) %}
21
+ {%- if content is string %}
22
+ {{- content }}
23
+ {%- elif content is iterable and content is not mapping %}
24
+ {%- for item in content %}
25
+ {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
26
+ {%- if is_system_content %}
27
+ {{- raise_exception('System message cannot contain images.') }}
28
+ {%- endif %}
29
+ {%- if do_vision_count %}
30
+ {%- set image_count.value = image_count.value + 1 %}
31
+ {%- endif %}
32
+ {%- if add_vision_id %}
33
+ {{- 'Picture ' ~ image_count.value ~ ': ' }}
34
+ {%- endif %}
35
+ {{- '<|vision_start|><|image_pad|><|vision_end|>\n' }}
36
+ {%- elif 'text' in item %}
37
+ {{- item.text + '\n' }}
38
+ {%- else %}
39
+ {{- raise_exception('Unexpected item type in content.') }}
40
+ {%- endif %}
41
+ {%- endfor %}
42
+ {%- elif content is none or content is undefined %}
43
+ {{- '' }}
44
+ {%- else %}
45
+ {{- raise_exception('Unexpected content type.') }}
46
+ {%- endif %}
47
+ {%- endmacro %}
48
+ {# SYSTEM MESSAGE #}
49
+ {%- if messages[0].role == 'system' %}
50
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
51
+ {{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
52
+ {%- endif %}
53
+ {# USER MESSAGE #}
54
+ {{- '<|im_start|>user\n' -}}
55
+ {{- '【task】' + mode|replace("-", " ") + '\n' -}}
56
+ {# Template Section (for structured task): specifies template, instructions, examples, previous_output #}
57
+ {%- if mode == 'structured' -%}
58
+ {{- '【template_start】' + template + '【template_end】\n' -}}
59
+ {# Instructions Section #}
60
+ {%- if instructions -%}
61
+ {{- '【instructions_start】' + instructions + '【instructions_end】\n'-}}
62
+ {%- endif -%}
63
+ {# Examples Section (only for extraction tasks) #}
64
+ {%- for message in messages -%}
65
+ {%- if message.role == 'developer' and 'content' in message -%}
66
+ {# Validate that there is at least one input and one output contents #}
67
+ {%- set example_inputs = message.content[:-1] -%}
68
+ {%- set example_output_part = message.content[-1] -%}
69
+ {%- if example_inputs|length > 0 -%}
70
+ {%- if not has_examples.flag -%}
71
+ {{- '【examples_start】\n' -}}
72
+ {%- set has_examples.flag = true -%}
73
+ {%- endif -%}
74
+ {{- '【example_input_start】' + render_content(example_inputs, true)|trim + '【example_input_end】\n' -}}
75
+ {# Example output: only keep the text of the first output content #}
76
+ {%- set output_text = '' -%}
77
+ {%- if example_output_part is string -%}
78
+ {%- set output_text = example_output_part -%}
79
+ {%- elif example_output_part.text is defined -%}
80
+ {%- set output_text = example_output_part.text -%}
81
+ {%- endif -%}
82
+ {{- '【example_output_start】' + output_text|trim + '【example_output_end】\n' -}}
83
+ {%- if loop.last and has_examples.flag -%}
84
+ {{- '【examples_end】\n' -}}
85
+ {%- endif -%}
86
+ {%- endif -%}
87
+ {%- endif -%}
88
+ {%- endfor -%}
89
+ {# Previous Output Section #}
90
+ {%- if previous_output -%}
91
+ {{- '【previous_output_start】' + previous_output + '【previous_output_end】\n' -}}
92
+ {%- endif -%}
93
+ {%- endif -%}
94
+ {{- '【document_start】\n' -}}
95
+ {# PROCESS PROVIDED USER MESSAGES (RENDERED INTO A SINGLE ONE) #}
96
+ {%- for message in messages -%}
97
+ {%- if message.role == "system" %}
98
+ {%- if not loop.first %}
99
+ {{- raise_exception('System message must be at the beginning.') }}
100
+ {%- endif %}
101
+ {%- elif message.role == 'user' and message.name != "example" -%}
102
+ {%- set content = render_content(message.content, true)|trim %}
103
+ {{- content + '\n' -}}
104
+ {# {%- elif message.role == 'assistant' and not loop.last %}
105
+ llama.cpp renders a synthetic init example with an assistant turn in
106
+ the middle; ignore it so valid NuExtract prompts render unchanged.
107
+ {{- raise_exception('Assistant message must be at the end.') }} #}
108
+ {%- endif %}
109
+ {%- endfor -%}
110
+ {{- '【document_end】<|im_end|>\n' -}}
111
+ {# ASSISTANT MESSAGE #}
112
+ {%- if messages[-1].role == 'assistant' %}
113
+ {%- if add_generation_prompt -%}
114
+ {{- raise_exception('`add_generation_prompt` can only be `True` when no assistant message is provided.') }}
115
+ {%- endif %}
116
+ {%- set content = render_content(messages[-1].content, true)|trim %}
117
+ {%- set reasoning_content = '' %}
118
+ {%- if messages[-1].reasoning_content is string %}
119
+ {%- set reasoning_content = messages[-1].reasoning_content %}
120
+ {%- else %}
121
+ {%- if '</think>' in content %}
122
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
123
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
124
+ {%- endif %}
125
+ {%- endif %}
126
+ {%- set reasoning_content = reasoning_content|trim %}
127
+ {% generation %}
128
+ {{- '<|im_start|>assistant\n<think>\n' + reasoning_content + '\n</think>\n\n' + content + '<|im_end|>\n' -}}
129
+ {% endgeneration %}
130
+ {%- endif -%}
131
+ {# GENERATION PROMPT #}
132
+ {%- if add_generation_prompt -%}
133
+ {{- '<|im_start|>assistant\n' -}}
134
+ {%- if not enable_thinking -%}
135
+ {{- '<think>\n\n</think>\n\n' -}}
136
+ {%- else %}
137
+ {{- '<think>\n' -}}
138
+ {%- endif %}
139
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3_5ForConditionalGeneration"
4
+ ],
5
+ "bos_token_id": null,
6
+ "dtype": "bfloat16",
7
+ "eos_token_id": 248044,
8
+ "image_token_id": 248056,
9
+ "model_type": "qwen3_5",
10
+ "pad_token_id": 248044,
11
+ "quantization": {
12
+ "group_size": 64,
13
+ "bits": 5,
14
+ "mode": "affine"
15
+ },
16
+ "quantization_config": {
17
+ "group_size": 64,
18
+ "bits": 5,
19
+ "mode": "affine"
20
+ },
21
+ "text_config": {
22
+ "attention_bias": false,
23
+ "attention_dropout": 0.0,
24
+ "attn_output_gate": true,
25
+ "bos_token_id": null,
26
+ "dtype": "bfloat16",
27
+ "eos_token_id": 248044,
28
+ "full_attention_interval": 4,
29
+ "head_dim": 256,
30
+ "hidden_act": "silu",
31
+ "hidden_size": 2560,
32
+ "initializer_range": 0.02,
33
+ "intermediate_size": 9216,
34
+ "layer_types": [
35
+ "linear_attention",
36
+ "linear_attention",
37
+ "linear_attention",
38
+ "full_attention",
39
+ "linear_attention",
40
+ "linear_attention",
41
+ "linear_attention",
42
+ "full_attention",
43
+ "linear_attention",
44
+ "linear_attention",
45
+ "linear_attention",
46
+ "full_attention",
47
+ "linear_attention",
48
+ "linear_attention",
49
+ "linear_attention",
50
+ "full_attention",
51
+ "linear_attention",
52
+ "linear_attention",
53
+ "linear_attention",
54
+ "full_attention",
55
+ "linear_attention",
56
+ "linear_attention",
57
+ "linear_attention",
58
+ "full_attention",
59
+ "linear_attention",
60
+ "linear_attention",
61
+ "linear_attention",
62
+ "full_attention",
63
+ "linear_attention",
64
+ "linear_attention",
65
+ "linear_attention",
66
+ "full_attention"
67
+ ],
68
+ "linear_conv_kernel_dim": 4,
69
+ "linear_key_head_dim": 128,
70
+ "linear_num_key_heads": 16,
71
+ "linear_num_value_heads": 32,
72
+ "linear_value_head_dim": 128,
73
+ "mamba_ssm_dtype": "float32",
74
+ "max_position_embeddings": 262144,
75
+ "mlp_only_layers": [],
76
+ "model_type": "qwen3_5_text",
77
+ "mtp_num_hidden_layers": 1,
78
+ "mtp_use_dedicated_embeddings": false,
79
+ "num_attention_heads": 16,
80
+ "num_hidden_layers": 32,
81
+ "num_key_value_heads": 4,
82
+ "pad_token_id": null,
83
+ "partial_rotary_factor": 0.25,
84
+ "rms_norm_eps": 1e-06,
85
+ "rope_parameters": {
86
+ "mrope_interleaved": true,
87
+ "mrope_section": [
88
+ 11,
89
+ 11,
90
+ 10
91
+ ],
92
+ "partial_rotary_factor": 0.25,
93
+ "rope_theta": 10000000,
94
+ "rope_type": "default"
95
+ },
96
+ "tie_word_embeddings": true,
97
+ "use_cache": true,
98
+ "vocab_size": 248320
99
+ },
100
+ "tie_word_embeddings": true,
101
+ "transformers_version": "5.5.4",
102
+ "video_token_id": 248057,
103
+ "vision_config": {
104
+ "deepstack_visual_indexes": [],
105
+ "depth": 24,
106
+ "dtype": "bfloat16",
107
+ "hidden_act": "gelu_pytorch_tanh",
108
+ "hidden_size": 1024,
109
+ "in_channels": 3,
110
+ "initializer_range": 0.02,
111
+ "intermediate_size": 4096,
112
+ "model_type": "qwen3_5",
113
+ "num_heads": 16,
114
+ "num_position_embeddings": 2304,
115
+ "out_hidden_size": 2560,
116
+ "patch_size": 16,
117
+ "spatial_merge_size": 2,
118
+ "temporal_patch_size": 2
119
+ },
120
+ "vision_end_token_id": 248054,
121
+ "vision_start_token_id": 248053
122
+ }
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "eos_token_id": 248044,
4
+ "transformers_version": "5.5.4",
5
+ "use_cache": true
6
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:59d7a10a7a5ff6da03d3d31ffe418de847a6ad53328aaec5360fcebca3dc0465
3
+ size 3559898117
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
processor_config.json ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_processor": {
3
+ "do_convert_rgb": true,
4
+ "do_normalize": true,
5
+ "do_rescale": true,
6
+ "image_mean": [
7
+ 0.5,
8
+ 0.5,
9
+ 0.5
10
+ ],
11
+ "image_processor_type": "Qwen3VLImageProcessor",
12
+ "image_std": [
13
+ 0.5,
14
+ 0.5,
15
+ 0.5
16
+ ],
17
+ "max_pixels": 16777216,
18
+ "merge_size": 2,
19
+ "min_pixels": 65536,
20
+ "patch_size": 16,
21
+ "rescale_factor": 0.00392156862745098,
22
+ "temporal_patch_size": 2
23
+ },
24
+ "processor_class": "Qwen3VLProcessor",
25
+ "video_processor": {
26
+ "do_convert_rgb": true,
27
+ "do_normalize": true,
28
+ "do_rescale": true,
29
+ "fps": 2.0,
30
+ "image_mean": [
31
+ 0.5,
32
+ 0.5,
33
+ 0.5
34
+ ],
35
+ "image_std": [
36
+ 0.5,
37
+ 0.5,
38
+ 0.5
39
+ ],
40
+ "max_frames": 768,
41
+ "max_pixels": 786432,
42
+ "merge_size": 2,
43
+ "min_frames": 4,
44
+ "min_pixels": 131072,
45
+ "patch_size": 16,
46
+ "rescale_factor": 0.00392156862745098,
47
+ "temporal_patch_size": 2,
48
+ "video_processor_type": "Qwen3VLVideoProcessor"
49
+ }
50
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:87a7830d63fcf43bf241c3c5242e96e62dd3fdc29224ca26fed8ea333db72de4
3
+ size 19989343
tokenizer_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "audio_bos_token": "<|audio_start|>",
4
+ "audio_eos_token": "<|audio_end|>",
5
+ "audio_token": "<|audio_pad|>",
6
+ "backend": "tokenizers",
7
+ "bos_token": null,
8
+ "clean_up_tokenization_spaces": false,
9
+ "eos_token": "<|im_end|>",
10
+ "errors": "replace",
11
+ "image_token": "<|image_pad|>",
12
+ "is_local": true,
13
+ "local_files_only": false,
14
+ "model_max_length": 262144,
15
+ "model_specific_special_tokens": {
16
+ "audio_bos_token": "<|audio_start|>",
17
+ "audio_eos_token": "<|audio_end|>",
18
+ "audio_token": "<|audio_pad|>",
19
+ "image_token": "<|image_pad|>",
20
+ "video_token": "<|video_pad|>",
21
+ "vision_bos_token": "<|vision_start|>",
22
+ "vision_eos_token": "<|vision_end|>"
23
+ },
24
+ "pad_token": "<|endoftext|>",
25
+ "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
26
+ "processor_class": "Qwen3VLProcessor",
27
+ "split_special_tokens": false,
28
+ "tokenizer_class": "TokenizersBackend",
29
+ "unk_token": null,
30
+ "video_token": "<|video_pad|>",
31
+ "vision_bos_token": "<|vision_start|>",
32
+ "vision_eos_token": "<|vision_end|>"
33
+ }