Run this model with HF Jobs
Run nvidia/Cosmos-Embed1-336p on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/nvidia/Cosmos-Embed1-336p. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/nvidia/Cosmos-Embed1-336p on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use nvidia/Cosmos-Embed1-336p with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Cosmos
How to use nvidia/Cosmos-Embed1-336p with Cosmos:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- NeMo
How to use nvidia/Cosmos-Embed1-336p with NeMo:
# tag did not correspond to a valid NeMo domain.
- Notebooks
- Google Colab
- Kaggle
First commit
Browse filesFiles changed (27)
- .gitattributes+1
- .gitignoreAdded+5
- README.mdAdded+385
- __init__.pyAdded+14
- added_tokens.jsonAdded+3
- assets/architecture.jpgAdded
- config.jsonAdded+21
- configuration_embed1.pyAdded+69
- convert_weights.pyAdded+64
- examples/example.ipynbAdded
- examples/test_smoke.pyAdded+188
- model-00001-of-00005.safetensorsAdded+3
- model-00002-of-00005.safetensorsAdded+3
- model-00003-of-00005.safetensorsAdded+3
- model-00004-of-00005.safetensorsAdded+3
- model-00005-of-00005.safetensorsAdded+3
- model.safetensors.index.jsonAdded+827
- modeling_embed1.pyAdded+261
- modeling_outputs.pyAdded+69
- modeling_qformer.pyAdded+1060
- modeling_utils.pyAdded+180
- modeling_vit.pyAdded+696
- preprocessing_embed1.pyAdded+133
- processor_config.jsonAdded+9
- special_tokens_map.jsonAdded+44
- tokenizer_config.jsonAdded+69
- vocab.txtAdded
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines3334353632 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text*.jpg filter=lfs diff=lfs merge=lfs -text
12345*.toml*.pyc__pycache__/.ipynb_checkpoints/.hypothesis/123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385---license: otherlicense_name: nvidia-open-model-licenselicense_link: >- https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-open-model-licenselibrary_name: cosmostags:- nvidia- nemo- cosmosextra_gated_prompt: >- # NVIDIA Open Model License Agreement
Version Release Date: January 6, 2025
This NVIDIA Open Model License Agreement (the "<ins>Agreement</ins>") is a legal agreement between the Legal Entity You represent, or if no entity is identified, You and NVIDIA Corporation and its Affiliates ("<ins>NVIDIA</ins>") and governs Your use of the Models that NVIDIA provides to You under this Agreement. NVIDIA and You are each a "<ins>party</ins>" and collectively the "<ins>parties</ins>."
NVIDIA models released under this Agreement are intended to be used permissively and enable the further development of AI technologies. Subject to the terms of this Agreement, NVIDIA confirms that:
* Models are commercially usable.
* You are free to create and distribute Derivative Models.
* NVIDIA does not claim ownership to any outputs generated using the Models or Model Derivatives.
By using, reproducing, modifying, distributing, performing or displaying any portion or element of the Model or Derivative Model, or otherwise accepting the terms of this Agreement, you agree to be bound by this Agreement.
## 1. Definitions
The following definitions apply to this Agreement:
1.1. "<ins>NVIDIA Cosmos Model</ins>" means a multimodal Model shared under this Agreement.
1.2. "<ins>Derivative Model</ins>" means all (a) modifications to the Model, (b) works based on the Model, and (c) any other derivative works of the Model. An output is not a Derivative Model.
1.3. "<ins>Legal Entity</ins>" means the union of the acting entity and all other entities that <ins>control</ins>, are controlled by, or are under common control with that entity. For the purposes of this definition, "<ins>control</ins>" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of fifty percent (50%) or more of the outstanding shares, or (c) beneficial ownership of such entity.
1.4. "<ins>Model</ins>" means the machine learning model, software, checkpoints, learnt weights, algorithms, parameters, configuration files and documentation shared under this Agreement.
1.5. "<ins>You</ins>" or "<ins>Your</ins>" means an individual or Legal Entity exercising permissions granted by this Agreement.
## 2. Conditions for Use, License Grant, AI Ethics and IP Ownership
2.1. Conditions for Use. The Model and any Derivative Model are subject to additional terms as described in Section 2 and Section 3 of this Agreement and govern Your use. If You institute copyright or patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Model or a Derivative Model constitutes direct or contributory copyright or patent infringement, then any licenses granted to You under this Agreement for that Model or Derivative Model will terminate as of the date such litigation is filed. If You bypass, disable, reduce the efficacy of, or circumvent any technical limitation, safety guardrail or associated safety guardrail hyperparameter, encryption, security, digital rights management, or authentication mechanism contained in the Model, your rights under this Agreement will automatically terminate. NVIDIA may update this Agreement to comply with legal and regulatory requirements at any time and You agree to either comply with any updated license or cease Your copying, use, and distribution of the Model and any Derivative Model.
2.2. License Grant. The rights granted herein are explicitly conditioned on Your full compliance with the terms of this Agreement. Subject to the terms and conditions of this Agreement, NVIDIA hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, revocable (as stated in Section 2.1) license to publicly perform, publicly display, reproduce, use, create derivative works of, make, have made, sell, offer for sale, distribute (through multiple tiers of distribution) and import the Model.
2.3. AI Ethics. Use of the Models under the Agreement must be consistent with NVIDIA's Trustworthy AI terms found at https://www.nvidia.com/en-us/agreements/trustworthy-ai/terms/.
2.4. NVIDIA owns the Model and any Model Derivatives created by NVIDIA. Subject to NVIDIA's underlying ownership rights in the Model or its Model Derivatives, You are and will be the owner of Your Model Derivatives. NVIDIA claims no ownership rights in outputs. You are responsible for outputs and their subsequent uses. Except as expressly granted in this Agreement, (a) NVIDIA reserves all rights, interests and remedies in connection with the Model and (b) no other license or right is granted to you by implication, estoppel or otherwise.
## 3. Redistribution
You may reproduce and distribute copies of the Model or Derivative Models thereof in any medium, with or without modifications, provided that You meet the following conditions:
3.1. If you distribute the Model, You must give any other recipients of the Model a copy of this Agreement and include the following attribution notice within a "Notice" text file with such copies: "Licensed by NVIDIA Corporation under the NVIDIA Open Model License";
3.2. If you distribute or make available a NVIDIA Cosmos Model, or a product or service (including an AI model) that contains or uses a NVIDIA Cosmos Model, use a NVIDIA Cosmos Model to create a Derivative Model, or use a NVIDIA Cosmos Model or its outputs to create, train, fine tune, or otherwise improve an AI model, you will include "Built on NVIDIA Cosmos" on a related website, user interface, blogpost, about page, or product documentation; and
3.3. 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 Models as a whole, provided Your use, reproduction, and distribution of the Model otherwise complies with the conditions stated in this Agreement.
## 4. Trademarks
This Agreement does not grant permission to use the trade names, trademarks, service marks, or product names of NVIDIA, except as required for reasonable and customary use in describing the origin of the Model and reproducing the content of the "Notice" text file.
## **5. Disclaimer of Warranty**
**Unless required by applicable law or agreed to in writing, NVIDIA provides the Model 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 Model, Derivative Models and outputs and assume any risks associated with Your exercise of permissions under this Agreement.**
## **6. 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, will NVIDIA be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this Agreement or out of the use or inability to use the Model, Derivative Models or outputs (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 NVIDIA has been advised of the possibility of such damages.**
## 7. Indemnity
You will indemnify and hold harmless NVIDIA from and against any claim by any third party arising out of or related to your use or distribution of the Model, Model Derivatives or outputs.
## 8. Feedback
NVIDIA appreciates your feedback, and You agree that NVIDIA may use it without restriction or compensation to You.
## 9. Governing Law
This Agreement will be governed in all respects by the laws of the United States and the laws of the State of Delaware, without regard to conflict of laws principles or the United Nations Convention on Contracts for the International Sale of Goods. The state and federal courts residing in Santa Clara County, California will have exclusive jurisdiction over any dispute or claim arising out of or related to this Agreement, and the parties irrevocably consent to personal jurisdiction and venue in those courts; except that, either party may apply for injunctive remedies or an equivalent type of urgent legal relief in any jurisdiction.
## 10. Trade and Compliance
You agree to comply with all applicable export, import, trade and economic sanctions laws and regulations, as amended, including without limitation U.S. Export Administration Regulations and Office of Foreign Assets Control regulations. These laws include restrictions on destinations, end-users and end-use.extra_gated_fields: By clicking Submit below, I accept the terms of the NVIDIA Open Model License Agreement and acknowledge that I am an adult of legal age of majority in the country in which the Cosmos Models will be used and have authority to accept this Agreement: checkboxextra_gated_description: >- The information you provide will be collected, stored, processed and shared in accordance with the [NVIDIA Privacy Policy](https://www.nvidia.com/en-us/about-nvidia/privacy-policy/).extra_gated_button_content: Submit---# **Cosmos-Embed1**: A joint video-text embedder for physical AI
[**Website**](https://research.nvidia.com/labs/dir/cosmos-embed1) | [**Hugging Face**](https://huggingface.co/collections/nvidia/cosmos-embed1-6833be2c9575cb89d6901504) | [**Demo app**](https://huggingface.co/spaces/nvidia/Cosmos-Embed1)
# Model Overview
## Description**Cosmos-Embed1** is a joint video-text embedder tailored for physical AI. It can be used for text-to-video retrieval, inverse video search, semantic deduplication, zero-shot and k-nearest-neighbors (kNN) classification, and as a base model for video curation tasks. It has state-of-the-art (SOTA) performance on autonomous vehicle (AV) and robotics datasets, while maintaining competitive performance in general domains. This model is ready for commercial use.
**Model Developer**: NVIDIA
## Model Versions
The Cosmos-Embed1 release includes the following embedders:* **Cosmos-Embed1** * [Cosmos-Embed1-224p](https://huggingface.co/nvidia/Cosmos-Embed1-224p) (optimized with 8 frames and 224x224 input resolution, 256-dim output text and video embeddings) * [Cosmos-Embed1-336p](https://huggingface.co/nvidia/Cosmos-Embed1-336p) (optimized with 8 frames and 336x336 input resolution, 768-dim output text and video embeddings) * [Cosmos-Embed1-448p](https://huggingface.co/nvidia/Cosmos-Embed1-448p) (optimized with 8 frames and 448x448 input resolution, 768-dim output text and video embeddings)
Note, while each checkpoint was optimized at a specific fixed resolution (and default to these), they all support arbitrary non-square resolutions.
### LicenseThis model is released under the [NVIDIA Open Model License](https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-open-model-license). For a custom license, please contact [cosmos-license@nvidia.com](mailto:cosmos-license@nvidia.com).
Under the NVIDIA Open Model License, NVIDIA confirms:
* Models are commercially usable.* You are free to create and distribute Derivative Models.* NVIDIA does not claim ownership to any outputs generated using the Models or Derivative Models.
**Important Note**: If you bypass, disable, reduce the efficacy of, or circumvent any technical limitation, safety guardrail orassociated safety guardrail hyperparameter, encryption, security, digital rights management, or authentication mechanism containedin the Model, your rights under [NVIDIA Open Model License Agreement](https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-open-model-license) will automatically terminate.
### Deployment Geography
Global
### Use Case
Physical AI: encompassing robotics, autonomous vehicles (AV) etc.
### Release Date* HuggingFace: [06/15/2025](https://huggingface.co/collections/nvidia/cosmos-embed1-6833be2c9575cb89d6901504)
## Model Architecture
The architecture is based on [QFormer](https://arxiv.org/abs/2301.12597), with modifications for processing video inputs.
The video embedder processes frames individually with a ViT backbone. The per-frame ViT features are concatenated in the temporal dimension and augmented with temporal embeddings. These are then passed into the QFormer which summarizes via cross-attention a compact set of visual query tokens from the provided frames. The visual query tokens are then pooled into a single video embedding. The text embedder processes tokenized text via the self-attention branch of the Qformer to produce a text embedding.
The normalized text and video embeddings are aligned via a contrastive video-text loss, as well as auxiliary losses such as video-text matching and video captioning. For the 336p and 448p variants, we additionally use summary and dense distillation losses.

## Input/Output Specifications
* **Input**
* **Input Type(s)**: Text+Video * **Input Format(s)**: * Text: UTF-8 string * Video: tensor scaled from 0 to 1 of RGB frame sequences. * **Input Parameters**: * Text: One-dimensional (1D) * Video: Three-dimensional (3D) * **Other Properties Related to Input**: * The input string will be truncated or padded to 128 text tokens. When used for text-to-video (T2V) retrieval, it should contain a short description of the object, scene or action of interest. * Arbitrary, non-square resolutions are supported in the inference code. This can be configured at model loading time. * The model architecture supports input videos of varying lengths, but it has been optimized for 8 frames, sampled at 1-2 frames per second (FPS).
* **Output** * **Output Type(s)**: Text+Video * **Output Format(s)**: * Text: floating-point normalized vector of size 256 (for 224p variant) or 768 (for 336p and 448p variants). * Video: floating-point normalized vector of size 256 (for 224p variant) or 768 (for 336p and 448p variants). * **Output Parameters**: * Text: One-dimensional (1D) * Video: One-dimensional (1D) * **Other Properties Related to Output**: Continuous-valued L2-normalized feature vectors with a dimensionality of 256 or 768. A distance can be calculated between embeddings using cosine distance. Dense intermediate feature maps are also provided for convenience.
Our AI models are designed and/or optimized to run on NVIDIA GPU-accelerated systems. By leveraging NVIDIA’s hardware (e.g. GPU cores) and software frameworks (e.g., CUDA libraries), the model achieves faster training and inference times compared to CPU-only solutions.
## Software Integration**Runtime Engine(s):*** [PyTorch](https://github.com/pytorch/pytorch)* [Transformer Engine](https://github.com/NVIDIA/TransformerEngine)
**Supported Hardware Microarchitecture Compatibility:*** NVIDIA Ampere* NVIDIA Hopper* NVIDIA Blackwell
Note: We have only tested Cosmos-Embed1 with BF16 precision on Ampere and Hopper GPUs. If you are using older versions of NVIDIA GPUs (e.g., NVIDIA Volta GPUs), you may need to switch to FP32 precision.
**Operating System(s)*** Linux (We have not tested on other operating systems.)
# Usage
## Installation
The main model and processor dependencies can be fetched with:```pip install transformers einops torch torchvision```
One can optionally install Transformer Engine for faster inference:```pip install --no-build-isolation transformer_engine[pytorch]```
## Example inference
A code snippet for video and text inference is shown below.For a step-by-step guide, please refer to the Juypter notebook [here](https://huggingface.co/nvidia/Cosmos-Embed1-336p/blob/main/examples/example.ipynb).```import decordimport numpy as npimport torchfrom transformers import AutoProcessor, AutoModelimport subprocessimport io
# load model and pre-processormodel = AutoModel.from_pretrained("nvidia/Cosmos-Embed1-336p", trust_remote_code=True).to("cuda", dtype=torch.bfloat16)preprocess = AutoProcessor.from_pretrained("nvidia/Cosmos-Embed1-336p", trust_remote_code=True)
# load mock datavideo_url = "https://upload.wikimedia.org/wikipedia/commons/3/3d/Branko_Paukovic%2C_javelin_throw.webm"subprocess.check_call(["wget", "-O", "/tmp/javelin_throw.mp4", video_url])reader = decord.VideoReader("/tmp/javelin_throw.mp4")frame_ids = np.linspace(0, len(reader)-1, 8, dtype=int).tolist()frames = reader.get_batch(frame_ids).asnumpy()batch = np.transpose(np.expand_dims(frames, 0), (0, 1, 4, 2, 3)) # BTCHWcaptions = [ "a person riding a motorcycle in the night", "a car overtaking a white truck", "a video of a knight fighting with a sword", "a man wearing red spandex throwing a javelin", "a young man javelin throwing during the evening", # distractor "a man throwing a javelin with both hands", # distractor]
# video and text processingvideo_inputs = preprocess(videos=batch).to("cuda", dtype=torch.bfloat16)video_out = model.get_video_embeddings(**video_inputs)text_inputs = preprocess(text=captions).to("cuda", dtype=torch.bfloat16)text_out = model.get_text_embeddings(**text_inputs)
# ranking and argmaxprobs = (torch.softmax(model.logit_scale.exp() * video_out.visual_proj @ text_out.text_proj.T, dim=-1))[0]print(captions[probs.argmax()])```
# Training and Evaluation
We train and evaluate the **Cosmos-Embed1** models on a variety of video datasets covering zero-shot classification and retrieval.We use public reference training/test splits when available (e.g. Kinetics), otherwise we take a 90/10% split. The training pool is approximately 8m unique videos with multiple curated captions, sampled from robotics, autonomous vehicle, activity recognition and general domains.
**Data Collection Method:*** [AgiBot](https://huggingface.co/datasets/agibot-world/AgiBotWorld-Beta): Automatic/Sensors* [BridgeV2](https://rail-berkeley.github.io/bridgedata/): Automatic/Sensors* [Robonet](https://github.com/SudeepDasari/RoboNet/wiki/Getting-Started): Automatic/Sensors* [DROID](https://droid-dataset.github.io): Automatic/Sensors* [1X](https://huggingface.co/datasets/1x-technologies/world_model_raw_data): Automatic/Sensors* [Kinetics-400/600/700](https://github.com/cvdfoundation/kinetics-dataset): Human* [OpenDV](https://github.com/OpenDriveLab/DriveAGI#opendv-youtube): Automatic/Sensors* AV action recognition (internal): Automatic/Sensors* Curated captioned video dataset (internal): Human
**Labeling Method:*** [AgiBot](https://huggingface.co/datasets/agibot-world/AgiBotWorld-Beta): Automated* [BridgeV2](https://rail-berkeley.github.io/bridgedata/): Automated* [Robonet](https://github.com/SudeepDasari/RoboNet/wiki/Getting-Started): Automated* [DROID](https://droid-dataset.github.io): Automated* [1X](https://huggingface.co/datasets/1x-technologies/world_model_raw_data): Automated* [Kinetics-400/600/700](https://github.com/cvdfoundation/kinetics-dataset): Hybrid: Human, Automated* [OpenDV](https://github.com/OpenDriveLab/DriveAGI#opendv-youtube): Automated* AV action recognition (internal): Hybrid: Human, Automated* Curated captioned video dataset (internal): Automated
## Metrics
* We compare with the state-of-the-art text/video embedders: [InternVideo2-1B](https://huggingface.co/collections/OpenGVLab/internvideo2-6618ccb574bd2f91410df5cd) and [Perception Encoder](https://github.com/facebookresearch/perception_models?tab=readme-ov-file). As input, we use 8 linearly spaced frames per clip and resize to square inputs.* Evaluation metrics: * (Class-Weighted) F1-score for text-video zero-shot classification * Text-to-video (T2V) and video-to-text (V2T) recall at k=1 for multi-modal retrieval, including DSL rerank.
### Robotics| | Agibot | | Bridge | ||------------------------|----------------|---------------|----------------|---------------|| Model Architecture | T2V-R@1 | V2T-R@1 | T2V-R@1 | V2T-R@1 ||| **InternVideo2-1B-S2** | 1.23 | 0.91 | 8.51 | 8.11 || **PE-Core-G14-448** | 1.16 | 0.83 | 7.19 | 5.24 || **Cosmos-Embed1-224** | **4.26** | **4.10** | **23.99** | **23.99** || **Cosmos-Embed1-336** | **7.04** | **6.33** | **24.51** | **22.90** || **Cosmos-Embed1-448** | **7.18** | **6.39** | **24.28** | **23.76** |
### AV| | OpenDV | ||------------------------|----------------|---------------|| Model Architecture | T2V-R@1 | V2T-R@1 ||| **InternVideo2-1B-S2** | 7.40 | 8.06 || **PE-Core-G14-448** | 9.58 | 9.30 || **Cosmos-Embed1-224** | **30.11** | **30.99** || **Cosmos-Embed1-336** | **34.42** | **34.67** || **Cosmos-Embed1-448** | **34.66** | **34.87** |
### General and Action Recognition| | Kinetics-400 (val) | Kinetics-600 (val) | Kinetics-700 (val) ||-------------------------|---------|---------|---------|| Model Architecture | F1 | F1 | F1 ||| **InternVideo2-1B-S2** | 62.80 | 60.20 | 52.18 || **PE-Core-G14-448** | 76.00 | 75.14 | 68.28 || **Cosmos-Embed1-224** | **83.06** | **82.22** | **70.96** || **Cosmos-Embed1-336** | **87.66** | **88.06** | **74.57** || **Cosmos-Embed1-448** | **88.21** | **88.60** | **75.27** |
## Inference
**Acceleration Engine**: PyTorch, Transformer Engine (optional)
**Test Hardware**: H100, A100
## Ethical Considerations
NVIDIA believes Trustworthy AI is a shared responsibility and we have established policies and practices to enable development for a wide array of AI applications. When downloaded or used in accordance with our terms of service, developers should work with their internal model team to ensure this model meets requirements for the relevant industry and use case and addresses unforeseen product misuse.
Users are responsible for model inputs and outputs. Users are responsible for ensuring safe integration of this model, including implementing guardrails as well as other safety mechanisms, prior to deployment.
For more detailed information on ethical considerations for this model, please see the subcards of Explainability, Bias, Safety & Security, and Privacy below.
Please report security vulnerabilities or NVIDIA AI Concerns [here](https://www.nvidia.com/en-us/support/submit-security-vulnerability/).
### Plus Plus (++) Promise
We value you, the datasets, the diversity they represent, and what we have been entrusted with. This model and its associated data have been:* Verified to comply with current applicable disclosure laws, regulations, and industry standards.* Verified to comply with applicable privacy labeling requirements.* Annotated to describe the collector/source (NVIDIA or a third-party).* Characterized for technical limitations.* Reviewed to ensure proper disclosure is accessible to, maintained for, and in compliance with NVIDIA data subjects and their requests.* Reviewed before release.* Tagged for known restrictions and potential safety implications.
### Bias
Field | Response:---------------------------------------------------------------------------------------------------|:---------------Participation considerations from adversely impacted groups [protected classes](https://www.senate.ca.gov/content/protected-classes) in model design and testing: | NoneMeasures taken to mitigate against unwanted bias: | None
### Explainability
Field | Response:------------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------Intended Application & Domain: | Embedding of text and videos for physical AIModel Type: | ViT, QFormerIntended Users: | Physical AI developersOutput: | Text/Video embedding vectorsDescribe how the model works: | Projects inputs into aligned embedding space (text/video).Technical Limitations: | Due to the training datasets being predominantly composed of short action-focused English captions, different text prompts may not be properly aligned to video data, producing suboptimal matching.Verified to have met prescribed NVIDIA quality standards: | YesPerformance Metrics: | Classification metrics (F1-score, accuracy), retrieval metrics (T2V recall@1, V2T recall@1)Potential Known Risks: | Embedder's output can include all forms of input, including what may be considered toxic, offensive, or indecent.Licensing: | [NVIDIA Open Model License](https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-open-model-license)
### PrivacyField | Response:----------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------Generatable or reverse engineerable personal information? | NoHow often is dataset reviewed? | Before ReleaseIs there provenance for all datasets used in training? | YesDoes data labeling (annotation, metadata) comply with privacy laws? | YesApplicable Privacy Policy | https://www.nvidia.com/en-us/about-nvidia/privacy-policy
### Safety
Field | Response:---------------------------------------------------|:----------------------------------Model Application(s): | Embedding of text and videos for physical AI applications (robotics, autonomous vehicles).Describe the life critical impact (if present). | None KnownUse Case Restrictions: | [NVIDIA Open Model License](https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-open-model-license)Model and dataset restrictions: | The Principle of least privilege (PoLP) is applied limiting access for dataset generation and model development. Restrictions enforce dataset access during training, and dataset license constraints adhered to. Model checkpoints are made available on Hugging Face, and may become available on cloud providers' model catalog.1234567891011121314# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0## 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.123{ "[DEC]": 30522}123456789101112131415161718192021{ "architectures": [ "CosmosEmbed1" ], "auto_map": { "AutoConfig": "configuration_embed1.CosmosEmbed1Config", "AutoProcessor": "preprocessing_embed1.CosmosEmbed1Processor", "AutoModel": "modeling_embed1.CosmosEmbed1" }, "embed_dim": 768, "max_txt_len": 128, "model_type": "cosmos-embed1", "num_query_tokens": 32, "num_video_frames": 8, "resolution": 336, "temporal_encoding_type": "neighboring_token_propagation", "transformers_version": "4.51.3", "vocab_size": 30523, "transformer_engine": false, "use_fp8": false}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0## 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.
"""Configuration class for Cosmos-Embed1."""
from typing import Any, Literal, Tuple, Union
from transformers import AutoConfig, PretrainedConfig
class CosmosEmbed1Config(PretrainedConfig): model_type = "cosmos-embed1"
def __init__( self, embed_dim: int = 768, num_query_tokens: int = 32, max_txt_len: int = 128, num_video_frames: int = 8, temporal_encoding_type: Literal[ "neighboring_token_propagation", "temporal_parameter" ] = "neighboring_token_propagation", resolution: Union[int, Tuple[int, int]] = 224, vocab_size: int = 30523, transformer_engine: bool = False, use_fp8: bool = False, **kwargs: Any, ) -> None: """Configuration for `CosmosEmbed1Config`.
Args: embed_dim (int): the dimension of extracted text-visual embeddings. num_query_tokens (int): number of learnable query tokens. max_txt_len (int): max length of text token sequences before truncation. num_video_frames (int): number of input video frames. temporal_encoding_type (str): temporal encoding module type. resolution (Union[int, Tuple[int, int]]): input video frame resolution. Can be an integer for square images (height=width) or a tuple of (height, width) for non-square. vocab_size (int): vocab size for text tokenizer. The default is from `bert-base-uncased` with an extra [DEC] token. transformer_engine (bool): whether to use TransformerEngine for acceleration. use_fp8 (bool): whether to use FP8 precision (requires transformer_engine=True). """ super().__init__(**kwargs)
self.embed_dim = embed_dim self.num_query_tokens = num_query_tokens self.max_txt_len = max_txt_len self.num_video_frames = num_video_frames self.temporal_encoding_type = temporal_encoding_type self.resolution = resolution self.vocab_size = vocab_size self.transformer_engine = transformer_engine self.use_fp8 = use_fp8
AutoConfig.register("cosmos-embed1", CosmosEmbed1Config)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0## 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.
"""Utility to convert weights to safetensors."""
import argparse
import torch
from .configuration_embed1 import CosmosEmbed1Configfrom .modeling_embed1 import CosmosEmbed1
def parse_args(): parser = argparse.ArgumentParser(description="Save model weights with optional format conversion and sharding.") parser.add_argument("--input_weights", type=str, required=True, help="Path to the input .pt weights file") parser.add_argument( "--output_weights", type=str, required=True, help="Path to the output directory where safetensors weights will be saved", ) return parser.parse_args()
def main(): args = parse_args() model = CosmosEmbed1(CosmosEmbed1Config()).to("cuda", dtype=torch.bfloat16)
# remove tensor sharing model.qformer.cls.predictions.decoder.weight = torch.nn.Parameter( model.qformer.cls.predictions.decoder.weight.clone() ) model.qformer.bert.embeddings.word_embeddings.weight = torch.nn.Parameter( model.qformer.bert.embeddings.word_embeddings.weight.clone() ) model.qformer.cls.predictions.decoder.bias = torch.nn.Parameter(model.qformer.cls.predictions.decoder.bias.clone()) model.qformer.cls.predictions.bias = torch.nn.Parameter(model.qformer.cls.predictions.bias.clone())
with open(args.input_weights, "rb") as fp: state_dict = torch.load(fp) model.load_state_dict(state_dict, strict=True)
model.save_pretrained( args.output_weights, safe_serialization=True, max_shard_size="500MB", )
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0## 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.
"""Smoke tests for Cosmos-Embed1 including Transformer Engine support."""
# Determine test model path - can be overridden via environment variable or use current directoryimport os
import pytestimport torchfrom transformers import AutoConfig, AutoModel, AutoProcessor, AutoTokenizer
MODEL_PATH = os.environ.get("COSMOS_EMBED1_MODEL_PATH", ".")
def test_smoke() -> None: """Original smoke test for basic functionality."""
preprocess = AutoProcessor.from_pretrained(MODEL_PATH, trust_remote_code=True) model = AutoModel.from_pretrained(MODEL_PATH, trust_remote_code=True).to("cuda", dtype=torch.bfloat16)
with torch.no_grad(): text_inputs = preprocess(text=["a cat", "a dog"]).to("cuda", dtype=torch.bfloat16) text_out = model.get_text_embeddings(**text_inputs) assert text_out.text_proj.shape == (2, 768)
video_inputs = preprocess(videos=torch.randint(0, 255, size=(2, 8, 3, 224, 224))).to( "cuda", dtype=torch.bfloat16 ) video_out = model.get_video_embeddings(**video_inputs) assert video_out.visual_proj.shape == (2, 768)
text_video_inputs = preprocess( text=["a cat", "a dog"], videos=torch.randint(0, 255, size=(2, 8, 3, 448, 448)), ).to("cuda", dtype=torch.bfloat16) text_video_out = model(**text_video_inputs) assert text_video_out.text_proj.shape == text_video_out.visual_proj.shape == (2, 768)
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, trust_remote_code=True) assert len(tokenizer) == 30523
# Clean up GPU memory after test del model torch.cuda.empty_cache()
def test_transformer_engine_available(): """Test if Transformer Engine is available.""" try: import transformer_engine.pytorch as te
# If we get here, TE is available assert True except ImportError: pytest.skip("Transformer Engine not available, skipping TE tests")
def test_load_standard_model(): """Test loading the standard (non-TE) model.""" model = AutoModel.from_pretrained(MODEL_PATH, trust_remote_code=True, torch_dtype=torch.bfloat16) assert model.transformer_engine == False assert hasattr(model, "visual_encoder") assert hasattr(model, "qformer")
# Clean up del model torch.cuda.empty_cache()
def test_load_transformer_engine_model(): """Test loading model with Transformer Engine enabled.""" try: import transformer_engine.pytorch as te except ImportError: pytest.skip("Transformer Engine not available, skipping TE tests")
# Load config and enable transformer engine config = AutoConfig.from_pretrained(MODEL_PATH) config.transformer_engine = True config.use_fp8 = False # Start with FP8 disabled for basic test
model = AutoModel.from_pretrained(MODEL_PATH, config=config, trust_remote_code=True, torch_dtype=torch.bfloat16)
assert model.transformer_engine == True assert model.use_fp8 == False assert hasattr(model, "visual_encoder") assert hasattr(model, "qformer")
# Clean up del model torch.cuda.empty_cache()
@pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA not available, skipping GPU test")def test_transformer_engine_inference(): """Test inference with Transformer Engine model.""" try: import transformer_engine.pytorch as te except ImportError: pytest.skip("Transformer Engine not available, skipping TE tests")
# Test text embeddings with standard model first preprocess = AutoProcessor.from_pretrained(MODEL_PATH, trust_remote_code=True) text_inputs = preprocess(text=["a cat"]).to("cuda", dtype=torch.bfloat16)
# Load standard model, run inference, then clean up model_standard = AutoModel.from_pretrained(MODEL_PATH, trust_remote_code=True, torch_dtype=torch.bfloat16).to( "cuda" )
with torch.no_grad(): text_out_std = model_standard.get_text_embeddings(**text_inputs)
# Clean up standard model before loading TE model del model_standard torch.cuda.empty_cache()
# Now load TE model and run inference config = AutoConfig.from_pretrained(MODEL_PATH) config.transformer_engine = True config.use_fp8 = False
model_te = AutoModel.from_pretrained( MODEL_PATH, config=config, trust_remote_code=True, torch_dtype=torch.bfloat16 ).to("cuda")
with torch.no_grad(): text_out_te = model_te.get_text_embeddings(**text_inputs)
# Check shapes match assert text_out_std.text_proj.shape == text_out_te.text_proj.shape assert text_out_std.text_proj.shape == (1, 768)
# Clean up GPU memory del model_te torch.cuda.empty_cache()
@pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA not available, skipping GPU test")def test_transformer_engine_fp8(): """Test loading model with Transformer Engine + FP8 (requires substantial GPU memory).""" try: import transformer_engine.pytorch as te except ImportError: pytest.skip("Transformer Engine not available, skipping FP8 tests")
# Clear memory before this memory-intensive test torch.cuda.empty_cache()
config = AutoConfig.from_pretrained(MODEL_PATH) config.transformer_engine = True config.use_fp8 = True
model = AutoModel.from_pretrained(MODEL_PATH, config=config, trust_remote_code=True, torch_dtype=torch.bfloat16)
assert model.transformer_engine == True assert model.use_fp8 == True
# Clean up del model torch.cuda.empty_cache()
def test_transformer_engine_config_validation(): """Test configuration validation for Transformer Engine."""
# Test that use_fp8=True without transformer_engine=True should fail config = AutoConfig.from_pretrained(MODEL_PATH) config.transformer_engine = False config.use_fp8 = True
with pytest.raises(ValueError, match="transformer_engine.*must be enabled.*use_fp8"): from modeling_vit import VisionTransformer
VisionTransformer(transformer_engine=False, use_fp8=True)123version https://git-lfs.github.com/spec/v1oid sha256:80b13abf2bec2afe7d052249eec63ceda98a66c8eb106f84e867b2313e95142asize 490147164123version https://git-lfs.github.com/spec/v1oid sha256:f9b419eb23b420f2811c638fecf54abf1294b1e7853667a9f11a2771ac926770size 487702864123version https://git-lfs.github.com/spec/v1oid sha256:875a80913380d79edfe2ba7dcc84a887f757be7b645ed1bdd7469c5643bf3fa2size 489139608123version https://git-lfs.github.com/spec/v1oid sha256:d5860af89681afdf527dd6cf2f83af0253bb8a15375c8cf13d4156f9e2b69127size 487706496123version https://git-lfs.github.com/spec/v1oid sha256:15ae8508a703e9dc113fdda5eadc115a4ecdac2a76b558f3eac550f21f7df0c5size 439256008123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827{ "metadata": { "total_size": 2393855732 }, "weight_map": { "itm_proj.bias": "model-00005-of-00005.safetensors", "itm_proj.weight": "model-00005-of-00005.safetensors", "ln_vision.bias": "model-00005-of-00005.safetensors", "ln_vision.weight": "model-00005-of-00005.safetensors", "logit_bias": "model-00001-of-00005.safetensors", "logit_scale": "model-00001-of-00005.safetensors", "qformer.bert.embeddings.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.embeddings.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.embeddings.position_embeddings.weight": "model-00005-of-00005.safetensors", "qformer.bert.embeddings.position_ids": "model-00005-of-00005.safetensors", "qformer.bert.embeddings.word_embeddings.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.attention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.attention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.attention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.attention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.attention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.attention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.attention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.attention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.attention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.attention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.crossattention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.crossattention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.crossattention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.crossattention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.crossattention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.crossattention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.crossattention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.crossattention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.crossattention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.crossattention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.intermediate.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.intermediate.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.intermediate_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.intermediate_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.output_query.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.output_query.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.output_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.0.output_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.attention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.attention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.attention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.attention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.attention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.attention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.attention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.attention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.attention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.attention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.intermediate.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.intermediate.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.intermediate_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.intermediate_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.output_query.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.output_query.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.output_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.1.output_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.attention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.attention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.attention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.attention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.attention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.attention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.attention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.attention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.attention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.attention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.crossattention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.crossattention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.crossattention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.crossattention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.crossattention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.crossattention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.crossattention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.crossattention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.crossattention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.crossattention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.intermediate.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.intermediate.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.intermediate_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.intermediate_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.output_query.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.output_query.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.output_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.10.output_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.attention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.attention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.attention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.attention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.attention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.attention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.attention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.attention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.attention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.attention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.intermediate.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.intermediate.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.intermediate_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.intermediate_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.output_query.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.output_query.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.output_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.11.output_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.attention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.attention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.attention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.attention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.attention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.attention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.attention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.attention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.attention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.attention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.crossattention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.crossattention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.crossattention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.crossattention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.crossattention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.crossattention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.crossattention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.crossattention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.crossattention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.crossattention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.intermediate.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.intermediate.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.intermediate_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.intermediate_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.output_query.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.output_query.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.output_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.2.output_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.attention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.attention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.attention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.attention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.attention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.attention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.attention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.attention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.attention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.attention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.intermediate.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.intermediate.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.intermediate_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.intermediate_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.output_query.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.output_query.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.output_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.3.output_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.attention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.attention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.attention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.attention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.attention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.attention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.attention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.attention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.attention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.attention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.crossattention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.crossattention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.crossattention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.crossattention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.crossattention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.crossattention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.crossattention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.crossattention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.crossattention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.crossattention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.intermediate.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.intermediate.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.intermediate_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.intermediate_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.output_query.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.output_query.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.output_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.4.output_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.attention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.attention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.attention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.attention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.attention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.attention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.attention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.attention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.attention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.attention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.intermediate.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.intermediate.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.intermediate_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.intermediate_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.output_query.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.output_query.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.output_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.5.output_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.attention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.attention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.attention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.attention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.attention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.attention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.attention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.attention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.attention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.attention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.crossattention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.crossattention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.crossattention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.crossattention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.crossattention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.crossattention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.crossattention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.crossattention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.crossattention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.crossattention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.intermediate.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.intermediate.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.intermediate_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.intermediate_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.output_query.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.output_query.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.output_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.6.output_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.attention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.attention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.attention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.attention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.attention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.attention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.attention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.attention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.attention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.attention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.intermediate.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.intermediate.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.intermediate_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.intermediate_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.output_query.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.output_query.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.output_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.7.output_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.attention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.attention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.attention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.attention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.attention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.attention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.attention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.attention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.attention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.attention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.crossattention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.crossattention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.crossattention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.crossattention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.crossattention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.crossattention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.crossattention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.crossattention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.crossattention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.crossattention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.intermediate.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.intermediate.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.intermediate_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.intermediate_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.output_query.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.output_query.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.output_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.8.output_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.attention.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.attention.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.attention.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.attention.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.attention.self.key.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.attention.self.key.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.attention.self.query.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.attention.self.query.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.attention.self.value.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.attention.self.value.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.intermediate.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.intermediate.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.intermediate_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.intermediate_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.output.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.output.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.output.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.output.dense.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.output_query.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.output_query.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.output_query.dense.bias": "model-00005-of-00005.safetensors", "qformer.bert.encoder.layer.9.output_query.dense.weight": "model-00005-of-00005.safetensors", "qformer.cls.predictions.bias": "model-00005-of-00005.safetensors", "qformer.cls.predictions.decoder.bias": "model-00005-of-00005.safetensors", "qformer.cls.predictions.decoder.weight": "model-00005-of-00005.safetensors", "qformer.cls.predictions.transform.LayerNorm.bias": "model-00005-of-00005.safetensors", "qformer.cls.predictions.transform.LayerNorm.weight": "model-00005-of-00005.safetensors", "qformer.cls.predictions.transform.dense.bias": "model-00005-of-00005.safetensors", "qformer.cls.predictions.transform.dense.weight": "model-00005-of-00005.safetensors", "query_tokens": "model-00001-of-00005.safetensors", "temporal_encoding.encoding.temp_embed": "model-00005-of-00005.safetensors", "text_proj.bias": "model-00005-of-00005.safetensors", "text_proj.weight": "model-00005-of-00005.safetensors", "vision_proj.bias": "model-00005-of-00005.safetensors", "vision_proj.weight": "model-00005-of-00005.safetensors", "visual_encoder.blocks.0.attn.proj.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.0.attn.proj.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.0.attn.qkv.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.0.attn.qkv.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.0.mlp.fc1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.0.mlp.fc1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.0.mlp.fc2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.0.mlp.fc2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.0.norm1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.0.norm1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.0.norm2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.0.norm2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.1.attn.proj.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.1.attn.proj.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.1.attn.qkv.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.1.attn.qkv.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.1.mlp.fc1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.1.mlp.fc1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.1.mlp.fc2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.1.mlp.fc2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.1.norm1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.1.norm1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.1.norm2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.1.norm2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.10.attn.proj.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.10.attn.proj.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.10.attn.qkv.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.10.attn.qkv.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.10.mlp.fc1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.10.mlp.fc1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.10.mlp.fc2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.10.mlp.fc2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.10.norm1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.10.norm1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.10.norm2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.10.norm2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.11.attn.proj.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.11.attn.proj.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.11.attn.qkv.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.11.attn.qkv.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.11.mlp.fc1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.11.mlp.fc1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.11.mlp.fc2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.11.mlp.fc2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.11.norm1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.11.norm1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.11.norm2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.11.norm2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.12.attn.proj.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.12.attn.proj.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.12.attn.qkv.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.12.attn.qkv.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.12.mlp.fc1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.12.mlp.fc1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.12.mlp.fc2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.12.mlp.fc2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.12.norm1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.12.norm1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.12.norm2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.12.norm2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.13.attn.proj.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.13.attn.proj.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.13.attn.qkv.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.13.attn.qkv.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.13.mlp.fc1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.13.mlp.fc1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.13.mlp.fc2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.13.mlp.fc2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.13.norm1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.13.norm1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.13.norm2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.13.norm2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.14.attn.proj.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.14.attn.proj.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.14.attn.qkv.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.14.attn.qkv.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.14.mlp.fc1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.14.mlp.fc1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.14.mlp.fc2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.14.mlp.fc2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.14.norm1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.14.norm1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.14.norm2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.14.norm2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.15.attn.proj.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.15.attn.proj.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.15.attn.qkv.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.15.attn.qkv.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.15.mlp.fc1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.15.mlp.fc1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.15.mlp.fc2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.15.mlp.fc2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.15.norm1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.15.norm1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.15.norm2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.15.norm2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.16.attn.proj.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.16.attn.proj.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.16.attn.qkv.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.16.attn.qkv.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.16.mlp.fc1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.16.mlp.fc1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.16.mlp.fc2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.16.mlp.fc2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.16.norm1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.16.norm1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.16.norm2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.16.norm2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.17.attn.proj.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.17.attn.proj.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.17.attn.qkv.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.17.attn.qkv.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.17.mlp.fc1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.17.mlp.fc1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.17.mlp.fc2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.17.mlp.fc2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.17.norm1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.17.norm1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.17.norm2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.17.norm2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.18.attn.proj.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.18.attn.proj.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.18.attn.qkv.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.18.attn.qkv.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.18.mlp.fc1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.18.mlp.fc1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.18.mlp.fc2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.18.mlp.fc2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.18.norm1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.18.norm1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.18.norm2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.18.norm2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.19.attn.proj.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.19.attn.proj.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.19.attn.qkv.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.19.attn.qkv.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.19.mlp.fc1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.19.mlp.fc1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.19.mlp.fc2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.19.mlp.fc2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.19.norm1.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.19.norm1.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.19.norm2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.19.norm2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.2.attn.proj.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.2.attn.proj.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.2.attn.qkv.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.2.attn.qkv.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.2.mlp.fc1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.2.mlp.fc1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.2.mlp.fc2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.2.mlp.fc2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.2.norm1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.2.norm1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.2.norm2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.2.norm2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.20.attn.proj.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.20.attn.proj.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.20.attn.qkv.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.20.attn.qkv.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.20.mlp.fc1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.20.mlp.fc1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.20.mlp.fc2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.20.mlp.fc2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.20.norm1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.20.norm1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.20.norm2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.20.norm2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.21.attn.proj.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.21.attn.proj.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.21.attn.qkv.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.21.attn.qkv.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.21.mlp.fc1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.21.mlp.fc1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.21.mlp.fc2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.21.mlp.fc2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.21.norm1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.21.norm1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.21.norm2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.21.norm2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.22.attn.proj.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.22.attn.proj.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.22.attn.qkv.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.22.attn.qkv.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.22.mlp.fc1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.22.mlp.fc1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.22.mlp.fc2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.22.mlp.fc2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.22.norm1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.22.norm1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.22.norm2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.22.norm2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.23.attn.proj.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.23.attn.proj.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.23.attn.qkv.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.23.attn.qkv.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.23.mlp.fc1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.23.mlp.fc1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.23.mlp.fc2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.23.mlp.fc2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.23.norm1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.23.norm1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.23.norm2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.23.norm2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.24.attn.proj.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.24.attn.proj.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.24.attn.qkv.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.24.attn.qkv.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.24.mlp.fc1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.24.mlp.fc1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.24.mlp.fc2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.24.mlp.fc2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.24.norm1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.24.norm1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.24.norm2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.24.norm2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.25.attn.proj.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.25.attn.proj.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.25.attn.qkv.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.25.attn.qkv.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.25.mlp.fc1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.25.mlp.fc1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.25.mlp.fc2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.25.mlp.fc2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.25.norm1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.25.norm1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.25.norm2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.25.norm2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.26.attn.proj.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.26.attn.proj.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.26.attn.qkv.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.26.attn.qkv.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.26.mlp.fc1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.26.mlp.fc1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.26.mlp.fc2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.26.mlp.fc2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.26.norm1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.26.norm1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.26.norm2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.26.norm2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.27.attn.proj.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.27.attn.proj.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.27.attn.qkv.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.27.attn.qkv.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.27.mlp.fc1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.27.mlp.fc1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.27.mlp.fc2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.27.mlp.fc2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.27.norm1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.27.norm1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.27.norm2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.27.norm2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.28.attn.proj.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.28.attn.proj.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.28.attn.qkv.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.28.attn.qkv.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.28.mlp.fc1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.28.mlp.fc1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.28.mlp.fc2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.28.mlp.fc2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.28.norm1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.28.norm1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.28.norm2.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.28.norm2.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.29.attn.proj.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.29.attn.proj.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.29.attn.qkv.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.29.attn.qkv.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.29.mlp.fc1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.29.mlp.fc1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.29.mlp.fc2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.29.mlp.fc2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.29.norm1.bias": "model-00003-of-00005.safetensors", "visual_encoder.blocks.29.norm1.weight": "model-00003-of-00005.safetensors", "visual_encoder.blocks.29.norm2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.29.norm2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.3.attn.proj.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.3.attn.proj.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.3.attn.qkv.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.3.attn.qkv.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.3.mlp.fc1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.3.mlp.fc1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.3.mlp.fc2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.3.mlp.fc2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.3.norm1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.3.norm1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.3.norm2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.3.norm2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.30.attn.proj.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.30.attn.proj.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.30.attn.qkv.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.30.attn.qkv.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.30.mlp.fc1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.30.mlp.fc1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.30.mlp.fc2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.30.mlp.fc2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.30.norm1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.30.norm1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.30.norm2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.30.norm2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.31.attn.proj.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.31.attn.proj.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.31.attn.qkv.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.31.attn.qkv.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.31.mlp.fc1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.31.mlp.fc1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.31.mlp.fc2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.31.mlp.fc2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.31.norm1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.31.norm1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.31.norm2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.31.norm2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.32.attn.proj.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.32.attn.proj.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.32.attn.qkv.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.32.attn.qkv.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.32.mlp.fc1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.32.mlp.fc1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.32.mlp.fc2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.32.mlp.fc2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.32.norm1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.32.norm1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.32.norm2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.32.norm2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.33.attn.proj.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.33.attn.proj.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.33.attn.qkv.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.33.attn.qkv.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.33.mlp.fc1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.33.mlp.fc1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.33.mlp.fc2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.33.mlp.fc2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.33.norm1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.33.norm1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.33.norm2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.33.norm2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.34.attn.proj.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.34.attn.proj.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.34.attn.qkv.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.34.attn.qkv.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.34.mlp.fc1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.34.mlp.fc1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.34.mlp.fc2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.34.mlp.fc2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.34.norm1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.34.norm1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.34.norm2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.34.norm2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.35.attn.proj.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.35.attn.proj.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.35.attn.qkv.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.35.attn.qkv.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.35.mlp.fc1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.35.mlp.fc1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.35.mlp.fc2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.35.mlp.fc2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.35.norm1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.35.norm1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.35.norm2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.35.norm2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.36.attn.proj.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.36.attn.proj.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.36.attn.qkv.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.36.attn.qkv.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.36.mlp.fc1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.36.mlp.fc1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.36.mlp.fc2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.36.mlp.fc2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.36.norm1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.36.norm1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.36.norm2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.36.norm2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.37.attn.proj.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.37.attn.proj.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.37.attn.qkv.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.37.attn.qkv.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.37.mlp.fc1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.37.mlp.fc1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.37.mlp.fc2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.37.mlp.fc2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.37.norm1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.37.norm1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.37.norm2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.37.norm2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.38.attn.proj.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.38.attn.proj.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.38.attn.qkv.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.38.attn.qkv.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.38.mlp.fc1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.38.mlp.fc1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.38.mlp.fc2.bias": "model-00005-of-00005.safetensors", "visual_encoder.blocks.38.mlp.fc2.weight": "model-00005-of-00005.safetensors", "visual_encoder.blocks.38.norm1.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.38.norm1.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.38.norm2.bias": "model-00004-of-00005.safetensors", "visual_encoder.blocks.38.norm2.weight": "model-00004-of-00005.safetensors", "visual_encoder.blocks.4.attn.proj.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.4.attn.proj.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.4.attn.qkv.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.4.attn.qkv.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.4.mlp.fc1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.4.mlp.fc1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.4.mlp.fc2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.4.mlp.fc2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.4.norm1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.4.norm1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.4.norm2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.4.norm2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.5.attn.proj.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.5.attn.proj.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.5.attn.qkv.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.5.attn.qkv.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.5.mlp.fc1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.5.mlp.fc1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.5.mlp.fc2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.5.mlp.fc2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.5.norm1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.5.norm1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.5.norm2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.5.norm2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.6.attn.proj.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.6.attn.proj.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.6.attn.qkv.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.6.attn.qkv.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.6.mlp.fc1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.6.mlp.fc1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.6.mlp.fc2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.6.mlp.fc2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.6.norm1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.6.norm1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.6.norm2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.6.norm2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.7.attn.proj.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.7.attn.proj.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.7.attn.qkv.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.7.attn.qkv.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.7.mlp.fc1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.7.mlp.fc1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.7.mlp.fc2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.7.mlp.fc2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.7.norm1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.7.norm1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.7.norm2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.7.norm2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.8.attn.proj.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.8.attn.proj.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.8.attn.qkv.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.8.attn.qkv.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.8.mlp.fc1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.8.mlp.fc1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.8.mlp.fc2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.8.mlp.fc2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.8.norm1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.8.norm1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.8.norm2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.8.norm2.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.9.attn.proj.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.9.attn.proj.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.9.attn.qkv.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.9.attn.qkv.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.9.mlp.fc1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.9.mlp.fc1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.9.mlp.fc2.bias": "model-00002-of-00005.safetensors", "visual_encoder.blocks.9.mlp.fc2.weight": "model-00002-of-00005.safetensors", "visual_encoder.blocks.9.norm1.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.9.norm1.weight": "model-00001-of-00005.safetensors", "visual_encoder.blocks.9.norm2.bias": "model-00001-of-00005.safetensors", "visual_encoder.blocks.9.norm2.weight": "model-00001-of-00005.safetensors", "visual_encoder.cls_token": "model-00001-of-00005.safetensors", "visual_encoder.patch_embed.proj.bias": "model-00001-of-00005.safetensors", "visual_encoder.patch_embed.proj.weight": "model-00001-of-00005.safetensors", "visual_encoder.pos_embed": "model-00001-of-00005.safetensors" }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0## 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.
"""Cosmos-Embed1 text+video embedder."""
import mathfrom copy import deepcopy
import torchfrom einops import rearrangefrom torch import nnfrom torch.nn import functional as Ffrom transformers import AutoModel, PreTrainedModel
from .configuration_embed1 import CosmosEmbed1Configfrom .modeling_outputs import TextEmbedderOutput, TextVideoEmbedderOutput, VideoEmbedderOutputfrom .modeling_qformer import BertLMHeadModel, load_qformerfrom .modeling_utils import EncodingFactory, rank0_firstfrom .modeling_vit import EvaViTG
class CosmosEmbed1(PreTrainedModel): config_class = CosmosEmbed1Config
def __init__(self, config: CosmosEmbed1Config) -> None: """Cosmos-Embed1 video embedder constructor.
Args: config (CosmosEmbed1Config): Model configuration. """ super().__init__(config)
self.embed_dim = config.embed_dim self.num_query_tokens = config.num_query_tokens self.num_video_frames = config.num_video_frames self.temporal_encoding_type = config.temporal_encoding_type self.resolution = config.resolution self.vocab_size = config.vocab_size self.transformer_engine = config.transformer_engine self.use_fp8 = config.use_fp8
# visual encoder initialization self.register_buffer( "normalization_mean", torch.tensor([0.485, 0.456, 0.406]).view(1, 1, 3, 1, 1), persistent=False, ) self.register_buffer( "normalization_std", torch.tensor([0.229, 0.224, 0.225]).view(1, 1, 3, 1, 1), persistent=False, ) self.visual_encoder = EvaViTG( img_size=self.resolution, transformer_engine=self.transformer_engine, use_fp8=self.use_fp8, ) self.ln_vision = nn.LayerNorm(self.visual_encoder.embed_dim)
# qformer initialization self.qformer, self.query_tokens = self._init_qformer( num_query_tokens=self.num_query_tokens, encoder_width=self.visual_encoder.embed_dim, vocab_size=self.vocab_size, ) # self.qformer. state_dict = self.qformer.state_dict() for name, param in self.qformer.named_parameters(): if "_query" in name: key_orig = name.replace("_query", "") param.data.copy_(state_dict[key_orig])
# temporal encoding self.temporal_encoding = EncodingFactory( self.temporal_encoding_type, embed_dim=self.visual_encoder.embed_dim, max_len=self.num_video_frames, )
# output projections self.vision_proj = nn.Linear(self.qformer.config.hidden_size, self.embed_dim) self.text_proj = nn.Linear(self.qformer.config.hidden_size, self.embed_dim) self.itm_proj = nn.Linear(self.qformer.config.hidden_size, 2) # initialize logit scale/bias like SigLIP (as per Table 4 in https://arxiv.org/pdf/2303.15343) self.logit_scale = nn.Parameter(torch.tensor(math.log(10.0))) self.logit_bias = nn.Parameter(torch.tensor(-10.0))
@property def hidden_dim(self) -> int: return self.visual_encoder.embed_dim
@torch.jit.ignore def no_weight_decay(self) -> set: ret = {"logit_scale", "logit_bias"} return ret
def forward( self, videos: torch.FloatTensor, input_ids: torch.LongTensor, attention_mask: torch.FloatTensor, ) -> TextVideoEmbedderOutput: """Forward function for `ComosEmbed1`.
Args: videos (`torch.Tensor` of shape `(batch_size, num_frames, RGB, height, width)`): batched videos with fixed number of RGB frames. input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary. Indices can be obtained by using [`AutoTokenizer`, `CosmosEmbed1Tokenizer`]. attention_mask: (`torch.Tensor` of shape `(batch_size, sequence_length)`): Mask to avoid performing attention on padding token indices. Mask values select in `[0, 1]`. - 1 for tokens that are **not masked**. - 0 for tokens that are **masked**. """ video_output = self.get_video_embeddings(videos) text_output = self.get_text_embeddings(input_ids, attention_mask) return TextVideoEmbedderOutput(**video_output, **text_output)
def get_video_embeddings(self, videos: torch.Tensor) -> VideoEmbedderOutput: videos = (videos - self.normalization_mean) / self.normalization_std batch_size, num_frames, _, H, W = videos.shape frame_batch = rearrange(videos, "b t c h w -> (b t) c h w")
# process video frames through ViT visual_embs = self.visual_encoder(frame_batch) visual_embs = self.ln_vision(visual_embs) visual_embs = rearrange( visual_embs, "(b t) k d -> b t k d", b=batch_size, t=num_frames, k=visual_embs.size(1), d=visual_embs.size(2), )
# add temporal encoding visual_embs = self.temporal_encoding(visual_embs)
# Q-Former cross-attention encoder_hidden_states = rearrange(visual_embs, "b t k d -> b (t k) d") encoder_attention_mask = torch.ones(encoder_hidden_states.size()[:-1], dtype=torch.long).to(videos.device) query_tokens = self.query_tokens.expand(encoder_hidden_states.size(0), -1, -1) visual_query_output = self.qformer.bert( query_embeds=query_tokens, encoder_hidden_states=encoder_hidden_states, encoder_attention_mask=encoder_attention_mask, use_cache=True, return_dict=True, )
visual_cls_tokens = visual_query_output.last_hidden_state.mean(dim=1, keepdim=False) visual_proj = self.vision_proj(visual_cls_tokens) visual_proj = F.normalize(visual_proj, dim=-1)
# reshape visual embs to (B,T,H,W,D), to confirm with expected output. # separate out the frame-level cls tokens if necessary. frame_cls_tokens, visual_embs = visual_embs[:, :, 0:1], visual_embs[:, :, 1:] h = H // self.visual_encoder.patch_size w = W // self.visual_encoder.patch_size visual_embs = rearrange(visual_embs, "b t (h w) d -> b t h w d", h=h, w=w)
return VideoEmbedderOutput( visual_proj=visual_proj, visual_embs=visual_embs, visual_query_output=visual_query_output, visual_cls_tokens=visual_cls_tokens, frame_cls_tokens=frame_cls_tokens, )
def get_text_embeddings( self, input_ids: torch.LongTensor, attention_mask: torch.FloatTensor, ) -> TextEmbedderOutput: text_query_output = self.qformer.bert( input_ids=input_ids, attention_mask=attention_mask.to(dtype=self.query_tokens.dtype), return_dict=True, ) text_proj = text_query_output.last_hidden_state[:, 0, :] text_proj = self.text_proj(text_proj) text_proj = F.normalize(text_proj, dim=-1)
return TextEmbedderOutput( text_proj=text_proj, text_embs=text_query_output.last_hidden_state, text_query_output=text_query_output, )
@classmethod @rank0_first def _init_qformer( cls: "CosmosEmbed1", num_query_tokens: int, encoder_width: int, vocab_size: int, hidden_size: int = 768, ) -> tuple[BertLMHeadModel, nn.Parameter]: """Convenience function for initializing QFormer module.""" qformer = load_qformer( num_query_tokens=num_query_tokens, encoder_width=encoder_width, hidden_size=hidden_size, vocab_size=vocab_size, ) query_tokens = nn.Parameter(torch.zeros(1, num_query_tokens, hidden_size)) query_tokens.data.normal_(mean=0.0, std=0.02) return qformer, query_tokens
@classmethod def from_pretrained(cls, pretrained_model_name_or_path: str, **kwargs): # Get config from kwargs or load from pretrained path config = kwargs.get("config", None) if config is None: config = CosmosEmbed1Config.from_pretrained(pretrained_model_name_or_path)
if config.transformer_engine: config_no_te = deepcopy(config) config_no_te.transformer_engine = False config_no_te.use_fp8 = False # Also disable FP8 for the base model
# Remove 'config' from kwargs to avoid conflict, we'll pass config_no_te kwargs_no_te = deepcopy(kwargs) kwargs_no_te["config"] = config_no_te
# Load standard (non-TE) model & weights base_model = super().from_pretrained(pretrained_model_name_or_path, **kwargs_no_te) base_state_dict = base_model.state_dict()
# Now build the TE version of the model model_with_te = cls(config=config)
# Load weights from non-TE model missing, unexpected = model_with_te.load_state_dict(base_state_dict, strict=False)
# Optional debug log if missing: print(f"[TransformerEngine] Missing keys: {missing}") if unexpected: print(f"[TransformerEngine] Unexpected keys: {unexpected}")
return model_with_te else: return super().from_pretrained(pretrained_model_name_or_path, **kwargs)
AutoModel.register(CosmosEmbed1Config, CosmosEmbed1)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0## 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.
"""Output definitions for Cosmos-Embed1."""
from dataclasses import dataclassfrom typing import Optional
import torchfrom transformers.modeling_outputs import CausalLMOutputWithCrossAttentions, ModelOutput
@dataclassclass TextEmbedderOutput(ModelOutput): """Output of a video embedder branch `get_text_embeddings` function.
Attrs: text_proj (`torch.FloatTensor` of shape `(batch_size, num_visual_embs, embed_dim)` or `(batch_size, embed_dim)`: text (video-aligned) projected embeddings from text branch. text_embs (`torch.FloatTensor` of shape `(batch_size, ...)`: text tokens from text branch. text_query_output (`transformer.modeling_outputs.CausalLMOutputWithCrossAttentions`): Useful text branch intermediate outputs like hidden states, past key values, attentions etc. """
text_proj: Optional[torch.FloatTensor] = None text_embs: Optional[torch.FloatTensor] = None text_query_output: Optional[CausalLMOutputWithCrossAttentions] = None
@dataclassclass VideoEmbedderOutput(ModelOutput): """Output of a video embedder branch `get_video_embeddings` function.
Attrs: visual_proj (`torch.FloatTensor` of shape `(batch_size, embed_dim)`): visual (text-aligned) projected embeddings from visual branch. visual_embs (`torch.FloatTensor` of shape `(batch_size, num_frames, height, width, encoder_dim)`): per-frame dense visual embeddings from visual encoder. visual_cls_tokens (`torch.FloatTensor` of shape `(batch_size, qformer_dim)`): visual pooled tokens from visual branch prior to projection and normalization. frame_cls_tokens (`torch.FloatTensor` of shape `(batch_size, num_frames, encoder_dim)`): per-frame cls tokens from visual encoder. visual_query_output (`transformer.modeling_outputs.CausalLMOutputWithCrossAttentions`): Useful visual branch intermediate outputs like hidden states, past key values, attentions etc. """
visual_proj: Optional[torch.FloatTensor] = None visual_embs: Optional[torch.FloatTensor] = None visual_cls_tokens: Optional[torch.FloatTensor] = None frame_cls_tokens: Optional[torch.FloatTensor] = None visual_query_output: Optional[CausalLMOutputWithCrossAttentions] = None
@dataclassclass TextVideoEmbedderOutput(VideoEmbedderOutput, TextEmbedderOutput): """Merged class of `VideoEmbedderOutput` and `TextEmbedderOutput`."""1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0## 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.
# Copyright (c) 2023, salesforce.com, inc.# All rights reserved.# SPDX-License-Identifier: BSD-3-Clause# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
"""Q-Former module.
Code adapted from:https://github.com/salesforce/LAVIS/blob/main/lavis/models/blip2_models/Qformer.py"""
import mathfrom logging import getLoggerfrom typing import Literal, Tuple
import torchimport torch.utils.checkpointfrom torch import Tensor, device, nnfrom torch.nn import CrossEntropyLossfrom transformers import GenerationMixinfrom transformers.activations import ACT2FNfrom transformers.modeling_outputs import ( BaseModelOutputWithPastAndCrossAttentions, BaseModelOutputWithPoolingAndCrossAttentions, CausalLMOutputWithCrossAttentions,)from transformers.modeling_utils import ( PreTrainedModel, apply_chunking_to_forward, find_pruneable_heads_and_indices, prune_linear_layer,)from transformers.models.bert.configuration_bert import BertConfig
logger = getLogger(__file__)
class BertEmbeddings(nn.Module): """Construct the embeddings from word and position embeddings."""
def __init__(self, config): super().__init__() self.word_embeddings = nn.Embedding(config.vocab_size, config.hidden_size, padding_idx=config.pad_token_id) self.position_embeddings = nn.Embedding(config.max_position_embeddings, config.hidden_size)
# self.LayerNorm is not snake-cased to stick with TensorFlow model variable name and be able to load # any TensorFlow checkpoint file self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps) self.dropout = nn.Dropout(config.hidden_dropout_prob)
# position_ids (1, len position emb) is contiguous in memory and exported when serialized self.register_buffer("position_ids", torch.arange(config.max_position_embeddings).expand((1, -1))) self.position_embedding_type = getattr(config, "position_embedding_type", "absolute")
self.config = config
def forward( self, input_ids=None, position_ids=None, query_embeds=None, past_key_values_length=0, ): if input_ids is not None: seq_length = input_ids.size()[1] else: seq_length = 0
if position_ids is None: position_ids = self.position_ids[:, past_key_values_length : seq_length + past_key_values_length].clone()
if input_ids is not None: embeddings = self.word_embeddings(input_ids) if self.position_embedding_type == "absolute": position_embeddings = self.position_embeddings(position_ids) embeddings = embeddings + position_embeddings
if query_embeds is not None: embeddings = torch.cat((query_embeds, embeddings), dim=1) else: embeddings = query_embeds
embeddings = self.LayerNorm(embeddings) embeddings = self.dropout(embeddings) return embeddings
# TODO: add more efficient attention kernels like FlashAttention V2/V3.class BertSelfAttention(nn.Module): def __init__(self, config, is_cross_attention): super().__init__() self.config = config if config.hidden_size % config.num_attention_heads != 0 and not hasattr(config, "embedding_size"): raise ValueError( "The hidden size (%d) is not a multiple of the number of attention " "heads (%d)" % (config.hidden_size, config.num_attention_heads) )
self.num_attention_heads = config.num_attention_heads self.attention_head_size = int(config.hidden_size / config.num_attention_heads) self.all_head_size = self.num_attention_heads * self.attention_head_size
self.query = nn.Linear(config.hidden_size, self.all_head_size) if is_cross_attention: self.key = nn.Linear(config.encoder_width, self.all_head_size) self.value = nn.Linear(config.encoder_width, self.all_head_size) else: self.key = nn.Linear(config.hidden_size, self.all_head_size) self.value = nn.Linear(config.hidden_size, self.all_head_size)
self.dropout = nn.Dropout(config.attention_probs_dropout_prob) self.position_embedding_type = getattr(config, "position_embedding_type", "absolute") if self.position_embedding_type == "relative_key" or self.position_embedding_type == "relative_key_query": self.max_position_embeddings = config.max_position_embeddings self.distance_embedding = nn.Embedding(2 * config.max_position_embeddings - 1, self.attention_head_size) self.save_attention = False
def save_attn_gradients(self, attn_gradients): self.attn_gradients = attn_gradients
def get_attn_gradients(self): return self.attn_gradients
def save_attention_map(self, attention_map): self.attention_map = attention_map
def get_attention_map(self): return self.attention_map
def transpose_for_scores(self, x): new_x_shape = x.size()[:-1] + ( self.num_attention_heads, self.attention_head_size, ) x = x.view(*new_x_shape) return x.permute(0, 2, 1, 3)
def forward( self, hidden_states, attention_mask=None, head_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, past_key_value=None, output_attentions=False, ): # If this is instantiated as a cross-attention module, the keys # and values come from an encoder; the attention mask needs to be # such that the encoder's padding tokens are not attended to. is_cross_attention = encoder_hidden_states is not None
if is_cross_attention: key_layer = self.transpose_for_scores(self.key(encoder_hidden_states)) value_layer = self.transpose_for_scores(self.value(encoder_hidden_states)) attention_mask = encoder_attention_mask elif past_key_value is not None: key_layer = self.transpose_for_scores(self.key(hidden_states)) value_layer = self.transpose_for_scores(self.value(hidden_states)) key_layer = torch.cat([past_key_value[0], key_layer], dim=2) value_layer = torch.cat([past_key_value[1], value_layer], dim=2) else: key_layer = self.transpose_for_scores(self.key(hidden_states)) value_layer = self.transpose_for_scores(self.value(hidden_states))
mixed_query_layer = self.query(hidden_states)
query_layer = self.transpose_for_scores(mixed_query_layer)
past_key_value = (key_layer, value_layer)
# Take the dot product between "query" and "key" to get the raw attention scores. attention_scores = torch.matmul(query_layer, key_layer.transpose(-1, -2))
if self.position_embedding_type == "relative_key" or self.position_embedding_type == "relative_key_query": seq_length = hidden_states.size()[1] position_ids_l = torch.arange(seq_length, dtype=torch.long, device=hidden_states.device).view(-1, 1) position_ids_r = torch.arange(seq_length, dtype=torch.long, device=hidden_states.device).view(1, -1) distance = position_ids_l - position_ids_r positional_embedding = self.distance_embedding(distance + self.max_position_embeddings - 1) positional_embedding = positional_embedding.to(dtype=query_layer.dtype) # fp16 compatibility
if self.position_embedding_type == "relative_key": relative_position_scores = torch.einsum("bhld,lrd->bhlr", query_layer, positional_embedding) attention_scores = attention_scores + relative_position_scores elif self.position_embedding_type == "relative_key_query": relative_position_scores_query = torch.einsum("bhld,lrd->bhlr", query_layer, positional_embedding) relative_position_scores_key = torch.einsum("bhrd,lrd->bhlr", key_layer, positional_embedding) attention_scores = attention_scores + relative_position_scores_query + relative_position_scores_key
attention_scores = attention_scores / math.sqrt(self.attention_head_size) if attention_mask is not None: # Apply the attention mask is (precomputed for all layers in BertModel forward() function) attention_scores = attention_scores + attention_mask
# Normalize the attention scores to probabilities. attention_probs = nn.Softmax(dim=-1)(attention_scores)
if is_cross_attention and self.save_attention: self.save_attention_map(attention_probs) attention_probs.register_hook(self.save_attn_gradients)
# This is actually dropping out entire tokens to attend to, which might # seem a bit unusual, but is taken from the original Transformer paper. attention_probs_dropped = self.dropout(attention_probs)
# Mask heads if we want to if head_mask is not None: attention_probs_dropped = attention_probs_dropped * head_mask
context_layer = torch.matmul(attention_probs_dropped, value_layer)
context_layer = context_layer.permute(0, 2, 1, 3).contiguous() new_context_layer_shape = context_layer.size()[:-2] + (self.all_head_size,) context_layer = context_layer.view(*new_context_layer_shape)
outputs = (context_layer, attention_probs) if output_attentions else (context_layer,)
outputs = outputs + (past_key_value,) return outputs
class BertSelfOutput(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps) self.dropout = nn.Dropout(config.hidden_dropout_prob)
def forward(self, hidden_states, input_tensor): hidden_states = self.dense(hidden_states) hidden_states = self.dropout(hidden_states) hidden_states = self.LayerNorm(hidden_states + input_tensor) return hidden_states
class BertAttention(nn.Module): def __init__(self, config, is_cross_attention=False): super().__init__() self.self = BertSelfAttention(config, is_cross_attention) self.output = BertSelfOutput(config) self.pruned_heads = set()
def prune_heads(self, heads): if len(heads) == 0: return heads, index = find_pruneable_heads_and_indices( heads, self.self.num_attention_heads, self.self.attention_head_size, self.pruned_heads, )
# Prune linear layers self.self.query = prune_linear_layer(self.self.query, index) self.self.key = prune_linear_layer(self.self.key, index) self.self.value = prune_linear_layer(self.self.value, index) self.output.dense = prune_linear_layer(self.output.dense, index, dim=1)
# Update hyper params and store pruned heads self.self.num_attention_heads = self.self.num_attention_heads - len(heads) self.self.all_head_size = self.self.attention_head_size * self.self.num_attention_heads self.pruned_heads = self.pruned_heads.union(heads)
def forward( self, hidden_states, attention_mask=None, head_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, past_key_value=None, output_attentions=False, ): self_outputs = self.self( hidden_states, attention_mask, head_mask, encoder_hidden_states, encoder_attention_mask, past_key_value, output_attentions, ) attention_output = self.output(self_outputs[0], hidden_states)
outputs = (attention_output,) + self_outputs[1:] # add attentions if we output them return outputs
class BertIntermediate(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.hidden_size, config.intermediate_size) if isinstance(config.hidden_act, str): self.intermediate_act_fn = ACT2FN[config.hidden_act] else: self.intermediate_act_fn = config.hidden_act
def forward(self, hidden_states): hidden_states = self.dense(hidden_states) hidden_states = self.intermediate_act_fn(hidden_states) return hidden_states
class BertOutput(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.intermediate_size, config.hidden_size) self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps) self.dropout = nn.Dropout(config.hidden_dropout_prob)
def forward(self, hidden_states, input_tensor): hidden_states = self.dense(hidden_states) hidden_states = self.dropout(hidden_states) hidden_states = self.LayerNorm(hidden_states + input_tensor) return hidden_states
class BertLayer(nn.Module): def __init__(self, config, layer_num): super().__init__() self.config = config self.chunk_size_feed_forward = config.chunk_size_feed_forward self.seq_len_dim = 1 self.attention = BertAttention(config) self.layer_num = layer_num if self.config.add_cross_attention and layer_num % self.config.cross_attention_freq == 0: self.crossattention = BertAttention(config, is_cross_attention=self.config.add_cross_attention) self.has_cross_attention = True else: self.has_cross_attention = False self.intermediate = BertIntermediate(config) self.output = BertOutput(config)
self.intermediate_query = BertIntermediate(config) self.output_query = BertOutput(config)
def forward( self, hidden_states, attention_mask=None, head_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, past_key_value=None, output_attentions=False, query_length=0, ): # decoder uni-directional self-attention cached key/values tuple is at positions 1,2 self_attn_past_key_value = past_key_value[:2] if past_key_value is not None else None self_attention_outputs = self.attention( hidden_states, attention_mask, head_mask, output_attentions=output_attentions, past_key_value=self_attn_past_key_value, ) attention_output = self_attention_outputs[0] outputs = self_attention_outputs[1:-1]
present_key_value = self_attention_outputs[-1]
if query_length > 0: query_attention_output = attention_output[:, :query_length, :]
if self.has_cross_attention: assert ( encoder_hidden_states is not None ), "encoder_hidden_states must be given for cross-attention layers" cross_attention_outputs = self.crossattention( query_attention_output, attention_mask, head_mask, encoder_hidden_states, encoder_attention_mask, output_attentions=output_attentions, ) query_attention_output = cross_attention_outputs[0] outputs = outputs + cross_attention_outputs[1:-1] # add cross attentions if we output attention weights
layer_output = apply_chunking_to_forward( self.feed_forward_chunk_query, self.chunk_size_feed_forward, self.seq_len_dim, query_attention_output, ) if attention_output.shape[1] > query_length: layer_output_text = apply_chunking_to_forward( self.feed_forward_chunk, self.chunk_size_feed_forward, self.seq_len_dim, attention_output[:, query_length:, :], ) layer_output = torch.cat([layer_output, layer_output_text], dim=1) else: layer_output = apply_chunking_to_forward( self.feed_forward_chunk, self.chunk_size_feed_forward, self.seq_len_dim, attention_output, ) outputs = (layer_output,) + outputs
outputs = outputs + (present_key_value,)
return outputs
def feed_forward_chunk(self, attention_output): intermediate_output = self.intermediate(attention_output) layer_output = self.output(intermediate_output, attention_output) return layer_output
def feed_forward_chunk_query(self, attention_output): intermediate_output = self.intermediate_query(attention_output) layer_output = self.output_query(intermediate_output, attention_output) return layer_output
class BertEncoder(nn.Module): def __init__(self, config): super().__init__() self.config = config self.layer = nn.ModuleList([BertLayer(config, i) for i in range(config.num_hidden_layers)])
def forward( self, hidden_states, attention_mask=None, head_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, past_key_values=None, use_cache=None, output_attentions=False, output_hidden_states=False, return_dict=True, query_length=0, ): all_hidden_states = () if output_hidden_states else None all_self_attentions = () if output_attentions else None all_cross_attentions = () if output_attentions and self.config.add_cross_attention else None
next_decoder_cache = () if use_cache else None
for i in range(self.config.num_hidden_layers): layer_module = self.layer[i] if output_hidden_states: all_hidden_states = all_hidden_states + (hidden_states,)
layer_head_mask = head_mask[i] if head_mask is not None else None past_key_value = past_key_values[i] if past_key_values is not None else None
if getattr(self.config, "gradient_checkpointing", False) and self.training: if use_cache: logger.warning( "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..." ) use_cache = False
def create_custom_forward(module): def custom_forward(*inputs): return module(*inputs, past_key_value, output_attentions, query_length)
return custom_forward
layer_outputs = torch.utils.checkpoint.checkpoint( create_custom_forward(layer_module), hidden_states, attention_mask, layer_head_mask, encoder_hidden_states, encoder_attention_mask, ) else: layer_outputs = layer_module( hidden_states, attention_mask, layer_head_mask, encoder_hidden_states, encoder_attention_mask, past_key_value, output_attentions, query_length, )
hidden_states = layer_outputs[0] if use_cache: next_decoder_cache += (layer_outputs[-1],) if output_attentions: all_self_attentions = all_self_attentions + (layer_outputs[1],) all_cross_attentions = all_cross_attentions + (layer_outputs[2],)
if output_hidden_states: all_hidden_states = all_hidden_states + (hidden_states,)
if not return_dict: return tuple( v for v in [ hidden_states, next_decoder_cache, all_hidden_states, all_self_attentions, all_cross_attentions, ] if v is not None ) return BaseModelOutputWithPastAndCrossAttentions( last_hidden_state=hidden_states, past_key_values=next_decoder_cache, hidden_states=all_hidden_states, attentions=all_self_attentions, cross_attentions=all_cross_attentions, )
class BertPooler(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.activation = nn.Tanh()
def forward(self, hidden_states): # We "pool" the model by simply taking the hidden state corresponding # to the first token. first_token_tensor = hidden_states[:, 0] pooled_output = self.dense(first_token_tensor) pooled_output = self.activation(pooled_output) return pooled_output
class BertPredictionHeadTransform(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) if isinstance(config.hidden_act, str): self.transform_act_fn = ACT2FN[config.hidden_act] else: self.transform_act_fn = config.hidden_act self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
def forward(self, hidden_states): hidden_states = self.dense(hidden_states) hidden_states = self.transform_act_fn(hidden_states) hidden_states = self.LayerNorm(hidden_states) return hidden_states
class BertLMPredictionHead(nn.Module): def __init__(self, config): super().__init__() self.transform = BertPredictionHeadTransform(config)
# The output weights are the same as the input embeddings, but there is # an output-only bias for each token. self.decoder = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
self.bias = nn.Parameter(torch.zeros(config.vocab_size))
# Need a link between the two variables so that the bias is correctly resized with `resize_token_embeddings` self.decoder.bias = self.bias
def forward(self, hidden_states): hidden_states = self.transform(hidden_states) hidden_states = self.decoder(hidden_states) return hidden_states
class BertOnlyMLMHead(nn.Module): def __init__(self, config): super().__init__() self.predictions = BertLMPredictionHead(config)
def forward(self, sequence_output): prediction_scores = self.predictions(sequence_output) return prediction_scores
class BertPreTrainedModel(PreTrainedModel): """ An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models. """
config_class = BertConfig base_model_prefix = "bert" _keys_to_ignore_on_load_missing = [r"position_ids"]
def _init_weights(self, module): """Initialize the weights""" if isinstance(module, (nn.Linear, nn.Embedding)): # Modified from original LAVIS implementation to add truncated normal. # This matches the original Tensorflow implementation from Google. nn.init.trunc_normal_(module.weight, std=self.config.initializer_range) elif isinstance(module, nn.LayerNorm): module.bias.data.zero_() module.weight.data.fill_(1.0) if isinstance(module, nn.Linear) and module.bias is not None: module.bias.data.zero_()
class BertModel(BertPreTrainedModel): """ The model can behave as an encoder (with only self-attention) as well as a decoder, in which case a layer of cross-attention is added between the self-attention layers, following the architecture described in `Attention is all you need <https://arxiv.org/abs/1706.03762>`__ by Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser and Illia Polosukhin. argument and :obj:`add_cross_attention` set to :obj:`True`; an :obj:`encoder_hidden_states` is then expected as an input to the forward pass. """
def __init__(self, config, add_pooling_layer=False): super().__init__(config) self.config = config
self.embeddings = BertEmbeddings(config)
self.encoder = BertEncoder(config)
self.pooler = BertPooler(config) if add_pooling_layer else None
self.init_weights()
def get_input_embeddings(self): return self.embeddings.word_embeddings
def set_input_embeddings(self, value): self.embeddings.word_embeddings = value
def _prune_heads(self, heads_to_prune): """ Prunes heads of the model. heads_to_prune: dict of {layer_num: list of heads to prune in this layer} See base class PreTrainedModel """ for layer, heads in heads_to_prune.items(): self.encoder.layer[layer].attention.prune_heads(heads)
def get_extended_attention_mask( self, attention_mask: Tensor, input_shape: Tuple[int], device: device, is_decoder: bool, has_query: bool = False, ) -> Tensor: """ Makes broadcastable attention and causal masks so that future and masked tokens are ignored.
Arguments: attention_mask (:obj:`torch.Tensor`): Mask with ones indicating tokens to attend to, zeros for tokens to ignore. input_shape (:obj:`Tuple[int]`): The shape of the input to the model. device: (:obj:`torch.device`): The device of the input to the model.
Returns: :obj:`torch.Tensor` The extended attention mask, with a the same dtype as :obj:`attention_mask.dtype`. """ # We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length] # ourselves in which case we just need to make it broadcastable to all heads. if attention_mask.dim() == 3: extended_attention_mask = attention_mask[:, None, :, :] elif attention_mask.dim() == 2: # Provided a padding mask of dimensions [batch_size, seq_length] # - if the model is a decoder, apply a causal mask in addition to the padding mask # - if the model is an encoder, make the mask broadcastable to [batch_size, num_heads, seq_length, seq_length] if is_decoder: batch_size, seq_length = input_shape
seq_ids = torch.arange(seq_length, device=device) causal_mask = seq_ids[None, None, :].repeat(batch_size, seq_length, 1) <= seq_ids[None, :, None]
# add a prefix ones mask to the causal mask # causal and attention masks must have same type with pytorch version < 1.3 causal_mask = causal_mask.to(attention_mask.dtype)
if causal_mask.shape[1] < attention_mask.shape[1]: prefix_seq_len = attention_mask.shape[1] - causal_mask.shape[1] if has_query: # UniLM style attention mask causal_mask = torch.cat( [ torch.zeros( (batch_size, prefix_seq_len, seq_length), device=device, dtype=causal_mask.dtype, ), causal_mask, ], axis=1, ) causal_mask = torch.cat( [ torch.ones( (batch_size, causal_mask.shape[1], prefix_seq_len), device=device, dtype=causal_mask.dtype, ), causal_mask, ], axis=-1, ) extended_attention_mask = causal_mask[:, None, :, :] * attention_mask[:, None, None, :] else: extended_attention_mask = attention_mask[:, None, None, :] else: raise ValueError( "Wrong shape for input_ids (shape {}) or attention_mask (shape {})".format( input_shape, attention_mask.shape ) )
# Since attention_mask is 1.0 for positions we want to attend and 0.0 for # masked positions, this operation will create a tensor which is 0.0 for # positions we want to attend and -10000.0 for masked positions. # Since we are adding it to the raw scores before the softmax, this is # effectively the same as removing these entirely. extended_attention_mask = extended_attention_mask.to(dtype=attention_mask.dtype) # fp16 compatibility extended_attention_mask = (1.0 - extended_attention_mask) * -10000.0 return extended_attention_mask
def forward( self, input_ids=None, attention_mask=None, position_ids=None, head_mask=None, query_embeds=None, encoder_hidden_states=None, encoder_attention_mask=None, past_key_values=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None, is_decoder=False, ): r""" encoder_hidden_states (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length, hidden_size)`, `optional`): Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if the model is configured as a decoder. encoder_attention_mask (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`): Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in the cross-attention if the model is configured as a decoder. Mask values selected in ``[0, 1]``: - 1 for tokens that are **not masked**, - 0 for tokens that are **masked**. past_key_values (:obj:`tuple(tuple(torch.FloatTensor))` of length :obj:`config.n_layers` with each tuple having 4 tensors of shape :obj:`(batch_size, num_heads, sequence_length - 1, embed_size_per_head)`): Contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding. If :obj:`past_key_values` are used, the user can optionally input only the last :obj:`decoder_input_ids` (those that don't have their past key value states given to this model) of shape :obj:`(batch_size, 1)` instead of all :obj:`decoder_input_ids` of shape :obj:`(batch_size, sequence_length)`. use_cache (:obj:`bool`, `optional`): If set to :obj:`True`, :obj:`past_key_values` key value states are returned and can be used to speed up decoding (see :obj:`past_key_values`). """ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions output_hidden_states = ( output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states ) return_dict = return_dict if return_dict is not None else self.config.use_return_dict
# use_cache = use_cache if use_cache is not None else self.config.use_cache
if input_ids is None: assert query_embeds is not None, "You have to specify query_embeds when input_ids is None"
# past_key_values_length past_key_values_length = ( past_key_values[0][0].shape[2] - self.config.query_length if past_key_values is not None else 0 )
query_length = query_embeds.shape[1] if query_embeds is not None else 0
embedding_output = self.embeddings( input_ids=input_ids, position_ids=position_ids, query_embeds=query_embeds, past_key_values_length=past_key_values_length, )
input_shape = embedding_output.size()[:-1] batch_size, seq_length = input_shape device = embedding_output.device
if attention_mask is None: attention_mask = torch.ones( ((batch_size, seq_length + past_key_values_length)), device=device, dtype=embedding_output.dtype )
# We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length] # ourselves in which case we just need to make it broadcastable to all heads. if is_decoder: extended_attention_mask = self.get_extended_attention_mask( attention_mask, input_ids.shape, device, is_decoder, has_query=(query_embeds is not None), ) else: extended_attention_mask = self.get_extended_attention_mask(attention_mask, input_shape, device, is_decoder)
# If a 2D or 3D attention mask is provided for the cross-attention # we need to make broadcastable to [batch_size, num_heads, seq_length, seq_length] if encoder_hidden_states is not None: if type(encoder_hidden_states) == list: encoder_batch_size, encoder_sequence_length, _ = encoder_hidden_states[0].size() else: ( encoder_batch_size, encoder_sequence_length, _, ) = encoder_hidden_states.size() encoder_hidden_shape = (encoder_batch_size, encoder_sequence_length)
if type(encoder_attention_mask) == list: encoder_extended_attention_mask = [self.invert_attention_mask(mask) for mask in encoder_attention_mask] elif encoder_attention_mask is None: encoder_attention_mask = torch.ones(encoder_hidden_shape, device=device, dtype=attention_mask.dtype) encoder_extended_attention_mask = self.invert_attention_mask(encoder_attention_mask) else: encoder_extended_attention_mask = self.invert_attention_mask(encoder_attention_mask) else: encoder_extended_attention_mask = None
# Prepare head mask if needed # 1.0 in head_mask indicate we keep the head # attention_probs has shape bsz x n_heads x N x N # input head_mask has shape [num_heads] or [num_hidden_layers x num_heads] # and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length] head_mask = self.get_head_mask(head_mask, self.config.num_hidden_layers)
encoder_outputs = self.encoder( embedding_output, attention_mask=extended_attention_mask, head_mask=head_mask, encoder_hidden_states=encoder_hidden_states, encoder_attention_mask=encoder_extended_attention_mask, past_key_values=past_key_values, use_cache=use_cache, output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict, query_length=query_length, ) sequence_output = encoder_outputs[0] pooled_output = self.pooler(sequence_output) if self.pooler is not None else None
if not return_dict: return (sequence_output, pooled_output) + encoder_outputs[1:]
return BaseModelOutputWithPoolingAndCrossAttentions( last_hidden_state=sequence_output, pooler_output=pooled_output, past_key_values=encoder_outputs.past_key_values, hidden_states=encoder_outputs.hidden_states, attentions=encoder_outputs.attentions, cross_attentions=encoder_outputs.cross_attentions, )
class BertLMHeadModel(BertPreTrainedModel, GenerationMixin): _keys_to_ignore_on_load_unexpected = [r"pooler"] _keys_to_ignore_on_load_missing = [r"position_ids", r"predictions.decoder.bias"]
def __init__(self, config): super().__init__(config)
self.bert = BertModel(config, add_pooling_layer=False) self.cls = BertOnlyMLMHead(config)
self.init_weights()
def get_output_embeddings(self): return self.cls.predictions.decoder
def set_output_embeddings(self, new_embeddings): self.cls.predictions.decoder = new_embeddings
def forward( self, input_ids=None, attention_mask=None, position_ids=None, head_mask=None, query_embeds=None, encoder_hidden_states=None, encoder_attention_mask=None, labels=None, past_key_values=None, use_cache=True, output_attentions=None, output_hidden_states=None, return_dict=None, return_logits=False, is_decoder=True, reduction="mean", ): r""" encoder_hidden_states (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length, hidden_size)`, `optional`): Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if the model is configured as a decoder. encoder_attention_mask (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`): Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in the cross-attention if the model is configured as a decoder. Mask values selected in ``[0, 1]``: - 1 for tokens that are **not masked**, - 0 for tokens that are **masked**. labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`): Labels for computing the left-to-right language modeling loss (next word prediction). Indices should be in ``[-100, 0, ..., config.vocab_size]`` (see ``input_ids`` docstring) Tokens with indices set to ``-100`` are ignored (masked), the loss is only computed for the tokens with labels n ``[0, ..., config.vocab_size]`` past_key_values (:obj:`tuple(tuple(torch.FloatTensor))` of length :obj:`config.n_layers` with each tuple having 4 tensors of shape :obj:`(batch_size, num_heads, sequence_length - 1, embed_size_per_head)`): Contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding. If :obj:`past_key_values` are used, the user can optionally input only the last :obj:`decoder_input_ids` (those that don't have their past key value states given to this model) of shape :obj:`(batch_size, 1)` instead of all :obj:`decoder_input_ids` of shape :obj:`(batch_size, sequence_length)`. use_cache (:obj:`bool`, `optional`): If set to :obj:`True`, :obj:`past_key_values` key value states are returned and can be used to speed up decoding (see :obj:`past_key_values`). Returns: Example:: >>> from transformers import BertTokenizer, BertLMHeadModel, BertConfig >>> import torch >>> tokenizer = BertTokenizer.from_pretrained('bert-base-cased') >>> config = BertConfig.from_pretrained("bert-base-cased") >>> model = BertLMHeadModel.from_pretrained('bert-base-cased', config=config) >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt") >>> outputs = model(**inputs) >>> prediction_logits = outputs.logits """ return_dict = return_dict if return_dict is not None else self.config.use_return_dict if labels is not None: use_cache = False if past_key_values is not None: query_embeds = None
outputs = self.bert( input_ids, attention_mask=attention_mask, position_ids=position_ids, head_mask=head_mask, query_embeds=query_embeds, encoder_hidden_states=encoder_hidden_states, encoder_attention_mask=encoder_attention_mask, past_key_values=past_key_values, use_cache=use_cache, output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict, is_decoder=is_decoder, )
sequence_output = outputs[0] if query_embeds is not None: sequence_output = outputs[0][:, query_embeds.shape[1] :, :]
prediction_scores = self.cls(sequence_output)
if return_logits: return prediction_scores[:, :-1, :].contiguous()
lm_loss = None if labels is not None: # we are doing next-token prediction; shift prediction scores and input ids by one shifted_prediction_scores = prediction_scores[:, :-1, :].contiguous() labels = labels[:, 1:].contiguous() loss_fct = CrossEntropyLoss(reduction=reduction, label_smoothing=0.1) lm_loss = loss_fct( shifted_prediction_scores.view(-1, self.config.vocab_size), labels.view(-1), ) if reduction == "none": lm_loss = lm_loss.view(prediction_scores.size(0), -1).sum(1)
if not return_dict: output = (prediction_scores,) + outputs[2:] return ((lm_loss,) + output) if lm_loss is not None else output
return CausalLMOutputWithCrossAttentions( loss=lm_loss, logits=prediction_scores, past_key_values=outputs.past_key_values, hidden_states=outputs.hidden_states, attentions=outputs.attentions, cross_attentions=outputs.cross_attentions, )
def prepare_inputs_for_generation(self, input_ids, query_embeds, past=None, attention_mask=None, **model_kwargs): # if model is used as a decoder in encoder-decoder model, the decoder attention mask is created on the fly if attention_mask is None: attention_mask = input_ids.new_ones(input_ids.shape) query_mask = input_ids.new_ones(query_embeds.shape[:-1]) attention_mask = torch.cat([query_mask, attention_mask], dim=-1)
# cut decoder_input_ids if past is used if past is not None: input_ids = input_ids[:, -1:]
return { "input_ids": input_ids, "query_embeds": query_embeds, "attention_mask": attention_mask, "past_key_values": past, "encoder_hidden_states": model_kwargs.get("encoder_hidden_states", None), "encoder_attention_mask": model_kwargs.get("encoder_attention_mask", None), "is_decoder": True, }
def _reorder_cache(self, past, beam_idx): reordered_past = () for layer_past in past: reordered_past += (tuple(past_state.index_select(0, beam_idx) for past_state in layer_past),) return reordered_past
def load_qformer( num_query_tokens: int, encoder_width: int, vocab_size: int = 30523, hidden_size: int = 768, cross_attention_freq: int = 2, base_model: Literal["bert-base-uncased", "bert-large-uncased"] = "bert-base-uncased",) -> BertLMHeadModel: """Utility to load QFormer module.
Args: num_query_tokens (int): number of query tokens. encoder_width (int): vector length of visual encoder embeddings. hidden_size (int): vector length of BERT's attention blocks. cross_attention_freq (int): block frequency of visual cross-attention. base_model (str): Base text model for QFormer. Default `bert-base-uncased`.
Returns: `BertLMHeadModel` module. """
encoder_config = BertConfig.from_pretrained(base_model) encoder_config.encoder_width = encoder_width encoder_config.hidden_size = hidden_size encoder_config.add_cross_attention = True encoder_config.cross_attention_freq = cross_attention_freq encoder_config.query_length = num_query_tokens encoder_config.vocab_size = vocab_size qformer = BertLMHeadModel(encoder_config) return qformer123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0## 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.
"""Misc functions and modules for Cosmos-Embed1."""
import functoolsfrom logging import getLoggerfrom typing import Callable, Optional, Protocol
import torchimport torch.distributed as distimport torch.nn as nn
logger = getLogger(__file__)
def get_rank(group: Optional[dist.ProcessGroup] = None) -> int: """Get the rank (GPU device) of the worker.
Returns: rank (int): The rank of the worker. """ rank = 0 if dist.is_available() and dist.is_initialized(): rank = dist.get_rank(group) return rank
def barrier() -> None: """Barrier for all GPUs.""" if dist.is_available() and dist.is_initialized(): dist.barrier()
def rank0_first(func: Callable) -> Callable: """Run the function on rank 0 first, then on other ranks."""
@functools.wraps(func) def wrapper(*args, **kwargs): # noqa: ANN202 if get_rank() == 0: result = func(*args, **kwargs) barrier() if get_rank() != 0: result = func(*args, **kwargs) return result
return wrapper
def add_docstring(docstring: str): def decorator(func): func.__doc__ = docstring return func
return decorator
INIT_DOCSTRING = """Constructor for encoding module.
Args: embed_dim: size of embedding vectors, e.g. x.shape[3]. max_len: maximum length of temporal sequence, e.g. x.shape[1]."""
FORWARD_DOCSTRING = """Forward function.
Args: x (`torch.Tensor`): rank 4 tensor to add spatio-temporal encodings to.
Returns: `torch.Tensor` of rank 4."""
class EncodingProtocol(Protocol): def __init__(self, embed_dim: int, max_len: int) -> None: pass
def forward(self, x: torch.Tensor) -> torch.Tensor: pass
def interpolate_temp_pos_embed(temp_embed: torch.Tensor, num_frames: int) -> torch.Tensor: """Linearly interpolates temporal encoding from `temp_embed.shape[0] to num_frames."""
temp_embed_resized = temp_embed.permute(1, 0).unsqueeze(0) temp_embed_resized = nn.functional.interpolate( temp_embed_resized, size=(num_frames), mode="linear", align_corners=False, ) return temp_embed_resized.squeeze(0).permute(1, 0)
class TemporalParameterEncoding(nn.Module, EncodingProtocol): @add_docstring(INIT_DOCSTRING) def __init__(self, embed_dim: int, max_len: int) -> None: super().__init__() self.embed_dim = embed_dim self.max_len = max_len self.temp_embed = nn.Parameter(torch.zeros(self.max_len, self.embed_dim)) nn.init.trunc_normal_(self.temp_embed, std=0.02)
@add_docstring(FORWARD_DOCSTRING) def forward(self, x: torch.Tensor) -> torch.Tensor: _, t, _, _ = x.shape if t != self.temp_embed.shape[0]: logger.debug(f"Interpolating temporal encodings from {self.temp_embed.shape[0]} to {t}.") temp_embed = interpolate_temp_pos_embed(self.temp_embed, t) else: temp_embed = self.temp_embed temp_embed = temp_embed.unsqueeze(0).unsqueeze(2) return x + temp_embed
def create_neighbor_weight_matrix(num_tokens: int, device: torch.device, dtype: torch.dtype) -> torch.Tensor: indices = torch.arange(num_tokens, dtype=dtype, device=device) abs_diff = torch.abs(indices.unsqueeze(0) - indices.unsqueeze(1)) weights = 1.0 / (2.0**abs_diff) return weights
def compute_t_adj(x: torch.Tensor, weights: torch.Tensor) -> torch.Tensor: return torch.einsum("bfnd,nk->bfkd", x, weights)
def token_propagation(x: torch.Tensor, num_tokens: int) -> torch.Tensor: """Apply neighboring token propagation update.""" weights = create_neighbor_weight_matrix(num_tokens, x.device, x.dtype) t_adj = compute_t_adj(x, weights) return x + t_adj - t_adj.detach()
class NeighboringTokenPropagationEncoding(TemporalParameterEncoding): """ Neighboring Token Propagation method inspired by Momentor (https://arxiv.org/abs/2402.11435) """
@add_docstring(FORWARD_DOCSTRING) def forward(self, x: torch.Tensor) -> torch.Tensor: _, t, q, _ = x.shape if t != self.temp_embed.shape[0]: logger.debug(f"Interpolating temporal encodings from {self.temp_embed.shape[0]} to {t}.") temp_embed = interpolate_temp_pos_embed(self.temp_embed, t) else: temp_embed = self.temp_embed temp_embed = temp_embed.unsqueeze(0).unsqueeze(2)
if self.training: temp_embed = token_propagation(temp_embed, q) return x + temp_embed
class EncodingFactory(nn.Module): def __init__(self, encoding_type: str, embed_dim: int, max_len: int) -> None: super().__init__() fn = { "temporal_parameter": TemporalParameterEncoding, "neighboring_token_propagation": NeighboringTokenPropagationEncoding, }[encoding_type] self.encoding = fn(embed_dim=embed_dim, max_len=max_len)
@add_docstring(FORWARD_DOCSTRING) def forward(self, x: torch.Tensor) -> torch.Tensor: return self.encoding(x)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0## 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.
# Copyright (c) 2023, salesforce.com, inc.# All rights reserved.# SPDX-License-Identifier: BSD-3-Clause# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
"""EVA-CLIP backbone used in BLIP2.
Code adapted from:https://github.com/salesforce/LAVIS/blob/main/lavis/models/eva_vit.py"""
import mathfrom functools import partialfrom logging import getLoggerfrom typing import Any, Optional, Tuple, Union
import torchimport torch.nn as nnimport torch.nn.functional as Fimport torch.utils.checkpoint as checkpoint
logger = getLogger(__file__)
TRANSFORMER_ENGINE_AVAILABLE = Falsetry: import transformer_engine.pytorch as te from transformer_engine.common.recipe import DelayedScaling, Format
TRANSFORMER_ENGINE_AVAILABLE = True logger.info("Transformer Engine is available, can set `transformer_engine=True` in config " "for faster inference.")except ImportError: pass
def drop_path(x, drop_prob: float = 0.0, training: bool = False, scale_by_keep: bool = True): """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
From https://github.com/huggingface/pytorch-image-models/blob/main/timm/layers/drop.py """ if drop_prob == 0.0 or not training: return x keep_prob = 1 - drop_prob shape = (x.shape[0],) + (1,) * (x.ndim - 1) # work with diff dim tensors, not just 2D ConvNets random_tensor = x.new_empty(shape).bernoulli_(keep_prob) if keep_prob > 0.0 and scale_by_keep: random_tensor.div_(keep_prob) return x * random_tensor
class DropPath(nn.Module): """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks)."""
def __init__(self, drop_prob: float) -> None: super().__init__() self.drop_prob = drop_prob
def forward(self, x: torch.Tensor) -> torch.Tensor: return drop_path(x, self.drop_prob, self.training)
def extra_repr(self) -> str: return "p={}".format(self.drop_prob)
class Mlp(nn.Module): def __init__( self, in_features: int, hidden_features: Optional[int] = None, out_features: Optional[int] = None, act_layer=nn.GELU, drop: float = 0.0, transformer_engine: bool = False, ) -> None: super().__init__() out_features = out_features or in_features hidden_features = hidden_features or in_features fn = te.Linear if transformer_engine else nn.Linear self.fc1 = fn(in_features, hidden_features) self.act = act_layer() self.fc2 = fn(hidden_features, out_features) self.drop = nn.Dropout(drop)
def forward(self, x): x = self.fc1(x) x = self.act(x) x = self.fc2(x) x = self.drop(x) return x
class Attention(nn.Module): def __init__( self, dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0.0, proj_drop=0.0, window_size=None, attn_head_dim=None, **kwargs, ): super().__init__() self.num_heads = num_heads head_dim = dim // num_heads if attn_head_dim is not None: head_dim = attn_head_dim all_head_dim = head_dim * self.num_heads self.scale = qk_scale or head_dim**-0.5
self.qkv = nn.Linear(dim, all_head_dim * 3, bias=qkv_bias)
if window_size: self.window_size = window_size self.num_relative_distance = (2 * window_size[0] - 1) * (2 * window_size[1] - 1) + 3 self.relative_position_bias_table = nn.Parameter( torch.zeros(self.num_relative_distance, num_heads) ) # 2*Wh-1 * 2*Ww-1, nH # cls to token & token 2 cls & cls to cls
# get pair-wise relative position index for each token inside the window coords_h = torch.arange(window_size[0]) coords_w = torch.arange(window_size[1]) coords = torch.stack(torch.meshgrid([coords_h, coords_w])) # 2, Wh, Ww coords_flatten = torch.flatten(coords, 1) # 2, Wh*Ww relative_coords = coords_flatten[:, :, None] - coords_flatten[:, None, :] # 2, Wh*Ww, Wh*Ww relative_coords = relative_coords.permute(1, 2, 0).contiguous() # Wh*Ww, Wh*Ww, 2 relative_coords[:, :, 0] += window_size[0] - 1 # shift to start from 0 relative_coords[:, :, 1] += window_size[1] - 1 relative_coords[:, :, 0] *= 2 * window_size[1] - 1 relative_position_index = torch.zeros( size=(window_size[0] * window_size[1] + 1,) * 2, dtype=relative_coords.dtype ) relative_position_index[1:, 1:] = relative_coords.sum(-1) # Wh*Ww, Wh*Ww relative_position_index[0, 0:] = self.num_relative_distance - 3 relative_position_index[0:, 0] = self.num_relative_distance - 2 relative_position_index[0, 0] = self.num_relative_distance - 1
self.register_buffer("relative_position_index", relative_position_index) else: self.window_size = None self.relative_position_bias_table = None self.relative_position_index = None
self.attn_drop = nn.Dropout(attn_drop) self.proj = nn.Linear(all_head_dim, dim) self.proj_drop = nn.Dropout(proj_drop)
def forward(self, x, rel_pos_bias=None): B, N, C = x.shape qkv = self.qkv(x) qkv = qkv.reshape(B, N, 3, self.num_heads, -1).permute(2, 0, 3, 1, 4) q, k, v = qkv[0], qkv[1], qkv[2]
q = q * self.scale attn = q @ k.transpose(-2, -1)
if self.relative_position_bias_table is not None: relative_position_bias = self.relative_position_bias_table[self.relative_position_index.view(-1)].view( self.window_size[0] * self.window_size[1] + 1, self.window_size[0] * self.window_size[1] + 1, -1 ) # Wh*Ww,Wh*Ww,nH relative_position_bias = relative_position_bias.permute(2, 0, 1).contiguous() # nH, Wh*Ww, Wh*Ww attn = attn + relative_position_bias.unsqueeze(0)
if rel_pos_bias is not None: attn = attn + rel_pos_bias
attn = attn.softmax(dim=-1) attn = self.attn_drop(attn)
x = (attn @ v).transpose(1, 2).reshape(B, N, -1) x = self.proj(x) x = self.proj_drop(x) return x
class TransformerEngineAttention(nn.Module): def __init__( self, dim: int, num_heads: int = 8, qkv_bias: bool = False, qk_scale: Optional[float] = None, attn_drop: float = 0.0, proj_drop: float = 0.0, window_size: Optional[int] = None, attn_head_dim: Optional[int] = None, checkpoint_attention: bool = False, ): super().__init__() self.num_heads = num_heads self.checkpoint_attention = checkpoint_attention head_dim = dim // num_heads if attn_head_dim is not None: head_dim = attn_head_dim all_head_dim = head_dim * self.num_heads self.scale = qk_scale or head_dim**-0.5
# QKV projection self.qkv = te.Linear(dim, all_head_dim * 3, bias=qkv_bias)
if window_size: raise NotImplementedError("`window_size` not implemented for TE!")
self.te_attn = te.DotProductAttention( num_attention_heads=num_heads, kv_channels=head_dim, attention_dropout=attn_drop, qkv_format="bshd", softmax_scale=self.scale, attn_mask_type="no_mask", )
# output projection + dropout self.proj = te.Linear(all_head_dim, dim) self.proj_drop = nn.Dropout(proj_drop)
def forward(self, x: torch.Tensor, rel_pos_bias: Optional[torch.Tensor] = None) -> torch.Tensor: """ x: [B, N, C] rel_pos_bias (optional): tensor of shape [num_heads, N, N] """ B, N, _ = x.shape qkv = self.qkv(x) qkv = qkv.reshape(B, N, 3, self.num_heads, -1).permute(2, 0, 1, 3, 4) q, k, v = qkv[0], qkv[1], qkv[2] # BNHC format
if rel_pos_bias is not None: raise NotImplementedError("`rel_pos_bias` not implemented for TE!")
# run TE's fused attention y = self.te_attn(q, k, v, checkpoint_core_attention=self.checkpoint_attention)
# final proj + dropout return self.proj_drop(self.proj(y))
class Block(nn.Module): def __init__( self, dim, num_heads, mlp_ratio=4.0, qkv_bias=False, qk_scale=None, drop=0.0, attn_drop=0.0, drop_path=0.0, init_values=None, act_layer=nn.GELU, norm_layer=nn.LayerNorm, window_size=None, attn_head_dim=None, transformer_engine: bool = False, checkpoint_attention: bool = False, ): super().__init__() self.transformer_engine = transformer_engine self.window_size = window_size self.checkpoint_attention = checkpoint_attention
if checkpoint_attention and not transformer_engine: raise ValueError("`checkpoint_attention` needs `transformer_engine`!")
self.norm1 = norm_layer(dim) attn_fn = TransformerEngineAttention if transformer_engine else Attention self.attn = attn_fn( dim, num_heads=num_heads, qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop, window_size=window_size, attn_head_dim=attn_head_dim, checkpoint_attention=checkpoint_attention, )
# NOTE: drop path for stochastic depth, we shall see if this is better than dropout here self.drop_path = DropPath(drop_path) if drop_path > 0.0 else nn.Identity() self.norm2 = norm_layer(dim) mlp_hidden_dim = int(dim * mlp_ratio) self.mlp = Mlp( in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop, transformer_engine=transformer_engine, )
if init_values is not None and init_values > 0: self.gamma_1 = nn.Parameter(init_values * torch.ones((dim)), requires_grad=True) self.gamma_2 = nn.Parameter(init_values * torch.ones((dim)), requires_grad=True) else: self.gamma_1, self.gamma_2 = None, None
def forward(self, x, rel_pos_bias=None): if self.gamma_1 is None: x = x + self.drop_path(self.attn(self.norm1(x), rel_pos_bias=rel_pos_bias)) x = x + self.drop_path(self.mlp(self.norm2(x))) else: x = x + self.drop_path(self.gamma_1 * self.attn(self.norm1(x), rel_pos_bias=rel_pos_bias)) x = x + self.drop_path(self.gamma_2 * self.mlp(self.norm2(x))) return x
class PatchEmbed(nn.Module): """Image to Patch Embedding"""
def __init__( self, img_size: Union[int, Tuple[int, int]] = 224, patch_size: Union[int, Tuple[int, int]] = 16, in_chans: int = 3, embed_dim: int = 768, ): super().__init__() img_size = (img_size, img_size) if isinstance(img_size, int) else img_size patch_size = (patch_size, patch_size) if isinstance(patch_size, int) else patch_size num_patches = (img_size[1] // patch_size[1]) * (img_size[0] // patch_size[0]) self.patch_shape = (img_size[0] // patch_size[0], img_size[1] // patch_size[1]) self.img_size = img_size self.patch_size = patch_size self.num_patches = num_patches
self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size)
def forward(self, x, **kwargs): B, C, H, W = x.shape assert ( H == self.img_size[0] and W == self.img_size[1] ), f"Input image size ({H}*{W}) doesn't match model ({self.img_size[0]}*{self.img_size[1]})." x = self.proj(x).flatten(2).transpose(1, 2) return x
class RelativePositionBias(nn.Module): def __init__(self, window_size, num_heads): super().__init__() self.window_size = window_size self.num_relative_distance = (2 * window_size[0] - 1) * (2 * window_size[1] - 1) + 3 self.relative_position_bias_table = nn.Parameter( torch.zeros(self.num_relative_distance, num_heads) ) # 2*Wh-1 * 2*Ww-1, nH # cls to token & token 2 cls & cls to cls
# get pair-wise relative position index for each token inside the window coords_h = torch.arange(window_size[0]) coords_w = torch.arange(window_size[1]) coords = torch.stack(torch.meshgrid([coords_h, coords_w])) # 2, Wh, Ww coords_flatten = torch.flatten(coords, 1) # 2, Wh*Ww relative_coords = coords_flatten[:, :, None] - coords_flatten[:, None, :] # 2, Wh*Ww, Wh*Ww relative_coords = relative_coords.permute(1, 2, 0).contiguous() # Wh*Ww, Wh*Ww, 2 relative_coords[:, :, 0] += window_size[0] - 1 # shift to start from 0 relative_coords[:, :, 1] += window_size[1] - 1 relative_coords[:, :, 0] *= 2 * window_size[1] - 1 relative_position_index = torch.zeros( size=(window_size[0] * window_size[1] + 1,) * 2, dtype=relative_coords.dtype ) relative_position_index[1:, 1:] = relative_coords.sum(-1) # Wh*Ww, Wh*Ww relative_position_index[0, 0:] = self.num_relative_distance - 3 relative_position_index[0:, 0] = self.num_relative_distance - 2 relative_position_index[0, 0] = self.num_relative_distance - 1
self.register_buffer("relative_position_index", relative_position_index)
def forward(self): relative_position_bias = self.relative_position_bias_table[self.relative_position_index.view(-1)].view( self.window_size[0] * self.window_size[1] + 1, self.window_size[0] * self.window_size[1] + 1, -1 ) # Wh*Ww,Wh*Ww,nH return relative_position_bias.permute(2, 0, 1).contiguous() # nH, Wh*Ww, Wh*Ww
class VisionTransformer(nn.Module): """Vision Transformer with support for patch or hybrid CNN input stage"""
def __init__( self, img_size=224, patch_size=16, in_chans=3, num_classes=1000, embed_dim=768, depth=12, num_heads=12, mlp_ratio=4.0, qkv_bias=False, qk_scale=None, drop_rate=0.0, attn_drop_rate=0.0, drop_path_rate=0.0, norm_layer=nn.LayerNorm, init_values=None, use_abs_pos_emb=True, use_rel_pos_bias=False, use_shared_rel_pos_bias=False, use_mean_pooling=True, init_scale=0.001, checkpoint_activations: bool = False, checkpoint_attention: bool = False, transformer_engine: bool = False, use_fp8: bool = False, ): super().__init__() self.image_size = img_size self.patch_size = patch_size self.num_classes = num_classes self.num_features = self.embed_dim = embed_dim # num_features for consistency with other models self.transformer_engine = transformer_engine self.use_fp8 = use_fp8 self.fp8_recipe = None
if use_fp8 and not transformer_engine: raise ValueError("`transformer_engine` must be enabled for `use_fp8`.") if use_fp8: # FP8 Recipe: Hybrid E4M3 forward, E5M2 backward self.fp8_recipe = DelayedScaling(fp8_format=Format.HYBRID, amax_history_len=16, amax_compute_algo="max")
self.patch_embed = PatchEmbed(img_size=img_size, patch_size=patch_size, in_chans=in_chans, embed_dim=embed_dim) num_patches = self.patch_embed.num_patches
self.cls_token = nn.Parameter(torch.zeros(1, 1, embed_dim)) if use_abs_pos_emb: self.pos_embed = nn.Parameter(torch.zeros(1, num_patches + 1, embed_dim)) else: self.pos_embed = None self.pos_drop = nn.Dropout(p=drop_rate)
if use_shared_rel_pos_bias: self.rel_pos_bias = RelativePositionBias(window_size=self.patch_embed.patch_shape, num_heads=num_heads) else: self.rel_pos_bias = None self.checkpoint_activations = checkpoint_activations self.checkpoint_attention = checkpoint_attention
dpr = [x.item() for x in torch.linspace(0, drop_path_rate, depth)] # stochastic depth decay rule self.use_rel_pos_bias = use_rel_pos_bias self.blocks = nn.ModuleList( [ Block( dim=embed_dim, num_heads=num_heads, mlp_ratio=mlp_ratio, qkv_bias=qkv_bias, qk_scale=qk_scale, drop=drop_rate, attn_drop=attn_drop_rate, drop_path=dpr[i], norm_layer=norm_layer, init_values=init_values, window_size=self.patch_embed.patch_shape if use_rel_pos_bias else None, transformer_engine=transformer_engine, checkpoint_attention=self.checkpoint_attention, ) for i in range(depth) ] )
if self.pos_embed is not None: nn.init.trunc_normal_(self.pos_embed, std=0.02) nn.init.trunc_normal_(self.cls_token, std=0.02)
self.apply(self._init_weights) self.fix_init_weight()
def fix_init_weight(self): def rescale(param, layer_id): param.div_(math.sqrt(2.0 * layer_id))
for layer_id, layer in enumerate(self.blocks): rescale(layer.attn.proj.weight.data, layer_id + 1) rescale(layer.mlp.fc2.weight.data, layer_id + 1)
def _init_weights(self, m): if isinstance(m, nn.Linear): nn.init.trunc_normal_(m.weight, std=0.02) if isinstance(m, nn.Linear) and m.bias is not None: nn.init.constant_(m.bias, 0) elif isinstance(m, nn.LayerNorm): nn.init.constant_(m.bias, 0) nn.init.constant_(m.weight, 1.0)
def get_classifier(self): return self.head
def reset_classifier(self, num_classes, global_pool=""): self.num_classes = num_classes self.head = nn.Linear(self.embed_dim, num_classes) if num_classes > 0 else nn.Identity()
def forward_features(self, x): if self.transformer_engine and self.use_fp8: with te.fp8_autocast(enabled=True, fp8_recipe=self.fp8_recipe): return self._forward_uncast(x) return self._forward_uncast(x)
def _forward_uncast(self, x): x = self.patch_embed(x) batch_size, seq_len, _ = x.size()
cls_tokens = self.cls_token.expand(batch_size, -1, -1) x = torch.cat((cls_tokens, x), dim=1) if self.pos_embed is not None: x = x + self.pos_embed x = self.pos_drop(x)
rel_pos_bias = self.rel_pos_bias() if self.rel_pos_bias is not None else None for blk in self.blocks: if self.checkpoint_activations: x = checkpoint.checkpoint(blk, x, rel_pos_bias) else: x = blk(x, rel_pos_bias) return x
def forward(self, x): x = self.forward_features(x) return x
def get_intermediate_layers(self, x): x = self.patch_embed(x) batch_size, seq_len, _ = x.size()
cls_tokens = self.cls_token.expand(batch_size, -1, -1) x = torch.cat((cls_tokens, x), dim=1) if self.pos_embed is not None: x = x + self.pos_embed x = self.pos_drop(x)
features = [] rel_pos_bias = self.rel_pos_bias() if self.rel_pos_bias is not None else None for blk in self.blocks: x = blk(x, rel_pos_bias) features.append(x)
return features
def get_num_layer(self, var_name=""): if var_name in ("cls_token", "mask_token", "pos_embed"): return 0 elif var_name.startswith("patch_embed"): return 0 elif var_name.startswith("rel_pos_bias"): return len(self.blocks) - 1 elif var_name.startswith("blocks"): layer_id = int(var_name.split(".")[1]) return layer_id + 1 else: return len(self.blocks)
def interpolate_pos_embed( pos_embed_key: str, num_patches: int, patch_embed_shape: torch.Size, checkpoint_model: dict[str, torch.Tensor], target_h: int = None, target_w: int = None,) -> None: if pos_embed_key in checkpoint_model: pos_embed_checkpoint = checkpoint_model[pos_embed_key].float() embedding_size = pos_embed_checkpoint.shape[-1] num_extra_tokens = patch_embed_shape - num_patches # height (== width) for the checkpoint position embedding orig_size = int((pos_embed_checkpoint.shape[-2] - num_extra_tokens) ** 0.5)
# If target dimensions are provided, use them; otherwise assume square if target_h is not None and target_w is not None: new_h, new_w = target_h, target_w else: # height (== width) for the new position embedding (square assumption) new_size = int(num_patches**0.5) new_h, new_w = new_size, new_size
# class_token and dist_token are kept unchanged if orig_size * orig_size != new_h * new_w: logger.info("Positional interpolation from %dx%d to %dx%d" % (orig_size, orig_size, new_h, new_w)) extra_tokens = pos_embed_checkpoint[:, :num_extra_tokens] # only the position tokens are interpolated pos_tokens = pos_embed_checkpoint[:, num_extra_tokens:] pos_tokens = pos_tokens.reshape(-1, orig_size, orig_size, embedding_size).permute(0, 3, 1, 2) pos_tokens = torch.nn.functional.interpolate( pos_tokens, size=(new_h, new_w), mode="bicubic", align_corners=False ) pos_tokens = pos_tokens.permute(0, 2, 3, 1).flatten(1, 2) new_pos_embed = torch.cat((extra_tokens, pos_tokens), dim=1) checkpoint_model[pos_embed_key] = new_pos_embed
class PositionalEmbeddingHook: def __init__(self, pos_embed_name, num_patches, patch_embed_shape, target_h=None, target_w=None): self.pos_embed_name = pos_embed_name self.num_patches = num_patches self.patch_embed_shape = patch_embed_shape self.target_h = target_h self.target_w = target_w
def __call__(self, state_dict, prefix, *args, **kwargs) -> None: logger.info("Calling `PositionalEmbeddingHook`") pos_embed_key = f"{prefix}{self.pos_embed_name}" interpolate_pos_embed( pos_embed_key, self.num_patches, self.patch_embed_shape, state_dict, self.target_h, self.target_w )
class EvaViTG(VisionTransformer): def __init__( self, img_size: Union[int, Tuple[int, int]] = 224, drop_path_rate: float = 0.4, pretrained: bool = False, checkpoint_path: Optional[str] = None, checkpoint_activations: bool = False, checkpoint_attention: bool = False, transformer_engine: bool = False, use_fp8: bool = False, **kwargs: Any, ) -> None: if not TRANSFORMER_ENGINE_AVAILABLE and transformer_engine: raise ValueError( "TransformerEngine is not available, " "please install transformer-engine or set `transformer_engine=False` in config." ) if use_fp8 and not transformer_engine: raise ValueError("`transformer_engine` must be enabled for `use_fp8`.") super().__init__( img_size=img_size, patch_size=14, use_mean_pooling=False, embed_dim=1408, depth=39, num_heads=1408 // 88, mlp_ratio=4.3637, qkv_bias=True, drop_path_rate=drop_path_rate, norm_layer=partial(nn.LayerNorm, eps=1e-6), checkpoint_activations=checkpoint_activations, checkpoint_attention=checkpoint_attention, transformer_engine=transformer_engine, use_fp8=use_fp8, ) self.checkpoint_path = checkpoint_path
# compatibility with pre-trained checkpoints self.register_pre_hooks()
# load pre-trained checkpoints if pretrained: self.load_checkpoint()
def load_checkpoint(self) -> None: logger.info(f"Loading checkpoint from {self.checkpoint_path}") state_dict = torch.load(self.checkpoint_path, map_location="cpu") incompatible_keys = self.load_state_dict(state_dict, strict=False) logger.info(f"Incompatible keys: {incompatible_keys}") logger.info(f"Loaded visual encoder {type(self)} with state dict from {self.checkpoint_path}")
def register_pre_hooks(self) -> None: """Register positional embedding interpolation when loading pre-trained checkpoints using different resolution.""" # Calculate target patch dimensions for non-square support patch_h = self.patch_embed.patch_shape[0] patch_w = self.patch_embed.patch_shape[1]
embed_hook = PositionalEmbeddingHook( pos_embed_name="pos_embed", num_patches=self.patch_embed.num_patches, patch_embed_shape=self.pos_embed.shape[-2], target_h=patch_h, target_w=patch_w, ) self._register_load_state_dict_pre_hook(embed_hook)
def _initialize_weights(self, m): if isinstance(m, nn.Linear): nn.init.trunc_normal_(m.weight, std=0.02) if isinstance(m, nn.Linear) and m.bias is not None: nn.init.constant_(m.bias, 0) elif isinstance(m, nn.LayerNorm): nn.init.constant_(m.bias, 0) nn.init.constant_(m.weight, 1.0)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0## 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.
"""Processor class for Cosmos-Embed1"""
from typing import List, Optional, Tuple, Union
import numpy as npimport torchimport torchvisionfrom transformers import AutoProcessor, BatchFeaturefrom transformers.processing_utils import ProcessorMixinfrom transformers.utils import TensorType
from .configuration_embed1 import CosmosEmbed1Config
class CosmosEmbed1Processor(ProcessorMixin): r""" Constructs a processor which wraps a BertTokenizer tokenizer and a fast video resize function.
Args: tokenizer ([`BertTokenizerFast`], *optional*): The tokenizer is a required input for text processing. config ([`CosmosEmbed1Config`], *optional*): Needed for processing options. """
attributes = ["tokenizer"] tokenizer_class = ("BertTokenizer", "BertTokenizerFast") config_class = CosmosEmbed1Config chat_template = None
def __init__( self, tokenizer=None, resolution: Union[int, Tuple[int, int]] = 336, num_video_frames: int = 8, max_txt_len: int = 128, **kwargs, ) -> None: super().__init__(tokenizer, **kwargs) self.resolution = resolution self.num_video_frames = num_video_frames self.max_txt_len = max_txt_len
def __call__( self, text: Optional[Union[str, List[str]]] = None, videos: Optional[Union[np.ndarray, torch.Tensor]] = None, return_tensors: Optional[Union[str, TensorType]] = TensorType.PYTORCH, resolution: Union[int, Tuple[int, int]] = None, num_video_frames: int = None, max_txt_len: int = None, **kwargs, ) -> BatchFeature: inputs = {}
if text is not None: max_txt_len = max_txt_len if max_txt_len is not None else self.max_txt_len tokenized = self.tokenizer( text, return_tensors="pt", padding="max_length", truncation=True, max_length=max_txt_len, **kwargs ) inputs["input_ids"] = tokenized.input_ids inputs["attention_mask"] = tokenized.attention_mask.float()
if videos is not None: if isinstance(videos, np.ndarray): videos = torch.from_numpy(videos) if not isinstance(videos, torch.Tensor) or videos.ndim != 5: raise ValueError("Processor expects a numpy or torch tensor of shape BTCHW from [0-255].") resolution = resolution if resolution is not None else self.resolution if isinstance(resolution, int): resolution = (resolution, resolution) _, t, c, h, w = videos.shape if c != 3: raise ValueError(f"Expected tensor of shape BTCHW with RGB channels, got channel size {c}.") num_video_frames = num_video_frames if num_video_frames is not None else self.num_video_frames if t != num_video_frames: raise ValueError(f"Expected tensor of shape BTCHW with {num_video_frames} frames, got {t}.") if h != resolution[0] or w != resolution[1]: videos = resize_video(videos, resolution) if videos.dtype == torch.uint8: videos = videos.float() inputs["videos"] = videos / 255.0
if not inputs: raise ValueError("Must pass either `text` or `videos` argument to __call__ function.")
return BatchFeature(inputs, tensor_type=return_tensors)
def resize_video(video: torch.Tensor, size: Tuple[int, int]) -> torch.Tensor: """Resize a video tensor (B, T, C, H, W) to a new height/width.
Args: video (torch.Tensor): (B, T, C, H, W) uint8 or float32. size (tuple): target (H', W') size. Returns: torch.Tensor: resized video of shape (B, T, C, H', W') """ h, w = size B, T, C, H, W = video.shape video = video.view(B * T, C, H, W) resize = torchvision.transforms.Resize( (h, w), antialias=True, interpolation=torchvision.transforms.InterpolationMode.BILINEAR, ) video = resize(video) new_H, new_W = video.shape[-2:] video = video.view(B, T, C, new_H, new_W) return video
AutoProcessor.register(CosmosEmbed1Config, CosmosEmbed1Processor)
__all__ = ["CosmosEmbed1Processor"]123456789{ "processor_class": "CosmosEmbed1Processor", "auto_map": { "AutoProcessor": "preprocessing_embed1.CosmosEmbed1Processor" }, "resolution": 336, "num_video_frames": 8, "max_txt_len": 128}1234567891011121314151617181920212223242526272829303132333435363738394041424344{ "bos_token": { "content": "[DEC]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }, "cls_token": { "content": "[CLS]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }, "mask_token": { "content": "[MASK]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }, "pad_token": { "content": "[PAD]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }, "sep_token": { "content": "[SEP]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }, "unk_token": { "content": "[UNK]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869{ "added_tokens_decoder": { "0": { "content": "[PAD]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "100": { "content": "[UNK]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "101": { "content": "[CLS]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "102": { "content": "[SEP]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "103": { "content": "[MASK]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "30522": { "content": "[DEC]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true } }, "bos_token": "[DEC]", "clean_up_tokenization_spaces": true, "cls_token": "[CLS]", "do_basic_tokenize": true, "do_lower_case": true, "extra_special_tokens": {}, "mask_token": "[MASK]", "model_max_length": 512, "never_split": null, "pad_token": "[PAD]", "processor_class": "CosmosEmbed1Processor", "sep_token": "[SEP]", "strip_accents": null, "tokenize_chinese_chars": true, "tokenizer_class": "BertTokenizer", "truncation_side": "right", "unk_token": "[UNK]"}.gitattributes+1
.gitignoreAdded+5
README.mdAdded+385
__init__.pyAdded+14
added_tokens.jsonAdded+3
assets/architecture.jpgAdded

Large File Pointer Details
- SHA256: 951f8a58cd455ffc2df2122f9913cb143afd5574ec0a0d9716b40fb70d826008
- Pointer size: 131 Bytes
- Size of remote file: 149 kB
config.jsonAdded+21
configuration_embed1.pyAdded+69
convert_weights.pyAdded+64
examples/example.ipynbAdded
examples/test_smoke.pyAdded+188
model-00001-of-00005.safetensorsAdded+3
model-00002-of-00005.safetensorsAdded+3
model-00003-of-00005.safetensorsAdded+3
model-00004-of-00005.safetensorsAdded+3
model-00005-of-00005.safetensorsAdded+3
model.safetensors.index.jsonAdded+827
modeling_embed1.pyAdded+261
modeling_outputs.pyAdded+69
modeling_qformer.pyAdded+1060
modeling_utils.pyAdded+180
modeling_vit.pyAdded+696
preprocessing_embed1.pyAdded+133
processor_config.jsonAdded+9
special_tokens_map.jsonAdded+44
tokenizer_config.jsonAdded+69
vocab.txtAdded