mossbee commited on
Commit
b312080
·
verified ·
1 Parent(s): 57c50a9

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -1,35 +1,8 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
  *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  *.safetensors filter=lfs diff=lfs merge=lfs -text
2
+ assets/architecture.jpg filter=lfs diff=lfs merge=lfs -text
3
+ assets/attention.jpg filter=lfs diff=lfs merge=lfs -text
4
+ assets/overview.jpg filter=lfs diff=lfs merge=lfs -text
5
+ examples/attention/1706.03762v7_page-0004.jpg filter=lfs diff=lfs merge=lfs -text
6
+ examples/attention/1706.03762v7_page-0005.jpg filter=lfs diff=lfs merge=lfs -text
7
+ examples/attention/1706.03762v7_page-0006.jpg filter=lfs diff=lfs merge=lfs -text
8
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
 
 
 
LICENSE ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ S-Lab License 1.0
2
+ Copyright 2026 S-Lab
3
+
4
+ Redistribution and use for non-commercial purpose in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
8
+
9
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
10
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12
+
13
+ In the event that redistribution and/or use for commercial purpose in source or binary forms, with or without modification is required, please contact the contributor(s) of the work.
LICENSE-QWEN 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 2026 Alibaba Cloud
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
README.md ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: slab
4
+ license_link: LICENSE
5
+ library_name: transformers
6
+ pipeline_tag: image-text-to-text
7
+ base_model: Qwen/Qwen3.5-9B
8
+ tags:
9
+ - document-question-answering
10
+ - multi-page-documents
11
+ - custom_code
12
+ ---
13
+
14
+ <div align="center">
15
+ <h2>DocSEAM: Bidirectional Cross-Page Encoding for Multi-Page Document Understanding</h2>
16
+ <p>
17
+ <a href="https://mossbee.github.io/">Hoang-Nhat Nguyen</a><sup>1</sup> &nbsp;·&nbsp;
18
+ <a href="https://www.mmlab-ntu.com/person/ccloy/">Chen Change Loy</a><sup>1,2</sup>
19
+ </p>
20
+ <p>
21
+ <sup>1</sup>S-Lab, Nanyang Technological University, Singapore &nbsp;·&nbsp; <sup>2</sup><a href="https://synvo.ai/">Synvo AI</a>
22
+ </p>
23
+ <p>
24
+ <a href="https://mossbee.github.io/projects/DocSEAM/"><img src="https://img.shields.io/badge/%F0%9F%8C%90-Project_Page-267CB9" alt="Project page"></a>
25
+ <a href="https://arxiv.org/abs/2611.34420"><img src="https://img.shields.io/badge/arXiv-Paper-B31B1B?logo=arxiv&amp;logoColor=white" alt="arXiv paper"></a>
26
+ <a href="https://huggingface.co/mossbee/DocSEAM"><img src="https://img.shields.io/badge/%F0%9F%A4%97-Hugging_Face-FFD21E" alt="Hugging Face model"></a>
27
+ <a href="https://github.com/mossbee/DocSEAM"><img src="https://img.shields.io/badge/GitHub-Code-181717?logo=github&amp;logoColor=white" alt="GitHub code"></a>
28
+ </p>
29
+ </div>
30
+
31
+ <p align="center"><strong>DocSEAM enriches visual features with context from neighboring pages for multi-page document understanding, preserving the visual token count.</strong></p>
32
+
33
+ <p align="center">
34
+ <img src="assets/overview.jpg" width="100%" alt="DocSEAM overview showing cross-page feature enrichment and benchmark results">
35
+ </p>
36
+
37
+ <details>
38
+ <summary><b>Introducing DocSEAM</b></summary>
39
+
40
+ <p>DocSEAM enriches each page's visual features with information from its immediate neighbors through center-anchored masked attention and directional salience gates. It preserves the visual token count passed to the language model.</p>
41
+ <p>The architecture below details the directional gates and anchored attention mask used to enrich the center page.</p>
42
+ <p align="center">
43
+ <img src="assets/architecture.jpg" width="100%" alt="DocSEAM architecture with directional gates and anchored attention masking">
44
+ </p>
45
+
46
+ </details>
47
+
48
+ This repository contains the complete BF16 DocSEAM inference checkpoint in six safetensors shards. It incorporates the trained cross-page encoder, merged language-model adaptation, and trained vision merger.
49
+
50
+ ## Run with Transformers
51
+
52
+ Install the dependencies in `requirements.txt`. Select a CUDA device with enough memory for the BF16 weights and the document's activations and cache. Peak memory increases with the number and resolution of pages.
53
+
54
+ ```python
55
+ from pathlib import Path
56
+
57
+ import torch
58
+ from huggingface_hub import hf_hub_download
59
+ from qwen_vl_utils import process_vision_info
60
+ from transformers import AutoModelForImageTextToText, AutoProcessor
61
+
62
+ model_path = "mossbee/DocSEAM"
63
+ processor = AutoProcessor.from_pretrained(model_path)
64
+ model = AutoModelForImageTextToText.from_pretrained(
65
+ model_path, dtype=torch.bfloat16, device_map={"": "cuda:0"}, trust_remote_code=True
66
+ )
67
+
68
+ page_paths = [
69
+ hf_hub_download(model_path, f"examples/attention/1706.03762v7_page-{page:04d}.jpg")
70
+ for page in (4, 5, 6)
71
+ ]
72
+ question = "How many parallel attention heads are used in the model? Answer with only the number."
73
+ pages = [
74
+ {"type": "image", "image": f"file://{Path(path).resolve()}",
75
+ "min_pixels": 32768, "max_pixels": 524288}
76
+ for path in page_paths
77
+ ]
78
+ messages = [{"role": "user", "content": [*pages, {"type": "text", "text": question}]}]
79
+ prompt = processor.apply_chat_template(
80
+ messages, tokenize=False, add_generation_prompt=True, enable_thinking=False
81
+ )
82
+ images, _ = process_vision_info(messages, image_patch_size=processor.image_processor.patch_size)
83
+ inputs = processor(text=[prompt], images=images, return_tensors="pt").to(model.device)
84
+ tokenizer = processor.tokenizer
85
+ with torch.inference_mode():
86
+ tokens = model.generate(
87
+ **inputs, max_new_tokens=128, do_sample=False,
88
+ eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id,
89
+ )
90
+ print(processor.decode(tokens[0, inputs.input_ids.shape[1]:], skip_special_tokens=True))
91
+ ```
92
+
93
+ The example downloads pages 4–6 of *Attention Is All You Need* from this repository. For a local model checkout, use its path as `model_path` and pass the three local image paths directly in `page_paths`.
94
+
95
+ `trust_remote_code=True` loads the DocSEAM architecture from `modeling_docseam.py` and `docseam.py` in this model repository.
96
+
97
+ ## Cross-page attention
98
+
99
+ <p align="center">
100
+ <img src="assets/attention.jpg" width="100%" alt="Cross-page attention on neighboring document pages">
101
+ </p>
102
+
103
+ ## License
104
+
105
+ DocSEAM is released under the [S-Lab License 1.0](LICENSE) for non-commercial use. The Qwen3.5-9B backbone's Apache-2.0 license is retained in [LICENSE-QWEN](LICENSE-QWEN).
106
+
107
+ ## Citation
108
+
109
+ ```bibtex
110
+ @article{nguyen2026docseam,
111
+ title={DocSEAM: Bidirectional Cross-Page Encoding for Multi-Page Document Understanding},
112
+ author={Nguyen, Hoang-Nhat and Loy, Chen Change},
113
+ journal={arXiv preprint arXiv:2611.34420},
114
+ year={2026},
115
+ }
116
+ ```
assets/architecture.jpg ADDED

Git LFS Details

  • SHA256: 11f74d2cdf61a84307f469f1da2c7f1860116f8f8117fc7a3ed4edb19a994b1d
  • Pointer size: 131 Bytes
  • Size of remote file: 319 kB
assets/attention.jpg ADDED

Git LFS Details

  • SHA256: 523091bcfdb8a87b1ba9a643d9242194f95f0157decd13d40d8a6423cc465b22
  • Pointer size: 131 Bytes
  • Size of remote file: 228 kB
assets/overview.jpg ADDED

Git LFS Details

  • SHA256: 8ee7fc51d305c137a660a3e96e71e55806efbfadf616762f90ab83be4ef63caa
  • Pointer size: 131 Bytes
  • Size of remote file: 422 kB
chat_template.jinja ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- set image_count = namespace(value=0) %}
2
+ {%- set video_count = namespace(value=0) %}
3
+ {%- macro render_content(content, do_vision_count, is_system_content=false) %}
4
+ {%- if content is string %}
5
+ {{- content }}
6
+ {%- elif content is iterable and content is not mapping %}
7
+ {%- for item in content %}
8
+ {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
9
+ {%- if is_system_content %}
10
+ {{- raise_exception('System message cannot contain images.') }}
11
+ {%- endif %}
12
+ {%- if do_vision_count %}
13
+ {%- set image_count.value = image_count.value + 1 %}
14
+ {%- endif %}
15
+ {%- if add_vision_id %}
16
+ {{- 'Picture ' ~ image_count.value ~ ': ' }}
17
+ {%- endif %}
18
+ {{- '<|vision_start|><|image_pad|><|vision_end|>' }}
19
+ {%- elif 'video' in item or item.type == 'video' %}
20
+ {%- if is_system_content %}
21
+ {{- raise_exception('System message cannot contain videos.') }}
22
+ {%- endif %}
23
+ {%- if do_vision_count %}
24
+ {%- set video_count.value = video_count.value + 1 %}
25
+ {%- endif %}
26
+ {%- if add_vision_id %}
27
+ {{- 'Video ' ~ video_count.value ~ ': ' }}
28
+ {%- endif %}
29
+ {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
30
+ {%- elif 'text' in item %}
31
+ {{- item.text }}
32
+ {%- else %}
33
+ {{- raise_exception('Unexpected item type in content.') }}
34
+ {%- endif %}
35
+ {%- endfor %}
36
+ {%- elif content is none or content is undefined %}
37
+ {{- '' }}
38
+ {%- else %}
39
+ {{- raise_exception('Unexpected content type.') }}
40
+ {%- endif %}
41
+ {%- endmacro %}
42
+ {%- if not messages %}
43
+ {{- raise_exception('No messages provided.') }}
44
+ {%- endif %}
45
+ {%- if tools and tools is iterable and tools is not mapping %}
46
+ {{- '<|im_start|>system\n' }}
47
+ {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
48
+ {%- for tool in tools %}
49
+ {{- "\n" }}
50
+ {{- tool | tojson }}
51
+ {%- endfor %}
52
+ {{- "\n</tools>" }}
53
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
54
+ {%- if messages[0].role == 'system' %}
55
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
56
+ {%- if content %}
57
+ {{- '\n\n' + content }}
58
+ {%- endif %}
59
+ {%- endif %}
60
+ {{- '<|im_end|>\n' }}
61
+ {%- else %}
62
+ {%- if messages[0].role == 'system' %}
63
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
64
+ {{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
65
+ {%- endif %}
66
+ {%- endif %}
67
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
68
+ {%- for message in messages[::-1] %}
69
+ {%- set index = (messages|length - 1) - loop.index0 %}
70
+ {%- if ns.multi_step_tool and message.role == "user" %}
71
+ {%- set content = render_content(message.content, false)|trim %}
72
+ {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
73
+ {%- set ns.multi_step_tool = false %}
74
+ {%- set ns.last_query_index = index %}
75
+ {%- endif %}
76
+ {%- endif %}
77
+ {%- endfor %}
78
+ {%- if ns.multi_step_tool %}
79
+ {{- raise_exception('No user query found in messages.') }}
80
+ {%- endif %}
81
+ {%- for message in messages %}
82
+ {%- set content = render_content(message.content, true)|trim %}
83
+ {%- if message.role == "system" %}
84
+ {%- if not loop.first %}
85
+ {{- raise_exception('System message must be at the beginning.') }}
86
+ {%- endif %}
87
+ {%- elif message.role == "user" %}
88
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
89
+ {%- elif message.role == "assistant" %}
90
+ {%- set reasoning_content = '' %}
91
+ {%- if message.reasoning_content is string %}
92
+ {%- set reasoning_content = message.reasoning_content %}
93
+ {%- else %}
94
+ {%- if '</think>' in content %}
95
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
96
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
97
+ {%- endif %}
98
+ {%- endif %}
99
+ {%- set reasoning_content = reasoning_content|trim %}
100
+ {%- if loop.index0 > ns.last_query_index %}
101
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
102
+ {%- else %}
103
+ {{- '<|im_start|>' + message.role + '\n' + content }}
104
+ {%- endif %}
105
+ {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
106
+ {%- for tool_call in message.tool_calls %}
107
+ {%- if tool_call.function is defined %}
108
+ {%- set tool_call = tool_call.function %}
109
+ {%- endif %}
110
+ {%- if loop.first %}
111
+ {%- if content|trim %}
112
+ {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
113
+ {%- else %}
114
+ {{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
115
+ {%- endif %}
116
+ {%- else %}
117
+ {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
118
+ {%- endif %}
119
+ {%- if tool_call.arguments is defined %}
120
+ {%- for args_name, args_value in tool_call.arguments|items %}
121
+ {{- '<parameter=' + args_name + '>\n' }}
122
+ {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
123
+ {{- args_value }}
124
+ {{- '\n</parameter>\n' }}
125
+ {%- endfor %}
126
+ {%- endif %}
127
+ {{- '</function>\n</tool_call>' }}
128
+ {%- endfor %}
129
+ {%- endif %}
130
+ {{- '<|im_end|>\n' }}
131
+ {%- elif message.role == "tool" %}
132
+ {%- if loop.previtem and loop.previtem.role != "tool" %}
133
+ {{- '<|im_start|>user' }}
134
+ {%- endif %}
135
+ {{- '\n<tool_response>\n' }}
136
+ {{- content }}
137
+ {{- '\n</tool_response>' }}
138
+ {%- if not loop.last and loop.nextitem.role != "tool" %}
139
+ {{- '<|im_end|>\n' }}
140
+ {%- elif loop.last %}
141
+ {{- '<|im_end|>\n' }}
142
+ {%- endif %}
143
+ {%- else %}
144
+ {{- raise_exception('Unexpected message role.') }}
145
+ {%- endif %}
146
+ {%- endfor %}
147
+ {%- if add_generation_prompt %}
148
+ {{- '<|im_start|>assistant\n' }}
149
+ {%- if enable_thinking is defined and enable_thinking is false %}
150
+ {{- '<think>\n\n</think>\n\n' }}
151
+ {%- else %}
152
+ {{- '<think>\n' }}
153
+ {%- endif %}
154
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "DocSEAMForConditionalGeneration"
4
+ ],
5
+ "auto_map": {
6
+ "AutoModelForImageTextToText": "modeling_docseam.DocSEAMForConditionalGeneration"
7
+ },
8
+ "dtype": "bfloat16",
9
+ "image_token_id": 248056,
10
+ "model_type": "qwen3_5",
11
+ "docseam_cap_frac": 0.2,
12
+ "docseam_num_layers": 2,
13
+ "docseam_pos_feature_mode": "frontier",
14
+ "text_config": {
15
+ "attention_bias": false,
16
+ "attention_dropout": 0.0,
17
+ "attn_output_gate": true,
18
+ "bos_token_id": null,
19
+ "dtype": "bfloat16",
20
+ "eos_token_id": 248044,
21
+ "full_attention_interval": 4,
22
+ "head_dim": 256,
23
+ "hidden_act": "silu",
24
+ "hidden_size": 4096,
25
+ "initializer_range": 0.02,
26
+ "intermediate_size": 12288,
27
+ "layer_types": [
28
+ "linear_attention",
29
+ "linear_attention",
30
+ "linear_attention",
31
+ "full_attention",
32
+ "linear_attention",
33
+ "linear_attention",
34
+ "linear_attention",
35
+ "full_attention",
36
+ "linear_attention",
37
+ "linear_attention",
38
+ "linear_attention",
39
+ "full_attention",
40
+ "linear_attention",
41
+ "linear_attention",
42
+ "linear_attention",
43
+ "full_attention",
44
+ "linear_attention",
45
+ "linear_attention",
46
+ "linear_attention",
47
+ "full_attention",
48
+ "linear_attention",
49
+ "linear_attention",
50
+ "linear_attention",
51
+ "full_attention",
52
+ "linear_attention",
53
+ "linear_attention",
54
+ "linear_attention",
55
+ "full_attention",
56
+ "linear_attention",
57
+ "linear_attention",
58
+ "linear_attention",
59
+ "full_attention"
60
+ ],
61
+ "linear_conv_kernel_dim": 4,
62
+ "linear_key_head_dim": 128,
63
+ "linear_num_key_heads": 16,
64
+ "linear_num_value_heads": 32,
65
+ "linear_value_head_dim": 128,
66
+ "mamba_ssm_dtype": "float32",
67
+ "max_position_embeddings": 262144,
68
+ "mlp_only_layers": [],
69
+ "model_type": "qwen3_5_text",
70
+ "mtp_num_hidden_layers": 1,
71
+ "mtp_use_dedicated_embeddings": false,
72
+ "num_attention_heads": 16,
73
+ "num_hidden_layers": 32,
74
+ "num_key_value_heads": 4,
75
+ "pad_token_id": null,
76
+ "partial_rotary_factor": 0.25,
77
+ "rms_norm_eps": 1e-06,
78
+ "rope_parameters": {
79
+ "mrope_interleaved": true,
80
+ "mrope_section": [
81
+ 11,
82
+ 11,
83
+ 10
84
+ ],
85
+ "partial_rotary_factor": 0.25,
86
+ "rope_theta": 10000000,
87
+ "rope_type": "default"
88
+ },
89
+ "tie_word_embeddings": false,
90
+ "use_cache": true,
91
+ "vocab_size": 248320
92
+ },
93
+ "tie_word_embeddings": false,
94
+ "transformers_version": "5.6.0",
95
+ "video_token_id": 248057,
96
+ "vision_config": {
97
+ "deepstack_visual_indexes": [],
98
+ "depth": 27,
99
+ "dtype": "bfloat16",
100
+ "hidden_act": "gelu_pytorch_tanh",
101
+ "hidden_size": 1152,
102
+ "in_channels": 3,
103
+ "initializer_range": 0.02,
104
+ "intermediate_size": 4304,
105
+ "model_type": "qwen3_5_vision",
106
+ "num_heads": 16,
107
+ "num_position_embeddings": 2304,
108
+ "out_hidden_size": 4096,
109
+ "patch_size": 16,
110
+ "spatial_merge_size": 2,
111
+ "temporal_patch_size": 2
112
+ },
113
+ "vision_end_token_id": 248054,
114
+ "vision_start_token_id": 248053
115
+ }
docseam.py ADDED
@@ -0,0 +1,1142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ DocSEAM: Document Selective Enrichment via Anchored Masking.
3
+
4
+ A small, injectable module placed after a pretrained VLM's vision encoder
5
+ (post-merger) and before the language model. It fuses each page with both
6
+ neighbors through asymmetric, salience-gated cross-page attention.
7
+
8
+ Key design:
9
+ - Joint masked self-attention over concatenated [Z_prev; Z_curr; Z_next]
10
+ - Asymmetric mask: curr <->{prev,next}, prev/next self-attend + read curr,
11
+ prev <-> next blocked
12
+ - Directional salience gate: learned content-conditioned gates decide which
13
+ boundary tokens send to and receive from each neighbor
14
+ - Zero-init output projections -> exact no-op at initialization
15
+ - Clone QKV/FFN from host vision block for stable injection
16
+ """
17
+
18
+ import math
19
+ from typing import Optional
20
+
21
+ import torch
22
+ import torch.nn as nn
23
+ import torch.nn.functional as F
24
+
25
+
26
+ _ACT_FACTORIES = {
27
+ "gelu_tanh": lambda: nn.GELU(approximate="tanh"),
28
+ "gelu_pytorch_tanh": lambda: nn.GELU(approximate="tanh"),
29
+ "gelu": lambda: nn.GELU(),
30
+ "silu": lambda: nn.SiLU(),
31
+ "relu": lambda: nn.ReLU(),
32
+ }
33
+
34
+
35
+ def _make_activation(name: str) -> nn.Module:
36
+ if name not in _ACT_FACTORIES:
37
+ raise ValueError(f"Unknown activation {name!r}. Known: {sorted(_ACT_FACTORIES)}")
38
+ return _ACT_FACTORIES[name]()
39
+
40
+
41
+ def _make_norm(hidden_size: int, eps: float = 1e-6) -> nn.LayerNorm:
42
+ return nn.LayerNorm(hidden_size, eps=eps)
43
+
44
+
45
+ # ---------------------------------------------------------------------------
46
+ # Positional feature for salience gate
47
+ # ---------------------------------------------------------------------------
48
+
49
+ def cross_page_pos_feature(dist_frac: torch.Tensor, num_freqs: int = 4) -> torch.Tensor:
50
+ """Continuous sinusoidal positional feature for distance-from-edge.
51
+
52
+ Args:
53
+ dist_frac: [...] float in [0, 1], capped fractional distance.
54
+ num_freqs: number of frequency bands.
55
+
56
+ Returns:
57
+ [..., 1 + 2*num_freqs] tensor (no learnable params).
58
+ """
59
+ freqs = (2.0 ** torch.arange(num_freqs, device=dist_frac.device, dtype=dist_frac.dtype)) * math.pi
60
+ angles = dist_frac.unsqueeze(-1) * freqs # [..., num_freqs]
61
+ return torch.cat([dist_frac.unsqueeze(-1), torch.sin(angles), torch.cos(angles)], dim=-1)
62
+
63
+
64
+ def compute_pos_features(
65
+ h: int, w: int, cap_frac: float, device: torch.device, dtype: torch.dtype,
66
+ ) -> torch.Tensor:
67
+ """Compute per-token positional features for a page grid.
68
+
69
+ Args:
70
+ h: grid height (post-merger rows).
71
+ w: grid width (post-merger cols).
72
+ cap_frac: CAP_FRAC — fraction of page height for capping distance.
73
+ device, dtype: tensor placement.
74
+
75
+ Returns:
76
+ [h*w, 18] tensor of positional features.
77
+ """
78
+ num_freqs = 4
79
+ n_tokens = h * w
80
+
81
+ # Row index for each token (tokens are stored row-major)
82
+ row_idx = torch.arange(h, device=device, dtype=dtype).unsqueeze(1).expand(h, w).reshape(n_tokens)
83
+ h_real = float(h)
84
+ cap_p = cap_frac * h_real
85
+
86
+ # Distance from top edge, capped
87
+ dist_top = torch.clamp(row_idx, max=cap_p) / h_real
88
+ # Distance from bottom edge, capped
89
+ dist_bot = torch.clamp(h_real - 1.0 - row_idx, max=cap_p) / h_real
90
+
91
+ # Sinusoidal expansion (9 dims each, 18 total)
92
+ feat_top = cross_page_pos_feature(dist_top, num_freqs) # [n_tokens, 9]
93
+ feat_bot = cross_page_pos_feature(dist_bot, num_freqs) # [n_tokens, 9]
94
+
95
+ return torch.cat([feat_top, feat_bot], dim=-1) # [n_tokens, 18]
96
+
97
+
98
+ @torch.no_grad()
99
+ def _find_content_frontiers(
100
+ content_mask: torch.Tensor,
101
+ h: int,
102
+ w: int,
103
+ ) -> Optional[tuple[torch.Tensor, torch.Tensor]]:
104
+ """Find first/last ink rows from a per-token content mask."""
105
+ content = content_mask.reshape(h, w).float()
106
+ row_score = content.amax(dim=1)
107
+ if row_score.numel() == 0:
108
+ return None
109
+
110
+ max_score = row_score.max()
111
+ threshold = torch.maximum(max_score * 0.25, row_score.new_tensor(0.03))
112
+ active_rows = torch.nonzero(row_score >= threshold, as_tuple=False).flatten()
113
+ if active_rows.numel() == 0:
114
+ active_rows = torch.nonzero(row_score > 0, as_tuple=False).flatten()
115
+ if active_rows.numel() == 0:
116
+ return None
117
+
118
+ return active_rows[0].to(device=content.device), active_rows[-1].to(device=content.device)
119
+
120
+
121
+ def compute_frontier_pos_features(
122
+ h: int,
123
+ w: int,
124
+ cap_frac: float,
125
+ device: torch.device,
126
+ dtype: torch.dtype,
127
+ content_mask: Optional[torch.Tensor],
128
+ ) -> torch.Tensor:
129
+ """Compute positional gate features relative to first/last ink rows.
130
+
131
+ Blank page margins outside the detected content band are treated as far
132
+ from the frontier, so the gate cannot use physical whitespace as the easy
133
+ shortcut for "near a boundary".
134
+ """
135
+ if content_mask is None:
136
+ return compute_pos_features(h, w, cap_frac, device, dtype)
137
+
138
+ content_mask = content_mask.to(device=device)
139
+ frontiers = _find_content_frontiers(content_mask, h, w)
140
+ if frontiers is None:
141
+ return compute_pos_features(h, w, cap_frac, device, dtype)
142
+
143
+ top_frontier, bottom_frontier = frontiers
144
+ num_freqs = 4
145
+ n_tokens = h * w
146
+ row_idx = torch.arange(h, device=device, dtype=dtype).unsqueeze(1).expand(h, w).reshape(n_tokens)
147
+ h_real = float(h)
148
+ cap_p = cap_frac * h_real
149
+ far = row_idx.new_full(row_idx.shape, cap_p)
150
+
151
+ top_frontier = top_frontier.to(device=device, dtype=dtype)
152
+ bottom_frontier = bottom_frontier.to(device=device, dtype=dtype)
153
+ dist_top_raw = row_idx - top_frontier
154
+ dist_bottom_raw = bottom_frontier - row_idx
155
+
156
+ dist_top = torch.where(dist_top_raw >= 0, torch.clamp(dist_top_raw, max=cap_p), far) / h_real
157
+ dist_bot = torch.where(dist_bottom_raw >= 0, torch.clamp(dist_bottom_raw, max=cap_p), far) / h_real
158
+
159
+ feat_top = cross_page_pos_feature(dist_top, num_freqs)
160
+ feat_bot = cross_page_pos_feature(dist_bot, num_freqs)
161
+ return torch.cat([feat_top, feat_bot], dim=-1)
162
+
163
+
164
+ def compute_edge_targets(
165
+ h: int,
166
+ w: int,
167
+ tau_frac: float,
168
+ device: torch.device,
169
+ dtype: torch.dtype,
170
+ ) -> tuple[torch.Tensor, torch.Tensor]:
171
+ """Soft top/bottom edge targets for directional gate regularization."""
172
+ n_tokens = h * w
173
+ row_idx = torch.arange(h, device=device, dtype=dtype).unsqueeze(1).expand(h, w).reshape(n_tokens)
174
+ denom = max(float(h - 1), 1.0)
175
+ tau = max(float(tau_frac), 1e-4)
176
+ dist_top = row_idx / denom
177
+ dist_bottom = (float(h - 1) - row_idx) / denom
178
+ target_top = torch.exp(-dist_top / tau)
179
+ target_bottom = torch.exp(-dist_bottom / tau)
180
+ return target_top, target_bottom
181
+
182
+
183
+ def compute_ink_edge_targets(
184
+ target_top: torch.Tensor,
185
+ target_bottom: torch.Tensor,
186
+ content_mask: torch.Tensor,
187
+ ) -> tuple[torch.Tensor, torch.Tensor]:
188
+ """Apply a detached per-token ink/content mask to edge targets."""
189
+ content_mask = content_mask.to(device=target_top.device, dtype=target_top.dtype)
190
+ return target_top * content_mask, target_bottom * content_mask
191
+
192
+
193
+ @torch.no_grad()
194
+ def compute_ink_frontier_targets(
195
+ content_mask: torch.Tensor,
196
+ h: int,
197
+ w: int,
198
+ tau_frac: float,
199
+ ) -> tuple[torch.Tensor, torch.Tensor]:
200
+ """Soft targets around the first/last ink rows, not the physical page edge."""
201
+ content = content_mask.reshape(h, w).float()
202
+ row_score = content.amax(dim=1)
203
+ if row_score.numel() == 0:
204
+ zeros = content.reshape(-1).to(dtype=content_mask.dtype)
205
+ return zeros, zeros
206
+
207
+ max_score = row_score.max()
208
+ threshold = torch.maximum(max_score * 0.25, row_score.new_tensor(0.03))
209
+ active_rows = torch.nonzero(row_score >= threshold, as_tuple=False).flatten()
210
+ if active_rows.numel() == 0:
211
+ active_rows = torch.nonzero(row_score > 0, as_tuple=False).flatten()
212
+ if active_rows.numel() == 0:
213
+ zeros = content.reshape(-1).to(dtype=content_mask.dtype)
214
+ return zeros, zeros
215
+
216
+ top_frontier = active_rows[0].to(device=content.device, dtype=content.dtype)
217
+ bottom_frontier = active_rows[-1].to(device=content.device, dtype=content.dtype)
218
+ row_idx = torch.arange(h, device=content.device, dtype=content.dtype).unsqueeze(1)
219
+ denom = max(float(h - 1), 1.0)
220
+ tau = max(float(tau_frac), 1e-4)
221
+
222
+ top_band = torch.exp(-torch.abs(row_idx - top_frontier) / (denom * tau))
223
+ bottom_band = torch.exp(-torch.abs(row_idx - bottom_frontier) / (denom * tau))
224
+ target_top = (top_band * content).reshape(-1).to(dtype=content_mask.dtype)
225
+ target_bottom = (bottom_band * content).reshape(-1).to(dtype=content_mask.dtype)
226
+ return target_top, target_bottom
227
+
228
+
229
+ # ---------------------------------------------------------------------------
230
+ # Asymmetric attention mask builder
231
+ # ---------------------------------------------------------------------------
232
+
233
+ def build_asymmetric_mask(
234
+ n_prev: int, n_curr: int, n_next: int, device: torch.device, dtype: torch.dtype,
235
+ ) -> torch.Tensor:
236
+ """Build the [3N, 3N] additive mask for the triplet attention.
237
+
238
+ Allowed flows:
239
+ prev -> {prev, curr} (self-attend + read center)
240
+ curr -> {prev, curr, next} (reads both neighbors — BIDIRECTIONAL)
241
+ next -> {curr, next} (self-attend + read center)
242
+ BLOCKED: prev <-> next (two pages apart, no direct link)
243
+
244
+ Returns:
245
+ [total, total] additive float mask. 0 = allowed, -inf = blocked.
246
+ """
247
+ total = n_prev + n_curr + n_next
248
+ min_val = torch.finfo(dtype).min
249
+ mask = torch.full((total, total), min_val, device=device, dtype=dtype)
250
+
251
+ # Ranges
252
+ p_s, p_e = 0, n_prev
253
+ c_s, c_e = n_prev, n_prev + n_curr
254
+ n_s, n_e = n_prev + n_curr, total
255
+
256
+ # prev -> prev (self-attend)
257
+ mask[p_s:p_e, p_s:p_e] = 0.0
258
+ # prev -> curr (read center)
259
+ mask[p_s:p_e, c_s:c_e] = 0.0
260
+ # curr -> prev (read prev neighbor)
261
+ mask[c_s:c_e, p_s:p_e] = 0.0
262
+ # curr -> curr (self-attend)
263
+ mask[c_s:c_e, c_s:c_e] = 0.0
264
+ # curr -> next (read next neighbor)
265
+ mask[c_s:c_e, n_s:n_e] = 0.0
266
+ # next -> curr (read center)
267
+ mask[n_s:n_e, c_s:c_e] = 0.0
268
+ # next -> next (self-attend)
269
+ mask[n_s:n_e, n_s:n_e] = 0.0
270
+ # prev <-> next: BLOCKED (stays at min_val)
271
+
272
+ return mask
273
+
274
+
275
+ # ---------------------------------------------------------------------------
276
+ # DocSEAM Block (single transformer layer over the triplet)
277
+ # ---------------------------------------------------------------------------
278
+
279
+ class DocSEAMBlock(nn.Module):
280
+ """Single DocSEAM transformer layer: salience-gated, asymmetric-masked
281
+ self-attention over [Z_prev; Z_curr; Z_next] + FFN.
282
+
283
+ Args:
284
+ hidden_size: token dimension (post-merger, = LLM hidden_size).
285
+ num_heads: attention heads.
286
+ intermediate_size: FFN inner dimension.
287
+ cap_frac: CAP_FRAC for salience gate positional features.
288
+ proj_init_std: if > 0, init output projections with normal(0, std);
289
+ otherwise zero-init (default for exact no-op).
290
+ activation: activation function name for FFN.
291
+ """
292
+
293
+ POS_FEAT_DIM = 18 # 2 * (1 + 2*4)
294
+
295
+ def __init__(
296
+ self,
297
+ hidden_size: int,
298
+ num_heads: int,
299
+ intermediate_size: int = 4096,
300
+ cap_frac: float = 0.20,
301
+ proj_init_std: float = 0.0,
302
+ activation: str = "gelu_pytorch_tanh",
303
+ ):
304
+ super().__init__()
305
+ self.hidden_size = hidden_size
306
+ self.num_heads = num_heads
307
+ self.head_dim = hidden_size // num_heads
308
+ self.cap_frac = cap_frac
309
+
310
+ # --- Norms ---
311
+ self.norm1 = _make_norm(hidden_size)
312
+ self.norm2 = _make_norm(hidden_size)
313
+
314
+ # --- Attention QKV (fused) + output projection ---
315
+ self.qkv = nn.Linear(hidden_size, hidden_size * 3, bias=True)
316
+ self.proj = nn.Linear(hidden_size, hidden_size, bias=True)
317
+
318
+ # --- FFN (2-linear GELU, mirroring Qwen3.5 vision block) ---
319
+ self.act = _make_activation(activation)
320
+ self.fc1 = nn.Linear(hidden_size, intermediate_size, bias=True)
321
+ self.fc2 = nn.Linear(intermediate_size, hidden_size, bias=True)
322
+
323
+ # --- Directional salience gate MLPs (D+18 -> D/4 -> 1) ---
324
+ gate_input_dim = hidden_size + self.POS_FEAT_DIM
325
+ gate_hidden_dim = hidden_size // 4
326
+ self.mlp_send_to_next = nn.Sequential(
327
+ nn.Linear(gate_input_dim, gate_hidden_dim),
328
+ nn.GELU(),
329
+ nn.Linear(gate_hidden_dim, 1),
330
+ )
331
+ self.mlp_recv_from_prev = nn.Sequential(
332
+ nn.Linear(gate_input_dim, gate_hidden_dim),
333
+ nn.GELU(),
334
+ nn.Linear(gate_hidden_dim, 1),
335
+ )
336
+ self.mlp_send_to_prev = nn.Sequential(
337
+ nn.Linear(gate_input_dim, gate_hidden_dim),
338
+ nn.GELU(),
339
+ nn.Linear(gate_hidden_dim, 1),
340
+ )
341
+ self.mlp_recv_from_next = nn.Sequential(
342
+ nn.Linear(gate_input_dim, gate_hidden_dim),
343
+ nn.GELU(),
344
+ nn.Linear(gate_hidden_dim, 1),
345
+ )
346
+
347
+ # --- Init ---
348
+ self._init_weights(proj_init_std)
349
+
350
+ def _init_weights(self, proj_init_std: float):
351
+ """Zero-init output projections and salience gate final layers."""
352
+ # Output projection: zero or tiny-normal
353
+ if proj_init_std > 0:
354
+ nn.init.normal_(self.proj.weight, std=proj_init_std)
355
+ nn.init.zeros_(self.proj.bias)
356
+ nn.init.normal_(self.fc2.weight, std=proj_init_std)
357
+ nn.init.zeros_(self.fc2.bias)
358
+ else:
359
+ nn.init.zeros_(self.proj.weight)
360
+ nn.init.zeros_(self.proj.bias)
361
+ nn.init.zeros_(self.fc2.weight)
362
+ nn.init.zeros_(self.fc2.bias)
363
+
364
+ # Salience gate final layers: zero-init so gates start neutral.
365
+ for mlp in (
366
+ self.mlp_send_to_next,
367
+ self.mlp_recv_from_prev,
368
+ self.mlp_send_to_prev,
369
+ self.mlp_recv_from_next,
370
+ ):
371
+ nn.init.zeros_(mlp[-1].weight)
372
+ nn.init.zeros_(mlp[-1].bias)
373
+
374
+ def _compute_salience_bias(
375
+ self,
376
+ tokens: torch.Tensor,
377
+ pos_feats: torch.Tensor,
378
+ n_prev: int,
379
+ n_curr: int,
380
+ n_next: int,
381
+ ) -> torch.Tensor:
382
+ """Compute additive salience bias for cross-page attention cells.
383
+
384
+ Args:
385
+ tokens: [total, D] the normalized concatenated tokens.
386
+ pos_feats: [total, 18] positional features for all tokens.
387
+ n_prev, n_curr, n_next: token counts per page.
388
+
389
+ Returns:
390
+ [total, total] additive bias (0 for same-page cells, gate values
391
+ for cross-page cells).
392
+ """
393
+ total = n_prev + n_curr + n_next
394
+
395
+ # Concatenate features for gate input
396
+ gate_input = torch.cat([tokens, pos_feats], dim=-1) # [total, D+18]
397
+
398
+ # Compute per-token directional scores.
399
+ s_send_to_next = self.mlp_send_to_next(gate_input).squeeze(-1) # [total]
400
+ s_recv_from_prev = self.mlp_recv_from_prev(gate_input).squeeze(-1) # [total]
401
+ s_send_to_prev = self.mlp_send_to_prev(gate_input).squeeze(-1) # [total]
402
+ s_recv_from_next = self.mlp_recv_from_next(gate_input).squeeze(-1) # [total]
403
+
404
+ # Cache for visualization.
405
+ self._last_salience = {
406
+ "s_send_to_next": s_send_to_next.detach(),
407
+ "s_recv_from_prev": s_recv_from_prev.detach(),
408
+ "s_send_to_prev": s_send_to_prev.detach(),
409
+ "s_recv_from_next": s_recv_from_next.detach(),
410
+ }
411
+
412
+ # log_sigmoid for numerical stability.
413
+ log_send_to_next = F.logsigmoid(s_send_to_next) # [total]
414
+ log_recv_from_prev = F.logsigmoid(s_recv_from_prev) # [total]
415
+ log_send_to_prev = F.logsigmoid(s_send_to_prev) # [total]
416
+ log_recv_from_next = F.logsigmoid(s_recv_from_next) # [total]
417
+
418
+ # Build bias: only apply to cross-page cells
419
+ bias = torch.zeros(total, total, device=tokens.device, dtype=tokens.dtype)
420
+
421
+ # Ranges
422
+ p_s, p_e = 0, n_prev
423
+ c_s, c_e = n_prev, n_prev + n_curr
424
+ n_s, n_e = n_prev + n_curr, total
425
+
426
+ # curr query reads prev key: current receives from previous; previous sends to next.
427
+ bias[c_s:c_e, p_s:p_e] = (
428
+ log_recv_from_prev[c_s:c_e].unsqueeze(1) + log_send_to_next[p_s:p_e].unsqueeze(0)
429
+ )
430
+ # curr query reads next key: current receives from next; next sends to previous.
431
+ bias[c_s:c_e, n_s:n_e] = (
432
+ log_recv_from_next[c_s:c_e].unsqueeze(1) + log_send_to_prev[n_s:n_e].unsqueeze(0)
433
+ )
434
+ # prev query reads curr key: previous receives from next; current sends to previous.
435
+ bias[p_s:p_e, c_s:c_e] = (
436
+ log_recv_from_next[p_s:p_e].unsqueeze(1) + log_send_to_prev[c_s:c_e].unsqueeze(0)
437
+ )
438
+ # next query reads curr key: next receives from previous; current sends to next.
439
+ bias[n_s:n_e, c_s:c_e] = (
440
+ log_recv_from_prev[n_s:n_e].unsqueeze(1) + log_send_to_next[c_s:c_e].unsqueeze(0)
441
+ )
442
+
443
+ return bias
444
+
445
+ def _compute_gate_scores(self, tokens: torch.Tensor, pos_feats: torch.Tensor) -> dict[str, torch.Tensor]:
446
+ gate_input = torch.cat([tokens, pos_feats], dim=-1)
447
+ return {
448
+ "s_send_to_next": self.mlp_send_to_next(gate_input).squeeze(-1),
449
+ "s_recv_from_prev": self.mlp_recv_from_prev(gate_input).squeeze(-1),
450
+ "s_send_to_prev": self.mlp_send_to_prev(gate_input).squeeze(-1),
451
+ "s_recv_from_next": self.mlp_recv_from_next(gate_input).squeeze(-1),
452
+ }
453
+
454
+ def compute_gate_aux_loss(
455
+ self,
456
+ triplet_tokens: torch.Tensor,
457
+ pos_feats: torch.Tensor,
458
+ target_top: Optional[torch.Tensor],
459
+ target_bottom: Optional[torch.Tensor],
460
+ target_content: Optional[torch.Tensor],
461
+ frontier_top: Optional[torch.Tensor],
462
+ frontier_bottom: Optional[torch.Tensor],
463
+ edge_prior_weight: float,
464
+ ink_prior_weight: float,
465
+ frontier_prior_weight: float,
466
+ gate_l1_weight: float,
467
+ gate_budget_weight: float,
468
+ gate_budget_target: float,
469
+ margin_penalty_weight: float = 0.0,
470
+ ) -> torch.Tensor:
471
+
472
+ normed = self.norm1(triplet_tokens)
473
+ scores = self._compute_gate_scores(normed, pos_feats)
474
+ loss = normed.new_zeros(())
475
+
476
+ def weighted_open_loss(score: torch.Tensor, weight: torch.Tensor) -> torch.Tensor:
477
+ open_loss = F.binary_cross_entropy_with_logits(
478
+ score,
479
+ torch.ones_like(score),
480
+ reduction="none",
481
+ )
482
+ weight = weight.detach()
483
+ return (open_loss * weight).sum() / weight.sum().clamp_min(1.0)
484
+
485
+ if edge_prior_weight > 0 and target_top is not None and target_bottom is not None:
486
+ edge_loss = (
487
+ F.binary_cross_entropy_with_logits(scores["s_send_to_next"], target_bottom)
488
+ + F.binary_cross_entropy_with_logits(scores["s_recv_from_prev"], target_top)
489
+ + F.binary_cross_entropy_with_logits(scores["s_send_to_prev"], target_top)
490
+ + F.binary_cross_entropy_with_logits(scores["s_recv_from_next"], target_bottom)
491
+ ) / 4.0
492
+ loss = loss + float(edge_prior_weight) * edge_loss
493
+
494
+ if ink_prior_weight > 0 and target_top is not None and target_bottom is not None and target_content is not None:
495
+ ink_top, ink_bottom = compute_ink_edge_targets(target_top, target_bottom, target_content)
496
+
497
+ ink_loss = (
498
+ weighted_open_loss(scores["s_send_to_next"], ink_bottom)
499
+ + weighted_open_loss(scores["s_recv_from_prev"], ink_top)
500
+ + weighted_open_loss(scores["s_send_to_prev"], ink_top)
501
+ + weighted_open_loss(scores["s_recv_from_next"], ink_bottom)
502
+ ) / 4.0
503
+ loss = loss + float(ink_prior_weight) * ink_loss
504
+
505
+ if frontier_prior_weight > 0 and frontier_top is not None and frontier_bottom is not None:
506
+ frontier_loss = (
507
+ weighted_open_loss(scores["s_send_to_next"], frontier_bottom)
508
+ + weighted_open_loss(scores["s_recv_from_prev"], frontier_top)
509
+ + weighted_open_loss(scores["s_send_to_prev"], frontier_top)
510
+ + weighted_open_loss(scores["s_recv_from_next"], frontier_bottom)
511
+ ) / 4.0
512
+ loss = loss + float(frontier_prior_weight) * frontier_loss
513
+
514
+ if (
515
+ margin_penalty_weight > 0
516
+ and target_top is not None
517
+ and target_bottom is not None
518
+ and target_content is not None
519
+ ):
520
+ blank = (1.0 - target_content.detach()).clamp(0.0, 1.0)
521
+ margin_top = target_top.detach() * blank
522
+ margin_bottom = target_bottom.detach() * blank
523
+
524
+ def weighted_close_loss(score: torch.Tensor, weight: torch.Tensor) -> torch.Tensor:
525
+ close_loss = F.binary_cross_entropy_with_logits(
526
+ score,
527
+ torch.zeros_like(score),
528
+ reduction="none",
529
+ )
530
+ return (close_loss * weight).sum() / weight.sum().clamp_min(1.0)
531
+
532
+ margin_loss = (
533
+ weighted_close_loss(scores["s_send_to_next"], margin_bottom)
534
+ + weighted_close_loss(scores["s_recv_from_prev"], margin_top)
535
+ + weighted_close_loss(scores["s_send_to_prev"], margin_top)
536
+ + weighted_close_loss(scores["s_recv_from_next"], margin_bottom)
537
+ ) / 4.0
538
+ loss = loss + float(margin_penalty_weight) * margin_loss
539
+
540
+ if gate_l1_weight > 0:
541
+ gate_l1 = torch.stack([torch.sigmoid(score).mean() for score in scores.values()]).mean()
542
+ loss = loss + float(gate_l1_weight) * gate_l1
543
+
544
+ if gate_budget_weight > 0:
545
+ gate_means = torch.stack([torch.sigmoid(score).mean() for score in scores.values()])
546
+ target = gate_means.new_tensor(float(gate_budget_target))
547
+ gate_budget = F.relu(gate_means - target).square().mean()
548
+ loss = loss + float(gate_budget_weight) * gate_budget
549
+
550
+ return loss
551
+
552
+ def forward(
553
+ self,
554
+ triplet_tokens: torch.Tensor,
555
+ attn_mask: torch.Tensor,
556
+ pos_feats: torch.Tensor,
557
+ n_prev: int,
558
+ n_curr: int,
559
+ n_next: int,
560
+ ) -> torch.Tensor:
561
+ """Forward pass through one DocSEAM layer.
562
+
563
+ Args:
564
+ triplet_tokens: [total, D] concatenated [Z_prev; Z_curr; Z_next].
565
+ attn_mask: [total, total] additive mask (0=allowed, -inf=blocked).
566
+ pos_feats: [total, 18] positional features for all tokens.
567
+ n_prev, n_curr, n_next: token counts per page.
568
+
569
+ Returns:
570
+ [total, D] updated tokens (all 3 pages updated).
571
+ """
572
+ total = triplet_tokens.shape[0]
573
+
574
+ # --- Attention ---
575
+ normed = self.norm1(triplet_tokens)
576
+
577
+ # QKV projection
578
+ qkv = self.qkv(normed) # [total, 3*D]
579
+ q = qkv[:, :self.hidden_size]
580
+ k = qkv[:, self.hidden_size:2 * self.hidden_size]
581
+ v = qkv[:, 2 * self.hidden_size:]
582
+
583
+ # Reshape for multi-head attention: [1, num_heads, total, head_dim]
584
+ q = q.view(total, self.num_heads, self.head_dim).transpose(0, 1).unsqueeze(0)
585
+ k = k.view(total, self.num_heads, self.head_dim).transpose(0, 1).unsqueeze(0)
586
+ v = v.view(total, self.num_heads, self.head_dim).transpose(0, 1).unsqueeze(0)
587
+
588
+ # Compute salience bias
589
+ salience_bias = self._compute_salience_bias(normed, pos_feats, n_prev, n_curr, n_next)
590
+
591
+ # Combine asymmetric mask + salience bias
592
+ # attn_mask: [total, total], salience_bias: [total, total]
593
+ combined_mask = attn_mask + salience_bias # [total, total]
594
+ # Expand for SDPA: [1, 1, total, total] (broadcast over batch and heads)
595
+ combined_mask = combined_mask.unsqueeze(0).unsqueeze(0)
596
+
597
+ # SDPA attention
598
+ attn_out = F.scaled_dot_product_attention(q, k, v, attn_mask=combined_mask)
599
+ # [1, num_heads, total, head_dim] -> [total, D]
600
+ attn_out = attn_out.squeeze(0).transpose(0, 1).contiguous().view(total, -1)
601
+
602
+ # Residual + projection
603
+ triplet_tokens = triplet_tokens + self.proj(attn_out)
604
+
605
+ # --- FFN ---
606
+ triplet_tokens = triplet_tokens + self.fc2(self.act(self.fc1(self.norm2(triplet_tokens))))
607
+
608
+ return triplet_tokens
609
+
610
+
611
+ # ---------------------------------------------------------------------------
612
+ # DocSEAM module (stack of DocSEAMBlock layers)
613
+ # ---------------------------------------------------------------------------
614
+
615
+ class DocSEAM(nn.Module):
616
+ """Triplet-Context Encoder with salience-gated cross-page Attention.
617
+
618
+ Operates on post-merger vision tokens. For each page, builds a triplet
619
+ [Z_{p-1}, Z_p, Z_{p+1}], runs stacked DocSEAMBlock layers, and returns
620
+ only the enriched center page tokens E_p.
621
+
622
+ Args:
623
+ hidden_size: token dimension (post-merger = LLM hidden_size).
624
+ num_heads: attention heads.
625
+ intermediate_size: FFN inner dimension.
626
+ num_layers: number of stacked DocSEAM layers (default 2).
627
+ cap_frac: CAP_FRAC for salience gate (default 0.20).
628
+ proj_init_std: init std for output projections (0 = zero-init).
629
+ activation: FFN activation name.
630
+ """
631
+
632
+ def __init__(
633
+ self,
634
+ hidden_size: int = 2560,
635
+ num_heads: int = 16,
636
+ intermediate_size: int = 4096,
637
+ num_layers: int = 2,
638
+ cap_frac: float = 0.20,
639
+ proj_init_std: float = 0.0,
640
+ activation: str = "gelu_pytorch_tanh",
641
+ ):
642
+ super().__init__()
643
+ self.hidden_size = hidden_size
644
+ self.num_heads = num_heads
645
+ self.num_layers = num_layers
646
+ self.cap_frac = cap_frac
647
+ self.edge_prior_weight = 0.0
648
+ self.ink_prior_weight = 0.0
649
+ self.frontier_prior_weight = 0.0
650
+ self.gate_l1_weight = 0.0
651
+ self.gate_budget_weight = 0.0
652
+ self.gate_budget_target = 0.20
653
+ self.edge_prior_tau = 0.08
654
+ self.pos_feature_mode = "physical"
655
+ self.margin_penalty_weight = 0.0
656
+ self.use_checkpoint = True
657
+ self.use_reentrant_checkpoint = True
658
+
659
+ self.layers = nn.ModuleList([
660
+ DocSEAMBlock(
661
+ hidden_size=hidden_size,
662
+ num_heads=num_heads,
663
+ intermediate_size=intermediate_size,
664
+ cap_frac=cap_frac,
665
+ proj_init_std=proj_init_std,
666
+ activation=activation,
667
+ )
668
+ for _ in range(num_layers)
669
+ ])
670
+
671
+ @staticmethod
672
+ def _row_band_indices(
673
+ h: int,
674
+ w: int,
675
+ start_row: int,
676
+ end_row: int,
677
+ offset: int,
678
+ device: torch.device,
679
+ ) -> torch.Tensor:
680
+ rows = torch.arange(start_row, end_row, device=device)
681
+ cols = torch.arange(w, device=device)
682
+ return offset + (rows[:, None] * w + cols[None, :]).reshape(-1)
683
+
684
+ @torch.no_grad()
685
+ def _compute_attention_flow(
686
+ self,
687
+ layer: DocSEAMBlock,
688
+ triplet_tokens: torch.Tensor,
689
+ attn_mask: torch.Tensor,
690
+ pos_feats: torch.Tensor,
691
+ n_prev: int,
692
+ n_curr: int,
693
+ n_next: int,
694
+ h_prev: int,
695
+ w_prev: int,
696
+ h_curr: int,
697
+ w_curr: int,
698
+ h_next: int,
699
+ w_next: int,
700
+ ) -> dict[str, torch.Tensor | float | int]:
701
+ """Compute selected cross-page attention-flow slices for diagnostics.
702
+
703
+ This avoids materializing the full [heads, total, total] attention matrix.
704
+ Probabilities are still normalized against all allowed keys, matching SDPA.
705
+ """
706
+ band_frac = float(getattr(self, "attention_flow_band_frac", self.cap_frac))
707
+ chunk_size = int(getattr(self, "attention_flow_chunk_size", 64))
708
+ chunk_size = max(1, chunk_size)
709
+
710
+ prev_band_rows = max(1, int(math.ceil(h_prev * band_frac)))
711
+ curr_band_rows = max(1, int(math.ceil(h_curr * band_frac)))
712
+ next_band_rows = max(1, int(math.ceil(h_next * band_frac)))
713
+
714
+ prev_bottom = self._row_band_indices(
715
+ h_prev, w_prev, h_prev - prev_band_rows, h_prev, 0, triplet_tokens.device
716
+ )
717
+ center_top = self._row_band_indices(
718
+ h_curr, w_curr, 0, curr_band_rows, n_prev, triplet_tokens.device
719
+ )
720
+ center_bottom = self._row_band_indices(
721
+ h_curr, w_curr, h_curr - curr_band_rows, h_curr, n_prev, triplet_tokens.device
722
+ )
723
+ next_top = self._row_band_indices(
724
+ h_next, w_next, 0, next_band_rows, n_prev + n_curr, triplet_tokens.device
725
+ )
726
+
727
+ normed = layer.norm1(triplet_tokens)
728
+ qkv = layer.qkv(normed)
729
+ q = qkv[:, : layer.hidden_size]
730
+ k = qkv[:, layer.hidden_size : 2 * layer.hidden_size]
731
+ q = q.view(-1, layer.num_heads, layer.head_dim).transpose(0, 1).float()
732
+ k = k.view(-1, layer.num_heads, layer.head_dim).transpose(0, 1).float()
733
+
734
+ salience_bias = layer._compute_salience_bias(normed, pos_feats, n_prev, n_curr, n_next)
735
+ combined_mask = (attn_mask + salience_bias).float()
736
+ scale = 1.0 / math.sqrt(layer.head_dim)
737
+
738
+ def summarize(query_idx: torch.Tensor, source_start: int, source_len: int, focus_idx: torch.Tensor):
739
+ source_sum = torch.zeros(source_len, device="cpu", dtype=torch.float64)
740
+ query_mass = torch.zeros(query_idx.numel(), device="cpu", dtype=torch.float64)
741
+ denom = 0
742
+
743
+ source_slice = slice(source_start, source_start + source_len)
744
+ local_focus = (focus_idx - source_start).detach().cpu()
745
+
746
+ for start in range(0, query_idx.numel(), chunk_size):
747
+ q_chunk_idx = query_idx[start : start + chunk_size]
748
+ q_chunk = q[:, q_chunk_idx, :]
749
+ logits = torch.einsum("hqd,hkd->hqk", q_chunk, k) * scale
750
+ logits = logits + combined_mask[q_chunk_idx].unsqueeze(0)
751
+ probs = torch.softmax(logits, dim=-1)
752
+ source_probs = probs[:, :, source_slice]
753
+
754
+ source_sum += source_probs.sum(dim=(0, 1)).detach().cpu().double()
755
+ query_mass[start : start + q_chunk_idx.numel()] = (
756
+ source_probs.sum(dim=-1).mean(dim=0).detach().cpu().double()
757
+ )
758
+ denom += source_probs.shape[0] * source_probs.shape[1]
759
+
760
+ source_avg = source_sum / max(denom, 1)
761
+ source_mass = float(source_avg.sum().item())
762
+ focus_mass = float(source_avg[local_focus].sum().item())
763
+ return source_avg.float(), query_mass.float(), source_mass, focus_mass / max(source_mass, 1e-12)
764
+
765
+ prev_source, center_top_mass, top_to_prev_mass, prev_bottom_frac = summarize(
766
+ center_top, 0, n_prev, prev_bottom
767
+ )
768
+ next_source, center_bottom_mass, bottom_to_next_mass, next_top_frac = summarize(
769
+ center_bottom, n_prev + n_curr, n_next, next_top
770
+ )
771
+
772
+ center_top_map = torch.zeros(n_curr, dtype=torch.float32)
773
+ center_bottom_map = torch.zeros(n_curr, dtype=torch.float32)
774
+ center_top_local = (center_top - n_prev).detach().cpu()
775
+ center_bottom_local = (center_bottom - n_prev).detach().cpu()
776
+ center_top_map[center_top_local] = center_top_mass
777
+ center_bottom_map[center_bottom_local] = center_bottom_mass
778
+
779
+ return {
780
+ "prev_source_from_center_top": prev_source,
781
+ "center_top_to_prev": center_top_map,
782
+ "center_bottom_to_next": center_bottom_map,
783
+ "next_source_from_center_bottom": next_source,
784
+ "top_to_prev_mass": top_to_prev_mass,
785
+ "bottom_to_next_mass": bottom_to_next_mass,
786
+ "prev_mass_bottom_band_frac": prev_bottom_frac,
787
+ "next_mass_top_band_frac": next_top_frac,
788
+ "band_frac": band_frac,
789
+ "prev_band_rows": prev_band_rows,
790
+ "curr_band_rows": curr_band_rows,
791
+ "next_band_rows": next_band_rows,
792
+ }
793
+
794
+ def _process_triplet(
795
+ self,
796
+ z_prev: torch.Tensor,
797
+ z_curr: torch.Tensor,
798
+ z_next: torch.Tensor,
799
+ h_prev: int, w_prev: int,
800
+ h_curr: int, w_curr: int,
801
+ h_next: int, w_next: int,
802
+ detach_neighbors: bool = False,
803
+ record_meta: Optional[dict] = None,
804
+ ink_prev: Optional[torch.Tensor] = None,
805
+ ink_curr: Optional[torch.Tensor] = None,
806
+ ink_next: Optional[torch.Tensor] = None,
807
+ ) -> torch.Tensor:
808
+ """Process a single triplet and return enriched center page tokens.
809
+
810
+ Args:
811
+ z_prev: [M_prev, D] previous page tokens (or self-fallback copy).
812
+ z_curr: [M_curr, D] center page tokens.
813
+ z_next: [M_next, D] next page tokens (or self-fallback copy).
814
+ h_prev, w_prev: grid dims of previous page.
815
+ h_curr, w_curr: grid dims of center page.
816
+ h_next, w_next: grid dims of next page.
817
+ detach_neighbors: if True, detach prev/next features (Stage A).
818
+
819
+ Returns:
820
+ [M_curr, D] enriched center page tokens.
821
+ """
822
+ if detach_neighbors:
823
+ z_prev = z_prev.detach()
824
+ z_next = z_next.detach()
825
+
826
+ n_prev, n_curr, n_next = z_prev.shape[0], z_curr.shape[0], z_next.shape[0]
827
+
828
+ # Concatenate triplet
829
+ triplet = torch.cat([z_prev, z_curr, z_next], dim=0) # [total, D]
830
+
831
+ # Build asymmetric mask (can be cached if sizes repeat)
832
+ attn_mask = build_asymmetric_mask(n_prev, n_curr, n_next, triplet.device, triplet.dtype)
833
+
834
+ # Compute positional features for each page.
835
+ pos_feature_mode = str(getattr(self, "pos_feature_mode", "physical") or "physical").lower()
836
+ if pos_feature_mode == "frontier":
837
+ pf_prev = compute_frontier_pos_features(
838
+ h_prev, w_prev, self.cap_frac, triplet.device, triplet.dtype, ink_prev
839
+ )
840
+ pf_curr = compute_frontier_pos_features(
841
+ h_curr, w_curr, self.cap_frac, triplet.device, triplet.dtype, ink_curr
842
+ )
843
+ pf_next = compute_frontier_pos_features(
844
+ h_next, w_next, self.cap_frac, triplet.device, triplet.dtype, ink_next
845
+ )
846
+ else:
847
+ pf_prev = compute_pos_features(h_prev, w_prev, self.cap_frac, triplet.device, triplet.dtype)
848
+ pf_curr = compute_pos_features(h_curr, w_curr, self.cap_frac, triplet.device, triplet.dtype)
849
+ pf_next = compute_pos_features(h_next, w_next, self.cap_frac, triplet.device, triplet.dtype)
850
+ pos_feats = torch.cat([pf_prev, pf_curr, pf_next], dim=0) # [total, 18]
851
+
852
+ edge_prior_weight = float(getattr(self, "edge_prior_weight", 0.0) or 0.0)
853
+ ink_prior_weight = float(getattr(self, "ink_prior_weight", 0.0) or 0.0)
854
+ frontier_prior_weight = float(getattr(self, "frontier_prior_weight", 0.0) or 0.0)
855
+ gate_l1_weight = float(getattr(self, "gate_l1_weight", 0.0) or 0.0)
856
+ gate_budget_weight = float(getattr(self, "gate_budget_weight", 0.0) or 0.0)
857
+ gate_budget_target = float(getattr(self, "gate_budget_target", 0.20) or 0.20)
858
+ margin_penalty_weight = float(getattr(self, "margin_penalty_weight", 0.0) or 0.0)
859
+ use_aux_loss = self.training and torch.is_grad_enabled() and (
860
+ edge_prior_weight > 0
861
+ or ink_prior_weight > 0
862
+ or frontier_prior_weight > 0
863
+ or gate_l1_weight > 0
864
+ or gate_budget_weight > 0
865
+ or margin_penalty_weight > 0
866
+ )
867
+ if use_aux_loss:
868
+ tau = float(getattr(self, "edge_prior_tau", 0.08) or 0.08)
869
+ prev_top, prev_bottom = compute_edge_targets(h_prev, w_prev, tau, triplet.device, triplet.dtype)
870
+ curr_top, curr_bottom = compute_edge_targets(h_curr, w_curr, tau, triplet.device, triplet.dtype)
871
+ next_top, next_bottom = compute_edge_targets(h_next, w_next, tau, triplet.device, triplet.dtype)
872
+ target_top = torch.cat([prev_top, curr_top, next_top], dim=0)
873
+ target_bottom = torch.cat([prev_bottom, curr_bottom, next_bottom], dim=0)
874
+ if ink_prev is not None and ink_curr is not None and ink_next is not None:
875
+ target_content = torch.cat(
876
+ [
877
+ ink_prev.reshape(-1).detach(),
878
+ ink_curr.reshape(-1).detach(),
879
+ ink_next.reshape(-1).detach(),
880
+ ],
881
+ dim=0,
882
+ ).to(device=triplet.device, dtype=triplet.dtype)
883
+ else:
884
+ target_content = None
885
+
886
+ if frontier_prior_weight > 0 and ink_prev is not None and ink_curr is not None and ink_next is not None:
887
+ prev_frontier_top, prev_frontier_bottom = compute_ink_frontier_targets(
888
+ ink_prev.detach().to(device=triplet.device),
889
+ h_prev,
890
+ w_prev,
891
+ tau,
892
+ )
893
+ curr_frontier_top, curr_frontier_bottom = compute_ink_frontier_targets(
894
+ ink_curr.detach().to(device=triplet.device),
895
+ h_curr,
896
+ w_curr,
897
+ tau,
898
+ )
899
+ next_frontier_top, next_frontier_bottom = compute_ink_frontier_targets(
900
+ ink_next.detach().to(device=triplet.device),
901
+ h_next,
902
+ w_next,
903
+ tau,
904
+ )
905
+ frontier_top = torch.cat(
906
+ [prev_frontier_top, curr_frontier_top, next_frontier_top],
907
+ dim=0,
908
+ ).to(device=triplet.device, dtype=triplet.dtype)
909
+ frontier_bottom = torch.cat(
910
+ [prev_frontier_bottom, curr_frontier_bottom, next_frontier_bottom],
911
+ dim=0,
912
+ ).to(device=triplet.device, dtype=triplet.dtype)
913
+ else:
914
+ frontier_top = None
915
+ frontier_bottom = None
916
+ else:
917
+ target_top = None
918
+ target_bottom = None
919
+ target_content = None
920
+ frontier_top = None
921
+ frontier_bottom = None
922
+
923
+ # Run through DocSEAM layers
924
+ for layer_idx, layer in enumerate(self.layers):
925
+ if use_aux_loss:
926
+ aux_loss = layer.compute_gate_aux_loss(
927
+ triplet,
928
+ pos_feats,
929
+ target_top,
930
+ target_bottom,
931
+ target_content,
932
+ frontier_top,
933
+ frontier_bottom,
934
+ edge_prior_weight=edge_prior_weight,
935
+ ink_prior_weight=ink_prior_weight,
936
+ frontier_prior_weight=frontier_prior_weight,
937
+ gate_l1_weight=gate_l1_weight,
938
+ gate_budget_weight=gate_budget_weight,
939
+ gate_budget_target=gate_budget_target,
940
+ margin_penalty_weight=margin_penalty_weight,
941
+ )
942
+ self._aux_loss = aux_loss if self._aux_loss is None else self._aux_loss + aux_loss
943
+ self._aux_loss_terms += 1
944
+
945
+ if getattr(self, "record_attention_flow", False):
946
+ flow = self._compute_attention_flow(
947
+ layer,
948
+ triplet,
949
+ attn_mask,
950
+ pos_feats,
951
+ n_prev,
952
+ n_curr,
953
+ n_next,
954
+ h_prev,
955
+ w_prev,
956
+ h_curr,
957
+ w_curr,
958
+ h_next,
959
+ w_next,
960
+ )
961
+ meta = {} if record_meta is None else dict(record_meta)
962
+ meta.update({
963
+ "layer": layer_idx,
964
+ "n_prev": n_prev,
965
+ "n_curr": n_curr,
966
+ "n_next": n_next,
967
+ "prev_grid": (h_prev, w_prev),
968
+ "curr_grid": (h_curr, w_curr),
969
+ "next_grid": (h_next, w_next),
970
+ })
971
+ meta.update(flow)
972
+ self._last_attention_flow_records.append(meta)
973
+
974
+ if self.training and torch.is_grad_enabled() and bool(getattr(self, "use_checkpoint", True)):
975
+ from torch.utils.checkpoint import checkpoint
976
+
977
+ if not triplet.requires_grad:
978
+ triplet.requires_grad_(True)
979
+
980
+ triplet = checkpoint(
981
+ layer,
982
+ triplet,
983
+ attn_mask,
984
+ pos_feats,
985
+ n_prev,
986
+ n_curr,
987
+ n_next,
988
+ use_reentrant=bool(getattr(self, "use_reentrant_checkpoint", True)),
989
+ )
990
+ else:
991
+ triplet = layer(triplet, attn_mask, pos_feats, n_prev, n_curr, n_next)
992
+
993
+ if getattr(self, "record_salience", False):
994
+ salience = layer._last_salience
995
+ meta = {} if record_meta is None else dict(record_meta)
996
+ meta.update({
997
+ "layer": layer_idx,
998
+ "n_prev": n_prev,
999
+ "n_curr": n_curr,
1000
+ "n_next": n_next,
1001
+ "prev_grid": (h_prev, w_prev),
1002
+ "curr_grid": (h_curr, w_curr),
1003
+ "next_grid": (h_next, w_next),
1004
+ })
1005
+ meta.update({key: value.detach().cpu() for key, value in salience.items()})
1006
+ self._last_salience_records.append(meta)
1007
+
1008
+ # Extract center page tokens only
1009
+ return triplet[n_prev:n_prev + n_curr]
1010
+
1011
+ def forward(
1012
+ self,
1013
+ page_tokens: list[torch.Tensor],
1014
+ page_grid_dims: list[tuple[int, int]],
1015
+ pages_per_document: list[int],
1016
+ detach_neighbors: bool = False,
1017
+ page_ink_masks: Optional[list[torch.Tensor]] = None,
1018
+ ) -> list[torch.Tensor]:
1019
+ """Process all pages across all documents in the batch.
1020
+
1021
+ Args:
1022
+ page_tokens: list of [M_p, D] tensors, one per page (all docs).
1023
+ page_grid_dims: list of (h_p, w_p) tuples, one per page.
1024
+ pages_per_document: list of page counts per document.
1025
+ detach_neighbors: if True, detach neighbor features (Stage A).
1026
+
1027
+ Returns:
1028
+ list of [M_p, D] enriched page tokens (same order/shapes as input).
1029
+ """
1030
+ if getattr(self, "record_salience", False):
1031
+ self._last_salience_records = []
1032
+ if getattr(self, "record_attention_flow", False):
1033
+ self._last_attention_flow_records = []
1034
+ self._aux_loss = None
1035
+ self._aux_loss_terms = 0
1036
+
1037
+ enriched = []
1038
+ page_idx = 0
1039
+
1040
+ for doc_num_pages in pages_per_document:
1041
+ doc_start = page_idx
1042
+ doc_end = page_idx + doc_num_pages
1043
+
1044
+ for p in range(doc_start, doc_end):
1045
+ # Get current page
1046
+ z_curr = page_tokens[p]
1047
+ h_curr, w_curr = page_grid_dims[p]
1048
+ ink_curr = page_ink_masks[p] if page_ink_masks is not None else None
1049
+
1050
+ # Get previous page (self-fallback if first page of document)
1051
+ if p == doc_start:
1052
+ z_prev = z_curr # self-fallback
1053
+ h_prev, w_prev = h_curr, w_curr
1054
+ ink_prev = ink_curr
1055
+ else:
1056
+ z_prev = page_tokens[p - 1]
1057
+ h_prev, w_prev = page_grid_dims[p - 1]
1058
+ ink_prev = page_ink_masks[p - 1] if page_ink_masks is not None else None
1059
+
1060
+ # Get next page (self-fallback if last page of document)
1061
+ if p == doc_end - 1:
1062
+ z_next = z_curr # self-fallback
1063
+ h_next, w_next = h_curr, w_curr
1064
+ ink_next = ink_curr
1065
+ else:
1066
+ z_next = page_tokens[p + 1]
1067
+ h_next, w_next = page_grid_dims[p + 1]
1068
+ ink_next = page_ink_masks[p + 1] if page_ink_masks is not None else None
1069
+
1070
+ e_p = self._process_triplet(
1071
+ z_prev, z_curr, z_next,
1072
+ h_prev, w_prev,
1073
+ h_curr, w_curr,
1074
+ h_next, w_next,
1075
+ detach_neighbors=detach_neighbors,
1076
+ ink_prev=ink_prev,
1077
+ ink_curr=ink_curr,
1078
+ ink_next=ink_next,
1079
+ record_meta={
1080
+ "doc_start": doc_start,
1081
+ "doc_end": doc_end,
1082
+ "curr_page_index": p,
1083
+ "prev_page_index": p if p == doc_start else p - 1,
1084
+ "next_page_index": p if p == doc_end - 1 else p + 1,
1085
+ "prev_is_self_fallback": p == doc_start,
1086
+ "next_is_self_fallback": p == doc_end - 1,
1087
+ },
1088
+ )
1089
+ enriched.append(e_p)
1090
+
1091
+ page_idx = doc_end
1092
+
1093
+ return enriched
1094
+
1095
+ def get_aux_loss(self) -> Optional[torch.Tensor]:
1096
+ """Return the mean auxiliary gate loss accumulated during the last forward."""
1097
+ if self._aux_loss is None or self._aux_loss_terms <= 0:
1098
+ return None
1099
+
1100
+ return self._aux_loss / float(self._aux_loss_terms)
1101
+
1102
+ @torch.no_grad()
1103
+ def clone_init_from_vision_block(self, vision_block: nn.Module):
1104
+ """Clone QKV and FFN first-linear weights from a Qwen3.5 vision block.
1105
+
1106
+ This ensures DocSEAM starts from a good feature space. The output
1107
+ projections remain at zero-init so the module is an exact no-op.
1108
+
1109
+ Args:
1110
+ vision_block: a Qwen3_5VisionBlock with .attn.qkv, .mlp.linear_fc1,
1111
+ .norm1, .norm2.
1112
+ """
1113
+ def _copy(dst, src):
1114
+ dst.data.copy_(src.data.to(dst.dtype))
1115
+
1116
+ def _copy_norm(dst_norm, src_norm):
1117
+ if hasattr(src_norm, "weight") and src_norm.weight is not None:
1118
+ _copy(dst_norm.weight, src_norm.weight)
1119
+ if hasattr(dst_norm, "bias") and dst_norm.bias is not None:
1120
+ if hasattr(src_norm, "bias") and src_norm.bias is not None:
1121
+ _copy(dst_norm.bias, src_norm.bias)
1122
+ else:
1123
+ dst_norm.bias.data.zero_()
1124
+
1125
+ for layer in self.layers:
1126
+ # Clone QKV from vision block's fused qkv
1127
+ _copy(layer.qkv.weight, vision_block.attn.qkv.weight)
1128
+ if vision_block.attn.qkv.bias is not None:
1129
+ _copy(layer.qkv.bias, vision_block.attn.qkv.bias)
1130
+ else:
1131
+ layer.qkv.bias.data.zero_()
1132
+
1133
+ # Clone FFN first linear
1134
+ _copy(layer.fc1.weight, vision_block.mlp.linear_fc1.weight)
1135
+ if vision_block.mlp.linear_fc1.bias is not None:
1136
+ _copy(layer.fc1.bias, vision_block.mlp.linear_fc1.bias)
1137
+ else:
1138
+ layer.fc1.bias.data.zero_()
1139
+
1140
+ # Clone norms
1141
+ _copy_norm(layer.norm1, vision_block.norm1)
1142
+ _copy_norm(layer.norm2, vision_block.norm2)
examples/attention/1706.03762v7_page-0004.jpg ADDED

Git LFS Details

  • SHA256: 5b2b9508108c4572e40d9779115b64604c13aeda9dee8ebba8a98990960badb4
  • Pointer size: 131 Bytes
  • Size of remote file: 615 kB
examples/attention/1706.03762v7_page-0005.jpg ADDED

Git LFS Details

  • SHA256: 8499f47a4531062eef94bbf9fc7b60de271b1129c4034de0e15a3f92643f21d4
  • Pointer size: 131 Bytes
  • Size of remote file: 700 kB
examples/attention/1706.03762v7_page-0006.jpg ADDED

Git LFS Details

  • SHA256: 829efd26bc549de53b44b794a18d7c7d7b28bcdace1abd8f549e9d4783b679c0
  • Pointer size: 131 Bytes
  • Size of remote file: 783 kB
examples/attention/question.jsonl ADDED
@@ -0,0 +1 @@
 
 
1
+ {"question_id": "attention_heads", "images": ["1706.03762v7_page-0004.jpg", "1706.03762v7_page-0005.jpg", "1706.03762v7_page-0006.jpg"], "num_images": 3, "user": "How many parallel attention heads are used in the model? Answer with only the number."}
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_sample": false,
3
+ "eos_token_id": 248046,
4
+ "pad_token_id": 248044,
5
+ "transformers_version": "5.6.0",
6
+ "use_cache": true
7
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dd63614f1dc80dce2d83be3f3e69af1f8a0ebc8add9b8e0abf3910f563e44344
3
+ size 2034237568
model-00002-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:524db8415bd82ff79dfbe81441c4f723a92f06ee6a5213d520b1aec8bc7217b1
3
+ size 3999615808
model-00003-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a85f2e08c9254bb47c3e265858cb9aa39afdfb6938a7c224ec73c373deecb85d
3
+ size 3997274128
model-00004-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c93f5466a3d54a8d5015e94091e6d55bdb7d9768f392206c017cc2652ae8c8d0
3
+ size 3997290904
model-00005-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2defde40803ec3cde5c3ee38e5d13e66078f26a8d47dd908f3cf987e9ce77d2c
3
+ size 3980131432
model-00006-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4b2ea24b6c4c889868af77ad7515ce06f6cd45a49e67f3eb71898a5f9614deb7
3
+ size 1281430888
model.safetensors.index.json ADDED
@@ -0,0 +1,824 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_parameters": 9644940536,
4
+ "total_size": 19289881072
5
+ },
6
+ "weight_map": {
7
+ "lm_head.weight": "model-00001-of-00006.safetensors",
8
+ "model.language_model.embed_tokens.weight": "model-00002-of-00006.safetensors",
9
+ "model.language_model.layers.0.input_layernorm.weight": "model-00002-of-00006.safetensors",
10
+ "model.language_model.layers.0.linear_attn.A_log": "model-00002-of-00006.safetensors",
11
+ "model.language_model.layers.0.linear_attn.conv1d.weight": "model-00002-of-00006.safetensors",
12
+ "model.language_model.layers.0.linear_attn.dt_bias": "model-00002-of-00006.safetensors",
13
+ "model.language_model.layers.0.linear_attn.in_proj_a.weight": "model-00002-of-00006.safetensors",
14
+ "model.language_model.layers.0.linear_attn.in_proj_b.weight": "model-00002-of-00006.safetensors",
15
+ "model.language_model.layers.0.linear_attn.in_proj_qkv.weight": "model-00002-of-00006.safetensors",
16
+ "model.language_model.layers.0.linear_attn.in_proj_z.weight": "model-00002-of-00006.safetensors",
17
+ "model.language_model.layers.0.linear_attn.norm.weight": "model-00002-of-00006.safetensors",
18
+ "model.language_model.layers.0.linear_attn.out_proj.weight": "model-00002-of-00006.safetensors",
19
+ "model.language_model.layers.0.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
20
+ "model.language_model.layers.0.mlp.gate_proj.weight": "model-00002-of-00006.safetensors",
21
+ "model.language_model.layers.0.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
22
+ "model.language_model.layers.0.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
23
+ "model.language_model.layers.1.input_layernorm.weight": "model-00002-of-00006.safetensors",
24
+ "model.language_model.layers.1.linear_attn.A_log": "model-00002-of-00006.safetensors",
25
+ "model.language_model.layers.1.linear_attn.conv1d.weight": "model-00002-of-00006.safetensors",
26
+ "model.language_model.layers.1.linear_attn.dt_bias": "model-00002-of-00006.safetensors",
27
+ "model.language_model.layers.1.linear_attn.in_proj_a.weight": "model-00002-of-00006.safetensors",
28
+ "model.language_model.layers.1.linear_attn.in_proj_b.weight": "model-00002-of-00006.safetensors",
29
+ "model.language_model.layers.1.linear_attn.in_proj_qkv.weight": "model-00002-of-00006.safetensors",
30
+ "model.language_model.layers.1.linear_attn.in_proj_z.weight": "model-00002-of-00006.safetensors",
31
+ "model.language_model.layers.1.linear_attn.norm.weight": "model-00002-of-00006.safetensors",
32
+ "model.language_model.layers.1.linear_attn.out_proj.weight": "model-00002-of-00006.safetensors",
33
+ "model.language_model.layers.1.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
34
+ "model.language_model.layers.1.mlp.gate_proj.weight": "model-00002-of-00006.safetensors",
35
+ "model.language_model.layers.1.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
36
+ "model.language_model.layers.1.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
37
+ "model.language_model.layers.10.input_layernorm.weight": "model-00003-of-00006.safetensors",
38
+ "model.language_model.layers.10.linear_attn.A_log": "model-00003-of-00006.safetensors",
39
+ "model.language_model.layers.10.linear_attn.conv1d.weight": "model-00003-of-00006.safetensors",
40
+ "model.language_model.layers.10.linear_attn.dt_bias": "model-00003-of-00006.safetensors",
41
+ "model.language_model.layers.10.linear_attn.in_proj_a.weight": "model-00003-of-00006.safetensors",
42
+ "model.language_model.layers.10.linear_attn.in_proj_b.weight": "model-00003-of-00006.safetensors",
43
+ "model.language_model.layers.10.linear_attn.in_proj_qkv.weight": "model-00003-of-00006.safetensors",
44
+ "model.language_model.layers.10.linear_attn.in_proj_z.weight": "model-00003-of-00006.safetensors",
45
+ "model.language_model.layers.10.linear_attn.norm.weight": "model-00003-of-00006.safetensors",
46
+ "model.language_model.layers.10.linear_attn.out_proj.weight": "model-00003-of-00006.safetensors",
47
+ "model.language_model.layers.10.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
48
+ "model.language_model.layers.10.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
49
+ "model.language_model.layers.10.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
50
+ "model.language_model.layers.10.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
51
+ "model.language_model.layers.11.input_layernorm.weight": "model-00003-of-00006.safetensors",
52
+ "model.language_model.layers.11.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
53
+ "model.language_model.layers.11.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
54
+ "model.language_model.layers.11.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
55
+ "model.language_model.layers.11.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
56
+ "model.language_model.layers.11.self_attn.k_norm.weight": "model-00003-of-00006.safetensors",
57
+ "model.language_model.layers.11.self_attn.k_proj.weight": "model-00003-of-00006.safetensors",
58
+ "model.language_model.layers.11.self_attn.o_proj.weight": "model-00003-of-00006.safetensors",
59
+ "model.language_model.layers.11.self_attn.q_norm.weight": "model-00003-of-00006.safetensors",
60
+ "model.language_model.layers.11.self_attn.q_proj.weight": "model-00003-of-00006.safetensors",
61
+ "model.language_model.layers.11.self_attn.v_proj.weight": "model-00003-of-00006.safetensors",
62
+ "model.language_model.layers.12.input_layernorm.weight": "model-00003-of-00006.safetensors",
63
+ "model.language_model.layers.12.linear_attn.A_log": "model-00003-of-00006.safetensors",
64
+ "model.language_model.layers.12.linear_attn.conv1d.weight": "model-00003-of-00006.safetensors",
65
+ "model.language_model.layers.12.linear_attn.dt_bias": "model-00003-of-00006.safetensors",
66
+ "model.language_model.layers.12.linear_attn.in_proj_a.weight": "model-00003-of-00006.safetensors",
67
+ "model.language_model.layers.12.linear_attn.in_proj_b.weight": "model-00003-of-00006.safetensors",
68
+ "model.language_model.layers.12.linear_attn.in_proj_qkv.weight": "model-00003-of-00006.safetensors",
69
+ "model.language_model.layers.12.linear_attn.in_proj_z.weight": "model-00003-of-00006.safetensors",
70
+ "model.language_model.layers.12.linear_attn.norm.weight": "model-00003-of-00006.safetensors",
71
+ "model.language_model.layers.12.linear_attn.out_proj.weight": "model-00003-of-00006.safetensors",
72
+ "model.language_model.layers.12.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
73
+ "model.language_model.layers.12.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
74
+ "model.language_model.layers.12.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
75
+ "model.language_model.layers.12.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
76
+ "model.language_model.layers.13.input_layernorm.weight": "model-00003-of-00006.safetensors",
77
+ "model.language_model.layers.13.linear_attn.A_log": "model-00003-of-00006.safetensors",
78
+ "model.language_model.layers.13.linear_attn.conv1d.weight": "model-00003-of-00006.safetensors",
79
+ "model.language_model.layers.13.linear_attn.dt_bias": "model-00003-of-00006.safetensors",
80
+ "model.language_model.layers.13.linear_attn.in_proj_a.weight": "model-00003-of-00006.safetensors",
81
+ "model.language_model.layers.13.linear_attn.in_proj_b.weight": "model-00003-of-00006.safetensors",
82
+ "model.language_model.layers.13.linear_attn.in_proj_qkv.weight": "model-00003-of-00006.safetensors",
83
+ "model.language_model.layers.13.linear_attn.in_proj_z.weight": "model-00003-of-00006.safetensors",
84
+ "model.language_model.layers.13.linear_attn.norm.weight": "model-00003-of-00006.safetensors",
85
+ "model.language_model.layers.13.linear_attn.out_proj.weight": "model-00003-of-00006.safetensors",
86
+ "model.language_model.layers.13.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
87
+ "model.language_model.layers.13.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
88
+ "model.language_model.layers.13.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
89
+ "model.language_model.layers.13.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
90
+ "model.language_model.layers.14.input_layernorm.weight": "model-00004-of-00006.safetensors",
91
+ "model.language_model.layers.14.linear_attn.A_log": "model-00004-of-00006.safetensors",
92
+ "model.language_model.layers.14.linear_attn.conv1d.weight": "model-00004-of-00006.safetensors",
93
+ "model.language_model.layers.14.linear_attn.dt_bias": "model-00004-of-00006.safetensors",
94
+ "model.language_model.layers.14.linear_attn.in_proj_a.weight": "model-00004-of-00006.safetensors",
95
+ "model.language_model.layers.14.linear_attn.in_proj_b.weight": "model-00004-of-00006.safetensors",
96
+ "model.language_model.layers.14.linear_attn.in_proj_qkv.weight": "model-00004-of-00006.safetensors",
97
+ "model.language_model.layers.14.linear_attn.in_proj_z.weight": "model-00004-of-00006.safetensors",
98
+ "model.language_model.layers.14.linear_attn.norm.weight": "model-00004-of-00006.safetensors",
99
+ "model.language_model.layers.14.linear_attn.out_proj.weight": "model-00004-of-00006.safetensors",
100
+ "model.language_model.layers.14.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
101
+ "model.language_model.layers.14.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
102
+ "model.language_model.layers.14.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
103
+ "model.language_model.layers.14.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
104
+ "model.language_model.layers.15.input_layernorm.weight": "model-00004-of-00006.safetensors",
105
+ "model.language_model.layers.15.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
106
+ "model.language_model.layers.15.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
107
+ "model.language_model.layers.15.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
108
+ "model.language_model.layers.15.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
109
+ "model.language_model.layers.15.self_attn.k_norm.weight": "model-00004-of-00006.safetensors",
110
+ "model.language_model.layers.15.self_attn.k_proj.weight": "model-00004-of-00006.safetensors",
111
+ "model.language_model.layers.15.self_attn.o_proj.weight": "model-00004-of-00006.safetensors",
112
+ "model.language_model.layers.15.self_attn.q_norm.weight": "model-00004-of-00006.safetensors",
113
+ "model.language_model.layers.15.self_attn.q_proj.weight": "model-00004-of-00006.safetensors",
114
+ "model.language_model.layers.15.self_attn.v_proj.weight": "model-00004-of-00006.safetensors",
115
+ "model.language_model.layers.16.input_layernorm.weight": "model-00004-of-00006.safetensors",
116
+ "model.language_model.layers.16.linear_attn.A_log": "model-00004-of-00006.safetensors",
117
+ "model.language_model.layers.16.linear_attn.conv1d.weight": "model-00004-of-00006.safetensors",
118
+ "model.language_model.layers.16.linear_attn.dt_bias": "model-00004-of-00006.safetensors",
119
+ "model.language_model.layers.16.linear_attn.in_proj_a.weight": "model-00004-of-00006.safetensors",
120
+ "model.language_model.layers.16.linear_attn.in_proj_b.weight": "model-00004-of-00006.safetensors",
121
+ "model.language_model.layers.16.linear_attn.in_proj_qkv.weight": "model-00004-of-00006.safetensors",
122
+ "model.language_model.layers.16.linear_attn.in_proj_z.weight": "model-00004-of-00006.safetensors",
123
+ "model.language_model.layers.16.linear_attn.norm.weight": "model-00004-of-00006.safetensors",
124
+ "model.language_model.layers.16.linear_attn.out_proj.weight": "model-00004-of-00006.safetensors",
125
+ "model.language_model.layers.16.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
126
+ "model.language_model.layers.16.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
127
+ "model.language_model.layers.16.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
128
+ "model.language_model.layers.16.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
129
+ "model.language_model.layers.17.input_layernorm.weight": "model-00004-of-00006.safetensors",
130
+ "model.language_model.layers.17.linear_attn.A_log": "model-00004-of-00006.safetensors",
131
+ "model.language_model.layers.17.linear_attn.conv1d.weight": "model-00004-of-00006.safetensors",
132
+ "model.language_model.layers.17.linear_attn.dt_bias": "model-00004-of-00006.safetensors",
133
+ "model.language_model.layers.17.linear_attn.in_proj_a.weight": "model-00004-of-00006.safetensors",
134
+ "model.language_model.layers.17.linear_attn.in_proj_b.weight": "model-00004-of-00006.safetensors",
135
+ "model.language_model.layers.17.linear_attn.in_proj_qkv.weight": "model-00004-of-00006.safetensors",
136
+ "model.language_model.layers.17.linear_attn.in_proj_z.weight": "model-00004-of-00006.safetensors",
137
+ "model.language_model.layers.17.linear_attn.norm.weight": "model-00004-of-00006.safetensors",
138
+ "model.language_model.layers.17.linear_attn.out_proj.weight": "model-00004-of-00006.safetensors",
139
+ "model.language_model.layers.17.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
140
+ "model.language_model.layers.17.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
141
+ "model.language_model.layers.17.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
142
+ "model.language_model.layers.17.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
143
+ "model.language_model.layers.18.input_layernorm.weight": "model-00004-of-00006.safetensors",
144
+ "model.language_model.layers.18.linear_attn.A_log": "model-00004-of-00006.safetensors",
145
+ "model.language_model.layers.18.linear_attn.conv1d.weight": "model-00004-of-00006.safetensors",
146
+ "model.language_model.layers.18.linear_attn.dt_bias": "model-00004-of-00006.safetensors",
147
+ "model.language_model.layers.18.linear_attn.in_proj_a.weight": "model-00004-of-00006.safetensors",
148
+ "model.language_model.layers.18.linear_attn.in_proj_b.weight": "model-00004-of-00006.safetensors",
149
+ "model.language_model.layers.18.linear_attn.in_proj_qkv.weight": "model-00004-of-00006.safetensors",
150
+ "model.language_model.layers.18.linear_attn.in_proj_z.weight": "model-00004-of-00006.safetensors",
151
+ "model.language_model.layers.18.linear_attn.norm.weight": "model-00004-of-00006.safetensors",
152
+ "model.language_model.layers.18.linear_attn.out_proj.weight": "model-00004-of-00006.safetensors",
153
+ "model.language_model.layers.18.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
154
+ "model.language_model.layers.18.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
155
+ "model.language_model.layers.18.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
156
+ "model.language_model.layers.18.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
157
+ "model.language_model.layers.19.input_layernorm.weight": "model-00004-of-00006.safetensors",
158
+ "model.language_model.layers.19.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
159
+ "model.language_model.layers.19.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
160
+ "model.language_model.layers.19.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
161
+ "model.language_model.layers.19.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
162
+ "model.language_model.layers.19.self_attn.k_norm.weight": "model-00004-of-00006.safetensors",
163
+ "model.language_model.layers.19.self_attn.k_proj.weight": "model-00004-of-00006.safetensors",
164
+ "model.language_model.layers.19.self_attn.o_proj.weight": "model-00004-of-00006.safetensors",
165
+ "model.language_model.layers.19.self_attn.q_norm.weight": "model-00004-of-00006.safetensors",
166
+ "model.language_model.layers.19.self_attn.q_proj.weight": "model-00004-of-00006.safetensors",
167
+ "model.language_model.layers.19.self_attn.v_proj.weight": "model-00004-of-00006.safetensors",
168
+ "model.language_model.layers.2.input_layernorm.weight": "model-00002-of-00006.safetensors",
169
+ "model.language_model.layers.2.linear_attn.A_log": "model-00002-of-00006.safetensors",
170
+ "model.language_model.layers.2.linear_attn.conv1d.weight": "model-00002-of-00006.safetensors",
171
+ "model.language_model.layers.2.linear_attn.dt_bias": "model-00002-of-00006.safetensors",
172
+ "model.language_model.layers.2.linear_attn.in_proj_a.weight": "model-00002-of-00006.safetensors",
173
+ "model.language_model.layers.2.linear_attn.in_proj_b.weight": "model-00002-of-00006.safetensors",
174
+ "model.language_model.layers.2.linear_attn.in_proj_qkv.weight": "model-00002-of-00006.safetensors",
175
+ "model.language_model.layers.2.linear_attn.in_proj_z.weight": "model-00002-of-00006.safetensors",
176
+ "model.language_model.layers.2.linear_attn.norm.weight": "model-00002-of-00006.safetensors",
177
+ "model.language_model.layers.2.linear_attn.out_proj.weight": "model-00002-of-00006.safetensors",
178
+ "model.language_model.layers.2.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
179
+ "model.language_model.layers.2.mlp.gate_proj.weight": "model-00002-of-00006.safetensors",
180
+ "model.language_model.layers.2.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
181
+ "model.language_model.layers.2.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
182
+ "model.language_model.layers.20.input_layernorm.weight": "model-00004-of-00006.safetensors",
183
+ "model.language_model.layers.20.linear_attn.A_log": "model-00004-of-00006.safetensors",
184
+ "model.language_model.layers.20.linear_attn.conv1d.weight": "model-00004-of-00006.safetensors",
185
+ "model.language_model.layers.20.linear_attn.dt_bias": "model-00004-of-00006.safetensors",
186
+ "model.language_model.layers.20.linear_attn.in_proj_a.weight": "model-00004-of-00006.safetensors",
187
+ "model.language_model.layers.20.linear_attn.in_proj_b.weight": "model-00004-of-00006.safetensors",
188
+ "model.language_model.layers.20.linear_attn.in_proj_qkv.weight": "model-00004-of-00006.safetensors",
189
+ "model.language_model.layers.20.linear_attn.in_proj_z.weight": "model-00004-of-00006.safetensors",
190
+ "model.language_model.layers.20.linear_attn.norm.weight": "model-00004-of-00006.safetensors",
191
+ "model.language_model.layers.20.linear_attn.out_proj.weight": "model-00004-of-00006.safetensors",
192
+ "model.language_model.layers.20.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
193
+ "model.language_model.layers.20.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
194
+ "model.language_model.layers.20.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
195
+ "model.language_model.layers.20.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
196
+ "model.language_model.layers.21.input_layernorm.weight": "model-00004-of-00006.safetensors",
197
+ "model.language_model.layers.21.linear_attn.A_log": "model-00004-of-00006.safetensors",
198
+ "model.language_model.layers.21.linear_attn.conv1d.weight": "model-00004-of-00006.safetensors",
199
+ "model.language_model.layers.21.linear_attn.dt_bias": "model-00004-of-00006.safetensors",
200
+ "model.language_model.layers.21.linear_attn.in_proj_a.weight": "model-00004-of-00006.safetensors",
201
+ "model.language_model.layers.21.linear_attn.in_proj_b.weight": "model-00004-of-00006.safetensors",
202
+ "model.language_model.layers.21.linear_attn.in_proj_qkv.weight": "model-00004-of-00006.safetensors",
203
+ "model.language_model.layers.21.linear_attn.in_proj_z.weight": "model-00004-of-00006.safetensors",
204
+ "model.language_model.layers.21.linear_attn.norm.weight": "model-00004-of-00006.safetensors",
205
+ "model.language_model.layers.21.linear_attn.out_proj.weight": "model-00004-of-00006.safetensors",
206
+ "model.language_model.layers.21.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
207
+ "model.language_model.layers.21.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
208
+ "model.language_model.layers.21.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
209
+ "model.language_model.layers.21.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
210
+ "model.language_model.layers.22.input_layernorm.weight": "model-00004-of-00006.safetensors",
211
+ "model.language_model.layers.22.linear_attn.A_log": "model-00004-of-00006.safetensors",
212
+ "model.language_model.layers.22.linear_attn.conv1d.weight": "model-00004-of-00006.safetensors",
213
+ "model.language_model.layers.22.linear_attn.dt_bias": "model-00004-of-00006.safetensors",
214
+ "model.language_model.layers.22.linear_attn.in_proj_a.weight": "model-00004-of-00006.safetensors",
215
+ "model.language_model.layers.22.linear_attn.in_proj_b.weight": "model-00004-of-00006.safetensors",
216
+ "model.language_model.layers.22.linear_attn.in_proj_qkv.weight": "model-00004-of-00006.safetensors",
217
+ "model.language_model.layers.22.linear_attn.in_proj_z.weight": "model-00004-of-00006.safetensors",
218
+ "model.language_model.layers.22.linear_attn.norm.weight": "model-00004-of-00006.safetensors",
219
+ "model.language_model.layers.22.linear_attn.out_proj.weight": "model-00004-of-00006.safetensors",
220
+ "model.language_model.layers.22.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
221
+ "model.language_model.layers.22.mlp.gate_proj.weight": "model-00004-of-00006.safetensors",
222
+ "model.language_model.layers.22.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
223
+ "model.language_model.layers.22.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
224
+ "model.language_model.layers.23.input_layernorm.weight": "model-00004-of-00006.safetensors",
225
+ "model.language_model.layers.23.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
226
+ "model.language_model.layers.23.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
227
+ "model.language_model.layers.23.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
228
+ "model.language_model.layers.23.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
229
+ "model.language_model.layers.23.self_attn.k_norm.weight": "model-00005-of-00006.safetensors",
230
+ "model.language_model.layers.23.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
231
+ "model.language_model.layers.23.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
232
+ "model.language_model.layers.23.self_attn.q_norm.weight": "model-00005-of-00006.safetensors",
233
+ "model.language_model.layers.23.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
234
+ "model.language_model.layers.23.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
235
+ "model.language_model.layers.24.input_layernorm.weight": "model-00005-of-00006.safetensors",
236
+ "model.language_model.layers.24.linear_attn.A_log": "model-00005-of-00006.safetensors",
237
+ "model.language_model.layers.24.linear_attn.conv1d.weight": "model-00005-of-00006.safetensors",
238
+ "model.language_model.layers.24.linear_attn.dt_bias": "model-00005-of-00006.safetensors",
239
+ "model.language_model.layers.24.linear_attn.in_proj_a.weight": "model-00005-of-00006.safetensors",
240
+ "model.language_model.layers.24.linear_attn.in_proj_b.weight": "model-00005-of-00006.safetensors",
241
+ "model.language_model.layers.24.linear_attn.in_proj_qkv.weight": "model-00005-of-00006.safetensors",
242
+ "model.language_model.layers.24.linear_attn.in_proj_z.weight": "model-00005-of-00006.safetensors",
243
+ "model.language_model.layers.24.linear_attn.norm.weight": "model-00005-of-00006.safetensors",
244
+ "model.language_model.layers.24.linear_attn.out_proj.weight": "model-00005-of-00006.safetensors",
245
+ "model.language_model.layers.24.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
246
+ "model.language_model.layers.24.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
247
+ "model.language_model.layers.24.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
248
+ "model.language_model.layers.24.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
249
+ "model.language_model.layers.25.input_layernorm.weight": "model-00005-of-00006.safetensors",
250
+ "model.language_model.layers.25.linear_attn.A_log": "model-00005-of-00006.safetensors",
251
+ "model.language_model.layers.25.linear_attn.conv1d.weight": "model-00005-of-00006.safetensors",
252
+ "model.language_model.layers.25.linear_attn.dt_bias": "model-00005-of-00006.safetensors",
253
+ "model.language_model.layers.25.linear_attn.in_proj_a.weight": "model-00005-of-00006.safetensors",
254
+ "model.language_model.layers.25.linear_attn.in_proj_b.weight": "model-00005-of-00006.safetensors",
255
+ "model.language_model.layers.25.linear_attn.in_proj_qkv.weight": "model-00005-of-00006.safetensors",
256
+ "model.language_model.layers.25.linear_attn.in_proj_z.weight": "model-00005-of-00006.safetensors",
257
+ "model.language_model.layers.25.linear_attn.norm.weight": "model-00005-of-00006.safetensors",
258
+ "model.language_model.layers.25.linear_attn.out_proj.weight": "model-00005-of-00006.safetensors",
259
+ "model.language_model.layers.25.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
260
+ "model.language_model.layers.25.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
261
+ "model.language_model.layers.25.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
262
+ "model.language_model.layers.25.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
263
+ "model.language_model.layers.26.input_layernorm.weight": "model-00005-of-00006.safetensors",
264
+ "model.language_model.layers.26.linear_attn.A_log": "model-00005-of-00006.safetensors",
265
+ "model.language_model.layers.26.linear_attn.conv1d.weight": "model-00005-of-00006.safetensors",
266
+ "model.language_model.layers.26.linear_attn.dt_bias": "model-00005-of-00006.safetensors",
267
+ "model.language_model.layers.26.linear_attn.in_proj_a.weight": "model-00005-of-00006.safetensors",
268
+ "model.language_model.layers.26.linear_attn.in_proj_b.weight": "model-00005-of-00006.safetensors",
269
+ "model.language_model.layers.26.linear_attn.in_proj_qkv.weight": "model-00005-of-00006.safetensors",
270
+ "model.language_model.layers.26.linear_attn.in_proj_z.weight": "model-00005-of-00006.safetensors",
271
+ "model.language_model.layers.26.linear_attn.norm.weight": "model-00005-of-00006.safetensors",
272
+ "model.language_model.layers.26.linear_attn.out_proj.weight": "model-00005-of-00006.safetensors",
273
+ "model.language_model.layers.26.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
274
+ "model.language_model.layers.26.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
275
+ "model.language_model.layers.26.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
276
+ "model.language_model.layers.26.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
277
+ "model.language_model.layers.27.input_layernorm.weight": "model-00005-of-00006.safetensors",
278
+ "model.language_model.layers.27.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
279
+ "model.language_model.layers.27.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
280
+ "model.language_model.layers.27.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
281
+ "model.language_model.layers.27.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
282
+ "model.language_model.layers.27.self_attn.k_norm.weight": "model-00005-of-00006.safetensors",
283
+ "model.language_model.layers.27.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
284
+ "model.language_model.layers.27.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
285
+ "model.language_model.layers.27.self_attn.q_norm.weight": "model-00005-of-00006.safetensors",
286
+ "model.language_model.layers.27.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
287
+ "model.language_model.layers.27.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
288
+ "model.language_model.layers.28.input_layernorm.weight": "model-00005-of-00006.safetensors",
289
+ "model.language_model.layers.28.linear_attn.A_log": "model-00005-of-00006.safetensors",
290
+ "model.language_model.layers.28.linear_attn.conv1d.weight": "model-00005-of-00006.safetensors",
291
+ "model.language_model.layers.28.linear_attn.dt_bias": "model-00005-of-00006.safetensors",
292
+ "model.language_model.layers.28.linear_attn.in_proj_a.weight": "model-00005-of-00006.safetensors",
293
+ "model.language_model.layers.28.linear_attn.in_proj_b.weight": "model-00005-of-00006.safetensors",
294
+ "model.language_model.layers.28.linear_attn.in_proj_qkv.weight": "model-00005-of-00006.safetensors",
295
+ "model.language_model.layers.28.linear_attn.in_proj_z.weight": "model-00005-of-00006.safetensors",
296
+ "model.language_model.layers.28.linear_attn.norm.weight": "model-00005-of-00006.safetensors",
297
+ "model.language_model.layers.28.linear_attn.out_proj.weight": "model-00005-of-00006.safetensors",
298
+ "model.language_model.layers.28.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
299
+ "model.language_model.layers.28.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
300
+ "model.language_model.layers.28.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
301
+ "model.language_model.layers.28.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
302
+ "model.language_model.layers.29.input_layernorm.weight": "model-00005-of-00006.safetensors",
303
+ "model.language_model.layers.29.linear_attn.A_log": "model-00005-of-00006.safetensors",
304
+ "model.language_model.layers.29.linear_attn.conv1d.weight": "model-00005-of-00006.safetensors",
305
+ "model.language_model.layers.29.linear_attn.dt_bias": "model-00005-of-00006.safetensors",
306
+ "model.language_model.layers.29.linear_attn.in_proj_a.weight": "model-00005-of-00006.safetensors",
307
+ "model.language_model.layers.29.linear_attn.in_proj_b.weight": "model-00005-of-00006.safetensors",
308
+ "model.language_model.layers.29.linear_attn.in_proj_qkv.weight": "model-00005-of-00006.safetensors",
309
+ "model.language_model.layers.29.linear_attn.in_proj_z.weight": "model-00005-of-00006.safetensors",
310
+ "model.language_model.layers.29.linear_attn.norm.weight": "model-00005-of-00006.safetensors",
311
+ "model.language_model.layers.29.linear_attn.out_proj.weight": "model-00005-of-00006.safetensors",
312
+ "model.language_model.layers.29.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
313
+ "model.language_model.layers.29.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
314
+ "model.language_model.layers.29.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
315
+ "model.language_model.layers.29.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
316
+ "model.language_model.layers.3.input_layernorm.weight": "model-00002-of-00006.safetensors",
317
+ "model.language_model.layers.3.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
318
+ "model.language_model.layers.3.mlp.gate_proj.weight": "model-00002-of-00006.safetensors",
319
+ "model.language_model.layers.3.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
320
+ "model.language_model.layers.3.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
321
+ "model.language_model.layers.3.self_attn.k_norm.weight": "model-00002-of-00006.safetensors",
322
+ "model.language_model.layers.3.self_attn.k_proj.weight": "model-00002-of-00006.safetensors",
323
+ "model.language_model.layers.3.self_attn.o_proj.weight": "model-00002-of-00006.safetensors",
324
+ "model.language_model.layers.3.self_attn.q_norm.weight": "model-00002-of-00006.safetensors",
325
+ "model.language_model.layers.3.self_attn.q_proj.weight": "model-00002-of-00006.safetensors",
326
+ "model.language_model.layers.3.self_attn.v_proj.weight": "model-00002-of-00006.safetensors",
327
+ "model.language_model.layers.30.input_layernorm.weight": "model-00005-of-00006.safetensors",
328
+ "model.language_model.layers.30.linear_attn.A_log": "model-00005-of-00006.safetensors",
329
+ "model.language_model.layers.30.linear_attn.conv1d.weight": "model-00005-of-00006.safetensors",
330
+ "model.language_model.layers.30.linear_attn.dt_bias": "model-00005-of-00006.safetensors",
331
+ "model.language_model.layers.30.linear_attn.in_proj_a.weight": "model-00005-of-00006.safetensors",
332
+ "model.language_model.layers.30.linear_attn.in_proj_b.weight": "model-00005-of-00006.safetensors",
333
+ "model.language_model.layers.30.linear_attn.in_proj_qkv.weight": "model-00005-of-00006.safetensors",
334
+ "model.language_model.layers.30.linear_attn.in_proj_z.weight": "model-00005-of-00006.safetensors",
335
+ "model.language_model.layers.30.linear_attn.norm.weight": "model-00005-of-00006.safetensors",
336
+ "model.language_model.layers.30.linear_attn.out_proj.weight": "model-00005-of-00006.safetensors",
337
+ "model.language_model.layers.30.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
338
+ "model.language_model.layers.30.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
339
+ "model.language_model.layers.30.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
340
+ "model.language_model.layers.30.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
341
+ "model.language_model.layers.31.input_layernorm.weight": "model-00005-of-00006.safetensors",
342
+ "model.language_model.layers.31.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
343
+ "model.language_model.layers.31.mlp.gate_proj.weight": "model-00005-of-00006.safetensors",
344
+ "model.language_model.layers.31.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
345
+ "model.language_model.layers.31.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
346
+ "model.language_model.layers.31.self_attn.k_norm.weight": "model-00005-of-00006.safetensors",
347
+ "model.language_model.layers.31.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
348
+ "model.language_model.layers.31.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
349
+ "model.language_model.layers.31.self_attn.q_norm.weight": "model-00005-of-00006.safetensors",
350
+ "model.language_model.layers.31.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
351
+ "model.language_model.layers.31.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
352
+ "model.language_model.layers.4.input_layernorm.weight": "model-00002-of-00006.safetensors",
353
+ "model.language_model.layers.4.linear_attn.A_log": "model-00002-of-00006.safetensors",
354
+ "model.language_model.layers.4.linear_attn.conv1d.weight": "model-00002-of-00006.safetensors",
355
+ "model.language_model.layers.4.linear_attn.dt_bias": "model-00002-of-00006.safetensors",
356
+ "model.language_model.layers.4.linear_attn.in_proj_a.weight": "model-00002-of-00006.safetensors",
357
+ "model.language_model.layers.4.linear_attn.in_proj_b.weight": "model-00002-of-00006.safetensors",
358
+ "model.language_model.layers.4.linear_attn.in_proj_qkv.weight": "model-00002-of-00006.safetensors",
359
+ "model.language_model.layers.4.linear_attn.in_proj_z.weight": "model-00002-of-00006.safetensors",
360
+ "model.language_model.layers.4.linear_attn.norm.weight": "model-00002-of-00006.safetensors",
361
+ "model.language_model.layers.4.linear_attn.out_proj.weight": "model-00002-of-00006.safetensors",
362
+ "model.language_model.layers.4.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
363
+ "model.language_model.layers.4.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
364
+ "model.language_model.layers.4.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
365
+ "model.language_model.layers.4.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
366
+ "model.language_model.layers.5.input_layernorm.weight": "model-00003-of-00006.safetensors",
367
+ "model.language_model.layers.5.linear_attn.A_log": "model-00003-of-00006.safetensors",
368
+ "model.language_model.layers.5.linear_attn.conv1d.weight": "model-00003-of-00006.safetensors",
369
+ "model.language_model.layers.5.linear_attn.dt_bias": "model-00003-of-00006.safetensors",
370
+ "model.language_model.layers.5.linear_attn.in_proj_a.weight": "model-00003-of-00006.safetensors",
371
+ "model.language_model.layers.5.linear_attn.in_proj_b.weight": "model-00003-of-00006.safetensors",
372
+ "model.language_model.layers.5.linear_attn.in_proj_qkv.weight": "model-00003-of-00006.safetensors",
373
+ "model.language_model.layers.5.linear_attn.in_proj_z.weight": "model-00003-of-00006.safetensors",
374
+ "model.language_model.layers.5.linear_attn.norm.weight": "model-00003-of-00006.safetensors",
375
+ "model.language_model.layers.5.linear_attn.out_proj.weight": "model-00003-of-00006.safetensors",
376
+ "model.language_model.layers.5.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
377
+ "model.language_model.layers.5.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
378
+ "model.language_model.layers.5.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
379
+ "model.language_model.layers.5.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
380
+ "model.language_model.layers.6.input_layernorm.weight": "model-00003-of-00006.safetensors",
381
+ "model.language_model.layers.6.linear_attn.A_log": "model-00003-of-00006.safetensors",
382
+ "model.language_model.layers.6.linear_attn.conv1d.weight": "model-00003-of-00006.safetensors",
383
+ "model.language_model.layers.6.linear_attn.dt_bias": "model-00003-of-00006.safetensors",
384
+ "model.language_model.layers.6.linear_attn.in_proj_a.weight": "model-00003-of-00006.safetensors",
385
+ "model.language_model.layers.6.linear_attn.in_proj_b.weight": "model-00003-of-00006.safetensors",
386
+ "model.language_model.layers.6.linear_attn.in_proj_qkv.weight": "model-00003-of-00006.safetensors",
387
+ "model.language_model.layers.6.linear_attn.in_proj_z.weight": "model-00003-of-00006.safetensors",
388
+ "model.language_model.layers.6.linear_attn.norm.weight": "model-00003-of-00006.safetensors",
389
+ "model.language_model.layers.6.linear_attn.out_proj.weight": "model-00003-of-00006.safetensors",
390
+ "model.language_model.layers.6.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
391
+ "model.language_model.layers.6.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
392
+ "model.language_model.layers.6.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
393
+ "model.language_model.layers.6.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
394
+ "model.language_model.layers.7.input_layernorm.weight": "model-00003-of-00006.safetensors",
395
+ "model.language_model.layers.7.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
396
+ "model.language_model.layers.7.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
397
+ "model.language_model.layers.7.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
398
+ "model.language_model.layers.7.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
399
+ "model.language_model.layers.7.self_attn.k_norm.weight": "model-00003-of-00006.safetensors",
400
+ "model.language_model.layers.7.self_attn.k_proj.weight": "model-00003-of-00006.safetensors",
401
+ "model.language_model.layers.7.self_attn.o_proj.weight": "model-00003-of-00006.safetensors",
402
+ "model.language_model.layers.7.self_attn.q_norm.weight": "model-00003-of-00006.safetensors",
403
+ "model.language_model.layers.7.self_attn.q_proj.weight": "model-00003-of-00006.safetensors",
404
+ "model.language_model.layers.7.self_attn.v_proj.weight": "model-00003-of-00006.safetensors",
405
+ "model.language_model.layers.8.input_layernorm.weight": "model-00003-of-00006.safetensors",
406
+ "model.language_model.layers.8.linear_attn.A_log": "model-00003-of-00006.safetensors",
407
+ "model.language_model.layers.8.linear_attn.conv1d.weight": "model-00003-of-00006.safetensors",
408
+ "model.language_model.layers.8.linear_attn.dt_bias": "model-00003-of-00006.safetensors",
409
+ "model.language_model.layers.8.linear_attn.in_proj_a.weight": "model-00003-of-00006.safetensors",
410
+ "model.language_model.layers.8.linear_attn.in_proj_b.weight": "model-00003-of-00006.safetensors",
411
+ "model.language_model.layers.8.linear_attn.in_proj_qkv.weight": "model-00003-of-00006.safetensors",
412
+ "model.language_model.layers.8.linear_attn.in_proj_z.weight": "model-00003-of-00006.safetensors",
413
+ "model.language_model.layers.8.linear_attn.norm.weight": "model-00003-of-00006.safetensors",
414
+ "model.language_model.layers.8.linear_attn.out_proj.weight": "model-00003-of-00006.safetensors",
415
+ "model.language_model.layers.8.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
416
+ "model.language_model.layers.8.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
417
+ "model.language_model.layers.8.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
418
+ "model.language_model.layers.8.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
419
+ "model.language_model.layers.9.input_layernorm.weight": "model-00003-of-00006.safetensors",
420
+ "model.language_model.layers.9.linear_attn.A_log": "model-00003-of-00006.safetensors",
421
+ "model.language_model.layers.9.linear_attn.conv1d.weight": "model-00003-of-00006.safetensors",
422
+ "model.language_model.layers.9.linear_attn.dt_bias": "model-00003-of-00006.safetensors",
423
+ "model.language_model.layers.9.linear_attn.in_proj_a.weight": "model-00003-of-00006.safetensors",
424
+ "model.language_model.layers.9.linear_attn.in_proj_b.weight": "model-00003-of-00006.safetensors",
425
+ "model.language_model.layers.9.linear_attn.in_proj_qkv.weight": "model-00003-of-00006.safetensors",
426
+ "model.language_model.layers.9.linear_attn.in_proj_z.weight": "model-00003-of-00006.safetensors",
427
+ "model.language_model.layers.9.linear_attn.norm.weight": "model-00003-of-00006.safetensors",
428
+ "model.language_model.layers.9.linear_attn.out_proj.weight": "model-00003-of-00006.safetensors",
429
+ "model.language_model.layers.9.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
430
+ "model.language_model.layers.9.mlp.gate_proj.weight": "model-00003-of-00006.safetensors",
431
+ "model.language_model.layers.9.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
432
+ "model.language_model.layers.9.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
433
+ "model.language_model.norm.weight": "model-00005-of-00006.safetensors",
434
+ "model.docseam.layers.0.fc1.bias": "model-00005-of-00006.safetensors",
435
+ "model.docseam.layers.0.fc1.weight": "model-00005-of-00006.safetensors",
436
+ "model.docseam.layers.0.fc2.bias": "model-00005-of-00006.safetensors",
437
+ "model.docseam.layers.0.fc2.weight": "model-00005-of-00006.safetensors",
438
+ "model.docseam.layers.0.mlp_recv_from_next.0.bias": "model-00005-of-00006.safetensors",
439
+ "model.docseam.layers.0.mlp_recv_from_next.0.weight": "model-00005-of-00006.safetensors",
440
+ "model.docseam.layers.0.mlp_recv_from_next.2.bias": "model-00005-of-00006.safetensors",
441
+ "model.docseam.layers.0.mlp_recv_from_next.2.weight": "model-00005-of-00006.safetensors",
442
+ "model.docseam.layers.0.mlp_recv_from_prev.0.bias": "model-00005-of-00006.safetensors",
443
+ "model.docseam.layers.0.mlp_recv_from_prev.0.weight": "model-00005-of-00006.safetensors",
444
+ "model.docseam.layers.0.mlp_recv_from_prev.2.bias": "model-00005-of-00006.safetensors",
445
+ "model.docseam.layers.0.mlp_recv_from_prev.2.weight": "model-00005-of-00006.safetensors",
446
+ "model.docseam.layers.0.mlp_send_to_next.0.bias": "model-00005-of-00006.safetensors",
447
+ "model.docseam.layers.0.mlp_send_to_next.0.weight": "model-00005-of-00006.safetensors",
448
+ "model.docseam.layers.0.mlp_send_to_next.2.bias": "model-00005-of-00006.safetensors",
449
+ "model.docseam.layers.0.mlp_send_to_next.2.weight": "model-00005-of-00006.safetensors",
450
+ "model.docseam.layers.0.mlp_send_to_prev.0.bias": "model-00005-of-00006.safetensors",
451
+ "model.docseam.layers.0.mlp_send_to_prev.0.weight": "model-00005-of-00006.safetensors",
452
+ "model.docseam.layers.0.mlp_send_to_prev.2.bias": "model-00005-of-00006.safetensors",
453
+ "model.docseam.layers.0.mlp_send_to_prev.2.weight": "model-00005-of-00006.safetensors",
454
+ "model.docseam.layers.0.norm1.bias": "model-00005-of-00006.safetensors",
455
+ "model.docseam.layers.0.norm1.weight": "model-00005-of-00006.safetensors",
456
+ "model.docseam.layers.0.norm2.bias": "model-00005-of-00006.safetensors",
457
+ "model.docseam.layers.0.norm2.weight": "model-00005-of-00006.safetensors",
458
+ "model.docseam.layers.0.proj.bias": "model-00005-of-00006.safetensors",
459
+ "model.docseam.layers.0.proj.weight": "model-00006-of-00006.safetensors",
460
+ "model.docseam.layers.0.qkv.bias": "model-00006-of-00006.safetensors",
461
+ "model.docseam.layers.0.qkv.weight": "model-00006-of-00006.safetensors",
462
+ "model.docseam.layers.1.fc1.bias": "model-00006-of-00006.safetensors",
463
+ "model.docseam.layers.1.fc1.weight": "model-00006-of-00006.safetensors",
464
+ "model.docseam.layers.1.fc2.bias": "model-00006-of-00006.safetensors",
465
+ "model.docseam.layers.1.fc2.weight": "model-00006-of-00006.safetensors",
466
+ "model.docseam.layers.1.mlp_recv_from_next.0.bias": "model-00006-of-00006.safetensors",
467
+ "model.docseam.layers.1.mlp_recv_from_next.0.weight": "model-00006-of-00006.safetensors",
468
+ "model.docseam.layers.1.mlp_recv_from_next.2.bias": "model-00006-of-00006.safetensors",
469
+ "model.docseam.layers.1.mlp_recv_from_next.2.weight": "model-00006-of-00006.safetensors",
470
+ "model.docseam.layers.1.mlp_recv_from_prev.0.bias": "model-00006-of-00006.safetensors",
471
+ "model.docseam.layers.1.mlp_recv_from_prev.0.weight": "model-00006-of-00006.safetensors",
472
+ "model.docseam.layers.1.mlp_recv_from_prev.2.bias": "model-00006-of-00006.safetensors",
473
+ "model.docseam.layers.1.mlp_recv_from_prev.2.weight": "model-00006-of-00006.safetensors",
474
+ "model.docseam.layers.1.mlp_send_to_next.0.bias": "model-00006-of-00006.safetensors",
475
+ "model.docseam.layers.1.mlp_send_to_next.0.weight": "model-00006-of-00006.safetensors",
476
+ "model.docseam.layers.1.mlp_send_to_next.2.bias": "model-00006-of-00006.safetensors",
477
+ "model.docseam.layers.1.mlp_send_to_next.2.weight": "model-00006-of-00006.safetensors",
478
+ "model.docseam.layers.1.mlp_send_to_prev.0.bias": "model-00006-of-00006.safetensors",
479
+ "model.docseam.layers.1.mlp_send_to_prev.0.weight": "model-00006-of-00006.safetensors",
480
+ "model.docseam.layers.1.mlp_send_to_prev.2.bias": "model-00006-of-00006.safetensors",
481
+ "model.docseam.layers.1.mlp_send_to_prev.2.weight": "model-00006-of-00006.safetensors",
482
+ "model.docseam.layers.1.norm1.bias": "model-00006-of-00006.safetensors",
483
+ "model.docseam.layers.1.norm1.weight": "model-00006-of-00006.safetensors",
484
+ "model.docseam.layers.1.norm2.bias": "model-00006-of-00006.safetensors",
485
+ "model.docseam.layers.1.norm2.weight": "model-00006-of-00006.safetensors",
486
+ "model.docseam.layers.1.proj.bias": "model-00006-of-00006.safetensors",
487
+ "model.docseam.layers.1.proj.weight": "model-00006-of-00006.safetensors",
488
+ "model.docseam.layers.1.qkv.bias": "model-00006-of-00006.safetensors",
489
+ "model.docseam.layers.1.qkv.weight": "model-00006-of-00006.safetensors",
490
+ "model.visual.blocks.0.attn.proj.bias": "model-00006-of-00006.safetensors",
491
+ "model.visual.blocks.0.attn.proj.weight": "model-00006-of-00006.safetensors",
492
+ "model.visual.blocks.0.attn.qkv.bias": "model-00006-of-00006.safetensors",
493
+ "model.visual.blocks.0.attn.qkv.weight": "model-00006-of-00006.safetensors",
494
+ "model.visual.blocks.0.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
495
+ "model.visual.blocks.0.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
496
+ "model.visual.blocks.0.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
497
+ "model.visual.blocks.0.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
498
+ "model.visual.blocks.0.norm1.bias": "model-00006-of-00006.safetensors",
499
+ "model.visual.blocks.0.norm1.weight": "model-00006-of-00006.safetensors",
500
+ "model.visual.blocks.0.norm2.bias": "model-00006-of-00006.safetensors",
501
+ "model.visual.blocks.0.norm2.weight": "model-00006-of-00006.safetensors",
502
+ "model.visual.blocks.1.attn.proj.bias": "model-00006-of-00006.safetensors",
503
+ "model.visual.blocks.1.attn.proj.weight": "model-00006-of-00006.safetensors",
504
+ "model.visual.blocks.1.attn.qkv.bias": "model-00006-of-00006.safetensors",
505
+ "model.visual.blocks.1.attn.qkv.weight": "model-00006-of-00006.safetensors",
506
+ "model.visual.blocks.1.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
507
+ "model.visual.blocks.1.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
508
+ "model.visual.blocks.1.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
509
+ "model.visual.blocks.1.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
510
+ "model.visual.blocks.1.norm1.bias": "model-00006-of-00006.safetensors",
511
+ "model.visual.blocks.1.norm1.weight": "model-00006-of-00006.safetensors",
512
+ "model.visual.blocks.1.norm2.bias": "model-00006-of-00006.safetensors",
513
+ "model.visual.blocks.1.norm2.weight": "model-00006-of-00006.safetensors",
514
+ "model.visual.blocks.10.attn.proj.bias": "model-00006-of-00006.safetensors",
515
+ "model.visual.blocks.10.attn.proj.weight": "model-00006-of-00006.safetensors",
516
+ "model.visual.blocks.10.attn.qkv.bias": "model-00006-of-00006.safetensors",
517
+ "model.visual.blocks.10.attn.qkv.weight": "model-00006-of-00006.safetensors",
518
+ "model.visual.blocks.10.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
519
+ "model.visual.blocks.10.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
520
+ "model.visual.blocks.10.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
521
+ "model.visual.blocks.10.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
522
+ "model.visual.blocks.10.norm1.bias": "model-00006-of-00006.safetensors",
523
+ "model.visual.blocks.10.norm1.weight": "model-00006-of-00006.safetensors",
524
+ "model.visual.blocks.10.norm2.bias": "model-00006-of-00006.safetensors",
525
+ "model.visual.blocks.10.norm2.weight": "model-00006-of-00006.safetensors",
526
+ "model.visual.blocks.11.attn.proj.bias": "model-00006-of-00006.safetensors",
527
+ "model.visual.blocks.11.attn.proj.weight": "model-00006-of-00006.safetensors",
528
+ "model.visual.blocks.11.attn.qkv.bias": "model-00006-of-00006.safetensors",
529
+ "model.visual.blocks.11.attn.qkv.weight": "model-00006-of-00006.safetensors",
530
+ "model.visual.blocks.11.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
531
+ "model.visual.blocks.11.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
532
+ "model.visual.blocks.11.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
533
+ "model.visual.blocks.11.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
534
+ "model.visual.blocks.11.norm1.bias": "model-00006-of-00006.safetensors",
535
+ "model.visual.blocks.11.norm1.weight": "model-00006-of-00006.safetensors",
536
+ "model.visual.blocks.11.norm2.bias": "model-00006-of-00006.safetensors",
537
+ "model.visual.blocks.11.norm2.weight": "model-00006-of-00006.safetensors",
538
+ "model.visual.blocks.12.attn.proj.bias": "model-00006-of-00006.safetensors",
539
+ "model.visual.blocks.12.attn.proj.weight": "model-00006-of-00006.safetensors",
540
+ "model.visual.blocks.12.attn.qkv.bias": "model-00006-of-00006.safetensors",
541
+ "model.visual.blocks.12.attn.qkv.weight": "model-00006-of-00006.safetensors",
542
+ "model.visual.blocks.12.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
543
+ "model.visual.blocks.12.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
544
+ "model.visual.blocks.12.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
545
+ "model.visual.blocks.12.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
546
+ "model.visual.blocks.12.norm1.bias": "model-00006-of-00006.safetensors",
547
+ "model.visual.blocks.12.norm1.weight": "model-00006-of-00006.safetensors",
548
+ "model.visual.blocks.12.norm2.bias": "model-00006-of-00006.safetensors",
549
+ "model.visual.blocks.12.norm2.weight": "model-00006-of-00006.safetensors",
550
+ "model.visual.blocks.13.attn.proj.bias": "model-00006-of-00006.safetensors",
551
+ "model.visual.blocks.13.attn.proj.weight": "model-00006-of-00006.safetensors",
552
+ "model.visual.blocks.13.attn.qkv.bias": "model-00006-of-00006.safetensors",
553
+ "model.visual.blocks.13.attn.qkv.weight": "model-00006-of-00006.safetensors",
554
+ "model.visual.blocks.13.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
555
+ "model.visual.blocks.13.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
556
+ "model.visual.blocks.13.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
557
+ "model.visual.blocks.13.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
558
+ "model.visual.blocks.13.norm1.bias": "model-00006-of-00006.safetensors",
559
+ "model.visual.blocks.13.norm1.weight": "model-00006-of-00006.safetensors",
560
+ "model.visual.blocks.13.norm2.bias": "model-00006-of-00006.safetensors",
561
+ "model.visual.blocks.13.norm2.weight": "model-00006-of-00006.safetensors",
562
+ "model.visual.blocks.14.attn.proj.bias": "model-00006-of-00006.safetensors",
563
+ "model.visual.blocks.14.attn.proj.weight": "model-00006-of-00006.safetensors",
564
+ "model.visual.blocks.14.attn.qkv.bias": "model-00006-of-00006.safetensors",
565
+ "model.visual.blocks.14.attn.qkv.weight": "model-00006-of-00006.safetensors",
566
+ "model.visual.blocks.14.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
567
+ "model.visual.blocks.14.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
568
+ "model.visual.blocks.14.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
569
+ "model.visual.blocks.14.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
570
+ "model.visual.blocks.14.norm1.bias": "model-00006-of-00006.safetensors",
571
+ "model.visual.blocks.14.norm1.weight": "model-00006-of-00006.safetensors",
572
+ "model.visual.blocks.14.norm2.bias": "model-00006-of-00006.safetensors",
573
+ "model.visual.blocks.14.norm2.weight": "model-00006-of-00006.safetensors",
574
+ "model.visual.blocks.15.attn.proj.bias": "model-00006-of-00006.safetensors",
575
+ "model.visual.blocks.15.attn.proj.weight": "model-00006-of-00006.safetensors",
576
+ "model.visual.blocks.15.attn.qkv.bias": "model-00006-of-00006.safetensors",
577
+ "model.visual.blocks.15.attn.qkv.weight": "model-00006-of-00006.safetensors",
578
+ "model.visual.blocks.15.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
579
+ "model.visual.blocks.15.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
580
+ "model.visual.blocks.15.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
581
+ "model.visual.blocks.15.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
582
+ "model.visual.blocks.15.norm1.bias": "model-00006-of-00006.safetensors",
583
+ "model.visual.blocks.15.norm1.weight": "model-00006-of-00006.safetensors",
584
+ "model.visual.blocks.15.norm2.bias": "model-00006-of-00006.safetensors",
585
+ "model.visual.blocks.15.norm2.weight": "model-00006-of-00006.safetensors",
586
+ "model.visual.blocks.16.attn.proj.bias": "model-00006-of-00006.safetensors",
587
+ "model.visual.blocks.16.attn.proj.weight": "model-00006-of-00006.safetensors",
588
+ "model.visual.blocks.16.attn.qkv.bias": "model-00006-of-00006.safetensors",
589
+ "model.visual.blocks.16.attn.qkv.weight": "model-00006-of-00006.safetensors",
590
+ "model.visual.blocks.16.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
591
+ "model.visual.blocks.16.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
592
+ "model.visual.blocks.16.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
593
+ "model.visual.blocks.16.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
594
+ "model.visual.blocks.16.norm1.bias": "model-00006-of-00006.safetensors",
595
+ "model.visual.blocks.16.norm1.weight": "model-00006-of-00006.safetensors",
596
+ "model.visual.blocks.16.norm2.bias": "model-00006-of-00006.safetensors",
597
+ "model.visual.blocks.16.norm2.weight": "model-00006-of-00006.safetensors",
598
+ "model.visual.blocks.17.attn.proj.bias": "model-00006-of-00006.safetensors",
599
+ "model.visual.blocks.17.attn.proj.weight": "model-00006-of-00006.safetensors",
600
+ "model.visual.blocks.17.attn.qkv.bias": "model-00006-of-00006.safetensors",
601
+ "model.visual.blocks.17.attn.qkv.weight": "model-00006-of-00006.safetensors",
602
+ "model.visual.blocks.17.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
603
+ "model.visual.blocks.17.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
604
+ "model.visual.blocks.17.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
605
+ "model.visual.blocks.17.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
606
+ "model.visual.blocks.17.norm1.bias": "model-00006-of-00006.safetensors",
607
+ "model.visual.blocks.17.norm1.weight": "model-00006-of-00006.safetensors",
608
+ "model.visual.blocks.17.norm2.bias": "model-00006-of-00006.safetensors",
609
+ "model.visual.blocks.17.norm2.weight": "model-00006-of-00006.safetensors",
610
+ "model.visual.blocks.18.attn.proj.bias": "model-00006-of-00006.safetensors",
611
+ "model.visual.blocks.18.attn.proj.weight": "model-00006-of-00006.safetensors",
612
+ "model.visual.blocks.18.attn.qkv.bias": "model-00006-of-00006.safetensors",
613
+ "model.visual.blocks.18.attn.qkv.weight": "model-00006-of-00006.safetensors",
614
+ "model.visual.blocks.18.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
615
+ "model.visual.blocks.18.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
616
+ "model.visual.blocks.18.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
617
+ "model.visual.blocks.18.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
618
+ "model.visual.blocks.18.norm1.bias": "model-00006-of-00006.safetensors",
619
+ "model.visual.blocks.18.norm1.weight": "model-00006-of-00006.safetensors",
620
+ "model.visual.blocks.18.norm2.bias": "model-00006-of-00006.safetensors",
621
+ "model.visual.blocks.18.norm2.weight": "model-00006-of-00006.safetensors",
622
+ "model.visual.blocks.19.attn.proj.bias": "model-00006-of-00006.safetensors",
623
+ "model.visual.blocks.19.attn.proj.weight": "model-00006-of-00006.safetensors",
624
+ "model.visual.blocks.19.attn.qkv.bias": "model-00006-of-00006.safetensors",
625
+ "model.visual.blocks.19.attn.qkv.weight": "model-00006-of-00006.safetensors",
626
+ "model.visual.blocks.19.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
627
+ "model.visual.blocks.19.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
628
+ "model.visual.blocks.19.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
629
+ "model.visual.blocks.19.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
630
+ "model.visual.blocks.19.norm1.bias": "model-00006-of-00006.safetensors",
631
+ "model.visual.blocks.19.norm1.weight": "model-00006-of-00006.safetensors",
632
+ "model.visual.blocks.19.norm2.bias": "model-00006-of-00006.safetensors",
633
+ "model.visual.blocks.19.norm2.weight": "model-00006-of-00006.safetensors",
634
+ "model.visual.blocks.2.attn.proj.bias": "model-00006-of-00006.safetensors",
635
+ "model.visual.blocks.2.attn.proj.weight": "model-00006-of-00006.safetensors",
636
+ "model.visual.blocks.2.attn.qkv.bias": "model-00006-of-00006.safetensors",
637
+ "model.visual.blocks.2.attn.qkv.weight": "model-00006-of-00006.safetensors",
638
+ "model.visual.blocks.2.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
639
+ "model.visual.blocks.2.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
640
+ "model.visual.blocks.2.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
641
+ "model.visual.blocks.2.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
642
+ "model.visual.blocks.2.norm1.bias": "model-00006-of-00006.safetensors",
643
+ "model.visual.blocks.2.norm1.weight": "model-00006-of-00006.safetensors",
644
+ "model.visual.blocks.2.norm2.bias": "model-00006-of-00006.safetensors",
645
+ "model.visual.blocks.2.norm2.weight": "model-00006-of-00006.safetensors",
646
+ "model.visual.blocks.20.attn.proj.bias": "model-00006-of-00006.safetensors",
647
+ "model.visual.blocks.20.attn.proj.weight": "model-00006-of-00006.safetensors",
648
+ "model.visual.blocks.20.attn.qkv.bias": "model-00006-of-00006.safetensors",
649
+ "model.visual.blocks.20.attn.qkv.weight": "model-00006-of-00006.safetensors",
650
+ "model.visual.blocks.20.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
651
+ "model.visual.blocks.20.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
652
+ "model.visual.blocks.20.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
653
+ "model.visual.blocks.20.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
654
+ "model.visual.blocks.20.norm1.bias": "model-00006-of-00006.safetensors",
655
+ "model.visual.blocks.20.norm1.weight": "model-00006-of-00006.safetensors",
656
+ "model.visual.blocks.20.norm2.bias": "model-00006-of-00006.safetensors",
657
+ "model.visual.blocks.20.norm2.weight": "model-00006-of-00006.safetensors",
658
+ "model.visual.blocks.21.attn.proj.bias": "model-00006-of-00006.safetensors",
659
+ "model.visual.blocks.21.attn.proj.weight": "model-00006-of-00006.safetensors",
660
+ "model.visual.blocks.21.attn.qkv.bias": "model-00006-of-00006.safetensors",
661
+ "model.visual.blocks.21.attn.qkv.weight": "model-00006-of-00006.safetensors",
662
+ "model.visual.blocks.21.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
663
+ "model.visual.blocks.21.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
664
+ "model.visual.blocks.21.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
665
+ "model.visual.blocks.21.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
666
+ "model.visual.blocks.21.norm1.bias": "model-00006-of-00006.safetensors",
667
+ "model.visual.blocks.21.norm1.weight": "model-00006-of-00006.safetensors",
668
+ "model.visual.blocks.21.norm2.bias": "model-00006-of-00006.safetensors",
669
+ "model.visual.blocks.21.norm2.weight": "model-00006-of-00006.safetensors",
670
+ "model.visual.blocks.22.attn.proj.bias": "model-00006-of-00006.safetensors",
671
+ "model.visual.blocks.22.attn.proj.weight": "model-00006-of-00006.safetensors",
672
+ "model.visual.blocks.22.attn.qkv.bias": "model-00006-of-00006.safetensors",
673
+ "model.visual.blocks.22.attn.qkv.weight": "model-00006-of-00006.safetensors",
674
+ "model.visual.blocks.22.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
675
+ "model.visual.blocks.22.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
676
+ "model.visual.blocks.22.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
677
+ "model.visual.blocks.22.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
678
+ "model.visual.blocks.22.norm1.bias": "model-00006-of-00006.safetensors",
679
+ "model.visual.blocks.22.norm1.weight": "model-00006-of-00006.safetensors",
680
+ "model.visual.blocks.22.norm2.bias": "model-00006-of-00006.safetensors",
681
+ "model.visual.blocks.22.norm2.weight": "model-00006-of-00006.safetensors",
682
+ "model.visual.blocks.23.attn.proj.bias": "model-00006-of-00006.safetensors",
683
+ "model.visual.blocks.23.attn.proj.weight": "model-00006-of-00006.safetensors",
684
+ "model.visual.blocks.23.attn.qkv.bias": "model-00006-of-00006.safetensors",
685
+ "model.visual.blocks.23.attn.qkv.weight": "model-00006-of-00006.safetensors",
686
+ "model.visual.blocks.23.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
687
+ "model.visual.blocks.23.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
688
+ "model.visual.blocks.23.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
689
+ "model.visual.blocks.23.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
690
+ "model.visual.blocks.23.norm1.bias": "model-00006-of-00006.safetensors",
691
+ "model.visual.blocks.23.norm1.weight": "model-00006-of-00006.safetensors",
692
+ "model.visual.blocks.23.norm2.bias": "model-00006-of-00006.safetensors",
693
+ "model.visual.blocks.23.norm2.weight": "model-00006-of-00006.safetensors",
694
+ "model.visual.blocks.24.attn.proj.bias": "model-00006-of-00006.safetensors",
695
+ "model.visual.blocks.24.attn.proj.weight": "model-00006-of-00006.safetensors",
696
+ "model.visual.blocks.24.attn.qkv.bias": "model-00006-of-00006.safetensors",
697
+ "model.visual.blocks.24.attn.qkv.weight": "model-00006-of-00006.safetensors",
698
+ "model.visual.blocks.24.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
699
+ "model.visual.blocks.24.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
700
+ "model.visual.blocks.24.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
701
+ "model.visual.blocks.24.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
702
+ "model.visual.blocks.24.norm1.bias": "model-00006-of-00006.safetensors",
703
+ "model.visual.blocks.24.norm1.weight": "model-00006-of-00006.safetensors",
704
+ "model.visual.blocks.24.norm2.bias": "model-00006-of-00006.safetensors",
705
+ "model.visual.blocks.24.norm2.weight": "model-00006-of-00006.safetensors",
706
+ "model.visual.blocks.25.attn.proj.bias": "model-00006-of-00006.safetensors",
707
+ "model.visual.blocks.25.attn.proj.weight": "model-00006-of-00006.safetensors",
708
+ "model.visual.blocks.25.attn.qkv.bias": "model-00006-of-00006.safetensors",
709
+ "model.visual.blocks.25.attn.qkv.weight": "model-00006-of-00006.safetensors",
710
+ "model.visual.blocks.25.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
711
+ "model.visual.blocks.25.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
712
+ "model.visual.blocks.25.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
713
+ "model.visual.blocks.25.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
714
+ "model.visual.blocks.25.norm1.bias": "model-00006-of-00006.safetensors",
715
+ "model.visual.blocks.25.norm1.weight": "model-00006-of-00006.safetensors",
716
+ "model.visual.blocks.25.norm2.bias": "model-00006-of-00006.safetensors",
717
+ "model.visual.blocks.25.norm2.weight": "model-00006-of-00006.safetensors",
718
+ "model.visual.blocks.26.attn.proj.bias": "model-00006-of-00006.safetensors",
719
+ "model.visual.blocks.26.attn.proj.weight": "model-00006-of-00006.safetensors",
720
+ "model.visual.blocks.26.attn.qkv.bias": "model-00006-of-00006.safetensors",
721
+ "model.visual.blocks.26.attn.qkv.weight": "model-00006-of-00006.safetensors",
722
+ "model.visual.blocks.26.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
723
+ "model.visual.blocks.26.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
724
+ "model.visual.blocks.26.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
725
+ "model.visual.blocks.26.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
726
+ "model.visual.blocks.26.norm1.bias": "model-00006-of-00006.safetensors",
727
+ "model.visual.blocks.26.norm1.weight": "model-00006-of-00006.safetensors",
728
+ "model.visual.blocks.26.norm2.bias": "model-00006-of-00006.safetensors",
729
+ "model.visual.blocks.26.norm2.weight": "model-00006-of-00006.safetensors",
730
+ "model.visual.blocks.3.attn.proj.bias": "model-00006-of-00006.safetensors",
731
+ "model.visual.blocks.3.attn.proj.weight": "model-00006-of-00006.safetensors",
732
+ "model.visual.blocks.3.attn.qkv.bias": "model-00006-of-00006.safetensors",
733
+ "model.visual.blocks.3.attn.qkv.weight": "model-00006-of-00006.safetensors",
734
+ "model.visual.blocks.3.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
735
+ "model.visual.blocks.3.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
736
+ "model.visual.blocks.3.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
737
+ "model.visual.blocks.3.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
738
+ "model.visual.blocks.3.norm1.bias": "model-00006-of-00006.safetensors",
739
+ "model.visual.blocks.3.norm1.weight": "model-00006-of-00006.safetensors",
740
+ "model.visual.blocks.3.norm2.bias": "model-00006-of-00006.safetensors",
741
+ "model.visual.blocks.3.norm2.weight": "model-00006-of-00006.safetensors",
742
+ "model.visual.blocks.4.attn.proj.bias": "model-00006-of-00006.safetensors",
743
+ "model.visual.blocks.4.attn.proj.weight": "model-00006-of-00006.safetensors",
744
+ "model.visual.blocks.4.attn.qkv.bias": "model-00006-of-00006.safetensors",
745
+ "model.visual.blocks.4.attn.qkv.weight": "model-00006-of-00006.safetensors",
746
+ "model.visual.blocks.4.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
747
+ "model.visual.blocks.4.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
748
+ "model.visual.blocks.4.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
749
+ "model.visual.blocks.4.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
750
+ "model.visual.blocks.4.norm1.bias": "model-00006-of-00006.safetensors",
751
+ "model.visual.blocks.4.norm1.weight": "model-00006-of-00006.safetensors",
752
+ "model.visual.blocks.4.norm2.bias": "model-00006-of-00006.safetensors",
753
+ "model.visual.blocks.4.norm2.weight": "model-00006-of-00006.safetensors",
754
+ "model.visual.blocks.5.attn.proj.bias": "model-00006-of-00006.safetensors",
755
+ "model.visual.blocks.5.attn.proj.weight": "model-00006-of-00006.safetensors",
756
+ "model.visual.blocks.5.attn.qkv.bias": "model-00006-of-00006.safetensors",
757
+ "model.visual.blocks.5.attn.qkv.weight": "model-00006-of-00006.safetensors",
758
+ "model.visual.blocks.5.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
759
+ "model.visual.blocks.5.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
760
+ "model.visual.blocks.5.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
761
+ "model.visual.blocks.5.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
762
+ "model.visual.blocks.5.norm1.bias": "model-00006-of-00006.safetensors",
763
+ "model.visual.blocks.5.norm1.weight": "model-00006-of-00006.safetensors",
764
+ "model.visual.blocks.5.norm2.bias": "model-00006-of-00006.safetensors",
765
+ "model.visual.blocks.5.norm2.weight": "model-00006-of-00006.safetensors",
766
+ "model.visual.blocks.6.attn.proj.bias": "model-00006-of-00006.safetensors",
767
+ "model.visual.blocks.6.attn.proj.weight": "model-00006-of-00006.safetensors",
768
+ "model.visual.blocks.6.attn.qkv.bias": "model-00006-of-00006.safetensors",
769
+ "model.visual.blocks.6.attn.qkv.weight": "model-00006-of-00006.safetensors",
770
+ "model.visual.blocks.6.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
771
+ "model.visual.blocks.6.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
772
+ "model.visual.blocks.6.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
773
+ "model.visual.blocks.6.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
774
+ "model.visual.blocks.6.norm1.bias": "model-00006-of-00006.safetensors",
775
+ "model.visual.blocks.6.norm1.weight": "model-00006-of-00006.safetensors",
776
+ "model.visual.blocks.6.norm2.bias": "model-00006-of-00006.safetensors",
777
+ "model.visual.blocks.6.norm2.weight": "model-00006-of-00006.safetensors",
778
+ "model.visual.blocks.7.attn.proj.bias": "model-00006-of-00006.safetensors",
779
+ "model.visual.blocks.7.attn.proj.weight": "model-00006-of-00006.safetensors",
780
+ "model.visual.blocks.7.attn.qkv.bias": "model-00006-of-00006.safetensors",
781
+ "model.visual.blocks.7.attn.qkv.weight": "model-00006-of-00006.safetensors",
782
+ "model.visual.blocks.7.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
783
+ "model.visual.blocks.7.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
784
+ "model.visual.blocks.7.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
785
+ "model.visual.blocks.7.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
786
+ "model.visual.blocks.7.norm1.bias": "model-00006-of-00006.safetensors",
787
+ "model.visual.blocks.7.norm1.weight": "model-00006-of-00006.safetensors",
788
+ "model.visual.blocks.7.norm2.bias": "model-00006-of-00006.safetensors",
789
+ "model.visual.blocks.7.norm2.weight": "model-00006-of-00006.safetensors",
790
+ "model.visual.blocks.8.attn.proj.bias": "model-00006-of-00006.safetensors",
791
+ "model.visual.blocks.8.attn.proj.weight": "model-00006-of-00006.safetensors",
792
+ "model.visual.blocks.8.attn.qkv.bias": "model-00006-of-00006.safetensors",
793
+ "model.visual.blocks.8.attn.qkv.weight": "model-00006-of-00006.safetensors",
794
+ "model.visual.blocks.8.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
795
+ "model.visual.blocks.8.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
796
+ "model.visual.blocks.8.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
797
+ "model.visual.blocks.8.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
798
+ "model.visual.blocks.8.norm1.bias": "model-00006-of-00006.safetensors",
799
+ "model.visual.blocks.8.norm1.weight": "model-00006-of-00006.safetensors",
800
+ "model.visual.blocks.8.norm2.bias": "model-00006-of-00006.safetensors",
801
+ "model.visual.blocks.8.norm2.weight": "model-00006-of-00006.safetensors",
802
+ "model.visual.blocks.9.attn.proj.bias": "model-00006-of-00006.safetensors",
803
+ "model.visual.blocks.9.attn.proj.weight": "model-00006-of-00006.safetensors",
804
+ "model.visual.blocks.9.attn.qkv.bias": "model-00006-of-00006.safetensors",
805
+ "model.visual.blocks.9.attn.qkv.weight": "model-00006-of-00006.safetensors",
806
+ "model.visual.blocks.9.mlp.linear_fc1.bias": "model-00006-of-00006.safetensors",
807
+ "model.visual.blocks.9.mlp.linear_fc1.weight": "model-00006-of-00006.safetensors",
808
+ "model.visual.blocks.9.mlp.linear_fc2.bias": "model-00006-of-00006.safetensors",
809
+ "model.visual.blocks.9.mlp.linear_fc2.weight": "model-00006-of-00006.safetensors",
810
+ "model.visual.blocks.9.norm1.bias": "model-00006-of-00006.safetensors",
811
+ "model.visual.blocks.9.norm1.weight": "model-00006-of-00006.safetensors",
812
+ "model.visual.blocks.9.norm2.bias": "model-00006-of-00006.safetensors",
813
+ "model.visual.blocks.9.norm2.weight": "model-00006-of-00006.safetensors",
814
+ "model.visual.merger.linear_fc1.bias": "model-00006-of-00006.safetensors",
815
+ "model.visual.merger.linear_fc1.weight": "model-00006-of-00006.safetensors",
816
+ "model.visual.merger.linear_fc2.bias": "model-00006-of-00006.safetensors",
817
+ "model.visual.merger.linear_fc2.weight": "model-00006-of-00006.safetensors",
818
+ "model.visual.merger.norm.bias": "model-00006-of-00006.safetensors",
819
+ "model.visual.merger.norm.weight": "model-00006-of-00006.safetensors",
820
+ "model.visual.patch_embed.proj.bias": "model-00006-of-00006.safetensors",
821
+ "model.visual.patch_embed.proj.weight": "model-00006-of-00006.safetensors",
822
+ "model.visual.pos_embed.weight": "model-00006-of-00006.safetensors"
823
+ }
824
+ }
modeling_docseam.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Transformers integration for DocSEAM on the Qwen3.5 backbone."""
2
+
3
+ from contextvars import ContextVar
4
+
5
+ import torch.nn.functional as F
6
+ from torch import nn
7
+ from transformers.models.qwen3_5.modeling_qwen3_5 import (
8
+ Qwen3_5ForConditionalGeneration,
9
+ Qwen3_5Model,
10
+ Qwen3_5PreTrainedModel,
11
+ )
12
+
13
+ from .docseam import DocSEAM
14
+
15
+
16
+ _page_counts = ContextVar("docseam_page_counts", default=None)
17
+
18
+
19
+ class DocSEAMModel(Qwen3_5Model):
20
+ def __init__(self, config):
21
+ super().__init__(config)
22
+ self.docseam = DocSEAM(
23
+ hidden_size=config.text_config.hidden_size,
24
+ num_heads=config.text_config.num_attention_heads,
25
+ intermediate_size=4096,
26
+ num_layers=config.docseam_num_layers,
27
+ cap_frac=config.docseam_cap_frac,
28
+ )
29
+ self.docseam.pos_feature_mode = config.docseam_pos_feature_mode
30
+ self.docseam.use_checkpoint = False
31
+
32
+ def forward(self, input_ids=None, position_ids=None, pixel_values=None, **kwargs):
33
+ pages = None
34
+ if pixel_values is not None and input_ids is not None:
35
+ image_starts = (
36
+ (input_ids[:, :-1] == self.config.vision_start_token_id)
37
+ & (input_ids[:, 1:] == self.config.image_token_id)
38
+ )
39
+ pages = [count for count in image_starts.sum(dim=1).tolist() if count]
40
+ token = _page_counts.set(pages)
41
+ try:
42
+ return super().forward(
43
+ input_ids=input_ids, position_ids=position_ids, pixel_values=pixel_values, **kwargs
44
+ )
45
+ finally:
46
+ _page_counts.reset(token)
47
+
48
+ def get_video_features(self, pixel_values_videos, video_grid_thw=None, **kwargs):
49
+ return super().get_image_features(pixel_values_videos, video_grid_thw, **kwargs)
50
+
51
+ def get_image_features(self, pixel_values, image_grid_thw=None, **kwargs):
52
+ return_dict = kwargs.pop("return_dict", getattr(self.config, "return_dict", True))
53
+ output = super().get_image_features(pixel_values, image_grid_thw, return_dict=True, **kwargs)
54
+ pages = _page_counts.get()
55
+ if pages is not None:
56
+ if sum(pages) != len(output.pooler_output):
57
+ raise ValueError("DocSEAM page counts do not match the encoded images.")
58
+ grids = image_grid_thw.tolist()
59
+ merge = self.visual.spatial_merge_size
60
+ output.pooler_output = tuple(self.docseam(
61
+ list(output.pooler_output),
62
+ page_grid_dims=[(h // merge, w // merge) for _, h, w in grids],
63
+ pages_per_document=pages,
64
+ page_ink_masks=_ink_masks(pixel_values, grids, merge),
65
+ ))
66
+ return output if return_dict else output.to_tuple()
67
+
68
+
69
+ def _ink_masks(pixel_values, grids, merge):
70
+ """Reproduce the Stage B runtime ink estimates used by the frontier gates."""
71
+ masks = []
72
+ start = 0
73
+ for t, h, w in grids:
74
+ stop = start + t * h * w
75
+ patches = pixel_values[start:stop].detach().float()
76
+ start = stop
77
+ rows, cols = h // merge, w // merge
78
+ darkness = ((1.0 - patches).clamp(0.0, 2.0) * 0.5).mean(dim=-1)
79
+ darkness = darkness.view(t, h, w).mean(dim=0)
80
+ darkness = darkness[: rows * merge, : cols * merge]
81
+ darkness = darkness.reshape(rows, merge, cols, merge).mean(dim=(1, 3))
82
+ darkness = F.avg_pool2d(darkness[None, None], kernel_size=3, stride=1, padding=1)[0, 0]
83
+ masks.append(((darkness - 0.01) / 0.12).clamp(0.0, 1.0).reshape(-1).to(pixel_values.dtype))
84
+ return masks
85
+
86
+
87
+ class DocSEAMForConditionalGeneration(Qwen3_5ForConditionalGeneration):
88
+ def __init__(self, config):
89
+ Qwen3_5PreTrainedModel.__init__(self, config)
90
+ self.model = DocSEAMModel(config)
91
+ self.lm_head = nn.Linear(config.text_config.hidden_size, config.text_config.vocab_size, bias=False)
92
+ self.post_init()
preprocessor_config.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "size": {
3
+ "longest_edge": 16777216,
4
+ "shortest_edge": 65536
5
+ },
6
+ "patch_size": 16,
7
+ "temporal_patch_size": 2,
8
+ "merge_size": 2,
9
+ "image_mean": [
10
+ 0.5,
11
+ 0.5,
12
+ 0.5
13
+ ],
14
+ "image_std": [
15
+ 0.5,
16
+ 0.5,
17
+ 0.5
18
+ ],
19
+ "processor_class": "Qwen3VLProcessor",
20
+ "image_processor_type": "Qwen2VLImageProcessorFast"
21
+ }
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ torch>=2.6
2
+ torchvision>=0.21
3
+ transformers==5.6.0
4
+ accelerate>=1.11
5
+ qwen-vl-utils==0.0.14
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f9e4d4901a92b997e463c1f46055088b6cca5ca61a6522d1b9f64c4bb81cb42
3
+ size 12807982
tokenizer_config.json ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "248044": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "248045": {
13
+ "content": "<|im_start|>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "248046": {
21
+ "content": "<|im_end|>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "248047": {
29
+ "content": "<|object_ref_start|>",
30
+ "lstrip": false,
31
+ "normalized": false,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "248048": {
37
+ "content": "<|object_ref_end|>",
38
+ "lstrip": false,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ },
44
+ "248049": {
45
+ "content": "<|box_start|>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": true
51
+ },
52
+ "248050": {
53
+ "content": "<|box_end|>",
54
+ "lstrip": false,
55
+ "normalized": false,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": true
59
+ },
60
+ "248051": {
61
+ "content": "<|quad_start|>",
62
+ "lstrip": false,
63
+ "normalized": false,
64
+ "rstrip": false,
65
+ "single_word": false,
66
+ "special": true
67
+ },
68
+ "248052": {
69
+ "content": "<|quad_end|>",
70
+ "lstrip": false,
71
+ "normalized": false,
72
+ "rstrip": false,
73
+ "single_word": false,
74
+ "special": true
75
+ },
76
+ "248053": {
77
+ "content": "<|vision_start|>",
78
+ "lstrip": false,
79
+ "normalized": false,
80
+ "rstrip": false,
81
+ "single_word": false,
82
+ "special": true
83
+ },
84
+ "248054": {
85
+ "content": "<|vision_end|>",
86
+ "lstrip": false,
87
+ "normalized": false,
88
+ "rstrip": false,
89
+ "single_word": false,
90
+ "special": true
91
+ },
92
+ "248055": {
93
+ "content": "<|vision_pad|>",
94
+ "lstrip": false,
95
+ "normalized": false,
96
+ "rstrip": false,
97
+ "single_word": false,
98
+ "special": true
99
+ },
100
+ "248056": {
101
+ "content": "<|image_pad|>",
102
+ "lstrip": false,
103
+ "normalized": false,
104
+ "rstrip": false,
105
+ "single_word": false,
106
+ "special": true
107
+ },
108
+ "248057": {
109
+ "content": "<|video_pad|>",
110
+ "lstrip": false,
111
+ "normalized": false,
112
+ "rstrip": false,
113
+ "single_word": false,
114
+ "special": true
115
+ },
116
+ "248058": {
117
+ "content": "<tool_call>",
118
+ "lstrip": false,
119
+ "normalized": false,
120
+ "rstrip": false,
121
+ "single_word": false,
122
+ "special": false
123
+ },
124
+ "248059": {
125
+ "content": "</tool_call>",
126
+ "lstrip": false,
127
+ "normalized": false,
128
+ "rstrip": false,
129
+ "single_word": false,
130
+ "special": false
131
+ },
132
+ "248060": {
133
+ "content": "<|fim_prefix|>",
134
+ "lstrip": false,
135
+ "normalized": false,
136
+ "rstrip": false,
137
+ "single_word": false,
138
+ "special": false
139
+ },
140
+ "248061": {
141
+ "content": "<|fim_middle|>",
142
+ "lstrip": false,
143
+ "normalized": false,
144
+ "rstrip": false,
145
+ "single_word": false,
146
+ "special": false
147
+ },
148
+ "248062": {
149
+ "content": "<|fim_suffix|>",
150
+ "lstrip": false,
151
+ "normalized": false,
152
+ "rstrip": false,
153
+ "single_word": false,
154
+ "special": false
155
+ },
156
+ "248063": {
157
+ "content": "<|fim_pad|>",
158
+ "lstrip": false,
159
+ "normalized": false,
160
+ "rstrip": false,
161
+ "single_word": false,
162
+ "special": false
163
+ },
164
+ "248064": {
165
+ "content": "<|repo_name|>",
166
+ "lstrip": false,
167
+ "normalized": false,
168
+ "rstrip": false,
169
+ "single_word": false,
170
+ "special": false
171
+ },
172
+ "248065": {
173
+ "content": "<|file_sep|>",
174
+ "lstrip": false,
175
+ "normalized": false,
176
+ "rstrip": false,
177
+ "single_word": false,
178
+ "special": false
179
+ },
180
+ "248066": {
181
+ "content": "<tool_response>",
182
+ "lstrip": false,
183
+ "normalized": false,
184
+ "rstrip": false,
185
+ "single_word": false,
186
+ "special": false
187
+ },
188
+ "248067": {
189
+ "content": "</tool_response>",
190
+ "lstrip": false,
191
+ "normalized": false,
192
+ "rstrip": false,
193
+ "single_word": false,
194
+ "special": false
195
+ },
196
+ "248068": {
197
+ "content": "<think>",
198
+ "lstrip": false,
199
+ "normalized": false,
200
+ "rstrip": false,
201
+ "single_word": false,
202
+ "special": false
203
+ },
204
+ "248069": {
205
+ "content": "</think>",
206
+ "lstrip": false,
207
+ "normalized": false,
208
+ "rstrip": false,
209
+ "single_word": false,
210
+ "special": false
211
+ },
212
+ "248070": {
213
+ "content": "<|audio_start|>",
214
+ "lstrip": false,
215
+ "normalized": false,
216
+ "rstrip": false,
217
+ "single_word": false,
218
+ "special": true
219
+ },
220
+ "248071": {
221
+ "content": "<|audio_end|>",
222
+ "lstrip": false,
223
+ "normalized": false,
224
+ "rstrip": false,
225
+ "single_word": false,
226
+ "special": true
227
+ },
228
+ "248072": {
229
+ "content": "<tts_pad>",
230
+ "lstrip": false,
231
+ "normalized": false,
232
+ "rstrip": false,
233
+ "single_word": false,
234
+ "special": true
235
+ },
236
+ "248073": {
237
+ "content": "<tts_text_bos>",
238
+ "lstrip": false,
239
+ "normalized": false,
240
+ "rstrip": false,
241
+ "single_word": false,
242
+ "special": true
243
+ },
244
+ "248074": {
245
+ "content": "<tts_text_eod>",
246
+ "lstrip": false,
247
+ "normalized": false,
248
+ "rstrip": false,
249
+ "single_word": false,
250
+ "special": true
251
+ },
252
+ "248075": {
253
+ "content": "<tts_text_bos_single>",
254
+ "lstrip": false,
255
+ "normalized": false,
256
+ "rstrip": false,
257
+ "single_word": false,
258
+ "special": true
259
+ },
260
+ "248076": {
261
+ "content": "<|audio_pad|>",
262
+ "lstrip": false,
263
+ "normalized": false,
264
+ "rstrip": false,
265
+ "single_word": false,
266
+ "special": true
267
+ }
268
+ },
269
+ "additional_special_tokens": [
270
+ "<|im_start|>",
271
+ "<|im_end|>",
272
+ "<|object_ref_start|>",
273
+ "<|object_ref_end|>",
274
+ "<|box_start|>",
275
+ "<|box_end|>",
276
+ "<|quad_start|>",
277
+ "<|quad_end|>",
278
+ "<|vision_start|>",
279
+ "<|vision_end|>",
280
+ "<|vision_pad|>",
281
+ "<|image_pad|>",
282
+ "<|video_pad|>"
283
+ ],
284
+ "bos_token": null,
285
+ "chat_template": "{%- set image_count = namespace(value=0) %}\n{%- set video_count = namespace(value=0) %}\n{%- macro render_content(content, do_vision_count, is_system_content=false) %}\n {%- if content is string %}\n {{- content }}\n {%- elif content is iterable and content is not mapping %}\n {%- for item in content %}\n {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain images.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set image_count.value = image_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Picture ' ~ image_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|image_pad|><|vision_end|>' }}\n {%- elif 'video' in item or item.type == 'video' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain videos.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set video_count.value = video_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Video ' ~ video_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|video_pad|><|vision_end|>' }}\n {%- elif 'text' in item %}\n {{- item.text }}\n {%- else %}\n {{- raise_exception('Unexpected item type in content.') }}\n {%- endif %}\n {%- endfor %}\n {%- elif content is none or content is undefined %}\n {{- '' }}\n {%- else %}\n {{- raise_exception('Unexpected content type.') }}\n {%- endif %}\n{%- endmacro %}\n{%- if not messages %}\n {{- raise_exception('No messages provided.') }}\n{%- endif %}\n{%- if tools and tools is iterable and tools is not mapping %}\n {{- '<|im_start|>system\\n' }}\n {{- \"# Tools\\n\\nYou have access to the following functions:\\n\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\" }}\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n<tool_call>\\n<function=example_function_name>\\n<parameter=example_parameter_1>\\nvalue_1\\n</parameter>\\n<parameter=example_parameter_2>\\nThis is the value for the second parameter\\nthat can span\\nmultiple lines\\n</parameter>\\n</function>\\n</tool_call>\\n\\n<IMPORTANT>\\nReminder:\\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\\n- Required parameters MUST be specified\\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\\n</IMPORTANT>' }}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {%- if content %}\n {{- '\\n\\n' + content }}\n {%- endif %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {{- '<|im_start|>system\\n' + content + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" %}\n {%- set content = render_content(message.content, false)|trim %}\n {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if ns.multi_step_tool %}\n {{- raise_exception('No user query found in messages.') }}\n{%- endif %}\n{%- for message in messages %}\n {%- set content = render_content(message.content, true)|trim %}\n {%- if message.role == \"system\" %}\n {%- if not loop.first %}\n {{- raise_exception('System message must be at the beginning.') }}\n {%- endif %}\n {%- elif message.role == \"user\" %}\n {{- '<|im_start|>' + message.role + '\\n' + content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- if '</think>' in content %}\n {%- set reasoning_content = content.split('</think>')[0].rstrip('\\n').split('<think>')[-1].lstrip('\\n') %}\n {%- set content = content.split('</think>')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- set reasoning_content = reasoning_content|trim %}\n {%- if loop.index0 > ns.last_query_index %}\n {{- '<|im_start|>' + message.role + '\\n<think>\\n' + reasoning_content + '\\n</think>\\n\\n' + content }}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {%- if loop.first %}\n {%- if content|trim %}\n {{- '\\n\\n<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- else %}\n {{- '<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- endif %}\n {%- else %}\n {{- '\\n<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- endif %}\n {%- if tool_call.arguments is defined %}\n {%- for args_name, args_value in tool_call.arguments|items %}\n {{- '<parameter=' + args_name + '>\\n' }}\n {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}\n {{- args_value }}\n {{- '\\n</parameter>\\n' }}\n {%- endfor %}\n {%- endif %}\n {{- '</function>\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.previtem and loop.previtem.role != \"tool\" %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- content }}\n {{- '\\n</tool_response>' }}\n {%- if not loop.last and loop.nextitem.role != \"tool\" %}\n {{- '<|im_end|>\\n' }}\n {%- elif loop.last %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- else %}\n {{- raise_exception('Unexpected message role.') }}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if enable_thinking is defined and enable_thinking is false %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- else %}\n {{- '<think>\\n' }}\n {%- endif %}\n{%- endif %}",
286
+ "clean_up_tokenization_spaces": false,
287
+ "eos_token": "<|im_end|>",
288
+ "errors": "replace",
289
+ "model_max_length": 262144,
290
+ "pad_token": "<|endoftext|>",
291
+ "split_special_tokens": false,
292
+ "tokenizer_class": "Qwen2Tokenizer",
293
+ "unk_token": null,
294
+ "add_bos_token": false,
295
+ "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
296
+ "extra_special_tokens": {
297
+ "audio_bos_token": "<|audio_start|>",
298
+ "audio_eos_token": "<|audio_end|>",
299
+ "audio_token": "<|audio_pad|>",
300
+ "image_token": "<|image_pad|>",
301
+ "video_token": "<|video_pad|>",
302
+ "vision_bos_token": "<|vision_start|>",
303
+ "vision_eos_token": "<|vision_end|>"
304
+ }
305
+ }
video_preprocessor_config.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "size": {
3
+ "longest_edge": 25165824,
4
+ "shortest_edge": 4096
5
+ },
6
+ "patch_size": 16,
7
+ "temporal_patch_size": 2,
8
+ "merge_size": 2,
9
+ "image_mean": [
10
+ 0.5,
11
+ 0.5,
12
+ 0.5
13
+ ],
14
+ "image_std": [
15
+ 0.5,
16
+ 0.5,
17
+ 0.5
18
+ ],
19
+ "processor_class": "Qwen3VLProcessor",
20
+ "video_processor_type": "Qwen3VLVideoProcessor"
21
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff