初始化项目,由ModelHub XC社区提供模型
Model: unsloth/LFM2-700M Source: Original Platform
This commit is contained in:
35
.gitattributes
vendored
Normal file
35
.gitattributes
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.model filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||||
|
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||||
41
LICENSE
Normal file
41
LICENSE
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
LICENSE TEXT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
LFM Open License v1.0
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
1. Definitions.
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by this document.
|
||||||
|
"Licensor" shall mean Liquid AI, Inc.
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||||
|
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||||
|
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work.
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||||
|
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||||
|
"Commercial Use" shall mean any use of the Work for direct or indirect commercial advantage or monetary compensation.
|
||||||
|
"Qualified Non-Profit Organization" shall mean a Legal Entity that is organized and operated exclusively for religious, charitable, scientific, testing for public safety, literary, or educational purposes, and which is exempt from federal income tax under Section 501(c)(3) of the United States Internal Revenue Code of 1986, as amended, or any equivalent non-profit or charitable organization in a foreign jurisdiction.
|
||||||
|
"Non-Commercial or Research Purposes" shall mean purposes that do not involve any use of the Work or a Derivative Work for Commercial Use.
|
||||||
|
"Threshold" shall mean annual revenue of 10 million United States dollars ($10,000,000) or more.
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of this License, including the Commercial Use limitation set forth in Section 5, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of this License, including the Commercial Use limitation set forth in Section 5, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||||
|
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||||
|
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
||||||
|
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||||
|
5. Commercial Use Limitation.
|
||||||
|
(a) The rights granted under this License for Commercial Use are conditioned upon You or Your Legal Entity not exceeding the Threshold.
|
||||||
|
(b) Any Commercial Use of the Work or a Derivative Work by a Legal Entity that exceeds the Threshold is not licensed under this Agreement.
|
||||||
|
(c) The Threshold shall not apply to a Qualified Non-Profit Organization's use of the Work or a Derivative Work for Non-Commercial or Research Purposes.
|
||||||
|
6. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||||
|
7. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except for the reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
8. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||||
|
9. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||||
|
10. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||||
|
11. Termination. This License will terminate automatically and immediately if You fail to comply with any of its terms and conditions. Upon termination, You must cease all use of the Work and any Derivative Works and delete all copies in Your possession.
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
260
README.md
Normal file
260
README.md
Normal file
@@ -0,0 +1,260 @@
|
|||||||
|
---
|
||||||
|
base_model:
|
||||||
|
- LiquidAI/LFM2-700M
|
||||||
|
library_name: transformers
|
||||||
|
license: other
|
||||||
|
license_name: lfm1.0
|
||||||
|
license_link: LICENSE
|
||||||
|
language:
|
||||||
|
- en
|
||||||
|
- ar
|
||||||
|
- zh
|
||||||
|
- fr
|
||||||
|
- de
|
||||||
|
- ja
|
||||||
|
- ko
|
||||||
|
- es
|
||||||
|
pipeline_tag: text-generation
|
||||||
|
tags:
|
||||||
|
- liquid
|
||||||
|
- unsloth
|
||||||
|
- lfm2
|
||||||
|
- edge
|
||||||
|
---
|
||||||
|
<div>
|
||||||
|
<p style="margin-top: 0;margin-bottom: 0;">
|
||||||
|
<em><a href="https://docs.unsloth.ai/basics/unsloth-dynamic-v2.0-gguf">Unsloth Dynamic 2.0</a> achieves superior accuracy & outperforms other leading quants.</em>
|
||||||
|
</p>
|
||||||
|
<div style="display: flex; gap: 5px; align-items: center; ">
|
||||||
|
<a href="https://github.com/unslothai/unsloth/">
|
||||||
|
<img src="https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png" width="133">
|
||||||
|
</a>
|
||||||
|
<a href="https://discord.gg/unsloth">
|
||||||
|
<img src="https://github.com/unslothai/unsloth/raw/main/images/Discord%20button.png" width="173">
|
||||||
|
</a>
|
||||||
|
<a href="https://docs.unsloth.ai/">
|
||||||
|
<img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="143">
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<div style="text-align: center;">
|
||||||
|
<img
|
||||||
|
src="https://cdn-uploads.huggingface.co/production/uploads/61b8e2ba285851687028d395/7_6D7rWrLxp2hb6OHSV1p.png"
|
||||||
|
alt="Liquid AI"
|
||||||
|
style="width: 100%; max-width: 66%; height: auto; display: inline-block; margin-bottom: 0.5em; margin-top: 0.5em;"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<a href="https://playground.liquid.ai/chat">
|
||||||
|
<svg width="114.8" height="20" viewBox="0 0 1300 200" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Liquid Playground" style="margin-bottom: 1em;">
|
||||||
|
<title>Liquid: Playground</title>
|
||||||
|
<g>
|
||||||
|
<rect fill="#fff" width="600" height="200"></rect>
|
||||||
|
<rect fill="url(#x)" x="600" width="700" height="200"></rect>
|
||||||
|
</g>
|
||||||
|
<g transform="translate(20, 30) scale(0.4, 0.4)">
|
||||||
|
<path d="M172.314 129.313L172.219 129.367L206.125 188.18C210.671 195.154 213.324 203.457 213.324 212.382C213.324 220.834 210.956 228.739 206.839 235.479L275.924 213.178L167.853 33.6L141.827 76.9614L172.314 129.313Z" fill="black"/>
|
||||||
|
<path d="M114.217 302.4L168.492 257.003C168.447 257.003 168.397 257.003 168.352 257.003C143.515 257.003 123.385 237.027 123.385 212.387C123.385 203.487 126.023 195.204 130.55 188.24L162.621 132.503L135.966 86.7327L60.0762 213.183L114.127 302.4H114.217Z" fill="black"/>
|
||||||
|
<path d="M191.435 250.681C191.435 250.681 191.43 250.681 191.425 250.686L129.71 302.4H221.294L267.71 226.593L191.435 250.686V250.681Z" fill="black"/>
|
||||||
|
</g>
|
||||||
|
<g aria-hidden="true" fill="#fff" text-anchor="start" font-family="Verdana,DejaVu Sans,sans-serif" font-size="110">
|
||||||
|
<text x="200" y="148" textLength="329" fill="#000" opacity="0.1">Liquid</text>
|
||||||
|
<text x="190" y="138" textLength="329" fill="#000">Liquid</text>
|
||||||
|
<text x="655" y="148" textLength="619" fill="#000" opacity="0.1">Playground</text>
|
||||||
|
<text x="645" y="138" textLength="619">Playground</text>
|
||||||
|
</g>
|
||||||
|
|
||||||
|
<linearGradient id="x" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||||
|
<stop offset="0%" style="stop-color:#000000"></stop>
|
||||||
|
<stop offset="100%" style="stop-color:#000000"></stop>
|
||||||
|
</linearGradient>
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</center>
|
||||||
|
|
||||||
|
# LFM2-700M
|
||||||
|
|
||||||
|
LFM2 is a new generation of hybrid models developed by [Liquid AI](https://www.liquid.ai/), specifically designed for edge AI and on-device deployment. It sets a new standard in terms of quality, speed, and memory efficiency.
|
||||||
|
|
||||||
|
We're releasing the weights of three post-trained checkpoints with 350M, 700M, and 1.2B parameters. They provide the following key features to create AI-powered edge applications:
|
||||||
|
|
||||||
|
* **Fast training & inference** – LFM2 achieves 3x faster training compared to its previous generation. It also benefits from 2x faster decode and prefill speed on CPU compared to Qwen3.
|
||||||
|
* **Best performance** – LFM2 outperforms similarly-sized models across multiple benchmark categories, including knowledge, mathematics, instruction following, and multilingual capabilities.
|
||||||
|
* **New architecture** – LFM2 is a new hybrid Liquid model with multiplicative gates and short convolutions.
|
||||||
|
* **Flexible deployment** – LFM2 runs efficiently on CPU, GPU, and NPU hardware for flexible deployment on smartphones, laptops, or vehicles.
|
||||||
|
|
||||||
|
Find more information about LFM2 in our [blog post](https://www.liquid.ai/blog/liquid-foundation-models-v2-our-second-series-of-generative-ai-models).
|
||||||
|
|
||||||
|
## 📄 Model details
|
||||||
|
|
||||||
|
Due to their small size, **we recommend fine-tuning LFM2 models on narrow use cases** to maximize performance.
|
||||||
|
They are particularly suited for agentic tasks, data extraction, RAG, creative writing, and multi-turn conversations.
|
||||||
|
However, we do not recommend using them for tasks that are knowledge-intensive or require programming skills.
|
||||||
|
|
||||||
|
| Property | Value |
|
||||||
|
| ------------------- | ----------------------------- |
|
||||||
|
| **Parameters** | 742,489,344 |
|
||||||
|
| **Layers** | 16 (10 conv + 6 attn) |
|
||||||
|
| **Context length** | 32,768 tokens |
|
||||||
|
| **Vocabulary size** | 65,536 |
|
||||||
|
| **Precision** | bfloat16 |
|
||||||
|
| **Training budget** | 10 trillion tokens |
|
||||||
|
| **License** | LFM Open License v1.0 |
|
||||||
|
|
||||||
|
**Supported languages**: English, Arabic, Chinese, French, German, Japanese, Korean, and Spanish.
|
||||||
|
|
||||||
|
**Generation parameters**: We recommend the following parameters:
|
||||||
|
* `temperature=0.3`
|
||||||
|
* `min_p=0.15`
|
||||||
|
* `repetition_penalty=1.05`
|
||||||
|
|
||||||
|
**Chat template**: LFM2 uses a ChatML-like chat template as follows:
|
||||||
|
|
||||||
|
```
|
||||||
|
<|startoftext|><|im_start|>system
|
||||||
|
You are a helpful assistant trained by Liquid AI.<|im_end|>
|
||||||
|
<|im_start|>user
|
||||||
|
What is C. elegans?<|im_end|>
|
||||||
|
<|im_start|>assistant
|
||||||
|
It's a tiny nematode that lives in temperate soil environments.<|im_end|>
|
||||||
|
```
|
||||||
|
|
||||||
|
You can apply it using the dedicated [`.apply_chat_template()`](https://huggingface.co/docs/transformers/en/chat_templating#applychattemplate) function from Hugging Face transformers.
|
||||||
|
|
||||||
|
**Tool use**: It consists of four main steps:
|
||||||
|
1. **Function definition**: LFM2 takes JSON function definitions as input (JSON objects between `<|tool_list_start|>` and `<|tool_list_end|>` special tokens), usually in the system prompt
|
||||||
|
2. **Function call**: LFM2 writes Pythonic function calls (a Python list between `<|tool_call_start|>` and `<|tool_call_end|>` special tokens), as the assistant answer.
|
||||||
|
3. **Function execution**: The function call is executed and the result is returned (string between `<|tool_response_start|>` and `<|tool_response_end|>` special tokens), as a "tool" role.
|
||||||
|
4. **Final answer**: LFM2 interprets the outcome of the function call to address the original user prompt in plain text.
|
||||||
|
|
||||||
|
Here is a simple example of a conversation using tool use:
|
||||||
|
|
||||||
|
```
|
||||||
|
<|startoftext|><|im_start|>system
|
||||||
|
List of tools: <|tool_list_start|>[{"name": "get_candidate_status", "description": "Retrieves the current status of a candidate in the recruitment process", "parameters": {"type": "object", "properties": {"candidate_id": {"type": "string", "description": "Unique identifier for the candidate"}}, "required": ["candidate_id"]}}]<|tool_list_end|><|im_end|>
|
||||||
|
<|im_start|>user
|
||||||
|
What is the current status of candidate ID 12345?<|im_end|>
|
||||||
|
<|im_start|>assistant
|
||||||
|
<|tool_call_start|>[get_candidate_status(candidate_id="12345")]<|tool_call_end|>Checking the current status of candidate ID 12345.<|im_end|>
|
||||||
|
<|im_start|>tool
|
||||||
|
<|tool_response_start|>{"candidate_id": "12345", "status": "Interview Scheduled", "position": "Clinical Research Associate", "date": "2023-11-20"}<|tool_response_end|><|im_end|>
|
||||||
|
<|im_start|>assistant
|
||||||
|
The candidate with ID 12345 is currently in the "Interview Scheduled" stage for the position of Clinical Research Associate, with an interview date set for 2023-11-20.<|im_end|>
|
||||||
|
```
|
||||||
|
|
||||||
|
**Architecture**: Hybrid model with multiplicative gates and short convolutions: 10 double-gated short-range LIV convolution blocks and 6 grouped query attention (GQA) blocks.
|
||||||
|
|
||||||
|
**Pre-training mixture**: Approximately 75% English, 20% multilingual, and 5% code data sourced from the web and licensed materials.
|
||||||
|
|
||||||
|
**Training approach**:
|
||||||
|
* Knowledge distillation using [LFM1-7B](https://www.liquid.ai/blog/introducing-lfm-7b-setting-new-standards-for-efficient-language-models) as teacher model
|
||||||
|
* Very large-scale SFT on 50% downstream tasks, 50% general domains
|
||||||
|
* Custom DPO with length normalization and semi-online datasets
|
||||||
|
* Iterative model merging
|
||||||
|
|
||||||
|
## 🏃 How to run LFM2
|
||||||
|
|
||||||
|
You can run LFM2 with transformers and llama.cpp. vLLM support is coming.
|
||||||
|
|
||||||
|
### 1. Transformers
|
||||||
|
|
||||||
|
To run LFM2, you need to install Hugging Face [`transformers`](https://github.com/huggingface/transformers) from source (v4.54.0.dev0).
|
||||||
|
You can update or install it with the following command: `pip install "transformers @ git+https://github.com/huggingface/transformers.git@main"`.
|
||||||
|
|
||||||
|
Here is an example of how to generate an answer with transformers in Python:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||||
|
|
||||||
|
# Load model and tokenizer
|
||||||
|
model_id = "LiquidAI/LFM2-700M"
|
||||||
|
model = AutoModelForCausalLM.from_pretrained(
|
||||||
|
model_id,
|
||||||
|
device_map="auto",
|
||||||
|
torch_dtype="bfloat16",
|
||||||
|
trust_remote_code=True,
|
||||||
|
# attn_implementation="flash_attention_2" <- uncomment on compatible GPU
|
||||||
|
)
|
||||||
|
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
||||||
|
|
||||||
|
# Generate answer
|
||||||
|
prompt = "What is C. elegans?"
|
||||||
|
input_ids = tokenizer.apply_chat_template(
|
||||||
|
[{"role": "user", "content": prompt}],
|
||||||
|
add_generation_prompt=True,
|
||||||
|
return_tensors="pt",
|
||||||
|
tokenize=True,
|
||||||
|
).to(model.device)
|
||||||
|
|
||||||
|
output = model.generate(
|
||||||
|
input_ids,
|
||||||
|
do_sample=True,
|
||||||
|
temperature=0.3,
|
||||||
|
min_p=0.15,
|
||||||
|
repetition_penalty=1.05,
|
||||||
|
max_new_tokens=512,
|
||||||
|
)
|
||||||
|
|
||||||
|
print(tokenizer.decode(output[0], skip_special_tokens=False))
|
||||||
|
|
||||||
|
# <|startoftext|><|im_start|>user
|
||||||
|
# What is C. elegans?<|im_end|>
|
||||||
|
# <|im_start|>assistant
|
||||||
|
# C. elegans, also known as Caenorhabditis elegans, is a small, free-living
|
||||||
|
# nematode worm (roundworm) that belongs to the phylum Nematoda.
|
||||||
|
```
|
||||||
|
|
||||||
|
You can directly run and test the model with this [Colab notebook](https://colab.research.google.com/drive/1_q3jQ6LtyiuPzFZv7Vw8xSfPU5FwkKZY?usp=sharing).
|
||||||
|
|
||||||
|
### 2. Llama.cpp
|
||||||
|
|
||||||
|
You can run LFM2 with llama.cpp using its [GGUF checkpoint](https://huggingface.co/LiquidAI/LFM2-700M-GGUF). Find more information in the model card.
|
||||||
|
|
||||||
|
## 🔧 How to fine-tune LFM2
|
||||||
|
|
||||||
|
We recommend fine-tuning LFM2 models on your use cases to maximize performance.
|
||||||
|
|
||||||
|
| Notebook | Description | Link |
|
||||||
|
|-------|------|------|
|
||||||
|
| SFT + LoRA | Supervised Fine-Tuning (SFT) notebook with a LoRA adapter in TRL. | <a href="https://colab.research.google.com/drive/1j5Hk_SyBb2soUsuhU0eIEA9GwLNRnElF?usp=sharing"><img src="https://cdn-uploads.huggingface.co/production/uploads/61b8e2ba285851687028d395/vlOyMEjwHa_b_LXysEu2E.png" width="120" alt="Colab link"></a> |
|
||||||
|
| DPO | Preference alignment with Direct Preference Optimization (DPO) in TRL. | <a href="https://colab.research.google.com/drive/1MQdsPxFHeZweGsNx4RH7Ia8lG8PiGE1t?usp=sharing"><img src="https://cdn-uploads.huggingface.co/production/uploads/61b8e2ba285851687028d395/vlOyMEjwHa_b_LXysEu2E.png" width="120" alt="Colab link"></a> |
|
||||||
|
|
||||||
|
## 📈 Performance
|
||||||
|
|
||||||
|
LFM2 outperforms similar-sized models across different evaluation categories.
|
||||||
|
|
||||||
|
### 1. Automated benchmarks
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
| Model | MMLU | GPQA | IFEval | IFBench | GSM8K | MGSM | MMMLU |
|
||||||
|
|-------|------|------|--------|---------|-------|------|-------|
|
||||||
|
| LFM2-350M | 43.43 | 27.46 | 65.12 | 16.41 | 30.1 | 29.52 | 37.99 |
|
||||||
|
| LFM2-700M | 49.9 | 28.48 | 72.23 | 20.56 | 46.4 | 45.36 | 43.28 |
|
||||||
|
| LFM2-1.2B | *55.23* | **31.47** | **74.89** | *20.7* | *58.3* | *55.04* | **46.73** |
|
||||||
|
| Qwen3-0.6B | 44.93 | 22.14 | 64.24 | 19.75 | 36.47 | 41.28 | 30.84 |
|
||||||
|
| Qwen3-1.7B | **59.11** | 27.72 | *73.98* | **21.27** | 51.4 | **66.56** | *46.51* |
|
||||||
|
| Llama-3.2-1B-Instruct | 46.6 | *28.84* | 52.39 | 16.86 | 35.71 | 29.12 | 38.15 |
|
||||||
|
| gemma-3-1b-it | 40.08 | 21.07 | 62.9 | 17.72 | **59.59** | 43.6 | 34.43 |
|
||||||
|
|
||||||
|
### 2. LLM-as-a-Judge
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
### 3. Inference
|
||||||
|
|
||||||
|
#### Throughput comparison on CPU in ExecuTorch
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### Throughput comparison on CPU in Llama.cpp
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 📬 Contact
|
||||||
|
|
||||||
|
If you are interested in custom solutions with edge deployment, please contact [our sales team](https://www.liquid.ai/contact).
|
||||||
4
chat_template.jinja
Normal file
4
chat_template.jinja
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{{bos_token}}{% for message in messages %}{{'<|im_start|>' + message['role'] + '
|
||||||
|
' + message['content'] + '<|im_end|>' + '
|
||||||
|
'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
|
||||||
|
' }}{% endif %}
|
||||||
3
config.json
Normal file
3
config.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:dce453d2b2823d121942a5a4564fbaf97fafba11c17d4569d716cbdf28863fb3
|
||||||
|
size 1258
|
||||||
1
configuration.json
Normal file
1
configuration.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"framework": "pytorch", "task": "text-generation", "allow_remote": true}
|
||||||
8
generation_config.json
Normal file
8
generation_config.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"_from_model_config": true,
|
||||||
|
"bos_token_id": 1,
|
||||||
|
"eos_token_id": 7,
|
||||||
|
"max_length": 32768,
|
||||||
|
"pad_token_id": 0,
|
||||||
|
"transformers_version": "4.54.0.dev0"
|
||||||
|
}
|
||||||
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:a7b52669217ecb538740187f41ce2a5802afa1c8d81d8d153b847bbd21d1bdda
|
||||||
|
size 1484995328
|
||||||
23
special_tokens_map.json
Normal file
23
special_tokens_map.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"bos_token": {
|
||||||
|
"content": "<|startoftext|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
"eos_token": {
|
||||||
|
"content": "<|im_end|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
"pad_token": {
|
||||||
|
"content": "<|pad|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
}
|
||||||
|
}
|
||||||
3
tokenizer.json
Normal file
3
tokenizer.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:98cff83b4f6d7e9d8929bebc62b07e92cf1b3f99c80d16bafe8b84a75448f40b
|
||||||
|
size 4732426
|
||||||
4077
tokenizer_config.json
Normal file
4077
tokenizer_config.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user