Views
No views yet

Instruction:\t{system_message}
Conversation:
'user1':\tuser message to analyse
'user2':\tuser message to analyse
Response:
apache-2.0, and this quantization has therefore used that same license.TheBloke/merlyn-education-corpus-qa-v2-AWQ.merlyn-education-corpus-qa-v2-AWQ--quantization awq parameter.python3 -m vllm.entrypoints.api_server --model TheBloke/merlyn-education-corpus-qa-v2-AWQ --quantization awq --dtype autoquantization=awq.1from vllm import LLM, SamplingParams
2
3prompts = [
4 "Tell me about AI",
5 "Write a story about llamas",
6 "What is 291 - 150?",
7 "How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
8]
9prompt_template=f'''Instruction:\t{system_message}
10Conversation:
11'user1':\tuser message to analyse
12'user2':\tuser message to analyse
13Response:
14'''
15
16prompts = [prompt_template.format(prompt=prompt) for prompt in prompts]
17
18sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
19
20llm = LLM(model="TheBloke/merlyn-education-corpus-qa-v2-AWQ", quantization="awq", dtype="auto")
21
22outputs = llm.generate(prompts, sampling_params)
23
24# Print the outputs.
25for output in outputs:
26 prompt = output.prompt
27 generated_text = output.outputs[0].text
28 print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")ghcr.io/huggingface/text-generation-inference:1.1.0--model-id TheBloke/merlyn-education-corpus-qa-v2-AWQ --port 3000 --quantize awq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096pip3 install huggingface-hub1from huggingface_hub import InferenceClient
2
3endpoint_url = "https://your-endpoint-url-here"
4
5prompt = "Tell me about AI"
6prompt_template=f'''Instruction:\t{system_message}
7Conversation:
8'user1':\tuser message to analyse
9'user2':\tuser message to analyse
10Response:
11'''
12
13client = InferenceClient(endpoint_url)
14response = client.text_generation(prompt,
15 max_new_tokens=128,
16 do_sample=True,
17 temperature=0.7,
18 top_p=0.95,
19 top_k=40,
20 repetition_penalty=1.1)
21
22print(f"Model output: ", response)pip3 install --upgrade "autoawq>=0.1.6" "transformers>=4.35.0"pip3 install https://github.com/casper-hansen/AutoAWQ/releases/download/v0.1.6/autoawq-0.1.6+cu118-cp310-cp310-linux_x86_64.whl1pip3 uninstall -y autoawq
2git clone https://github.com/casper-hansen/AutoAWQ
3cd AutoAWQ
4pip3 install .1from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
2
3model_name_or_path = "TheBloke/merlyn-education-corpus-qa-v2-AWQ"
4
5tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
6model = AutoModelForCausalLM.from_pretrained(
7 model_name_or_path,
8 low_cpu_mem_usage=True,
9 device_map="cuda:0"
10)
11
12# Using the text streamer to stream output one token at a time
13streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
14
15prompt = "Tell me about AI"
16prompt_template=f'''Instruction:\t{system_message}
17Conversation:
18'user1':\tuser message to analyse
19'user2':\tuser message to analyse
20Response:
21'''
22
23# Convert prompt to tokens
24tokens = tokenizer(
25 prompt_template,
26 return_tensors='pt'
27).input_ids.cuda()
28
29generation_params = {
30 "do_sample": True,
31 "temperature": 0.7,
32 "top_p": 0.95,
33 "top_k": 40,
34 "max_new_tokens": 512,
35 "repetition_penalty": 1.1
36}
37
38# Generate streamed output, visible one token at a time
39generation_output = model.generate(
40 tokens,
41 streamer=streamer,
42 **generation_params
43)
44
45# Generation without a streamer, which will include the prompt in the output
46generation_output = model.generate(
47 tokens,
48 **generation_params
49)
50
51# Get the tokens from the output, decode them, print them
52token_output = generation_output[0]
53text_output = tokenizer.decode(token_output)
54print("model.generate output: ", text_output)
55
56# Inference is also possible via Transformers' pipeline
57from transformers import pipeline
58
59pipe = pipeline(
60 "text-generation",
61 model=model,
62 tokenizer=tokenizer,
63 **generation_params
64)
65
66pipe_output = pipe(prompt_template)[0]['generated_text']
67print("pipeline output: ", pipe_output)
68Loader: AutoAWQ.1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_path = "MerlynMind/merlyn-education-corpus-qa-v2"
5device = torch.device("cuda:0") # change device id as necessary
6model = AutoModelForCausalLM.from_pretrained(model_path)
7tokenizer = AutoTokenizer.from_pretrained(model_path, fast_tokenizer=True)
8model.to(device) # move to device
91info = '''Information:\tThe Solar System is about 4.6 billion years old. The Sun formed by gravity in a large molecular cloud. It is mainly hydrogen, which it converts into helium.
2Information:\tThe formation and evolution of the Solar System began 4.6 billion years ago with the gravitational collapse of a small part of a giant molecular cloud.
3Information:\tAstronomers are now more or less certain that the order of the planets was not always as it is today. Knowing what we know today, we can see the Solar System is strange. All other planetary system we are able to study have their largest planet close to their star. Also we have noticed other oddities in the Solar System. Mars is smaller than it ought to be, and the asteroid belt has been disturbed.
4Information:\tFor thousands of years, people had no need for a name for the "Solar System". They thought the Earth stayed still at the center of everything (geocentrism). The Greek philosopher Aristarchus of Samos suggested that there was a special order in the sky. Nicolaus Copernicus was the first to develop a mathematical system that described what we now call the "Solar System". This was called a "new system of the world". In the 17th century, Galileo Galilei, Johannes Kepler and Isaac Newton began to understand physics more clearly. People began to accept the idea that the Earth is a planet that moves around the Sun, and that the planets are worlds, and that all worlds are governed by the same same physical laws. More recently, telescopes and space probes sometimes let us see details directly. All inner planets have surface features. The gas giants (as the name suggests) have surfaces whose make-up is gradually being discovered.
5Information:\tThere are eight planets in the Solar System. From closest to farthest from the Sun, they are: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus and Neptune. The first four planets are called terrestrial planets. They are mostly made of rock and metal, and they are mostly solid. The last four planets are called gas giants. This is because they are much larger than other planets and are mostly made of gas.
6'''
7qs = "Question:\tHow old is the Solar System?"
8
9prompt = tokenizer.bos_token
10prompt += '''Instruction:\tYou are to try to answer the following question using only the pieces of information given.
11Instruction:\tYour response should be a well formed JSON object with an 'answerable' property followed by an 'answer' property.
12Instruction:\tIf you cannot answer the question given the information, the value of the 'answerable' should be 'false' and the 'answer' should be an empty string.
13Instruction:\tIf you can answer the question given the information, the value of the 'answerable' should be 'true' and your answer should be the string value of the 'answer' property.
14''' + info + qs + " Response:"
151from transformers import StoppingCriteria, StoppingCriteriaList
2
3eos_tokens = [tokenizer.eos_token,'\n']
4eos_token_ids = [tokenizer.encode(token)[0] for token in eos_tokens]
5
6class MultipleEOSTokensStoppingCriteria(StoppingCriteria):
7 def __init__(self, eos_token_ids):
8 self.eos_token_ids = set(eos_token_ids)
9 def __call__(self, input_ids, scores) -> bool:
10 if input_ids.shape[-1] <= 1:
11 return False
12 for eos_token_id in self.eos_token_ids:
13 if eos_token_id == input_ids[0, -1].item():
14 return True
15 return False
16
17# Define stopping criteria
18multiple_eos_tokens_processor = MultipleEOSTokensStoppingCriteria(eos_token_ids)
19stopping_criteria = StoppingCriteriaList([multiple_eos_tokens_processor])1inputs = tokenizer(prompt, return_tensors="pt", return_token_type_ids=False).to(device)
2generate_ids = model.generate(
3 **inputs,
4 max_new_tokens=1024,
5 temperature=0.0,
6 num_beams=2,
7 top_p=1,
8 stopping_criteria=stopping_criteria
9)
10response = tokenizer.decode(generate_ids[0],
11 skip_special_tokens=True,
12 clean_up_tokenization_spaces=True)[{"answerable": "true", "answer": "4.6 billion years"}]