Image Feature Extraction
Transformers
Safetensors
motif_vision
feature-extraction
motif
vision-transformer
self-supervised
video
custom_code
Instructions to use Motif-Technologies/Motif-Vision-Encoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Motif-Technologies/Motif-Vision-Encoder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-feature-extraction", model="Motif-Technologies/Motif-Vision-Encoder", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Motif-Technologies/Motif-Vision-Encoder", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Initial release: MOTIF vision encoder 7B (bf16 safetensors + modeling_motif.py)
Browse filesFiles changed (10)
- LICENSEAdded+202
- README.mdAdded+124
- config.jsonAdded+36
- model-00001-of-00004.safetensorsAdded+3
- model-00002-of-00004.safetensorsAdded+3
- model-00003-of-00004.safetensorsAdded+3
- model-00004-of-00004.safetensorsAdded+3
- model.safetensors.index.jsonAdded+780
- modeling_motif.pyAdded+1671
- preprocessor_config.jsonAdded+27
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124---license: apache-2.0library_name: transformerspipeline_tag: image-feature-extractiontags: - motif - vision-transformer - self-supervised - image-feature-extraction - video - custom_code---
# MOTIF Vision Encoder
MOTIF Vision Encoder is a **unified image + video** self-supervised vision encoder on a ViTbackbone. A single **3D-convolutional tokenizer** ingests both modalities — an image is a1-frame clip (`T=1`), a video is `T>1` — so the same weights produce **dense patch-levelfeatures** and a **language-aligned global (CLS) representation**.
- **Architecture**: ViT-7B (embed 4096 / depth 40 / heads 32), patch 16, 3D axial RoPE (`base=100`), SwiGLU FFN, LayerScale, per-head QK-norm, gated attention, 4 register tokens.- **Tokenizer**: `Conv3d(kernel=stride=(tubelet, patch, patch))` — image `(B,3,H,W)` → `T=1`, video `(B,T,3,H,W)`. Token layout `[CLS] + [register × 4] + [patch × N]`.- **This repo**: inference-only. Weights + self-contained `modeling_motif.py` (loaded via `trust_remote_code`). Training/eval code lives in the GitHub repo.
## Usage
The model ships a self-contained `modeling_motif.py`, so it loads with `trust_remote_code=True`.
### Image
```pythonimport torchfrom transformers import AutoImageProcessor, AutoModelfrom transformers.image_utils import load_image
url = "http://images.cocodataset.org/val2017/000000039769.jpg"image = load_image(url)
repo = "Motif-Technologies/motif-vision-encoder-7B"processor = AutoImageProcessor.from_pretrained(repo)model = AutoModel.from_pretrained(repo, trust_remote_code=True, dtype=torch.bfloat16).to("cuda").eval()
inputs = processor(images=image, return_tensors="pt").to(model.device, torch.bfloat16)with torch.inference_mode(): outputs = model(**inputs)
outputs.last_hidden_state # (1, 1 + 4 + N, 4096) CLS + registers + patch tokensoutputs.pooler_output # (1, 4096) global (CLS) representation
patch_tokens = outputs.last_hidden_state[:, 5:, :] # (1, N, 4096), N = (H/16)*(W/16)```
The processor resizes the shorter side to 512, center-crops to 512×512, and normalizes withImageNet mean/std (BICUBIC). `H`/`W` must be multiples of 16.
### Video
An image is a 1-frame clip; a video is the same call with a `(B, T, 3, H, W)` tensor. Apply thesame per-frame transform (resize → center-crop → ImageNet norm) and stack over time:
```pythonimport torch
video = torch.randn(1, 8, 3, 256, 256, device="cuda", dtype=torch.bfloat16) # (B, T, 3, H, W)with torch.inference_mode(): outputs = model(pixel_values=video)```
## Model details
| | ||---|---|| Backbone | ViT-7B, patch 16, embed 4096, depth 40, heads 32, SwiGLU || Register tokens | 4 || Position encoding | 3D axial RoPE (T,H,W), `base=100.0` || Video tokenizer | 3D Conv, tubelet size 2 || Precision | bf16 weights || Training | DINO + iBOT + KoLeo self-distillation, Gram anchoring, contrastive caption alignment |
Outputs (`BaseModelOutputWithPooling`): `last_hidden_state` `(B, 1+4+N, 4096)`,`pooler_output` `(B, 4096)`.
## Evaluation
Compared against the strongest publicly reported self-supervised / vision backbones. Higher isbetter for every column **except KITTI depth MSE** (lower is better). Best value per column in**bold**.
| Model | Params | ImageNet-1K<br>lin. probe ↑ | ADE20K<br>mIoU ↑ | DAVIS<br>J&F ↑ | K400 ↑ | KITTI<br>depth MSE ↓ ||---|---|---|---|---|---|---|| **Motif Vision Encoder** | **7B** | 87.2 | 52.0 | **71.7** | *in progress* | *in progress* || DINOv3 | 7B | **88.2** | **55.9** | 71.1 | **87.8** | **2.3** || DINOv2 | 1.1B | 86.5 | 49.0 | 63.9 | 84.4 | – || V-JEPA 2.1 | 2B | 85.5 | 47.9 | 69.0 | 87.7 | 3.x || SigLIP2 | 2B | 84.5 | 45.4 | 56.1 | 86.9 | – |
- **DAVIS video segmentation (J&F 71.7)** — best in the table, surpassing DINOv3 7B (71.1), reflecting the encoder's dense, temporally-coherent patch features on video.- **ImageNet-1K linear probe (87.2)** and **ADE20K semantic segmentation (52.0 mIoU)** are second only to DINOv3 7B while ahead of DINOv2, V-JEPA 2.1, and SigLIP2.- K400 action recognition and KITTI depth estimation are still being evaluated and will be added as the runs complete.
Protocol: DINOv3-style linear/attentive probes for image tasks; V-JEPA 2-style protocol forvideo. Comparison numbers are the best figures reported by each model's authors.
## License
Released under **Apache-2.0** (see `LICENSE`). The model was trained on data governed by therespective dataset licenses; downstream users are responsible for compliance with those terms.
## Citation
```bibtex@misc{motif_vision_encoder, title = {MOTIF Vision Encoder: a unified image/video self-supervised vision encoder}, author = {Motif Technologies}, year = {2026}, howpublished = {\url{https://huggingface.co/Motif-Technologies/motif-vision-encoder-7B}}}```123456789101112131415161718192021222324252627282930313233343536{ "architectures": [ "MotifVisionModel" ], "auto_map": { "AutoConfig": "modeling_motif.MotifVisionConfig", "AutoModel": "modeling_motif.MotifVisionModel" }, "depth": 40, "drop_path_rate": 0.0, "dtype": "bfloat16", "embed_dim": 4096, "ffn_bias": true, "ffn_layer": "swiglu64", "ffn_ratio": 3.0, "gated_attention": "elementwise", "img_size": 512, "in_chans": 3, "layerscale_init": 1e-05, "mask_k_bias": true, "model_type": "motif_vision", "n_storage_tokens": 4, "norm_layer": "layernormbf16", "num_frames": 1, "num_heads": 32, "patch_size": 16, "pos_embed_rope_base": 100.0, "pos_embed_rope_rescale_coords": 2.0, "proj_bias": true, "qk_norm": true, "qkv_bias": false, "transformers_version": "5.8.1", "tubelet_size": 2, "untie_cls_and_patch_norms": false, "untie_global_and_local_cls_norm": true}123version https://git-lfs.github.com/spec/v1oid sha256:7199e2a02cd8547f6e2d4271f51aab282eb3686d938e8eb54bb2af242e81cc8asize 3939675808123version https://git-lfs.github.com/spec/v1oid sha256:ae96352d3961197861bc7b8147d46d589b2d08557f6a2090157f576895a8e202size 3994160376123version https://git-lfs.github.com/spec/v1oid sha256:02a2a4bab1dc9dacc740b8c25aa90a21028a2e0feadfa077a1cd1268e4a7f09csize 3994134520123version https://git-lfs.github.com/spec/v1oid sha256:04f1a7bf84c7c84cff9687f30c07e3982f9411618083d9e4d58c51dac78d202fsize 2853015560123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780{ "metadata": { "total_parameters": 7390451712, "total_size": 14780903552 }, "weight_map": { "backbone.blocks.0.attn.gate_proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.0.attn.gate_proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.0.attn.k_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.0.attn.proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.0.attn.proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.0.attn.q_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.0.attn.qkv.weight": "model-00001-of-00004.safetensors", "backbone.blocks.0.ls1.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.0.ls2.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.0.mlp.w1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.0.mlp.w1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.0.mlp.w2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.0.mlp.w2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.0.mlp.w3.bias": "model-00001-of-00004.safetensors", "backbone.blocks.0.mlp.w3.weight": "model-00001-of-00004.safetensors", "backbone.blocks.0.norm1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.0.norm1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.0.norm2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.0.norm2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.1.attn.gate_proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.1.attn.gate_proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.1.attn.k_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.1.attn.proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.1.attn.proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.1.attn.q_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.1.attn.qkv.weight": "model-00001-of-00004.safetensors", "backbone.blocks.1.ls1.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.1.ls2.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.1.mlp.w1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.1.mlp.w1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.1.mlp.w2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.1.mlp.w2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.1.mlp.w3.bias": "model-00001-of-00004.safetensors", "backbone.blocks.1.mlp.w3.weight": "model-00001-of-00004.safetensors", "backbone.blocks.1.norm1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.1.norm1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.1.norm2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.1.norm2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.10.attn.gate_proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.10.attn.gate_proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.10.attn.k_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.10.attn.proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.10.attn.proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.10.attn.q_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.10.attn.qkv.weight": "model-00001-of-00004.safetensors", "backbone.blocks.10.ls1.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.10.ls2.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.10.mlp.w1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.10.mlp.w1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.10.mlp.w2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.10.mlp.w2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.10.mlp.w3.bias": "model-00002-of-00004.safetensors", "backbone.blocks.10.mlp.w3.weight": "model-00002-of-00004.safetensors", "backbone.blocks.10.norm1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.10.norm1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.10.norm2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.10.norm2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.11.attn.gate_proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.11.attn.gate_proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.11.attn.k_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.11.attn.proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.11.attn.proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.11.attn.q_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.11.attn.qkv.weight": "model-00002-of-00004.safetensors", "backbone.blocks.11.ls1.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.11.ls2.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.11.mlp.w1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.11.mlp.w1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.11.mlp.w2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.11.mlp.w2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.11.mlp.w3.bias": "model-00002-of-00004.safetensors", "backbone.blocks.11.mlp.w3.weight": "model-00002-of-00004.safetensors", "backbone.blocks.11.norm1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.11.norm1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.11.norm2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.11.norm2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.12.attn.gate_proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.12.attn.gate_proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.12.attn.k_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.12.attn.proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.12.attn.proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.12.attn.q_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.12.attn.qkv.weight": "model-00002-of-00004.safetensors", "backbone.blocks.12.ls1.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.12.ls2.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.12.mlp.w1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.12.mlp.w1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.12.mlp.w2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.12.mlp.w2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.12.mlp.w3.bias": "model-00002-of-00004.safetensors", "backbone.blocks.12.mlp.w3.weight": "model-00002-of-00004.safetensors", "backbone.blocks.12.norm1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.12.norm1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.12.norm2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.12.norm2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.13.attn.gate_proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.13.attn.gate_proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.13.attn.k_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.13.attn.proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.13.attn.proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.13.attn.q_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.13.attn.qkv.weight": "model-00002-of-00004.safetensors", "backbone.blocks.13.ls1.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.13.ls2.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.13.mlp.w1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.13.mlp.w1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.13.mlp.w2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.13.mlp.w2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.13.mlp.w3.bias": "model-00002-of-00004.safetensors", "backbone.blocks.13.mlp.w3.weight": "model-00002-of-00004.safetensors", "backbone.blocks.13.norm1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.13.norm1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.13.norm2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.13.norm2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.14.attn.gate_proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.14.attn.gate_proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.14.attn.k_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.14.attn.proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.14.attn.proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.14.attn.q_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.14.attn.qkv.weight": "model-00002-of-00004.safetensors", "backbone.blocks.14.ls1.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.14.ls2.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.14.mlp.w1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.14.mlp.w1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.14.mlp.w2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.14.mlp.w2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.14.mlp.w3.bias": "model-00002-of-00004.safetensors", "backbone.blocks.14.mlp.w3.weight": "model-00002-of-00004.safetensors", "backbone.blocks.14.norm1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.14.norm1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.14.norm2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.14.norm2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.15.attn.gate_proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.15.attn.gate_proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.15.attn.k_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.15.attn.proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.15.attn.proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.15.attn.q_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.15.attn.qkv.weight": "model-00002-of-00004.safetensors", "backbone.blocks.15.ls1.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.15.ls2.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.15.mlp.w1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.15.mlp.w1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.15.mlp.w2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.15.mlp.w2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.15.mlp.w3.bias": "model-00002-of-00004.safetensors", "backbone.blocks.15.mlp.w3.weight": "model-00002-of-00004.safetensors", "backbone.blocks.15.norm1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.15.norm1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.15.norm2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.15.norm2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.16.attn.gate_proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.16.attn.gate_proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.16.attn.k_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.16.attn.proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.16.attn.proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.16.attn.q_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.16.attn.qkv.weight": "model-00002-of-00004.safetensors", "backbone.blocks.16.ls1.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.16.ls2.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.16.mlp.w1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.16.mlp.w1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.16.mlp.w2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.16.mlp.w2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.16.mlp.w3.bias": "model-00002-of-00004.safetensors", "backbone.blocks.16.mlp.w3.weight": "model-00002-of-00004.safetensors", "backbone.blocks.16.norm1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.16.norm1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.16.norm2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.16.norm2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.17.attn.gate_proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.17.attn.gate_proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.17.attn.k_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.17.attn.proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.17.attn.proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.17.attn.q_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.17.attn.qkv.weight": "model-00002-of-00004.safetensors", "backbone.blocks.17.ls1.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.17.ls2.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.17.mlp.w1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.17.mlp.w1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.17.mlp.w2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.17.mlp.w2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.17.mlp.w3.bias": "model-00002-of-00004.safetensors", "backbone.blocks.17.mlp.w3.weight": "model-00002-of-00004.safetensors", "backbone.blocks.17.norm1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.17.norm1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.17.norm2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.17.norm2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.18.attn.gate_proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.18.attn.gate_proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.18.attn.k_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.18.attn.proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.18.attn.proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.18.attn.q_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.18.attn.qkv.weight": "model-00002-of-00004.safetensors", "backbone.blocks.18.ls1.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.18.ls2.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.18.mlp.w1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.18.mlp.w1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.18.mlp.w2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.18.mlp.w2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.18.mlp.w3.bias": "model-00002-of-00004.safetensors", "backbone.blocks.18.mlp.w3.weight": "model-00002-of-00004.safetensors", "backbone.blocks.18.norm1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.18.norm1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.18.norm2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.18.norm2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.19.attn.gate_proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.19.attn.gate_proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.19.attn.k_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.19.attn.proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.19.attn.proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.19.attn.q_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.19.attn.qkv.weight": "model-00002-of-00004.safetensors", "backbone.blocks.19.ls1.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.19.ls2.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.19.mlp.w1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.19.mlp.w1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.19.mlp.w2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.19.mlp.w2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.19.mlp.w3.bias": "model-00002-of-00004.safetensors", "backbone.blocks.19.mlp.w3.weight": "model-00002-of-00004.safetensors", "backbone.blocks.19.norm1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.19.norm1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.19.norm2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.19.norm2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.2.attn.gate_proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.2.attn.gate_proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.2.attn.k_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.2.attn.proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.2.attn.proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.2.attn.q_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.2.attn.qkv.weight": "model-00001-of-00004.safetensors", "backbone.blocks.2.ls1.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.2.ls2.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.2.mlp.w1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.2.mlp.w1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.2.mlp.w2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.2.mlp.w2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.2.mlp.w3.bias": "model-00001-of-00004.safetensors", "backbone.blocks.2.mlp.w3.weight": "model-00001-of-00004.safetensors", "backbone.blocks.2.norm1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.2.norm1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.2.norm2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.2.norm2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.20.attn.gate_proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.20.attn.gate_proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.20.attn.k_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.20.attn.proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.20.attn.proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.20.attn.q_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.20.attn.qkv.weight": "model-00002-of-00004.safetensors", "backbone.blocks.20.ls1.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.20.ls2.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.20.mlp.w1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.20.mlp.w1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.20.mlp.w2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.20.mlp.w2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.20.mlp.w3.bias": "model-00002-of-00004.safetensors", "backbone.blocks.20.mlp.w3.weight": "model-00002-of-00004.safetensors", "backbone.blocks.20.norm1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.20.norm1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.20.norm2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.20.norm2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.21.attn.gate_proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.21.attn.gate_proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.21.attn.k_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.21.attn.proj.bias": "model-00002-of-00004.safetensors", "backbone.blocks.21.attn.proj.weight": "model-00002-of-00004.safetensors", "backbone.blocks.21.attn.q_norm.weight": "model-00002-of-00004.safetensors", "backbone.blocks.21.attn.qkv.weight": "model-00002-of-00004.safetensors", "backbone.blocks.21.ls1.gamma": "model-00002-of-00004.safetensors", "backbone.blocks.21.ls2.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.21.mlp.w1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.21.mlp.w1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.21.mlp.w2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.21.mlp.w2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.21.mlp.w3.bias": "model-00003-of-00004.safetensors", "backbone.blocks.21.mlp.w3.weight": "model-00003-of-00004.safetensors", "backbone.blocks.21.norm1.bias": "model-00002-of-00004.safetensors", "backbone.blocks.21.norm1.weight": "model-00002-of-00004.safetensors", "backbone.blocks.21.norm2.bias": "model-00002-of-00004.safetensors", "backbone.blocks.21.norm2.weight": "model-00002-of-00004.safetensors", "backbone.blocks.22.attn.gate_proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.22.attn.gate_proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.22.attn.k_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.22.attn.proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.22.attn.proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.22.attn.q_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.22.attn.qkv.weight": "model-00003-of-00004.safetensors", "backbone.blocks.22.ls1.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.22.ls2.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.22.mlp.w1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.22.mlp.w1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.22.mlp.w2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.22.mlp.w2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.22.mlp.w3.bias": "model-00003-of-00004.safetensors", "backbone.blocks.22.mlp.w3.weight": "model-00003-of-00004.safetensors", "backbone.blocks.22.norm1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.22.norm1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.22.norm2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.22.norm2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.23.attn.gate_proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.23.attn.gate_proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.23.attn.k_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.23.attn.proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.23.attn.proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.23.attn.q_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.23.attn.qkv.weight": "model-00003-of-00004.safetensors", "backbone.blocks.23.ls1.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.23.ls2.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.23.mlp.w1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.23.mlp.w1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.23.mlp.w2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.23.mlp.w2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.23.mlp.w3.bias": "model-00003-of-00004.safetensors", "backbone.blocks.23.mlp.w3.weight": "model-00003-of-00004.safetensors", "backbone.blocks.23.norm1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.23.norm1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.23.norm2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.23.norm2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.24.attn.gate_proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.24.attn.gate_proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.24.attn.k_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.24.attn.proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.24.attn.proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.24.attn.q_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.24.attn.qkv.weight": "model-00003-of-00004.safetensors", "backbone.blocks.24.ls1.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.24.ls2.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.24.mlp.w1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.24.mlp.w1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.24.mlp.w2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.24.mlp.w2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.24.mlp.w3.bias": "model-00003-of-00004.safetensors", "backbone.blocks.24.mlp.w3.weight": "model-00003-of-00004.safetensors", "backbone.blocks.24.norm1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.24.norm1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.24.norm2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.24.norm2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.25.attn.gate_proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.25.attn.gate_proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.25.attn.k_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.25.attn.proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.25.attn.proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.25.attn.q_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.25.attn.qkv.weight": "model-00003-of-00004.safetensors", "backbone.blocks.25.ls1.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.25.ls2.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.25.mlp.w1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.25.mlp.w1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.25.mlp.w2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.25.mlp.w2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.25.mlp.w3.bias": "model-00003-of-00004.safetensors", "backbone.blocks.25.mlp.w3.weight": "model-00003-of-00004.safetensors", "backbone.blocks.25.norm1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.25.norm1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.25.norm2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.25.norm2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.26.attn.gate_proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.26.attn.gate_proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.26.attn.k_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.26.attn.proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.26.attn.proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.26.attn.q_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.26.attn.qkv.weight": "model-00003-of-00004.safetensors", "backbone.blocks.26.ls1.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.26.ls2.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.26.mlp.w1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.26.mlp.w1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.26.mlp.w2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.26.mlp.w2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.26.mlp.w3.bias": "model-00003-of-00004.safetensors", "backbone.blocks.26.mlp.w3.weight": "model-00003-of-00004.safetensors", "backbone.blocks.26.norm1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.26.norm1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.26.norm2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.26.norm2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.27.attn.gate_proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.27.attn.gate_proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.27.attn.k_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.27.attn.proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.27.attn.proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.27.attn.q_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.27.attn.qkv.weight": "model-00003-of-00004.safetensors", "backbone.blocks.27.ls1.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.27.ls2.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.27.mlp.w1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.27.mlp.w1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.27.mlp.w2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.27.mlp.w2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.27.mlp.w3.bias": "model-00003-of-00004.safetensors", "backbone.blocks.27.mlp.w3.weight": "model-00003-of-00004.safetensors", "backbone.blocks.27.norm1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.27.norm1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.27.norm2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.27.norm2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.28.attn.gate_proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.28.attn.gate_proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.28.attn.k_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.28.attn.proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.28.attn.proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.28.attn.q_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.28.attn.qkv.weight": "model-00003-of-00004.safetensors", "backbone.blocks.28.ls1.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.28.ls2.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.28.mlp.w1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.28.mlp.w1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.28.mlp.w2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.28.mlp.w2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.28.mlp.w3.bias": "model-00003-of-00004.safetensors", "backbone.blocks.28.mlp.w3.weight": "model-00003-of-00004.safetensors", "backbone.blocks.28.norm1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.28.norm1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.28.norm2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.28.norm2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.29.attn.gate_proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.29.attn.gate_proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.29.attn.k_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.29.attn.proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.29.attn.proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.29.attn.q_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.29.attn.qkv.weight": "model-00003-of-00004.safetensors", "backbone.blocks.29.ls1.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.29.ls2.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.29.mlp.w1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.29.mlp.w1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.29.mlp.w2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.29.mlp.w2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.29.mlp.w3.bias": "model-00003-of-00004.safetensors", "backbone.blocks.29.mlp.w3.weight": "model-00003-of-00004.safetensors", "backbone.blocks.29.norm1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.29.norm1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.29.norm2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.29.norm2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.3.attn.gate_proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.3.attn.gate_proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.3.attn.k_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.3.attn.proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.3.attn.proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.3.attn.q_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.3.attn.qkv.weight": "model-00001-of-00004.safetensors", "backbone.blocks.3.ls1.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.3.ls2.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.3.mlp.w1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.3.mlp.w1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.3.mlp.w2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.3.mlp.w2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.3.mlp.w3.bias": "model-00001-of-00004.safetensors", "backbone.blocks.3.mlp.w3.weight": "model-00001-of-00004.safetensors", "backbone.blocks.3.norm1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.3.norm1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.3.norm2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.3.norm2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.30.attn.gate_proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.30.attn.gate_proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.30.attn.k_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.30.attn.proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.30.attn.proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.30.attn.q_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.30.attn.qkv.weight": "model-00003-of-00004.safetensors", "backbone.blocks.30.ls1.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.30.ls2.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.30.mlp.w1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.30.mlp.w1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.30.mlp.w2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.30.mlp.w2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.30.mlp.w3.bias": "model-00003-of-00004.safetensors", "backbone.blocks.30.mlp.w3.weight": "model-00003-of-00004.safetensors", "backbone.blocks.30.norm1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.30.norm1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.30.norm2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.30.norm2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.31.attn.gate_proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.31.attn.gate_proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.31.attn.k_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.31.attn.proj.bias": "model-00003-of-00004.safetensors", "backbone.blocks.31.attn.proj.weight": "model-00003-of-00004.safetensors", "backbone.blocks.31.attn.q_norm.weight": "model-00003-of-00004.safetensors", "backbone.blocks.31.attn.qkv.weight": "model-00003-of-00004.safetensors", "backbone.blocks.31.ls1.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.31.ls2.gamma": "model-00003-of-00004.safetensors", "backbone.blocks.31.mlp.w1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.31.mlp.w1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.31.mlp.w2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.31.mlp.w2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.31.mlp.w3.bias": "model-00003-of-00004.safetensors", "backbone.blocks.31.mlp.w3.weight": "model-00003-of-00004.safetensors", "backbone.blocks.31.norm1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.31.norm1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.31.norm2.bias": "model-00003-of-00004.safetensors", "backbone.blocks.31.norm2.weight": "model-00003-of-00004.safetensors", "backbone.blocks.32.attn.gate_proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.32.attn.gate_proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.32.attn.k_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.32.attn.proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.32.attn.proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.32.attn.q_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.32.attn.qkv.weight": "model-00003-of-00004.safetensors", "backbone.blocks.32.ls1.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.32.ls2.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.32.mlp.w1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.32.mlp.w1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.32.mlp.w2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.32.mlp.w2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.32.mlp.w3.bias": "model-00004-of-00004.safetensors", "backbone.blocks.32.mlp.w3.weight": "model-00004-of-00004.safetensors", "backbone.blocks.32.norm1.bias": "model-00003-of-00004.safetensors", "backbone.blocks.32.norm1.weight": "model-00003-of-00004.safetensors", "backbone.blocks.32.norm2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.32.norm2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.33.attn.gate_proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.33.attn.gate_proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.33.attn.k_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.33.attn.proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.33.attn.proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.33.attn.q_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.33.attn.qkv.weight": "model-00004-of-00004.safetensors", "backbone.blocks.33.ls1.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.33.ls2.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.33.mlp.w1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.33.mlp.w1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.33.mlp.w2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.33.mlp.w2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.33.mlp.w3.bias": "model-00004-of-00004.safetensors", "backbone.blocks.33.mlp.w3.weight": "model-00004-of-00004.safetensors", "backbone.blocks.33.norm1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.33.norm1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.33.norm2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.33.norm2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.34.attn.gate_proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.34.attn.gate_proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.34.attn.k_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.34.attn.proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.34.attn.proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.34.attn.q_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.34.attn.qkv.weight": "model-00004-of-00004.safetensors", "backbone.blocks.34.ls1.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.34.ls2.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.34.mlp.w1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.34.mlp.w1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.34.mlp.w2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.34.mlp.w2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.34.mlp.w3.bias": "model-00004-of-00004.safetensors", "backbone.blocks.34.mlp.w3.weight": "model-00004-of-00004.safetensors", "backbone.blocks.34.norm1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.34.norm1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.34.norm2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.34.norm2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.35.attn.gate_proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.35.attn.gate_proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.35.attn.k_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.35.attn.proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.35.attn.proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.35.attn.q_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.35.attn.qkv.weight": "model-00004-of-00004.safetensors", "backbone.blocks.35.ls1.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.35.ls2.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.35.mlp.w1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.35.mlp.w1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.35.mlp.w2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.35.mlp.w2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.35.mlp.w3.bias": "model-00004-of-00004.safetensors", "backbone.blocks.35.mlp.w3.weight": "model-00004-of-00004.safetensors", "backbone.blocks.35.norm1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.35.norm1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.35.norm2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.35.norm2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.36.attn.gate_proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.36.attn.gate_proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.36.attn.k_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.36.attn.proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.36.attn.proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.36.attn.q_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.36.attn.qkv.weight": "model-00004-of-00004.safetensors", "backbone.blocks.36.ls1.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.36.ls2.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.36.mlp.w1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.36.mlp.w1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.36.mlp.w2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.36.mlp.w2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.36.mlp.w3.bias": "model-00004-of-00004.safetensors", "backbone.blocks.36.mlp.w3.weight": "model-00004-of-00004.safetensors", "backbone.blocks.36.norm1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.36.norm1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.36.norm2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.36.norm2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.37.attn.gate_proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.37.attn.gate_proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.37.attn.k_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.37.attn.proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.37.attn.proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.37.attn.q_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.37.attn.qkv.weight": "model-00004-of-00004.safetensors", "backbone.blocks.37.ls1.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.37.ls2.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.37.mlp.w1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.37.mlp.w1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.37.mlp.w2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.37.mlp.w2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.37.mlp.w3.bias": "model-00004-of-00004.safetensors", "backbone.blocks.37.mlp.w3.weight": "model-00004-of-00004.safetensors", "backbone.blocks.37.norm1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.37.norm1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.37.norm2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.37.norm2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.38.attn.gate_proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.38.attn.gate_proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.38.attn.k_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.38.attn.proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.38.attn.proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.38.attn.q_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.38.attn.qkv.weight": "model-00004-of-00004.safetensors", "backbone.blocks.38.ls1.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.38.ls2.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.38.mlp.w1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.38.mlp.w1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.38.mlp.w2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.38.mlp.w2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.38.mlp.w3.bias": "model-00004-of-00004.safetensors", "backbone.blocks.38.mlp.w3.weight": "model-00004-of-00004.safetensors", "backbone.blocks.38.norm1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.38.norm1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.38.norm2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.38.norm2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.39.attn.gate_proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.39.attn.gate_proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.39.attn.k_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.39.attn.proj.bias": "model-00004-of-00004.safetensors", "backbone.blocks.39.attn.proj.weight": "model-00004-of-00004.safetensors", "backbone.blocks.39.attn.q_norm.weight": "model-00004-of-00004.safetensors", "backbone.blocks.39.attn.qkv.weight": "model-00004-of-00004.safetensors", "backbone.blocks.39.ls1.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.39.ls2.gamma": "model-00004-of-00004.safetensors", "backbone.blocks.39.mlp.w1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.39.mlp.w1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.39.mlp.w2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.39.mlp.w2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.39.mlp.w3.bias": "model-00004-of-00004.safetensors", "backbone.blocks.39.mlp.w3.weight": "model-00004-of-00004.safetensors", "backbone.blocks.39.norm1.bias": "model-00004-of-00004.safetensors", "backbone.blocks.39.norm1.weight": "model-00004-of-00004.safetensors", "backbone.blocks.39.norm2.bias": "model-00004-of-00004.safetensors", "backbone.blocks.39.norm2.weight": "model-00004-of-00004.safetensors", "backbone.blocks.4.attn.gate_proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.4.attn.gate_proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.4.attn.k_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.4.attn.proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.4.attn.proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.4.attn.q_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.4.attn.qkv.weight": "model-00001-of-00004.safetensors", "backbone.blocks.4.ls1.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.4.ls2.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.4.mlp.w1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.4.mlp.w1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.4.mlp.w2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.4.mlp.w2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.4.mlp.w3.bias": "model-00001-of-00004.safetensors", "backbone.blocks.4.mlp.w3.weight": "model-00001-of-00004.safetensors", "backbone.blocks.4.norm1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.4.norm1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.4.norm2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.4.norm2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.5.attn.gate_proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.5.attn.gate_proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.5.attn.k_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.5.attn.proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.5.attn.proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.5.attn.q_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.5.attn.qkv.weight": "model-00001-of-00004.safetensors", "backbone.blocks.5.ls1.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.5.ls2.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.5.mlp.w1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.5.mlp.w1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.5.mlp.w2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.5.mlp.w2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.5.mlp.w3.bias": "model-00001-of-00004.safetensors", "backbone.blocks.5.mlp.w3.weight": "model-00001-of-00004.safetensors", "backbone.blocks.5.norm1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.5.norm1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.5.norm2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.5.norm2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.6.attn.gate_proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.6.attn.gate_proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.6.attn.k_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.6.attn.proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.6.attn.proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.6.attn.q_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.6.attn.qkv.weight": "model-00001-of-00004.safetensors", "backbone.blocks.6.ls1.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.6.ls2.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.6.mlp.w1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.6.mlp.w1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.6.mlp.w2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.6.mlp.w2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.6.mlp.w3.bias": "model-00001-of-00004.safetensors", "backbone.blocks.6.mlp.w3.weight": "model-00001-of-00004.safetensors", "backbone.blocks.6.norm1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.6.norm1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.6.norm2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.6.norm2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.7.attn.gate_proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.7.attn.gate_proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.7.attn.k_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.7.attn.proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.7.attn.proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.7.attn.q_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.7.attn.qkv.weight": "model-00001-of-00004.safetensors", "backbone.blocks.7.ls1.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.7.ls2.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.7.mlp.w1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.7.mlp.w1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.7.mlp.w2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.7.mlp.w2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.7.mlp.w3.bias": "model-00001-of-00004.safetensors", "backbone.blocks.7.mlp.w3.weight": "model-00001-of-00004.safetensors", "backbone.blocks.7.norm1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.7.norm1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.7.norm2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.7.norm2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.8.attn.gate_proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.8.attn.gate_proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.8.attn.k_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.8.attn.proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.8.attn.proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.8.attn.q_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.8.attn.qkv.weight": "model-00001-of-00004.safetensors", "backbone.blocks.8.ls1.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.8.ls2.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.8.mlp.w1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.8.mlp.w1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.8.mlp.w2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.8.mlp.w2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.8.mlp.w3.bias": "model-00001-of-00004.safetensors", "backbone.blocks.8.mlp.w3.weight": "model-00001-of-00004.safetensors", "backbone.blocks.8.norm1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.8.norm1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.8.norm2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.8.norm2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.9.attn.gate_proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.9.attn.gate_proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.9.attn.k_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.9.attn.proj.bias": "model-00001-of-00004.safetensors", "backbone.blocks.9.attn.proj.weight": "model-00001-of-00004.safetensors", "backbone.blocks.9.attn.q_norm.weight": "model-00001-of-00004.safetensors", "backbone.blocks.9.attn.qkv.weight": "model-00001-of-00004.safetensors", "backbone.blocks.9.ls1.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.9.ls2.gamma": "model-00001-of-00004.safetensors", "backbone.blocks.9.mlp.w1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.9.mlp.w1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.9.mlp.w2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.9.mlp.w2.weight": "model-00001-of-00004.safetensors", "backbone.blocks.9.mlp.w3.bias": "model-00001-of-00004.safetensors", "backbone.blocks.9.mlp.w3.weight": "model-00001-of-00004.safetensors", "backbone.blocks.9.norm1.bias": "model-00001-of-00004.safetensors", "backbone.blocks.9.norm1.weight": "model-00001-of-00004.safetensors", "backbone.blocks.9.norm2.bias": "model-00001-of-00004.safetensors", "backbone.blocks.9.norm2.weight": "model-00001-of-00004.safetensors", "backbone.cls_token": "model-00001-of-00004.safetensors", "backbone.local_cls_norm.bias": "model-00004-of-00004.safetensors", "backbone.local_cls_norm.weight": "model-00004-of-00004.safetensors", "backbone.mask_token": "model-00001-of-00004.safetensors", "backbone.norm.bias": "model-00004-of-00004.safetensors", "backbone.norm.weight": "model-00004-of-00004.safetensors", "backbone.patch_embed.proj.bias": "model-00001-of-00004.safetensors", "backbone.patch_embed.proj.weight": "model-00001-of-00004.safetensors", "backbone.rope_embed.periods_h": "model-00001-of-00004.safetensors", "backbone.rope_embed.periods_t": "model-00001-of-00004.safetensors", "backbone.rope_embed.periods_w": "model-00001-of-00004.safetensors", "backbone.storage_tokens": "model-00001-of-00004.safetensors" }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671# Copyright (c) Motif Technologies.# Self-contained inference model for MOTIF Vision Encoder (image + video).# Auto-assembled from the training repo's inference path; NO training code."""MOTIF Vision Encoder — unified image/video ViT backbone (inference-only).
Usage: from transformers import AutoModel import torch model = AutoModel.from_pretrained("Motif-Technologies/motif-vision-encoder", trust_remote_code=True).eval() # image: (B, 3, H, W) video: (B, T, 3, H, W) (H,W multiples of 16) out = model(pixel_values=torch.randn(1, 3, 224, 224)) out.last_hidden_state # (B, 1+num_register+N, D) out.pooler_output # (B, D) CLS token"""import mathfrom typing import Callable, Literal
import torchimport torch.nn as nnimport torch.nn.functional as Ffrom torch import Tensor
from transformers import PreTrainedModel, PretrainedConfigfrom transformers.modeling_outputs import BaseModelOutputWithPooling
# ---- utils ----
def cat_keep_shapes(x_list: list[Tensor]) -> tuple[Tensor, list[tuple[int]], list[int]]: """Concatenate list of tensors while preserving their shapes for later reconstruction.""" shapes = [x.shape for x in x_list] num_tokens = [x.select(dim=-1, index=0).numel() for x in x_list] flattened = torch.cat([x.flatten(0, -2) for x in x_list]) return flattened, shapes, num_tokens
def uncat_with_shapes(flattened: Tensor, shapes: list[tuple[int]], num_tokens: list[int]) -> list[Tensor]: """Reverse of cat_keep_shapes: split and reshape flattened tensor back to original shapes.""" outputs_splitted = torch.split_with_sizes(flattened, num_tokens, dim=0) shapes_adjusted = [shape[:-1] + torch.Size([flattened.shape[-1]]) for shape in shapes] outputs_reshaped = [o.reshape(shape) for o, shape in zip(outputs_splitted, shapes_adjusted)] return outputs_reshaped
def named_apply( fn: Callable, module: nn.Module, name: str = "", depth_first: bool = True, include_root: bool = False,) -> nn.Module: """Apply fn to all submodules (in-place, no replacement).""" if not depth_first and include_root: fn(module=module, name=name) for child_name, child_module in module.named_children(): child_name = ".".join((name, child_name)) if name else child_name named_apply( fn=fn, module=child_module, name=child_name, depth_first=depth_first, include_root=True, ) if depth_first and include_root: fn(module=module, name=name) return module
# ---- rms_norm ----
import torchfrom torch import Tensor, nn
class RMSNorm(nn.Module): """Root Mean Square Layer Normalization.
A simpler alternative to LayerNorm that normalizes by RMS without centering.
Args: dim: Number of features. eps: Small constant for numerical stability. """
def __init__( self, dim: int, eps: float = 1e-6, device: torch.device | str | None = None, ) -> None: super().__init__() self.eps = eps self.weight = nn.Parameter(torch.ones(dim, device=device))
def reset_parameters(self) -> None: """Reset weight to ones.""" nn.init.ones_(self.weight)
def forward(self, x: Tensor) -> Tensor: """Apply RMS normalization.""" rms = torch.sqrt(x.pow(2).mean(-1, keepdim=True) + self.eps) return x / rms * self.weight
# ---- layer_scale ----
import torchfrom torch import Tensor, nn
class LayerScale(nn.Module): """Per-channel scaling that allows gradual incorporation of each layer's contribution.
Initializes to a small value (e.g., 1e-5) so that early in training, each layer's contribution is nearly zero, stabilizing deep network training.
Args: dim: Number of channels. init_values: Initial value for all channels. inplace: Whether to apply scaling in-place. device: Device for parameter allocation. """
def __init__( self, dim: int, init_values: float | Tensor = 1e-5, inplace: bool = False, device: torch.device | None = None, ) -> None: super().__init__() self.inplace = inplace self.gamma = nn.Parameter(torch.empty(dim, device=device)) self.init_values = init_values
def reset_parameters(self) -> None: """Reset gamma to initial values.""" nn.init.constant_(self.gamma, self.init_values)
def forward(self, x: Tensor) -> Tensor: """Apply per-channel scaling.""" return x.mul_(self.gamma) if self.inplace else x * self.gamma
# ---- patch_embed ----
import math
import torch.nn as nnfrom torch import Tensor
class PatchEmbed(nn.Module): """Video (5D) or Image (4D) to Patch Embedding via 3D Convolution.
Handles both modalities through a single Conv3d projection: - Image (B, C, H, W): unsqueeze temporal dim -> (B, C, 1, H, W) -> Conv3d - Video (B, T, C, H, W): transpose -> (B, C, T, H, W) -> Conv3d
Output: (B, N_total, embed_dim) N_total = (T // tubelet_size) * (H // patch_size) * (W // patch_size)
Args: img_size: Input image size (used for reference only). patch_size: Spatial patch size in pixels. in_chans: Number of input channels. embed_dim: Output embedding dimension. tubelet_size: Temporal patch size (number of frames per temporal token). flatten_embedding: Whether to flatten spatial dimensions. """
def __init__( self, img_size: int = 224, patch_size: int = 16, in_chans: int = 3, embed_dim: int = 768, tubelet_size: int = 1, flatten_embedding: bool = True, ) -> None: super().__init__() self.img_size = img_size self.patch_size = (patch_size, patch_size) if isinstance(patch_size, int) else patch_size self.tubelet_size = tubelet_size self.flatten_embedding = flatten_embedding self.in_chans = in_chans
# 3D Convolution: kernel and stride = (tubelet_size, patch_h, patch_w) self.proj = nn.Conv3d( in_chans, embed_dim, kernel_size=(tubelet_size, self.patch_size[0], self.patch_size[1]), stride=(tubelet_size, self.patch_size[0], self.patch_size[1]), )
def forward(self, x: Tensor) -> Tensor: """Tokenize input images or videos.
Args: x: Input tensor. Image: (B, C, H, W) or Video: (B, T, C, H, W)
Returns: Patch tokens of shape (B, N_total, embed_dim). """ if x.ndim == 4: # Image: (B, C, H, W) -> (B, C, 1, H, W) x = x.unsqueeze(2) # If tubelet_size > 1, repeat the single frame to match kernel size if self.tubelet_size > 1: x = x.expand(-1, -1, self.tubelet_size, -1, -1) elif x.ndim == 5: # Video: (B, T, C, H, W) -> (B, C, T, H, W) x = x.transpose(1, 2)
# Conv3d Projection -> (B, embed_dim, T', H', W') x = self.proj(x)
if self.flatten_embedding: # Flatten spatial+temporal: (B, embed_dim, N) -> (B, N, embed_dim) x = x.flatten(2).transpose(1, 2)
return x
def reset_parameters(self) -> None: """Reset Conv3d parameters with uniform initialization.""" k = 1 / (self.in_chans * self.tubelet_size * self.patch_size[0] * self.patch_size[1]) nn.init.uniform_(self.proj.weight, -math.sqrt(k), math.sqrt(k)) if self.proj.bias is not None: nn.init.uniform_(self.proj.bias, -math.sqrt(k), math.sqrt(k))
# ---- rope ----
import mathfrom typing import Literal
import numpy as npimport torchfrom torch import Tensor, nn
class RopePositionEmbedding3D(nn.Module): """Full 3D axial RoPE with independent T/H/W frequency bands.
Unlike the original MOTIF implementation which simply repeats 2D spatial angles across temporal frames (making temporal positions indistinguishable), this implementation partitions the head dimension into three axis groups:
D_head = D_T + D_H + D_W (no spare dimensions)
By default, the split is spatial-heavy for SSL (spatial quality is priority): D_T = D_head // 4 (25% temporal) D_H = (D_head - D_T) // 2 (37.5% height) D_W = D_head - D_T - D_H (37.5% width) e.g., D_head=64 → T=16, H=24, W=24
This can be overridden via ``fhw_dim=(D_T, D_H, D_W)`` for full control.
For images (T=1): t=0 for all tokens, making temporal angles constant and the output is equivalent to spatial-only RoPE.
Args: embed_dim: Total embedding dimension. num_heads: Number of attention heads. fhw_dim: Optional explicit (D_T, D_H, D_W) partition. Each must be even. If None, uses the spatial-heavy default described above. base: Frequency base (100.0 for spatial vision convention). min_period: Minimum period (alternative to base). max_period: Maximum period (alternative to base). normalize_coords: How to normalize coordinates. shift_coords: Random shift range during training. jitter_coords: Random jitter multiplier during training. rescale_coords: Random rescale multiplier during training. dtype: Data type for computation. device: Device for parameter allocation. """
def __init__( self, embed_dim: int, *, num_heads: int, fhw_dim: tuple[int, int, int] | None = None, base: float | None = 100.0, min_period: float | None = None, max_period: float | None = None, normalize_coords: Literal["min", "max", "separate"] = "separate", shift_coords: float | None = None, jitter_coords: float | None = None, rescale_coords: float | None = None, dtype: torch.dtype | None = None, device: torch.device | None = None, ) -> None: super().__init__() both_periods = min_period is not None and max_period is not None if (base is None and not both_periods) or (base is not None and both_periods): raise ValueError("Either `base` or `min_period`+`max_period` must be provided.")
D_head = embed_dim // num_heads self.base = base self.min_period = min_period self.max_period = max_period self.D_head = D_head self.normalize_coords = normalize_coords self.shift_coords = shift_coords self.jitter_coords = jitter_coords self.rescale_coords = rescale_coords
# Partition head dimension into 3 groups: T, H, W (no spare) if fhw_dim is not None: self.D_T, self.D_H, self.D_W = fhw_dim assert self.D_T + self.D_H + self.D_W == D_head, ( f"fhw_dim must sum to D_head={D_head}, got {sum(fhw_dim)}" ) else: # Default: spatial-heavy split (SSL prioritizes spatial quality) self.D_T = D_head // 4 # 25% temporal self.D_H = (D_head - self.D_T) // 2 # 37.5% height self.D_W = D_head - self.D_T - self.D_H # 37.5% width assert self.D_T % 2 == 0 and self.D_H % 2 == 0 and self.D_W % 2 == 0, ( f"All axis dims must be even, got T={self.D_T}, H={self.D_H}, W={self.D_W}" )
self.dtype = dtype # Separate period buffers for each axis (n_freqs = D_axis // 2) self.register_buffer( "periods_t", torch.empty(self.D_T // 2, device=device, dtype=dtype), persistent=True, ) self.register_buffer( "periods_h", torch.empty(self.D_H // 2, device=device, dtype=dtype), persistent=True, ) self.register_buffer( "periods_w", torch.empty(self.D_W // 2, device=device, dtype=dtype), persistent=True, ) self._init_weights()
def forward(self, *, T: int = 1, H: int, W: int) -> tuple[Tensor, Tensor]: """Compute 3D axial RoPE sin/cos for (T, H, W) grid.
The head dimension is partitioned as [D_T | D_H | D_W]: - D_T: temporal frequency bands (angles vary with t) - D_H: height frequency bands (angles vary with h) - D_W: width frequency bands (angles vary with w)
For images (T=1), all tokens get t=0, so temporal angles are constant and the output is equivalent to spatial-only RoPE.
Args: T: Number of temporal positions (T_grid = num_frames // tubelet_size). H: Height in patches. W: Width in patches.
Returns: Tuple of (sin, cos), each of shape (T*H*W, D_head). """ device = self.periods_t.device dtype = self.dtype dd = {"device": device, "dtype": dtype}
# 1. Compute normalized coordinates for each axis if T > 1: coords_t = torch.arange(0.5, T, **dd) / T # [T] else: coords_t = torch.tensor([0.5], **dd) # [1] - constant for images
coords_h, coords_w = self._compute_spatial_coords(H, W, **dd)
# Shift to [-1, +1] range coords_t = 2.0 * coords_t - 1.0 # [T] coords_h = 2.0 * coords_h - 1.0 # [H] coords_w = 2.0 * coords_w - 1.0 # [W]
# Apply training-time augmentations to spatial coords only if self.training: coords_h, coords_w = self._augment_spatial_coords(coords_h, coords_w, dd)
# 2. Compute raw angles for each axis (n_freqs = D_axis // 2) angles_t = 2 * math.pi * coords_t[:, None] / self.periods_t[None, :] # [T, D_T//2] angles_h = 2 * math.pi * coords_h[:, None] / self.periods_h[None, :] # [H, D_H//2] angles_w = 2 * math.pi * coords_w[:, None] / self.periods_w[None, :] # [W, D_W//2]
# 3. Build full 3D grid: create (T*H*W, D_head) angle tensor t_idx, h_idx, w_idx = torch.meshgrid( torch.arange(T, device=device), torch.arange(H, device=device), torch.arange(W, device=device), indexing="ij", ) t_idx = t_idx.flatten() # [T*H*W] h_idx = h_idx.flatten() # [T*H*W] w_idx = w_idx.flatten() # [T*H*W]
# Gather per-token raw angles and concatenate to D_head//2 token_angles_t = angles_t[t_idx] # [T*H*W, D_T//2] token_angles_h = angles_h[h_idx] # [T*H*W, D_H//2] token_angles_w = angles_w[w_idx] # [T*H*W, D_W//2] angles_half = torch.cat([token_angles_t, token_angles_h, token_angles_w], dim=-1) # [T*H*W, D_head//2]
# tile(2) on full concat — matches MOTIF 2D RoPE pattern # This ensures rotate_half pairs (dim i ↔ dim i+D//2) have identical angles, # making the rotation orthogonal (preserves dot products in attention). angles = angles_half.tile(2) # [T*H*W, D_head]
cos = torch.cos(angles) sin = torch.sin(angles)
return (sin, cos)
def _compute_spatial_coords(self, H: int, W: int, **dd) -> tuple[Tensor, Tensor]: """Compute normalized spatial coordinates.""" if self.normalize_coords == "max": max_HW = max(H, W) coords_h = torch.arange(0.5, H, **dd) / max_HW coords_w = torch.arange(0.5, W, **dd) / max_HW elif self.normalize_coords == "min": min_HW = min(H, W) coords_h = torch.arange(0.5, H, **dd) / min_HW coords_w = torch.arange(0.5, W, **dd) / min_HW elif self.normalize_coords == "separate": coords_h = torch.arange(0.5, H, **dd) / H coords_w = torch.arange(0.5, W, **dd) / W else: raise ValueError(f"Unknown normalize_coords: {self.normalize_coords}") return coords_h, coords_w
def _augment_spatial_coords( self, coords_h: Tensor, coords_w: Tensor, dd: dict, ) -> tuple[Tensor, Tensor]: """Apply training-time coordinate augmentations to spatial coords.""" if self.shift_coords is not None: shift = torch.empty(2, **dd).uniform_(-self.shift_coords, self.shift_coords) coords_h = coords_h + shift[0] coords_w = coords_w + shift[1] if self.jitter_coords is not None: jitter_max = np.log(self.jitter_coords) jitter = torch.empty(2, **dd).uniform_(-jitter_max, jitter_max).exp() coords_h = coords_h * jitter[0] coords_w = coords_w * jitter[1] if self.rescale_coords is not None: rescale_max = np.log(self.rescale_coords) rescale = torch.empty(1, **dd).uniform_(-rescale_max, rescale_max).exp() coords_h = coords_h * rescale coords_w = coords_w * rescale return coords_h, coords_w
def _compute_periods(self, n_freqs: int, device: torch.device, dtype: torch.dtype | None) -> Tensor: """Compute frequency periods for a single axis.
Args: n_freqs: Number of frequency bands (D_axis // 2). device: Device for tensor allocation. dtype: Data type for computation.
Returns: Tensor of shape (n_freqs,) with logarithmically spaced periods. """ if self.base is not None: return self.base ** ( 2 * torch.arange(n_freqs, device=device, dtype=dtype) / (2 * n_freqs) ) else: base = self.max_period / self.min_period exponents = torch.linspace(0, 1, n_freqs, device=device, dtype=dtype) periods = base**exponents periods = periods / base return periods * self.max_period
def _init_weights(self) -> None: """Initialize frequency periods for all three axes.
Each axis gets its own frequency schedule based on its dimension size: periods[i] = base^(2i / D_axis)
This produces logarithmically spaced periods from 1.0 to base, with more frequencies for axes with more allocated dimensions. """ device = self.periods_t.device dtype = self.dtype
self.periods_t.data = self._compute_periods(self.D_T // 2, device, dtype) self.periods_h.data = self._compute_periods(self.D_H // 2, device, dtype) self.periods_w.data = self._compute_periods(self.D_W // 2, device, dtype)
# ---- attention ----
import math
import torchimport torch.nn.functional as Ffrom torch import Tensor, nn
def rope_rotate_half(x: Tensor) -> Tensor: """Rotate half of the dimensions: [-x2, x1] from [x1, x2].
Args: x: Input tensor of shape (..., D).
Returns: Rotated tensor of shape (..., D). """ x1, x2 = x.chunk(2, dim=-1) return torch.cat([-x2, x1], dim=-1)
def rope_apply(x: Tensor, sin: Tensor, cos: Tensor) -> Tensor: """Apply rotary position embedding to input tensor.
Args: x: Input tensor of shape (..., D). sin: Sine angles of shape (..., D). cos: Cosine angles of shape (..., D).
Returns: Rotated tensor of shape (..., D). """ return (x * cos) + (rope_rotate_half(x) * sin)
class LinearKMaskedBias(nn.Linear): """Linear layer with masked bias for the K component of QKV.
Zeroes out the bias for the K component (middle third of output) to avoid interference with RoPE positional encoding. """
def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) o = self.out_features assert o % 3 == 0 if self.bias is not None: self.register_buffer("bias_mask", torch.full_like(self.bias, fill_value=math.nan))
def forward(self, input: Tensor) -> Tensor: """Forward pass with masked bias.""" masked_bias = self.bias * self.bias_mask.to(self.bias.dtype) if self.bias is not None else None return F.linear(input, self.weight, masked_bias)
class SelfAttention(nn.Module): """Multi-head self-attention with RoPE support.
Uses torch.nn.functional.scaled_dot_product_attention for FlashAttention compatibility. RoPE is applied to Q and K on patch tokens only (not CLS/register).
Args: dim: Model dimension. num_heads: Number of attention heads. qkv_bias: Whether to use bias in QKV projection. proj_bias: Whether to use bias in output projection. attn_drop: Attention dropout probability. proj_drop: Output projection dropout probability. mask_k_bias: Whether to mask K bias (for RoPE compatibility). device: Device for parameter allocation. gated_attention: Gated attention variant. None disables gating, "headwise" applies a per-head scalar gate, "elementwise" applies a per-element gate. Gate scores are query-dependent (derived from input) and applied as sigmoid after SDPA. Reference: https://arxiv.org/abs/2505.06708 """
def __init__( self, dim: int, num_heads: int = 8, qkv_bias: bool = False, proj_bias: bool = True, attn_drop: float = 0.0, proj_drop: float = 0.0, mask_k_bias: bool = False, device: str | None = None, gated_attention: str | None = None, qk_norm: bool = False, ) -> None: super().__init__() self.num_heads = num_heads self.head_dim = dim // num_heads self.scale = self.head_dim**-0.5
linear_class = LinearKMaskedBias if mask_k_bias else nn.Linear self.qkv = linear_class(dim, dim * 3, bias=qkv_bias, device=device) self.attn_drop = nn.Dropout(attn_drop) self.proj = nn.Linear(dim, dim, bias=proj_bias, device=device) self.proj_drop = nn.Dropout(proj_drop)
self.qk_norm = qk_norm if qk_norm: self.q_norm = RMSNorm(self.head_dim, device=device) self.k_norm = RMSNorm(self.head_dim, device=device)
self.gated_attention = gated_attention if gated_attention == "headwise": self.gate_proj = nn.Linear(dim, num_heads, bias=True, device=device) elif gated_attention == "elementwise": self.gate_proj = nn.Linear(dim, dim, bias=True, device=device) elif gated_attention is not None: raise ValueError(f"Unknown gated_attention mode: {gated_attention!r}. Use 'headwise' or 'elementwise'.")
def apply_rope( self, q: Tensor, k: Tensor, rope: tuple[Tensor, Tensor], ) -> tuple[Tensor, Tensor]: """Apply RoPE to query and key tensors.
RoPE is applied only to patch tokens (prefix tokens like CLS and register are excluded based on the difference between sequence length and rope length).
Args: q: Query tensor of shape (B, heads, N, D_head). k: Key tensor of shape (B, heads, N, D_head). rope: Tuple of (sin, cos), each of shape (N_patches, D_head).
Returns: Tuple of rotated (q, k) tensors. """ q_dtype = q.dtype k_dtype = k.dtype sin, cos = rope rope_dtype = sin.dtype q = q.to(dtype=rope_dtype) k = k.to(dtype=rope_dtype) N = q.shape[-2] prefix = N - sin.shape[-2] assert prefix >= 0 q_prefix = q[:, :, :prefix, :] q = rope_apply(q[:, :, prefix:, :], sin, cos) q = torch.cat((q_prefix, q), dim=-2) k_prefix = k[:, :, :prefix, :] k = rope_apply(k[:, :, prefix:, :], sin, cos) k = torch.cat((k_prefix, k), dim=-2) q = q.to(dtype=q_dtype) k = k.to(dtype=k_dtype) return q, k
def forward(self, x: Tensor, attn_bias: Tensor | None = None, rope: Tensor | None = None) -> Tensor: """Forward pass for single tensor input.
Args: x: Input tensor of shape (B, N, D). attn_bias: Unused (kept for interface compatibility). rope: Optional RoPE (sin, cos) tuple.
Returns: Output tensor of shape (B, N, D). """ gate_score = self._compute_gate(x) if self.gated_attention else None qkv = self.qkv(x) attn_v = self.compute_attention(qkv=qkv, attn_bias=attn_bias, rope=rope, gate_score=gate_score) x = self.proj(attn_v) x = self.proj_drop(x) return x
def forward_list( self, x_list: list[Tensor], attn_bias: Tensor | None = None, rope_list: list[tuple[Tensor, Tensor]] | None = None, ) -> list[Tensor]: """Forward pass for list of tensors (multi-crop efficiency).
Concatenates inputs for a single QKV projection, then splits for per-crop attention computation (needed because different crops have different RoPE).
Args: x_list: List of input tensors. attn_bias: Unused. rope_list: List of RoPE (sin, cos) tuples, one per input.
Returns: List of output tensors. """ assert len(x_list) == len(rope_list) x_flat, shapes, num_tokens = cat_keep_shapes(x_list) qkv_flat = self.qkv(x_flat) qkv_list = uncat_with_shapes(qkv_flat, shapes, num_tokens)
if self.gated_attention: gate_flat = self._compute_gate(x_flat) gate_list = uncat_with_shapes(gate_flat, shapes, num_tokens) else: gate_list = [None] * len(x_list)
att_out = [] for qkv, _, rope, gate_score in zip(qkv_list, shapes, rope_list, gate_list): att_out.append(self.compute_attention(qkv, attn_bias=attn_bias, rope=rope, gate_score=gate_score)) x_flat, shapes, num_tokens = cat_keep_shapes(att_out) x_flat = self.proj(x_flat) return uncat_with_shapes(x_flat, shapes, num_tokens)
def _compute_gate(self, x: Tensor) -> Tensor: """Compute raw gate scores from input.
Returns the raw projection without reshaping so that the output keeps the same number of leading dimensions as ``x``. This is critical for ``forward_list`` where ``uncat_with_shapes`` must split a 2-D flat tensor back to per-crop 3-D tensors — adding extra dims here would break that reshape. The per-head unflatten happens later inside ``compute_attention`` where B and N are known.
Args: x: Input tensor of shape (..., D). Supports both 2D (flat) and 3D (batched).
Returns: Raw gate projection. Headwise: (..., num_heads). Elementwise: (..., D). """ return self.gate_proj(x)
def compute_attention( self, qkv: Tensor, attn_bias: Tensor | None = None, rope: tuple[Tensor, Tensor] | None = None, gate_score: Tensor | None = None, ) -> Tensor: """Compute scaled dot-product attention.
Args: qkv: Combined QKV tensor of shape (B, N, 3*D). attn_bias: Unused. rope: Optional RoPE (sin, cos) tuple. gate_score: Optional gate tensor from _compute_gate.
Returns: Attention output of shape (B, N, D). """ assert attn_bias is None B, N, _ = qkv.shape C = self.qkv.in_features
qkv = qkv.reshape(B, N, 3, self.num_heads, self.head_dim) q, k, v = torch.unbind(qkv, 2) q, k, v = [t.transpose(1, 2) for t in [q, k, v]] if self.qk_norm: q = self.q_norm(q) k = self.k_norm(k) if rope is not None: q, k = self.apply_rope(q, k, rope) x = torch.nn.functional.scaled_dot_product_attention(q, k, v) x = x.transpose(1, 2) # (B, N, num_heads, head_dim) if gate_score is not None: # _compute_gate returns raw projection: (..., num_heads) or (..., D). # Reshape to (B, N, num_heads, 1) or (B, N, num_heads, head_dim) here. if self.gated_attention == "headwise": gate_score = gate_score.unflatten(-1, (self.num_heads, 1)) else: # elementwise gate_score = gate_score.unflatten(-1, (self.num_heads, self.head_dim)) x = x * torch.sigmoid(gate_score) return x.reshape([B, N, C])
# ---- ffn ----
from typing import Callable
import torch.nn.functional as Ffrom torch import Tensor, nn
class ListForwardMixin: """Mixin providing forward_list for efficient multi-crop processing."""
def forward(self, x: Tensor) -> Tensor: """Forward pass for a single tensor.""" raise NotImplementedError
def forward_list(self, x_list: list[Tensor]) -> list[Tensor]: """Forward pass for a list of tensors, concatenated for efficiency.""" x_flat, shapes, num_tokens = cat_keep_shapes(x_list) x_flat = self.forward(x_flat) return uncat_with_shapes(x_flat, shapes, num_tokens)
class SwiGLUFFN(nn.Module, ListForwardMixin): """SwiGLU Feed-Forward Network: w3(silu(w1(x)) * w2(x)).
Used for larger ViT models (SO400M+) due to better gradient flow. Hidden dimension is aligned to a multiple of `align_to` for GPU efficiency.
Args: in_features: Input dimension. hidden_features: Hidden dimension before alignment. out_features: Output dimension (default: same as in_features). act_layer: Unused (SwiGLU has built-in SiLU activation). drop: Unused (no dropout in SwiGLU). bias: Whether to use bias in linear layers. align_to: Align hidden dimension to this multiple. device: Device for parameter allocation. """
def __init__( self, in_features: int, hidden_features: int | None = None, out_features: int | None = None, act_layer: Callable[..., nn.Module] | None = None, drop: float = 0.0, bias: bool = True, align_to: int = 8, device: str | None = None, ) -> None: super().__init__() out_features = out_features or in_features hidden_features = hidden_features or in_features d = int(hidden_features * 2 / 3) swiglu_hidden_features = d + (-d % align_to) self.w1 = nn.Linear(in_features, swiglu_hidden_features, bias=bias, device=device) self.w2 = nn.Linear(in_features, swiglu_hidden_features, bias=bias, device=device) self.w3 = nn.Linear(swiglu_hidden_features, out_features, bias=bias, device=device)
def forward(self, x: Tensor) -> Tensor: """Forward pass: w3(silu(w1(x)) * w2(x)).""" x1 = self.w1(x) x2 = self.w2(x) hidden = F.silu(x1) * x2 return self.w3(hidden)
# ---- block ----
from typing import Callable
import torchfrom torch import Tensor, nn
torch._dynamo.config.automatic_dynamic_shapes = Falsetorch._dynamo.config.accumulated_cache_size_limit = 1024# Per-code-object recompile cap (default 8). With dynamic=False + fullgraph=True,# every distinct input shape forces a static recompile of the block. Gram adds the# Gram-teacher forward at gram_teacher_crops_size (e.g. 768/1152) on top of the# 512/768 image + video + local-crop shapes, pushing the distinct-shape count past# 8 → FailOnRecompileLimitHit (hard crash, not the eager-fallback warning seen when# fullgraph=False). Raise the cap so all Gram shapes compile; the accumulated cap# (1024) still bounds total graphs. Only the shapes that actually occur are compiled,# so a high cap costs nothing when Gram is off.torch._dynamo.config.recompile_limit = 64
class SelfAttentionBlock(nn.Module): """Pre-norm transformer block: Norm -> Attention -> LayerScale -> DropPath -> Residual.
Supports both single-tensor and list-of-tensors forward for efficient multi-crop processing during MOTIF training.
Args: dim: Model dimension. num_heads: Number of attention heads. ffn_ratio: FFN hidden dimension ratio. qkv_bias: Whether to use bias in QKV projection. proj_bias: Whether to use bias in output projection. ffn_bias: Whether to use bias in FFN layers. drop: Dropout probability. attn_drop: Attention dropout probability. init_values: LayerScale initial values (None disables LayerScale). drop_path: Stochastic depth drop probability. act_layer: Activation function class. norm_layer: Normalization layer class. attn_class: Attention class. ffn_layer: FFN class. mask_k_bias: Whether to mask K bias. device: Device for parameter allocation. """
def __init__( self, dim: int, num_heads: int, ffn_ratio: float = 4.0, qkv_bias: bool = False, proj_bias: bool = True, ffn_bias: bool = True, drop: float = 0.0, attn_drop: float = 0.0, init_values: float | None = None, drop_path: float = 0.0, act_layer: Callable[..., nn.Module] = nn.GELU, norm_layer: Callable[..., nn.Module] = nn.LayerNorm, attn_class: Callable[..., nn.Module] = SelfAttention, ffn_layer: Callable[..., nn.Module] = SwiGLUFFN, mask_k_bias: bool = False, device: str | None = None, gated_attention: str | None = None, qk_norm: bool = False, ) -> None: super().__init__() self.norm1 = norm_layer(dim) self.attn = attn_class( dim, num_heads=num_heads, qkv_bias=qkv_bias, proj_bias=proj_bias, attn_drop=attn_drop, proj_drop=drop, mask_k_bias=mask_k_bias, device=device, gated_attention=gated_attention, qk_norm=qk_norm, ) self.ls1 = LayerScale(dim, init_values=init_values, device=device) if init_values else nn.Identity()
self.norm2 = norm_layer(dim) mlp_hidden_dim = int(dim * ffn_ratio) self.mlp = ffn_layer( in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop, bias=ffn_bias, device=device, ) self.ls2 = LayerScale(dim, init_values=init_values, device=device) if init_values else nn.Identity()
self.sample_drop_ratio = drop_path
@staticmethod def _maybe_index_rope( rope: tuple[Tensor, Tensor] | None, indices: Tensor, ) -> tuple[Tensor, Tensor] | None: """Optionally index into RoPE embeddings for stochastic depth.""" if rope is None: return None sin, cos = rope assert sin.ndim == cos.ndim if sin.ndim == 4: return sin[indices], cos[indices] else: return sin, cos
def _forward_list(self, x_list: list[Tensor], rope_list: list | None = None) -> list[Tensor]: """Forward pass for list of tensors with stochastic depth support.
Concatenates tokens from multiple inputs for efficient elementwise operations, then splits for per-input attention computation (different RoPE per crop). """ b_list = [x.shape[0] for x in x_list] sample_subset_sizes = [max(int(b * (1 - self.sample_drop_ratio)), 1) for b in b_list] residual_scale_factors = [b / s for b, s in zip(b_list, sample_subset_sizes)]
if self.training and self.sample_drop_ratio > 0.0: indices_1_list = [ (torch.randperm(b, device=x.device))[:s] for x, b, s in zip(x_list, b_list, sample_subset_sizes) ] x_subset_1_list = [x[idx] for x, idx in zip(x_list, indices_1_list)]
if rope_list is not None: rope_subset_list = [ self._maybe_index_rope(rope, idx) for rope, idx in zip(rope_list, indices_1_list) ] else: rope_subset_list = rope_list
norm1 = [self.norm1(x) for x in x_subset_1_list] residual_1_list = self.attn.forward_list(norm1, rope_list=rope_subset_list)
x_attn_list = [ torch.index_add( x, dim=0, source=self.ls1(r), index=idx, alpha=scale, ) for x, r, idx, scale in zip(x_list, residual_1_list, indices_1_list, residual_scale_factors) ]
indices_2_list = [ (torch.randperm(b, device=x.device))[:s] for x, b, s in zip(x_list, b_list, sample_subset_sizes) ] x_subset_2_list = [x[idx] for x, idx in zip(x_attn_list, indices_2_list)] norm2_list = [self.norm2(x) for x in x_subset_2_list]
residual_2_list = self.mlp.forward_list(norm2_list)
x_ffn = [ torch.index_add( xa, dim=0, source=self.ls2(r), index=idx, alpha=scale, ) for xa, r, idx, scale in zip(x_attn_list, residual_2_list, indices_2_list, residual_scale_factors) ] else: x_out = [] for x, rope in zip(x_list, rope_list): x_attn = x + self.ls1(self.attn(self.norm1(x), rope=rope)) x_ffn_item = x_attn + self.ls2(self.mlp(self.norm2(x_attn))) x_out.append(x_ffn_item) x_ffn = x_out
return x_ffn
def forward( self, x_or_x_list: Tensor | list[Tensor], rope_or_rope_list: tuple | list | None = None, ) -> Tensor | list[Tensor]: """Forward pass accepting either a single tensor or list of tensors.
Args: x_or_x_list: Single tensor (B, N, D) or list of tensors. rope_or_rope_list: Single RoPE tuple or list of RoPE tuples.
Returns: Output tensor(s) matching input format. """ if isinstance(x_or_x_list, Tensor): return self._forward_list([x_or_x_list], rope_list=[rope_or_rope_list])[0] elif isinstance(x_or_x_list, list): if rope_or_rope_list is None: rope_or_rope_list = [None for _ in x_or_x_list] return self._forward_list(x_or_x_list, rope_list=rope_or_rope_list) else: raise AssertionError(f"Unexpected input type: {type(x_or_x_list)}")
# ---- vision_transformer ----
import loggingfrom functools import partialfrom typing import Any
import torchimport torch.nn.initfrom torch import Tensor, nn
logger = logging.getLogger("motif")
ffn_layer_dict: dict[str, type] = { "swiglu": SwiGLUFFN, "swiglu32": partial(SwiGLUFFN, align_to=32), "swiglu64": partial(SwiGLUFFN, align_to=64), "swiglu128": partial(SwiGLUFFN, align_to=128),}
norm_layer_dict: dict[str, type] = { "layernorm": partial(nn.LayerNorm, eps=1e-6), "layernormbf16": partial(nn.LayerNorm, eps=1e-5), "rmsnorm": RMSNorm,}
dtype_dict: dict[str, torch.dtype] = { "fp32": torch.float32, "fp16": torch.float16, "bf16": torch.bfloat16,}
def init_weights_vit(module: nn.Module, name: str = "") -> None: """Initialize weights for ViT components.
Applied recursively via named_apply to all submodules.
Args: module: Module to initialize. name: Module name (for logging, unused). """ if isinstance(module, nn.Linear): torch.nn.init.trunc_normal_(module.weight, std=0.02) if module.bias is not None: nn.init.zeros_(module.bias) if hasattr(module, "bias_mask") and module.bias_mask is not None: o = module.out_features module.bias_mask.fill_(1) module.bias_mask[o // 3 : 2 * o // 3].fill_(0) if isinstance(module, nn.LayerNorm): module.reset_parameters() if isinstance(module, LayerScale): module.reset_parameters() if isinstance(module, PatchEmbed): module.reset_parameters() if isinstance(module, RMSNorm): module.reset_parameters()
class MotifVisionTransformer(nn.Module): """Vision Transformer backbone with 3D RoPE for unified image/video processing.
Key features: - PatchEmbed (Conv3d) for unified image/video tokenization - Full 3D axial RoPE positional encoding (T/H/W) - CLS token + register (storage) tokens - LayerScale and stochastic depth (DropPath) - MLP or SwiGLU FFN variants - FSDP-compatible (SHARD_GRAD_OP strategy)
Token sequence layout: [CLS] + [Register x n_storage_tokens] + [Patch x N_total]
Args: img_size: Input image size. patch_size: Spatial patch size. in_chans: Number of input channels. embed_dim: Embedding dimension. depth: Number of transformer blocks. num_heads: Number of attention heads. ffn_ratio: FFN hidden dimension ratio. qkv_bias: Whether to use bias in QKV. drop_path_rate: Stochastic depth rate. layerscale_init: LayerScale initial value (None to disable). norm_layer: Normalization layer name. ffn_layer: FFN layer name. ffn_bias: Whether to use bias in FFN. proj_bias: Whether to use bias in attention output projection. n_storage_tokens: Number of register tokens. mask_k_bias: Whether to mask K bias in attention. untie_cls_and_patch_norms: Use separate norms for CLS and patch tokens. untie_global_and_local_cls_norm: Use separate norm for local CLS tokens. device: Device for parameter allocation. num_frames: Number of input video frames. tubelet_size: Temporal patch size for Conv3d. pos_embed_rope_base: RoPE frequency base (100.0 for vision). gated_attention: Gated attention variant (None, "headwise", "elementwise"). See https://arxiv.org/abs/2505.06708. """
def __init__( self, *, img_size: int = 224, patch_size: int = 16, in_chans: int = 3, embed_dim: int = 768, depth: int = 12, num_heads: int = 12, ffn_ratio: float = 4.0, qkv_bias: bool = True, drop_path_rate: float = 0.0, layerscale_init: float | None = None, norm_layer: str = "layernorm", ffn_layer: str = "mlp", ffn_bias: bool = True, proj_bias: bool = True, n_storage_tokens: int = 0, mask_k_bias: bool = False, untie_cls_and_patch_norms: bool = False, untie_global_and_local_cls_norm: bool = False, device: Any | None = None, num_frames: int = 1, tubelet_size: int = 1, pos_embed_rope_base: float = 100.0, pos_embed_rope_rescale_coords: float | None = None, pos_embed_rope_shift_coords: float | None = None, pos_embed_rope_jitter_coords: float | None = None, pos_embed_rope_fhw_dim: tuple[int, int, int] | None = None, gated_attention: str | None = None, qk_norm: bool = False, **ignored_kwargs, ) -> None: super().__init__() if len(ignored_kwargs) > 0: logger.warning(f"Ignored kwargs: {ignored_kwargs}")
norm_layer_cls = norm_layer_dict[norm_layer]
self.num_features = self.embed_dim = embed_dim self.n_blocks = depth self.num_heads = num_heads self.patch_size = patch_size
self.patch_embed = PatchEmbed( img_size=img_size, patch_size=patch_size, in_chans=in_chans, embed_dim=embed_dim, tubelet_size=tubelet_size, flatten_embedding=True, )
self.cls_token = nn.Parameter(torch.empty(1, 1, embed_dim, device=device)) self.n_storage_tokens = n_storage_tokens if self.n_storage_tokens > 0: self.storage_tokens = nn.Parameter(torch.empty(1, n_storage_tokens, embed_dim, device=device))
# Convert 0.0 to None for backward compat (0.0 means disabled) _rescale = pos_embed_rope_rescale_coords if pos_embed_rope_rescale_coords else None _shift = pos_embed_rope_shift_coords if pos_embed_rope_shift_coords else None _jitter = pos_embed_rope_jitter_coords if pos_embed_rope_jitter_coords else None self.rope_embed = RopePositionEmbedding3D( embed_dim=embed_dim, num_heads=num_heads, fhw_dim=pos_embed_rope_fhw_dim, base=pos_embed_rope_base, rescale_coords=_rescale, shift_coords=_shift, jitter_coords=_jitter, )
logger.info(f"using {ffn_layer} layer as FFN") ffn_layer_cls = ffn_layer_dict[ffn_layer] ffn_ratio_sequence = [ffn_ratio] * depth
blocks_list = [ SelfAttentionBlock( dim=embed_dim, num_heads=num_heads, ffn_ratio=ffn_ratio_sequence[i], qkv_bias=qkv_bias, proj_bias=proj_bias, ffn_bias=ffn_bias, drop_path=drop_path_rate, norm_layer=norm_layer_cls, act_layer=nn.GELU, ffn_layer=ffn_layer_cls, init_values=layerscale_init, mask_k_bias=mask_k_bias, device=device, gated_attention=gated_attention, qk_norm=qk_norm, ) for i in range(depth) ]
self.chunked_blocks = False self.blocks = nn.ModuleList(blocks_list)
self.norm = norm_layer_cls(embed_dim)
self.untie_cls_and_patch_norms = untie_cls_and_patch_norms if untie_cls_and_patch_norms: self.cls_norm = norm_layer_cls(embed_dim) else: self.cls_norm = None
self.untie_global_and_local_cls_norm = untie_global_and_local_cls_norm if untie_global_and_local_cls_norm: self.local_cls_norm = norm_layer_cls(embed_dim) else: self.local_cls_norm = None self.head = nn.Identity() self.mask_token = nn.Parameter(torch.empty(1, embed_dim, device=device))
def init_weights(self) -> None: """Initialize all model weights.""" self.rope_embed._init_weights() nn.init.normal_(self.cls_token, std=0.02) if self.n_storage_tokens > 0: nn.init.normal_(self.storage_tokens, std=0.02) nn.init.zeros_(self.mask_token) named_apply(init_weights_vit, self)
def prepare_tokens_with_masks( self, x: Tensor, masks: Tensor | None = None, ) -> tuple[Tensor, tuple[int, int, int]]: """Tokenize input and assemble token sequence with CLS + register + patches.
Args: x: Input tensor. Image: (B, C, H, W) or Video: (B, T, C, H, W). masks: Boolean mask of shape (B, N_spatial) indicating which patches to mask.
Returns: Tuple of: - Token sequence: (B, 1 + n_storage + N_total, embed_dim) - Grid dimensions: (T_grid, H_grid, W_grid) """ if x.ndim == 5: B, T, C, H, W = x.shape # Video: Conv3d kernel=stride=tubelet downsamples raw T to T // tubelet. T_grid = T // self.patch_embed.tubelet_size else: B, C, H, W = x.shape # Image (4D): PatchEmbed expands raw T=1 to tubelet then Conv3d(stride=tubelet) # produces a single temporal token (output T_out = (tubelet - tubelet)/tubelet + 1 = 1). # vjepa2 vision_transformer.py:171-173 passes T=1 (no division) for the same reason. T_grid = 1
x = self.patch_embed(x) # (B, N_total, D)
# Grid dimensions for RoPE computation H_grid = H // self.patch_embed.patch_size[0] W_grid = W // self.patch_embed.patch_size[1]
if masks is not None: # Expand spatial mask to spatio-temporal if needed (tube masking) if masks.shape[1] != x.shape[1]: ratio = x.shape[1] // masks.shape[1] masks = masks.unsqueeze(1).repeat(1, ratio, 1).flatten(1)
# Replace masked positions with mask_token x = torch.where(masks.unsqueeze(-1), self.mask_token.to(x.dtype).unsqueeze(0), x) cls_token = self.cls_token else: # Include mask_token in computation graph even when not masking cls_token = self.cls_token + 0 * self.mask_token
if self.n_storage_tokens > 0: storage_tokens = self.storage_tokens else: storage_tokens = torch.empty( 1, 0, cls_token.shape[-1], dtype=cls_token.dtype, device=cls_token.device, )
x = torch.cat( [ cls_token.expand(B, -1, -1), storage_tokens.expand(B, -1, -1), x, ], dim=1, )
return x, (T_grid, H_grid, W_grid)
def forward_features_list( self, x_list: list[Tensor], masks_list: list[Tensor | None], ) -> list[dict[str, Tensor]]: """Forward pass for a list of inputs (multi-crop).
Args: x_list: List of input tensors (global crops, local crops). masks_list: List of corresponding masks (None for unmasked).
Returns: List of output dictionaries, one per input, containing: - x_norm_clstoken: Normalized CLS token (B, D) - x_storage_tokens: Normalized register tokens (B, n_storage, D) - x_norm_patchtokens: Normalized patch tokens (B, N, D) - x_prenorm: Pre-normalization features (B, 1+n_storage+N, D) - masks: Original masks """ x = [] rope_params = [] for t_x, t_masks in zip(x_list, masks_list): t2_x, grid_tuple = self.prepare_tokens_with_masks(t_x, t_masks) x.append(t2_x) rope_params.append(grid_tuple)
# Pre-compute RoPE sin/cos once — identical across all blocks. # Hoisting this out of the loop avoids breaking FSDP2's forward prefetch # chain (rope_embed is part of the outer FSDP unit, calling it between # block forwards disrupts the prefetch scheduling). if self.rope_embed is not None: rope_sincos = [self.rope_embed(T=t, H=h, W=w) for t, h, w in rope_params] else: rope_sincos = [None for _ in rope_params]
for _, blk in enumerate(self.blocks): x = blk(x, rope_sincos)
all_x = x output = [] for idx, (x, masks) in enumerate(zip(all_x, masks_list)): if self.untie_cls_and_patch_norms or self.untie_global_and_local_cls_norm: if self.untie_global_and_local_cls_norm and self.training and idx == 1: x_norm_cls_reg = self.local_cls_norm(x[:, : self.n_storage_tokens + 1]) elif self.untie_cls_and_patch_norms: x_norm_cls_reg = self.cls_norm(x[:, : self.n_storage_tokens + 1]) else: x_norm_cls_reg = self.norm(x[:, : self.n_storage_tokens + 1]) x_norm_patch = self.norm(x[:, self.n_storage_tokens + 1 :]) else: x_norm = self.norm(x) x_norm_cls_reg = x_norm[:, : self.n_storage_tokens + 1] x_norm_patch = x_norm[:, self.n_storage_tokens + 1 :] output.append( { "x_norm_clstoken": x_norm_cls_reg[:, 0], "x_storage_tokens": x_norm_cls_reg[:, 1:], "x_norm_patchtokens": x_norm_patch, "x_prenorm": x, "masks": masks, } ) return output
def forward_features( self, x: Tensor | list[Tensor], masks: Tensor | list[Tensor | None] | None = None, ) -> dict[str, Tensor] | list[dict[str, Tensor]]: """Forward pass for single or multiple inputs.
Args: x: Single tensor or list of tensors. masks: Single mask or list of masks.
Returns: Output dict (single input) or list of output dicts (multiple inputs). """ if isinstance(x, torch.Tensor): return self.forward_features_list([x], [masks])[0] else: return self.forward_features_list(x, masks)
def _get_intermediate_layers_not_chunked( self, x: Tensor, n: int | list[int] = 1, ) -> list[Tensor]: """Run forward pass and collect intermediate block outputs.
Args: x: Input tensor (B, C, H, W) or (B, T, C, H, W). n: If int, return last n layers. If list, return specific layer indices.
Returns: List of intermediate outputs, each (B, 1+n_storage+N, D). """ x, grid_tuple = self.prepare_tokens_with_masks(x, masks=None) T, H, W = grid_tuple
output, total_block_len = [], len(self.blocks) blocks_to_take = range(total_block_len - n, total_block_len) if isinstance(n, int) else n
if self.rope_embed is not None: rope_sincos = self.rope_embed(T=T, H=H, W=W) else: rope_sincos = None
for i, blk in enumerate(self.blocks): x = blk([x], [rope_sincos])[0] if i in blocks_to_take: output.append(x)
assert len(output) == len(blocks_to_take), ( f"only {len(output)} / {len(blocks_to_take)} blocks found" ) return output
def get_intermediate_layers( self, x: Tensor, n: int | list[int] = 1, reshape: bool = False, return_class_token: bool = False, norm: bool = True, ) -> tuple[Tensor, ...]: """Extract intermediate layer outputs for downstream evaluation.
This method is critical for dense prediction tasks (segmentation, depth) that need multi-scale features from different transformer blocks.
Args: x: Input image (B, C, H, W) or video (B, T, C, H, W). n: If int, return outputs from last n layers. If list[int], return outputs from specific layer indices. reshape: If True, reshape patch tokens to spatial form (B, D, H_grid, W_grid). return_class_token: If True, return (patch_tokens, cls_token) tuples. norm: If True, apply final LayerNorm to outputs.
Returns: If return_class_token is False: Tuple of patch token tensors, one per requested layer. Each tensor is (B, N, D) or (B, D, H_grid, W_grid) if reshape=True. If return_class_token is True: Tuple of (patch_tokens, cls_token) pairs. """ # Determine spatial dims for reshape if x.ndim == 5: B, T_in, C, H, W = x.shape else: B, C, H, W = x.shape T_in = 1
outputs = self._get_intermediate_layers_not_chunked(x, n)
if norm: outputs_normed = [] for out in outputs: if self.untie_cls_and_patch_norms: x_norm_cls_reg = self.cls_norm(out[:, : self.n_storage_tokens + 1]) x_norm_patch = self.norm(out[:, self.n_storage_tokens + 1 :]) outputs_normed.append(torch.cat((x_norm_cls_reg, x_norm_patch), dim=1)) else: outputs_normed.append(self.norm(out)) outputs = outputs_normed
class_tokens = [out[:, 0] for out in outputs] outputs = [out[:, self.n_storage_tokens + 1 :] for out in outputs]
if reshape: # Image (T_in=1): PatchEmbed expands to tubelet then Conv3d(stride=tubelet) → T_out=1. # Video: Conv3d downsamples T_in → T_in // tubelet. Matches prepare_tokens_with_masks # and vjepa2 vision_transformer.py:171-177. if x.ndim == 5: T_grid = T_in // self.patch_embed.tubelet_size else: T_grid = 1 H_grid = H // self.patch_size W_grid = W // self.patch_size if T_grid > 1: # Video: reshape to (B, D, T_grid, H_grid, W_grid) outputs = [ out.reshape(B, T_grid, H_grid, W_grid, -1).permute(0, 4, 1, 2, 3).contiguous() for out in outputs ] else: # Image: reshape to (B, D, H_grid, W_grid) outputs = [ out.reshape(B, H_grid, W_grid, -1).permute(0, 3, 1, 2).contiguous() for out in outputs ]
if return_class_token: return tuple(zip(outputs, class_tokens)) return tuple(outputs)
def forward( self, *args, is_training: bool = False, **kwargs, ) -> dict[str, Tensor] | list[dict[str, Tensor]] | Tensor: """High-level forward: training returns feature dict, inference returns CLS logits.
Args: is_training: If True, return full feature dictionary.
Returns: Feature dict(s) if training, CLS token logits if inference. """ ret = self.forward_features(*args, **kwargs) if is_training: return ret else: return self.head(ret["x_norm_clstoken"])
# ============================================================================# HuggingFace transformers wrapper (inference-only)# ============================================================================class MotifVisionConfig(PretrainedConfig): """Config for the MOTIF Vision Encoder backbone (image + video)."""
model_type = "motif_vision"
def __init__( self, img_size: int = 224, patch_size: int = 16, in_chans: int = 3, embed_dim: int = 4096, depth: int = 40, num_heads: int = 32, ffn_ratio: float = 3.0, qkv_bias: bool = False, drop_path_rate: float = 0.0, layerscale_init: float | None = 1.0e-5, norm_layer: str = "layernormbf16", ffn_layer: str = "swiglu64", ffn_bias: bool = True, proj_bias: bool = True, n_storage_tokens: int = 4, mask_k_bias: bool = True, untie_cls_and_patch_norms: bool = False, untie_global_and_local_cls_norm: bool = True, num_frames: int = 1, tubelet_size: int = 2, pos_embed_rope_base: float = 100.0, pos_embed_rope_rescale_coords: float | None = 2.0, gated_attention: str | None = "elementwise", qk_norm: bool = True, **kwargs, ): self.img_size = img_size self.patch_size = patch_size self.in_chans = in_chans self.embed_dim = embed_dim self.depth = depth self.num_heads = num_heads self.ffn_ratio = ffn_ratio self.qkv_bias = qkv_bias self.drop_path_rate = drop_path_rate self.layerscale_init = layerscale_init self.norm_layer = norm_layer self.ffn_layer = ffn_layer self.ffn_bias = ffn_bias self.proj_bias = proj_bias self.n_storage_tokens = n_storage_tokens self.mask_k_bias = mask_k_bias self.untie_cls_and_patch_norms = untie_cls_and_patch_norms self.untie_global_and_local_cls_norm = untie_global_and_local_cls_norm self.num_frames = num_frames self.tubelet_size = tubelet_size self.pos_embed_rope_base = pos_embed_rope_base self.pos_embed_rope_rescale_coords = pos_embed_rope_rescale_coords self.gated_attention = gated_attention self.qk_norm = qk_norm super().__init__(**kwargs)
class MotifVisionModel(PreTrainedModel): """MOTIF Vision Encoder for HF `AutoModel` (inference). Returns dense + CLS features."""
config_class = MotifVisionConfig base_model_prefix = "motif" main_input_name = "pixel_values" _no_split_modules = ["SelfAttentionBlock"] supports_gradient_checkpointing = False
def __init__(self, config: MotifVisionConfig): super().__init__(config) self.backbone = MotifVisionTransformer( img_size=config.img_size, patch_size=config.patch_size, in_chans=config.in_chans, embed_dim=config.embed_dim, depth=config.depth, num_heads=config.num_heads, ffn_ratio=config.ffn_ratio, qkv_bias=config.qkv_bias, drop_path_rate=config.drop_path_rate, layerscale_init=config.layerscale_init, norm_layer=config.norm_layer, ffn_layer=config.ffn_layer, ffn_bias=config.ffn_bias, proj_bias=config.proj_bias, n_storage_tokens=config.n_storage_tokens, mask_k_bias=config.mask_k_bias, untie_cls_and_patch_norms=config.untie_cls_and_patch_norms, untie_global_and_local_cls_norm=config.untie_global_and_local_cls_norm, num_frames=config.num_frames, tubelet_size=config.tubelet_size, pos_embed_rope_base=config.pos_embed_rope_base, pos_embed_rope_rescale_coords=config.pos_embed_rope_rescale_coords, gated_attention=config.gated_attention, qk_norm=config.qk_norm, ) self.post_init()
@torch.no_grad() def forward(self, pixel_values: Tensor, return_dict: bool = True, **kwargs): """pixel_values: image (B,3,H,W) or video (B,T,3,H,W). H,W multiples of patch_size.""" out = self.backbone.forward_features(pixel_values) cls = out["x_norm_clstoken"] reg = out["x_storage_tokens"] patch = out["x_norm_patchtokens"] last_hidden = torch.cat([cls.unsqueeze(1), reg, patch], dim=1) if not return_dict: return (last_hidden, cls) return BaseModelOutputWithPooling(last_hidden_state=last_hidden, pooler_output=cls)
AutoConfig_registered = Falsetry: from transformers import AutoConfig, AutoModel AutoConfig.register("motif_vision", MotifVisionConfig) AutoModel.register(MotifVisionConfig, MotifVisionModel) AutoConfig_registered = Trueexcept Exception: pass123456789101112131415161718192021222324252627{ "image_processor_type": "BitImageProcessor", "do_resize": true, "size": { "shortest_edge": 512 }, "do_center_crop": true, "crop_size": { "height": 512, "width": 512 }, "do_rescale": true, "rescale_factor": 0.00392156862745098, "do_normalize": true, "image_mean": [ 0.485, 0.456, 0.406 ], "image_std": [ 0.229, 0.224, 0.225 ], "resample": 3, "do_convert_rgb": true}LICENSEAdded+202
README.mdAdded+124
config.jsonAdded+36
model-00001-of-00004.safetensorsAdded+3
model-00002-of-00004.safetensorsAdded+3
model-00003-of-00004.safetensorsAdded+3
model-00004-of-00004.safetensorsAdded+3
model.safetensors.index.jsonAdded+780
modeling_motif.pyAdded+1671
preprocessor_config.jsonAdded+27