stop criteria esnetildi
#32
by ismailhakki37 - opened
346 unmodified lines34734834935035135235335435535635735835910 unmodified lines370371372373374375177 unmodified lines553554555556557558559346 unmodified linesprompt, our_chatbot.tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(our_chatbot.model.device)# Set up stopping criteriastop_str = (our_chatbot.conversation.sepif our_chatbot.conversation.sep_style != SeparatorStyle.TWOelse our_chatbot.conversation.sep2)keywords = [stop_str]stopping_criteria = KeywordsStoppingCriteria(keywords, our_chatbot.tokenizer, input_ids)10 unmodified linesrepetition_penalty=repetition_penalty,use_cache=False,stopping_criteria=[stopping_criteria],)# Decode response177 unmodified linestop_p = float(payload.get("top_p", 1.0))max_output_tokens = int(payload.get("max_output_tokens",payload.get("max_new_tokens",payload.get("max_tokens", 4096))))repetition_penalty = float(payload.get("repetition_penalty", 1.0))conv_mode_override = payload.get("conv_mode", None)346 unmodified lines34734834935035135235335435535635735835936036136236336436536636736836910 unmodified lines380381382383384385386387388177 unmodified lines566567568569570571572346 unmodified linesprompt, our_chatbot.tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(our_chatbot.model.device)# Set up stopping criteria - more flexible to allow longer responsesstop_str = (our_chatbot.conversation.sepif our_chatbot.conversation.sep_style != SeparatorStyle.TWOelse our_chatbot.conversation.sep2)# Use minimal stopping criteria to allow longer responseskeywords = []if stop_str and stop_str.strip():keywords.append(stop_str)# Only add very basic stopping criteria to prevent infinite generationif not keywords:keywords = ["</s>", "<s>"]print(f"[DEBUG] Using stopping criteria: {keywords}")stopping_criteria = KeywordsStoppingCriteria(keywords, our_chatbot.tokenizer, input_ids)10 unmodified linesrepetition_penalty=repetition_penalty,use_cache=False,stopping_criteria=[stopping_criteria],pad_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 response177 unmodified linestop_p = float(payload.get("top_p", 1.0))max_output_tokens = int(payload.get("max_output_tokens",payload.get("max_new_tokens",payload.get("max_tokens", 8192))))repetition_penalty = float(payload.get("repetition_penalty", 1.0))conv_mode_override = payload.get("conv_mode", None)
handler.py+16-3