# Copyright 2025 the LlamaFactory team. # # 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 os from typing import TYPE_CHECKING, Any import numpy as np import pytest import torch from PIL import Image from llamafactory.data.mm_plugin import get_mm_plugin from llamafactory.extras.packages import is_transformers_version_greater_than from llamafactory.hparams import get_infer_args from llamafactory.model import load_tokenizer if TYPE_CHECKING: from transformers import PreTrainedTokenizer, ProcessorMixin from transformers.image_processing_utils import BaseImageProcessor from llamafactory.data.mm_plugin import BasePlugin from llamafactory.model.loader import TokenizerModule HF_TOKEN = os.getenv("HF_TOKEN") TINY_LLAMA3 = os.getenv("TINY_LLAMA3", "llamafactory/tiny-random-Llama-3") TINY_LLAMA4 = os.getenv("TINY_LLAMA4", "llamafactory/tiny-random-Llama-4") MM_MESSAGES = [ {"role": "user", "content": "What is in this image?"}, {"role": "assistant", "content": "A cat."}, ] OMNI_MESSAGES = [ {"role": "user", "content": "What is in this image?"}, {"role": "assistant", "content": "A cat."}, {"role": "user", "content": "