Video-Text-to-Text
Transformers
Safetensors
English
videochat_flash_qwen
feature-extraction
multimodal
custom_code
Eval Results (legacy)
Run this model with HF Jobs
Run OpenGVLab/VideoChat-Flash-Qwen2_5-7B_InternVideo2-1B 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/OpenGVLab/VideoChat-Flash-Qwen2_5-7B_InternVideo2-1B. 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/OpenGVLab/VideoChat-Flash-Qwen2_5-7B_InternVideo2-1B 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 OpenGVLab/VideoChat-Flash-Qwen2_5-7B_InternVideo2-1B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenGVLab/VideoChat-Flash-Qwen2_5-7B_InternVideo2-1B with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("OpenGVLab/VideoChat-Flash-Qwen2_5-7B_InternVideo2-1B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
support transformers 4.57 (#3)
Browse files- support transformers 4.57 (b13f72c9d1e80b6a2d9a81b41452412d5ecf9cf6)
Files changed (2)
- config.json+1-1
- modeling_qwen2_flash.py+45-7
199 unmodified lines200201202203204205206199 unmodified lines"mm_vision_select_layer": -2,"mm_vision_tower": "internvideo2","mm_vision_tower_lr": 2e-06,"model_type": "qwen2","num_attention_heads": 28,"num_hidden_layers": 28,"num_key_value_heads": 4,199 unmodified lines200201202203204205206199 unmodified lines"mm_vision_select_layer": -2,"mm_vision_tower": "internvideo2","mm_vision_tower_lr": 2e-06,"model_type": "videochat_flash_qwen","num_attention_heads": 28,"num_hidden_layers": 28,"num_key_value_heads": 4,
275 unmodified lines27627727827928028128296 unmodified lines379380381382383384385287 unmodified lines673674675676677678679313 unmodified lines993994995996997998999483 unmodified lines1483148414851486148714881489149026 unmodified lines15171518151915201521152215231524275 unmodified lines"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class ""with a layer index.")kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)96 unmodified lines"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class ""with a layer index.")kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)# Because the input can be padded, the absolute sequence length depends on the max position id.rotary_seq_len = max(kv_seq_len, position_ids[:, -1].max().item()) + 1287 unmodified lineskv_seq_len = key_states.shape[-2]if past_key_value is not None:kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)313 unmodified linesuse_legacy_cache = not isinstance(past_key_values, Cache)if use_legacy_cache:past_key_values = DynamicCache.from_legacy_cache(past_key_values)past_key_values_length = past_key_values.get_usable_length(seq_length)if position_ids is None:device = input_ids.device if input_ids is not None else inputs_embeds.device483 unmodified linesif past_key_values is not None:if isinstance(past_key_values, Cache):cache_length = past_key_values.get_seq_length()past_length = past_key_values.seen_tokensmax_cache_length = past_key_values.get_max_length()else:cache_length = past_length = past_key_values[0][0].shape[2]max_cache_length = None26 unmodified linesif past_key_values:position_ids = position_ids[:, -input_ids.shape[1] :]# if `inputs_embeds` are passed, we only want to use them in the 1st generation stepif inputs_embeds is not None and past_key_values is None:model_inputs = {"inputs_embeds": inputs_embeds}else:model_inputs = {"input_ids": input_ids}275 unmodified lines27627727827928028128228328428528696 unmodified lines383384385386387388389390391392393287 unmodified lines681682683684685686687688689690691313 unmodified lines10051006100710081009101010111012101310141015483 unmodified lines149915001501150215031504150515061507150815091510151115121513151426 unmodified lines1541154215431544154515461547154815491550155115521553155415551556155715581559156015611562275 unmodified lines"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class ""with a layer index.")# get_usable_length has been removed in transformers 4.54.0if hasattr(past_key_value, "get_usable_length"):kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)else:kv_seq_len += past_key_value.get_seq_length(self.layer_idx)cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)96 unmodified lines"for auto-regressive decoding with k/v caching, please make sure to initialize the attention class ""with a layer index.")# get_usable_length has been removed in transformers 4.54.0if hasattr(past_key_value, "get_usable_length"):kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)else:kv_seq_len += past_key_value.get_seq_length(self.layer_idx)# Because the input can be padded, the absolute sequence length depends on the max position id.rotary_seq_len = max(kv_seq_len, position_ids[:, -1].max().item()) + 1287 unmodified lineskv_seq_len = key_states.shape[-2]if past_key_value is not None:# get_usable_length has been removed in transformers 4.54.0if hasattr(past_key_value, "get_usable_length"):kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)else:kv_seq_len += past_key_value.get_seq_length(self.layer_idx)cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)313 unmodified linesuse_legacy_cache = not isinstance(past_key_values, Cache)if use_legacy_cache:past_key_values = DynamicCache.from_legacy_cache(past_key_values)# get_usable_length has been removed in transformers 4.54.0if hasattr(past_key_values, "get_usable_length"):past_key_values_length = past_key_values.get_usable_length(seq_length)else:past_key_values_length = past_key_values.get_seq_length()if position_ids is None:device = input_ids.device if input_ids is not None else inputs_embeds.device483 unmodified linesif past_key_values is not None:if isinstance(past_key_values, Cache):cache_length = past_key_values.get_seq_length()# seen_tokens property has been removed in transformers 4.54.0past_length = getattr(past_key_values, 'seen_tokens', cache_length)# get_max_length() has been replaced by get_max_cache_shape() in transformers 4.49.0# in transformers 4.54.0, DynamicCache returns -1 instead of None to indicate no limitif hasattr(past_key_values, 'get_max_cache_shape'):max_cache_length = past_key_values.get_max_cache_shape()# Convert -1 to None for consistency with old behaviormax_cache_length = None if max_cache_length == -1 else max_cache_lengthelse:max_cache_length = past_key_values.get_max_length()else:cache_length = past_length = past_key_values[0][0].shape[2]max_cache_length = None26 unmodified linesif past_key_values:position_ids = position_ids[:, -input_ids.shape[1] :]def is_cache_empty(past_key_values):if past_key_values is None or len(past_key_values) == 0:return Trueif hasattr(past_key_values, 'is_initialized'):return past_key_values.is_initialized == Falseif isinstance(past_key_values, Cache):for idx, layer in enumerate(past_key_values.layers):if past_key_values.get_seq_length(idx) > 0:return Falsereturn Truereturn False# if `inputs_embeds` are passed, we only want to use them in the 1st generation step# in newer transformers versions, past_key_values can be an empty cache in the 1st generation step.if inputs_embeds is not None and is_cache_empty(past_key_values):model_inputs = {"inputs_embeds": inputs_embeds}else:model_inputs = {"input_ids": input_ids}
config.json+1-1
modeling_qwen2_flash.py+45-7