GarageCyril commited on
Commit
f622778
·
0 Parent(s):

Super-squash branch 'main' using huggingface_hub

Browse files
.gitattributes ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz 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
+ onnx/decoder_model_merged_q4.onnx_data filter=lfs diff=lfs merge=lfs -text
37
+ onnx/embed_tokens_quantized.onnx_data filter=lfs diff=lfs merge=lfs -text
38
+ onnx/vision_encoder_quantized.onnx_data filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: lfm-open-license-v1.0
4
+ license_link: https://huggingface.co/LiquidAI/LFM2.5-VL-450M/blob/main/LICENSE
5
+ base_model: LiquidAI/LFM2.5-VL-450M
6
+ pipeline_tag: image-text-to-text
7
+ library_name: transformers.js
8
+ tags:
9
+ - ad-detection
10
+ - ad-blocking
11
+ - onnx
12
+ - webgpu
13
+ - transformers-js
14
+ - lfm2.5
15
+ - vision-language-model
16
+ - browser
17
+ ---
18
+
19
+ # Minus-v0.1 — a vision model that blocks ads by *looking* at them
20
+
21
+ **Minus-v0.1** is a 450M-parameter vision–language model fine-tuned to answer one question about an image: **"Is this an advertisement?"** It powers the [Minus Chrome extension](https://github.com/garagehq/Minus-chrome-extension), where it runs **entirely in the browser** (transformers.js + ONNX Runtime Web on WebGPU) and covers detected ads with language flashcards — no filter lists, no servers, no telemetry. It is the browser sibling of the [minus](https://github.com/garagehq/minus) HDMI ad-blocking device.
22
+
23
+ Instead of matching URLs or DOM patterns like a classic ad blocker, Minus classifies **pixels**: screenshots of page elements, video frames, and iframes. That means it generalizes to first-party ads, sponsored tiles, native placements and streaming-TV commercials that filter lists can't see — and it keeps working when ad-tech rotates domains.
24
+
25
+ - **Base model:** [LiquidAI/LFM2.5-VL-450M](https://huggingface.co/LiquidAI/LFM2.5-VL-450M)
26
+ - **Task:** binary ad / not-ad classification via a single-token answer (`Yes` / `No`), scored as `p(ad) = P(Yes)`
27
+ - **Prompt:** `Is this an advertisement? Answer Yes or No.`
28
+ - **Format in this repo:** ONNX, quantized for the browser (~430 MB total): q4 decoder, q8 token embeddings, q8 vision encoder. **WebGPU required** (the q4 decoder uses `GatherBlockQuantized`, which onnxruntime-web's WASM backend doesn't implement).
29
+
30
+ ## How it was trained
31
+
32
+ Minus-v0.1 is **iteration 28** of a months-long training campaign (the first 27 iterations were exploration: base-model selection between FastVLM / SmolVLM / CLIP-style classifiers / LFM2.5-VL, then successive rounds of hard-negative and hard-positive mining, each gated by frozen benchmarks and *live* in-browser soak tests).
33
+
34
+ **Recipe (frozen across late iterations):** LoRA (r=16, α=32) on the language-model blocks only — vision tower and projector stay frozen — lr 2e-4, 3 epochs, effective batch 32. Trained on a single NVIDIA Jetson AGX Thor (128 GB unified memory). The LoRA is merged before export.
35
+
36
+ **Data (not released):** ~81,600 training samples across two domains:
37
+
38
+ - **Streaming TV** — frames sampled by the minus HDMI device during real viewing sessions: commercials vs. program content. The freshest batch (19,328 frames) went through a **two-judge audit** (previous model + an independent VLM judge, disagreements human-reviewed) before training; notably, one device-labeled bucket turned out to be **72% mislabeled** and was corrected — training on raw labels would have poisoned the ad class.
39
+ - **Web pages** — display/banner ad creatives vs. hard negatives mined from real browsing: editorial content, product photography (e-commerce tiles that *look* like ads), site self-promo and UI elements, cookie/consent banners, chat widgets, site headers, and scale-jittered variants of all of these to survive browser resampling.
40
+
41
+ Roughly **45% of the web-ad positives are native/chum-box style** (Taboola/Outbrain-like), which classic blockers struggle with.
42
+
43
+ ## Evaluation
44
+
45
+ All gates are held-out sets that were **frozen before** this iteration trained; the live number comes from headed-browser soaks on real sites.
46
+
47
+ | benchmark | result |
48
+ |---|---|
49
+ | Streaming holdout (1,956 frames, hand-verified) | **99.90%** ad recall / **98.06%** non-ad recall |
50
+ | Static-web bench (999 images) @ shipping gate | **98.0%** ad recall, **11** false positives |
51
+ | Product-image FP holdout (199 ad-look-alike product shots) | **1/199** false positives |
52
+ | Live in-browser precision (month of soak tests, real sites) | **~90–94%** of covered elements are actually ads |
53
+
54
+ The static-web PR curve dominates or ties the previous production model at **every** operating point with non-ad recall ≥ 95%.
55
+
56
+ ## Using the model
57
+
58
+ ### transformers.js (what the extension does)
59
+
60
+ ```js
61
+ import { AutoProcessor, AutoModelForVision2Seq, RawImage } from "@huggingface/transformers";
62
+
63
+ const processor = await AutoProcessor.from_pretrained("TheGarageDev/Minus-v0.1");
64
+ const model = await AutoModelForVision2Seq.from_pretrained("TheGarageDev/Minus-v0.1", {
65
+ device: "webgpu", // REQUIRED — the q4 decoder is WebGPU-only
66
+ dtype: { embed_tokens: "q8", vision_encoder: "q8", decoder_model_merged: "q4" },
67
+ });
68
+
69
+ const image = await RawImage.read(imageUrlOrCanvas);
70
+ const messages = [{ role: "user", content: [
71
+ { type: "image" },
72
+ { type: "text", text: "Is this an advertisement? Answer Yes or No." },
73
+ ]}];
74
+ const prompt = processor.apply_chat_template(messages, { add_generation_prompt: true });
75
+ const inputs = await processor(prompt, image);
76
+
77
+ // One decode step; compare the logits of "Yes" vs "No" for a calibrated p(ad).
78
+ const { logits } = await model({ ...inputs });
79
+ // p_ad = softmax over {logit("Yes"), logit("No")} — see the extension's engine
80
+ // (offscreen.js) for the exact token ids + scoring code.
81
+ ```
82
+
83
+ **Thresholding matters.** The extension does not block at p ≥ 0.5 — it uses per-context gates chosen from the PR curve: **0.60** for elements with ad context (iframes / ad-slot containers) and **0.88** for bare images. If you deploy this model, pick your own operating point for your precision target.
84
+
85
+ ### Python (reference / server-side)
86
+
87
+ The ONNX graphs run under `onnxruntime` too (CPU/CUDA execution providers support the quantized ops). For full-precision experiments, start from the base model and the recipe above.
88
+
89
+ ## Limitations & honest notes
90
+
91
+ - **Binary classifier, not a chat model.** The fine-tune deliberately collapses the model onto Yes/No answers for one prompt; don't expect general VLM behavior.
92
+ - **Domain:** English-centric web pages and US/EU streaming TV. Ads in other scripts/markets will work worse.
93
+ - **Preprocessing sensitivity:** browser-side image resampling can shift scores on borderline UI-like inputs (we train with scale-jitter to mitigate; a handful of known residuals remain, e.g. certain consent banners).
94
+ - **Screenshots of ads vs. ads:** the model sees pixels. Editorial *about* an ad, or a screenshot of an ad inside an article, can legitimately score high.
95
+ - The training dataset is **not** released.
96
+
97
+ ## License
98
+
99
+ Inherits the **[LFM Open License v1.0](https://huggingface.co/LiquidAI/LFM2.5-VL-450M/blob/main/LICENSE)** from the base model ([LiquidAI/LFM2.5-VL-450M](https://huggingface.co/LiquidAI/LFM2.5-VL-450M)). The Minus extension source is at [garagehq/Minus-chrome-extension](https://github.com/garagehq/Minus-chrome-extension).
chat_template.jinja ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{- bos_token -}}
2
+ {%- set keep_past_thinking = keep_past_thinking | default(false) -%}
3
+
4
+ {%- macro format_arg_value(arg_value) -%}
5
+ {%- if arg_value is string -%}
6
+ {{- '"' + arg_value + '"' -}}
7
+ {%- elif arg_value is mapping -%}
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
+ {%- else -%}
18
+ {%- set _ns = namespace(result="") -%}
19
+ {%- for item in content -%}
20
+ {%- if item.type == "image" -%}
21
+ {%- set _ns.result = _ns.result + "<image>" -%}
22
+ {%- elif item.type == "text" -%}
23
+ {%- set _ns.result = _ns.result + item.text -%}
24
+ {%- else -%}
25
+ {%- set _ns.result = _ns.result + item | tojson -%}
26
+ {%- endif -%}
27
+ {%- endfor -%}
28
+ {{- _ns.result -}}
29
+ {%- endif -%}
30
+ {%- endmacro -%}
31
+
32
+ {%- macro render_tool_calls(tool_calls) -%}
33
+ {%- set tool_calls_ns = namespace(tool_calls=[]) -%}
34
+ {%- for tool_call in tool_calls -%}
35
+ {%- set func_name = tool_call.function.name -%}
36
+ {%- set func_args = tool_call.function.arguments -%}
37
+ {%- set args_ns = namespace(arg_strings=[]) -%}
38
+ {%- for arg_name, arg_value in func_args.items() -%}
39
+ {%- set args_ns.arg_strings = args_ns.arg_strings + [arg_name + "=" + format_arg_value(arg_value)] -%}
40
+ {%- endfor -%}
41
+ {%- set tool_calls_ns.tool_calls = tool_calls_ns.tool_calls + [func_name + "(" + (args_ns.arg_strings | join(", ")) + ")"] -%}
42
+ {%- endfor -%}
43
+ {{- "<|tool_call_start|>[" + (tool_calls_ns.tool_calls | join(", ")) + "]<|tool_call_end|>" -}}
44
+ {%- endmacro -%}
45
+
46
+ {%- set ns = namespace(system_prompt="", last_assistant_index=-1) -%}
47
+ {%- if messages[0].role == "system" -%}
48
+ {%- if messages[0].content is defined -%}
49
+ {%- set ns.system_prompt = parse_content(messages[0].content) -%}
50
+ {%- endif -%}
51
+ {%- set messages = messages[1:] -%}
52
+ {%- endif -%}
53
+ {%- if tools -%}
54
+ {%- set ns.system_prompt = ns.system_prompt + ("\n\n" if ns.system_prompt else "") + "Today's date: " + strftime_now("%Y-%m-%d") + "\n\nList of tools: " + (tools | tojson) -%}
55
+ {%- endif -%}
56
+ {%- if ns.system_prompt -%}
57
+ {{- "<|im_start|>system\n" + ns.system_prompt + "<|im_end|>\n" -}}
58
+ {%- endif -%}
59
+ {%- for message in messages -%}
60
+ {%- if message.role == "assistant" -%}
61
+ {%- set ns.last_assistant_index = loop.index0 -%}
62
+ {%- endif -%}
63
+ {%- endfor -%}
64
+ {%- for message in messages -%}
65
+ {{- "<|im_start|>" + message.role + "\n" -}}
66
+ {%- if message.role == "assistant" -%}
67
+ {%- generation -%}
68
+ {%- if message.thinking is defined and (keep_past_thinking or loop.index0 == ns.last_assistant_index) -%}
69
+ {{- "<think>" + message.thinking + "</think>" -}}
70
+ {%- endif -%}
71
+ {%- if message.tool_calls is defined -%}
72
+ {{- render_tool_calls(message.tool_calls) -}}
73
+ {%- endif -%}
74
+ {%- if message.content is defined -%}
75
+ {%- set content = parse_content(message.content) -%}
76
+ {%- if not keep_past_thinking and loop.index0 != ns.last_assistant_index -%}
77
+ {%- if "</think>" in content -%}
78
+ {%- set content = content.split("</think>")[-1] | trim -%}
79
+ {%- endif -%}
80
+ {%- endif -%}
81
+ {{- content + ("" if (continue_final_message and loop.last) else "<|im_end|>\n") -}}
82
+ {%- endif -%}
83
+ {%- endgeneration -%}
84
+ {%- else %}
85
+ {%- if message.content is defined -%}
86
+ {{- parse_content(message.content) + "<|im_end|>\n" -}}
87
+ {%- endif -%}
88
+ {%- endif %}
89
+ {%- endfor -%}
90
+ {%- if add_generation_prompt -%}
91
+ {{- "<|im_start|>assistant\n" -}}
92
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Lfm2VlForConditionalGeneration"
4
+ ],
5
+ "do_image_splitting": true,
6
+ "downsample_factor": 2,
7
+ "dtype": "bfloat16",
8
+ "encoder_patch_size": 16,
9
+ "image_token_id": 396,
10
+ "max_image_tokens": 256,
11
+ "max_pixels_tolerance": 2.0,
12
+ "max_tiles": 10,
13
+ "min_image_tokens": 64,
14
+ "min_tiles": 2,
15
+ "model_type": "lfm2_vl",
16
+ "projector_bias": true,
17
+ "projector_hidden_act": "gelu",
18
+ "projector_hidden_size": 2048,
19
+ "projector_use_layernorm": false,
20
+ "text_config": {
21
+ "_name_or_path": "LiquidAI/LFM2-350M",
22
+ "architectures": [
23
+ "Lfm2ForCausalLM"
24
+ ],
25
+ "block_auto_adjust_ff_dim": true,
26
+ "block_dim": 1024,
27
+ "block_ffn_dim_multiplier": 1.0,
28
+ "block_mlp_init_scale": 1.0,
29
+ "block_multiple_of": 256,
30
+ "block_norm_eps": 1e-05,
31
+ "block_out_init_scale": 1.0,
32
+ "block_use_swiglu": true,
33
+ "block_use_xavier_init": true,
34
+ "bos_token_id": 1,
35
+ "conv_L_cache": 3,
36
+ "conv_bias": false,
37
+ "conv_dim": 1024,
38
+ "conv_dim_out": 1024,
39
+ "conv_use_xavier_init": true,
40
+ "dtype": "bfloat16",
41
+ "eos_token_id": 7,
42
+ "full_attn_idxs": null,
43
+ "hidden_size": 1024,
44
+ "initializer_range": 0.02,
45
+ "intermediate_size": 6656,
46
+ "layer_types": [
47
+ "conv",
48
+ "conv",
49
+ "full_attention",
50
+ "conv",
51
+ "conv",
52
+ "full_attention",
53
+ "conv",
54
+ "conv",
55
+ "full_attention",
56
+ "conv",
57
+ "full_attention",
58
+ "conv",
59
+ "full_attention",
60
+ "conv",
61
+ "full_attention",
62
+ "conv"
63
+ ],
64
+ "max_position_embeddings": 128000,
65
+ "model_type": "lfm2",
66
+ "norm_eps": 1e-05,
67
+ "num_attention_heads": 16,
68
+ "num_heads": 16,
69
+ "num_hidden_layers": 16,
70
+ "num_key_value_heads": 8,
71
+ "pad_token_id": 0,
72
+ "rope_parameters": {
73
+ "rope_theta": 1000000.0,
74
+ "rope_type": "default"
75
+ },
76
+ "tie_word_embeddings": true,
77
+ "use_cache": true,
78
+ "use_pos_enc": true,
79
+ "vocab_size": 65536
80
+ },
81
+ "tie_word_embeddings": true,
82
+ "tile_size": 512,
83
+ "transformers_version": "5.7.0.dev0",
84
+ "use_image_special_tokens": true,
85
+ "use_thumbnail": true,
86
+ "vision_config": {
87
+ "attention_dropout": 0.0,
88
+ "dtype": "bfloat16",
89
+ "hidden_act": "gelu_pytorch_tanh",
90
+ "hidden_size": 768,
91
+ "intermediate_size": 3072,
92
+ "layer_norm_eps": 1e-06,
93
+ "model_type": "siglip2_vision_model",
94
+ "num_attention_heads": 12,
95
+ "num_channels": 3,
96
+ "num_hidden_layers": 12,
97
+ "num_patches": 256,
98
+ "patch_size": 16,
99
+ "vision_use_head": false
100
+ },
101
+ "transformers.js_config": {
102
+ "use_external_data_format": true,
103
+ "kv_cache_dtype": {
104
+ "fp16": "float16",
105
+ "q4f16": "float16"
106
+ }
107
+ }
108
+ }
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 7,
5
+ "pad_token_id": 0,
6
+ "transformers_version": "5.7.0.dev0"
7
+ }
onnx/decoder_model_merged_q4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:22527f6d3e1af239dac22c8cfd073827f2f7f2b177233b8621c121d1e83ec2e7
3
+ size 188262
onnx/decoder_model_merged_q4.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:791ef1847e833a5c97320de5db55fac7306ad1d49f4b088697e4e169e9d49281
3
+ size 260075520
onnx/embed_tokens_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8198d1e54e70e576f9f53efb310fa20fea4674d9e2f55de1d246f194992acd08
3
+ size 822
onnx/embed_tokens_quantized.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:881d06041a181ce14a3d1235a4efe164d639b4f3b579cd2994faf46afa6a5d6b
3
+ size 77594624
onnx/vision_encoder_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c8c1991efb42f97689b53c338f393ca21611d6b4d3604ae4476826284a9c0e3e
3
+ size 187977
onnx/vision_encoder_quantized.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8b6b008a1f1743dd08606dd9445b03801af82ee864a7b7e0d47d68237f160987
3
+ size 109874176
preprocessor_config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "data_format": "channels_first",
3
+ "do_image_splitting": true,
4
+ "do_normalize": true,
5
+ "do_pad": true,
6
+ "do_rescale": true,
7
+ "do_resize": true,
8
+ "downsample_factor": 2,
9
+ "encoder_patch_size": 16,
10
+ "image_mean": [
11
+ 0.5,
12
+ 0.5,
13
+ 0.5
14
+ ],
15
+ "image_processor_type": "Lfm2VlImageProcessor",
16
+ "image_std": [
17
+ 0.5,
18
+ 0.5,
19
+ 0.5
20
+ ],
21
+ "max_image_tokens": 256,
22
+ "max_num_patches": 1024,
23
+ "max_pixels_tolerance": 2.0,
24
+ "max_tiles": 10,
25
+ "min_image_tokens": 64,
26
+ "min_tiles": 2,
27
+ "resample": 2,
28
+ "rescale_factor": 0.00392156862745098,
29
+ "return_row_col_info": true,
30
+ "size": {
31
+ "height": 512,
32
+ "width": 512
33
+ },
34
+ "tile_size": 512,
35
+ "use_thumbnail": true,
36
+ "processor_class": "Lfm2VlProcessor"
37
+ }
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": "Lfm2VlImageProcessor",
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": 2,
28
+ "resample": 2,
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
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "<|startoftext|>",
4
+ "clean_up_tokenization_spaces": true,
5
+ "eos_token": "<|im_end|>",
6
+ "extra_special_tokens": [],
7
+ "image_end_token": "<|image_end|>",
8
+ "image_start_token": "<|image_start|>",
9
+ "image_thumbnail": "<|img_thumbnail|>",
10
+ "image_token": "<image>",
11
+ "is_local": false,
12
+ "legacy": false,
13
+ "local_files_only": false,
14
+ "model_max_length": 1000000000000000019884624838656,
15
+ "model_specific_special_tokens": {
16
+ "image_end_token": "<|image_end|>",
17
+ "image_start_token": "<|image_start|>",
18
+ "image_token": "<image>"
19
+ },
20
+ "pad_token": "<|pad|>",
21
+ "processor_class": "Lfm2VlProcessor",
22
+ "return_token_type_ids": false,
23
+ "sp_model_kwargs": {},
24
+ "spaces_between_special_tokens": false,
25
+ "tokenizer_class": "TokenizersBackend",
26
+ "use_default_system_prompt": false,
27
+ "use_fast": true,
28
+ "chat_template": "{{- bos_token -}}\n{%- set keep_past_thinking = keep_past_thinking | default(false) -%}\n\n{%- macro format_arg_value(arg_value) -%}\n {%- if arg_value is string -%}\n {{- '\"' + arg_value + '\"' -}}\n {%- elif arg_value is mapping -%}\n {{- arg_value | tojson -}}\n {%- else -%}\n {{- arg_value | string -}}\n {%- endif -%}\n{%- endmacro -%}\n\n{%- macro parse_content(content) -%}\n {%- if content is string -%}\n {{- content -}}\n {%- else -%}\n {%- set _ns = namespace(result=\"\") -%}\n {%- for item in content -%}\n {%- if item.type == \"image\" -%}\n {%- set _ns.result = _ns.result + \"<image>\" -%}\n {%- elif item.type == \"text\" -%}\n {%- set _ns.result = _ns.result + item.text -%}\n {%- else -%}\n {%- set _ns.result = _ns.result + item | tojson -%}\n {%- endif -%}\n {%- endfor -%}\n {{- _ns.result -}}\n {%- endif -%}\n{%- endmacro -%}\n\n{%- macro render_tool_calls(tool_calls) -%}\n {%- set tool_calls_ns = namespace(tool_calls=[]) -%}\n {%- for tool_call in tool_calls -%}\n {%- set func_name = tool_call.function.name -%}\n {%- set func_args = tool_call.function.arguments -%}\n {%- set args_ns = namespace(arg_strings=[]) -%}\n {%- for arg_name, arg_value in func_args.items() -%}\n {%- set args_ns.arg_strings = args_ns.arg_strings + [arg_name + \"=\" + format_arg_value(arg_value)] -%}\n {%- endfor -%}\n {%- set tool_calls_ns.tool_calls = tool_calls_ns.tool_calls + [func_name + \"(\" + (args_ns.arg_strings | join(\", \")) + \")\"] -%}\n {%- endfor -%}\n {{- \"<|tool_call_start|>[\" + (tool_calls_ns.tool_calls | join(\", \")) + \"]<|tool_call_end|>\" -}}\n{%- endmacro -%}\n\n{%- set ns = namespace(system_prompt=\"\", last_assistant_index=-1) -%}\n{%- if messages[0].role == \"system\" -%}\n {%- if messages[0].content is defined -%}\n {%- set ns.system_prompt = parse_content(messages[0].content) -%}\n {%- endif -%}\n {%- set messages = messages[1:] -%}\n{%- endif -%}\n{%- if tools -%}\n {%- set ns.system_prompt = ns.system_prompt + (\"\\n\\n\" if ns.system_prompt else \"\") + \"Today's date: \" + strftime_now(\"%Y-%m-%d\") + \"\\n\\nList of tools: \" + (tools | tojson) -%}\n{%- endif -%}\n{%- if ns.system_prompt -%}\n {{- \"<|im_start|>system\\n\" + ns.system_prompt + \"<|im_end|>\\n\" -}}\n{%- endif -%}\n{%- for message in messages -%}\n {%- if message.role == \"assistant\" -%}\n {%- set ns.last_assistant_index = loop.index0 -%}\n {%- endif -%}\n{%- endfor -%}\n{%- for message in messages -%}\n {{- \"<|im_start|>\" + message.role + \"\\n\" -}}\n {%- if message.role == \"assistant\" -%}\n {%- generation -%}\n {%- if message.thinking is defined and (keep_past_thinking or loop.index0 == ns.last_assistant_index) -%}\n {{- \"<think>\" + message.thinking + \"</think>\" -}}\n {%- endif -%}\n {%- if message.tool_calls is defined -%}\n {{- render_tool_calls(message.tool_calls) -}}\n {%- endif -%}\n {%- if message.content is defined -%}\n {%- set content = parse_content(message.content) -%}\n {%- if not keep_past_thinking and loop.index0 != ns.last_assistant_index -%}\n {%- if \"</think>\" in content -%}\n {%- set content = content.split(\"</think>\")[-1] | trim -%}\n {%- endif -%}\n {%- endif -%}\n {{- content + (\"\" if (continue_final_message and loop.last) else \"<|im_end|>\\n\") -}}\n {%- endif -%}\n {%- endgeneration -%}\n {%- else %}\n {%- if message.content is defined -%}\n {{- parse_content(message.content) + \"<|im_end|>\\n\" -}}\n {%- endif -%}\n {%- endif %}\n{%- endfor -%}\n{%- if add_generation_prompt -%}\n {{- \"<|im_start|>assistant\\n\" -}}\n{%- endif -%}"
29
+ }