Image-Text-to-Text
Transformers
Safetensors
English
vision
vlm
vision-language-model
image-text
instruction-tuning
dpo
lora
custom-architecture
conversational
Instructions to use mkd-dev/keural-VLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mkd-dev/keural-VLM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="mkd-dev/keural-VLM") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("mkd-dev/keural-VLM", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use mkd-dev/keural-VLM with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mkd-dev/keural-VLM" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mkd-dev/keural-VLM", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/mkd-dev/keural-VLM
- SGLang
How to use mkd-dev/keural-VLM with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "mkd-dev/keural-VLM" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mkd-dev/keural-VLM", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "mkd-dev/keural-VLM" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mkd-dev/keural-VLM", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use mkd-dev/keural-VLM with Docker Model Runner:
docker model run hf.co/mkd-dev/keural-VLM
Commit ·
d95f479
0
Parent(s):
Duplicate from mkd-ai-dev/keural-VLM
Browse filesCo-authored-by: Md Najmul Hossain <mkd-hossain@users.noreply.huggingface.co>
- .gitattributes +15 -0
- LICENSE +201 -0
- README.md +264 -0
- assets/cat_saliency.png +3 -0
- assets/dog_saliency.png +3 -0
- assets/dpo_training_curves.png +3 -0
- assets/fig_all_benchmarks.png +0 -0
- assets/fig_inference.png +3 -0
- assets/fig_mme.png +3 -0
- assets/fig_pope.png +0 -0
- assets/fig_scienceqa.png +0 -0
- assets/fig_textvqa.png +0 -0
- assets/fig_vqav2.png +0 -0
- assets/horse_saliency.png +3 -0
- assets/keural_vision_encoder.gif +3 -0
- assets/keural_vlm_ieee.png +3 -0
- assets/qualitative_examples.png +3 -0
- assets/token_budget_curve.png +3 -0
- assets/training_loss_curves.png +3 -0
- chat_template.jinja +87 -0
- dpo_adapter/adapter_config.json +45 -0
- dpo_adapter/adapter_model.safetensors +3 -0
- sft_adapter/adapter_config.json +45 -0
- sft_adapter/adapter_model.safetensors +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +17 -0
- vision_encoder/config.json +133 -0
- vision_encoder/model.safetensors +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
sft_adapter/adapter_model.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
dpo_adapter/adapter_model.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
vision_encoder/model.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
assets/keural_vlm_ieee.png filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
assets/training_loss_curves.png filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
assets/token_budget_curve.png filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
assets/dpo_training_curves.png filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
assets/fig_mme.png filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
assets/fig_inference.png filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
assets/qualitative_examples.png filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
assets/cat_saliency.png filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
assets/dog_saliency.png filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
assets/horse_saliency.png filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
assets/keural_vision_encoder.gif filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
|
LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright 2026 MKD CO., LTD.
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
README.md
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: other
|
| 4 |
+
library_name: transformers
|
| 5 |
+
tags:
|
| 6 |
+
- vision
|
| 7 |
+
- vlm
|
| 8 |
+
- vision-language-model
|
| 9 |
+
- image-text
|
| 10 |
+
- instruction-tuning
|
| 11 |
+
- dpo
|
| 12 |
+
- lora
|
| 13 |
+
- custom-architecture
|
| 14 |
+
pipeline_tag: image-text-to-text
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
<div align="center">
|
| 18 |
+
|
| 19 |
+
# Keural VLM — Vision-Language Model <sub>(PoC · V0.1)</sub>
|
| 20 |
+
|
| 21 |
+
**##Keural VLM is a proof-of-concept vision-language model developed to explore lightweight multimodal learning using a custom vision encoder. Unlike many existing VLMs, the model does not rely on a pretrained CLIP backbone. Instead, the visual encoder is trained from scratch and connected to Mistral-7B-Instruct through a lightweight projection module.
|
| 22 |
+
.**
|
| 23 |
+
|
| 24 |
+
<p>
|
| 25 |
+
<img src="https://img.shields.io/badge/MKD_Co.,_Ltd.-Keural-6d28d9?style=for-the-badge" alt="MKD">
|
| 26 |
+
<img src="https://img.shields.io/badge/status-V0.1_PoC-16a34a?style=for-the-badge" alt="Status">
|
| 27 |
+
</p>
|
| 28 |
+
|
| 29 |
+
<p>
|
| 30 |
+
<img src="https://img.shields.io/badge/vision_encoder-24.7M-8b5cf6" alt="Params">
|
| 31 |
+
<img src="https://img.shields.io/badge/LLM-Mistral--7B--Instruct-f59e0b" alt="LLM">
|
| 32 |
+
<img src="https://img.shields.io/badge/PyTorch-2.x-ee4c2c?logo=pytorch&logoColor=white" alt="PyTorch">
|
| 33 |
+
<img src="https://img.shields.io/badge/_Transformers-integrated-fcd34d" alt="Transformers">
|
| 34 |
+
<img src="https://img.shields.io/badge/PEFT-LoRA_+_DPO-38bdf8" alt="PEFT">
|
| 35 |
+
<img src="https://img.shields.io/badge/trained_on-1×_RTX_5090-22d3ee" alt="Hardware">
|
| 36 |
+
</p>
|
| 37 |
+
|
| 38 |
+
<br>
|
| 39 |
+
|
| 40 |
+
<img src="assets/keural_vision_encoder.gif" alt="Keural VLM architecture animation" width="98%">
|
| 41 |
+
|
| 42 |
+
<br>
|
| 43 |
+
|
| 44 |
+
*Image → CNN Stem → Adaptive Token Budget → Spatial Transformer → LevelAware Projector → Mistral-7B → Answer*
|
| 45 |
+
|
| 46 |
+
</div>
|
| 47 |
+
|
| 48 |
+
---
|
| 49 |
+
|
| 50 |
+
## Highlights
|
| 51 |
+
|
| 52 |
+
| | |
|
| 53 |
+
|---|---|
|
| 54 |
+
| **From scratch** | 24.7M vision encoder — **12.4× smaller** than LLaVA's CLIP encoder (307M) |
|
| 55 |
+
| **Adaptive Token Budget (ATB)** | Token count is a runtime knob — dense regions get more tokens, blank regions fewer |
|
| 56 |
+
| **Hierarchical Concept Tokenization (HCT)** | Every token carries a semantic level: global / region / detail |
|
| 57 |
+
| **3-phase pipeline** | Vision pretraining → projector alignment → SFT + DPO |
|
| 58 |
+
| **DPO improved every benchmark** | e.g. VQAv2 **+30.7pp**, ScienceQA **+14.0pp** |
|
| 59 |
+
|
| 60 |
+
---
|
| 61 |
+
|
| 62 |
+
## What This Is
|
| 63 |
+
|
| 64 |
+
A complete Vision-Language Model (VLM) proof-of-concept built entirely from scratch — no CLIP, no pretrained vision backbone.
|
| 65 |
+
|
| 66 |
+
| Component | Details |
|
| 67 |
+
|---|---|
|
| 68 |
+
| **Vision Encoder** | 24.7M params, trained from scratch on CC3M + CC12M (~15M pairs) |
|
| 69 |
+
| **Projector** | `LevelAwareProjector` (384 → 2048 → 4096) |
|
| 70 |
+
| **LLM** | `Mistral-7B-Instruct-v0.3` (4-bit NF4 QLoRA) |
|
| 71 |
+
| **SFT** | LLaVA-Instruct-150K, 30,000 steps |
|
| 72 |
+
| **DPO** | RLHF-V dataset, 5,733 pairs, 3,000 steps |
|
| 73 |
+
|
| 74 |
+
---
|
| 75 |
+
|
| 76 |
+
## Architecture
|
| 77 |
+
|
| 78 |
+
```
|
| 79 |
+
Image (256×256)
|
| 80 |
+
↓
|
| 81 |
+
CNN Stem → ATB Tokenizer → Spatial Transformer (12 layers, embed_dim=384)
|
| 82 |
+
↓
|
| 83 |
+
KeuralEncoderOutput {tokens, level_ids, spatial_metadata, saliency_scores, pooled}
|
| 84 |
+
↓
|
| 85 |
+
LevelAwareProjector (384 → 2048 → 4096)
|
| 86 |
+
↓
|
| 87 |
+
Visual Tokens (N_vis × 4096)
|
| 88 |
+
↓
|
| 89 |
+
Mistral-7B-Instruct-v0.3 + SFT LoRA + DPO LoRA
|
| 90 |
+
↓
|
| 91 |
+
Text Response
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
<div align="center">
|
| 95 |
+
<img src="assets/keural_vlm_ieee.png" alt="Keural VLM detailed architecture" width="92%">
|
| 96 |
+
</div>
|
| 97 |
+
|
| 98 |
+
### Key Innovations
|
| 99 |
+
|
| 100 |
+
**Adaptive Token Budget (ATB) Tokenization** — token count is a runtime parameter; dense regions get more tokens, blank regions fewer.
|
| 101 |
+
|
| 102 |
+
```python
|
| 103 |
+
out = encoder(image, token_budget=64) # fast / cheap
|
| 104 |
+
out = encoder(image, token_budget=256) # default
|
| 105 |
+
out = encoder(image, token_budget=1024) # full fidelity
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
**Hierarchical Concept Tokenization (HCT)** — every token carries a semantic level tag.
|
| 109 |
+
|
| 110 |
+
```python
|
| 111 |
+
out = encoder(image)
|
| 112 |
+
print(out.level_ids) # {0=global, 1=region, 2=detail}
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
---
|
| 116 |
+
|
| 117 |
+
## Training Pipeline
|
| 118 |
+
|
| 119 |
+
<table>
|
| 120 |
+
<tr><th>Phase</th><th>What trains</th><th>Data</th><th>Steps</th><th>Result</th></tr>
|
| 121 |
+
<tr><td><b>1 · Vision Encoder</b> </td><td>Encoder from scratch</td><td>CC3M + CC12M (~15.3M)</td><td>~75,000</td><td>24.7M params · 1× RTX 5090</td></tr>
|
| 122 |
+
<tr><td><b>2A · Projector Align</b> </td><td>Projector + LLM LoRA (r=64), encoder frozen</td><td>LLaVA-Instruct-150K</td><td>10,000</td><td>—</td></tr>
|
| 123 |
+
<tr><td><b>2B · SFT</b> </td><td>LLM LoRA (r=64, α=128)</td><td>LLaVA-Instruct-150K</td><td>30,000</td><td>final loss <b>1.022</b></td></tr>
|
| 124 |
+
<tr><td><b>2B · DPO</b> </td><td>DPO LoRA (r=16, α=32)</td><td>RLHF-V (5,733 pairs)</td><td>3,000</td><td>loss <b>0.235</b> · reward acc <b>95%</b> · margin <b>2.11</b></td></tr>
|
| 125 |
+
</table>
|
| 126 |
+
|
| 127 |
+
---
|
| 128 |
+
|
| 129 |
+
## Benchmark Results
|
| 130 |
+
|
| 131 |
+
Evaluated on 1,000 samples each (where applicable). The vision encoder is **12.4× smaller** than LLaVA's CLIP encoder (307M).
|
| 132 |
+
|
| 133 |
+
| Benchmark | Keural SFT-30K | Keural SFT+DPO | LLaVA 1.5 <sub>(307M enc)</sub> | LLaVA 1.6 <sub>(307M enc)</sub> |
|
| 134 |
+
|---|:---:|:---:|:---:|:---:|
|
| 135 |
+
| VQAv2 Accuracy | 12.9% | **43.6%** | 78.5% | 81.8% |
|
| 136 |
+
| POPE F1 | 66.9% | **67.0%** | 85.9% | 86.5% |
|
| 137 |
+
| MME Total Score | 704.3 | **838.8** | 1510.7 | 1519.3 |
|
| 138 |
+
| TextVQA Accuracy | 0.8% | **6.6%** | 58.2% | 64.9% |
|
| 139 |
+
| ScienceQA Accuracy | 39.7% | **53.7%** | 66.8% | 70.6% |
|
| 140 |
+
|
| 141 |
+
> **POPE F1 (67.0%)** is the standout — within 19pp of LLaVA 1.6 using a **12× smaller** encoder.
|
| 142 |
+
> **DPO improved every benchmark**, most dramatically VQAv2 (+30.7pp) and ScienceQA (+14.0pp).
|
| 143 |
+
> **TextVQA** is low by design — no OCR training. EasyOCR integration in the GUI bridges this gap.
|
| 144 |
+
|
| 145 |
+
<div align="center">
|
| 146 |
+
<img src="assets/fig_all_benchmarks.png" alt="All benchmarks" width="90%">
|
| 147 |
+
</div>
|
| 148 |
+
|
| 149 |
+
| | |
|
| 150 |
+
|:---:|:---:|
|
| 151 |
+
| <img src="assets/fig_vqav2.png" width="100%"> | <img src="assets/fig_pope.png" width="100%"> |
|
| 152 |
+
| <img src="assets/fig_mme.png" width="100%"> | <img src="assets/fig_scienceqa.png" width="100%"> |
|
| 153 |
+
|
| 154 |
+
---
|
| 155 |
+
|
| 156 |
+
## Qualitative & Saliency
|
| 157 |
+
|
| 158 |
+
The ATB tokenizer concentrates tokens on salient regions. Left → right: original · saliency heatmap · token placement.
|
| 159 |
+
|
| 160 |
+
<div align="center">
|
| 161 |
+
<img src="assets/cat_saliency.png" alt="Saliency — cat" width="80%">
|
| 162 |
+
<img src="assets/qualitative_examples.png" alt="Qualitative examples" width="90%">
|
| 163 |
+
</div>
|
| 164 |
+
|
| 165 |
+
---
|
| 166 |
+
|
| 167 |
+
## DPO Training Curves
|
| 168 |
+
|
| 169 |
+
| Metric | Step 0 | Step 3000 |
|
| 170 |
+
|---|:---:|:---:|
|
| 171 |
+
| Loss | 0.694 | **0.235** |
|
| 172 |
+
| Reward Accuracy | ~50% | **95%** |
|
| 173 |
+
| Reward Margin | 0.0 | **2.11** |
|
| 174 |
+
|
| 175 |
+
<div align="center">
|
| 176 |
+
<img src="assets/dpo_training_curves.png" alt="DPO training curves" width="80%">
|
| 177 |
+
</div>
|
| 178 |
+
|
| 179 |
+
---
|
| 180 |
+
|
| 181 |
+
## Repository Structure
|
| 182 |
+
|
| 183 |
+
```
|
| 184 |
+
keural-vlm-poc/
|
| 185 |
+
├── vision_encoder/ # Keural encoder weights (config + safetensors)
|
| 186 |
+
├── sft_adapter/ # SFT LoRA (30K steps)
|
| 187 |
+
├── dpo_adapter/ # DPO LoRA (3K steps, RLHF-V) — stacks on SFT
|
| 188 |
+
├── assets/ # figures, diagrams, animation
|
| 189 |
+
└── tokenizer.json … # Mistral tokenizer + chat template
|
| 190 |
+
```
|
| 191 |
+
|
| 192 |
+
For inference, load: **Vision Encoder → Projector → Mistral-7B + SFT LoRA + DPO LoRA**.
|
| 193 |
+
|
| 194 |
+
---
|
| 195 |
+
|
| 196 |
+
## Usage
|
| 197 |
+
|
| 198 |
+
```python
|
| 199 |
+
import torch
|
| 200 |
+
from transformers import AutoModel, AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 201 |
+
from peft import PeftModel
|
| 202 |
+
from alignment.projectors import LevelAwareProjector
|
| 203 |
+
|
| 204 |
+
device = "cuda"
|
| 205 |
+
|
| 206 |
+
# 1. Vision encoder (frozen)
|
| 207 |
+
encoder = AutoModel.from_pretrained(
|
| 208 |
+
"mkd-hika/keural-vision-encoder-poc",
|
| 209 |
+
trust_remote_code=True, torch_dtype=torch.bfloat16,
|
| 210 |
+
).to(device).eval()
|
| 211 |
+
|
| 212 |
+
# 2. Projector
|
| 213 |
+
projector = LevelAwareProjector(encoder_dim=384, hidden_dim=2048, llm_dim=4096)
|
| 214 |
+
projector.load_state_dict(torch.load("projector.pt", map_location=device))
|
| 215 |
+
projector = projector.to(device, dtype=torch.bfloat16).eval()
|
| 216 |
+
|
| 217 |
+
# 3. LLM + SFT LoRA + DPO LoRA
|
| 218 |
+
bnb_cfg = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.bfloat16,
|
| 219 |
+
bnb_4bit_use_double_quant=True, bnb_4bit_quant_type="nf4")
|
| 220 |
+
base_llm = AutoModelForCausalLM.from_pretrained(
|
| 221 |
+
"mistralai/Mistral-7B-Instruct-v0.3",
|
| 222 |
+
quantization_config=bnb_cfg, device_map="auto", torch_dtype=torch.bfloat16,
|
| 223 |
+
)
|
| 224 |
+
llm = PeftModel.from_pretrained(base_llm, "sft_adapter") # SFT LoRA
|
| 225 |
+
llm = PeftModel.from_pretrained(llm, "dpo_adapter") # DPO LoRA
|
| 226 |
+
llm.eval()
|
| 227 |
+
```
|
| 228 |
+
|
| 229 |
+
---
|
| 230 |
+
|
| 231 |
+
## Roadmap
|
| 232 |
+
|
| 233 |
+
| Phase | Encoder Params | Hardware | Status |
|
| 234 |
+
|---|:---:|:---:|:---:|
|
| 235 |
+
| **PoC** (this model) | 24.7M | 1× RTX 5090 | Complete (SFT + DPO) |
|
| 236 |
+
| Mid-level | ~183.5 | 8× H100 80 GB | Planned |
|
| 237 |
+
| Commercial | ~1.1B | 64× H100 80 GB | Future |
|
| 238 |
+
|
| 239 |
+
---
|
| 240 |
+
|
| 241 |
+
## Citation
|
| 242 |
+
|
| 243 |
+
```bibtex
|
| 244 |
+
@misc{keural_vlm_2026,
|
| 245 |
+
title = {Keural VLM: Vision-Language Model with Content-Adaptive Encoding via Saliency-Guided Token Budgets},
|
| 246 |
+
author = {Hika Barki and MKD Co., Ltd.},
|
| 247 |
+
year = {2026},
|
| 248 |
+
},
|
| 249 |
+
}
|
| 250 |
+
```
|
| 251 |
+
|
| 252 |
+
---
|
| 253 |
+
|
| 254 |
+
## 📄 License
|
| 255 |
+
|
| 256 |
+
See [LICENSE](LICENSE) for details.
|
| 257 |
+
|
| 258 |
+
*Training data: CC3M, CC12M, LLaVA-Instruct-150K, RLHF-V — respective data licenses apply.*
|
| 259 |
+
|
| 260 |
+
<div align="center">
|
| 261 |
+
|
| 262 |
+
**MKD Co., Ltd. — 2026**
|
| 263 |
+
|
| 264 |
+
</div>
|
assets/cat_saliency.png
ADDED
|
Git LFS Details
|
assets/dog_saliency.png
ADDED
|
Git LFS Details
|
assets/dpo_training_curves.png
ADDED
|
Git LFS Details
|
assets/fig_all_benchmarks.png
ADDED
|
assets/fig_inference.png
ADDED
|
Git LFS Details
|
assets/fig_mme.png
ADDED
|
Git LFS Details
|
assets/fig_pope.png
ADDED
|
assets/fig_scienceqa.png
ADDED
|
assets/fig_textvqa.png
ADDED
|
assets/fig_vqav2.png
ADDED
|
assets/horse_saliency.png
ADDED
|
Git LFS Details
|
assets/keural_vision_encoder.gif
ADDED
|
Git LFS Details
|
assets/keural_vlm_ieee.png
ADDED
|
Git LFS Details
|
assets/qualitative_examples.png
ADDED
|
Git LFS Details
|
assets/token_budget_curve.png
ADDED
|
Git LFS Details
|
assets/training_loss_curves.png
ADDED
|
Git LFS Details
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if messages[0]["role"] == "system" %}
|
| 2 |
+
{%- set system_message = messages[0]["content"] %}
|
| 3 |
+
{%- set loop_messages = messages[1:] %}
|
| 4 |
+
{%- else %}
|
| 5 |
+
{%- set loop_messages = messages %}
|
| 6 |
+
{%- endif %}
|
| 7 |
+
{%- if not tools is defined %}
|
| 8 |
+
{%- set tools = none %}
|
| 9 |
+
{%- endif %}
|
| 10 |
+
{%- set user_messages = loop_messages | selectattr("role", "equalto", "user") | list %}
|
| 11 |
+
|
| 12 |
+
{#- This block checks for alternating user/assistant messages, skipping tool calling messages #}
|
| 13 |
+
{%- set ns = namespace() %}
|
| 14 |
+
{%- set ns.index = 0 %}
|
| 15 |
+
{%- for message in loop_messages %}
|
| 16 |
+
{%- if not (message.role == "tool" or message.role == "tool_results" or (message.tool_calls is defined and message.tool_calls is not none)) %}
|
| 17 |
+
{%- if (message["role"] == "user") != (ns.index % 2 == 0) %}
|
| 18 |
+
{{- raise_exception("After the optional system message, conversation roles must alternate user/assistant/user/assistant/...") }}
|
| 19 |
+
{%- endif %}
|
| 20 |
+
{%- set ns.index = ns.index + 1 %}
|
| 21 |
+
{%- endif %}
|
| 22 |
+
{%- endfor %}
|
| 23 |
+
|
| 24 |
+
{{- bos_token }}
|
| 25 |
+
{%- for message in loop_messages %}
|
| 26 |
+
{%- if message["role"] == "user" %}
|
| 27 |
+
{%- if tools is not none and (message == user_messages[-1]) %}
|
| 28 |
+
{{- "[AVAILABLE_TOOLS] [" }}
|
| 29 |
+
{%- for tool in tools %}
|
| 30 |
+
{%- set tool = tool.function %}
|
| 31 |
+
{{- '{"type": "function", "function": {' }}
|
| 32 |
+
{%- for key, val in tool.items() if key != "return" %}
|
| 33 |
+
{%- if val is string %}
|
| 34 |
+
{{- '"' + key + '": "' + val + '"' }}
|
| 35 |
+
{%- else %}
|
| 36 |
+
{{- '"' + key + '": ' + val|tojson }}
|
| 37 |
+
{%- endif %}
|
| 38 |
+
{%- if not loop.last %}
|
| 39 |
+
{{- ", " }}
|
| 40 |
+
{%- endif %}
|
| 41 |
+
{%- endfor %}
|
| 42 |
+
{{- "}}" }}
|
| 43 |
+
{%- if not loop.last %}
|
| 44 |
+
{{- ", " }}
|
| 45 |
+
{%- else %}
|
| 46 |
+
{{- "]" }}
|
| 47 |
+
{%- endif %}
|
| 48 |
+
{%- endfor %}
|
| 49 |
+
{{- "[/AVAILABLE_TOOLS]" }}
|
| 50 |
+
{%- endif %}
|
| 51 |
+
{%- if loop.last and system_message is defined %}
|
| 52 |
+
{{- "[INST] " + system_message + "\n\n" + message["content"] + "[/INST]" }}
|
| 53 |
+
{%- else %}
|
| 54 |
+
{{- "[INST] " + message["content"] + "[/INST]" }}
|
| 55 |
+
{%- endif %}
|
| 56 |
+
{%- elif message.tool_calls is defined and message.tool_calls is not none %}
|
| 57 |
+
{{- "[TOOL_CALLS] [" }}
|
| 58 |
+
{%- for tool_call in message.tool_calls %}
|
| 59 |
+
{%- set out = tool_call.function|tojson %}
|
| 60 |
+
{{- out[:-1] }}
|
| 61 |
+
{%- if not tool_call.id is defined or tool_call.id|length != 9 %}
|
| 62 |
+
{{- raise_exception("Tool call IDs should be alphanumeric strings with length 9!") }}
|
| 63 |
+
{%- endif %}
|
| 64 |
+
{{- ', "id": "' + tool_call.id + '"}' }}
|
| 65 |
+
{%- if not loop.last %}
|
| 66 |
+
{{- ", " }}
|
| 67 |
+
{%- else %}
|
| 68 |
+
{{- "]" + eos_token }}
|
| 69 |
+
{%- endif %}
|
| 70 |
+
{%- endfor %}
|
| 71 |
+
{%- elif message["role"] == "assistant" %}
|
| 72 |
+
{{- " " + message["content"]|trim + eos_token}}
|
| 73 |
+
{%- elif message["role"] == "tool_results" or message["role"] == "tool" %}
|
| 74 |
+
{%- if message.content is defined and message.content.content is defined %}
|
| 75 |
+
{%- set content = message.content.content %}
|
| 76 |
+
{%- else %}
|
| 77 |
+
{%- set content = message.content %}
|
| 78 |
+
{%- endif %}
|
| 79 |
+
{{- '[TOOL_RESULTS] {"content": ' + content|string + ", " }}
|
| 80 |
+
{%- if not message.tool_call_id is defined or message.tool_call_id|length != 9 %}
|
| 81 |
+
{{- raise_exception("Tool call IDs should be alphanumeric strings with length 9!") }}
|
| 82 |
+
{%- endif %}
|
| 83 |
+
{{- '"call_id": "' + message.tool_call_id + '"}[/TOOL_RESULTS]' }}
|
| 84 |
+
{%- else %}
|
| 85 |
+
{{- raise_exception("Only user and assistant roles are supported, with the exception of an initial optional system message!") }}
|
| 86 |
+
{%- endif %}
|
| 87 |
+
{%- endfor %}
|
dpo_adapter/adapter_config.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"alora_invocation_tokens": null,
|
| 3 |
+
"alpha_pattern": {},
|
| 4 |
+
"arrow_config": null,
|
| 5 |
+
"auto_mapping": null,
|
| 6 |
+
"base_model_name_or_path": null,
|
| 7 |
+
"bias": "none",
|
| 8 |
+
"corda_config": null,
|
| 9 |
+
"ensure_weight_tying": false,
|
| 10 |
+
"eva_config": null,
|
| 11 |
+
"exclude_modules": null,
|
| 12 |
+
"fan_in_fan_out": false,
|
| 13 |
+
"inference_mode": true,
|
| 14 |
+
"init_lora_weights": true,
|
| 15 |
+
"layer_replication": null,
|
| 16 |
+
"layers_pattern": null,
|
| 17 |
+
"layers_to_transform": null,
|
| 18 |
+
"loftq_config": {},
|
| 19 |
+
"lora_alpha": 32,
|
| 20 |
+
"lora_bias": false,
|
| 21 |
+
"lora_dropout": 0.05,
|
| 22 |
+
"lora_ga_config": null,
|
| 23 |
+
"megatron_config": null,
|
| 24 |
+
"megatron_core": "megatron.core",
|
| 25 |
+
"modules_to_save": null,
|
| 26 |
+
"peft_type": "LORA",
|
| 27 |
+
"peft_version": "0.19.1",
|
| 28 |
+
"qalora_group_size": 16,
|
| 29 |
+
"r": 16,
|
| 30 |
+
"rank_pattern": {},
|
| 31 |
+
"revision": null,
|
| 32 |
+
"target_modules": [
|
| 33 |
+
"q_proj",
|
| 34 |
+
"o_proj",
|
| 35 |
+
"k_proj",
|
| 36 |
+
"v_proj"
|
| 37 |
+
],
|
| 38 |
+
"target_parameters": null,
|
| 39 |
+
"task_type": "CAUSAL_LM",
|
| 40 |
+
"trainable_token_indices": null,
|
| 41 |
+
"use_bdlora": null,
|
| 42 |
+
"use_dora": false,
|
| 43 |
+
"use_qalora": false,
|
| 44 |
+
"use_rslora": false
|
| 45 |
+
}
|
dpo_adapter/adapter_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ffaee7022d97988c9b99953a6f5cddc2d268f259c339644356806e4066f4c369
|
| 3 |
+
size 27301896
|
sft_adapter/adapter_config.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"alora_invocation_tokens": null,
|
| 3 |
+
"alpha_pattern": {},
|
| 4 |
+
"arrow_config": null,
|
| 5 |
+
"auto_mapping": null,
|
| 6 |
+
"base_model_name_or_path": "mistralai/Mistral-7B-Instruct-v0.3",
|
| 7 |
+
"bias": "none",
|
| 8 |
+
"corda_config": null,
|
| 9 |
+
"ensure_weight_tying": false,
|
| 10 |
+
"eva_config": null,
|
| 11 |
+
"exclude_modules": null,
|
| 12 |
+
"fan_in_fan_out": false,
|
| 13 |
+
"inference_mode": true,
|
| 14 |
+
"init_lora_weights": true,
|
| 15 |
+
"layer_replication": null,
|
| 16 |
+
"layers_pattern": null,
|
| 17 |
+
"layers_to_transform": null,
|
| 18 |
+
"loftq_config": {},
|
| 19 |
+
"lora_alpha": 32,
|
| 20 |
+
"lora_bias": false,
|
| 21 |
+
"lora_dropout": 0.05,
|
| 22 |
+
"lora_ga_config": null,
|
| 23 |
+
"megatron_config": null,
|
| 24 |
+
"megatron_core": "megatron.core",
|
| 25 |
+
"modules_to_save": null,
|
| 26 |
+
"peft_type": "LORA",
|
| 27 |
+
"peft_version": "0.19.1",
|
| 28 |
+
"qalora_group_size": 16,
|
| 29 |
+
"r": 16,
|
| 30 |
+
"rank_pattern": {},
|
| 31 |
+
"revision": null,
|
| 32 |
+
"target_modules": [
|
| 33 |
+
"q_proj",
|
| 34 |
+
"k_proj",
|
| 35 |
+
"v_proj",
|
| 36 |
+
"o_proj"
|
| 37 |
+
],
|
| 38 |
+
"target_parameters": null,
|
| 39 |
+
"task_type": "CAUSAL_LM",
|
| 40 |
+
"trainable_token_indices": null,
|
| 41 |
+
"use_bdlora": null,
|
| 42 |
+
"use_dora": false,
|
| 43 |
+
"use_qalora": false,
|
| 44 |
+
"use_rslora": false
|
| 45 |
+
}
|
sft_adapter/adapter_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:21111f5d89eab1d673f5ed6b59259197a556dcc6fccb99d04c23fed7918d8999
|
| 3 |
+
size 54560368
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": true,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<s>",
|
| 5 |
+
"clean_up_tokenization_spaces": false,
|
| 6 |
+
"eos_token": "</s>",
|
| 7 |
+
"is_local": false,
|
| 8 |
+
"legacy": false,
|
| 9 |
+
"local_files_only": false,
|
| 10 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 11 |
+
"pad_token": "</s>",
|
| 12 |
+
"sp_model_kwargs": {},
|
| 13 |
+
"spaces_between_special_tokens": false,
|
| 14 |
+
"tokenizer_class": "TokenizersBackend",
|
| 15 |
+
"unk_token": "<unk>",
|
| 16 |
+
"use_default_system_prompt": false
|
| 17 |
+
}
|
vision_encoder/config.json
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"KeuralVisionModel"
|
| 4 |
+
],
|
| 5 |
+
"default_token_budget": 256,
|
| 6 |
+
"depth": 12,
|
| 7 |
+
"dtype": "float32",
|
| 8 |
+
"embed_dim": 384,
|
| 9 |
+
"keural_config": {
|
| 10 |
+
"data": {
|
| 11 |
+
"captions_path": "data/indexes/cc3m_wds_train.tsv",
|
| 12 |
+
"dataset_name": "cc3m+cc12m",
|
| 13 |
+
"extra_sources": [
|
| 14 |
+
{
|
| 15 |
+
"captions_path": "data/indexes/cc12m_wds_train.tsv",
|
| 16 |
+
"images_root": "data/cc12m"
|
| 17 |
+
}
|
| 18 |
+
],
|
| 19 |
+
"image_buckets": [
|
| 20 |
+
[
|
| 21 |
+
224,
|
| 22 |
+
224
|
| 23 |
+
],
|
| 24 |
+
[
|
| 25 |
+
256,
|
| 26 |
+
256
|
| 27 |
+
],
|
| 28 |
+
[
|
| 29 |
+
320,
|
| 30 |
+
320
|
| 31 |
+
]
|
| 32 |
+
],
|
| 33 |
+
"images_root": "data/cc3m",
|
| 34 |
+
"max_caption_length": 64,
|
| 35 |
+
"num_workers": 4,
|
| 36 |
+
"pixel_mean": [
|
| 37 |
+
0.485,
|
| 38 |
+
0.456,
|
| 39 |
+
0.406
|
| 40 |
+
],
|
| 41 |
+
"pixel_std": [
|
| 42 |
+
0.229,
|
| 43 |
+
0.224,
|
| 44 |
+
0.225
|
| 45 |
+
],
|
| 46 |
+
"text_encoder_name": "sentence-transformers/all-MiniLM-L6-v2"
|
| 47 |
+
},
|
| 48 |
+
"loss": {
|
| 49 |
+
"hct_alpha": 0.5,
|
| 50 |
+
"lambda_hct": 1.0,
|
| 51 |
+
"lambda_sal": 1.0,
|
| 52 |
+
"learnable_bias_init": -10.0,
|
| 53 |
+
"learnable_temperature_init": 2.3,
|
| 54 |
+
"primary": "sigmoid_siglip",
|
| 55 |
+
"saliency_beta": 0.01,
|
| 56 |
+
"saliency_lambda_smooth": 4.0
|
| 57 |
+
},
|
| 58 |
+
"name": "keural-tiny-poc",
|
| 59 |
+
"saliency": {
|
| 60 |
+
"hidden_channels": 96
|
| 61 |
+
},
|
| 62 |
+
"spatial": {
|
| 63 |
+
"depth": 12,
|
| 64 |
+
"embed_dim": 384,
|
| 65 |
+
"head_dim": 64,
|
| 66 |
+
"mlp_ratio": 4,
|
| 67 |
+
"norm_eps": 1e-06,
|
| 68 |
+
"num_heads": 6,
|
| 69 |
+
"rope_base": 10000.0,
|
| 70 |
+
"use_pool_token": true
|
| 71 |
+
},
|
| 72 |
+
"stem": {
|
| 73 |
+
"activation": "gelu",
|
| 74 |
+
"channels": [
|
| 75 |
+
64,
|
| 76 |
+
128,
|
| 77 |
+
256,
|
| 78 |
+
384
|
| 79 |
+
],
|
| 80 |
+
"kernel_size": 3
|
| 81 |
+
},
|
| 82 |
+
"tokenizer": {
|
| 83 |
+
"budget_floors": {
|
| 84 |
+
"detail": 0,
|
| 85 |
+
"global": 4,
|
| 86 |
+
"region": 8
|
| 87 |
+
},
|
| 88 |
+
"budget_split": {
|
| 89 |
+
"detail": 0.7,
|
| 90 |
+
"global": 0.05,
|
| 91 |
+
"region": 0.25
|
| 92 |
+
},
|
| 93 |
+
"default_token_budget": 256,
|
| 94 |
+
"gumbel_temperature_end": 0.1,
|
| 95 |
+
"gumbel_temperature_start": 1.0,
|
| 96 |
+
"max_token_budget": 1024,
|
| 97 |
+
"nms_radius": {
|
| 98 |
+
"detail": 1,
|
| 99 |
+
"region": 2
|
| 100 |
+
},
|
| 101 |
+
"roi_align_size": 2,
|
| 102 |
+
"saliency_smooth_kernel": {
|
| 103 |
+
"detail": 3,
|
| 104 |
+
"region": 5
|
| 105 |
+
},
|
| 106 |
+
"temperature_anneal_steps": 10000,
|
| 107 |
+
"warmup_steps_fixed_grid": 5000
|
| 108 |
+
},
|
| 109 |
+
"training": {
|
| 110 |
+
"batch_size_per_device": 256,
|
| 111 |
+
"betas": [
|
| 112 |
+
0.9,
|
| 113 |
+
0.95
|
| 114 |
+
],
|
| 115 |
+
"gradient_accumulation": 4,
|
| 116 |
+
"gradient_checkpointing": false,
|
| 117 |
+
"log_every": 50,
|
| 118 |
+
"lr": 0.001,
|
| 119 |
+
"lr_schedule": "cosine_with_warmup",
|
| 120 |
+
"max_steps": 75000,
|
| 121 |
+
"optimizer": "adamw",
|
| 122 |
+
"precision": "bfloat16",
|
| 123 |
+
"save_every": 1000,
|
| 124 |
+
"seed": 42,
|
| 125 |
+
"warmup_steps": 2000,
|
| 126 |
+
"weight_decay": 0.05
|
| 127 |
+
}
|
| 128 |
+
},
|
| 129 |
+
"max_token_budget": 1024,
|
| 130 |
+
"model_type": "keural_vision",
|
| 131 |
+
"num_heads": 6,
|
| 132 |
+
"transformers_version": "4.57.2"
|
| 133 |
+
}
|
vision_encoder/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8fe763e68959e79120156879fbbf6cc6f77744517f91123786d149b36c3ad0b3
|
| 3 |
+
size 98683012
|