# Copyright (C) 2025 AIDC-AI # 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. import math from typing import Dict, List, Optional, Tuple, Union import PIL.Image import numpy as np import torch # from flash_attn import flash_attn_varlen_func # from flash_attn.layers.rotary import apply_rotary_emb from torch import Tensor, nn from torch.nn import functional as F from transformers import ( AutoConfig, AutoImageProcessor, AutoModel, AutoModelForCausalLM, AutoTokenizer, ) from transformers.activations import ACT2FN from transformers.generation.utils import GenerateOutput from transformers.modeling_outputs import BaseModelOutputWithNoAttention from transformers.modeling_utils import PreTrainedModel from ovis_image.model.ovis.configuration_ovis2_5 import Siglip2NavitConfig, Ovis2_5_Config from ovis_image.model.ops import get_attention_type_by_system IMAGE_PLACEHOLDER = "" IMAGE_PLACEHOLDER_ID = -200 VIDEO_PLACEHOLDER = "