cstr commited on
Commit
788fa2b
·
verified ·
1 Parent(s): de765f9

Add README

Browse files
Files changed (1) hide show
  1. README.md +113 -0
README.md ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ - de
6
+ - zh
7
+ - multilingual
8
+ library_name: onnxruntime
9
+ tags:
10
+ - onnx
11
+ - embedding
12
+ - text-embedding
13
+ - retrieval
14
+ - sentence-similarity
15
+ - feature-extraction
16
+ pipeline_tag: sentence-similarity
17
+ base_model: codefuse-ai/F2LLM-v2-0.6B
18
+ ---
19
+
20
+ # F2LLM-v2-0.6B — FP32 ONNX (dynamo export)
21
+
22
+ ONNX export of [codefuse-ai/F2LLM-v2-0.6B](https://huggingface.co/codefuse-ai/F2LLM-v2-0.6B), a general-purpose multilingual embedding model from the F2LLM-v2 family, trained on 60M high-quality multilingual examples supporting 200+ languages.
23
+
24
+ This is the **full-precision (FP32) reference** export. For production use, prefer the [INT8](https://huggingface.co/cstr/F2LLM-v2-0.6B-ONNX-INT8) or [INT4](https://huggingface.co/cstr/F2LLM-v2-0.6B-ONNX-INT4) variants which are 2–3× smaller with negligible quality loss.
25
+
26
+ ## Export method
27
+
28
+ Exported with **`torch.onnx.export(dynamo=True)`** (PyTorch 2.9, opset 20).
29
+
30
+ The dynamo exporter traces at the FX-graph / symbolic level. All internal tensor shapes — including the Qwen3 causal attention mask — carry symbolic batch and sequence dimensions throughout. **Dynamic batch verified:** batch = 1, 2, 4, 8 all produce correct output shapes.
31
+
32
+ ## Model details
33
+
34
+ | Property | Value |
35
+ |---|---|
36
+ | Base model | codefuse-ai/F2LLM-v2-0.6B |
37
+ | Architecture | Qwen3 decoder |
38
+ | Parameters | ~600 M |
39
+ | Embedding dim | 1024 |
40
+ | Max context | 32 768 tokens |
41
+ | Languages | 200+ (multilingual) |
42
+ | Inputs | `input_ids [batch, seq]`, `attention_mask [batch, seq]` |
43
+ | Output | `last_hidden_state [batch, seq, 1024]` |
44
+ | Pooling | Last-token pooling + L2 normalisation (applied by inference runtime) |
45
+ | File size | ~2.4 GB (`model.onnx` + `model.onnx.data`) |
46
+
47
+ ## Inference
48
+
49
+ ```python
50
+ import onnxruntime as ort
51
+ import numpy as np
52
+ from tokenizers import Tokenizer
53
+
54
+ tokenizer = Tokenizer.from_file("tokenizer.json")
55
+ tokenizer.enable_padding(pad_id=0, direction="right")
56
+ tokenizer.enable_truncation(max_length=512)
57
+
58
+ session = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])
59
+
60
+ texts = ["semantic search example", "another sentence"]
61
+ enc = tokenizer.encode_batch(texts)
62
+ ids = np.array([e.ids for e in enc], dtype=np.int64)
63
+ mask = np.array([e.attention_mask for e in enc], dtype=np.int64)
64
+
65
+ lhs = session.run(None, {"input_ids": ids, "attention_mask": mask})[0] # [batch, seq, 1024]
66
+
67
+ # Last-token pooling: take embedding at last non-padding position
68
+ seq_lens = mask.sum(axis=1) - 1
69
+ embeddings = lhs[np.arange(len(texts)), seq_lens]
70
+
71
+ # L2 normalise
72
+ norms = np.linalg.norm(embeddings, axis=1, keepdims=True)
73
+ embeddings = embeddings / np.maximum(norms, 1e-8)
74
+ print(embeddings.shape) # (2, 1024)
75
+ ```
76
+
77
+ > **Query prefix**: For asymmetric retrieval, prepend `"Instruct: <task description>\nQuery: "` to query strings. Documents are encoded without a prefix.
78
+
79
+ ## Files
80
+
81
+ | File | Size | Description |
82
+ |---|---|---|
83
+ | `model.onnx` | ~4 MB | ONNX graph (opset 20, no weights) |
84
+ | `model.onnx.data` | ~2.38 GB | External weight data |
85
+ | `tokenizer.json` | 8 MB | HuggingFace fast tokenizer |
86
+ | `config.json` | — | Model config |
87
+
88
+ ## Quantized variants
89
+
90
+ | Repo | Precision | Size | Notes |
91
+ |---|---|---|---|
92
+ | [cstr/F2LLM-v2-0.6B-ONNX](https://huggingface.co/cstr/F2LLM-v2-0.6B-ONNX) | FP32 | 2.4 GB | This repo — reference |
93
+ | [cstr/F2LLM-v2-0.6B-ONNX-INT8](https://huggingface.co/cstr/F2LLM-v2-0.6B-ONNX-INT8) | INT8 per-channel | 1.1 GB | Recommended for most use |
94
+ | [cstr/F2LLM-v2-0.6B-ONNX-INT4](https://huggingface.co/cstr/F2LLM-v2-0.6B-ONNX-INT4) | INT4 MatMulNBits | 0.9 GB | Minimum RAM |
95
+ | [cstr/F2LLM-v2-0.6B-ONNX-INT8-FULL](https://huggingface.co/cstr/F2LLM-v2-0.6B-ONNX-INT8-FULL) | INT8 incl. embeddings | 0.6 GB | Smallest file |
96
+
97
+ ## Citation
98
+
99
+ ```bibtex
100
+ @misc{f2llm-v2,
101
+ title={F2LLM-v2: Inclusive, Performant, and Efficient Embeddings for a Multilingual World},
102
+ author={Ziyin Zhang and Zihan Liao and Hang Yu and Peng Di and Rui Wang},
103
+ year={2026},
104
+ eprint={2603.19223},
105
+ archivePrefix={arXiv},
106
+ primaryClass={cs.CL},
107
+ url={https://arxiv.org/abs/2603.19223},
108
+ }
109
+ ```
110
+
111
+ ## License
112
+
113
+ Apache 2.0 — same as [codefuse-ai/F2LLM-v2-0.6B](https://huggingface.co/codefuse-ai/F2LLM-v2-0.6B).