Upload folder using huggingface_hub
Browse files- config.json +7 -3
- configuration.py +115 -0
- modeling_tinyllava_llama.py +852 -0
config.json
CHANGED
|
@@ -8,15 +8,19 @@
|
|
| 8 |
"ignore_index": -100,
|
| 9 |
"image_aspect_ratio": "square",
|
| 10 |
"image_token_index": -200,
|
| 11 |
-
"llm_model_name_or_path": "/
|
| 12 |
"model_type": "tinyllava",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
"num_queries": 128,
|
| 14 |
"num_resampler_layers": 3,
|
| 15 |
"pad_token": "<unk>",
|
| 16 |
"pad_token_id": 0,
|
| 17 |
"resampler_hidden_size": 768,
|
| 18 |
"text_config": {
|
| 19 |
-
"_name_or_path": "/
|
| 20 |
"architectures": [
|
| 21 |
"LlamaForCausalLM"
|
| 22 |
],
|
|
@@ -30,7 +34,7 @@
|
|
| 30 |
"torch_dtype": "bfloat16"
|
| 31 |
},
|
| 32 |
"tokenizer_model_max_length": 2048,
|
| 33 |
-
"tokenizer_name_or_path": "/
|
| 34 |
"tokenizer_padding_side": "right",
|
| 35 |
"tokenizer_use_fast": false,
|
| 36 |
"torch_dtype": "bfloat16",
|
|
|
|
| 8 |
"ignore_index": -100,
|
| 9 |
"image_aspect_ratio": "square",
|
| 10 |
"image_token_index": -200,
|
| 11 |
+
"llm_model_name_or_path": "keeeeenw/MicroLlama",
|
| 12 |
"model_type": "tinyllava",
|
| 13 |
+
"auto_map": {
|
| 14 |
+
"AutoConfig": "configuration.TinyLlavaConfig",
|
| 15 |
+
"AutoModelForCausalLM": "modeling_tinyllava_llama.TinyLlavaForConditionalGeneration"
|
| 16 |
+
},
|
| 17 |
"num_queries": 128,
|
| 18 |
"num_resampler_layers": 3,
|
| 19 |
"pad_token": "<unk>",
|
| 20 |
"pad_token_id": 0,
|
| 21 |
"resampler_hidden_size": 768,
|
| 22 |
"text_config": {
|
| 23 |
+
"_name_or_path": "keeeeenw/MicroLlama",
|
| 24 |
"architectures": [
|
| 25 |
"LlamaForCausalLM"
|
| 26 |
],
|
|
|
|
| 34 |
"torch_dtype": "bfloat16"
|
| 35 |
},
|
| 36 |
"tokenizer_model_max_length": 2048,
|
| 37 |
+
"tokenizer_name_or_path": "keeeeenw/MicroLlama",
|
| 38 |
"tokenizer_padding_side": "right",
|
| 39 |
"tokenizer_use_fast": false,
|
| 40 |
"torch_dtype": "bfloat16",
|
configuration.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PretrainedConfig
|
| 2 |
+
from transformers import CONFIG_MAPPING
|
| 3 |
+
from transformers import AutoConfig
|
| 4 |
+
|
| 5 |
+
IGNORE_INDEX = -100
|
| 6 |
+
IMAGE_TOKEN_INDEX = -200
|
| 7 |
+
DEFAULT_IMAGE_TOKEN = "<image>"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class TinyLlavaConfig(PretrainedConfig):
|
| 11 |
+
|
| 12 |
+
model_type = "tinyllava"
|
| 13 |
+
def __init__(
|
| 14 |
+
self,
|
| 15 |
+
llm_model_name_or_path = '',
|
| 16 |
+
tokenizer_name_or_path = None,
|
| 17 |
+
vision_model_name_or_path = '',
|
| 18 |
+
vision_model_name_or_path2 = '',
|
| 19 |
+
connector_type = None,
|
| 20 |
+
text_config=None,
|
| 21 |
+
hidden_size=2048,
|
| 22 |
+
vocab_size=32000,
|
| 23 |
+
ignore_index=-100,
|
| 24 |
+
image_token_index=32000,
|
| 25 |
+
pad_token = None,
|
| 26 |
+
pad_token_id = None,
|
| 27 |
+
tokenizer_padding_side = 'right',
|
| 28 |
+
tokenizer_model_max_length = 2048,
|
| 29 |
+
vision_config = None,
|
| 30 |
+
vision_hidden_size = None,
|
| 31 |
+
vision_feature_layer = -2,
|
| 32 |
+
vision_feature_select_strategy = 'patch',
|
| 33 |
+
image_aspect_ratio = 'square',
|
| 34 |
+
resampler_hidden_size = None,
|
| 35 |
+
num_queries = None,
|
| 36 |
+
num_resampler_layers = None,
|
| 37 |
+
use_cache = False,
|
| 38 |
+
cache_dir = None,
|
| 39 |
+
tokenizer_use_fast = False,
|
| 40 |
+
tune_type_llm = 'frozen',
|
| 41 |
+
tune_type_connector = 'frozen',
|
| 42 |
+
tune_type_vision_tower = 'frozen',
|
| 43 |
+
tune_vision_tower_from_layer = -1,
|
| 44 |
+
|
| 45 |
+
**kwargs
|
| 46 |
+
|
| 47 |
+
):
|
| 48 |
+
self.llm_model_name_or_path = llm_model_name_or_path
|
| 49 |
+
self.tokenizer_name_or_path = tokenizer_name_or_path or self.llm_model_name_or_path
|
| 50 |
+
self.vision_model_name_or_path = vision_model_name_or_path
|
| 51 |
+
self.vision_model_name_or_path2 = vision_model_name_or_path2
|
| 52 |
+
self.connector_type = connector_type
|
| 53 |
+
self.tune_type_llm = tune_type_llm
|
| 54 |
+
self.tune_type_connector = tune_type_connector
|
| 55 |
+
self.tune_type_vision_tower = tune_type_vision_tower
|
| 56 |
+
self.tune_vision_tower_from_layer = tune_vision_tower_from_layer
|
| 57 |
+
|
| 58 |
+
self.ignore_index = IGNORE_INDEX
|
| 59 |
+
self.image_token_index = IMAGE_TOKEN_INDEX
|
| 60 |
+
self.pad_token = pad_token
|
| 61 |
+
self.pad_token_id = pad_token_id
|
| 62 |
+
self.tokenizer_padding_side = tokenizer_padding_side
|
| 63 |
+
self.tokenizer_model_max_length = tokenizer_model_max_length
|
| 64 |
+
self.vision_feature_layer = vision_feature_layer
|
| 65 |
+
self.vision_feature_select_strategy = vision_feature_select_strategy
|
| 66 |
+
self.image_aspect_ratio = image_aspect_ratio
|
| 67 |
+
self.resampler_hidden_size = resampler_hidden_size
|
| 68 |
+
self.num_queries = num_queries
|
| 69 |
+
self.num_resampler_layers = num_resampler_layers
|
| 70 |
+
self.use_cache = use_cache
|
| 71 |
+
self.cache_dir = cache_dir
|
| 72 |
+
self.tokenizer_use_fast = tokenizer_use_fast
|
| 73 |
+
self._load_text_config(text_config)
|
| 74 |
+
self._load_vision_config(vision_config)
|
| 75 |
+
|
| 76 |
+
super().__init__(**kwargs)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def _load_text_config(self, text_config=None):
|
| 80 |
+
if self.llm_model_name_or_path is None or self.llm_model_name_or_path == '':
|
| 81 |
+
self.text_config = CONFIG_MAPPING['llama']()
|
| 82 |
+
|
| 83 |
+
else:
|
| 84 |
+
self.text_config = AutoConfig.from_pretrained(self.llm_model_name_or_path, trust_remote_code=True)
|
| 85 |
+
if text_config is not None:
|
| 86 |
+
self.text_config = self.text_config.from_dict(text_config)
|
| 87 |
+
|
| 88 |
+
self.hidden_size = getattr(self.text_config, 'hidden_size', getattr(self.text_config, 'model_dim', None))
|
| 89 |
+
self.vocab_size = getattr(self.text_config, 'vocab_size', None)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def _load_vision_config(self, vision_config=None):
|
| 94 |
+
if self.vision_model_name_or_path is None or self.vision_model_name_or_path == '':
|
| 95 |
+
self.vision_config = CONFIG_MAPPING['clip_vision_model'](
|
| 96 |
+
intermediate_size=4096,
|
| 97 |
+
hidden_size=1024,
|
| 98 |
+
patch_size=14,
|
| 99 |
+
image_size=336,
|
| 100 |
+
num_hidden_layers=24,
|
| 101 |
+
num_attention_heads=16,
|
| 102 |
+
vocab_size=32000,
|
| 103 |
+
projection_dim=768,
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
else:
|
| 107 |
+
self.vision_config = AutoConfig.from_pretrained(self.vision_model_name_or_path.split(':')[-1])
|
| 108 |
+
self.vision_config = getattr(self.vision_config, 'vision_config', self.vision_config)
|
| 109 |
+
if vision_config is not None:
|
| 110 |
+
self.vision_config = self.vision_config.from_dict(vision_config)
|
| 111 |
+
|
| 112 |
+
self.vision_config.model_name_or_path = self.vision_model_name_or_path.split(':')[-1]
|
| 113 |
+
self.vision_config.model_name_or_path2 = self.vision_model_name_or_path2.split(':')[-1]
|
| 114 |
+
self.vision_hidden_size = getattr(self.vision_config, 'hidden_size', None)
|
| 115 |
+
|
modeling_tinyllava_llama.py
ADDED
|
@@ -0,0 +1,852 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
TinyLLaVA Standalone Model - Factory-Aligned Implementation
|
| 3 |
+
=========================================================
|
| 4 |
+
|
| 5 |
+
This file contains a standalone implementation of TinyLLaVA that replicates the behavior
|
| 6 |
+
of the factory-based model system without requiring the full factory infrastructure.
|
| 7 |
+
|
| 8 |
+
CRITICAL ALIGNMENT REQUIREMENTS:
|
| 9 |
+
===============================
|
| 10 |
+
|
| 11 |
+
To create a standalone model that produces identical results to the factory system,
|
| 12 |
+
the following components must be EXACTLY aligned:
|
| 13 |
+
|
| 14 |
+
1. PROMPT TEMPLATE FORMATTING:
|
| 15 |
+
- Factory: "A chat between... USER: <image>\nQuestion ASSISTANT:" (NO SPACE after ASSISTANT:)
|
| 16 |
+
- Bug: Adding space after "ASSISTANT: " causes repetitive, verbose generation
|
| 17 |
+
- Fix: Use exact format "ASSISTANT:" without trailing space
|
| 18 |
+
|
| 19 |
+
2. TOKENIZATION:
|
| 20 |
+
- Must use identical tokenizer_image_token() logic as factory
|
| 21 |
+
- Handle BOS token offsets correctly
|
| 22 |
+
- Use _insert_separator() function name (not insert_separator)
|
| 23 |
+
|
| 24 |
+
3. STOPPING CRITERIA:
|
| 25 |
+
- Factory uses KeywordsStoppingCriteria with ["</s>"] keywords
|
| 26 |
+
- Critical: Without stopping criteria, model generates repetitive loops
|
| 27 |
+
- Must stop at EOS tokens and clean output by removing trailing "</s>"
|
| 28 |
+
|
| 29 |
+
4. IMAGE PROCESSING:
|
| 30 |
+
- Process images as list: process_images([image], processor, config)
|
| 31 |
+
- Handle both list and tensor outputs correctly
|
| 32 |
+
- Apply proper device placement
|
| 33 |
+
|
| 34 |
+
5. GENERATION PARAMETERS:
|
| 35 |
+
- Use identical parameters: temperature, top_p, num_beams, max_new_tokens
|
| 36 |
+
- Same stopping criteria and output cleaning as factory
|
| 37 |
+
|
| 38 |
+
COMMON BUGS AND FIXES:
|
| 39 |
+
======================
|
| 40 |
+
|
| 41 |
+
BUG: Repetitive, numbered output (1. Be cautious... 2. Wet and muddy... 3. Noisy...)
|
| 42 |
+
FIX: Remove space after "ASSISTANT:" in prompt format
|
| 43 |
+
|
| 44 |
+
BUG: Model doesn't stop generating, creates very long responses
|
| 45 |
+
FIX: Add KeywordsStoppingCriteria with ["</s>"] keywords
|
| 46 |
+
|
| 47 |
+
BUG: Different results despite same architecture
|
| 48 |
+
FIX: Ensure exact prompt template matching factory system
|
| 49 |
+
|
| 50 |
+
BUG: Image not processed correctly
|
| 51 |
+
FIX: Pass images as list [image] not single image to process_images()
|
| 52 |
+
|
| 53 |
+
FACTORY SYSTEM COMPARISON:
|
| 54 |
+
=========================
|
| 55 |
+
|
| 56 |
+
Factory system uses:
|
| 57 |
+
- tinyllava.data.template.LlamaTemplate for prompt formatting
|
| 58 |
+
- tinyllava.utils.eval_utils.KeywordsStoppingCriteria for stopping
|
| 59 |
+
- tinyllava.eval.run_tiny_llava.eval_model() for inference pipeline
|
| 60 |
+
|
| 61 |
+
This standalone implementation replicates all these behaviors without dependencies.
|
| 62 |
+
|
| 63 |
+
USAGE:
|
| 64 |
+
======
|
| 65 |
+
model = AutoModelForCausalLM.from_pretrained(path, trust_remote_code=True)
|
| 66 |
+
tokenizer = AutoTokenizer.from_pretrained(path)
|
| 67 |
+
output, time = model.chat(prompt="Question?", image="path/url", tokenizer=tokenizer)
|
| 68 |
+
"""
|
| 69 |
+
|
| 70 |
+
import time
|
| 71 |
+
|
| 72 |
+
# Removed unused imports: dataclasses, Enum
|
| 73 |
+
from typing import List, Tuple, Optional, Union
|
| 74 |
+
import requests
|
| 75 |
+
from PIL import Image
|
| 76 |
+
from io import BytesIO
|
| 77 |
+
import base64
|
| 78 |
+
import re
|
| 79 |
+
|
| 80 |
+
import torch
|
| 81 |
+
import torch.utils.checkpoint
|
| 82 |
+
from torch import nn
|
| 83 |
+
from torch.nn import functional as F
|
| 84 |
+
|
| 85 |
+
from transformers.utils import logging
|
| 86 |
+
from transformers import PreTrainedModel
|
| 87 |
+
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 88 |
+
from transformers.generation.utils import GenerateOutput, StoppingCriteria
|
| 89 |
+
from transformers import CLIPVisionModel, CLIPImageProcessor, SiglipVisionModel, SiglipImageProcessor
|
| 90 |
+
|
| 91 |
+
from .configuration import TinyLlavaConfig, IGNORE_INDEX, IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN
|
| 92 |
+
|
| 93 |
+
from transformers import AutoConfig, AutoModelForCausalLM, LlamaForCausalLM
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
logger = logging.get_logger(__name__)
|
| 98 |
+
|
| 99 |
+
# Model Constants (aligned with factory)
|
| 100 |
+
IGNORE_INDEX = -100
|
| 101 |
+
IMAGE_TOKEN_INDEX = -200
|
| 102 |
+
DEFAULT_IMAGE_TOKEN = "<image>"
|
| 103 |
+
|
| 104 |
+
# Factory-aligned template formatting functions
|
| 105 |
+
def format_llama_prompt(question_list, answer_list, has_image=False):
|
| 106 |
+
"""Format prompt using factory template logic"""
|
| 107 |
+
system = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. "
|
| 108 |
+
|
| 109 |
+
if isinstance(question_list, str):
|
| 110 |
+
question_list = [question_list]
|
| 111 |
+
if isinstance(answer_list, str):
|
| 112 |
+
answer_list = [answer_list]
|
| 113 |
+
|
| 114 |
+
msg = system
|
| 115 |
+
for i, (question, answer) in enumerate(zip(question_list, answer_list)):
|
| 116 |
+
# Format image token if present
|
| 117 |
+
if DEFAULT_IMAGE_TOKEN in question:
|
| 118 |
+
question = question.replace(DEFAULT_IMAGE_TOKEN, '').strip()
|
| 119 |
+
question = f"<image>\n{question}"
|
| 120 |
+
|
| 121 |
+
# Format user and assistant messages
|
| 122 |
+
msg += f"USER: {question} "
|
| 123 |
+
if answer is not None:
|
| 124 |
+
msg += f"ASSISTANT: {answer}</s>"
|
| 125 |
+
|
| 126 |
+
return msg
|
| 127 |
+
|
| 128 |
+
def format_chat_prompt(prompt, has_image=False):
|
| 129 |
+
"""
|
| 130 |
+
Format a single chat prompt for inference - matches factory template exactly.
|
| 131 |
+
|
| 132 |
+
CRITICAL: This function replicates the exact prompt formatting used by:
|
| 133 |
+
- tinyllava.data.template.LlamaTemplate
|
| 134 |
+
- tinyllava.eval.run_tiny_llava.eval_model()
|
| 135 |
+
|
| 136 |
+
CRITICAL BUG FIX: Must end with "ASSISTANT:" (NO SPACE)
|
| 137 |
+
- Wrong: "ASSISTANT: " (with space) -> causes repetitive generation
|
| 138 |
+
- Right: "ASSISTANT:" (no space) -> normal generation
|
| 139 |
+
|
| 140 |
+
Args:
|
| 141 |
+
prompt: User question/prompt
|
| 142 |
+
has_image: Whether this prompt includes an image
|
| 143 |
+
|
| 144 |
+
Returns:
|
| 145 |
+
Formatted prompt string ready for tokenization
|
| 146 |
+
|
| 147 |
+
Factory Template Equivalent:
|
| 148 |
+
system + format_user.apply(content=formatted_prompt) + "ASSISTANT:"
|
| 149 |
+
where format_user = "USER: {{content}} "
|
| 150 |
+
and format_image_token = "<image>\n{{content}}"
|
| 151 |
+
"""
|
| 152 |
+
# Exact system message from factory template (tinyllava/data/template/llama_template.py:17)
|
| 153 |
+
system = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. "
|
| 154 |
+
|
| 155 |
+
if has_image:
|
| 156 |
+
# Clean prompt and apply factory template format_image_token: "<image>\n{{content}}"
|
| 157 |
+
clean_prompt = prompt.replace(DEFAULT_IMAGE_TOKEN, '').strip() if DEFAULT_IMAGE_TOKEN in prompt else prompt.strip()
|
| 158 |
+
formatted_prompt = f"<image>\n{clean_prompt}"
|
| 159 |
+
else:
|
| 160 |
+
formatted_prompt = prompt
|
| 161 |
+
|
| 162 |
+
# Apply factory template format_user: "USER: {{content}} "
|
| 163 |
+
# Then add ASSISTANT: for incomplete conversation (NO SPACE after ASSISTANT:)
|
| 164 |
+
# CRITICAL: Space after ASSISTANT: causes generation issues!
|
| 165 |
+
return system + f"USER: {formatted_prompt} ASSISTANT:"
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def load_image_from_base64(image):
|
| 169 |
+
return Image.open(BytesIO(base64.b64decode(image)))
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def expand2square(pil_img, background_color):
|
| 173 |
+
width, height = pil_img.size
|
| 174 |
+
if width == height:
|
| 175 |
+
return pil_img
|
| 176 |
+
elif width > height:
|
| 177 |
+
result = Image.new(pil_img.mode, (width, width), background_color)
|
| 178 |
+
result.paste(pil_img, (0, (width - height) // 2))
|
| 179 |
+
return result
|
| 180 |
+
else:
|
| 181 |
+
result = Image.new(pil_img.mode, (height, height), background_color)
|
| 182 |
+
result.paste(pil_img, ((height - width) // 2, 0))
|
| 183 |
+
return result
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def process_images(images, image_processor, model_cfg):
|
| 187 |
+
image_aspect_ratio = getattr(model_cfg, "image_aspect_ratio", None)
|
| 188 |
+
new_images = []
|
| 189 |
+
if image_aspect_ratio == 'pad':
|
| 190 |
+
for image in images:
|
| 191 |
+
image = expand2square(image, tuple(int(x*255) for x in image_processor.image_mean))
|
| 192 |
+
image = image_processor.preprocess(image, return_tensors='pt')['pixel_values'][0]
|
| 193 |
+
new_images.append(image)
|
| 194 |
+
else:
|
| 195 |
+
return image_processor(images, return_tensors='pt')['pixel_values']
|
| 196 |
+
if all(x.shape == new_images[0].shape for x in new_images):
|
| 197 |
+
new_images = torch.stack(new_images, dim=0)
|
| 198 |
+
return new_images
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def tokenizer_image_token(prompt, tokenizer, image_token_index=IMAGE_TOKEN_INDEX, return_tensors=None):
|
| 202 |
+
"""
|
| 203 |
+
Tokenize prompt with image tokens, matching factory implementation exactly.
|
| 204 |
+
|
| 205 |
+
CRITICAL: This function must match tinyllava.data.template.base.Template.tokenizer_image_token()
|
| 206 |
+
|
| 207 |
+
Key details:
|
| 208 |
+
- Function name must be _insert_separator (not insert_separator) to match factory
|
| 209 |
+
- Handle BOS token offset correctly
|
| 210 |
+
- Process image tokens by replacing <image> with image_token_index
|
| 211 |
+
|
| 212 |
+
Args:
|
| 213 |
+
prompt: Text prompt with <image> tokens
|
| 214 |
+
tokenizer: HuggingFace tokenizer
|
| 215 |
+
image_token_index: Token ID for image placeholders (default: IMAGE_TOKEN_INDEX)
|
| 216 |
+
return_tensors: Return format ('pt' for PyTorch tensor)
|
| 217 |
+
|
| 218 |
+
Returns:
|
| 219 |
+
List of token IDs or PyTorch tensor if return_tensors='pt'
|
| 220 |
+
|
| 221 |
+
Factory equivalent: tinyllava.data.template.base.Template.tokenizer_image_token()
|
| 222 |
+
"""
|
| 223 |
+
def _insert_separator(X, sep):
|
| 224 |
+
return [ele for sublist in zip(X, [sep]*len(X)) for ele in sublist][:-1]
|
| 225 |
+
prompt_chunks = [tokenizer(chunk).input_ids for chunk in prompt.split('<image>')]
|
| 226 |
+
|
| 227 |
+
input_ids = []
|
| 228 |
+
offset = 0
|
| 229 |
+
if len(prompt_chunks) > 0 and len(prompt_chunks[0]) > 0 and prompt_chunks[0][0] == tokenizer.bos_token_id:
|
| 230 |
+
offset = 1
|
| 231 |
+
input_ids.append(prompt_chunks[0][0])
|
| 232 |
+
|
| 233 |
+
for x in _insert_separator(prompt_chunks, [image_token_index] * (offset + 1)):
|
| 234 |
+
input_ids.extend(x[offset:])
|
| 235 |
+
|
| 236 |
+
if return_tensors is not None:
|
| 237 |
+
if return_tensors == 'pt':
|
| 238 |
+
return torch.tensor(input_ids, dtype=torch.long)
|
| 239 |
+
raise ValueError(f'Unsupported tensor type: {return_tensors}')
|
| 240 |
+
return input_ids
|
| 241 |
+
|
| 242 |
+
def load_image(image_file):
|
| 243 |
+
if image_file.startswith("http") or image_file.startswith("https"):
|
| 244 |
+
response = requests.get(image_file)
|
| 245 |
+
image = Image.open(BytesIO(response.content)).convert("RGB")
|
| 246 |
+
else:
|
| 247 |
+
image = Image.open(image_file).convert("RGB")
|
| 248 |
+
return image
|
| 249 |
+
|
| 250 |
+
ACT_TYPE = {
|
| 251 |
+
'relu': nn.ReLU,
|
| 252 |
+
'gelu': nn.GELU
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
class Connector(nn.Module):
|
| 256 |
+
def __init__(self, config=None):
|
| 257 |
+
super().__init__()
|
| 258 |
+
mlp_gelu_match = re.match(r'^mlp(\d+)x_gelu$', config.connector_type)
|
| 259 |
+
act_type = config.connector_type.split('_')[-1]
|
| 260 |
+
mlp_depth = int(mlp_gelu_match.group(1))
|
| 261 |
+
modules = [nn.Linear(config.vision_hidden_size, config.hidden_size)]
|
| 262 |
+
for _ in range(1, mlp_depth):
|
| 263 |
+
modules.append(ACT_TYPE[act_type]())
|
| 264 |
+
modules.append(nn.Linear(config.hidden_size, config.hidden_size))
|
| 265 |
+
|
| 266 |
+
self._connector = nn.Sequential(*modules)
|
| 267 |
+
|
| 268 |
+
def forward(self, x):
|
| 269 |
+
return self._connector(x)
|
| 270 |
+
|
| 271 |
+
class VisionTower(nn.Module):
|
| 272 |
+
def __init__(self, cfg, model_name_or_path = 'clip'):
|
| 273 |
+
super().__init__()
|
| 274 |
+
if 'clip' in model_name_or_path:
|
| 275 |
+
self._vision_tower = CLIPVisionModel(cfg)
|
| 276 |
+
self._image_processor = CLIPImageProcessor.from_pretrained(cfg.model_name_or_path)
|
| 277 |
+
else:
|
| 278 |
+
self._vision_tower = SiglipVisionModel(cfg)
|
| 279 |
+
self._image_processor = SiglipImageProcessor.from_pretrained(cfg.model_name_or_path)
|
| 280 |
+
|
| 281 |
+
self.config = cfg
|
| 282 |
+
|
| 283 |
+
def forward(self, x, **kwargs):
|
| 284 |
+
image_features = self._vision_tower(x, output_hidden_states=True)
|
| 285 |
+
image_features = image_features.hidden_states[kwargs.get('vision_feature_layer', -2)]
|
| 286 |
+
|
| 287 |
+
if kwargs.get('vision_feature_select_strategy', 'patch') == 'patch':
|
| 288 |
+
image_features = image_features[:, 1:]
|
| 289 |
+
elif kwargs.get('vision_feature_select_strategy', 'patch') == 'cls_patch':
|
| 290 |
+
image_features = image_features
|
| 291 |
+
else:
|
| 292 |
+
raise ValueError(f"Unexpected select feature: {kwargs.get('vision_feature_select_strategy')}")
|
| 293 |
+
|
| 294 |
+
return image_features
|
| 295 |
+
|
| 296 |
+
@property
|
| 297 |
+
def vision_tower(self):
|
| 298 |
+
return self._vision_tower
|
| 299 |
+
|
| 300 |
+
@vision_tower.setter
|
| 301 |
+
def vision_tower(self, vision_tower):
|
| 302 |
+
self._vision_tower = vision_tower
|
| 303 |
+
|
| 304 |
+
def get_value_from_kwargs(kwargs, name):
|
| 305 |
+
if name in kwargs:
|
| 306 |
+
return kwargs.pop(name)
|
| 307 |
+
else:
|
| 308 |
+
return None
|
| 309 |
+
|
| 310 |
+
class KeywordsStoppingCriteria(StoppingCriteria):
|
| 311 |
+
"""
|
| 312 |
+
Stopping criteria that stops generation when specific keywords are generated.
|
| 313 |
+
|
| 314 |
+
CRITICAL: This class is essential for preventing repetitive generation.
|
| 315 |
+
Without stopping criteria, the model will continue generating indefinitely,
|
| 316 |
+
leading to repetitive, verbose output.
|
| 317 |
+
|
| 318 |
+
Factory equivalent: tinyllava.utils.eval_utils.KeywordsStoppingCriteria
|
| 319 |
+
|
| 320 |
+
The factory system uses this with keywords=["</s>"] to stop at EOS tokens.
|
| 321 |
+
This prevents the model from generating beyond the natural response end.
|
| 322 |
+
|
| 323 |
+
Args:
|
| 324 |
+
keywords: List of stop words/tokens (typically ["</s>"])
|
| 325 |
+
tokenizer: Tokenizer to encode keywords
|
| 326 |
+
input_ids: Initial input tokens to track generation start
|
| 327 |
+
"""
|
| 328 |
+
def __init__(self, keywords, tokenizer, input_ids):
|
| 329 |
+
self.keywords = keywords
|
| 330 |
+
self.keyword_ids = []
|
| 331 |
+
self.max_keyword_len = 0
|
| 332 |
+
for keyword in keywords:
|
| 333 |
+
cur_keyword_ids = tokenizer(keyword).input_ids
|
| 334 |
+
if len(cur_keyword_ids) > 1 and cur_keyword_ids[0] == tokenizer.bos_token_id:
|
| 335 |
+
cur_keyword_ids = cur_keyword_ids[1:]
|
| 336 |
+
if len(cur_keyword_ids) > self.max_keyword_len:
|
| 337 |
+
self.max_keyword_len = len(cur_keyword_ids)
|
| 338 |
+
self.keyword_ids.append(torch.tensor(cur_keyword_ids))
|
| 339 |
+
self.tokenizer = tokenizer
|
| 340 |
+
self.start_len = input_ids.shape[1]
|
| 341 |
+
|
| 342 |
+
def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
|
| 343 |
+
"""Check if any keyword appears at the end of generated sequence."""
|
| 344 |
+
offset = min(input_ids.shape[1] - self.start_len, self.max_keyword_len)
|
| 345 |
+
self.keyword_ids = [keyword_id.to(input_ids.device) for keyword_id in self.keyword_ids]
|
| 346 |
+
for keyword_id in self.keyword_ids:
|
| 347 |
+
if (input_ids[0, -keyword_id.shape[0]:] == keyword_id).all():
|
| 348 |
+
return True
|
| 349 |
+
return False
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
class TinyLlavaPreTrainedModel(PreTrainedModel):
|
| 353 |
+
config_class = TinyLlavaConfig
|
| 354 |
+
base_model_prefix = "model"
|
| 355 |
+
supports_gradient_checkpointing = True
|
| 356 |
+
_no_split_modules = ["LlavaVisionAttention"]
|
| 357 |
+
_skip_keys_device_placement = "past_key_values"
|
| 358 |
+
_supports_flash_attn_2 = True
|
| 359 |
+
|
| 360 |
+
def _init_weights(self, module):
|
| 361 |
+
std = (
|
| 362 |
+
self.config.initializer_range
|
| 363 |
+
if hasattr(self.config, "initializer_range")
|
| 364 |
+
else self.config.text_config.initializer_range
|
| 365 |
+
)
|
| 366 |
+
|
| 367 |
+
if hasattr(module, "class_embedding"):
|
| 368 |
+
module.class_embedding.data.normal_(mean=0.0, std=std)
|
| 369 |
+
|
| 370 |
+
if isinstance(module, (nn.Linear, nn.Conv2d)):
|
| 371 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 372 |
+
if module.bias is not None:
|
| 373 |
+
module.bias.data.zero_()
|
| 374 |
+
elif isinstance(module, nn.Embedding):
|
| 375 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 376 |
+
if module.padding_idx is not None:
|
| 377 |
+
module.weight.data[module.padding_idx].zero_()
|
| 378 |
+
|
| 379 |
+
@property
|
| 380 |
+
def _supports_sdpa(self):
|
| 381 |
+
return self.language_model._supports_sdpa
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
class TinyLlavaForConditionalGeneration(TinyLlavaPreTrainedModel):
|
| 385 |
+
def __init__(self, config: TinyLlavaConfig):
|
| 386 |
+
|
| 387 |
+
super().__init__(config)
|
| 388 |
+
|
| 389 |
+
self.language_model = LlamaForCausalLM(config.text_config)
|
| 390 |
+
self.vision_tower = VisionTower(config.vision_config, config.vision_model_name_or_path)
|
| 391 |
+
self.connector = Connector(config)
|
| 392 |
+
self.post_init()
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
def get_input_embeddings(self):
|
| 396 |
+
return self.language_model.get_input_embeddings()
|
| 397 |
+
|
| 398 |
+
def set_input_embeddings(self, value):
|
| 399 |
+
self.language_model.set_input_embeddings(value)
|
| 400 |
+
|
| 401 |
+
def get_output_embeddings(self):
|
| 402 |
+
return self.language_model.get_output_embeddings()
|
| 403 |
+
|
| 404 |
+
def set_output_embeddings(self, new_embeddings):
|
| 405 |
+
self.language_model.set_output_embeddings(new_embeddings)
|
| 406 |
+
|
| 407 |
+
def set_decoder(self, decoder):
|
| 408 |
+
self.language_model.set_decoder(decoder)
|
| 409 |
+
|
| 410 |
+
def get_decoder(self):
|
| 411 |
+
return self.language_model.get_decoder()
|
| 412 |
+
|
| 413 |
+
def tie_weights(self):
|
| 414 |
+
return self.language_model.tie_weights()
|
| 415 |
+
|
| 416 |
+
def resize_token_embeddings(self, new_num_tokens: Optional[int] = None, pad_to_multiple_of=None) -> nn.Embedding:
|
| 417 |
+
model_embeds = self.language_model.resize_token_embeddings(new_num_tokens, pad_to_multiple_of)
|
| 418 |
+
# update vocab size
|
| 419 |
+
self.config.text_config.vocab_size = model_embeds.num_embeddings
|
| 420 |
+
self.config.vocab_size = model_embeds.num_embeddings
|
| 421 |
+
self.vocab_size = model_embeds.num_embeddings
|
| 422 |
+
return model_embeds
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
def forward(
|
| 426 |
+
self,
|
| 427 |
+
input_ids: torch.LongTensor = None,
|
| 428 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 429 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 430 |
+
past_key_values: Optional[List[torch.FloatTensor]] = None,
|
| 431 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 432 |
+
labels: Optional[torch.LongTensor] = None,
|
| 433 |
+
use_cache: Optional[bool] = None,
|
| 434 |
+
output_attentions: Optional[bool] = None,
|
| 435 |
+
output_hidden_states: Optional[bool] = None,
|
| 436 |
+
images: Optional[torch.FloatTensor] = None,
|
| 437 |
+
image_sizes: Optional[List[List[int]]] = None,
|
| 438 |
+
return_dict: Optional[bool] = None,
|
| 439 |
+
) -> Union[Tuple, CausalLMOutputWithPast]:
|
| 440 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
| 441 |
+
if inputs_embeds is None:
|
| 442 |
+
(
|
| 443 |
+
input_ids,
|
| 444 |
+
position_ids,
|
| 445 |
+
attention_mask,
|
| 446 |
+
past_key_values,
|
| 447 |
+
inputs_embeds,
|
| 448 |
+
labels
|
| 449 |
+
) = self.prepare_inputs_labels_for_multimodal(
|
| 450 |
+
input_ids,
|
| 451 |
+
position_ids,
|
| 452 |
+
attention_mask,
|
| 453 |
+
past_key_values,
|
| 454 |
+
labels,
|
| 455 |
+
images,
|
| 456 |
+
image_sizes
|
| 457 |
+
)
|
| 458 |
+
return self.language_model.forward(
|
| 459 |
+
input_ids=input_ids,
|
| 460 |
+
attention_mask=attention_mask,
|
| 461 |
+
position_ids=position_ids,
|
| 462 |
+
past_key_values=past_key_values,
|
| 463 |
+
inputs_embeds=inputs_embeds,
|
| 464 |
+
labels=labels,
|
| 465 |
+
use_cache=use_cache,
|
| 466 |
+
output_attentions=output_attentions,
|
| 467 |
+
output_hidden_states=output_hidden_states,
|
| 468 |
+
return_dict=return_dict
|
| 469 |
+
)
|
| 470 |
+
|
| 471 |
+
@torch.no_grad()
|
| 472 |
+
def generate(
|
| 473 |
+
self,
|
| 474 |
+
inputs: Optional[torch.Tensor] = None,
|
| 475 |
+
images: Optional[torch.Tensor] = None,
|
| 476 |
+
image_sizes: Optional[torch.Tensor] = None,
|
| 477 |
+
**kwargs,
|
| 478 |
+
) -> Union[GenerateOutput, torch.LongTensor]:
|
| 479 |
+
position_ids = kwargs.pop("position_ids", None)
|
| 480 |
+
attention_mask = kwargs.pop("attention_mask", None)
|
| 481 |
+
if "inputs_embeds" in kwargs:
|
| 482 |
+
raise NotImplementedError("`inputs_embeds` is not supported")
|
| 483 |
+
|
| 484 |
+
if images is not None:
|
| 485 |
+
(
|
| 486 |
+
inputs,
|
| 487 |
+
position_ids,
|
| 488 |
+
attention_mask,
|
| 489 |
+
_,
|
| 490 |
+
inputs_embeds,
|
| 491 |
+
_
|
| 492 |
+
) = self.prepare_inputs_labels_for_multimodal(
|
| 493 |
+
inputs,
|
| 494 |
+
position_ids,
|
| 495 |
+
attention_mask,
|
| 496 |
+
None,
|
| 497 |
+
None,
|
| 498 |
+
images,
|
| 499 |
+
image_sizes=image_sizes
|
| 500 |
+
)
|
| 501 |
+
else:
|
| 502 |
+
inputs_embeds = self.language_model.get_input_embeddings()(inputs)
|
| 503 |
+
|
| 504 |
+
return self.language_model.generate(
|
| 505 |
+
position_ids=position_ids,
|
| 506 |
+
attention_mask=attention_mask,
|
| 507 |
+
inputs_embeds=inputs_embeds,
|
| 508 |
+
**kwargs
|
| 509 |
+
)
|
| 510 |
+
|
| 511 |
+
def encode_images(self, images):
|
| 512 |
+
kwargs = {}
|
| 513 |
+
kwargs['vision_feature_layer'] = self.config.vision_feature_layer
|
| 514 |
+
kwargs['vision_feature_select_strategy'] = self.config.vision_feature_select_strategy
|
| 515 |
+
images = images.to(device=self.device, dtype=self.dtype)
|
| 516 |
+
image_features = self.vision_tower(images, **kwargs)
|
| 517 |
+
image_features = self.connector(image_features)
|
| 518 |
+
return image_features
|
| 519 |
+
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
def prepare_inputs_for_generation(self, input_ids, past_key_values=None,
|
| 523 |
+
inputs_embeds=None, **kwargs):
|
| 524 |
+
images = kwargs.pop("images", None)
|
| 525 |
+
image_sizes = kwargs.pop("image_sizes", None)
|
| 526 |
+
inputs = self.language_model.prepare_inputs_for_generation(
|
| 527 |
+
input_ids, past_key_values=past_key_values, inputs_embeds=inputs_embeds, **kwargs
|
| 528 |
+
)
|
| 529 |
+
if images is not None:
|
| 530 |
+
inputs['images'] = images
|
| 531 |
+
if image_sizes is not None:
|
| 532 |
+
inputs['image_sizes'] = image_sizes
|
| 533 |
+
return inputs
|
| 534 |
+
|
| 535 |
+
def prepare_inputs_labels_for_multimodal(
|
| 536 |
+
self, input_ids, position_ids, attention_mask, past_key_values, labels,
|
| 537 |
+
images, image_sizes=None
|
| 538 |
+
):
|
| 539 |
+
vision_tower = self.vision_tower
|
| 540 |
+
if vision_tower is None or images is None or input_ids.shape[1] == 1:
|
| 541 |
+
return input_ids, position_ids, attention_mask, past_key_values, None, labels
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
image_features = self.encode_images(images)
|
| 545 |
+
|
| 546 |
+
# TODO: image start / end is not implemented here to support pretraining.
|
| 547 |
+
if getattr(self.config, 'tune_mm_mlp_adapter', False):
|
| 548 |
+
raise NotImplementedError
|
| 549 |
+
|
| 550 |
+
# Let's just add dummy tensors if they do not exist,
|
| 551 |
+
# it is a headache to deal with None all the time.
|
| 552 |
+
# But it is not ideal, and if you have a better idea,
|
| 553 |
+
# please open an issue / submit a PR, thanks.
|
| 554 |
+
_labels = labels
|
| 555 |
+
_position_ids = position_ids
|
| 556 |
+
_attention_mask = attention_mask
|
| 557 |
+
if attention_mask is None:
|
| 558 |
+
attention_mask = torch.ones_like(input_ids, dtype=torch.bool)
|
| 559 |
+
else:
|
| 560 |
+
attention_mask = attention_mask.bool()
|
| 561 |
+
if position_ids is None:
|
| 562 |
+
position_ids = torch.arange(0, input_ids.shape[1], dtype=torch.long, device=input_ids.device)
|
| 563 |
+
if labels is None:
|
| 564 |
+
labels = torch.full_like(input_ids, IGNORE_INDEX)
|
| 565 |
+
|
| 566 |
+
# remove the padding using attention_mask -- FIXME
|
| 567 |
+
_input_ids = input_ids
|
| 568 |
+
input_ids = [cur_input_ids[cur_attention_mask] for cur_input_ids, cur_attention_mask in zip(input_ids, attention_mask)]
|
| 569 |
+
labels = [cur_labels[cur_attention_mask] for cur_labels, cur_attention_mask in zip(labels, attention_mask)]
|
| 570 |
+
|
| 571 |
+
new_input_embeds = []
|
| 572 |
+
new_labels = []
|
| 573 |
+
cur_image_idx = 0
|
| 574 |
+
for batch_idx, cur_input_ids in enumerate(input_ids):
|
| 575 |
+
num_images = (cur_input_ids == IMAGE_TOKEN_INDEX).sum()
|
| 576 |
+
if num_images == 0:
|
| 577 |
+
cur_image_features = image_features[cur_image_idx]
|
| 578 |
+
cur_input_embeds_1 = self.language_model.get_input_embeddings()(cur_input_ids)
|
| 579 |
+
cur_input_embeds = torch.cat([cur_input_embeds_1, cur_image_features[0:0]], dim=0)
|
| 580 |
+
new_input_embeds.append(cur_input_embeds)
|
| 581 |
+
new_labels.append(labels[batch_idx])
|
| 582 |
+
cur_image_idx += 1
|
| 583 |
+
continue
|
| 584 |
+
|
| 585 |
+
image_token_indices = [-1] + torch.where(cur_input_ids == IMAGE_TOKEN_INDEX)[0].tolist() + [cur_input_ids.shape[0]]
|
| 586 |
+
cur_input_ids_noim = []
|
| 587 |
+
cur_labels = labels[batch_idx]
|
| 588 |
+
cur_labels_noim = []
|
| 589 |
+
for i in range(len(image_token_indices) - 1):
|
| 590 |
+
cur_input_ids_noim.append(cur_input_ids[image_token_indices[i]+1:image_token_indices[i+1]])
|
| 591 |
+
cur_labels_noim.append(cur_labels[image_token_indices[i]+1:image_token_indices[i+1]])
|
| 592 |
+
split_sizes = [x.shape[0] for x in cur_labels_noim]
|
| 593 |
+
cur_input_embeds = self.language_model.get_input_embeddings()(torch.cat(cur_input_ids_noim))
|
| 594 |
+
cur_input_embeds_no_im = torch.split(cur_input_embeds, split_sizes, dim=0)
|
| 595 |
+
cur_new_input_embeds = []
|
| 596 |
+
cur_new_labels = []
|
| 597 |
+
|
| 598 |
+
for i in range(num_images + 1):
|
| 599 |
+
cur_new_input_embeds.append(cur_input_embeds_no_im[i])
|
| 600 |
+
cur_new_labels.append(cur_labels_noim[i])
|
| 601 |
+
if i < num_images:
|
| 602 |
+
cur_image_features = image_features[cur_image_idx]
|
| 603 |
+
cur_image_idx += 1
|
| 604 |
+
cur_new_input_embeds.append(cur_image_features)
|
| 605 |
+
cur_new_labels.append(torch.full((cur_image_features.shape[0],), IGNORE_INDEX, device=cur_labels.device, dtype=cur_labels.dtype))
|
| 606 |
+
|
| 607 |
+
cur_new_input_embeds = [x.to(self.device) for x in cur_new_input_embeds]
|
| 608 |
+
|
| 609 |
+
cur_new_input_embeds = torch.cat(cur_new_input_embeds)
|
| 610 |
+
cur_new_labels = torch.cat(cur_new_labels)
|
| 611 |
+
|
| 612 |
+
new_input_embeds.append(cur_new_input_embeds)
|
| 613 |
+
new_labels.append(cur_new_labels)
|
| 614 |
+
|
| 615 |
+
# Truncate sequences to max length as image embeddings can make the sequence longer
|
| 616 |
+
tokenizer_model_max_length = getattr(self.config, 'tokenizer_model_max_length', None)
|
| 617 |
+
if tokenizer_model_max_length is not None:
|
| 618 |
+
new_input_embeds = [x[:tokenizer_model_max_length] for x in new_input_embeds]
|
| 619 |
+
new_labels = [x[:tokenizer_model_max_length] for x in new_labels]
|
| 620 |
+
|
| 621 |
+
# Combine them
|
| 622 |
+
max_len = max(x.shape[0] for x in new_input_embeds)
|
| 623 |
+
batch_size = len(new_input_embeds)
|
| 624 |
+
|
| 625 |
+
new_input_embeds_padded = []
|
| 626 |
+
new_labels_padded = torch.full((batch_size, max_len), IGNORE_INDEX, dtype=new_labels[0].dtype, device=new_labels[0].device)
|
| 627 |
+
attention_mask = torch.zeros((batch_size, max_len), dtype=attention_mask.dtype, device=attention_mask.device)
|
| 628 |
+
position_ids = torch.zeros((batch_size, max_len), dtype=position_ids.dtype, device=position_ids.device)
|
| 629 |
+
|
| 630 |
+
for i, (cur_new_embed, cur_new_labels) in enumerate(zip(new_input_embeds, new_labels)):
|
| 631 |
+
cur_len = cur_new_embed.shape[0]
|
| 632 |
+
if getattr(self.config, 'tokenizer_padding_side', 'right') == "left":
|
| 633 |
+
new_input_embeds_padded.append(torch.cat((
|
| 634 |
+
torch.zeros((max_len - cur_len, cur_new_embed.shape[1]), dtype=cur_new_embed.dtype, device=cur_new_embed.device),
|
| 635 |
+
cur_new_embed
|
| 636 |
+
), dim=0))
|
| 637 |
+
if cur_len > 0:
|
| 638 |
+
new_labels_padded[i, -cur_len:] = cur_new_labels
|
| 639 |
+
attention_mask[i, -cur_len:] = True
|
| 640 |
+
position_ids[i, -cur_len:] = torch.arange(0, cur_len, dtype=position_ids.dtype, device=position_ids.device)
|
| 641 |
+
else:
|
| 642 |
+
new_input_embeds_padded.append(torch.cat((
|
| 643 |
+
cur_new_embed,
|
| 644 |
+
torch.zeros((max_len - cur_len, cur_new_embed.shape[1]), dtype=cur_new_embed.dtype, device=cur_new_embed.device)
|
| 645 |
+
), dim=0))
|
| 646 |
+
if cur_len > 0:
|
| 647 |
+
new_labels_padded[i, :cur_len] = cur_new_labels
|
| 648 |
+
attention_mask[i, :cur_len] = True
|
| 649 |
+
position_ids[i, :cur_len] = torch.arange(0, cur_len, dtype=position_ids.dtype, device=position_ids.device)
|
| 650 |
+
|
| 651 |
+
new_input_embeds = torch.stack(new_input_embeds_padded, dim=0)
|
| 652 |
+
|
| 653 |
+
if _labels is None:
|
| 654 |
+
new_labels = None
|
| 655 |
+
else:
|
| 656 |
+
new_labels = new_labels_padded
|
| 657 |
+
|
| 658 |
+
if _attention_mask is None:
|
| 659 |
+
attention_mask = None
|
| 660 |
+
else:
|
| 661 |
+
attention_mask = attention_mask.to(dtype=_attention_mask.dtype)
|
| 662 |
+
|
| 663 |
+
if _position_ids is None:
|
| 664 |
+
position_ids = None
|
| 665 |
+
|
| 666 |
+
return None, position_ids, attention_mask, past_key_values, new_input_embeds, new_labels
|
| 667 |
+
|
| 668 |
+
def chat(
|
| 669 |
+
self,
|
| 670 |
+
prompt: str,
|
| 671 |
+
tokenizer = None,
|
| 672 |
+
image: str = None,
|
| 673 |
+
max_new_tokens: int = 512,
|
| 674 |
+
num_beams = 1,
|
| 675 |
+
top_p=None,
|
| 676 |
+
temperature=0
|
| 677 |
+
):
|
| 678 |
+
"""
|
| 679 |
+
Standalone chat interface that replicates factory system behavior exactly.
|
| 680 |
+
|
| 681 |
+
CRITICAL FIXES APPLIED:
|
| 682 |
+
=====================
|
| 683 |
+
|
| 684 |
+
1. PROMPT FORMAT: Uses exact factory template format with "ASSISTANT:" (no space)
|
| 685 |
+
2. STOPPING CRITERIA: Added KeywordsStoppingCriteria(["</s>"]) to prevent loops
|
| 686 |
+
3. IMAGE PROCESSING: Process images as [image] list, handle tensor outputs
|
| 687 |
+
4. OUTPUT CLEANING: Strip EOS tokens like factory does
|
| 688 |
+
|
| 689 |
+
This method replicates:
|
| 690 |
+
- tinyllava.eval.run_tiny_llava.eval_model() pipeline
|
| 691 |
+
- tinyllava.data.template.LlamaTemplate formatting
|
| 692 |
+
- tinyllava.utils.eval_utils.KeywordsStoppingCriteria stopping
|
| 693 |
+
|
| 694 |
+
Args:
|
| 695 |
+
prompt: User question
|
| 696 |
+
tokenizer: HuggingFace tokenizer
|
| 697 |
+
image: Image path/URL or None
|
| 698 |
+
max_new_tokens: Maximum tokens to generate
|
| 699 |
+
num_beams: Beam search width
|
| 700 |
+
top_p: Nucleus sampling parameter
|
| 701 |
+
temperature: Sampling temperature
|
| 702 |
+
|
| 703 |
+
Returns:
|
| 704 |
+
Tuple of (generated_text: str, generation_time: float)
|
| 705 |
+
|
| 706 |
+
BUG HISTORY:
|
| 707 |
+
============
|
| 708 |
+
- Original: Repetitive numbered lists due to wrong prompt format
|
| 709 |
+
- Fixed: Exact factory template alignment prevents repetition
|
| 710 |
+
"""
|
| 711 |
+
image_processor = self.vision_tower._image_processor
|
| 712 |
+
|
| 713 |
+
# Format prompt using factory-aligned template
|
| 714 |
+
has_image = image is not None
|
| 715 |
+
# Don't add image token here - let format_chat_prompt handle it properly
|
| 716 |
+
formatted_prompt = format_chat_prompt(prompt, has_image)
|
| 717 |
+
|
| 718 |
+
image_tensor = None
|
| 719 |
+
if image is not None:
|
| 720 |
+
image = load_image(image)
|
| 721 |
+
image_tensor = process_images([image], image_processor, self.config)
|
| 722 |
+
if isinstance(image_tensor, list):
|
| 723 |
+
image_tensor = torch.stack(image_tensor).to(self.device)
|
| 724 |
+
else:
|
| 725 |
+
image_tensor = image_tensor.to(self.device)
|
| 726 |
+
|
| 727 |
+
# Tokenize using factory-aligned method
|
| 728 |
+
input_ids = tokenizer_image_token(formatted_prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt")
|
| 729 |
+
|
| 730 |
+
# Ensure proper shape and BOS token handling
|
| 731 |
+
if input_ids.dim() == 1:
|
| 732 |
+
input_ids = input_ids.unsqueeze(0)
|
| 733 |
+
input_ids = input_ids.to(self.device)
|
| 734 |
+
|
| 735 |
+
# Generate
|
| 736 |
+
stime = time.time()
|
| 737 |
+
|
| 738 |
+
# Add stopping criteria to match factory behavior
|
| 739 |
+
stop_str = "</s>"
|
| 740 |
+
keywords = [stop_str]
|
| 741 |
+
stopping_criteria = KeywordsStoppingCriteria(keywords, tokenizer, input_ids)
|
| 742 |
+
|
| 743 |
+
with torch.inference_mode():
|
| 744 |
+
output_ids = self.generate(
|
| 745 |
+
input_ids,
|
| 746 |
+
images=image_tensor,
|
| 747 |
+
do_sample=True if temperature > 0 else False,
|
| 748 |
+
temperature=temperature,
|
| 749 |
+
top_p=top_p,
|
| 750 |
+
num_beams=num_beams,
|
| 751 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 752 |
+
max_new_tokens=max_new_tokens,
|
| 753 |
+
use_cache=True,
|
| 754 |
+
stopping_criteria=[stopping_criteria],
|
| 755 |
+
)
|
| 756 |
+
|
| 757 |
+
generation_time = time.time() - stime
|
| 758 |
+
outputs = tokenizer.batch_decode(
|
| 759 |
+
output_ids, skip_special_tokens=True
|
| 760 |
+
)[0]
|
| 761 |
+
|
| 762 |
+
# Clean output like factory does
|
| 763 |
+
outputs = outputs.strip()
|
| 764 |
+
if outputs.endswith(stop_str):
|
| 765 |
+
outputs = outputs[:-len(stop_str)]
|
| 766 |
+
outputs = outputs.strip()
|
| 767 |
+
|
| 768 |
+
return outputs, generation_time
|
| 769 |
+
|
| 770 |
+
|
| 771 |
+
AutoConfig.register("tinyllava", TinyLlavaConfig)
|
| 772 |
+
AutoModelForCausalLM.register(TinyLlavaConfig, TinyLlavaForConditionalGeneration)
|
| 773 |
+
|
| 774 |
+
"""
|
| 775 |
+
=============================================================================
|
| 776 |
+
STEP-BY-STEP GUIDE: Creating a Factory-Aligned Standalone Model
|
| 777 |
+
=============================================================================
|
| 778 |
+
|
| 779 |
+
To convert a factory-based TinyLLaVA model to a standalone HuggingFace model
|
| 780 |
+
that produces identical results, follow these steps:
|
| 781 |
+
|
| 782 |
+
STEP 1: Copy Factory Template Logic
|
| 783 |
+
===================================
|
| 784 |
+
- Copy prompt formatting from tinyllava/data/template/llama_template.py
|
| 785 |
+
- Key components:
|
| 786 |
+
* system message (exact text with trailing space)
|
| 787 |
+
* format_user = "USER: {{content}} "
|
| 788 |
+
* format_assistant = "ASSISTANT: {{content}}</s>"
|
| 789 |
+
* format_image_token = "<image>\n{{content}}"
|
| 790 |
+
|
| 791 |
+
STEP 2: Fix Critical Prompt Format Bug
|
| 792 |
+
======================================
|
| 793 |
+
CRITICAL: The prompt MUST end with "ASSISTANT:" (NO SPACE)
|
| 794 |
+
- Factory format: "...USER: <image>\nQuestion ASSISTANT:"
|
| 795 |
+
- Wrong format: "...USER: <image>\nQuestion ASSISTANT: " (causes repetition)
|
| 796 |
+
- This single space difference causes completely different generation behavior
|
| 797 |
+
|
| 798 |
+
STEP 3: Add Stopping Criteria
|
| 799 |
+
===============================
|
| 800 |
+
Copy KeywordsStoppingCriteria from tinyllava.utils.eval_utils
|
| 801 |
+
- Must stop at ["</s>"] tokens
|
| 802 |
+
- Without stopping criteria, model generates infinite repetitive loops
|
| 803 |
+
- Add to generate() call: stopping_criteria=[KeywordsStoppingCriteria(["</s>"], tokenizer, input_ids)]
|
| 804 |
+
|
| 805 |
+
STEP 4: Fix Tokenization
|
| 806 |
+
=========================
|
| 807 |
+
Copy tokenizer_image_token from tinyllava.data.template.base
|
| 808 |
+
- Use _insert_separator (with underscore) function name
|
| 809 |
+
- Handle BOS token offsets correctly
|
| 810 |
+
- Process <image> tokens properly
|
| 811 |
+
|
| 812 |
+
STEP 5: Fix Image Processing
|
| 813 |
+
============================
|
| 814 |
+
- Pass images as list: process_images([image], processor, config)
|
| 815 |
+
- Handle both list and tensor return types
|
| 816 |
+
- Apply proper device placement: .to(self.device)
|
| 817 |
+
|
| 818 |
+
STEP 6: Add Output Cleaning
|
| 819 |
+
===========================
|
| 820 |
+
Clean outputs like factory does:
|
| 821 |
+
```python
|
| 822 |
+
outputs = outputs.strip()
|
| 823 |
+
if outputs.endswith(stop_str):
|
| 824 |
+
outputs = outputs[:-len(stop_str)]
|
| 825 |
+
outputs = outputs.strip()
|
| 826 |
+
```
|
| 827 |
+
|
| 828 |
+
STEP 7: Test and Validate
|
| 829 |
+
=========================
|
| 830 |
+
Compare outputs between factory and standalone:
|
| 831 |
+
- Factory: python simply_inference.py
|
| 832 |
+
- Standalone: python hugging_face_inference.py
|
| 833 |
+
- Outputs should be nearly identical
|
| 834 |
+
|
| 835 |
+
DEBUGGING CHECKLIST:
|
| 836 |
+
====================
|
| 837 |
+
□ Prompt ends with "ASSISTANT:" (no space)
|
| 838 |
+
□ KeywordsStoppingCriteria added with ["</s>"]
|
| 839 |
+
□ Images processed as [image] list
|
| 840 |
+
□ _insert_separator function name used
|
| 841 |
+
□ Output cleaning implemented
|
| 842 |
+
□ Exact system message from factory template
|
| 843 |
+
□ Generation parameters match factory
|
| 844 |
+
|
| 845 |
+
RESULT COMPARISON:
|
| 846 |
+
==================
|
| 847 |
+
Before fixes: "1. Be cautious... 2. Wet and muddy... 3. Noisy... (repeats)"
|
| 848 |
+
After fixes: "When I visit the beach at the waterfront, I should be cautious about several things. First, I should be cautious about the water..." (matches factory)
|
| 849 |
+
|
| 850 |
+
This documentation ensures future standalone models can be created without
|
| 851 |
+
repeating the debugging process that identified these critical alignment issues.
|
| 852 |
+
"""
|