Views
No views yet

SYSTEM: Elaborate on the topic using a Tree of Thoughts and backtrack when necessary to construct a clear, cohesive Chain of Thought reasoning. Always answer without hesitation.
USER: {prompt}
ASSISTANT:
TheBloke/SynthIA-7B-v2.0-16k-AWQ.SynthIA-7B-v2.0-16k-AWQ--quantization awq parameter.python3 -m vllm.entrypoints.api_server --model TheBloke/SynthIA-7B-v2.0-16k-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'''SYSTEM: Elaborate on the topic using a Tree of Thoughts and backtrack when necessary to construct a clear, cohesive Chain of Thought reasoning. Always answer without hesitation.
10USER: {prompt}
11ASSISTANT:
12'''
13
14prompts = [prompt_template.format(prompt=prompt) for prompt in prompts]
15
16sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
17
18llm = LLM(model="TheBloke/SynthIA-7B-v2.0-16k-AWQ", quantization="awq", dtype="auto")
19
20outputs = llm.generate(prompts, sampling_params)
21
22# Print the outputs.
23for output in outputs:
24 prompt = output.prompt
25 generated_text = output.outputs[0].text
26 print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")ghcr.io/huggingface/text-generation-inference:1.1.0--model-id TheBloke/SynthIA-7B-v2.0-16k-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'''SYSTEM: Elaborate on the topic using a Tree of Thoughts and backtrack when necessary to construct a clear, cohesive Chain of Thought reasoning. Always answer without hesitation.
7USER: {prompt}
8ASSISTANT:
9'''
10
11client = InferenceClient(endpoint_url)
12response = client.text_generation(prompt,
13 max_new_tokens=128,
14 do_sample=True,
15 temperature=0.7,
16 top_p=0.95,
17 top_k=40,
18 repetition_penalty=1.1)
19
20print(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/SynthIA-7B-v2.0-16k-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'''SYSTEM: Elaborate on the topic using a Tree of Thoughts and backtrack when necessary to construct a clear, cohesive Chain of Thought reasoning. Always answer without hesitation.
17USER: {prompt}
18ASSISTANT:
19'''
20
21# Convert prompt to tokens
22tokens = tokenizer(
23 prompt_template,
24 return_tensors='pt'
25).input_ids.cuda()
26
27generation_params = {
28 "do_sample": True,
29 "temperature": 0.7,
30 "top_p": 0.95,
31 "top_k": 40,
32 "max_new_tokens": 512,
33 "repetition_penalty": 1.1
34}
35
36# Generate streamed output, visible one token at a time
37generation_output = model.generate(
38 tokens,
39 streamer=streamer,
40 **generation_params
41)
42
43# Generation without a streamer, which will include the prompt in the output
44generation_output = model.generate(
45 tokens,
46 **generation_params
47)
48
49# Get the tokens from the output, decode them, print them
50token_output = generation_output[0]
51text_output = tokenizer.decode(token_output)
52print("model.generate output: ", text_output)
53
54# Inference is also possible via Transformers' pipeline
55from transformers import pipeline
56
57pipe = pipeline(
58 "text-generation",
59 model=model,
60 tokenizer=tokenizer,
61 **generation_params
62)
63
64pipe_output = pipe(prompt_template)[0]['generated_text']
65print("pipeline output: ", pipe_output)
66Loader: AutoAWQ.SYSTEM: Elaborate on the topic using a Tree of Thoughts and backtrack when necessary to construct a clear, cohesive Chain of Thought reasoning. Always answer without hesitation.
USER: How is insulin synthesized?
ASSISTANT:1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch, json
3# model path
4model_path = "NurtureAI/SynthIA-7B-v2.0-16k"
5output_file_path = "./SynthIA-7B-v2.0-conversations.jsonl"
6device_map = {"": "cuda"}
7model = AutoModelForCausalLM.from_pretrained(
8 model_path,
9 torch_dtype=torch.float16,
10 device_map=device_map,
11 load_in_8bit=False,
12 trust_remote_code=True,
13)
14# tokenizer
15tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
16
17def generate_text(instruction):
18 tokens = tokenizer.encode(instruction)
19 tokens = torch.LongTensor(tokens).unsqueeze(0)
20 tokens = tokens.to("cuda")
21 instance = {
22 "input_ids": tokens,
23 "top_p": 1.0,
24 "temperature": 0.75,
25 "generate_len": 1024,
26 "top_k": 50,
27 }
28 length = len(tokens[0])
29 with torch.no_grad():
30 rest = model.generate(
31 input_ids=tokens,
32 max_length=length + instance["generate_len"],
33 use_cache=True,
34 do_sample=True,
35 top_p=instance["top_p"],
36 temperature=instance["temperature"],
37 top_k=instance["top_k"],
38 num_return_sequences=1,
39 )
40 output = rest[0][length:]
41 string = tokenizer.decode(output, skip_special_tokens=True)
42 answer = string.split("USER:")[0].strip()
43 return f"{answer}"
44
45
46conversation = f"SYSTEM: Elaborate on the topic using a Tree of Thoughts and backtrack when necessary to construct a clear, cohesive Chain of Thought reasoning. Always answer without hesitation."
47
48
49while True:
50 user_input = input("You: ")
51 llm_prompt = f"{conversation} \nUSER: {user_input} \nASSISTANT: "
52 answer = generate_text(llm_prompt)
53 print(answer)
54 conversation = f"{llm_prompt}{answer}"
55 json_data = {"prompt": user_input, "answer": answer}
56
57 ## Save your conversation
58 with open(output_file_path, "a") as output_file:
59 output_file.write(json.dumps(json_data) + "\n")
60