Release merged diffusion checkpoint and bilingual model card
Browse files- .gitattributes +1 -0
- LICENSE +202 -0
- NOTICE +14 -0
- README.md +44 -0
- block_diffusion.py +278 -0
- chat_template.jinja +137 -0
- config.json +169 -0
- generation_config.json +7 -0
- generation_limits.py +2 -0
- model-00001-of-00013.safetensors +3 -0
- model-00002-of-00013.safetensors +3 -0
- model-00003-of-00013.safetensors +3 -0
- model-00004-of-00013.safetensors +3 -0
- model-00005-of-00013.safetensors +3 -0
- model-00006-of-00013.safetensors +3 -0
- model-00007-of-00013.safetensors +3 -0
- model-00008-of-00013.safetensors +3 -0
- model-00009-of-00013.safetensors +3 -0
- model-00010-of-00013.safetensors +3 -0
- model-00011-of-00013.safetensors +3 -0
- model-00012-of-00013.safetensors +3 -0
- model-00013-of-00013.safetensors +3 -0
- model.safetensors.index.json +0 -0
- processor_config.json +25 -0
- requirements.txt +7 -0
- run_diffusion.py +69 -0
- tokenizer.json +3 -0
- tokenizer_config.json +85 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* 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
|
|
|
|
|
|
| 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 [yyyy] [name of copyright owner]
|
| 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.
|
NOTICE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Diffusion-Inkling-2-mini
|
| 2 |
+
|
| 3 |
+
Based on Inkling 2 Mini, made available by Thinking Machines Lab, Inc.
|
| 4 |
+
Upstream source: https://huggingface.co/thinkingmachines/Inkling-2-Mini
|
| 5 |
+
Upstream revision: fcd43a4241eb71e9f56f5f4d4bb125438cc613d9
|
| 6 |
+
Upstream license: Apache License, Version 2.0
|
| 7 |
+
|
| 8 |
+
Modified by the Diffusion-Inkling-2-mini project: trained and merged the
|
| 9 |
+
query-projection LoRA, added future-convolution weights and masked
|
| 10 |
+
block-diffusion decoding, and exported full native-format Safetensors.
|
| 11 |
+
Tokenizer and processor assets originate from the upstream model.
|
| 12 |
+
|
| 13 |
+
Research reference: DiCALM, https://arxiv.org/abs/2611.33919.
|
| 14 |
+
Nothing in this notice implies endorsement by Thinking Machines Lab.
|
README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: thinkingmachines/Inkling-2-Mini
|
| 4 |
+
base_model_relation: finetune
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
- ja
|
| 9 |
+
tags:
|
| 10 |
+
- block-diffusion
|
| 11 |
+
- masked-denoising
|
| 12 |
+
- safetensors
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# Diffusion-Inkling-2-mini
|
| 16 |
+
|
| 17 |
+
**▮▮▮ → text.** A merged block-diffusion checkpoint for English and Japanese.
|
| 18 |
+
**▮▮▮ → 文章。** 英語・日本語に対応したブロック拡散モデル。
|
| 19 |
+
|
| 20 |
+
## English
|
| 21 |
+
|
| 22 |
+
An independent research adaptation of Thinking Machines Lab’s **Inkling 2 Mini**. The query-projection LoRA is merged into the full checkpoint, alongside the learned forward-looking convolution weights. The included runner generates text by filling masks within each block.
|
| 23 |
+
|
| 24 |
+
**Format:** BF16 Safetensors (with some FP32 tensors), tokenizer included. Use a CUDA GPU with room for about 52 GB of weights plus runtime buffers. The runner defaults to 128-token blocks and accepts sizes from 1 to 512. Larger blocks and lower confidence thresholds can degrade output quality.
|
| 25 |
+
|
| 26 |
+
## 日本語
|
| 27 |
+
|
| 28 |
+
Thinking Machines Lab の **Inkling 2 Mini** をベースにした独立の研究モデルです。クエリ射影のLoRAを本体の重みに統合し、ブロック内の未来位置を参照する畳み込みを追加しました。同梱ランナーは、ブロック内のマスクを段階的に埋めて文章を生成します。
|
| 29 |
+
|
| 30 |
+
**形式:** BF16主体(一部FP32)のSafetensors。トークナイザー同梱。重み約52 GBと実行用バッファが収まるCUDA GPUが必要です。既定のブロック幅は128、指定範囲は1〜512です。ブロックを大きくしたり、しきい値を下げたりすると、回答品質が落ちる場合があります。
|
| 31 |
+
|
| 32 |
+
## Quick start / 実行
|
| 33 |
+
|
| 34 |
+
```bash
|
| 35 |
+
hf download summerAIO/Diffusion-Inkling-2-mini --local-dir diffusion-inkling
|
| 36 |
+
pip install -r diffusion-inkling/requirements.txt
|
| 37 |
+
python diffusion-inkling/run_diffusion.py "空はなぜ青く見えるの?"
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
## License / ライセンス
|
| 41 |
+
|
| 42 |
+
Apache 2.0: [LICENSE](./blob/main/LICENSE) · [NOTICE](./blob/main/NOTICE)
|
| 43 |
+
Base / ベース: [Thinking Machines Lab — Inkling 2 Mini](https://huggingface.co/thinkingmachines/Inkling-2-Mini) · [Model Acceptable Use Policy](https://thinkingmachines.ai/model-acceptable-use-policy/)
|
| 44 |
+
Method reference / 手法の参考: [DiCALM](https://arxiv.org/abs/2611.33919)
|
block_diffusion.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
from copy import copy
|
| 3 |
+
from contextvars import ContextVar
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
from torch import nn
|
| 7 |
+
from torch.nn import functional as F
|
| 8 |
+
|
| 9 |
+
from generation_limits import MAX_BLOCK_SIZE
|
| 10 |
+
|
| 11 |
+
BLOCK_SIZE = 128
|
| 12 |
+
ACTIVE = ContextVar('diffusion_block_start', default=None)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def masks(length, start, subblock, window, device, dtype):
|
| 16 |
+
return attention_masks(length, start, subblock, window, device, dtype)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def attention_masks(length, start, subblock, window, device, dtype, query_start=0, sliding_start=0):
|
| 20 |
+
q = torch.arange(query_start, length, device=device)[:, None]
|
| 21 |
+
k = torch.arange(length, device=device)[None, :]
|
| 22 |
+
allow = (k <= q) | ((q >= start) & ((q-start)//subblock == (k-start)//subblock))
|
| 23 |
+
def additive(visible):
|
| 24 |
+
return torch.zeros_like(visible, dtype=dtype)[None, None].masked_fill(~visible, float('-inf'))
|
| 25 |
+
return {'full_attention': additive(allow),
|
| 26 |
+
'sliding_attention': additive((allow & ((q-k).abs() < window))[:, sliding_start:]),
|
| 27 |
+
'linear_attention': None}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def future_residual(x, taps, start):
|
| 31 |
+
positions = torch.arange(x.shape[1], device=x.device)
|
| 32 |
+
result = torch.zeros_like(x, dtype=torch.float32)
|
| 33 |
+
for offset, tap in enumerate(taps, 1):
|
| 34 |
+
valid = (positions >= start) & (positions + offset < x.shape[1])
|
| 35 |
+
index = (positions + offset).clamp(max=x.shape[1]-1)
|
| 36 |
+
result = result + x[:, index].float() * tap * valid[None, :, None]
|
| 37 |
+
return result
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def install_future_convolutions(model):
|
| 45 |
+
from transformers.models.inkling2_loop.modeling_inkling2_loop import (
|
| 46 |
+
Inkling2LoopDynamicShortConvolution, Inkling2LoopShortConvolution,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
for module in list(model.modules()):
|
| 50 |
+
if isinstance(module, Inkling2LoopShortConvolution):
|
| 51 |
+
weight = module.conv1d.weight
|
| 52 |
+
width, device = weight.shape[0], weight.device
|
| 53 |
+
scale = math.sqrt(module.conv_kernel_size + 1)
|
| 54 |
+
elif isinstance(module, Inkling2LoopDynamicShortConvolution):
|
| 55 |
+
width, device = module.static_weight.shape[1], module.static_weight.device
|
| 56 |
+
scale = math.sqrt(2 * module.conv_kernel_size + 1)
|
| 57 |
+
else:
|
| 58 |
+
continue
|
| 59 |
+
module.register_parameter('future_taps', nn.Parameter(torch.zeros(2, width, device=device)))
|
| 60 |
+
|
| 61 |
+
def extend(mod, args, out, scale=scale):
|
| 62 |
+
start = ACTIVE.get()
|
| 63 |
+
if start is None:
|
| 64 |
+
return out
|
| 65 |
+
return out + (future_residual(args[0], mod.future_taps, start) / scale).to(out.dtype)
|
| 66 |
+
|
| 67 |
+
module.register_forward_hook(extend)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def logits(model, ids, positions, start=None, subblock=BLOCK_SIZE):
|
| 71 |
+
attention = None
|
| 72 |
+
if start is not None:
|
| 73 |
+
config = model.config.text_config
|
| 74 |
+
attention = masks(ids.shape[1], start, subblock, config.sliding_window_size,
|
| 75 |
+
ids.device, model.get_input_embeddings().weight.dtype)
|
| 76 |
+
context = ACTIVE.set(start)
|
| 77 |
+
try:
|
| 78 |
+
return model(input_ids=ids, attention_mask=attention, use_cache=False,
|
| 79 |
+
logits_to_keep=positions).logits[0]
|
| 80 |
+
finally:
|
| 81 |
+
ACTIVE.reset(context)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def guarded_candidates(scores, ids, positions, mask_id, stop_ids, suppressed):
|
| 85 |
+
scores[:, mask_id] = -torch.inf
|
| 86 |
+
if suppressed:
|
| 87 |
+
scores[:, suppressed] = -torch.inf
|
| 88 |
+
if stop_ids:
|
| 89 |
+
scores[1:, list(stop_ids)] = -torch.inf
|
| 90 |
+
# Prevent a third identical token after an already-established run.
|
| 91 |
+
previous = ids[0, (positions - 1).clamp_min(0)]
|
| 92 |
+
earlier = ids[0, (positions - 2).clamp_min(0)]
|
| 93 |
+
repeated = (positions >= 2) & (previous == earlier) & (previous != mask_id)
|
| 94 |
+
if stop_ids:
|
| 95 |
+
repeated &= ~torch.isin(previous, positions.new_tensor(list(stop_ids)))
|
| 96 |
+
scores[repeated.nonzero().flatten(), previous[repeated]] = -torch.inf
|
| 97 |
+
confidence, tokens = scores.softmax(-1).max(-1)
|
| 98 |
+
eligible = positions <= positions[0] + 11
|
| 99 |
+
# Adjacent identical guesses deep inside one masked run are often the same
|
| 100 |
+
# marginal repeated, not independent evidence for multiple occurrences.
|
| 101 |
+
eligible[1:] &= ((positions[1:] != positions[:-1] + 1) | (tokens[1:] != tokens[:-1]))
|
| 102 |
+
return confidence.masked_fill(~eligible, -torch.inf), tokens
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
@torch.no_grad()
|
| 108 |
+
def generate(model, ids, mask_id, stop_ids, max_new_tokens=128, threshold=0.9, stats=None, prefix_cache=False,
|
| 109 |
+
block_steps=0, confidence_order=False, guarded=False, suppressed=(), scorer=None,
|
| 110 |
+
block_size=BLOCK_SIZE):
|
| 111 |
+
tokens = []
|
| 112 |
+
for _, _, _, _, tokens, _ in denoise_steps(
|
| 113 |
+
model, ids, mask_id, stop_ids, max_new_tokens, threshold, stats, prefix_cache, block_steps, confidence_order,
|
| 114 |
+
guarded=guarded, suppressed=suppressed, scorer=scorer, block_size=block_size,
|
| 115 |
+
):
|
| 116 |
+
pass
|
| 117 |
+
return tokens
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def fork_prefix_cache(cache):
|
| 121 |
+
"""Fork dynamic Inkling cache metadata and writable short-convolution state.
|
| 122 |
+
|
| 123 |
+
Dynamic attention updates replace K/V tensor references (torch.cat), so
|
| 124 |
+
the immutable prefix K/V storage itself can be shared with every trial.
|
| 125 |
+
"""
|
| 126 |
+
fork = copy(cache)
|
| 127 |
+
fork.layers = []
|
| 128 |
+
for original in cache.layers:
|
| 129 |
+
layer = copy(original)
|
| 130 |
+
for name in ('conv_kernel_size', 'has_previous_state', 'is_conv_states_initialized'):
|
| 131 |
+
setattr(layer, name, copy(getattr(original, name)))
|
| 132 |
+
layer.conv_states = {i: state.clone() if state is not None else None
|
| 133 |
+
for i, state in original.conv_states.items()}
|
| 134 |
+
layer.cumulative_length_linear = original.cumulative_length_linear.clone()
|
| 135 |
+
fork.layers.append(layer)
|
| 136 |
+
return fork
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
class BlockPrefix:
|
| 140 |
+
def __init__(self, model):
|
| 141 |
+
self.model = model
|
| 142 |
+
self.cache = None
|
| 143 |
+
self.length = 0
|
| 144 |
+
self.last_logits = None
|
| 145 |
+
|
| 146 |
+
def attention(self, ids, diffusion_start):
|
| 147 |
+
window = self.model.config.text_config.sliding_window_size
|
| 148 |
+
active_width = max(1, ids.shape[1] - diffusion_start)
|
| 149 |
+
return attention_masks(ids.shape[1], diffusion_start, active_width, window, ids.device,
|
| 150 |
+
self.model.get_input_embeddings().weight.dtype, query_start=self.length,
|
| 151 |
+
sliding_start=max(0, self.length - window + 1))
|
| 152 |
+
|
| 153 |
+
@torch.no_grad()
|
| 154 |
+
def commit(self, ids):
|
| 155 |
+
if self.length == ids.shape[1]:
|
| 156 |
+
return False
|
| 157 |
+
out = self.model(input_ids=ids[:, self.length:], attention_mask=self.attention(ids, ids.shape[1]),
|
| 158 |
+
cache=self.cache, use_cache=True, logits_to_keep=1)
|
| 159 |
+
self.cache = out.cache
|
| 160 |
+
self.last_logits = out.logits[0]
|
| 161 |
+
self.length = ids.shape[1]
|
| 162 |
+
return True
|
| 163 |
+
|
| 164 |
+
@torch.no_grad()
|
| 165 |
+
def scores(self, ids, positions, attention):
|
| 166 |
+
# Token shift: the first query's prediction comes from the causal prefix.
|
| 167 |
+
first = positions[0].item() == self.length
|
| 168 |
+
local = positions[int(first):] - self.length - 1
|
| 169 |
+
if not local.numel():
|
| 170 |
+
return self.last_logits.clone()
|
| 171 |
+
context = ACTIVE.set(0)
|
| 172 |
+
try:
|
| 173 |
+
out = self.model(input_ids=ids[:, self.length:], attention_mask=attention,
|
| 174 |
+
cache=fork_prefix_cache(self.cache), use_cache=True, logits_to_keep=local).logits[0]
|
| 175 |
+
finally:
|
| 176 |
+
ACTIVE.reset(context)
|
| 177 |
+
return torch.cat((self.last_logits, out), dim=0) if first else out
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def denoise_steps(model, ids, mask_id, stop_ids, max_new_tokens=128, threshold=0.9, stats=None, prefix_cache=False,
|
| 181 |
+
block_steps=0, confidence_order=False, one_at_a_time=False, guarded=False, suppressed=(),
|
| 182 |
+
scorer=None, block_size=BLOCK_SIZE, observe_draft=None):
|
| 183 |
+
if not 1 <= block_size <= MAX_BLOCK_SIZE:
|
| 184 |
+
raise ValueError(f'block_size must be between 1 and {MAX_BLOCK_SIZE}')
|
| 185 |
+
generated = []
|
| 186 |
+
block = 0
|
| 187 |
+
prefix = BlockPrefix(model) if prefix_cache else None
|
| 188 |
+
if scorer is not None and prefix is not None and not hasattr(scorer, 'begin_block'):
|
| 189 |
+
raise ValueError('A custom scorer cannot be combined with prefix caching')
|
| 190 |
+
|
| 191 |
+
def evaluate(positions):
|
| 192 |
+
if scorer is not None:
|
| 193 |
+
return scorer(ids, positions, start)
|
| 194 |
+
if prefix is not None:
|
| 195 |
+
return prefix.scores(ids, positions, attention)
|
| 196 |
+
return logits(model, ids, positions-1, start, subblock=ids.shape[1]-start)
|
| 197 |
+
while len(generated) < max_new_tokens:
|
| 198 |
+
block += 1
|
| 199 |
+
start = ids.shape[1]
|
| 200 |
+
width = min(block_size, max_new_tokens-len(generated))
|
| 201 |
+
yield block, 0, width, 0, list(generated), [mask_id] * width
|
| 202 |
+
if prefix is not None:
|
| 203 |
+
commit = getattr(scorer, 'commit_prefix', None)
|
| 204 |
+
committed = prefix.commit(ids) if commit is None else commit(prefix, ids)
|
| 205 |
+
if committed and stats is not None:
|
| 206 |
+
stats['cache_commits'] = stats.get('cache_commits', 0) + 1
|
| 207 |
+
ids = torch.cat([ids, ids.new_full((1, width), mask_id)], dim=1)
|
| 208 |
+
attention = prefix.attention(ids, start) if prefix is not None else None
|
| 209 |
+
if prefix is not None and scorer is not None:
|
| 210 |
+
scorer.begin_block(prefix, ids, attention)
|
| 211 |
+
cursor = start
|
| 212 |
+
step = 0
|
| 213 |
+
block_start = len(generated)
|
| 214 |
+
if confidence_order:
|
| 215 |
+
while True:
|
| 216 |
+
positions = (ids[0, start:] == mask_id).nonzero().flatten() + start
|
| 217 |
+
if not positions.numel():
|
| 218 |
+
break
|
| 219 |
+
with torch.no_grad():
|
| 220 |
+
scores = evaluate(positions)
|
| 221 |
+
if guarded:
|
| 222 |
+
confidence, tokens = guarded_candidates(scores, ids, positions, mask_id, stop_ids, suppressed)
|
| 223 |
+
else:
|
| 224 |
+
scores[:, mask_id] = -torch.inf
|
| 225 |
+
confidence, tokens = scores.softmax(-1).max(-1)
|
| 226 |
+
step += 1
|
| 227 |
+
if stats is not None:
|
| 228 |
+
stats['forwards'] += 1
|
| 229 |
+
count = max(1, int((confidence >= threshold).sum().item()))
|
| 230 |
+
if block_steps:
|
| 231 |
+
count = max(count, math.ceil(len(positions) / max(1, block_steps-step+1)))
|
| 232 |
+
if one_at_a_time:
|
| 233 |
+
count = 1
|
| 234 |
+
elif guarded:
|
| 235 |
+
count = min(count, int(confidence.isfinite().sum().item()))
|
| 236 |
+
if one_at_a_time and confidence.max().item() < threshold:
|
| 237 |
+
chosen = positions.new_zeros(1)
|
| 238 |
+
else:
|
| 239 |
+
chosen = confidence.topk(count).indices
|
| 240 |
+
ids[0, positions[chosen]] = tokens[chosen]
|
| 241 |
+
if observe_draft is not None:
|
| 242 |
+
observe_draft(torch.stack((positions - start, tokens)).tolist())
|
| 243 |
+
cells = ids[0, start:].tolist()
|
| 244 |
+
visible = []
|
| 245 |
+
stopped = False
|
| 246 |
+
for token in cells:
|
| 247 |
+
if token == mask_id:
|
| 248 |
+
break
|
| 249 |
+
if token in stop_ids:
|
| 250 |
+
stopped = True
|
| 251 |
+
break
|
| 252 |
+
visible.append(token)
|
| 253 |
+
yield block, step, width, width-cells.count(mask_id), generated + visible, cells
|
| 254 |
+
if stopped:
|
| 255 |
+
return
|
| 256 |
+
generated.extend(cells)
|
| 257 |
+
continue
|
| 258 |
+
while cursor < start + width:
|
| 259 |
+
positions = torch.arange(cursor, start+width, device=ids.device)
|
| 260 |
+
with torch.no_grad():
|
| 261 |
+
scores = evaluate(positions)
|
| 262 |
+
step += 1
|
| 263 |
+
if stats is not None:
|
| 264 |
+
stats['forwards'] += 1
|
| 265 |
+
scores[:, mask_id] = -torch.inf
|
| 266 |
+
confidence, tokens = scores.softmax(-1).max(-1)
|
| 267 |
+
low = (confidence < threshold).nonzero()
|
| 268 |
+
count = max(1, int(low[0, 0])) if low.numel() else len(positions)
|
| 269 |
+
if block_steps:
|
| 270 |
+
count = max(count, math.ceil(len(positions) / max(1, block_steps-step+1)))
|
| 271 |
+
ids[0, cursor:cursor+count] = tokens[:count]
|
| 272 |
+
cursor += count
|
| 273 |
+
for token in tokens[:count].tolist():
|
| 274 |
+
if token in stop_ids:
|
| 275 |
+
yield block, step, width, len(generated)-block_start, list(generated), ids[0, start:].tolist()
|
| 276 |
+
return
|
| 277 |
+
generated.append(token)
|
| 278 |
+
yield block, step, width, len(generated)-block_start, list(generated), ids[0, start:].tolist()
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- set effort_map = {"none": 0.0, "minimal": 0.1, "low": 0.2, "medium": 0.7, "high": 0.9, "xhigh": 0.99, "max": 0.99} -%}
|
| 2 |
+
{%- set role_token = {"user": "<|message_user|>", "assistant": "<|message_model|>", "system": "<|message_system|>", "tool": "<|message_tool|>"} -%}
|
| 3 |
+
|
| 4 |
+
{%- macro emit_thinking_effort() -%}
|
| 5 |
+
{%- set eff = reasoning_effort if reasoning_effort is defined and reasoning_effort is not none else 0.9 -%}
|
| 6 |
+
{%- if eff is string -%}
|
| 7 |
+
{%- set key = eff | trim -%}
|
| 8 |
+
{%- if key not in effort_map -%}
|
| 9 |
+
{{- raise_exception("Unknown reasoning_effort: " ~ eff) -}}
|
| 10 |
+
{%- endif -%}
|
| 11 |
+
{%- set num = effort_map[key] -%}
|
| 12 |
+
{%- else -%}
|
| 13 |
+
{%- set num = eff | float -%}
|
| 14 |
+
{%- endif -%}
|
| 15 |
+
{%- if num < 0.0 or num > 0.99 -%}
|
| 16 |
+
{{- raise_exception("reasoning_effort must be in [0.0, 0.99]") -}}
|
| 17 |
+
{%- endif -%}
|
| 18 |
+
{{- "<|message_system|><|content_text|>Thinking effort level: " -}}
|
| 19 |
+
{%- if num == 0.0 -%}0{%- else -%}{{ num }}{%- endif -%}
|
| 20 |
+
{{- "<|end_message|>" -}}
|
| 21 |
+
{%- endmacro -%}
|
| 22 |
+
|
| 23 |
+
{%- if tools -%}
|
| 24 |
+
{%- set tool_state = namespace(specs=[]) -%}
|
| 25 |
+
{%- for tool in tools -%}
|
| 26 |
+
{%- set fn = tool.function if tool.function is defined else tool -%}
|
| 27 |
+
{%- set spec = {
|
| 28 |
+
"description": (fn.description if fn.description is defined and fn.description else ""),
|
| 29 |
+
"name": fn.name,
|
| 30 |
+
"parameters": (fn.parameters if fn.parameters is defined and fn.parameters else {}),
|
| 31 |
+
"type": (tool.type if tool.type is defined and tool.type else "function"),
|
| 32 |
+
} -%}
|
| 33 |
+
{%- set tool_state.specs = tool_state.specs + [spec] -%}
|
| 34 |
+
{%- endfor -%}
|
| 35 |
+
{{- "<|message_system|>tool_declare<|content_xml|>" -}}
|
| 36 |
+
{{- tool_state.specs | tojson(sort_keys=true, separators=(",", ":")) -}}
|
| 37 |
+
{{- "<|end_message|>" -}}
|
| 38 |
+
{%- endif -%}
|
| 39 |
+
|
| 40 |
+
{%- set state = namespace(effort_emitted=false) -%}
|
| 41 |
+
{%- for message in messages -%}
|
| 42 |
+
{%- if message.role not in role_token -%}
|
| 43 |
+
{{- raise_exception("Unknown message role: " ~ message.role) -}}
|
| 44 |
+
{%- endif -%}
|
| 45 |
+
{%- if not state.effort_emitted and message.role != "system" -%}
|
| 46 |
+
{{- emit_thinking_effort() -}}
|
| 47 |
+
{%- set state.effort_emitted = true -%}
|
| 48 |
+
{%- endif -%}
|
| 49 |
+
|
| 50 |
+
{%- set header = namespace(text=role_token[message.role]) -%}
|
| 51 |
+
{%- if message.role == "tool" -%}
|
| 52 |
+
{%- if message.name is defined and message.name -%}
|
| 53 |
+
{%- set header.text = header.text ~ message.name -%}
|
| 54 |
+
{%- elif message.tool_call_id is defined and message.tool_call_id -%}
|
| 55 |
+
{%- for prev in messages -%}
|
| 56 |
+
{%- if prev.role == "assistant" and prev.tool_calls -%}
|
| 57 |
+
{%- for tc in prev.tool_calls -%}
|
| 58 |
+
{%- if tc.id is defined and tc.id == message.tool_call_id and tc.function.name is defined -%}
|
| 59 |
+
{%- set header.text = header.text ~ tc.function.name -%}
|
| 60 |
+
{%- endif -%}
|
| 61 |
+
{%- endfor -%}
|
| 62 |
+
{%- endif -%}
|
| 63 |
+
{%- endfor -%}
|
| 64 |
+
{%- endif -%}
|
| 65 |
+
{%- elif message.role == "assistant" and message.name is defined and message.name -%}
|
| 66 |
+
{%- set header.text = header.text ~ message.name -%}
|
| 67 |
+
{%- endif -%}
|
| 68 |
+
{%- set rtok = header.text -%}
|
| 69 |
+
{%- set rendered -%}
|
| 70 |
+
|
| 71 |
+
{%- if message.role == "assistant" and message.reasoning_content is defined and message.reasoning_content -%}
|
| 72 |
+
{{- rtok ~ "<|content_thinking|>" ~ message.reasoning_content ~ "<|end_message|>" -}}
|
| 73 |
+
{%- endif -%}
|
| 74 |
+
|
| 75 |
+
{%- if message.content is string and (message.content or not (message.role == "assistant" and (message.tool_calls or message.reasoning_content))) -%}
|
| 76 |
+
{{- rtok ~ "<|content_text|>" ~ message.content ~ "<|end_message|>" -}}
|
| 77 |
+
{%- elif message.content -%}
|
| 78 |
+
{%- for part in message.content -%}
|
| 79 |
+
{%- if part is string -%}
|
| 80 |
+
{{- rtok ~ "<|content_text|>" ~ part ~ "<|end_message|>" -}}
|
| 81 |
+
{%- elif part.type is not defined or part.type in ("text", "input_text") -%}
|
| 82 |
+
{%- set text_part = (part.text if part.text is defined and part.text is string else "") -%}
|
| 83 |
+
{{- rtok ~ "<|content_text|>" ~ text_part ~ "<|end_message|>" -}}
|
| 84 |
+
{%- elif part.type in ("image", "input_image", "image_url") -%}
|
| 85 |
+
{%- if message.role not in ("user", "tool") -%}
|
| 86 |
+
{{- raise_exception("Image content is only supported for user and tool messages") -}}
|
| 87 |
+
{%- endif -%}
|
| 88 |
+
{{- rtok ~ "<|content_image|><|unused_200054|><|end_message|>" -}}
|
| 89 |
+
{%- elif part.type in ("audio", "input_audio", "audio_url") -%}
|
| 90 |
+
{{- raise_exception("Inkling 2 does not accept audio input") -}}
|
| 91 |
+
{%- else -%}
|
| 92 |
+
{{- raise_exception("Unsupported content part type: " ~ part.type) -}}
|
| 93 |
+
{%- endif -%}
|
| 94 |
+
{%- endfor -%}
|
| 95 |
+
{%- endif -%}
|
| 96 |
+
|
| 97 |
+
{%- if message.role == "assistant" and message.tool_calls -%}
|
| 98 |
+
{%- for tc in message.tool_calls -%}
|
| 99 |
+
{%- set fn = tc.function -%}
|
| 100 |
+
{%- if fn.name is not defined or fn.name is not string -%}
|
| 101 |
+
{{- raise_exception("tool call function name must be a string") -}}
|
| 102 |
+
{%- endif -%}
|
| 103 |
+
{%- if message.name is defined and message.name and message.name != fn.name -%}
|
| 104 |
+
{{- raise_exception("assistant name " ~ message.name ~ " does not match its tool call " ~ fn.name) -}}
|
| 105 |
+
{%- endif -%}
|
| 106 |
+
{%- set args = fn.arguments if fn.arguments is defined and fn.arguments else {} -%}
|
| 107 |
+
{%- if args is string -%}
|
| 108 |
+
{{- raise_exception("tool call arguments must be a parsed object, not a JSON string; canonicalize upstream") -}}
|
| 109 |
+
{%- endif -%}
|
| 110 |
+
{%- if args is not mapping -%}
|
| 111 |
+
{{- raise_exception("tool call arguments must be an object") -}}
|
| 112 |
+
{%- endif -%}
|
| 113 |
+
{{- "<|message_model|>" ~ fn.name ~ "<|content_invoke_tool_json|>" -}}
|
| 114 |
+
{{- '{"name":' ~ (fn.name | tojson(sort_keys=true, separators=(",", ":"))) ~ ',"args":' -}}
|
| 115 |
+
{{- "{" -}}
|
| 116 |
+
{%- for key, value in args | dictsort(case_sensitive=true) -%}
|
| 117 |
+
{{- (key | tojson) ~ ":" ~ (value | tojson(separators=(",", ":"))) -}}
|
| 118 |
+
{%- if not loop.last -%},{%- endif -%}
|
| 119 |
+
{%- endfor -%}
|
| 120 |
+
{{- "}}<|end_message|>" -}}
|
| 121 |
+
{%- endfor -%}
|
| 122 |
+
{%- endif -%}
|
| 123 |
+
|
| 124 |
+
{%- if message.role == "assistant" -%}
|
| 125 |
+
{{- "<|content_model_end_sampling|>" -}}
|
| 126 |
+
{%- endif -%}
|
| 127 |
+
{%- endset -%}
|
| 128 |
+
{%- if message.role == "assistant" -%}
|
| 129 |
+
{%- generation -%}{{- rendered -}}{%- endgeneration -%}
|
| 130 |
+
{%- else -%}
|
| 131 |
+
{{- rendered -}}
|
| 132 |
+
{%- endif -%}
|
| 133 |
+
{%- endfor -%}
|
| 134 |
+
|
| 135 |
+
{%- if not state.effort_emitted -%}
|
| 136 |
+
{{- emit_thinking_effort() -}}
|
| 137 |
+
{%- endif -%}
|
config.json
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Inkling2LoopForConditionalGeneration"
|
| 4 |
+
],
|
| 5 |
+
"dtype": "bfloat16",
|
| 6 |
+
"eos_token_id": 200006,
|
| 7 |
+
"image_token_id": 200054,
|
| 8 |
+
"model_type": "inkling2_loop",
|
| 9 |
+
"mtp_config": {
|
| 10 |
+
"block_size": 8,
|
| 11 |
+
"head_dim": 128,
|
| 12 |
+
"hidden_size": 2304,
|
| 13 |
+
"intermediate_size": 9216,
|
| 14 |
+
"local_layer_ids": [
|
| 15 |
+
0,
|
| 16 |
+
2
|
| 17 |
+
],
|
| 18 |
+
"markov_head_type": "rnn_hidden",
|
| 19 |
+
"markov_rank": 256,
|
| 20 |
+
"max_position_embeddings": 1048576,
|
| 21 |
+
"num_attention_heads": 24,
|
| 22 |
+
"num_hidden_layers": 3,
|
| 23 |
+
"num_key_value_heads": 8,
|
| 24 |
+
"o_bias": false,
|
| 25 |
+
"q_bias": false,
|
| 26 |
+
"rms_norm_eps": 1e-06,
|
| 27 |
+
"rope_theta": 1000000.0,
|
| 28 |
+
"sliding_window_size": 1024,
|
| 29 |
+
"target_layer_ids": [
|
| 30 |
+
5,
|
| 31 |
+
23,
|
| 32 |
+
41,
|
| 33 |
+
48
|
| 34 |
+
],
|
| 35 |
+
"torch_dtype": "bfloat16"
|
| 36 |
+
},
|
| 37 |
+
"text_config": {
|
| 38 |
+
"attention_dropout": 0.0,
|
| 39 |
+
"attn_res_normalize_values": true,
|
| 40 |
+
"bos_token_id": null,
|
| 41 |
+
"conv_kernel_size": 4,
|
| 42 |
+
"d_rel": 16,
|
| 43 |
+
"dtype": "bfloat16",
|
| 44 |
+
"eos_token_id": 200006,
|
| 45 |
+
"final_logit_softcapping": 30.0,
|
| 46 |
+
"head_dim": 128,
|
| 47 |
+
"hidden_act": "silu",
|
| 48 |
+
"hidden_size": 2304,
|
| 49 |
+
"initializer_range": 0.02,
|
| 50 |
+
"layer_types": [
|
| 51 |
+
"hybrid_sliding",
|
| 52 |
+
"hybrid_sliding",
|
| 53 |
+
"hybrid_sliding",
|
| 54 |
+
"hybrid_sliding",
|
| 55 |
+
"hybrid_sliding",
|
| 56 |
+
"hybrid",
|
| 57 |
+
"hybrid_sliding",
|
| 58 |
+
"hybrid_sliding",
|
| 59 |
+
"hybrid_sliding",
|
| 60 |
+
"hybrid_sliding",
|
| 61 |
+
"hybrid_sliding",
|
| 62 |
+
"hybrid",
|
| 63 |
+
"hybrid_sliding",
|
| 64 |
+
"hybrid_sliding",
|
| 65 |
+
"hybrid_sliding",
|
| 66 |
+
"hybrid_sliding",
|
| 67 |
+
"hybrid_sliding",
|
| 68 |
+
"hybrid",
|
| 69 |
+
"hybrid_sliding",
|
| 70 |
+
"hybrid_sliding",
|
| 71 |
+
"hybrid_sliding",
|
| 72 |
+
"hybrid_sliding",
|
| 73 |
+
"hybrid_sliding",
|
| 74 |
+
"hybrid"
|
| 75 |
+
],
|
| 76 |
+
"local_layer_ids": [
|
| 77 |
+
0,
|
| 78 |
+
1,
|
| 79 |
+
2,
|
| 80 |
+
3,
|
| 81 |
+
4,
|
| 82 |
+
6,
|
| 83 |
+
7,
|
| 84 |
+
8,
|
| 85 |
+
9,
|
| 86 |
+
10,
|
| 87 |
+
12,
|
| 88 |
+
13,
|
| 89 |
+
14,
|
| 90 |
+
15,
|
| 91 |
+
16,
|
| 92 |
+
18,
|
| 93 |
+
19,
|
| 94 |
+
20,
|
| 95 |
+
21,
|
| 96 |
+
22
|
| 97 |
+
],
|
| 98 |
+
"log_scaling_alpha": 0.1,
|
| 99 |
+
"log_scaling_n_floor": 8192,
|
| 100 |
+
"loop_config": {
|
| 101 |
+
"core_end": 18,
|
| 102 |
+
"core_start": 6,
|
| 103 |
+
"gate_rank": 64,
|
| 104 |
+
"is_varloop": false,
|
| 105 |
+
"num_passes": 3
|
| 106 |
+
},
|
| 107 |
+
"loop_gate_rank": 64,
|
| 108 |
+
"loop_layer_index_end": 18,
|
| 109 |
+
"loop_layer_index_start": 6,
|
| 110 |
+
"loop_num_passes": 3,
|
| 111 |
+
"max_position_embeddings": 1048576,
|
| 112 |
+
"mlp_gate_softcap": 4.0,
|
| 113 |
+
"mlp_up_softcap": 25.0,
|
| 114 |
+
"model_type": "inkling2_loop_text",
|
| 115 |
+
"moe_intermediate_size": 1152,
|
| 116 |
+
"n_layers_per_attn_res_block": 6,
|
| 117 |
+
"n_routed_experts": 128,
|
| 118 |
+
"n_shared_experts": 0,
|
| 119 |
+
"num_attention_heads": 24,
|
| 120 |
+
"num_experts_per_tok": 8,
|
| 121 |
+
"num_hidden_layers": 24,
|
| 122 |
+
"num_key_value_heads": 8,
|
| 123 |
+
"o_bias": false,
|
| 124 |
+
"pad_token_id": null,
|
| 125 |
+
"q_bias": false,
|
| 126 |
+
"qk_l2_clip_threshold": 22.627416997969522,
|
| 127 |
+
"rel_extent": 1024,
|
| 128 |
+
"rel_l2_clip_threshold": 8.0,
|
| 129 |
+
"rms_norm_eps": 1e-06,
|
| 130 |
+
"route_scale": 8.0,
|
| 131 |
+
"scoring_func": "sigmoid",
|
| 132 |
+
"sliding_window_size": 1024,
|
| 133 |
+
"swa_head_dim": 128,
|
| 134 |
+
"swa_num_attention_heads": 24,
|
| 135 |
+
"swa_num_key_value_heads": 8,
|
| 136 |
+
"unpadded_vocab_size": 200058,
|
| 137 |
+
"use_cache": true,
|
| 138 |
+
"use_gate_bias": true,
|
| 139 |
+
"use_value_norm_no_gamma": true,
|
| 140 |
+
"vocab_size": 201024
|
| 141 |
+
},
|
| 142 |
+
"transformers_version": "5.26.0.dev0",
|
| 143 |
+
"vision_config": {
|
| 144 |
+
"attention_dropout": 0.0,
|
| 145 |
+
"dtype": "bfloat16",
|
| 146 |
+
"hidden_act": "gelu",
|
| 147 |
+
"hidden_size": 1024,
|
| 148 |
+
"initializer_range": 0.02,
|
| 149 |
+
"intermediate_size": 4096,
|
| 150 |
+
"layer_norm_eps": 1e-05,
|
| 151 |
+
"layer_scale_init_value": 0.1,
|
| 152 |
+
"mlp_ratio": 4.0,
|
| 153 |
+
"model_type": "inkling2_vision",
|
| 154 |
+
"num_attention_heads": 16,
|
| 155 |
+
"num_channels": 3,
|
| 156 |
+
"num_hidden_layers": 23,
|
| 157 |
+
"patch_size": 20,
|
| 158 |
+
"posemb_grid_size": 32,
|
| 159 |
+
"projection_hidden_dim": 4096,
|
| 160 |
+
"projector_bias": false,
|
| 161 |
+
"rope_parameters": {
|
| 162 |
+
"rope_theta": 10000.0,
|
| 163 |
+
"rope_type": "axial"
|
| 164 |
+
},
|
| 165 |
+
"spatial_merge_size": 2,
|
| 166 |
+
"temporal_patch_size": 2,
|
| 167 |
+
"text_hidden_size": 2304
|
| 168 |
+
}
|
| 169 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"do_sample": true,
|
| 3 |
+
"eos_token_id": 200006,
|
| 4 |
+
"pad_token_id": 199999,
|
| 5 |
+
"temperature": 1.0,
|
| 6 |
+
"transformers_version": "5.26.0.dev0"
|
| 7 |
+
}
|
generation_limits.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MAX_BLOCK_SIZE = 512
|
| 2 |
+
MAX_DIFFUSION_CONTEXT = 1024
|
model-00001-of-00013.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:969875792f73ed878858428e56d532bc463fddf7c59a1f58afe6fa75d9910f9c
|
| 3 |
+
size 4432789832
|
model-00002-of-00013.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c44903b1b03445dee6cbf8da99bea8312888e33c971130d1f82ef77aa9082a43
|
| 3 |
+
size 4921926536
|
model-00003-of-00013.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ff9c2d9bee0ca77a4548ce9ab39aff81f1b66abb17680510b82a7788c7c1ece1
|
| 3 |
+
size 4187560864
|
model-00004-of-00013.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2546199878a0b77adfd3224b787205995aec0f3d4bd06023078e4ede9ae76896
|
| 3 |
+
size 4201413264
|
model-00005-of-00013.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1d2d9ae3084b578f38ccfc94e2a26534cb8f683ebc99c93cfda8807de971c96d
|
| 3 |
+
size 4201413200
|
model-00006-of-00013.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8f8aafffa4bd6729712e26b87ba839c8c40857df162b3f9ec739c32a3e696373
|
| 3 |
+
size 4201720080
|
model-00007-of-00013.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1b2e6549590793f72685f30264aa877d69ed7223b07842aa0ab0d31f7f1bdc46
|
| 3 |
+
size 4201413336
|
model-00008-of-00013.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:621e3ddee8001ea316c633e9c7c2a9f7ad0e2e022dc12ede4476c42a9734a08e
|
| 3 |
+
size 4201413336
|
model-00009-of-00013.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:68b96d826e650654800c155fbdb907984e77433d90f2464e39087e4049ca25b4
|
| 3 |
+
size 4201720080
|
model-00010-of-00013.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:64af94f2bc0424a6b2350b2fb8d404f68fc9fd5e24e49b8126441645b5de4b60
|
| 3 |
+
size 4187254176
|
model-00011-of-00013.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b9225367c078e1e39449d429463f55a8dffa99c0dc6e07e0643e9e7c6142d3eb
|
| 3 |
+
size 4187254176
|
model-00012-of-00013.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9f6b31c36c1d37a6f588b49d246ba7c60d08c725cc5a9827f2ec8dc624217418
|
| 3 |
+
size 4770687456
|
model-00013-of-00013.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c8da5b1f02a259061ae82bbff51e54e1be230435529b85ba1cfc9439561c8cf0
|
| 3 |
+
size 921867392
|
model.safetensors.index.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
processor_config.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"image_processor": {
|
| 3 |
+
"do_convert_rgb": true,
|
| 4 |
+
"do_normalize": true,
|
| 5 |
+
"do_rescale": true,
|
| 6 |
+
"image_mean": [
|
| 7 |
+
0.5,
|
| 8 |
+
0.5,
|
| 9 |
+
0.5
|
| 10 |
+
],
|
| 11 |
+
"image_processor_type": "Inkling2ImageProcessor",
|
| 12 |
+
"image_std": [
|
| 13 |
+
0.5,
|
| 14 |
+
0.5,
|
| 15 |
+
0.5
|
| 16 |
+
],
|
| 17 |
+
"rescale_factor": 0.00392156862745098,
|
| 18 |
+
"size": {
|
| 19 |
+
"height": 40,
|
| 20 |
+
"width": 40
|
| 21 |
+
}
|
| 22 |
+
},
|
| 23 |
+
"image_token": "<|unused_200054|>",
|
| 24 |
+
"processor_class": "Inkling2Processor"
|
| 25 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch==2.14.1
|
| 2 |
+
torchvision==0.29.2
|
| 3 |
+
accelerate>=1.16
|
| 4 |
+
tiktoken>=0.14
|
| 5 |
+
safetensors>=0.8
|
| 6 |
+
huggingface-hub>=2.4,<3
|
| 7 |
+
transformers @ git+https://github.com/huggingface/transformers.git@626e62ef889c9b77c4d1425e076b17ee098ae925
|
run_diffusion.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
+
"""Load the merged Diffusion-Inkling-2-mini checkpoint and run masked denoising."""
|
| 3 |
+
import argparse
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
import torch
|
| 7 |
+
from transformers import AutoProcessor
|
| 8 |
+
from transformers.models.inkling2_loop.modeling_inkling2_loop import Inkling2LoopForConditionalGeneration
|
| 9 |
+
|
| 10 |
+
from block_diffusion import generate, install_future_convolutions
|
| 11 |
+
from generation_limits import MAX_BLOCK_SIZE, MAX_DIFFUSION_CONTEXT
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class DiffusionInkling2Mini(Inkling2LoopForConditionalGeneration):
|
| 15 |
+
_keep_in_fp32_modules_strict = [*(Inkling2LoopForConditionalGeneration._keep_in_fp32_modules_strict or []),
|
| 16 |
+
'future_taps']
|
| 17 |
+
|
| 18 |
+
def __init__(self, config):
|
| 19 |
+
super().__init__(config)
|
| 20 |
+
install_future_convolutions(self)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def load_merged(source):
|
| 24 |
+
model, info = DiffusionInkling2Mini.from_pretrained(
|
| 25 |
+
str(source), device_map={'': 'cuda:0'}, dtype=torch.bfloat16,
|
| 26 |
+
attn_implementation='eager', experts_implementation='grouped_mm', use_kernels=False,
|
| 27 |
+
output_loading_info=True,
|
| 28 |
+
)
|
| 29 |
+
if any(info.get(key) for key in ('missing_keys', 'unexpected_keys', 'mismatched_keys', 'error_msgs')):
|
| 30 |
+
raise RuntimeError(f'Incomplete merged checkpoint load: {info}')
|
| 31 |
+
return model.eval(), AutoProcessor.from_pretrained(str(source))
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def encode_prompt(processor, prompt):
|
| 35 |
+
rendered = processor.apply_chat_template([{'role': 'user', 'content': prompt}], tokenize=False,
|
| 36 |
+
add_generation_prompt=False, reasoning_effort='none')
|
| 37 |
+
return processor.tokenizer(rendered + '<|message_model|><|content_text|>',
|
| 38 |
+
add_special_tokens=False, return_tensors='pt')['input_ids']
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def generate_reply(model, processor, prompt, block_size=128, max_new_tokens=128, threshold=0.7):
|
| 42 |
+
tokenizer = processor.tokenizer
|
| 43 |
+
mask = tokenizer.convert_tokens_to_ids('<|unused_200054|>')
|
| 44 |
+
stop = {tokenizer.eos_token_id, tokenizer.convert_tokens_to_ids('<|end_message|>')}
|
| 45 |
+
suppressed = sorted(set(tokenizer.all_special_ids) - stop)
|
| 46 |
+
ids = encode_prompt(processor, prompt).to(model.device)
|
| 47 |
+
if ids.shape[1] + max_new_tokens > MAX_DIFFUSION_CONTEXT or (ids == mask).any():
|
| 48 |
+
raise ValueError(f'Input and output budget must fit in {MAX_DIFFUSION_CONTEXT} tokens without the reserved mask.')
|
| 49 |
+
tokens = generate(model, ids, mask, stop, max_new_tokens=max_new_tokens, threshold=threshold,
|
| 50 |
+
confidence_order=True, guarded=True, suppressed=suppressed, block_size=block_size)
|
| 51 |
+
return tokenizer.decode(tokens, skip_special_tokens=True)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def main():
|
| 55 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 56 |
+
parser.add_argument('prompt')
|
| 57 |
+
parser.add_argument('--model', default=str(Path(__file__).resolve().parent))
|
| 58 |
+
parser.add_argument('--block-size', type=int, default=128)
|
| 59 |
+
parser.add_argument('--max-new-tokens', type=int, default=128)
|
| 60 |
+
parser.add_argument('--threshold', type=float, default=0.7)
|
| 61 |
+
args = parser.parse_args()
|
| 62 |
+
if not 1 <= args.block_size <= MAX_BLOCK_SIZE or not 0 <= args.threshold <= 1 or args.max_new_tokens < 1:
|
| 63 |
+
parser.error('Specify a valid block size, confidence threshold, and reply budget.')
|
| 64 |
+
model, processor = load_merged(args.model)
|
| 65 |
+
print(generate_reply(model, processor, args.prompt, args.block_size, args.max_new_tokens, args.threshold))
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
if __name__ == '__main__':
|
| 69 |
+
main()
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7f332727f9a3f093dd452a39cc978e6757627e5dad1b0673aa4e75174f236dd6
|
| 3 |
+
size 26178678
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"begin_of_text": "<|begin_of_text|>",
|
| 4 |
+
"clean_up_tokenization_spaces": false,
|
| 5 |
+
"content_image": "<|content_image|>",
|
| 6 |
+
"content_invoke_tool_json": "<|content_invoke_tool_json|>",
|
| 7 |
+
"content_invoke_tool_text": "<|content_invoke_tool_text|>",
|
| 8 |
+
"content_model_end_sampling": "<|content_model_end_sampling|>",
|
| 9 |
+
"content_text": "<|content_text|>",
|
| 10 |
+
"content_thinking": "<|content_thinking|>",
|
| 11 |
+
"content_tool_error": "<|content_tool_error|>",
|
| 12 |
+
"content_xml": "<|content_xml|>",
|
| 13 |
+
"end_message": "<|end_message|>",
|
| 14 |
+
"endoftext": "<|endoftext|>",
|
| 15 |
+
"eos_token": "<|content_model_end_sampling|>",
|
| 16 |
+
"fix_mistral_regex": false,
|
| 17 |
+
"is_local": false,
|
| 18 |
+
"local_files_only": false,
|
| 19 |
+
"message_model": "<|message_model|>",
|
| 20 |
+
"message_system": "<|message_system|>",
|
| 21 |
+
"message_tool": "<|message_tool|>",
|
| 22 |
+
"message_user": "<|message_user|>",
|
| 23 |
+
"model_max_length": 1048576,
|
| 24 |
+
"model_specific_special_tokens": {
|
| 25 |
+
"begin_of_text": "<|begin_of_text|>",
|
| 26 |
+
"content_image": "<|content_image|>",
|
| 27 |
+
"content_invoke_tool_json": "<|content_invoke_tool_json|>",
|
| 28 |
+
"content_invoke_tool_text": "<|content_invoke_tool_text|>",
|
| 29 |
+
"content_model_end_sampling": "<|content_model_end_sampling|>",
|
| 30 |
+
"content_text": "<|content_text|>",
|
| 31 |
+
"content_thinking": "<|content_thinking|>",
|
| 32 |
+
"content_tool_error": "<|content_tool_error|>",
|
| 33 |
+
"content_xml": "<|content_xml|>",
|
| 34 |
+
"end_message": "<|end_message|>",
|
| 35 |
+
"endoftext": "<|endoftext|>",
|
| 36 |
+
"message_model": "<|message_model|>",
|
| 37 |
+
"message_system": "<|message_system|>",
|
| 38 |
+
"message_tool": "<|message_tool|>",
|
| 39 |
+
"message_user": "<|message_user|>"
|
| 40 |
+
},
|
| 41 |
+
"pad_token": "<|endoftext|>",
|
| 42 |
+
"processor_class": "Inkling2Processor",
|
| 43 |
+
"response_template": {
|
| 44 |
+
"defaults": {
|
| 45 |
+
"role": "assistant"
|
| 46 |
+
},
|
| 47 |
+
"fields": {
|
| 48 |
+
"content": {
|
| 49 |
+
"close": "<|end_message|>",
|
| 50 |
+
"content": "text",
|
| 51 |
+
"content_args": {
|
| 52 |
+
"strip": false
|
| 53 |
+
},
|
| 54 |
+
"join": "",
|
| 55 |
+
"open_pattern": "(?:<\\|message_model\\|>[^<]*)?<\\|content_(?:text|tool_error|invoke_tool_text)\\|>",
|
| 56 |
+
"repeats": true
|
| 57 |
+
},
|
| 58 |
+
"reasoning_content": {
|
| 59 |
+
"close": "<|end_message|>",
|
| 60 |
+
"content": "text",
|
| 61 |
+
"content_args": {
|
| 62 |
+
"strip": false
|
| 63 |
+
},
|
| 64 |
+
"join": "",
|
| 65 |
+
"open_pattern": "(?:<\\|message_model\\|>[^<]*)?<\\|content_thinking\\|>",
|
| 66 |
+
"repeats": true
|
| 67 |
+
},
|
| 68 |
+
"tool_calls": {
|
| 69 |
+
"close": "<|end_message|>",
|
| 70 |
+
"content": "json",
|
| 71 |
+
"open_pattern": "(?:<\\|message_model\\|>[^<]*)?<\\|content_invoke_tool_json\\|>",
|
| 72 |
+
"repeats": true,
|
| 73 |
+
"transform": {
|
| 74 |
+
"function": {
|
| 75 |
+
"arguments": "{content.args}",
|
| 76 |
+
"name": "{content.name}"
|
| 77 |
+
},
|
| 78 |
+
"type": "function"
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
},
|
| 82 |
+
"start_anchor_pattern": "<\\|end_message\\|>|<\\|content_model_end_sampling\\|>"
|
| 83 |
+
},
|
| 84 |
+
"tokenizer_class": "TokenizersBackend"
|
| 85 |
+
}
|