Feature Extraction
Transformers
Safetensors
English
vfm
verification
guardrails
llm-as-a-judge
agent-governance
custom_code
Instructions to use spitis/VFM-0.6B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use spitis/VFM-0.6B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="spitis/VFM-0.6B", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("spitis/VFM-0.6B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Commit ·
d573d3f
0
Parent(s):
VFM public release
Browse files- .gitattributes +36 -0
- LICENSE +202 -0
- README.md +85 -0
- collator_vfm.py +114 -0
- config.json +100 -0
- configuration_vfm.py +67 -0
- merges.txt +0 -0
- model.safetensors +3 -0
- modeling_vfm.py +288 -0
- tokenizer.json +3 -0
- tokenizer_config.json +239 -0
- vocab.json +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
Apache License
|
| 3 |
+
Version 2.0, January 2004
|
| 4 |
+
http://www.apache.org/licenses/
|
| 5 |
+
|
| 6 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 7 |
+
|
| 8 |
+
1. Definitions.
|
| 9 |
+
|
| 10 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 11 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 12 |
+
|
| 13 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 14 |
+
the copyright owner that is granting the License.
|
| 15 |
+
|
| 16 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 17 |
+
other entities that control, are controlled by, or are under common
|
| 18 |
+
control with that entity. For the purposes of this definition,
|
| 19 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 20 |
+
direction or management of such entity, whether by contract or
|
| 21 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 22 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 23 |
+
|
| 24 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 25 |
+
exercising permissions granted by this License.
|
| 26 |
+
|
| 27 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 28 |
+
including but not limited to software source code, documentation
|
| 29 |
+
source, and configuration files.
|
| 30 |
+
|
| 31 |
+
"Object" form shall mean any form resulting from mechanical
|
| 32 |
+
transformation or translation of a Source form, including but
|
| 33 |
+
not limited to compiled object code, generated documentation,
|
| 34 |
+
and conversions to other media types.
|
| 35 |
+
|
| 36 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 37 |
+
Object form, made available under the License, as indicated by a
|
| 38 |
+
copyright notice that is included in or attached to the work
|
| 39 |
+
(an example is provided in the Appendix below).
|
| 40 |
+
|
| 41 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 42 |
+
form, that is based on (or derived from) the Work and for which the
|
| 43 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 44 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 45 |
+
of this License, Derivative Works shall not include works that remain
|
| 46 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 47 |
+
the Work and Derivative Works thereof.
|
| 48 |
+
|
| 49 |
+
"Contribution" shall mean any work of authorship, including
|
| 50 |
+
the original version of the Work and any modifications or additions
|
| 51 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 52 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 53 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 54 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 55 |
+
means any form of electronic, verbal, or written communication sent
|
| 56 |
+
to the Licensor or its representatives, including but not limited to
|
| 57 |
+
communication on electronic mailing lists, source code control systems,
|
| 58 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 59 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 60 |
+
excluding communication that is conspicuously marked or otherwise
|
| 61 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 62 |
+
|
| 63 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 64 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 65 |
+
subsequently incorporated within the Work.
|
| 66 |
+
|
| 67 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 68 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 69 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 70 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 71 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 72 |
+
Work and such Derivative Works in Source or Object form.
|
| 73 |
+
|
| 74 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 75 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 76 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 77 |
+
(except as stated in this section) patent license to make, have made,
|
| 78 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 79 |
+
where such license applies only to those patent claims licensable
|
| 80 |
+
by such Contributor that are necessarily infringed by their
|
| 81 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 82 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 83 |
+
institute patent litigation against any entity (including a
|
| 84 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 85 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 86 |
+
or contributory patent infringement, then any patent licenses
|
| 87 |
+
granted to You under this License for that Work shall terminate
|
| 88 |
+
as of the date such litigation is filed.
|
| 89 |
+
|
| 90 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 91 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 92 |
+
modifications, and in Source or Object form, provided that You
|
| 93 |
+
meet the following conditions:
|
| 94 |
+
|
| 95 |
+
(a) You must give any other recipients of the Work or
|
| 96 |
+
Derivative Works a copy of this License; and
|
| 97 |
+
|
| 98 |
+
(b) You must cause any modified files to carry prominent notices
|
| 99 |
+
stating that You changed the files; and
|
| 100 |
+
|
| 101 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 102 |
+
that You distribute, all copyright, patent, trademark, and
|
| 103 |
+
attribution notices from the Source form of the Work,
|
| 104 |
+
excluding those notices that do not pertain to any part of
|
| 105 |
+
the Derivative Works; and
|
| 106 |
+
|
| 107 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 108 |
+
distribution, then any Derivative Works that You distribute must
|
| 109 |
+
include a readable copy of the attribution notices contained
|
| 110 |
+
within such NOTICE file, excluding those notices that do not
|
| 111 |
+
pertain to any part of the Derivative Works, in at least one
|
| 112 |
+
of the following places: within a NOTICE text file distributed
|
| 113 |
+
as part of the Derivative Works; within the Source form or
|
| 114 |
+
documentation, if provided along with the Derivative Works; or,
|
| 115 |
+
within a display generated by the Derivative Works, if and
|
| 116 |
+
wherever such third-party notices normally appear. The contents
|
| 117 |
+
of the NOTICE file are for informational purposes only and
|
| 118 |
+
do not modify the License. You may add Your own attribution
|
| 119 |
+
notices within Derivative Works that You distribute, alongside
|
| 120 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 121 |
+
that such additional attribution notices cannot be construed
|
| 122 |
+
as modifying the License.
|
| 123 |
+
|
| 124 |
+
You may add Your own copyright statement to Your modifications and
|
| 125 |
+
may provide additional or different license terms and conditions
|
| 126 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 127 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 128 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 129 |
+
the conditions stated in this License.
|
| 130 |
+
|
| 131 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 132 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 133 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 134 |
+
this License, without any additional terms or conditions.
|
| 135 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 136 |
+
the terms of any separate license agreement you may have executed
|
| 137 |
+
with Licensor regarding such Contributions.
|
| 138 |
+
|
| 139 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 140 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 141 |
+
except as required for reasonable and customary use in describing the
|
| 142 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 143 |
+
|
| 144 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 145 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 146 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 147 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 148 |
+
implied, including, without limitation, any warranties or conditions
|
| 149 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 150 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 151 |
+
appropriateness of using or redistributing the Work and assume any
|
| 152 |
+
risks associated with Your exercise of permissions under this License.
|
| 153 |
+
|
| 154 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 155 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 156 |
+
unless required by applicable law (such as deliberate and grossly
|
| 157 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 158 |
+
liable to You for damages, including any direct, indirect, special,
|
| 159 |
+
incidental, or consequential damages of any character arising as a
|
| 160 |
+
result of this License or out of the use or inability to use the
|
| 161 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 162 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 163 |
+
other commercial damages or losses), even if such Contributor
|
| 164 |
+
has been advised of the possibility of such damages.
|
| 165 |
+
|
| 166 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 167 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 168 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 169 |
+
or other liability obligations and/or rights consistent with this
|
| 170 |
+
License. However, in accepting such obligations, You may act only
|
| 171 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 172 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 173 |
+
defend, and hold each Contributor harmless for any liability
|
| 174 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 175 |
+
of your accepting any such warranty or additional liability.
|
| 176 |
+
|
| 177 |
+
END OF TERMS AND CONDITIONS
|
| 178 |
+
|
| 179 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 180 |
+
|
| 181 |
+
To apply the Apache License to your work, attach the following
|
| 182 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 183 |
+
replaced with your own identifying information. (Don't include
|
| 184 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 185 |
+
comment syntax for the file format. We also recommend that a
|
| 186 |
+
file or class name and description of purpose be included on the
|
| 187 |
+
same "printed page" as the copyright notice for easier
|
| 188 |
+
identification within third-party archives.
|
| 189 |
+
|
| 190 |
+
Copyright 2024 Alibaba Cloud
|
| 191 |
+
|
| 192 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 193 |
+
you may not use this file except in compliance with the License.
|
| 194 |
+
You may obtain a copy of the License at
|
| 195 |
+
|
| 196 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 197 |
+
|
| 198 |
+
Unless required by applicable law or agreed to in writing, software
|
| 199 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 200 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 201 |
+
See the License for the specific language governing permissions and
|
| 202 |
+
limitations under the License.
|
README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: Qwen/Qwen3-0.6B
|
| 4 |
+
datasets:
|
| 5 |
+
- spitis/CriteriaBank
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
library_name: transformers
|
| 9 |
+
tags:
|
| 10 |
+
- verification
|
| 11 |
+
- guardrails
|
| 12 |
+
- llm-as-a-judge
|
| 13 |
+
- agent-governance
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# VFM-0.6B
|
| 17 |
+
|
| 18 |
+
VFM-0.6B verifies natural-language criteria against a context and target text. It uses a Qwen3-0.6B backbone and a three-class head, pretrained on [CriteriaBank](https://huggingface.co/datasets/spitis/CriteriaBank) for *Runtime Verification of Multiple Natural Language Criteria for Agent Governance* (NeurIPS 2026).
|
| 19 |
+
|
| 20 |
+
Each criterion receives **YES** (satisfied), **NO** (not satisfied), or **N/A** (inapplicable or insufficient evidence). Criteria are scored independently over a shared prefix, without text generation. [Code and training recipes](https://github.com/spitis/vfm).
|
| 21 |
+
|
| 22 |
+
**Use**
|
| 23 |
+
|
| 24 |
+
```bash
|
| 25 |
+
pip install git+https://github.com/spitis/vfm
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
```python
|
| 29 |
+
from vfm import VFM
|
| 30 |
+
|
| 31 |
+
vfm = VFM.from_pretrained("spitis/VFM-0.6B")
|
| 32 |
+
verdicts = vfm.verify(
|
| 33 |
+
context="Describe today's weather.",
|
| 34 |
+
target="It is sunny today.",
|
| 35 |
+
criteria=["Does the response mention sunshine?", "Does the response mention rain?"],
|
| 36 |
+
)
|
| 37 |
+
for v in verdicts:
|
| 38 |
+
print(v["criterion"], v["verdict"], v["p_yes"], v["p_no"], v["p_na"])
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
`context` accepts a string or chat messages; `target` is appended as the next turn. Outputs also include `logits` and `p_yes_binary = p_yes / (p_yes + p_no)`. Use `verify_batch` for separate traces.
|
| 42 |
+
|
| 43 |
+
Keep criteria short and atomic. Prefixes are left-truncated at 4,096 tokens by default (`max_length`); criterion blocks at 64 tokens, including chat-template tokens. `verify` reuses the prefix cache across chunks of 64 criteria (`chunk_size`).
|
| 44 |
+
|
| 45 |
+
**Training and results**
|
| 46 |
+
|
| 47 |
+
Full-parameter pretraining uses 393,531 model-labelled CriteriaBank rows, cross-entropy plus KL to the frozen base model (λ = 1), AdamW, and batch size 128. The released checkpoint is the one saved at **step 2,000 of the 3,075 pretraining steps**.
|
| 48 |
+
|
| 49 |
+
Paper results below use the released weights for zero-shot evaluation; ternary benchmarks use their YES/NO subset.
|
| 50 |
+
|
| 51 |
+
| Benchmark | Zero-shot ROC-AUC |
|
| 52 |
+
|---|---:|
|
| 53 |
+
| InFoBench | 0.887 |
|
| 54 |
+
| Synthetic governance | 0.880 |
|
| 55 |
+
| ContractNLI | 0.857 |
|
| 56 |
+
| INSURE-Dial | 0.713 |
|
| 57 |
+
| BeaverTails | 0.722 |
|
| 58 |
+
| IFEval | 0.654 |
|
| 59 |
+
| PRM800K | 0.635 |
|
| 60 |
+
| LLM-AggreFact | 0.736 |
|
| 61 |
+
|
| 62 |
+
After benchmark finetuning (mean ± standard deviation over three seeds):
|
| 63 |
+
|
| 64 |
+
- Synthetic governance accuracy: **87.2 ± 0.5%**, with **75.1 ± 1.4%** on transfer domains.
|
| 65 |
+
- INSURE-Dial accuracy: **82.6 ± 0.6%**.
|
| 66 |
+
- Across six learning curves, macro AULC is **0.789**, versus 0.772 without KL and 0.736 for Direct-FT.
|
| 67 |
+
|
| 68 |
+
Finetuned results require separate benchmark training. Governance uses dev selection; INSURE-Dial uses five-fold checkpoint selection over real calls.
|
| 69 |
+
|
| 70 |
+
**Limitations**
|
| 71 |
+
|
| 72 |
+
Finetune and tune decision thresholds for your domain. Zero-shot calibration and N/A prediction are weak. Labels are model-generated; evaluations are English-only and text-only. Even the best finetuned 4B verifier approves about 20% of gold violations on INSURE-Dial. Use for monitoring and escalation, not standalone enforcement.
|
| 73 |
+
|
| 74 |
+
**License:** Apache-2.0, including the Qwen3-0.6B base model. Tokenizer files are unchanged from Qwen3.
|
| 75 |
+
|
| 76 |
+
**Citation**
|
| 77 |
+
|
| 78 |
+
```bibtex
|
| 79 |
+
@inproceedings{pitis2026vfm,
|
| 80 |
+
title = {Runtime Verification of Multiple Natural Language Criteria for Agent Governance},
|
| 81 |
+
author = {Pitis, Silviu and Alamdari, Parand A. and Tang, Jessica and Klassen, Toryn Q. and McIlraith, Sheila A.},
|
| 82 |
+
booktitle = {Advances in Neural Information Processing Systems},
|
| 83 |
+
year = {2026}
|
| 84 |
+
}
|
| 85 |
+
```
|
collator_vfm.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tokenization and batching for the VFM.
|
| 2 |
+
|
| 3 |
+
The (context, target) prefix is rendered with the backbone's chat template, with the
|
| 4 |
+
target appended as the next turn. Each criterion is rendered as its own one-turn chat
|
| 5 |
+
prompt (user message + assistant generation prompt) and padded to a fixed block of
|
| 6 |
+
`max_criterion_length` tokens; the head reads the last non-padding token of each block.
|
| 7 |
+
"""
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import warnings
|
| 11 |
+
from typing import Any, Dict, List, Optional, Sequence, Union
|
| 12 |
+
|
| 13 |
+
import torch
|
| 14 |
+
|
| 15 |
+
from .configuration_vfm import LABEL_NAMES
|
| 16 |
+
|
| 17 |
+
Messages = List[Dict[str, Any]]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _messages(context: Union[str, Messages, None]) -> Messages:
|
| 21 |
+
if context is None:
|
| 22 |
+
return []
|
| 23 |
+
if isinstance(context, str):
|
| 24 |
+
return [{"role": "user", "content": context}]
|
| 25 |
+
return list(context)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _next_role(messages: Messages) -> str:
|
| 29 |
+
"""Role of the target turn: assistant after a user turn, otherwise user."""
|
| 30 |
+
if not messages:
|
| 31 |
+
return "user"
|
| 32 |
+
return "assistant" if messages[-1].get("role", "user") == "user" else "user"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def format_prefix(tokenizer, context: Union[str, Messages, None], target: Optional[str]) -> str:
|
| 36 |
+
"""Render the shared (context, target) prefix as text."""
|
| 37 |
+
messages = _messages(context)
|
| 38 |
+
if target:
|
| 39 |
+
messages = messages + [{"role": _next_role(messages), "content": target}]
|
| 40 |
+
return tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=False,
|
| 41 |
+
enable_thinking=False)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def format_criterion(tokenizer, criterion: str) -> str:
|
| 45 |
+
"""Render one criterion as a one-turn chat prompt ending at the answer position (with
|
| 46 |
+
thinking disabled, so the template inserts an empty think block)."""
|
| 47 |
+
return tokenizer.apply_chat_template([{"role": "user", "content": criterion}], tokenize=False,
|
| 48 |
+
add_generation_prompt=True, enable_thinking=False)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class VFMCollator:
|
| 52 |
+
"""Turns VFM rows into model inputs.
|
| 53 |
+
|
| 54 |
+
Each row is a dict with `context`, `target`, `criteria` (list of N strings) and
|
| 55 |
+
optionally `labels` (list of N labels). All rows in a batch must have the same N
|
| 56 |
+
(single-criterion rows are the common case for training).
|
| 57 |
+
|
| 58 |
+
Returns `input_ids`/`attention_mask` (B, L), left-padded and left-truncated, and
|
| 59 |
+
`criterion_input_ids`/`criterion_attention_mask` (B, N*T) with T =
|
| 60 |
+
`max_criterion_length`, plus `labels` (B, N) when labels are present.
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
def __init__(self, tokenizer, max_length: int = 4096, max_criterion_length: int = 64):
|
| 64 |
+
self.tokenizer = tokenizer
|
| 65 |
+
self.max_length = max_length
|
| 66 |
+
self.max_criterion_length = max_criterion_length
|
| 67 |
+
if tokenizer.pad_token is None:
|
| 68 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 69 |
+
self._warned_long = False
|
| 70 |
+
|
| 71 |
+
def _tokenize(self, texts: List[str], max_length: int, padding_side: str, padding):
|
| 72 |
+
tok = self.tokenizer
|
| 73 |
+
old = (tok.padding_side, tok.truncation_side)
|
| 74 |
+
tok.padding_side, tok.truncation_side = padding_side, "left"
|
| 75 |
+
try:
|
| 76 |
+
return tok(texts, padding=padding, truncation=True, max_length=max_length,
|
| 77 |
+
return_tensors="pt")
|
| 78 |
+
finally:
|
| 79 |
+
tok.padding_side, tok.truncation_side = old
|
| 80 |
+
|
| 81 |
+
def encode_prefixes(self, rows: Sequence[Dict[str, Any]]) -> Dict[str, torch.Tensor]:
|
| 82 |
+
texts = [format_prefix(self.tokenizer, r.get("context"), r.get("target")) for r in rows]
|
| 83 |
+
enc = self._tokenize(texts, self.max_length, "left", "longest")
|
| 84 |
+
return {"input_ids": enc["input_ids"], "attention_mask": enc["attention_mask"]}
|
| 85 |
+
|
| 86 |
+
def encode_criteria(self, criteria: Sequence[str]) -> Dict[str, torch.Tensor]:
|
| 87 |
+
"""Tokenize criteria into fixed-size blocks: returns (N, T) tensors."""
|
| 88 |
+
texts = [format_criterion(self.tokenizer, c) for c in criteria]
|
| 89 |
+
if not self._warned_long:
|
| 90 |
+
lengths = [len(self.tokenizer(t, add_special_tokens=False)["input_ids"]) for t in texts]
|
| 91 |
+
if max(lengths, default=0) > self.max_criterion_length:
|
| 92 |
+
warnings.warn(
|
| 93 |
+
f"Some criteria exceed {self.max_criterion_length} tokens including the chat "
|
| 94 |
+
"template and are truncated from the left, as in training. Keep criteria short "
|
| 95 |
+
"and atomic.", stacklevel=3)
|
| 96 |
+
self._warned_long = True
|
| 97 |
+
enc = self._tokenize(texts, self.max_criterion_length, "right", "max_length")
|
| 98 |
+
return {"criterion_input_ids": enc["input_ids"],
|
| 99 |
+
"criterion_attention_mask": enc["attention_mask"]}
|
| 100 |
+
|
| 101 |
+
def __call__(self, rows: Sequence[Dict[str, Any]]) -> Dict[str, torch.Tensor]:
|
| 102 |
+
n = len(rows[0]["criteria"])
|
| 103 |
+
if any(len(r["criteria"]) != n for r in rows):
|
| 104 |
+
raise ValueError("All rows in a batch must have the same number of criteria")
|
| 105 |
+
batch = self.encode_prefixes(rows)
|
| 106 |
+
crit = self.encode_criteria([c for r in rows for c in r["criteria"]])
|
| 107 |
+
B, T = len(rows), self.max_criterion_length
|
| 108 |
+
batch["criterion_input_ids"] = crit["criterion_input_ids"].reshape(B, n * T)
|
| 109 |
+
batch["criterion_attention_mask"] = crit["criterion_attention_mask"].reshape(B, n * T)
|
| 110 |
+
if rows[0].get("labels") is not None:
|
| 111 |
+
batch["labels"] = torch.tensor([[LABEL_NAMES.index(l) for l in r["labels"]] for r in rows],
|
| 112 |
+
dtype=torch.long)
|
| 113 |
+
return batch
|
| 114 |
+
|
config.json
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"VFMForCriteriaVerification"
|
| 4 |
+
],
|
| 5 |
+
"auto_map": {
|
| 6 |
+
"AutoConfig": "configuration_vfm.VFMConfig",
|
| 7 |
+
"AutoModel": "modeling_vfm.VFMForCriteriaVerification"
|
| 8 |
+
},
|
| 9 |
+
"backbone_config": {
|
| 10 |
+
"_name_or_path": "Qwen/Qwen3-0.6B",
|
| 11 |
+
"architectures": [
|
| 12 |
+
"Qwen3Model"
|
| 13 |
+
],
|
| 14 |
+
"attention_bias": false,
|
| 15 |
+
"attention_dropout": 0.0,
|
| 16 |
+
"bos_token_id": 151643,
|
| 17 |
+
"dtype": "bfloat16",
|
| 18 |
+
"eos_token_id": 151645,
|
| 19 |
+
"head_dim": 128,
|
| 20 |
+
"hidden_act": "silu",
|
| 21 |
+
"hidden_size": 1024,
|
| 22 |
+
"initializer_range": 0.02,
|
| 23 |
+
"intermediate_size": 3072,
|
| 24 |
+
"layer_types": [
|
| 25 |
+
"full_attention",
|
| 26 |
+
"full_attention",
|
| 27 |
+
"full_attention",
|
| 28 |
+
"full_attention",
|
| 29 |
+
"full_attention",
|
| 30 |
+
"full_attention",
|
| 31 |
+
"full_attention",
|
| 32 |
+
"full_attention",
|
| 33 |
+
"full_attention",
|
| 34 |
+
"full_attention",
|
| 35 |
+
"full_attention",
|
| 36 |
+
"full_attention",
|
| 37 |
+
"full_attention",
|
| 38 |
+
"full_attention",
|
| 39 |
+
"full_attention",
|
| 40 |
+
"full_attention",
|
| 41 |
+
"full_attention",
|
| 42 |
+
"full_attention",
|
| 43 |
+
"full_attention",
|
| 44 |
+
"full_attention",
|
| 45 |
+
"full_attention",
|
| 46 |
+
"full_attention",
|
| 47 |
+
"full_attention",
|
| 48 |
+
"full_attention",
|
| 49 |
+
"full_attention",
|
| 50 |
+
"full_attention",
|
| 51 |
+
"full_attention",
|
| 52 |
+
"full_attention"
|
| 53 |
+
],
|
| 54 |
+
"max_position_embeddings": 40960,
|
| 55 |
+
"max_window_layers": 28,
|
| 56 |
+
"model_type": "qwen3",
|
| 57 |
+
"num_attention_heads": 16,
|
| 58 |
+
"num_hidden_layers": 28,
|
| 59 |
+
"num_key_value_heads": 8,
|
| 60 |
+
"rms_norm_eps": 1e-06,
|
| 61 |
+
"rope_scaling": null,
|
| 62 |
+
"rope_theta": 1000000,
|
| 63 |
+
"sliding_window": null,
|
| 64 |
+
"tie_word_embeddings": true,
|
| 65 |
+
"use_cache": true,
|
| 66 |
+
"use_sliding_window": false,
|
| 67 |
+
"vocab_size": 151936
|
| 68 |
+
},
|
| 69 |
+
"base_model_name_or_path": "Qwen/Qwen3-0.6B",
|
| 70 |
+
"dtype": "bfloat16",
|
| 71 |
+
"enable_thinking": false,
|
| 72 |
+
"id2label": {
|
| 73 |
+
"0": "YES",
|
| 74 |
+
"1": "NO",
|
| 75 |
+
"2": "N/A"
|
| 76 |
+
},
|
| 77 |
+
"isolate_criteria": true,
|
| 78 |
+
"label2id": {
|
| 79 |
+
"N/A": 2,
|
| 80 |
+
"NO": 1,
|
| 81 |
+
"YES": 0
|
| 82 |
+
},
|
| 83 |
+
"max_criterion_length": 64,
|
| 84 |
+
"max_prefix_length": 4096,
|
| 85 |
+
"model_type": "vfm",
|
| 86 |
+
"preserve_lambda": 1.0,
|
| 87 |
+
"preserve_loss": "kl_base",
|
| 88 |
+
"tie_word_embeddings": false,
|
| 89 |
+
"transformers_version": "4.57.1",
|
| 90 |
+
"verbalizer_token_ids": [
|
| 91 |
+
7414,
|
| 92 |
+
2753,
|
| 93 |
+
21693
|
| 94 |
+
],
|
| 95 |
+
"verbalizers": [
|
| 96 |
+
" Yes",
|
| 97 |
+
"No",
|
| 98 |
+
" Unknown"
|
| 99 |
+
]
|
| 100 |
+
}
|
configuration_vfm.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Configuration for the VFM criterion verifier."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
from typing import Any, Dict, List, Optional, Union
|
| 5 |
+
|
| 6 |
+
from transformers import AutoConfig, PretrainedConfig
|
| 7 |
+
|
| 8 |
+
LABEL_NAMES = ["YES", "NO", "N/A"]
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class VFMConfig(PretrainedConfig):
|
| 12 |
+
r"""Configuration of a VFM: a decoder-only backbone plus a 3-way (YES / NO / N/A) head.
|
| 13 |
+
|
| 14 |
+
Args:
|
| 15 |
+
backbone_config (`dict` or `PretrainedConfig`): configuration of the backbone
|
| 16 |
+
(e.g. a `Qwen3Config`). The backbone is built from this config, so loading a
|
| 17 |
+
VFM never downloads the base model.
|
| 18 |
+
max_criterion_length (`int`, defaults to 64): token length of each criterion
|
| 19 |
+
block, including the chat-template tokens. Longer criteria are truncated
|
| 20 |
+
from the left, as in training.
|
| 21 |
+
max_prefix_length (`int`, defaults to 4096): default maximum token length of the
|
| 22 |
+
shared (context, target) prefix. Longer prefixes are truncated from the left.
|
| 23 |
+
verbalizers (`list[str]`): verbalizer strings whose unembedding rows initialized
|
| 24 |
+
the head (training provenance only).
|
| 25 |
+
verbalizer_token_ids (`list[int]`): token ids of `verbalizers`.
|
| 26 |
+
base_model_name_or_path (`str`): the base model the backbone was trained from
|
| 27 |
+
(provenance only; not loaded).
|
| 28 |
+
preserve_loss (`str`): pretraining regularizer, `"kl_base"` or `"none"`
|
| 29 |
+
(training metadata only).
|
| 30 |
+
preserve_lambda (`float`): weight of the pretraining regularizer.
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
model_type = "vfm"
|
| 34 |
+
sub_configs = {"backbone_config": AutoConfig}
|
| 35 |
+
|
| 36 |
+
def __init__(
|
| 37 |
+
self,
|
| 38 |
+
backbone_config: Optional[Union[Dict[str, Any], PretrainedConfig]] = None,
|
| 39 |
+
max_criterion_length: int = 64,
|
| 40 |
+
max_prefix_length: int = 4096,
|
| 41 |
+
verbalizers: Optional[List[str]] = None,
|
| 42 |
+
verbalizer_token_ids: Optional[List[int]] = None,
|
| 43 |
+
base_model_name_or_path: Optional[str] = None,
|
| 44 |
+
preserve_loss: str = "none",
|
| 45 |
+
preserve_lambda: float = 0.0,
|
| 46 |
+
**kwargs,
|
| 47 |
+
):
|
| 48 |
+
if isinstance(backbone_config, dict):
|
| 49 |
+
backbone_config = dict(backbone_config)
|
| 50 |
+
model_type = backbone_config.pop("model_type", "qwen3")
|
| 51 |
+
backbone_config = AutoConfig.for_model(model_type, **backbone_config)
|
| 52 |
+
self.backbone_config = backbone_config
|
| 53 |
+
self.max_criterion_length = max_criterion_length
|
| 54 |
+
self.max_prefix_length = max_prefix_length
|
| 55 |
+
self.verbalizers = verbalizers
|
| 56 |
+
self.verbalizer_token_ids = verbalizer_token_ids
|
| 57 |
+
self.base_model_name_or_path = base_model_name_or_path
|
| 58 |
+
self.preserve_loss = preserve_loss
|
| 59 |
+
self.preserve_lambda = preserve_lambda
|
| 60 |
+
kwargs.setdefault("id2label", {i: n for i, n in enumerate(LABEL_NAMES)})
|
| 61 |
+
kwargs.setdefault("label2id", {n: i for i, n in enumerate(LABEL_NAMES)})
|
| 62 |
+
kwargs.setdefault("tie_word_embeddings", False)
|
| 63 |
+
super().__init__(**kwargs)
|
| 64 |
+
|
| 65 |
+
@property
|
| 66 |
+
def hidden_size(self) -> int:
|
| 67 |
+
return self.backbone_config.hidden_size
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e2a66be03fe742e9ae030405b4009a66d85c5680e779621aa43946aba578d4eb
|
| 3 |
+
size 1192142366
|
modeling_vfm.py
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""VFM: a criterion verifier with tree attention over a shared (context, target) prefix.
|
| 2 |
+
|
| 3 |
+
The backbone reads the prefix once, followed by N criterion blocks. A 4D attention mask
|
| 4 |
+
lets each criterion attend to the full prefix and causally to itself, but not to other
|
| 5 |
+
criteria, and the prefix never attends to criteria. Every criterion block starts at the
|
| 6 |
+
position right after the prefix, so verdicts do not depend on how many criteria are
|
| 7 |
+
scored or in what order. A linear head maps the hidden state of the last token of each
|
| 8 |
+
block to YES / NO / N/A logits.
|
| 9 |
+
"""
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
from dataclasses import dataclass
|
| 13 |
+
from typing import Any, Dict, List, Optional, Sequence
|
| 14 |
+
|
| 15 |
+
import torch
|
| 16 |
+
import torch.nn as nn
|
| 17 |
+
from transformers import AutoModel, PreTrainedModel
|
| 18 |
+
from transformers.utils import ModelOutput
|
| 19 |
+
|
| 20 |
+
from .collator_vfm import VFMCollator
|
| 21 |
+
from .configuration_vfm import LABEL_NAMES, VFMConfig
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@dataclass
|
| 25 |
+
class VFMOutput(ModelOutput):
|
| 26 |
+
"""Outputs of `VFMForCriteriaVerification`.
|
| 27 |
+
|
| 28 |
+
logits: (B, N, 3) YES / NO / N/A logits, one row per criterion.
|
| 29 |
+
loss: cross-entropy against `labels` when given (ignore index -100).
|
| 30 |
+
prefix_hidden_states: (B, L, H) last-layer prefix states, only when requested
|
| 31 |
+
(used by the KL regularizer during pretraining).
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
loss: Optional[torch.FloatTensor] = None
|
| 35 |
+
logits: Optional[torch.FloatTensor] = None
|
| 36 |
+
prefix_hidden_states: Optional[torch.FloatTensor] = None
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def _criterion_mask(n_blocks: int, block: int, crit_mask: torch.Tensor) -> torch.Tensor:
|
| 40 |
+
"""(B, 1, n_blocks*block, n_blocks*block) boolean mask among criterion tokens: causal
|
| 41 |
+
within each block, no attention across blocks."""
|
| 42 |
+
device = crit_mask.device
|
| 43 |
+
idx = torch.arange(n_blocks * block, device=device)
|
| 44 |
+
r, c = idx.unsqueeze(1), idx.unsqueeze(0)
|
| 45 |
+
allowed = (r >= c) & (r // block == c // block)
|
| 46 |
+
return allowed.unsqueeze(0).unsqueeze(0) & (crit_mask.unsqueeze(1).unsqueeze(1) == 1)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def _readout(hidden: torch.Tensor, crit_mask: torch.Tensor, n_blocks: int, block: int) -> torch.Tensor:
|
| 50 |
+
"""Hidden state at the last non-padding token of each criterion block: (B, N, H)."""
|
| 51 |
+
B, _, H = hidden.shape
|
| 52 |
+
blocks = hidden.reshape(B, n_blocks, block, H)
|
| 53 |
+
last = (crit_mask.reshape(B, n_blocks, block).sum(-1).long() - 1).clamp(min=0)
|
| 54 |
+
return torch.gather(blocks, 2, last[:, :, None, None].expand(-1, -1, 1, H)).squeeze(2)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class VFMPreTrainedModel(PreTrainedModel):
|
| 58 |
+
config_class = VFMConfig
|
| 59 |
+
base_model_prefix = "vfm"
|
| 60 |
+
supports_gradient_checkpointing = True
|
| 61 |
+
_supports_sdpa = True
|
| 62 |
+
_supports_flash_attn = False
|
| 63 |
+
_supports_flash_attn_2 = False
|
| 64 |
+
_no_split_modules = ["Qwen3DecoderLayer"]
|
| 65 |
+
|
| 66 |
+
def _init_weights(self, module):
|
| 67 |
+
std = getattr(self.config.backbone_config, "initializer_range", 0.02)
|
| 68 |
+
if isinstance(module, nn.Linear):
|
| 69 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 70 |
+
if module.bias is not None:
|
| 71 |
+
module.bias.data.zero_()
|
| 72 |
+
elif isinstance(module, nn.Embedding):
|
| 73 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 74 |
+
elif hasattr(module, "weight") and module.__class__.__name__.endswith("RMSNorm"):
|
| 75 |
+
module.weight.data.fill_(1.0)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class VFMForCriteriaVerification(VFMPreTrainedModel):
|
| 79 |
+
"""Backbone + ternary verification head. See the module docstring for the layout."""
|
| 80 |
+
|
| 81 |
+
def __init__(self, config: VFMConfig, backbone: Optional[nn.Module] = None):
|
| 82 |
+
super().__init__(config)
|
| 83 |
+
bcfg = backbone.config if backbone is not None else config.backbone_config
|
| 84 |
+
# The tree mask is a dense 4D mask, which flash-attention kernels do not accept.
|
| 85 |
+
if getattr(bcfg, "_attn_implementation", None) in (None, "flash_attention_2", "flash_attention_3"):
|
| 86 |
+
bcfg._attn_implementation = "sdpa"
|
| 87 |
+
if backbone is None:
|
| 88 |
+
backbone = AutoModel.from_config(bcfg)
|
| 89 |
+
self.backbone = backbone
|
| 90 |
+
self.verification_head = nn.Linear(config.hidden_size, len(LABEL_NAMES), bias=True)
|
| 91 |
+
self.post_init()
|
| 92 |
+
|
| 93 |
+
# ------------------------------------------------------------------ helpers
|
| 94 |
+
def get_input_embeddings(self):
|
| 95 |
+
return self.backbone.get_input_embeddings()
|
| 96 |
+
|
| 97 |
+
def set_input_embeddings(self, value):
|
| 98 |
+
self.backbone.set_input_embeddings(value)
|
| 99 |
+
|
| 100 |
+
def _float_mask(self, mask_bool: torch.Tensor, dtype: torch.dtype) -> torch.Tensor:
|
| 101 |
+
zero = torch.tensor(0.0, dtype=dtype, device=mask_bool.device)
|
| 102 |
+
neg = torch.tensor(torch.finfo(dtype).min, dtype=dtype, device=mask_bool.device)
|
| 103 |
+
return torch.where(mask_bool, zero, neg)
|
| 104 |
+
|
| 105 |
+
# ------------------------------------------------------------------ forward
|
| 106 |
+
def forward(
|
| 107 |
+
self,
|
| 108 |
+
input_ids: torch.LongTensor,
|
| 109 |
+
criterion_input_ids: torch.LongTensor,
|
| 110 |
+
attention_mask: Optional[torch.LongTensor] = None,
|
| 111 |
+
criterion_attention_mask: Optional[torch.LongTensor] = None,
|
| 112 |
+
labels: Optional[torch.LongTensor] = None,
|
| 113 |
+
output_prefix_hidden_states: bool = False,
|
| 114 |
+
**kwargs,
|
| 115 |
+
) -> VFMOutput:
|
| 116 |
+
"""Score N criteria per row in one pass.
|
| 117 |
+
|
| 118 |
+
input_ids, attention_mask: (B, L) left-padded prefix.
|
| 119 |
+
criterion_input_ids, criterion_attention_mask: (B, N*T) right-padded criterion
|
| 120 |
+
blocks of T = config.max_criterion_length tokens each.
|
| 121 |
+
labels: optional (B, N) with 0=YES, 1=NO, 2=N/A, -100=ignore.
|
| 122 |
+
"""
|
| 123 |
+
B, L = input_ids.shape
|
| 124 |
+
T = self.config.max_criterion_length
|
| 125 |
+
device = input_ids.device
|
| 126 |
+
if attention_mask is None:
|
| 127 |
+
attention_mask = torch.ones_like(input_ids)
|
| 128 |
+
if criterion_attention_mask is None:
|
| 129 |
+
criterion_attention_mask = torch.ones_like(criterion_input_ids)
|
| 130 |
+
if criterion_input_ids.shape[1] % T:
|
| 131 |
+
raise ValueError(f"criterion_input_ids length must be a multiple of {T}")
|
| 132 |
+
N = criterion_input_ids.shape[1] // T
|
| 133 |
+
C = N * T
|
| 134 |
+
|
| 135 |
+
embed = self.get_input_embeddings()
|
| 136 |
+
inputs_embeds = torch.cat([embed(input_ids), embed(criterion_input_ids)], dim=1)
|
| 137 |
+
|
| 138 |
+
# Positions: prefix 0..L-1; every criterion block continues from the prefix end.
|
| 139 |
+
prefix_pos = torch.arange(L, device=device).unsqueeze(0).expand(B, -1)
|
| 140 |
+
crit_pos = (L + torch.arange(T, device=device)).repeat(N).unsqueeze(0).expand(B, -1)
|
| 141 |
+
position_ids = torch.cat([prefix_pos, crit_pos], dim=1)
|
| 142 |
+
|
| 143 |
+
# Tree attention mask (True = may attend).
|
| 144 |
+
key_ok = attention_mask.unsqueeze(1).unsqueeze(1) == 1 # (B,1,1,L)
|
| 145 |
+
mask = torch.zeros((B, 1, L + C, L + C), dtype=torch.bool, device=device)
|
| 146 |
+
causal = torch.tril(torch.ones((L, L), dtype=torch.bool, device=device))
|
| 147 |
+
mask[:, :, :L, :L] = causal.unsqueeze(0).unsqueeze(0) & key_ok
|
| 148 |
+
mask[:, :, L:, :L] = key_ok.expand(B, 1, C, L)
|
| 149 |
+
mask[:, :, L:, L:] = _criterion_mask(N, T, criterion_attention_mask)
|
| 150 |
+
|
| 151 |
+
out = self.backbone(inputs_embeds=inputs_embeds, position_ids=position_ids,
|
| 152 |
+
attention_mask=self._float_mask(mask, inputs_embeds.dtype),
|
| 153 |
+
use_cache=False, return_dict=True)
|
| 154 |
+
hidden = out.last_hidden_state
|
| 155 |
+
logits = self.verification_head(_readout(hidden[:, L:], criterion_attention_mask, N, T))
|
| 156 |
+
|
| 157 |
+
loss = None
|
| 158 |
+
if labels is not None:
|
| 159 |
+
loss = nn.functional.cross_entropy(logits.reshape(-1, logits.shape[-1]).float(),
|
| 160 |
+
labels.reshape(-1).to(device), ignore_index=-100)
|
| 161 |
+
return VFMOutput(loss=loss, logits=logits,
|
| 162 |
+
prefix_hidden_states=hidden[:, :L] if output_prefix_hidden_states else None)
|
| 163 |
+
|
| 164 |
+
# -------------------------------------------------------- prefix-cached path
|
| 165 |
+
@torch.no_grad()
|
| 166 |
+
def encode_prefix(self, input_ids: torch.LongTensor, attention_mask: Optional[torch.LongTensor] = None):
|
| 167 |
+
"""Run the backbone on the prefix only; returns (cache, prefix_length)."""
|
| 168 |
+
from transformers import DynamicCache
|
| 169 |
+
|
| 170 |
+
L = input_ids.shape[1]
|
| 171 |
+
if attention_mask is None:
|
| 172 |
+
attention_mask = torch.ones_like(input_ids)
|
| 173 |
+
position_ids = torch.arange(L, device=input_ids.device).unsqueeze(0).expand(input_ids.shape[0], -1)
|
| 174 |
+
cache = DynamicCache(config=self.backbone.config)
|
| 175 |
+
out = self.backbone(input_ids=input_ids, attention_mask=attention_mask, position_ids=position_ids,
|
| 176 |
+
past_key_values=cache, use_cache=True, return_dict=True)
|
| 177 |
+
return out.past_key_values, L
|
| 178 |
+
|
| 179 |
+
@torch.no_grad()
|
| 180 |
+
def score_with_prefix_cache(self, criterion_input_ids, criterion_attention_mask, cache, prefix_length,
|
| 181 |
+
prefix_attention_mask=None) -> torch.Tensor:
|
| 182 |
+
"""Logits (B, N, 3) for criterion blocks attending to a cached prefix.
|
| 183 |
+
|
| 184 |
+
The cache is cropped back to the prefix afterwards, so it can be reused for the
|
| 185 |
+
next chunk of criteria.
|
| 186 |
+
"""
|
| 187 |
+
B = criterion_input_ids.shape[0]
|
| 188 |
+
T = self.config.max_criterion_length
|
| 189 |
+
N = criterion_input_ids.shape[1] // T
|
| 190 |
+
C = N * T
|
| 191 |
+
L = prefix_length
|
| 192 |
+
device = criterion_input_ids.device
|
| 193 |
+
if prefix_attention_mask is None:
|
| 194 |
+
prefix_attention_mask = torch.ones((B, L), dtype=torch.long, device=device)
|
| 195 |
+
inputs_embeds = self.get_input_embeddings()(criterion_input_ids)
|
| 196 |
+
position_ids = (L + torch.arange(T, device=device)).repeat(N).unsqueeze(0).expand(B, -1)
|
| 197 |
+
mask = torch.zeros((B, 1, C, L + C), dtype=torch.bool, device=device)
|
| 198 |
+
mask[:, :, :, :L] = (prefix_attention_mask.unsqueeze(1).unsqueeze(1) == 1).expand(B, 1, C, L)
|
| 199 |
+
mask[:, :, :, L:] = _criterion_mask(N, T, criterion_attention_mask)
|
| 200 |
+
try:
|
| 201 |
+
out = self.backbone(inputs_embeds=inputs_embeds, position_ids=position_ids,
|
| 202 |
+
attention_mask=self._float_mask(mask, inputs_embeds.dtype),
|
| 203 |
+
past_key_values=cache, cache_position=torch.arange(L, L + C, device=device),
|
| 204 |
+
use_cache=True, return_dict=True)
|
| 205 |
+
finally:
|
| 206 |
+
extra = cache.get_seq_length() - L
|
| 207 |
+
if extra > 0:
|
| 208 |
+
cache.crop(-extra)
|
| 209 |
+
return self.verification_head(_readout(out.last_hidden_state, criterion_attention_mask, N, T))
|
| 210 |
+
|
| 211 |
+
# ------------------------------------------------------------- high level
|
| 212 |
+
def _collator(self, tokenizer, max_length: Optional[int] = None) -> VFMCollator:
|
| 213 |
+
return VFMCollator(tokenizer, max_length=max_length or self.config.max_prefix_length,
|
| 214 |
+
max_criterion_length=self.config.max_criterion_length)
|
| 215 |
+
|
| 216 |
+
@staticmethod
|
| 217 |
+
def _verdicts(criteria: Sequence[str], logits: torch.Tensor) -> List[Dict[str, Any]]:
|
| 218 |
+
logits = logits.float()
|
| 219 |
+
probs = logits.softmax(-1).tolist()
|
| 220 |
+
binary = logits[:, :2].softmax(-1)[:, 0].tolist()
|
| 221 |
+
out = []
|
| 222 |
+
for c, p, pb, lg in zip(criteria, probs, binary, logits.tolist()):
|
| 223 |
+
out.append({"criterion": c, "verdict": LABEL_NAMES[max(range(3), key=p.__getitem__)],
|
| 224 |
+
"p_yes": p[0], "p_no": p[1], "p_na": p[2], "p_yes_binary": pb, "logits": lg})
|
| 225 |
+
return out
|
| 226 |
+
|
| 227 |
+
@torch.no_grad()
|
| 228 |
+
def verify(self, tokenizer, context, target: Optional[str], criteria: Sequence[str],
|
| 229 |
+
chunk_size: int = 64, max_length: Optional[int] = None) -> List[Dict[str, Any]]:
|
| 230 |
+
"""Score many criteria against one (context, target).
|
| 231 |
+
|
| 232 |
+
The prefix is encoded once and its key-value cache is reused for chunks of
|
| 233 |
+
`chunk_size` criteria, so memory stays flat in the number of criteria.
|
| 234 |
+
|
| 235 |
+
Args:
|
| 236 |
+
tokenizer: the model's tokenizer.
|
| 237 |
+
context: a string (one user turn) or a list of {"role", "content"} messages.
|
| 238 |
+
target: the text being verified (e.g. the assistant response), or None.
|
| 239 |
+
criteria: natural-language yes/no questions.
|
| 240 |
+
Returns:
|
| 241 |
+
One dict per criterion: criterion, verdict (YES / NO / N/A), p_yes, p_no,
|
| 242 |
+
p_na, p_yes_binary (P(YES) renormalized over YES and NO), and the raw logits.
|
| 243 |
+
"""
|
| 244 |
+
if isinstance(criteria, str):
|
| 245 |
+
criteria = [criteria]
|
| 246 |
+
if not criteria:
|
| 247 |
+
return []
|
| 248 |
+
self.eval()
|
| 249 |
+
device = next(self.parameters()).device
|
| 250 |
+
col = self._collator(tokenizer, max_length)
|
| 251 |
+
pre = col.encode_prefixes([{"context": context, "target": target}])
|
| 252 |
+
cache, L = self.encode_prefix(pre["input_ids"].to(device), pre["attention_mask"].to(device))
|
| 253 |
+
results = []
|
| 254 |
+
for i in range(0, len(criteria), chunk_size):
|
| 255 |
+
chunk = list(criteria[i:i + chunk_size])
|
| 256 |
+
enc = col.encode_criteria(chunk)
|
| 257 |
+
ids = enc["criterion_input_ids"].reshape(1, -1).to(device)
|
| 258 |
+
am = enc["criterion_attention_mask"].reshape(1, -1).to(device)
|
| 259 |
+
logits = self.score_with_prefix_cache(ids, am, cache, L, pre["attention_mask"].to(device))
|
| 260 |
+
results.extend(self._verdicts(chunk, logits[0]))
|
| 261 |
+
return results
|
| 262 |
+
|
| 263 |
+
@torch.no_grad()
|
| 264 |
+
def verify_batch(self, tokenizer, rows: Sequence[Dict[str, Any]], batch_size: int = 16,
|
| 265 |
+
max_length: Optional[int] = None) -> List[Dict[str, Any]]:
|
| 266 |
+
"""Score single-criterion rows {context, target, criterion}, batched with padding.
|
| 267 |
+
|
| 268 |
+
Use this for many different (context, target) pairs; use `verify` for many
|
| 269 |
+
criteria on one pair.
|
| 270 |
+
"""
|
| 271 |
+
self.eval()
|
| 272 |
+
device = next(self.parameters()).device
|
| 273 |
+
col = self._collator(tokenizer, max_length)
|
| 274 |
+
results = []
|
| 275 |
+
for i in range(0, len(rows), batch_size):
|
| 276 |
+
chunk = [{"context": r.get("context"), "target": r.get("target"),
|
| 277 |
+
"criteria": [r["criterion"]]} for r in rows[i:i + batch_size]]
|
| 278 |
+
batch = col(chunk)
|
| 279 |
+
out = self(input_ids=batch["input_ids"].to(device),
|
| 280 |
+
attention_mask=batch["attention_mask"].to(device),
|
| 281 |
+
criterion_input_ids=batch["criterion_input_ids"].to(device),
|
| 282 |
+
criterion_attention_mask=batch["criterion_attention_mask"].to(device))
|
| 283 |
+
results.extend(self._verdicts([r["criteria"][0] for r in chunk], out.logits[:, 0]))
|
| 284 |
+
return results
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
VFMConfig.register_for_auto_class()
|
| 288 |
+
VFMForCriteriaVerification.register_for_auto_class("AutoModel")
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aeb13307a71acd8fe81861d94ad54ab689df773318809eed3cbe794b4492dae4
|
| 3 |
+
size 11422654
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_token": false,
|
| 3 |
+
"add_prefix_space": false,
|
| 4 |
+
"added_tokens_decoder": {
|
| 5 |
+
"151643": {
|
| 6 |
+
"content": "<|endoftext|>",
|
| 7 |
+
"lstrip": false,
|
| 8 |
+
"normalized": false,
|
| 9 |
+
"rstrip": false,
|
| 10 |
+
"single_word": false,
|
| 11 |
+
"special": true
|
| 12 |
+
},
|
| 13 |
+
"151644": {
|
| 14 |
+
"content": "<|im_start|>",
|
| 15 |
+
"lstrip": false,
|
| 16 |
+
"normalized": false,
|
| 17 |
+
"rstrip": false,
|
| 18 |
+
"single_word": false,
|
| 19 |
+
"special": true
|
| 20 |
+
},
|
| 21 |
+
"151645": {
|
| 22 |
+
"content": "<|im_end|>",
|
| 23 |
+
"lstrip": false,
|
| 24 |
+
"normalized": false,
|
| 25 |
+
"rstrip": false,
|
| 26 |
+
"single_word": false,
|
| 27 |
+
"special": true
|
| 28 |
+
},
|
| 29 |
+
"151646": {
|
| 30 |
+
"content": "<|object_ref_start|>",
|
| 31 |
+
"lstrip": false,
|
| 32 |
+
"normalized": false,
|
| 33 |
+
"rstrip": false,
|
| 34 |
+
"single_word": false,
|
| 35 |
+
"special": true
|
| 36 |
+
},
|
| 37 |
+
"151647": {
|
| 38 |
+
"content": "<|object_ref_end|>",
|
| 39 |
+
"lstrip": false,
|
| 40 |
+
"normalized": false,
|
| 41 |
+
"rstrip": false,
|
| 42 |
+
"single_word": false,
|
| 43 |
+
"special": true
|
| 44 |
+
},
|
| 45 |
+
"151648": {
|
| 46 |
+
"content": "<|box_start|>",
|
| 47 |
+
"lstrip": false,
|
| 48 |
+
"normalized": false,
|
| 49 |
+
"rstrip": false,
|
| 50 |
+
"single_word": false,
|
| 51 |
+
"special": true
|
| 52 |
+
},
|
| 53 |
+
"151649": {
|
| 54 |
+
"content": "<|box_end|>",
|
| 55 |
+
"lstrip": false,
|
| 56 |
+
"normalized": false,
|
| 57 |
+
"rstrip": false,
|
| 58 |
+
"single_word": false,
|
| 59 |
+
"special": true
|
| 60 |
+
},
|
| 61 |
+
"151650": {
|
| 62 |
+
"content": "<|quad_start|>",
|
| 63 |
+
"lstrip": false,
|
| 64 |
+
"normalized": false,
|
| 65 |
+
"rstrip": false,
|
| 66 |
+
"single_word": false,
|
| 67 |
+
"special": true
|
| 68 |
+
},
|
| 69 |
+
"151651": {
|
| 70 |
+
"content": "<|quad_end|>",
|
| 71 |
+
"lstrip": false,
|
| 72 |
+
"normalized": false,
|
| 73 |
+
"rstrip": false,
|
| 74 |
+
"single_word": false,
|
| 75 |
+
"special": true
|
| 76 |
+
},
|
| 77 |
+
"151652": {
|
| 78 |
+
"content": "<|vision_start|>",
|
| 79 |
+
"lstrip": false,
|
| 80 |
+
"normalized": false,
|
| 81 |
+
"rstrip": false,
|
| 82 |
+
"single_word": false,
|
| 83 |
+
"special": true
|
| 84 |
+
},
|
| 85 |
+
"151653": {
|
| 86 |
+
"content": "<|vision_end|>",
|
| 87 |
+
"lstrip": false,
|
| 88 |
+
"normalized": false,
|
| 89 |
+
"rstrip": false,
|
| 90 |
+
"single_word": false,
|
| 91 |
+
"special": true
|
| 92 |
+
},
|
| 93 |
+
"151654": {
|
| 94 |
+
"content": "<|vision_pad|>",
|
| 95 |
+
"lstrip": false,
|
| 96 |
+
"normalized": false,
|
| 97 |
+
"rstrip": false,
|
| 98 |
+
"single_word": false,
|
| 99 |
+
"special": true
|
| 100 |
+
},
|
| 101 |
+
"151655": {
|
| 102 |
+
"content": "<|image_pad|>",
|
| 103 |
+
"lstrip": false,
|
| 104 |
+
"normalized": false,
|
| 105 |
+
"rstrip": false,
|
| 106 |
+
"single_word": false,
|
| 107 |
+
"special": true
|
| 108 |
+
},
|
| 109 |
+
"151656": {
|
| 110 |
+
"content": "<|video_pad|>",
|
| 111 |
+
"lstrip": false,
|
| 112 |
+
"normalized": false,
|
| 113 |
+
"rstrip": false,
|
| 114 |
+
"single_word": false,
|
| 115 |
+
"special": true
|
| 116 |
+
},
|
| 117 |
+
"151657": {
|
| 118 |
+
"content": "<tool_call>",
|
| 119 |
+
"lstrip": false,
|
| 120 |
+
"normalized": false,
|
| 121 |
+
"rstrip": false,
|
| 122 |
+
"single_word": false,
|
| 123 |
+
"special": false
|
| 124 |
+
},
|
| 125 |
+
"151658": {
|
| 126 |
+
"content": "</tool_call>",
|
| 127 |
+
"lstrip": false,
|
| 128 |
+
"normalized": false,
|
| 129 |
+
"rstrip": false,
|
| 130 |
+
"single_word": false,
|
| 131 |
+
"special": false
|
| 132 |
+
},
|
| 133 |
+
"151659": {
|
| 134 |
+
"content": "<|fim_prefix|>",
|
| 135 |
+
"lstrip": false,
|
| 136 |
+
"normalized": false,
|
| 137 |
+
"rstrip": false,
|
| 138 |
+
"single_word": false,
|
| 139 |
+
"special": false
|
| 140 |
+
},
|
| 141 |
+
"151660": {
|
| 142 |
+
"content": "<|fim_middle|>",
|
| 143 |
+
"lstrip": false,
|
| 144 |
+
"normalized": false,
|
| 145 |
+
"rstrip": false,
|
| 146 |
+
"single_word": false,
|
| 147 |
+
"special": false
|
| 148 |
+
},
|
| 149 |
+
"151661": {
|
| 150 |
+
"content": "<|fim_suffix|>",
|
| 151 |
+
"lstrip": false,
|
| 152 |
+
"normalized": false,
|
| 153 |
+
"rstrip": false,
|
| 154 |
+
"single_word": false,
|
| 155 |
+
"special": false
|
| 156 |
+
},
|
| 157 |
+
"151662": {
|
| 158 |
+
"content": "<|fim_pad|>",
|
| 159 |
+
"lstrip": false,
|
| 160 |
+
"normalized": false,
|
| 161 |
+
"rstrip": false,
|
| 162 |
+
"single_word": false,
|
| 163 |
+
"special": false
|
| 164 |
+
},
|
| 165 |
+
"151663": {
|
| 166 |
+
"content": "<|repo_name|>",
|
| 167 |
+
"lstrip": false,
|
| 168 |
+
"normalized": false,
|
| 169 |
+
"rstrip": false,
|
| 170 |
+
"single_word": false,
|
| 171 |
+
"special": false
|
| 172 |
+
},
|
| 173 |
+
"151664": {
|
| 174 |
+
"content": "<|file_sep|>",
|
| 175 |
+
"lstrip": false,
|
| 176 |
+
"normalized": false,
|
| 177 |
+
"rstrip": false,
|
| 178 |
+
"single_word": false,
|
| 179 |
+
"special": false
|
| 180 |
+
},
|
| 181 |
+
"151665": {
|
| 182 |
+
"content": "<tool_response>",
|
| 183 |
+
"lstrip": false,
|
| 184 |
+
"normalized": false,
|
| 185 |
+
"rstrip": false,
|
| 186 |
+
"single_word": false,
|
| 187 |
+
"special": false
|
| 188 |
+
},
|
| 189 |
+
"151666": {
|
| 190 |
+
"content": "</tool_response>",
|
| 191 |
+
"lstrip": false,
|
| 192 |
+
"normalized": false,
|
| 193 |
+
"rstrip": false,
|
| 194 |
+
"single_word": false,
|
| 195 |
+
"special": false
|
| 196 |
+
},
|
| 197 |
+
"151667": {
|
| 198 |
+
"content": "<think>",
|
| 199 |
+
"lstrip": false,
|
| 200 |
+
"normalized": false,
|
| 201 |
+
"rstrip": false,
|
| 202 |
+
"single_word": false,
|
| 203 |
+
"special": false
|
| 204 |
+
},
|
| 205 |
+
"151668": {
|
| 206 |
+
"content": "</think>",
|
| 207 |
+
"lstrip": false,
|
| 208 |
+
"normalized": false,
|
| 209 |
+
"rstrip": false,
|
| 210 |
+
"single_word": false,
|
| 211 |
+
"special": false
|
| 212 |
+
}
|
| 213 |
+
},
|
| 214 |
+
"additional_special_tokens": [
|
| 215 |
+
"<|im_start|>",
|
| 216 |
+
"<|im_end|>",
|
| 217 |
+
"<|object_ref_start|>",
|
| 218 |
+
"<|object_ref_end|>",
|
| 219 |
+
"<|box_start|>",
|
| 220 |
+
"<|box_end|>",
|
| 221 |
+
"<|quad_start|>",
|
| 222 |
+
"<|quad_end|>",
|
| 223 |
+
"<|vision_start|>",
|
| 224 |
+
"<|vision_end|>",
|
| 225 |
+
"<|vision_pad|>",
|
| 226 |
+
"<|image_pad|>",
|
| 227 |
+
"<|video_pad|>"
|
| 228 |
+
],
|
| 229 |
+
"bos_token": null,
|
| 230 |
+
"chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0].role == 'system' %}\n {{- messages[0].content + '\\n\\n' }}\n {%- endif %}\n {{- \"# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0].content + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n{%- endfor %}\n{%- for message in messages %}\n {%- if message.content is string %}\n {%- set content = message.content %}\n {%- else %}\n {%- set content = '' %}\n {%- endif %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) %}\n {{- '<|im_start|>' + message.role + '\\n' + content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- if '</think>' in content %}\n {%- set reasoning_content = content.split('</think>')[0].rstrip('\\n').split('<think>')[-1].lstrip('\\n') %}\n {%- set content = content.split('</think>')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- if loop.index0 > ns.last_query_index %}\n {%- if loop.last or (not loop.last and reasoning_content) %}\n {{- '<|im_start|>' + message.role + '\\n<think>\\n' + reasoning_content.strip('\\n') + '\\n</think>\\n\\n' + content.lstrip('\\n') }}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls %}\n {%- for tool_call in message.tool_calls %}\n {%- if (loop.first and content) or (not loop.first) %}\n {{- '\\n' }}\n {%- endif %}\n {%- if tool_call.function %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {%- if tool_call.arguments is string %}\n {{- tool_call.arguments }}\n {%- else %}\n {{- tool_call.arguments | tojson }}\n {%- endif %}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.first or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if enable_thinking is defined and enable_thinking is false %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- endif %}\n{%- endif %}",
|
| 231 |
+
"clean_up_tokenization_spaces": false,
|
| 232 |
+
"eos_token": "<|im_end|>",
|
| 233 |
+
"errors": "replace",
|
| 234 |
+
"model_max_length": 131072,
|
| 235 |
+
"pad_token": "<|endoftext|>",
|
| 236 |
+
"split_special_tokens": false,
|
| 237 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
| 238 |
+
"unk_token": null
|
| 239 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|