Video-Text-to-Text
Transformers
Safetensors
English
Chinese
moss_vl
feature-extraction
Realtime
Streaming
Video-Understanding
Image-Understanding
MOSS-VL
OpenMOSS
multimodal
video
vision-language
custom_code
Instructions to use OpenMOSS-Team/MOSS-VL-Realtime with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenMOSS-Team/MOSS-VL-Realtime with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("OpenMOSS-Team/MOSS-VL-Realtime", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Ascend NPU support: device-aware cache release, GIL-friendly idle wait, <=8-D vision processing, BICUBIC declaration
#3
by Joiin0392 - opened
Files changed (3)
2873 unmodified lines28742875287628772878287928802881217 unmodified lines30993100310131023103310431053106489 unmodified lines35963597359835993600360136022873 unmodified linesdef stop_real_time_generate(self):gc.collect()if torch.cuda.is_available():torch.cuda.empty_cache()self.continue_generating = False@staticmethod217 unmodified linesbreakif self.continue_generating and should_wait_for_new_input and not frames_to_process and not prompts_to_process:# Busy-wait — matches VideoMllama reference. Caller controls cadence via# `max_tokens_per_turn` sleeping in `_real_time_sample`.continuebreak489 unmodified linesand buf_list[-1] == invalid_token_id)if is_silence_or_ellipsis or is_complete_text or is_invalid_complete:output_text_queue.put(decoded_text)token_buffer.clear()input_ids = torch.cat([input_ids, next_tokens[:, None]], dim=-1)2873 unmodified lines2874287528762877287828792880288128822883288428852886217 unmodified lines31043105310631073108310931103111311231133114489 unmodified lines36043605360636073608360936103611361236133614361536163617361836192873 unmodified linesdef stop_real_time_generate(self):gc.collect()try:import torch_npu # noqa: F401if torch.npu.is_available():torch.npu.empty_cache()except ImportError:if torch.cuda.is_available():torch.cuda.empty_cache()self.continue_generating = False@staticmethod217 unmodified linesbreakif self.continue_generating and should_wait_for_new_input and not frames_to_process and not prompts_to_process:# GIL-friendly wait: a bare `continue` busy-spin monopolizes the GIL# and starves in-process siblings (in-process ASR decode inflates# ~150ms -> 40-80s while a realtime session idles in <|silence|>).# 20ms poll keeps input-detection latency negligible.time.sleep(0.02)continuebreak489 unmodified linesand buf_list[-1] == invalid_token_id)if is_silence_or_ellipsis or is_complete_text or is_invalid_complete:# The end-of-buffer guard above only catches an INCOMPLETE# trailing char. Under sampling, a multi-byte char can also# break MID-string (the next token completes a different# char, orphaning the first char's tail bytes) — the# replacement char then stays in the text forever. Those# bytes are unrecoverable at this point: drop the broken# character instead of emitting mojibake.clean_text = decoded_text.replace("\ufffd", "")if clean_text:output_text_queue.put(clean_text)token_buffer.clear()input_ids = torch.cat([input_ids, next_tokens[:, None]], dim=-1)
163 unmodified lines164165166167168169170171172173174175163 unmodified lines)# Reorder dimensions to group grid and patch information for subsequent flattening.# (batch, grid_t, grid_h, grid_w, merge_h, merge_w, channel, temp_patch_size, patch_h, patch_w)patches = patches.permute(0, 1, 4, 7, 5, 8, 3, 2, 6, 9)flatten_patches = patches.reshape(batch_size,grid_t * grid_h * grid_w,channel * temporal_patch_size * patch_size * patch_size,)processed_images_grouped[shape] = flatten_patchesprocessed_grids[shape] = [[grid_t, grid_h, grid_w]] * batch_size163 unmodified lines164165166167168169170171172173174175176177178179180163 unmodified lines)# Reorder dimensions to group grid and patch information for subsequent flattening.# (batch, grid_t, grid_h, grid_w, merge_h, merge_w, channel, temp_patch_size, patch_h, patch_w)# NPU ops support at most 8-D tensors; route the 10-D permute+reshape# through CPU there. CUDA handles 10-D natively — keep it on-device.patches_device = patches.deviceif patches_device.type == "npu":patches = patches.cpu()patches = patches.permute(0, 1, 4, 7, 5, 8, 3, 2, 6, 9)flatten_patches = patches.reshape(batch_size,grid_t * grid_h * grid_w,channel * temporal_patch_size * patch_size * patch_size,).to(patches_device)processed_images_grouped[shape] = flatten_patchesprocessed_grids[shape] = [[grid_t, grid_h, grid_w]] * batch_size
1146 unmodified lines1147114811491150115111521153115411551156115711581146 unmodified linesmerge_size,patch_size,)patches = patches.permute(0, 1, 4, 7, 5, 8, 3, 2, 6, 9)flatten_patches = patches.reshape(batch_size,grid_t * grid_h * grid_w,channel * temporal_patch_size * patch_size * patch_size,)processed_videos_grouped[shape] = flatten_patchesprocessed_grids[shape] = [[grid_t, grid_h, grid_w]] * batch_size1146 unmodified lines114711481149115011511152115311541155115611571158115911601161116211631146 unmodified linesmerge_size,patch_size,)patches_device = patches.device# NPU: max 8D tensors — route the 10D permute+reshape through CPU.# CUDA handles 10D natively — keep it on-device.if patches_device.type == "npu":patches = patches.cpu()patches = patches.permute(0, 1, 4, 7, 5, 8, 3, 2, 6, 9)flatten_patches = patches.reshape(batch_size,grid_t * grid_h * grid_w,channel * temporal_patch_size * patch_size * patch_size,).to(patches_device)processed_videos_grouped[shape] = flatten_patchesprocessed_grids[shape] = [[grid_t, grid_h, grid_w]] * batch_size
modeling_moss_vl.py+22-5
processing_moss_vl.py+6-1
video_processing_moss_vl.py+6-1