Views
No views yet
<|start_header_id|>system<|end_header_id|>
You are focused on providing systematic, well-reasoned responses. Response Structure: - Format: <think>{{reasoning}}</think>{{answer}} - Reasoning: Minimum 6 logical steps only when it required in <think> block - Process: Think first, then answer.
You are a helpful AI assistant named Llama, made by Meta AI.
<|eot_id|><|start_header_id|>user<|end_header_id|>
How many r's are in strawberry?<|eot_id|><|start_header_id|>assistant<|end_header_id|><think>1# test the model
2import torch
3from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer
4
5def main():
6 model_id = "CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1"
7
8 # Load the tokenizer.
9 tokenizer = AutoTokenizer.from_pretrained(model_id, add_eos_token=True)
10
11 # Load the model using bitsandbytes 8-bit quantization if CUDA is available.
12 if torch.cuda.is_available():
13 model = AutoModelForCausalLM.from_pretrained(
14 model_id,
15 load_in_8bit=True,
16 device_map="auto"
17 )
18 device = torch.device("cuda")
19 else:
20 model = AutoModelForCausalLM.from_pretrained(model_id)
21 device = torch.device("cpu")
22
23 # Define the generation parameters.
24 generation_kwargs = {
25 "max_new_tokens": 2048,
26 "do_sample": True,
27 "temperature": 0.5,
28 "top_p": 0.9,
29 "repetition_penalty": 1.1,
30 "num_return_sequences": 1,
31 "forced_eos_token_id": tokenizer.eos_token_id,
32 "pad_token_id": tokenizer.eos_token_id
33 }
34
35 print("Enter your prompt (type 'exit' to quit):")
36 while True:
37 # Get user input.
38 user_input = input("Input> ")
39 if user_input.lower().strip() in ("exit", "quit"):
40 break
41
42 # Construct the prompt in your desired format.
43 prompt = f"""
44<|start_header_id|>system<|end_header_id|>
45You are focused on providing systematic, well-reasoned responses. Response Structure: - Format: <think>{{reasoning}}</think>{{answer}} - Reasoning: Minimum 6 logical steps only when it required in <think> block - Process: Think first, then answer.
46
47You are a helpful AI assistant named Llama, made by Meta AI.
48<|eot_id|><|start_header_id|>user<|end_header_id|>
49
50How many r's are in strawberry?<|eot_id|><|start_header_id|>assistant<|end_header_id|><think>
51"""
52
53 # Tokenize the prompt and send to the selected device.
54 input_ids = tokenizer.encode(prompt, return_tensors="pt", add_special_tokens=True).to(device)
55
56 # Create a new TextStreamer instance for streaming responses.
57 streamer = TextStreamer(tokenizer)
58 generation_kwargs["streamer"] = streamer
59
60 print("\nAssistant Response:")
61 # Generate the text (tokens will stream to stdout via the streamer).
62 outputs = model.generate(input_ids, **generation_kwargs)
63
64if __name__ == "__main__":
65 main()1import torch
2from transformers import pipeline
3
4model_id = "CreitinGameplays/Llama-3.2-3B-Instruct-R1-v1"
5
6pipe = pipeline(
7 "text-generation",
8 model=model_id,
9 torch_dtype=torch.bfloat16,
10 device_map="auto"
11)
12
13messages = [{"role": "user", "content": "hello there!"}]
14
15outputs = pipe(
16 messages,
17 temperature=0.5,
18 repetition_penalty=1.1,
19 max_new_tokens=2048
20)
21
22print(outputs[0]["generated_text"][-1])