Image-Text-to-Text
Transformers
ONNX
Transformers.js
lfm2_vl
lfm2
vision
multimodal
food
calories
nutrition
conversational
Instructions to use opencal/opencal-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use opencal/opencal-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="opencal/opencal-base") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("opencal/opencal-base") model = AutoModelForMultimodalLM.from_pretrained("opencal/opencal-base", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Transformers.js
How to use opencal/opencal-base with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('image-text-to-text', 'opencal/opencal-base'); - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use opencal/opencal-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "opencal/opencal-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "opencal/opencal-base", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/opencal/opencal-base
- SGLang
How to use opencal/opencal-base with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "opencal/opencal-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "opencal/opencal-base", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "opencal/opencal-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "opencal/opencal-base", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use opencal/opencal-base with Docker Model Runner:
docker model run hf.co/opencal/opencal-base
Publish OpenCal base LFM2.5-VL-450M ONNX (transformers.js)
Browse files- .gitattributes +3 -33
- README.md +88 -0
- chat_template.jinja +92 -0
- config.json +103 -0
- generation_config.json +7 -0
- onnx/decoder_model_merged.onnx +3 -0
- onnx/decoder_model_merged.onnx_data +3 -0
- onnx/decoder_model_merged_fp16.onnx +3 -0
- onnx/decoder_model_merged_fp16.onnx_data +3 -0
- onnx/decoder_model_merged_q4.onnx +3 -0
- onnx/decoder_model_merged_q4.onnx_data +3 -0
- onnx/decoder_model_merged_q4f16.onnx +3 -0
- onnx/decoder_model_merged_q4f16.onnx_data +3 -0
- onnx/embed_tokens.onnx +3 -0
- onnx/embed_tokens_fp16.onnx +3 -0
- onnx/embed_tokens_fp16.onnx_data +3 -0
- onnx/embed_tokens_q4.onnx +3 -0
- onnx/embed_tokens_q4.onnx_data +3 -0
- onnx/embed_tokens_quantized.onnx +3 -0
- onnx/embed_tokens_quantized.onnx_data +3 -0
- onnx/vision_encoder.onnx +3 -0
- onnx/vision_encoder.onnx_data +3 -0
- onnx/vision_encoder_fp16.onnx +3 -0
- onnx/vision_encoder_fp16.onnx_data +3 -0
- onnx/vision_encoder_q4.onnx +3 -0
- onnx/vision_encoder_q4.onnx_data +3 -0
- onnx/vision_encoder_quantized.onnx +3 -0
- onnx/vision_encoder_quantized.onnx_data +3 -0
- preprocessor_config.json +29 -0
- processor_config.json +39 -0
- tokenizer.json +0 -0
- tokenizer_config.json +29 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,5 @@
|
|
| 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 |
-
*.
|
| 18 |
-
*.
|
| 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 |
-
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.onnx_data filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
pipeline_tag: image-text-to-text
|
| 4 |
+
tags:
|
| 5 |
+
- lfm2
|
| 6 |
+
- vision
|
| 7 |
+
- multimodal
|
| 8 |
+
- food
|
| 9 |
+
- calories
|
| 10 |
+
- nutrition
|
| 11 |
+
- onnx
|
| 12 |
+
- transformers.js
|
| 13 |
+
license: apache-2.0
|
| 14 |
+
base_model: LiquidAI/LFM2.5-VL-450M
|
| 15 |
+
model-type: lfm2_vl
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# OpenCal Base
|
| 19 |
+
|
| 20 |
+
**OpenCal Base** is a LFM2.5-VL-450M fine-tune that reads food photos (and text) and
|
| 21 |
+
outputs structured ingredient + gram-weight extractions aligned to the USDA food
|
| 22 |
+
database. It is exported to ONNX for the `@huggingface/transformers.js` browser
|
| 23 |
+
runtime (WebGPU / WASM / CPU).
|
| 24 |
+
|
| 25 |
+
## Model details
|
| 26 |
+
|
| 27 |
+
| Field | Value |
|
| 28 |
+
| --- | --- |
|
| 29 |
+
| Base model | [`LiquidAI/LFM2.5-VL-450M`](https://huggingface.co/LiquidAI/LFM2.5-VL-450M) |
|
| 30 |
+
| Fine-tune | LoRA, OpenCal v6 (gram-weight + kcal/macro target) |
|
| 31 |
+
| Architecture | `Lfm2VlForConditionalGeneration` (`model_type: lfm2_vl`) |
|
| 32 |
+
| Runtime | ONNX / transformers.js (WebGPU, WASM, CPU) |
|
| 33 |
+
| License | Apache-2.0 |
|
| 34 |
+
|
| 35 |
+
## Fine-tune summary
|
| 36 |
+
|
| 37 |
+
LoRA on top of the frozen base, merged weights. Target format is a JSON list of
|
| 38 |
+
`{name, grams, kcal, protein_g, carbs_g, fat_g}` extracted per item, with grams
|
| 39 |
+
normalized per 100 g and macros sourced from USDA data. The model is used by the
|
| 40 |
+
OpenCal app to turn a photo or a text description of a meal into per-item
|
| 41 |
+
nutrition.
|
| 42 |
+
|
| 43 |
+
### Benchmark results (OpenCal internal evals)
|
| 44 |
+
|
| 45 |
+
- **F101** (full meals, median gold kcal ≈ 293): kcal MAE **243**, WAPE **41.5%**,
|
| 46 |
+
within-50% of gold **70.4%**.
|
| 47 |
+
- **N5k** (lab samples, median gold kcal ≈ 43): ingredient-identity recall
|
| 48 |
+
baseline **76.4%**, this model **84.4%** (reference LLM **73.6%**).
|
| 49 |
+
|
| 50 |
+
## Usage (transformers.js)
|
| 51 |
+
|
| 52 |
+
```js
|
| 53 |
+
import { AutoModelForImageTextToText, AutoProcessor, RawImage } from '@huggingface/transformers';
|
| 54 |
+
|
| 55 |
+
const processor = await AutoProcessor.from_pretrained('OpenCal/opencal-base');
|
| 56 |
+
const model = await AutoModelForImageTextToText.from_pretrained('OpenCal/opencal-base', { dtype: 'auto', device: 'webgpu' });
|
| 57 |
+
|
| 58 |
+
const image = await RawImage.fromURL('https://example.com/meal.jpg');
|
| 59 |
+
const texts = ['List the ingredients and their amounts in grams'];
|
| 60 |
+
|
| 61 |
+
const { inputs } = await processor(image, texts, { return_tensor: false });
|
| 62 |
+
const { logits } = await model(inputs);
|
| 63 |
+
const decoded = processor.batch_decode(logits[1].id); // [1] for single sample
|
| 64 |
+
console.log(decoded[0]);
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
## File layout (ONNX)
|
| 68 |
+
|
| 69 |
+
The model is split into the standard LFM2.5-VL ONNX components. The suffix of each
|
| 70 |
+
weight file selects the runtime/precision:
|
| 71 |
+
|
| 72 |
+
| File | Precision | Use |
|
| 73 |
+
| --- | --- | --- |
|
| 74 |
+
| `embed_tokens{,_fp16,_q4,_quantized}.onnx` | fp32 / fp16 / q4 / q8 | input embeddings (`input_ids → inputs_embeds`) |
|
| 75 |
+
| `decoder_model_merged{,_fp16,_q4,_q4f16}.onnx` | fp32 / fp16 / q4 / q4f16 | text decoder (main body) |
|
| 76 |
+
| `vision_encoder{,_fp16,_q4,_quantized}.onnx` | fp32 / fp16 / q4 / q8 | vision encoder |
|
| 77 |
+
|
| 78 |
+
- `q4f16` — MatMulNBits q4 weights with fp16 scales / KV cache (WebGPU production path).
|
| 79 |
+
- `quantized` (= q8, `MatMulNBits`) — WASM path.
|
| 80 |
+
- `fp16` — 16-bit WebGPU path.
|
| 81 |
+
|
| 82 |
+
`tokenizer.json`, `preprocessor_config.json`, `config.json`, and
|
| 83 |
+
`generation_config.json` are at the repository root.
|
| 84 |
+
|
| 85 |
+
## Citation / base model
|
| 86 |
+
|
| 87 |
+
This model derives from `LiquidAI/LFM2.5-VL-450M`. Please see the base repository
|
| 88 |
+
for the original weights and paper.
|
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,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"conv_L_cache": 3,
|
| 35 |
+
"conv_bias": false,
|
| 36 |
+
"conv_dim": 1024,
|
| 37 |
+
"conv_dim_out": 1024,
|
| 38 |
+
"conv_use_xavier_init": true,
|
| 39 |
+
"dtype": "bfloat16",
|
| 40 |
+
"eos_token_id": 7,
|
| 41 |
+
"hidden_size": 1024,
|
| 42 |
+
"initializer_range": 0.02,
|
| 43 |
+
"intermediate_size": 6656,
|
| 44 |
+
"layer_types": [
|
| 45 |
+
"conv",
|
| 46 |
+
"conv",
|
| 47 |
+
"full_attention",
|
| 48 |
+
"conv",
|
| 49 |
+
"conv",
|
| 50 |
+
"full_attention",
|
| 51 |
+
"conv",
|
| 52 |
+
"conv",
|
| 53 |
+
"full_attention",
|
| 54 |
+
"conv",
|
| 55 |
+
"full_attention",
|
| 56 |
+
"conv",
|
| 57 |
+
"full_attention",
|
| 58 |
+
"conv",
|
| 59 |
+
"full_attention",
|
| 60 |
+
"conv"
|
| 61 |
+
],
|
| 62 |
+
"max_position_embeddings": 128000,
|
| 63 |
+
"model_type": "lfm2",
|
| 64 |
+
"norm_eps": 1e-05,
|
| 65 |
+
"num_attention_heads": 16,
|
| 66 |
+
"num_heads": 16,
|
| 67 |
+
"num_hidden_layers": 16,
|
| 68 |
+
"num_key_value_heads": 8,
|
| 69 |
+
"rope_parameters": {
|
| 70 |
+
"rope_theta": 1000000.0,
|
| 71 |
+
"rope_type": "default"
|
| 72 |
+
},
|
| 73 |
+
"use_cache": true,
|
| 74 |
+
"use_pos_enc": true,
|
| 75 |
+
"vocab_size": 65536
|
| 76 |
+
},
|
| 77 |
+
"tile_size": 512,
|
| 78 |
+
"transformers_version": "5.0.0.dev0",
|
| 79 |
+
"use_image_special_tokens": true,
|
| 80 |
+
"use_thumbnail": true,
|
| 81 |
+
"vision_config": {
|
| 82 |
+
"attention_dropout": 0.0,
|
| 83 |
+
"dtype": "bfloat16",
|
| 84 |
+
"hidden_act": "gelu_pytorch_tanh",
|
| 85 |
+
"hidden_size": 768,
|
| 86 |
+
"intermediate_size": 3072,
|
| 87 |
+
"layer_norm_eps": 1e-06,
|
| 88 |
+
"model_type": "siglip2_vision_model",
|
| 89 |
+
"num_attention_heads": 12,
|
| 90 |
+
"num_channels": 3,
|
| 91 |
+
"num_hidden_layers": 12,
|
| 92 |
+
"num_patches": 256,
|
| 93 |
+
"patch_size": 16,
|
| 94 |
+
"vision_use_head": false
|
| 95 |
+
},
|
| 96 |
+
"transformers.js_config": {
|
| 97 |
+
"use_external_data_format": {
|
| 98 |
+
"vision_encoder": true,
|
| 99 |
+
"embed_tokens": true,
|
| 100 |
+
"decoder_model_merged": true
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
}
|
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": "4.57.0"
|
| 7 |
+
}
|
onnx/decoder_model_merged.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bb0e0195c934b3a038e88fb737ee49d1e3c677348d30bc410f9b61a8b91e9cd8
|
| 3 |
+
size 143084
|
onnx/decoder_model_merged.onnx_data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:429ed2a9ee7dee62d986ea56c0bb926faff679564526c80e297c87a757fa1780
|
| 3 |
+
size 1450700800
|
onnx/decoder_model_merged_fp16.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4128700047fb544477d3d385384cd9e9ef429706d4f23522c0c1b99525f0ef00
|
| 3 |
+
size 148963
|
onnx/decoder_model_merged_fp16.onnx_data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a3976377d486ddb1af3a20eab8c745c02c590aac60a9c0e74f99bac6b0da5573
|
| 3 |
+
size 725350400
|
onnx/decoder_model_merged_q4.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:26600302bd9db0ef26d1a98fba0aae22dac99468e2195ce6d9b9bc7308c18f68
|
| 3 |
+
size 171898
|
onnx/decoder_model_merged_q4.onnx_data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3dda301667af570f62f558049d16a7dcbd12ab182cab25f533213b8fe9281594
|
| 3 |
+
size 481030144
|
onnx/decoder_model_merged_q4f16.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f317539516f689aca8a6b0b2e4ae6a28999b07bf6af700b6bdfa485aed4bb867
|
| 3 |
+
size 127695
|
onnx/decoder_model_merged_q4f16.onnx_data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:08edea158e32ec95c29cac14fa636ab0bf562eaed6efbd13a647d2e95dd36861
|
| 3 |
+
size 312342528
|
onnx/embed_tokens.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3fcae1b697f9e35d181c119d41f06a3d9153bf09b19280ef154b5f77fd64f29c
|
| 3 |
+
size 268435815
|
onnx/embed_tokens_fp16.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:291d72b491d3187f3cafbb0ec35c5f889360a044d7db815510eff0fabb2af371
|
| 3 |
+
size 573
|
onnx/embed_tokens_fp16.onnx_data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6936dd14d4e0fa29f4046159dfa5738363f020216ed39a2ed14d276d8d473aa6
|
| 3 |
+
size 134217728
|
onnx/embed_tokens_q4.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:82bc6c3fab26502e87373f39e12da0f434256b83220aaa542689530853c55dd3
|
| 3 |
+
size 440
|
onnx/embed_tokens_q4.onnx_data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9ff7054e7ccb91937cf032fb2fad0b459c168e60fbb379bc4c030ed17ef2165c
|
| 3 |
+
size 268435456
|
onnx/embed_tokens_quantized.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:63f28d0ca5ec447470d42ca4ce0ac92a6f7fae90e91504601e63c138be8c9091
|
| 3 |
+
size 447
|
onnx/embed_tokens_quantized.onnx_data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9ff7054e7ccb91937cf032fb2fad0b459c168e60fbb379bc4c030ed17ef2165c
|
| 3 |
+
size 268435456
|
onnx/vision_encoder.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0170bb7f54d5dbb1b9a35b51f4b60b99feac3bb0753c3b8740fa2176c2763d1e
|
| 3 |
+
size 123527
|
onnx/vision_encoder.onnx_data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aac5a4f96f8964b961d129f38c5549b57d25b170e896f3ce4a9567ddb500faaa
|
| 3 |
+
size 376939520
|
onnx/vision_encoder_fp16.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d6c020610d1619939e98e0d355558dbc3a86f4e4f447747fabffb9fe77d8b7fb
|
| 3 |
+
size 124811
|
onnx/vision_encoder_fp16.onnx_data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8c7eb51d1edf6f2ac7e051abc56d602d2540345aeca8534d2bff20136ff3e591
|
| 3 |
+
size 188469760
|
onnx/vision_encoder_q4.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ca4861376b1c409486a38237676754d0286d13b00e561bd113acebaaaddc56af
|
| 3 |
+
size 146157
|
onnx/vision_encoder_q4.onnx_data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:09c5dcb8282cdce1e0f4c80a05b8285cad3762e14acac0d241f83bc6b345d41b
|
| 3 |
+
size 59982848
|
onnx/vision_encoder_quantized.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8650b9d3e2f80659b858c40b673f731a7371cf8ad3d8888e8f93b189a8f653c4
|
| 3 |
+
size 161659
|
onnx/vision_encoder_quantized.onnx_data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ee54206551cff5e2e6ddda6da4f84677542b249258f1a70710ff43399c74a5c1
|
| 3 |
+
size 109874176
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"processor_class": "Lfm2VlProcessor",
|
| 3 |
+
"image_processor_type": "Lfm2VlImageProcessor",
|
| 4 |
+
"data_format": "channels_first",
|
| 5 |
+
"do_image_splitting": true,
|
| 6 |
+
"do_normalize": true,
|
| 7 |
+
"do_pad": true,
|
| 8 |
+
"do_rescale": true,
|
| 9 |
+
"do_resize": true,
|
| 10 |
+
"downsample_factor": 2,
|
| 11 |
+
"encoder_patch_size": 16,
|
| 12 |
+
"image_mean": [0.5, 0.5, 0.5],
|
| 13 |
+
"image_std": [0.5, 0.5, 0.5],
|
| 14 |
+
"max_image_tokens": 256,
|
| 15 |
+
"max_num_patches": 1024,
|
| 16 |
+
"max_pixels_tolerance": 2.0,
|
| 17 |
+
"max_tiles": 10,
|
| 18 |
+
"min_image_tokens": 64,
|
| 19 |
+
"min_tiles": 2,
|
| 20 |
+
"resample": 2,
|
| 21 |
+
"rescale_factor": 0.00392156862745098,
|
| 22 |
+
"return_row_col_info": true,
|
| 23 |
+
"size": {
|
| 24 |
+
"height": 512,
|
| 25 |
+
"width": 512
|
| 26 |
+
},
|
| 27 |
+
"tile_size": 512,
|
| 28 |
+
"use_thumbnail": true
|
| 29 |
+
}
|
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": true,
|
| 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 \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 \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 |
+
}
|