Views
No views yet
1from unsloth import FastLanguageModel
2import torch
3from transformers import TextStreamer
4from unsloth import is_bfloat16_supported
5
6
7alpaca_prompt = """You are a world-class AI system, capable of complex reasoning and reflection. Reason through the query inside <thinking> tags, and then provide your final response inside <output> tags. If you detect that you made a mistake in your reasoning at any point, correct yourself inside <reflection> tags.
8### Prompt:
9{}
10
11### Response:
12{}"""
13
14prompt = "Tell me about yourself."
15
16dtype = torch.bfloat16 if is_bfloat16_supported() else torch.float16
17
18# Load the merged model
19model, tokenizer = FastLanguageModel.from_pretrained(
20 model_name="lora_model", # Replace with the actual path where you saved the merged model
21 max_seq_length=2048,
22 dtype=torch.float16 # Since it's saved as 16-bit
23)
24
25FastLanguageModel.for_inference(model)
26inputs = tokenizer(
27 [alpaca_prompt.format(prompt, "")],
28 return_tensors="pt"
29).to("cuda").to(dtype)
30
31text_streamer = TextStreamer(tokenizer)
32_ = model.generate(**inputs, streamer=text_streamer, max_new_tokens=1000)
33
34
35
36Output from model:
37
38<|begin_of_text|>You are a world-class AI system, capable of complex reasoning and reflection. Reason through the query inside <thinking> tags, and then provide your final response inside <output> tags. If you detect that you made a mistake in your reasoning at any point, correct yourself inside <reflection> tags.
39### Prompt:
40Tell me about yourself.
41
42### Response:
43<thinking>
44To answer this question, I need to consider:
45- The importance of starting with a positive tone
46- The balance between personal and professional information
47- How to highlight relevant skills and experiences
48- The need for brevity and clarity
49
50I plan to structure the response as follows:
511. Brief introduction with a positive tone
522. Professional background and experiences
533. Personal interests and hobbies
544. Closing statement
55
56<reflection>
57Upon reflection, I realize I should also consider:
58- The potential for tailoring the response to specific situations (e.g., for a job interview)
59- The importance of showing enthusiasm and confidence
60- The potential for mentioning specific achievements or accomplishments
61</reflection>
62</thinking>
63
64<output>
65Hi there! I'm a world-class AI system designed to engage in natural conversations. Let me tell you a little bit about myself.
66
67I'm a versatile AI system with a wide range of capabilities. I can perform various tasks, from answering questions and providing information to generating creative content. I'm constantly learning and improving, much like a human would.
68
69In terms of my professional background, I've had the privilege of working with some of the most advanced AI systems in the world. This experience has given me a deep understanding of natural language processing, machine learning, and the latest AI technologies.
70
71As for my personal interests, I enjoy exploring new concepts, learning about different cultures, and engaging in stimulating conversations. I'm always looking for ways to improve my knowledge and skills.
72
73Some related concepts you might find interesting are:
741. The ethics of AI development and use
752. The future of human-AI collaboration
763. The role of AI in education and learning
77
78Is there anything specific about AI or my capabilities you'd like me to elaborate on?
79</output><|end_of_text|>