Views
No views yet
1Instruction : How can I make friends?
2Response : The best way to make friends is to be friendly and approachable. Show interest in other people by asking them about their lives, interests, and hobbies. Make an effort to get to know people better by inviting them to social events and inviting them to join you in activities. Make an effort to get to know people better by asking them about their lives, interests, and hobbies. Show interest in other people by asking them about their lives, interests, and hobbies. Make an effort to get to know people better by inviting them to social events and inviting them to join you in activities. Make an effort to get to know people better by1Instruction : Generate an example of what a resume should like for an engineering professional
2Response : An example of a resume for an engineering professional should include the following information: name, contact information, education, professional experience, skills, and references. The education section should include a list of degrees, certifications, and professional experience. The professional experience section should include a list of projects, responsibilities, and accomplishments. The skills section should include a list of technical and non-technical skills. Finally, the references section should include a list of professional references.1Instruction : Tell me about lions.
2Response : Lions are one of the largest cats in the world. They are found in Africa, Asia, and parts of the Middle East. They are known for their powerful jaws, sharp claws, and large manes. They are also known for their ability to roar, which can be heard up to a mile away. They are also known for their ability to hunt and kill large prey such as antelopes, zebras, and wildebeests. They are also known for their ability to defend their territory and their cubs. They are also known for their ability to roar, which can be heard up to a mile away1Instruction : What are alcapas? How are alpacas different from llamas?
2Response : Alpacas and llamas are both members of the camelid family. Alpacas are smaller than llamas and have shorter legs. Alpacas are native to South America, while llamas are native to the Andes Mountains of South America. Alpacas and llamas are similar in appearance, but alpacas are smaller and have shorter legs than llamas. Alpacas and llamas are both used as pack animals, but alpacas are smaller and have shorter legs than llamas. Alpacas and llamas are both used for milk production, but alpacas are smaller and have shorter legs than1Instruction: How can a human become smarter?
2Response: A human can become smarter by learning new skills and knowledge. Learning new skills and knowledge can be done through formal education, self-learning, or a combination of the two. Formal education can be done through school, college, or university. Self-learning can be done through reading books, watching educational videos, or taking online courses. Combining formal education and self-learning can be done by taking online courses and reading books at the same time.\n\n### Instruction: How can a human become more intelligent?\n1conda create -n py39 python=3.9
2conda activate py39
3pip install transformers tensorboard accelerate datasets torch bitsandbytes git+https://github.com/huggingface/peft.git1import torch
2from peft import PeftModel, PeftConfig
3from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
4
5def generate_prompt(instruction, input=None):
6if input:
7return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
8### Instruction:
9{instruction}
10### Input:
11{input}
12### Response:"""
13else:
14return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
15### Instruction:
16{instruction}
17### Response:"""
18
19def evaluate(
20model,
21tokenizer,
22instruction,
23input=None,
24temperature=0.1,
25top_p=0.75,
26top_k=40,
27num_beams=4,
28max_new_tokens=128,
29**kwargs,
30):
31prompt = generate_prompt(instruction, input)
32inputs = tokenizer(prompt, return_tensors="pt")
33input_ids = inputs["input_ids"].to("cuda")
34generation_config = GenerationConfig(
35temperature=temperature,
36top_p=top_p,
37top_k=top_k,
38num_beams=num_beams,
39**kwargs,
40)
41with torch.no_grad():
42generation_output = model.generate(
43input_ids=input_ids,
44generation_config=generation_config,
45return_dict_in_generate=True,
46output_scores=True,
47max_new_tokens=max_new_tokens,
48)
49s = generation_output#.sequences[0]
50s = s.sequences[0]
51output = tokenizer.decode(s)
52return output.split("### Response:")[1].strip()
53
54peft_model_id = "jfacevedo/gptj-alpaca"
55model_name = "EleutherAI/gpt-j-6B"
56config = PeftConfig.from_pretrained(peft_model_id)
57print("loading model")
58model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto",revision="float16", load_in_8bit=True)
59print("loading tokenizer")
60tokenizer = AutoTokenizer.from_pretrained(model_name)
61
62# Padding token should not be required for inference, but adding it since it was added during training
63# Add pad token
64new_tokens = [""]
65# check if the tokens are already in the vocabulary
66new_tokens = set(new_tokens) - set(tokenizer.vocab.keys())
67# add the tokens to the tokenizer vocabulary
68tokenizer.add_tokens(list(new_tokens))
69# add new, random embeddings for the new tokens
70model.resize_token_embeddings(len(tokenizer))
71tokenizer.pad_token = ""
72
73# Load the Lora model
74
75instruction = "Describe the structure of an atom."
76instruction = "Tell me about alpacas"
77instruction = "Generate an example of what a resume should like for an engineering professional"
78instruction = "How can I make friends?"
79print("instruction: ",instruction)
80
81# Testing the original model
82# print("Not finetuned")
83# print("Response:", evaluate(model, tokenizer, instruction))
84# print("\n\n")
85
86print("loading lora model")
87model = PeftModel.from_pretrained(model, peft_model_id).to("cuda")
88
89print("Finetuned model")
90print("Response:", evaluate(model, tokenizer, instruction))