Upload InternVideo2Stage2VideoEncoder
Browse files- README.md +199 -0
- config.json +169 -0
- config.py +220 -0
- model.py +41 -0
- model.safetensors +3 -0
README.md
ADDED
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
library_name: transformers
|
3 |
+
tags: []
|
4 |
+
---
|
5 |
+
|
6 |
+
# Model Card for Model ID
|
7 |
+
|
8 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
## Model Details
|
13 |
+
|
14 |
+
### Model Description
|
15 |
+
|
16 |
+
<!-- Provide a longer summary of what this model is. -->
|
17 |
+
|
18 |
+
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
19 |
+
|
20 |
+
- **Developed by:** [More Information Needed]
|
21 |
+
- **Funded by [optional]:** [More Information Needed]
|
22 |
+
- **Shared by [optional]:** [More Information Needed]
|
23 |
+
- **Model type:** [More Information Needed]
|
24 |
+
- **Language(s) (NLP):** [More Information Needed]
|
25 |
+
- **License:** [More Information Needed]
|
26 |
+
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
+
|
28 |
+
### Model Sources [optional]
|
29 |
+
|
30 |
+
<!-- Provide the basic links for the model. -->
|
31 |
+
|
32 |
+
- **Repository:** [More Information Needed]
|
33 |
+
- **Paper [optional]:** [More Information Needed]
|
34 |
+
- **Demo [optional]:** [More Information Needed]
|
35 |
+
|
36 |
+
## Uses
|
37 |
+
|
38 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
39 |
+
|
40 |
+
### Direct Use
|
41 |
+
|
42 |
+
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
43 |
+
|
44 |
+
[More Information Needed]
|
45 |
+
|
46 |
+
### Downstream Use [optional]
|
47 |
+
|
48 |
+
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
49 |
+
|
50 |
+
[More Information Needed]
|
51 |
+
|
52 |
+
### Out-of-Scope Use
|
53 |
+
|
54 |
+
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
55 |
+
|
56 |
+
[More Information Needed]
|
57 |
+
|
58 |
+
## Bias, Risks, and Limitations
|
59 |
+
|
60 |
+
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
61 |
+
|
62 |
+
[More Information Needed]
|
63 |
+
|
64 |
+
### Recommendations
|
65 |
+
|
66 |
+
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
67 |
+
|
68 |
+
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
69 |
+
|
70 |
+
## How to Get Started with the Model
|
71 |
+
|
72 |
+
Use the code below to get started with the model.
|
73 |
+
|
74 |
+
[More Information Needed]
|
75 |
+
|
76 |
+
## Training Details
|
77 |
+
|
78 |
+
### Training Data
|
79 |
+
|
80 |
+
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
81 |
+
|
82 |
+
[More Information Needed]
|
83 |
+
|
84 |
+
### Training Procedure
|
85 |
+
|
86 |
+
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
+
|
88 |
+
#### Preprocessing [optional]
|
89 |
+
|
90 |
+
[More Information Needed]
|
91 |
+
|
92 |
+
|
93 |
+
#### Training Hyperparameters
|
94 |
+
|
95 |
+
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
96 |
+
|
97 |
+
#### Speeds, Sizes, Times [optional]
|
98 |
+
|
99 |
+
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
100 |
+
|
101 |
+
[More Information Needed]
|
102 |
+
|
103 |
+
## Evaluation
|
104 |
+
|
105 |
+
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
+
|
107 |
+
### Testing Data, Factors & Metrics
|
108 |
+
|
109 |
+
#### Testing Data
|
110 |
+
|
111 |
+
<!-- This should link to a Dataset Card if possible. -->
|
112 |
+
|
113 |
+
[More Information Needed]
|
114 |
+
|
115 |
+
#### Factors
|
116 |
+
|
117 |
+
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
+
|
119 |
+
[More Information Needed]
|
120 |
+
|
121 |
+
#### Metrics
|
122 |
+
|
123 |
+
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
+
|
125 |
+
[More Information Needed]
|
126 |
+
|
127 |
+
### Results
|
128 |
+
|
129 |
+
[More Information Needed]
|
130 |
+
|
131 |
+
#### Summary
|
132 |
+
|
133 |
+
|
134 |
+
|
135 |
+
## Model Examination [optional]
|
136 |
+
|
137 |
+
<!-- Relevant interpretability work for the model goes here -->
|
138 |
+
|
139 |
+
[More Information Needed]
|
140 |
+
|
141 |
+
## Environmental Impact
|
142 |
+
|
143 |
+
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
+
|
145 |
+
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
+
|
147 |
+
- **Hardware Type:** [More Information Needed]
|
148 |
+
- **Hours used:** [More Information Needed]
|
149 |
+
- **Cloud Provider:** [More Information Needed]
|
150 |
+
- **Compute Region:** [More Information Needed]
|
151 |
+
- **Carbon Emitted:** [More Information Needed]
|
152 |
+
|
153 |
+
## Technical Specifications [optional]
|
154 |
+
|
155 |
+
### Model Architecture and Objective
|
156 |
+
|
157 |
+
[More Information Needed]
|
158 |
+
|
159 |
+
### Compute Infrastructure
|
160 |
+
|
161 |
+
[More Information Needed]
|
162 |
+
|
163 |
+
#### Hardware
|
164 |
+
|
165 |
+
[More Information Needed]
|
166 |
+
|
167 |
+
#### Software
|
168 |
+
|
169 |
+
[More Information Needed]
|
170 |
+
|
171 |
+
## Citation [optional]
|
172 |
+
|
173 |
+
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
+
|
175 |
+
**BibTeX:**
|
176 |
+
|
177 |
+
[More Information Needed]
|
178 |
+
|
179 |
+
**APA:**
|
180 |
+
|
181 |
+
[More Information Needed]
|
182 |
+
|
183 |
+
## Glossary [optional]
|
184 |
+
|
185 |
+
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
+
|
187 |
+
[More Information Needed]
|
188 |
+
|
189 |
+
## More Information [optional]
|
190 |
+
|
191 |
+
[More Information Needed]
|
192 |
+
|
193 |
+
## Model Card Authors [optional]
|
194 |
+
|
195 |
+
[More Information Needed]
|
196 |
+
|
197 |
+
## Model Card Contact
|
198 |
+
|
199 |
+
[More Information Needed]
|
config.json
ADDED
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"InternVideo2Stage2VideoEncoder"
|
4 |
+
],
|
5 |
+
"auto_map": {
|
6 |
+
"AutoConfig": "config.InternVideo2Config",
|
7 |
+
"AutoModel": "model.InternVideo2Stage2VideoEncoder"
|
8 |
+
},
|
9 |
+
"auto_resume": false,
|
10 |
+
"batch_size": 64,
|
11 |
+
"batch_size_test": 4,
|
12 |
+
"best_key": [
|
13 |
+
"msrvtt_1k_test_match",
|
14 |
+
"t2v_r1"
|
15 |
+
],
|
16 |
+
"compile_model": false,
|
17 |
+
"criterion": {
|
18 |
+
"clip_loss_ratio": [
|
19 |
+
1.0,
|
20 |
+
1.0
|
21 |
+
],
|
22 |
+
"distill_final_features": true,
|
23 |
+
"loss_weight": {
|
24 |
+
"mlm": 1.0,
|
25 |
+
"mvm": 0.0,
|
26 |
+
"uta": 0.0,
|
27 |
+
"vtc": 1.0,
|
28 |
+
"vtm": 1.0
|
29 |
+
},
|
30 |
+
"mlm_masking_prob": 0.5,
|
31 |
+
"vtm_hard_neg": true
|
32 |
+
},
|
33 |
+
"debug": false,
|
34 |
+
"deep_fusion": false,
|
35 |
+
"deepspeed": {
|
36 |
+
"enable": true,
|
37 |
+
"stage": 1
|
38 |
+
},
|
39 |
+
"delete_ds_optim_states": true,
|
40 |
+
"device": "cuda",
|
41 |
+
"dist_url": "env://",
|
42 |
+
"evaluate": false,
|
43 |
+
"evaluation": {
|
44 |
+
"eval_frame_ensemble": "concat",
|
45 |
+
"eval_offload": true,
|
46 |
+
"eval_x_only": false,
|
47 |
+
"k_test": 128
|
48 |
+
},
|
49 |
+
"gradient_checkpointing": true,
|
50 |
+
"inputs": {
|
51 |
+
"batch_size": {
|
52 |
+
"image": 64,
|
53 |
+
"video": 64
|
54 |
+
},
|
55 |
+
"batch_size_test": {
|
56 |
+
"image": 4,
|
57 |
+
"video": 4
|
58 |
+
},
|
59 |
+
"image_res": 224,
|
60 |
+
"max_txt_l": {
|
61 |
+
"image": 32,
|
62 |
+
"video": 32
|
63 |
+
},
|
64 |
+
"video_input": {
|
65 |
+
"num_frames": 8,
|
66 |
+
"num_frames_test": 8,
|
67 |
+
"random_aug": false,
|
68 |
+
"sample_type": "rand",
|
69 |
+
"sample_type_test": "middle"
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"jump_evaluate": false,
|
73 |
+
"log_freq": 100,
|
74 |
+
"max_txt_l": 32,
|
75 |
+
"mode": "pt",
|
76 |
+
"model": {
|
77 |
+
"embed_dim": 512,
|
78 |
+
"find_unused_parameters": false,
|
79 |
+
"model_cls": "InternVideo2_Stage2",
|
80 |
+
"multimodal": {
|
81 |
+
"enable": true
|
82 |
+
},
|
83 |
+
"temp": 0.07,
|
84 |
+
"text_encoder": "bert_large",
|
85 |
+
"vision_encoder": {
|
86 |
+
"checkpoint_num": 40,
|
87 |
+
"clip_embed_dim": 768,
|
88 |
+
"clip_input_resolution": 224,
|
89 |
+
"clip_norm_type": "l2",
|
90 |
+
"clip_return_layer": 6,
|
91 |
+
"clip_student_return_interval": 1,
|
92 |
+
"clip_teacher": null,
|
93 |
+
"clip_teacher_embed_dim": 3200,
|
94 |
+
"clip_teacher_final_dim": 768,
|
95 |
+
"clip_teacher_return_interval": 1,
|
96 |
+
"d_model": 1408,
|
97 |
+
"image_mask_ratio": 0.5,
|
98 |
+
"image_mask_type": "random",
|
99 |
+
"img_size": 224,
|
100 |
+
"keep_temporal": false,
|
101 |
+
"name": "pretrain_internvideo2_1b_patch14_224",
|
102 |
+
"num_frames": 8,
|
103 |
+
"only_mask": true,
|
104 |
+
"patch_size": 14,
|
105 |
+
"pretrained": "/home/linanxi/InternVideo/checkpoints/InternVideo2-stage2_1b-224p-f4/InternVideo2-stage2_1b-224p-f4.pt",
|
106 |
+
"sep_image_video_pos_embed": true,
|
107 |
+
"tubelet_size": 1,
|
108 |
+
"use_checkpoint": false,
|
109 |
+
"use_flash_attn": true,
|
110 |
+
"use_fused_mlp": true,
|
111 |
+
"use_fused_rmsnorm": true,
|
112 |
+
"video_mask_ratio": 0.8,
|
113 |
+
"video_mask_type": "random"
|
114 |
+
}
|
115 |
+
},
|
116 |
+
"model_type": "internvideo2",
|
117 |
+
"num_frames": 8,
|
118 |
+
"num_frames_test": 8,
|
119 |
+
"num_workers": 6,
|
120 |
+
"optimizer": {
|
121 |
+
"different_lr": {
|
122 |
+
"enable": false,
|
123 |
+
"lr": 0.001,
|
124 |
+
"module_names": []
|
125 |
+
},
|
126 |
+
"lr": 5e-05,
|
127 |
+
"max_grad_norm": 3.0,
|
128 |
+
"opt": "adamW",
|
129 |
+
"opt_betas": [
|
130 |
+
0.9,
|
131 |
+
0.98
|
132 |
+
],
|
133 |
+
"weight_decay": 0.05
|
134 |
+
},
|
135 |
+
"output_dir": null,
|
136 |
+
"pretrained_path": "",
|
137 |
+
"resume": false,
|
138 |
+
"save_ckpt_iter": null,
|
139 |
+
"save_latest": true,
|
140 |
+
"scheduler": {
|
141 |
+
"epochs": 10,
|
142 |
+
"min_lr_multi": 0.01,
|
143 |
+
"sched": "cosine",
|
144 |
+
"warmup_epochs": 1
|
145 |
+
},
|
146 |
+
"seed": 42,
|
147 |
+
"test_file": {
|
148 |
+
"didemo_ret_test": "available_corpus[\"didemo_ret_test\"]",
|
149 |
+
"msrvtt_1k_test": "available_corpus[\"msrvtt_1k_test\"]"
|
150 |
+
},
|
151 |
+
"test_types": [
|
152 |
+
"msrvtt_1k_test",
|
153 |
+
"didemo_ret_test"
|
154 |
+
],
|
155 |
+
"text_enc": "bert_large",
|
156 |
+
"tokenizer": null,
|
157 |
+
"torch_dtype": "float16",
|
158 |
+
"train_file": "available_corpus[\"pretrain_example_data_1B\"]",
|
159 |
+
"transformers_version": "4.47.0",
|
160 |
+
"use_bf16": true,
|
161 |
+
"use_flash_sdp": false,
|
162 |
+
"use_half_precision": true,
|
163 |
+
"use_mem_efficient_sdp": false,
|
164 |
+
"wandb": {
|
165 |
+
"enable": false,
|
166 |
+
"entity": "opengvlab",
|
167 |
+
"project": "InternVideo2-Stage2"
|
168 |
+
}
|
169 |
+
}
|
config.py
ADDED
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import PretrainedConfig, PreTrainedModel, AutoModel, AutoConfig
|
2 |
+
|
3 |
+
class DotDict(dict):
|
4 |
+
"""字典类,支持通过属性访问键值对。"""
|
5 |
+
|
6 |
+
def __getattr__(self, key):
|
7 |
+
if key in self:
|
8 |
+
return self[key]
|
9 |
+
else:
|
10 |
+
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{key}'")
|
11 |
+
|
12 |
+
def __setattr__(self, key, value):
|
13 |
+
self[key] = value
|
14 |
+
|
15 |
+
def __delattr__(self, key):
|
16 |
+
if key in self:
|
17 |
+
del self[key]
|
18 |
+
else:
|
19 |
+
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{key}'")
|
20 |
+
|
21 |
+
|
22 |
+
class InternVideo2Config(PretrainedConfig):
|
23 |
+
model_type = "internvideo2"
|
24 |
+
|
25 |
+
def __init__(self,
|
26 |
+
tokenizer=None,
|
27 |
+
train_file=None,
|
28 |
+
test_file=None,
|
29 |
+
test_types=None,
|
30 |
+
num_workers=6,
|
31 |
+
best_key=None,
|
32 |
+
num_frames=8,
|
33 |
+
num_frames_test=8,
|
34 |
+
batch_size=64,
|
35 |
+
batch_size_test=4,
|
36 |
+
max_txt_l=32,
|
37 |
+
inputs=None,
|
38 |
+
text_enc="bert_large",
|
39 |
+
model=None,
|
40 |
+
criterion=None,
|
41 |
+
optimizer=None,
|
42 |
+
scheduler=None,
|
43 |
+
evaluate=False,
|
44 |
+
deep_fusion=False,
|
45 |
+
evaluation=None,
|
46 |
+
use_half_precision=True,
|
47 |
+
use_bf16=True,
|
48 |
+
gradient_checkpointing=True,
|
49 |
+
use_flash_sdp=False,
|
50 |
+
use_mem_efficient_sdp=False,
|
51 |
+
compile_model=False,
|
52 |
+
wandb=None,
|
53 |
+
dist_url="env://",
|
54 |
+
device="cuda",
|
55 |
+
mode="pt",
|
56 |
+
output_dir=None,
|
57 |
+
resume=False,
|
58 |
+
debug=False,
|
59 |
+
log_freq=100,
|
60 |
+
seed=42,
|
61 |
+
save_latest=True,
|
62 |
+
auto_resume=False,
|
63 |
+
jump_evaluate=False,
|
64 |
+
pretrained_path="",
|
65 |
+
save_ckpt_iter=None,
|
66 |
+
delete_ds_optim_states=True,
|
67 |
+
deepspeed=None,
|
68 |
+
**kwargs):
|
69 |
+
super().__init__(**kwargs)
|
70 |
+
|
71 |
+
self.tokenizer = tokenizer
|
72 |
+
|
73 |
+
# Data configuration
|
74 |
+
self.train_file = train_file or "available_corpus[\"pretrain_example_data_1B\"]"
|
75 |
+
self.test_file = DotDict(test_file or {
|
76 |
+
"msrvtt_1k_test": "available_corpus[\"msrvtt_1k_test\"]",
|
77 |
+
"didemo_ret_test": "available_corpus[\"didemo_ret_test\"]"
|
78 |
+
})
|
79 |
+
self.test_types = test_types or ["msrvtt_1k_test", "didemo_ret_test"]
|
80 |
+
self.num_workers = num_workers
|
81 |
+
self.best_key = best_key or ["msrvtt_1k_test_match", "t2v_r1"]
|
82 |
+
|
83 |
+
# Input configuration
|
84 |
+
self.num_frames = num_frames
|
85 |
+
self.num_frames_test = num_frames_test
|
86 |
+
self.batch_size = batch_size
|
87 |
+
self.batch_size_test = batch_size_test
|
88 |
+
self.max_txt_l = max_txt_l
|
89 |
+
self.inputs = DotDict(inputs or {
|
90 |
+
"image_res": 224,
|
91 |
+
"video_input": DotDict({
|
92 |
+
"num_frames": num_frames,
|
93 |
+
"sample_type": "rand",
|
94 |
+
"num_frames_test": num_frames_test,
|
95 |
+
"sample_type_test": "middle",
|
96 |
+
"random_aug": False
|
97 |
+
}),
|
98 |
+
"max_txt_l": DotDict({"image": max_txt_l, "video": max_txt_l}),
|
99 |
+
"batch_size": DotDict({"image": batch_size, "video": batch_size}),
|
100 |
+
"batch_size_test": DotDict({"image": batch_size_test, "video": batch_size_test})
|
101 |
+
})
|
102 |
+
|
103 |
+
# Model configuration
|
104 |
+
self.text_enc = text_enc
|
105 |
+
self.model = DotDict(model or {
|
106 |
+
"model_cls": "InternVideo2_Stage2",
|
107 |
+
"vision_encoder": DotDict({
|
108 |
+
"name": "pretrain_internvideo2_1b_patch14_224",
|
109 |
+
"img_size": 224,
|
110 |
+
"num_frames": num_frames,
|
111 |
+
"tubelet_size": 1,
|
112 |
+
"patch_size": 14,
|
113 |
+
"d_model": 1408,
|
114 |
+
"clip_embed_dim": 768,
|
115 |
+
"clip_teacher_embed_dim": 3200,
|
116 |
+
"clip_teacher_final_dim": 768,
|
117 |
+
"clip_norm_type": "l2",
|
118 |
+
"clip_return_layer": 6,
|
119 |
+
"clip_student_return_interval": 1,
|
120 |
+
"pretrained": "/home/linanxi/InternVideo/checkpoints/InternVideo2-stage2_1b-224p-f4/InternVideo2-stage2_1b-224p-f4.pt",
|
121 |
+
"use_checkpoint": False,
|
122 |
+
"checkpoint_num": 40,
|
123 |
+
"use_flash_attn": True,
|
124 |
+
"use_fused_rmsnorm": True,
|
125 |
+
"use_fused_mlp": True,
|
126 |
+
"clip_teacher": None,
|
127 |
+
"clip_input_resolution": 224,
|
128 |
+
"clip_teacher_return_interval": 1,
|
129 |
+
"video_mask_type": "random",
|
130 |
+
"video_mask_ratio": 0.8,
|
131 |
+
"image_mask_type": "random",
|
132 |
+
"image_mask_ratio": 0.5,
|
133 |
+
"sep_image_video_pos_embed": True,
|
134 |
+
"keep_temporal": False,
|
135 |
+
"only_mask": True
|
136 |
+
}),
|
137 |
+
"text_encoder": text_enc,
|
138 |
+
"multimodal": DotDict({"enable": True}),
|
139 |
+
"embed_dim": 512,
|
140 |
+
"temp": 0.07,
|
141 |
+
"find_unused_parameters": False
|
142 |
+
})
|
143 |
+
|
144 |
+
# Criterion configuration
|
145 |
+
self.criterion = DotDict(criterion or {
|
146 |
+
"loss_weight": DotDict({
|
147 |
+
"vtc": 1.0,
|
148 |
+
"mlm": 1.0,
|
149 |
+
"vtm": 1.0,
|
150 |
+
"mvm": 0.0,
|
151 |
+
"uta": 0.0
|
152 |
+
}),
|
153 |
+
"vtm_hard_neg": True,
|
154 |
+
"mlm_masking_prob": 0.5,
|
155 |
+
"distill_final_features": True,
|
156 |
+
"clip_loss_ratio": [1.0, 1.0]
|
157 |
+
})
|
158 |
+
|
159 |
+
# Optimizer configuration
|
160 |
+
self.optimizer = DotDict(optimizer or {
|
161 |
+
"opt": "adamW",
|
162 |
+
"lr": 5e-5,
|
163 |
+
"opt_betas": [0.9, 0.98],
|
164 |
+
"weight_decay": 0.05,
|
165 |
+
"max_grad_norm": 3.0,
|
166 |
+
"different_lr": DotDict({"enable": False, "module_names": [], "lr": 1e-3})
|
167 |
+
})
|
168 |
+
|
169 |
+
# Scheduler configuration
|
170 |
+
self.scheduler = DotDict(scheduler or {
|
171 |
+
"sched": "cosine",
|
172 |
+
"epochs": 10,
|
173 |
+
"min_lr_multi": 0.01,
|
174 |
+
"warmup_epochs": 1
|
175 |
+
})
|
176 |
+
|
177 |
+
# Evaluation configuration
|
178 |
+
self.evaluate = evaluate
|
179 |
+
self.deep_fusion = deep_fusion
|
180 |
+
self.evaluation = DotDict(evaluation or {
|
181 |
+
"eval_frame_ensemble": "concat",
|
182 |
+
"eval_x_only": False,
|
183 |
+
"k_test": 128,
|
184 |
+
"eval_offload": True
|
185 |
+
})
|
186 |
+
|
187 |
+
# Miscellaneous
|
188 |
+
self.use_half_precision = use_half_precision
|
189 |
+
self.use_bf16 = use_bf16
|
190 |
+
self.gradient_checkpointing = gradient_checkpointing
|
191 |
+
self.use_flash_sdp = use_flash_sdp
|
192 |
+
self.use_mem_efficient_sdp = use_mem_efficient_sdp
|
193 |
+
self.compile_model = compile_model
|
194 |
+
|
195 |
+
self.wandb = DotDict(wandb or {
|
196 |
+
"enable": False,
|
197 |
+
"entity": "opengvlab",
|
198 |
+
"project": "InternVideo2-Stage2"
|
199 |
+
})
|
200 |
+
|
201 |
+
self.dist_url = dist_url
|
202 |
+
self.device = device
|
203 |
+
self.mode = mode
|
204 |
+
self.output_dir = output_dir
|
205 |
+
self.resume = resume
|
206 |
+
self.debug = debug
|
207 |
+
self.log_freq = log_freq
|
208 |
+
self.seed = seed
|
209 |
+
|
210 |
+
self.save_latest = save_latest
|
211 |
+
self.auto_resume = auto_resume
|
212 |
+
self.jump_evaluate = jump_evaluate
|
213 |
+
self.pretrained_path = pretrained_path
|
214 |
+
self.save_ckpt_iter = save_ckpt_iter
|
215 |
+
self.delete_ds_optim_states = delete_ds_optim_states
|
216 |
+
|
217 |
+
self.deepspeed = DotDict(deepspeed or {
|
218 |
+
"enable": True,
|
219 |
+
"stage": 1
|
220 |
+
})
|
model.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from internvideo2_stage2 import InternVideo2_Stage2 as IV2S2
|
2 |
+
from transformers import PretrainedConfig, PreTrainedModel, AutoModel, AutoConfig
|
3 |
+
from config import InternVideo2Config as config
|
4 |
+
import warnings
|
5 |
+
import torch
|
6 |
+
warnings.filterwarnings("ignore")
|
7 |
+
|
8 |
+
# model_config = config()
|
9 |
+
# model = IV2S2(model_config)
|
10 |
+
# print(model)
|
11 |
+
|
12 |
+
class InternVideo2Stage2VideoEncoder(PreTrainedModel):
|
13 |
+
config_class = config
|
14 |
+
|
15 |
+
def __init__(self, config):
|
16 |
+
super().__init__(config)
|
17 |
+
self.config = config
|
18 |
+
self.model = IV2S2(config).half().to(config.device)
|
19 |
+
|
20 |
+
def forward(self, x: torch.tensor):
|
21 |
+
"""forward pass
|
22 |
+
Args:
|
23 |
+
x (torch.tensor): Shape (B, N, C, H, W) or (N, C, H, W)
|
24 |
+
Returns:
|
25 |
+
torch.tensor: Shape (B*N, hidden_size)
|
26 |
+
"""
|
27 |
+
# x: Shape(B, C, N, H, W)
|
28 |
+
# output: Shape(B, N*98, hidden_size)
|
29 |
+
if len(x.shape) == 4:
|
30 |
+
x = x.unsqueeze(0)
|
31 |
+
B, N, C, H, W = x.shape
|
32 |
+
x = x.permute(0, 2, 1, 3, 4) # Shape(B, C, N, H, W)
|
33 |
+
output = self.model.encode_vision(x)
|
34 |
+
pooled_vision_embeds = output[1]
|
35 |
+
return pooled_vision_embeds
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
model_config = config()
|
39 |
+
model = InternVideo2Stage2VideoEncoder(model_config)
|
40 |
+
x = torch.randn(2, 3, 8, 224, 224, dtype=torch.float16).to(model_config.device)
|
41 |
+
output = model(x)
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5aa6e5518080f7c11b1a55221c8fd72ee0d9dff5ba50c11794b32cf3c6df1c71
|
3 |
+
size 2104856154
|