Upload 3 files
Browse files- Inference.py +220 -0
- inference_1.py +139 -0
- test_sft_nothink_10.json +12 -0
Inference.py
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from vllm import LLM, SamplingParams
|
| 2 |
+
import argparse
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import datetime
|
| 7 |
+
|
| 8 |
+
def setup_model(model_path, tensor_parallel_size=None, dtype="bfloat16", gpu_memory_utilization=0.85):
|
| 9 |
+
"""
|
| 10 |
+
Initialize the fine-tuned Qwen-2.5-7B model from a local path with explicit GPU configuration.
|
| 11 |
+
|
| 12 |
+
Args:
|
| 13 |
+
model_path: Path to the directory containing the trained model
|
| 14 |
+
tensor_parallel_size: Number of GPUs to use for tensor parallelism (None means auto-detect)
|
| 15 |
+
dtype: Data type for model weights (bfloat16, float16, or float32)
|
| 16 |
+
gpu_memory_utilization: Fraction of GPU memory to use (0.0 to 1.0)
|
| 17 |
+
"""
|
| 18 |
+
print(f"Loading fine-tuned Qwen model from: {model_path}")
|
| 19 |
+
print(f"GPU configuration: tensor_parallel_size={tensor_parallel_size}, dtype={dtype}, "
|
| 20 |
+
f"gpu_memory_utilization={gpu_memory_utilization}")
|
| 21 |
+
|
| 22 |
+
# Initialize the model with VLLM using GPU settings
|
| 23 |
+
llm = LLM(
|
| 24 |
+
model=model_path,
|
| 25 |
+
trust_remote_code=True,
|
| 26 |
+
tensor_parallel_size=tensor_parallel_size, # Number of GPUs to use
|
| 27 |
+
dtype=dtype, # Data type for model weights
|
| 28 |
+
gpu_memory_utilization=gpu_memory_utilization, # Memory usage per GPU
|
| 29 |
+
enforce_eager=False, # Set to True if you encounter CUDA issues
|
| 30 |
+
# max_model_len=8192, # Uncomment if you need longer context
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
print("Model loaded successfully!")
|
| 34 |
+
return llm
|
| 35 |
+
|
| 36 |
+
def generate_response(llm, prompt, temperature=0.7, max_tokens=512, top_p=0.9):
|
| 37 |
+
"""Generate a response for a given prompt."""
|
| 38 |
+
sampling_params = SamplingParams(
|
| 39 |
+
temperature=temperature,
|
| 40 |
+
top_p=top_p,
|
| 41 |
+
max_tokens=max_tokens
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
outputs = llm.generate([prompt], sampling_params)
|
| 45 |
+
return outputs[0].outputs[0].text
|
| 46 |
+
|
| 47 |
+
def chat_completion(llm, messages, temperature=0.7, max_tokens=512):
|
| 48 |
+
"""Generate a chat completion from messages."""
|
| 49 |
+
sampling_params = SamplingParams(
|
| 50 |
+
temperature=temperature,
|
| 51 |
+
top_p=0.9,
|
| 52 |
+
max_tokens=max_tokens
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Convert messages to a prompt using the model's chat template
|
| 56 |
+
tokenizer = llm.get_tokenizer()
|
| 57 |
+
if hasattr(tokenizer, "apply_chat_template"):
|
| 58 |
+
# For newer transformers versions
|
| 59 |
+
prompt = tokenizer.apply_chat_template(
|
| 60 |
+
messages,
|
| 61 |
+
tokenize=False,
|
| 62 |
+
add_generation_prompt=True
|
| 63 |
+
)
|
| 64 |
+
else:
|
| 65 |
+
# Fallback for models without chat template
|
| 66 |
+
prompt = format_messages_manually(messages)
|
| 67 |
+
|
| 68 |
+
outputs = llm.generate([prompt], sampling_params)
|
| 69 |
+
return outputs[0].outputs[0].text
|
| 70 |
+
|
| 71 |
+
def format_messages_manually(messages):
|
| 72 |
+
"""Format messages manually if chat template is not available."""
|
| 73 |
+
formatted_prompt = ""
|
| 74 |
+
for message in messages:
|
| 75 |
+
role = message["role"]
|
| 76 |
+
content = message["content"]
|
| 77 |
+
if role == "system":
|
| 78 |
+
formatted_prompt += f"<|im_start|>system\n{content}<|im_end|>\n"
|
| 79 |
+
elif role == "user":
|
| 80 |
+
formatted_prompt += f"<|im_start|>user\n{content}<|im_end|>\n"
|
| 81 |
+
elif role == "assistant":
|
| 82 |
+
formatted_prompt += f"<|im_start|>assistant\n{content}<|im_end|>\n"
|
| 83 |
+
formatted_prompt += "<|im_start|>assistant\n"
|
| 84 |
+
return formatted_prompt
|
| 85 |
+
|
| 86 |
+
def batch_inference(llm, prompts, temperature=0.7, max_tokens=512):
|
| 87 |
+
"""Run batch inference on multiple prompts."""
|
| 88 |
+
sampling_params = SamplingParams(
|
| 89 |
+
temperature=temperature,
|
| 90 |
+
top_p=0.9,
|
| 91 |
+
max_tokens=max_tokens
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
outputs = llm.generate(prompts, sampling_params)
|
| 95 |
+
return [output.outputs[0].text for output in outputs]
|
| 96 |
+
|
| 97 |
+
def save_to_json(data, output_path=None):
|
| 98 |
+
"""Save results to a JSON file."""
|
| 99 |
+
if not output_path:
|
| 100 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 101 |
+
output_path = f"qwen_inference_results_{timestamp}.json"
|
| 102 |
+
|
| 103 |
+
with open(output_path, 'w', encoding='utf-8') as f:
|
| 104 |
+
json.dump(data, f, ensure_ascii=False, indent=2)
|
| 105 |
+
|
| 106 |
+
print(f"Results saved to: {output_path}")
|
| 107 |
+
return output_path
|
| 108 |
+
|
| 109 |
+
def main():
|
| 110 |
+
parser = argparse.ArgumentParser(description="GPU inference with fine-tuned Qwen model with JSON output")
|
| 111 |
+
parser.add_argument("--model_path", required=True, help="Path to the fine-tuned model directory")
|
| 112 |
+
parser.add_argument("--mode", choices=["single", "chat", "batch"], default="single", help="Inference mode")
|
| 113 |
+
parser.add_argument("--prompt", help="Prompt for single inference mode")
|
| 114 |
+
parser.add_argument("--prompt_file", help="File containing prompts for batch mode (one per line)")
|
| 115 |
+
parser.add_argument("--output_file", help="Path to save JSON results (default: auto-generated)")
|
| 116 |
+
parser.add_argument("--max_tokens", type=int, default=512, help="Maximum tokens in response")
|
| 117 |
+
parser.add_argument("--temperature", type=float, default=0.7, help="Temperature for sampling")
|
| 118 |
+
parser.add_argument("--gpu_count", type=int, help="Number of GPUs to use (default: all available)")
|
| 119 |
+
parser.add_argument("--dtype", choices=["float16", "bfloat16", "float32"], default="bfloat16", help="Data type for weights")
|
| 120 |
+
parser.add_argument("--gpu_memory_utilization", type=float, default=0.85, help="GPU memory utilization (0.0-1.0)")
|
| 121 |
+
args = parser.parse_args()
|
| 122 |
+
|
| 123 |
+
# Initialize the model with specified GPU settings
|
| 124 |
+
llm = setup_model(
|
| 125 |
+
model_path=args.model_path,
|
| 126 |
+
tensor_parallel_size=args.gpu_count,
|
| 127 |
+
dtype=args.dtype,
|
| 128 |
+
gpu_memory_utilization=args.gpu_memory_utilization
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
results = {}
|
| 132 |
+
|
| 133 |
+
if args.mode == "single":
|
| 134 |
+
if not args.prompt:
|
| 135 |
+
args.prompt = input("Enter your prompt: ")
|
| 136 |
+
|
| 137 |
+
print("\nGenerating response...")
|
| 138 |
+
start_time = time.time()
|
| 139 |
+
response = generate_response(
|
| 140 |
+
llm,
|
| 141 |
+
args.prompt,
|
| 142 |
+
temperature=args.temperature,
|
| 143 |
+
max_tokens=args.max_tokens
|
| 144 |
+
)
|
| 145 |
+
end_time = time.time()
|
| 146 |
+
|
| 147 |
+
print(f"\nResponse:\n{response}")
|
| 148 |
+
|
| 149 |
+
results = {
|
| 150 |
+
"mode": "single",
|
| 151 |
+
"timestamp": datetime.datetime.now().isoformat(),
|
| 152 |
+
"input": args.prompt,
|
| 153 |
+
"output": response,
|
| 154 |
+
"parameters": {
|
| 155 |
+
"temperature": args.temperature,
|
| 156 |
+
"max_tokens": args.max_tokens
|
| 157 |
+
},
|
| 158 |
+
"performance": {
|
| 159 |
+
"time_seconds": end_time - start_time
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
elif args.mode == "chat":
|
| 164 |
+
# For chat mode, we'll save the entire conversation history
|
| 165 |
+
messages = [{"role": "system", "content": "You are a helpful AI assistant."}]
|
| 166 |
+
results = {
|
| 167 |
+
"mode": "chat",
|
| 168 |
+
"timestamp": datetime.datetime.now().isoformat(),
|
| 169 |
+
"conversation": []
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
print("\nChat mode. Type 'exit' or 'quit' to end the conversation and save to JSON.\n")
|
| 173 |
+
|
| 174 |
+
while True:
|
| 175 |
+
user_input = input("\nYou: ")
|
| 176 |
+
if user_input.lower() in ["exit", "quit"]:
|
| 177 |
+
print("Ending conversation and saving results...")
|
| 178 |
+
break
|
| 179 |
+
|
| 180 |
+
messages.append({"role": "user", "content": user_input})
|
| 181 |
+
|
| 182 |
+
start_time = time.time()
|
| 183 |
+
response = chat_completion(
|
| 184 |
+
llm,
|
| 185 |
+
messages,
|
| 186 |
+
temperature=args.temperature,
|
| 187 |
+
max_tokens=args.max_tokens
|
| 188 |
+
)
|
| 189 |
+
end_time = time.time()
|
| 190 |
+
|
| 191 |
+
print(f"\nAssistant: {response}")
|
| 192 |
+
messages.append({"role": "assistant", "content": response})
|
| 193 |
+
|
| 194 |
+
# Add this exchange to results
|
| 195 |
+
results["conversation"].append({
|
| 196 |
+
"user": user_input,
|
| 197 |
+
"assistant": response,
|
| 198 |
+
"time_seconds": end_time - start_time
|
| 199 |
+
})
|
| 200 |
+
|
| 201 |
+
elif args.mode == "batch":
|
| 202 |
+
if not args.prompt_file:
|
| 203 |
+
print("Error: --prompt_file required for batch mode")
|
| 204 |
+
return
|
| 205 |
+
with open(args.prompt_file, 'r', encoding='utf-8') as f:
|
| 206 |
+
prompts = json.load(f)
|
| 207 |
+
|
| 208 |
+
print(f"Running batch inference on {len(prompts)} prompts...")
|
| 209 |
+
inference_results = batch_inference(
|
| 210 |
+
llm,
|
| 211 |
+
prompts,
|
| 212 |
+
temperature=args.temperature,
|
| 213 |
+
max_tokens=args.max_tokens
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
with open(args.output_file, "w") as final:
|
| 217 |
+
json.dump(inference_results, final)
|
| 218 |
+
|
| 219 |
+
if __name__ == "__main__":
|
| 220 |
+
main()
|
inference_1.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from vllm import LLM, SamplingParams
|
| 2 |
+
import argparse
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
def setup_model(model_path):
|
| 6 |
+
"""
|
| 7 |
+
Initialize the fine-tuned Qwen-2.5-7B model from a local path.
|
| 8 |
+
|
| 9 |
+
Args:
|
| 10 |
+
model_path: Path to the directory containing the trained model
|
| 11 |
+
"""
|
| 12 |
+
print(f"Loading fine-tuned Qwen model from: {model_path}")
|
| 13 |
+
|
| 14 |
+
# Initialize the model with VLLM using local path
|
| 15 |
+
# trust_remote_code=True is required for custom Qwen model code
|
| 16 |
+
llm = LLM(
|
| 17 |
+
model=model_path,
|
| 18 |
+
trust_remote_code=True,
|
| 19 |
+
# Optional parameters for performance tuning
|
| 20 |
+
# tensor_parallel_size=2, # Use multiple GPUs
|
| 21 |
+
# dtype="bfloat16", # Use bfloat16 for more efficient inference
|
| 22 |
+
# gpu_memory_utilization=0.85 # Control memory usage
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
print("Model loaded successfully!")
|
| 26 |
+
return llm
|
| 27 |
+
|
| 28 |
+
def generate_response(llm, prompt, temperature=0.7, max_tokens=512, top_p=0.9):
|
| 29 |
+
"""Generate a response for a given prompt."""
|
| 30 |
+
sampling_params = SamplingParams(
|
| 31 |
+
temperature=temperature,
|
| 32 |
+
top_p=top_p,
|
| 33 |
+
max_tokens=max_tokens
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
outputs = llm.generate([prompt], sampling_params)
|
| 37 |
+
return outputs[0].outputs[0].text
|
| 38 |
+
|
| 39 |
+
def chat_completion(llm, messages, temperature=0.7, max_tokens=512):
|
| 40 |
+
"""Generate a chat completion from messages."""
|
| 41 |
+
sampling_params = SamplingParams(
|
| 42 |
+
temperature=temperature,
|
| 43 |
+
top_p=0.9,
|
| 44 |
+
max_tokens=max_tokens
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
# Convert messages to a prompt using the model's chat template
|
| 48 |
+
tokenizer = llm.get_tokenizer()
|
| 49 |
+
if hasattr(tokenizer, "apply_chat_template"):
|
| 50 |
+
# For newer transformers versions
|
| 51 |
+
prompt = tokenizer.apply_chat_template(
|
| 52 |
+
messages,
|
| 53 |
+
tokenize=False,
|
| 54 |
+
add_generation_prompt=True
|
| 55 |
+
)
|
| 56 |
+
else:
|
| 57 |
+
# Fallback for models without chat template
|
| 58 |
+
prompt = format_messages_manually(messages)
|
| 59 |
+
|
| 60 |
+
outputs = llm.generate([prompt], sampling_params)
|
| 61 |
+
return outputs[0].outputs[0].text
|
| 62 |
+
|
| 63 |
+
def format_messages_manually(messages):
|
| 64 |
+
"""Format messages manually if chat template is not available."""
|
| 65 |
+
formatted_prompt = ""
|
| 66 |
+
for message in messages:
|
| 67 |
+
role = message["role"]
|
| 68 |
+
content = message["content"]
|
| 69 |
+
if role == "system":
|
| 70 |
+
formatted_prompt += f"<|im_start|>system\n{content}<|im_end|>\n"
|
| 71 |
+
elif role == "user":
|
| 72 |
+
formatted_prompt += f"<|im_start|>user\n{content}<|im_end|>\n"
|
| 73 |
+
elif role == "assistant":
|
| 74 |
+
formatted_prompt += f"<|im_start|>assistant\n{content}<|im_end|>\n"
|
| 75 |
+
formatted_prompt += "<|im_start|>assistant\n"
|
| 76 |
+
return formatted_prompt
|
| 77 |
+
|
| 78 |
+
def batch_inference(llm, prompts, temperature=0.7, max_tokens=512):
|
| 79 |
+
"""Run batch inference on multiple prompts."""
|
| 80 |
+
sampling_params = SamplingParams(
|
| 81 |
+
temperature=temperature,
|
| 82 |
+
top_p=0.9,
|
| 83 |
+
max_tokens=max_tokens
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
outputs = llm.generate(prompts, sampling_params)
|
| 87 |
+
return [output.outputs[0].text for output in outputs]
|
| 88 |
+
|
| 89 |
+
def main():
|
| 90 |
+
parser = argparse.ArgumentParser(description="Inference with fine-tuned Qwen-2.5-7B model")
|
| 91 |
+
parser.add_argument("--model_path", required=True, help="Path to the fine-tuned model directory")
|
| 92 |
+
parser.add_argument("--mode", choices=["single", "chat", "batch"], default="single", help="Inference mode")
|
| 93 |
+
parser.add_argument("--prompt", help="Prompt for single inference mode")
|
| 94 |
+
parser.add_argument("--prompt_file", help="File containing prompts for batch mode (one per line)")
|
| 95 |
+
args = parser.parse_args()
|
| 96 |
+
|
| 97 |
+
# Initialize the model
|
| 98 |
+
llm = setup_model(args.model_path)
|
| 99 |
+
|
| 100 |
+
if args.mode == "single":
|
| 101 |
+
if not args.prompt:
|
| 102 |
+
args.prompt = input("Enter your prompt: ")
|
| 103 |
+
|
| 104 |
+
print("\nGenerating response...")
|
| 105 |
+
response = generate_response(llm, args.prompt)
|
| 106 |
+
print(f"\nResponse:\n{response}")
|
| 107 |
+
|
| 108 |
+
elif args.mode == "chat":
|
| 109 |
+
messages = [{"role": "system", "content": "You are a helpful AI assistant."}]
|
| 110 |
+
print("\nChat mode. Type 'exit' or 'quit' to end the conversation.\n")
|
| 111 |
+
|
| 112 |
+
while True:
|
| 113 |
+
user_input = input("\nYou: ")
|
| 114 |
+
if user_input.lower() in ["exit", "quit"]:
|
| 115 |
+
print("Goodbye!")
|
| 116 |
+
break
|
| 117 |
+
|
| 118 |
+
messages.append({"role": "user", "content": user_input})
|
| 119 |
+
response = chat_completion(llm, messages)
|
| 120 |
+
|
| 121 |
+
print(f"\nAssistant: {response}")
|
| 122 |
+
messages.append({"role": "assistant", "content": response})
|
| 123 |
+
|
| 124 |
+
elif args.mode == "batch":
|
| 125 |
+
if not args.prompt_file:
|
| 126 |
+
print("Error: --prompt_file required for batch mode")
|
| 127 |
+
return
|
| 128 |
+
|
| 129 |
+
with open(args.prompt_file, 'r') as f:
|
| 130 |
+
prompts = [line.strip() for line in f if line.strip()]
|
| 131 |
+
|
| 132 |
+
print(f"Running batch inference on {len(prompts)} prompts...")
|
| 133 |
+
responses = batch_inference(llm, prompts)
|
| 134 |
+
|
| 135 |
+
with open("./test.json", "w") as final:
|
| 136 |
+
json.dump(responses, final)
|
| 137 |
+
|
| 138 |
+
if __name__ == "__main__":
|
| 139 |
+
main()
|
test_sft_nothink_10.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
"<|im_start|>system\nYou are a helpful assistant. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning process and answer are enclosed within <think> </think> and <answer> </answer> tags, respectively, i.e., <think> reasoning process here </think> <answer> answer here </answer>. Now the user gives an instruction that describes a task and ask you write an answer that appropriately completes the request. After thinking, when you finally reach a conclusion, clearly state the answer within <answer> </answer> tags.\n<|im_end|>\n<|im_start|>user\nInstruction: Evaluate the titles of Product 1 and Product 2 to assess their similarity and whether they are likely to be purchased or viewed together. Then, select the appropriate option.\n\nInput:\nProduct 1: Cerwin-Vega XED52 Speaker 275 W PMPO 2-Way, 2 Count, Black\nProduct 2: Rockford R169X2 6 x 9 Inches Full Range Coaxial Speaker, Set of 2\n\nOptions:\nA: Users who buy product 1 may also buy product 2.\nB: Users who view product 1 may also view product 2.\nC: The product 1 is similar with the product 2.\n<|im_end|>\n<|im_start|>assistant\n<think>Okay, I think I have finished thinking.</think>",
|
| 3 |
+
"<|im_start|>system\nYou are a helpful assistant. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning process and answer are enclosed within <think> </think> and <answer> </answer> tags, respectively, i.e., <think> reasoning process here </think> <answer> answer here </answer>. Now the user gives an instruction that describes a task and ask you write an answer that appropriately completes the request. After thinking, when you finally reach a conclusion, clearly state the answer within <answer> </answer> tags.\n<|im_end|>\n<|im_start|>user\nInstruction: Given the title of two products, predict if the two products are similar, if the two products will be purchased or viewed together. Answer only from the options.\n\nInput:\nProduct 1: Kenable Internal Memory Card Reader for 5.25 CD/DVD Bay With USB Port BLACK\nProduct 2: CORSAIR Carbide 100R Mid-Tower Case\n\nOptions:\nA: Users who buy product 1 may also buy product 2.\nB: Users who view product 1 may also view product 2.\nC: The product 1 is similar with the product 2.\n<|im_end|>\n<|im_start|>assistant\n<think>Okay, I think I have finished thinking.</think>",
|
| 4 |
+
"<|im_start|>system\nYou are a helpful assistant. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning process and answer are enclosed within <think> </think> and <answer> </answer> tags, respectively, i.e., <think> reasoning process here </think> <answer> answer here </answer>. Now the user gives an instruction that describes a task and ask you write an answer that appropriately completes the request. After thinking, when you finally reach a conclusion, clearly state the answer within <answer> </answer> tags.\n<|im_end|>\n<|im_start|>user\nInstruction: Analyze the titles of Product 1 and Product 2 to determine if they are similar, if they will be purchased or viewed together, and choose the corresponding option.\n\nInput:\nProduct 1: Master Half Dozen Red Pool Cue Chalk\nProduct 2: Premium Pool Table Billiard Cue Chalk 12 Pieces Choose Blue, Green, Black, Purple, Pink, Hot Pink, or Mustard\n\nOptions:\nA: Users who buy product 1 may also buy product 2.\nB: Users who view product 1 may also view product 2.\nC: The product 1 is similar with the product 2.\n<|im_end|>\n<|im_start|>assistant\n<think>Okay, I think I have finished thinking.</think>",
|
| 5 |
+
"<|im_start|>system\nYou are a helpful assistant. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning process and answer are enclosed within <think> </think> and <answer> </answer> tags, respectively, i.e., <think> reasoning process here </think> <answer> answer here </answer>. Now the user gives an instruction that describes a task and ask you write an answer that appropriately completes the request. After thinking, when you finally reach a conclusion, clearly state the answer within <answer> </answer> tags.\n<|im_end|>\n<|im_start|>user\nInstruction: Evaluate the titles of Product 1 and Product 2 to assess their similarity and whether they are likely to be purchased or viewed together. Then, select the appropriate option.\n\nInput:\nProduct 1: Mossy Oak Full Spandex Face Mask\nProduct 2: Scent Control Spray - Remington Hunting Odor Elimination Spray - 24 oz\n\nOptions:\nA: Users who buy product 1 may also buy product 2.\nB: Users who view product 1 may also view product 2.\nC: The product 1 is similar with the product 2.\n<|im_end|>\n<|im_start|>assistant\n<think>Okay, I think I have finished thinking.</think>",
|
| 6 |
+
"<|im_start|>system\nYou are a helpful assistant. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning process and answer are enclosed within <think> </think> and <answer> </answer> tags, respectively, i.e., <think> reasoning process here </think> <answer> answer here </answer>. Now the user gives an instruction that describes a task and ask you write an answer that appropriately completes the request. After thinking, when you finally reach a conclusion, clearly state the answer within <answer> </answer> tags.\n<|im_end|>\n<|im_start|>user\nInstruction: Predict whether two products are similar, whether two products are likely to be purchased or viewed together based on their titles. Choose your answer from the provided options.\n\nInput:\nProduct 1: Monoprice 11952 Polyurethane Replacement Ear Pads for PID 8323 type Headphones - Red\nProduct 2: Monoprice Hi-Fi Light Weight Over the Ear Headphones - Black with a 50mm driver and a 47in 3.5mm cable for Apple Iphone iPod Android Smartphone Samsung Galaxy Tablets MP3\n\nOptions:\nA: Users who buy product 1 may also buy product 2.\nB: Users who view product 1 may also view product 2.\nC: The product 1 is similar with the product 2.\n<|im_end|>\n<|im_start|>assistant\n<think>Okay, I think I have finished thinking.</think>",
|
| 7 |
+
"<|im_start|>system\nYou are a helpful assistant. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning process and answer are enclosed within <think> </think> and <answer> </answer> tags, respectively, i.e., <think> reasoning process here </think> <answer> answer here </answer>. Now the user gives an instruction that describes a task and ask you write an answer that appropriately completes the request. After thinking, when you finally reach a conclusion, clearly state the answer within <answer> </answer> tags.\n<|im_end|>\n<|im_start|>user\nInstruction: Analyze the titles of Product 1 and Product 2 to determine if they are similar, if they will be purchased or viewed together, and choose the corresponding option.\n\nInput:\nProduct 1: Coleman Twin High Performance LED Lantern\nProduct 2: Coleman Twin LED Lantern\n\nOptions:\nA: Users who buy product 1 may also buy product 2.\nB: Users who view product 1 may also view product 2.\nC: The product 1 is similar with the product 2.\n<|im_end|>\n<|im_start|>assistant\n<think>Okay, I think I have finished thinking.</think>",
|
| 8 |
+
"<|im_start|>system\nYou are a helpful assistant. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning process and answer are enclosed within <think> </think> and <answer> </answer> tags, respectively, i.e., <think> reasoning process here </think> <answer> answer here </answer>. Now the user gives an instruction that describes a task and ask you write an answer that appropriately completes the request. After thinking, when you finally reach a conclusion, clearly state the answer within <answer> </answer> tags.\n<|im_end|>\n<|im_start|>user\nInstruction: Evaluate the titles of Product 1 and Product 2 to assess their similarity and whether they are likely to be purchased or viewed together. Then, select the appropriate option.\n\nInput:\nProduct 1: TOOGOO(R) Pocket Pen Fishing Rod + 4.3:1 Spinning Reel Tackle Set\nProduct 2: Zebco Zcast 5'6" 2Piece Medium-Light Action Rod Casting\n\nOptions:\nA: Users who buy product 1 may also buy product 2.\nB: Users who view product 1 may also view product 2.\nC: The product 1 is similar with the product 2.\n<|im_end|>\n<|im_start|>assistant\n<think>Okay, I think I have finished thinking.</think>",
|
| 9 |
+
"<|im_start|>system\nYou are a helpful assistant. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning process and answer are enclosed within <think> </think> and <answer> </answer> tags, respectively, i.e., <think> reasoning process here </think> <answer> answer here </answer>. Now the user gives an instruction that describes a task and ask you write an answer that appropriately completes the request. After thinking, when you finally reach a conclusion, clearly state the answer within <answer> </answer> tags.\n<|im_end|>\n<|im_start|>user\nInstruction: Evaluate the titles of Product 1 and Product 2 to assess their similarity and whether they are likely to be purchased or viewed together. Then, select the appropriate option.\n\nInput:\nProduct 1: Hiware 12-piece Good Stainless Steel Teaspoon, 6.7 Inches\nProduct 2: Winco 0001-06 12-Piece Dominion Salad Fork Set, 18-0 Stainless Steel\n\nOptions:\nA: Users who buy product 1 may also buy product 2.\nB: Users who view product 1 may also view product 2.\nC: The product 1 is similar with the product 2.\n<|im_end|>\n<|im_start|>assistant\n<think>Okay, I think I have finished thinking.</think>",
|
| 10 |
+
"<|im_start|>system\nYou are a helpful assistant. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning process and answer are enclosed within <think> </think> and <answer> </answer> tags, respectively, i.e., <think> reasoning process here </think> <answer> answer here </answer>. Now the user gives an instruction that describes a task and ask you write an answer that appropriately completes the request. After thinking, when you finally reach a conclusion, clearly state the answer within <answer> </answer> tags.\n<|im_end|>\n<|im_start|>user\nInstruction: Evaluate the titles of Product 1 and Product 2 to assess their similarity and whether they are likely to be purchased or viewed together. Then, select the appropriate option.\n\nInput:\nProduct 1: 55mm Wide Angle Lens for Nikon D3400 with 18-55MM AF-P DX , D5600 with 18-55MM AF-P DX, DL24-500, DL 24-500MM Digital Camera\nProduct 2: Powerextra EN-EL14 EN-EL14a 2 x Battery & Car Charger Compatible with Nikon D3100 D3200 D3300 D3400 D3500 D5100 D5200 D5300 D5500 D5600 P7000 P7100 P7200 P7700 P7800 DSLR Cameras\n\nOptions:\nA: Users who buy product 1 may also buy product 2.\nB: Users who view product 1 may also view product 2.\nC: The product 1 is similar with the product 2.\n<|im_end|>\n<|im_start|>assistant\n<think>Okay, I think I have finished thinking.</think>",
|
| 11 |
+
"<|im_start|>system\nYou are a helpful assistant. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning process and answer are enclosed within <think> </think> and <answer> </answer> tags, respectively, i.e., <think> reasoning process here </think> <answer> answer here </answer>. Now the user gives an instruction that describes a task and ask you write an answer that appropriately completes the request. After thinking, when you finally reach a conclusion, clearly state the answer within <answer> </answer> tags.\n<|im_end|>\n<|im_start|>user\nInstruction: Given the title of two products, predict if the two products are similar, if the two products will be purchased or viewed together. Answer only from the options.\n\nInput:\nProduct 1: Sticky Holsters MD-2 Medium\nProduct 2: TRUGLO TFX PRO Tritium & Fiber-Optic Xtreme Handgun Sights, Ruger LC Set (TG13RS2PC)\n\nOptions:\nA: Users who buy product 1 may also buy product 2.\nB: Users who view product 1 may also view product 2.\nC: The product 1 is similar with the product 2.\n<|im_end|>\n<|im_start|>assistant\n<think>Okay, I think I have finished thinking.</think>"
|
| 12 |
+
]
|