qgallouedec HF Staff commited on
Commit
140cb85
·
verified ·
1 Parent(s): e4b39e2

Upload Lfm2VlForConditionalGeneration

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,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags:
4
+ - trl
5
+ ---
6
+
7
+ # Tiny Lfm2VlForConditionalGeneration
8
+
9
+ This is a minimal model built for unit tests in the [TRL](https://github.com/huggingface/trl) library.
chat_template.jinja ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{- bos_token -}}
2
+ {%- set preserve_thinking = preserve_thinking | default(false) -%}
3
+
4
+ {%- macro format_arg_value(arg_value) -%}
5
+ {%- if arg_value is string -%}
6
+ {{- "'" + (arg_value | replace("\\", "\\\\") | replace("'", "\\'") | replace("\n", "\\n") | replace("\r", "\\r")) + "'" -}}
7
+ {%- elif arg_value is mapping or arg_value is iterable -%}
8
+ {{- arg_value | tojson -}}
9
+ {%- else -%}
10
+ {{- arg_value | string -}}
11
+ {%- endif -%}
12
+ {%- endmacro -%}
13
+
14
+ {%- macro parse_content(content) -%}
15
+ {%- if content is string -%}
16
+ {{- content -}}
17
+ {%- elif content is mapping -%}
18
+ {{- content | tojson -}}
19
+ {%- elif content is iterable -%}
20
+ {%- set _ns = namespace(result="") -%}
21
+ {%- for item in content -%}
22
+ {%- if item is string -%}
23
+ {%- set _ns.result = _ns.result + item -%}
24
+ {%- elif item is mapping and item.get("type") == "image" -%}
25
+ {%- set _ns.result = _ns.result + "<image>" -%}
26
+ {%- elif item is mapping and item.get("type") == "text" -%}
27
+ {%- set _ns.result = _ns.result + ((item.get("text") or "") | string) -%}
28
+ {%- else -%}
29
+ {%- set _ns.result = _ns.result + (item | tojson) -%}
30
+ {%- endif -%}
31
+ {%- endfor -%}
32
+ {{- _ns.result -}}
33
+ {%- endif -%}
34
+ {%- endmacro -%}
35
+
36
+ {%- macro render_tool_calls(tool_calls) -%}
37
+ {%- set tool_calls_ns = namespace(tool_calls=[]) -%}
38
+ {%- for tool_call in tool_calls -%}
39
+ {%- set func = tool_call["function"] if "function" in tool_call else tool_call -%}
40
+ {%- set func_name = func["name"] -%}
41
+ {%- set func_args = func.get("arguments") -%}
42
+ {%- set args_ns = namespace(arg_strings=[]) -%}
43
+ {%- if func_args is mapping -%}
44
+ {%- for arg_name, arg_value in func_args.items() -%}
45
+ {%- set args_ns.arg_strings = args_ns.arg_strings + [arg_name + "=" + format_arg_value(arg_value)] -%}
46
+ {%- endfor -%}
47
+ {%- elif func_args is string and (func_args | trim) not in ["", "{}", "null"] -%}
48
+ {{- raise_exception("Tool call arguments must be a mapping, got a JSON-encoded string: parse arguments with json.loads() before applying the chat template") -}}
49
+ {%- endif -%}
50
+ {%- set tool_calls_ns.tool_calls = tool_calls_ns.tool_calls + [func_name + "(" + (args_ns.arg_strings | join(", ")) + ")"] -%}
51
+ {%- endfor -%}
52
+ {{- "<|tool_call_start|>[" + (tool_calls_ns.tool_calls | join(", ")) + "]<|tool_call_end|>" -}}
53
+ {%- endmacro -%}
54
+
55
+ {%- set ns = namespace(system_prompt="", last_user_index=-1) -%}
56
+ {%- if messages and messages[0]["role"] == "system" -%}
57
+ {%- if messages[0].get("content") -%}
58
+ {%- set ns.system_prompt = parse_content(messages[0]["content"]) -%}
59
+ {%- endif -%}
60
+ {%- set messages = messages[1:] -%}
61
+ {%- endif -%}
62
+ {%- if tools -%}
63
+ {%- set ns.system_prompt = ns.system_prompt + ("\n" if ns.system_prompt else "") + "List of tools: [" -%}
64
+ {%- for tool in tools -%}
65
+ {%- if tool is not string -%}
66
+ {%- set tool = tool | tojson -%}
67
+ {%- endif -%}
68
+ {%- set ns.system_prompt = ns.system_prompt + tool -%}
69
+ {%- if not loop.last -%}
70
+ {%- set ns.system_prompt = ns.system_prompt + ", " -%}
71
+ {%- endif -%}
72
+ {%- endfor -%}
73
+ {%- set ns.system_prompt = ns.system_prompt + "]" -%}
74
+ {%- endif -%}
75
+ {%- if ns.system_prompt -%}
76
+ {{- "<|im_start|>system\n" + ns.system_prompt + "<|im_end|>\n" -}}
77
+ {%- endif -%}
78
+ {%- for message in messages -%}
79
+ {%- if message["role"] == "user" -%}
80
+ {%- set ns.last_user_index = loop.index0 -%}
81
+ {%- endif -%}
82
+ {%- endfor -%}
83
+ {%- for message in messages -%}
84
+ {{- "<|im_start|>" + message.role + "\n" -}}
85
+ {%- if message.role == "assistant" -%}
86
+ {%- generation -%}
87
+ {%- set keep_thinking = preserve_thinking or loop.index0 > ns.last_user_index -%}
88
+ {%- set thinking = message.thinking or message.reasoning or message.reasoning_content -%}
89
+ {%- set thinking = thinking if thinking is string else "" -%}
90
+ {%- if thinking and keep_thinking -%}
91
+ {{- "<think>" + thinking + "</think>" -}}
92
+ {%- endif -%}
93
+ {%- set _cfm_tag = "CONTINUE_FINAL_MESSAGE_TAG " -%}
94
+ {%- set _has_cfm = false -%}
95
+ {%- set content = "" -%}
96
+ {%- if message.get("content") -%}
97
+ {%- set content = parse_content(message.content) -%}
98
+ {%- endif -%}
99
+ {%- if not keep_thinking and "</think>" in content -%}
100
+ {%- set content = content.split("</think>")[-1] | trim -%}
101
+ {%- endif -%}
102
+ {%- if content.endswith(_cfm_tag) -%}
103
+ {%- set _has_cfm = true -%}
104
+ {%- set _trunc_len = (content | length) - (_cfm_tag | length) -%}
105
+ {%- set content = content[:_trunc_len] -%}
106
+ {%- endif -%}
107
+ {{- content -}}
108
+ {%- if message.tool_calls -%}
109
+ {{- render_tool_calls(message.tool_calls) -}}
110
+ {%- endif -%}
111
+ {%- if _has_cfm -%}
112
+ {{- _cfm_tag -}}
113
+ {%- endif -%}
114
+ {{- "<|im_end|>\n" -}}
115
+ {%- endgeneration -%}
116
+ {%- else %}
117
+ {%- if message.get("content") -%}
118
+ {{- parse_content(message["content"]) -}}
119
+ {%- endif -%}
120
+ {{- "<|im_end|>\n" -}}
121
+ {%- endif %}
122
+ {%- endfor -%}
123
+ {%- if add_generation_prompt -%}
124
+ {{- "<|im_start|>assistant\n" -}}
125
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Lfm2VlForConditionalGeneration"
4
+ ],
5
+ "auto_map": {},
6
+ "bos_token_id": 124894,
7
+ "do_image_splitting": true,
8
+ "do_resize": true,
9
+ "downsample_factor": 2,
10
+ "dtype": "bfloat16",
11
+ "encoder_patch_size": 16,
12
+ "eos_token_id": 124900,
13
+ "freeze_language_model": false,
14
+ "freeze_multi_modal_projector": false,
15
+ "freeze_vision_tower": false,
16
+ "image_token_id": 124907,
17
+ "keep_trainable_parameters_fp32": true,
18
+ "language_model_lr_multiplier": 1.0,
19
+ "lfm2_attention_backend": "flash_varlen",
20
+ "lfm2_attention_fusion": "fused_linear",
21
+ "lfm2_flash_varlen_blhd_fastpath": false,
22
+ "lfm2_frozen_input_grad_only_linear": true,
23
+ "lfm2_mlp_fusion": "triton_swiglu",
24
+ "lfm2_rmsnorm_fusion": "none",
25
+ "lfm2_short_conv_frozen_recompute_in_proj": 0,
26
+ "lfm2_torch_compile_clone_outputs": false,
27
+ "lfm2_torch_compile_disable_cudagraphs": true,
28
+ "lfm2_torch_compile_dynamic": true,
29
+ "lfm2_torch_compile_fullgraph": false,
30
+ "lfm2_torch_compile_layers": "none",
31
+ "lfm2_torch_compile_mlp": false,
32
+ "lfm2_torch_compile_mode": "reduce-overhead",
33
+ "lfm2_vl_direct_image_merge_by_shape": true,
34
+ "lfm2_vl_forward_dtype": "bf16",
35
+ "lfm2_vl_frozen_vision_chunk_size": 2048,
36
+ "lfm2_vl_grouped_image_projector": true,
37
+ "lfm2_vl_grouped_vision_by_patch_count": false,
38
+ "lfm2_vl_grouped_vision_by_shape": true,
39
+ "lfm2_vl_inplace_image_merge": true,
40
+ "lfm2_vl_siglip_packed_vision": true,
41
+ "lfm2_vl_torch_compile_vision_encoder": true,
42
+ "lfm2_vl_torch_compile_vision_encoder_mode": "whole",
43
+ "lm_head_loss_mask_only": true,
44
+ "max_image_tokens": 256,
45
+ "max_num_patches": 1024,
46
+ "max_pixels_tolerance": 2.0,
47
+ "max_tiles": 10,
48
+ "min_image_tokens": 64,
49
+ "min_tiles": 1,
50
+ "model_type": "lfm2_vl",
51
+ "pad_token_id": 124893,
52
+ "projector_bias": true,
53
+ "projector_hidden_act": "gelu",
54
+ "projector_hidden_size": 32,
55
+ "projector_lr_multiplier": 1.0,
56
+ "projector_use_layernorm": false,
57
+ "siglip2_layernorm_fusion": "liger",
58
+ "text_config": {
59
+ "architectures": [
60
+ "Lfm2ForCausalLM"
61
+ ],
62
+ "block__name_mlp": "parallel_mlp_merged",
63
+ "block_auto_adjust_ff_dim": false,
64
+ "block_dim": 2048,
65
+ "block_ffn_dim_multiplier": 1.0,
66
+ "block_ffn_te_autocast": false,
67
+ "block_ffn_use_quantized_params": false,
68
+ "block_mlp_init_scale": 1.0,
69
+ "block_multiple_of": 256,
70
+ "block_norm_eps": 1e-05,
71
+ "block_out_init_scale": 1.0,
72
+ "block_use_swiglu": true,
73
+ "block_use_xavier_init": true,
74
+ "bos_token_id": 124894,
75
+ "conv_L_cache": 3,
76
+ "conv_bias": false,
77
+ "conv_dim": 2048,
78
+ "conv_use_xavier_init": true,
79
+ "dtype": "bfloat16",
80
+ "eos_token_id": 124900,
81
+ "hidden_size": 8,
82
+ "initializer_range": 0.02,
83
+ "intermediate_size": 32,
84
+ "layer_types": [
85
+ "conv",
86
+ "full_attention"
87
+ ],
88
+ "lfm2_attention_backend": "flash_varlen",
89
+ "lfm2_flash_varlen_blhd_fastpath": false,
90
+ "lfm2_frozen_input_grad_only_linear": true,
91
+ "max_position_embeddings": 128000,
92
+ "mm_config_image_embedder": {
93
+ "activation_checkpointing_layer_stride": 0,
94
+ "attn_implementation": "sdpa",
95
+ "cuda_sync_points": [],
96
+ "downsample": 2,
97
+ "encoder_load_balance": false,
98
+ "hidden_dim": 2048,
99
+ "hidden_state_index": -1,
100
+ "layer_norm": false,
101
+ "max_batch_size": 1024,
102
+ "pretrained_model_name_or_path": "google/siglip2-so400m-patch16-naflex",
103
+ "set_activation_checkpointing": false,
104
+ "use_image_special_tokens": true,
105
+ "use_pooling_head": false,
106
+ "use_slice_special_tokens": false,
107
+ "use_torch_pixel_unshuffle": false
108
+ },
109
+ "model_type": "lfm2",
110
+ "norm_eps": 1e-05,
111
+ "num_attention_heads": 4,
112
+ "num_heads": 32,
113
+ "num_hidden_layers": 2,
114
+ "num_key_value_heads": 2,
115
+ "output_softcap": 0.0,
116
+ "pad_token_id": 124893,
117
+ "rope_parameters": {
118
+ "rope_theta": 1000000.0,
119
+ "rope_type": "default"
120
+ },
121
+ "tie_embedding": true,
122
+ "tie_word_embeddings": true,
123
+ "use_cache": true,
124
+ "use_pos_enc": true,
125
+ "vocab_size": 128000
126
+ },
127
+ "tie_word_embeddings": true,
128
+ "tile_size": 512,
129
+ "transformers_version": "5.0.0",
130
+ "use_image_special_tokens": true,
131
+ "use_thumbnail": true,
132
+ "vision_config": {
133
+ "attention_dropout": 0.0,
134
+ "dtype": "bfloat16",
135
+ "hidden_act": "gelu_pytorch_tanh",
136
+ "hidden_size": 16,
137
+ "intermediate_size": 32,
138
+ "layer_norm_eps": 1e-06,
139
+ "model_type": "siglip2_vision_model",
140
+ "num_attention_heads": 4,
141
+ "num_channels": 3,
142
+ "num_hidden_layers": 2,
143
+ "num_patches": 256,
144
+ "patch_size": 16,
145
+ "vision_use_head": false
146
+ },
147
+ "vision_tower_lr_multiplier": 1.0
148
+ }
generation_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 124894,
4
+ "do_sample": true,
5
+ "eos_token_id": [
6
+ 124900
7
+ ],
8
+ "output_attentions": false,
9
+ "output_hidden_states": false,
10
+ "pad_token_id": 124893,
11
+ "repetition_penalty": 1.0,
12
+ "temperature": 0.2,
13
+ "top_k": 50,
14
+ "transformers_version": "5.0.0",
15
+ "use_cache": true
16
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d95dc9b19ca8a18f78d50f40a99f1704e34be272c057d2720a2a93a7d05bf3e3
3
+ size 2106448
processor_config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_processor": {
3
+ "data_format": "channels_first",
4
+ "do_image_splitting": true,
5
+ "do_normalize": true,
6
+ "do_pad": true,
7
+ "do_rescale": true,
8
+ "do_resize": true,
9
+ "downsample_factor": 2,
10
+ "encoder_patch_size": 16,
11
+ "image_mean": [
12
+ 0.5,
13
+ 0.5,
14
+ 0.5
15
+ ],
16
+ "image_processor_type": "Lfm2VlImageProcessorFast",
17
+ "image_std": [
18
+ 0.5,
19
+ 0.5,
20
+ 0.5
21
+ ],
22
+ "max_image_tokens": 256,
23
+ "max_num_patches": 1024,
24
+ "max_pixels_tolerance": 2.0,
25
+ "max_tiles": 10,
26
+ "min_image_tokens": 64,
27
+ "min_tiles": 1,
28
+ "resample": 3,
29
+ "rescale_factor": 0.00392156862745098,
30
+ "return_row_col_info": true,
31
+ "size": {
32
+ "height": 512,
33
+ "width": 512
34
+ },
35
+ "tile_size": 512,
36
+ "use_thumbnail": true
37
+ },
38
+ "processor_class": "Lfm2VlProcessor"
39
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8096ecb9f54599d756c8de728a598a340bc1e43c0deb77ddd62456c38349fcee
3
+ size 17905750
tokenizer_config.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "<|startoftext|>",
4
+ "clean_up_tokenization_spaces": false,
5
+ "eos_token": "<|im_end|>",
6
+ "is_local": false,
7
+ "legacy": false,
8
+ "local_files_only": false,
9
+ "max_length": null,
10
+ "model_max_length": 1000000000000000019884624838656,
11
+ "pad_to_multiple_of": null,
12
+ "pad_token": "<|pad|>",
13
+ "pad_token_type_id": 0,
14
+ "padding_side": "left",
15
+ "processor_class": "Lfm2VlProcessor",
16
+ "tokenizer_class": "TokenizersBackend",
17
+ "use_default_system_prompt": false
18
+ }