max token arttılırdı
#38
by ismailhakki37 - opened
350 unmodified lines3513523533543553563573583593 unmodified lines3633643653663673681 unmodified line3703713723733743755 unmodified lines3813823833843853865 unmodified lines3923933943953963971 unmodified line399400401402403404104 unmodified lines50951051151251351451573 unmodified lines589590591592593594350 unmodified linestry:if hasattr(our_chatbot, 'conv_mode') and our_chatbot.conv_mode and LLAVA_AVAILABLE:our_chatbot.conversation = conv_templates[our_chatbot.conv_mode].copy()else:# Use default conversation templateour_chatbot.conversation = our_chatbot.conversation.__class__()except Exception as e:print(f"[DEBUG] Failed to reset conversation: {e}")# Continue with existing conversation3 unmodified linesour_chatbot.conversation.append_message(our_chatbot.conversation.roles[1], None)prompt = our_chatbot.conversation.get_prompt()# Tokenize inputinput_ids = tokenizer_image_token(prompt, our_chatbot.tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt"1 unmodified line# No stopping criteria - let model generate freely up to max_new_tokensprint(f"[DEBUG] No stopping criteria - free generation up to {max_output_tokens} tokens")stopping_criteria = None# Set seed for deterministic generation5 unmodified lines# Generate response using deterministic greedy decoding# This eliminates randomness and ensures consistent responseswith torch.no_grad():outputs = our_chatbot.model.generate(inputs=input_ids,5 unmodified linespad_token_id=our_chatbot.tokenizer.eos_token_id,eos_token_id=our_chatbot.tokenizer.eos_token_id,length_penalty=1.0, # Don't penalize longer sequences)# Decode response1 unmodified lineprint(f"[DEBUG] Outputs shape: {outputs.shape if hasattr(outputs, 'shape') else 'No shape attr'}")print(f"[DEBUG] Outputs length: {len(outputs) if hasattr(outputs, '__len__') else 'No length'}")print(f"[DEBUG] Input IDs shape: {input_ids.shape}")if len(outputs) == 0:return {"error": "Model generated empty output"}104 unmodified linesself.model_base = Noneself.num_gpus = 1self.conv_mode = Noneself.max_new_tokens = 1024self.num_frames = 16self.load_8bit = Falseself.load_4bit = False73 unmodified linesrepetition_penalty = float(payload.get("repetition_penalty", 1.0))conv_mode_override = payload.get("conv_mode", None)if not message_text or not message_text.strip():return {"error": "Missing prompt text. Use 'message', 'query', 'prompt', or 'istem' key"}350 unmodified lines3513523533543553563573583593603613 unmodified lines3653663673683693703713723733741 unmodified line3763773783793803813823835 unmodified lines3893903913923933943953963973985 unmodified lines4044054064074084094101 unmodified line412413414415416417418419104 unmodified lines52452552652752852953073 unmodified lines604605606607608609610611612613614615616617618619350 unmodified linestry:if hasattr(our_chatbot, 'conv_mode') and our_chatbot.conv_mode and LLAVA_AVAILABLE:our_chatbot.conversation = conv_templates[our_chatbot.conv_mode].copy()print(f"[DEBUG] Reset conversation using conv_mode: {our_chatbot.conv_mode}")else:# Use default conversation templateour_chatbot.conversation = our_chatbot.conversation.__class__()print(f"[DEBUG] Reset conversation using default template")except Exception as e:print(f"[DEBUG] Failed to reset conversation: {e}")# Continue with existing conversation3 unmodified linesour_chatbot.conversation.append_message(our_chatbot.conversation.roles[1], None)prompt = our_chatbot.conversation.get_prompt()print(f"[DEBUG] Conversation template: {type(our_chatbot.conversation).__name__}")print(f"[DEBUG] Conversation roles: {our_chatbot.conversation.roles if hasattr(our_chatbot.conversation, 'roles') else 'No roles'}")print(f"[DEBUG] Final prompt length: {len(prompt)} characters")# Tokenize inputinput_ids = tokenizer_image_token(prompt, our_chatbot.tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt"1 unmodified line# No stopping criteria - let model generate freely up to max_new_tokensprint(f"[DEBUG] No stopping criteria - free generation up to {max_output_tokens} tokens")print(f"[DEBUG] Input prompt length: {len(prompt)} characters")print(f"[DEBUG] Input tokens: {input_ids.shape[1]} tokens")stopping_criteria = None# Set seed for deterministic generation5 unmodified lines# Generate response using deterministic greedy decoding# This eliminates randomness and ensures consistent responsesprint(f"[DEBUG] About to generate with max_new_tokens: {max_output_tokens}")print(f"[DEBUG] Model device: {our_chatbot.model.device}")print(f"[DEBUG] Image tensor device: {image_tensor.device}")with torch.no_grad():outputs = our_chatbot.model.generate(inputs=input_ids,5 unmodified linespad_token_id=our_chatbot.tokenizer.eos_token_id,eos_token_id=our_chatbot.tokenizer.eos_token_id,length_penalty=1.0, # Don't penalize longer sequencesearly_stopping=False, # Ensure no early stopping)# Decode response1 unmodified lineprint(f"[DEBUG] Outputs shape: {outputs.shape if hasattr(outputs, 'shape') else 'No shape attr'}")print(f"[DEBUG] Outputs length: {len(outputs) if hasattr(outputs, '__len__') else 'No length'}")print(f"[DEBUG] Input IDs shape: {input_ids.shape}")print(f"[DEBUG] Generated tokens: {outputs.shape[1] - input_ids.shape[1] if hasattr(outputs, 'shape') else 'Unknown'}")print(f"[DEBUG] Expected max tokens: {max_output_tokens}")if len(outputs) == 0:return {"error": "Model generated empty output"}104 unmodified linesself.model_base = Noneself.num_gpus = 1self.conv_mode = Noneself.max_new_tokens = 4096self.num_frames = 16self.load_8bit = Falseself.load_4bit = False73 unmodified linesrepetition_penalty = float(payload.get("repetition_penalty", 1.0))conv_mode_override = payload.get("conv_mode", None)# Debug: Log all generation parametersprint(f"[DEBUG] Generation parameters:")print(f"[DEBUG] max_output_tokens: {max_output_tokens}")print(f"[DEBUG] repetition_penalty: {repetition_penalty}")print(f"[DEBUG] Original payload max_output_tokens: {payload.get('max_output_tokens')}")print(f"[DEBUG] Original payload max_new_tokens: {payload.get('max_new_tokens')}")print(f"[DEBUG] Original payload max_tokens: {payload.get('max_tokens')}")print(f"[DEBUG] Full payload keys: {list(payload.keys())}")print(f"[DEBUG] Payload values: {dict(payload)}")if not message_text or not message_text.strip():return {"error": "Missing prompt text. Use 'message', 'query', 'prompt', or 'istem' key"}
handler.py+26-1