Views
No views yet

<|im_start|>system
{system_message}<|im_end|>
<|im_start|>user
{prompt}<|im_end|>
<|im_start|>assistant
TheBloke/Mistral-7B-OpenOrca-oasst_top1_2023-08-25-v1-AWQ.Mistral-7B-OpenOrca-oasst_top1_2023-08-25-v1-AWQ--quantization awq parameter.python3 -m vllm.entrypoints.api_server --model TheBloke/Mistral-7B-OpenOrca-oasst_top1_2023-08-25-v1-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'''<|im_start|>system
10{system_message}<|im_end|>
11<|im_start|>user
12{prompt}<|im_end|>
13<|im_start|>assistant
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/Mistral-7B-OpenOrca-oasst_top1_2023-08-25-v1-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/Mistral-7B-OpenOrca-oasst_top1_2023-08-25-v1-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'''<|im_start|>system
7{system_message}<|im_end|>
8<|im_start|>user
9{prompt}<|im_end|>
10<|im_start|>assistant
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/Mistral-7B-OpenOrca-oasst_top1_2023-08-25-v1-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'''<|im_start|>system
17{system_message}<|im_end|>
18<|im_start|>user
19{prompt}<|im_end|>
20<|im_start|>assistant
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.reference-data-model:
datasets:
- OpenAssistant/oasst_top1_2023-08-25:
Lang: "bg,ca,cs,da,de,en,es,fr,hr,hu,it,nl,pl,pt,ro,ru,sl,sr,sv,uk"
Link: https://huggingface.co/datasets/OpenAssistant/oasst_top1_2023-08-25
model:
- Open-Orca/Mistral-7B-OpenOrca
Link: https://huggingface.co/Open-Orca/Mistral-7B-OpenOrca
100 examples of generating:
Link: https://docs.google.com/spreadsheets/d/1_4rqFnhgvjA7trwAaEidaRWczAMzuKpw/edit?usp=sharing&ouid=116592149115238887304&rtpof=true&sd=true
Version 2:
Link: https://huggingface.co/NickyNicky/Mistral-7B-OpenOrca-oasst_top1_2023-08-25-v2
1import torch, transformers,torchvision
2torch.__version__,transformers.__version__, torchvision.__version__
3#OUTPUTS: ('2.0.1+cu118', '4.34.0.dev0', '0.15.2+cu118')1
2from transformers import (
3 AutoModelForCausalLM,
4 AutoTokenizer,
5 BitsAndBytesConfig,
6 HfArgumentParser,
7 TrainingArguments,
8 pipeline,
9 logging,
10 GenerationConfig,
11 TextIteratorStreamer,
12)
13import torch
14
15# model_id = 'Open-Orca/Mistral-7B-OpenOrca'
16model_id='NickyNicky/Mistral-7B-OpenOrca-oasst_top1_2023-08-25-v1'
17
18model = AutoModelForCausalLM.from_pretrained(model_id,
19 device_map="auto",
20 trust_remote_code=True,
21 torch_dtype=torch.bfloat16,
22 load_in_4bit=True,
23 low_cpu_mem_usage= True,
24 )
25
26max_length=2048
27print("max_length",max_length)
28
29
30tokenizer = AutoTokenizer.from_pretrained(model_id,
31 # use_fast = False,
32 max_length=max_length,)
33
34tokenizer.pad_token = tokenizer.eos_token
35tokenizer.padding_side = 'right'
36
37#EXAMPLE #1
38txt="""<|im_start|>user
39I'm looking for an efficient Python script to output prime numbers. Can you help me out? I'm interested in a script that can handle large numbers and output them quickly. Also, it would be great if the script could take a range of numbers as input and output all the prime numbers within that range. Can you generate a script that fits these requirements? Thanks!<|im_end|>
40<|im_start|>assistant
41"""
42
43#EXAMPLE #2
44txt="""<|im_start|>user
45Estoy desarrollando una REST API con Nodejs, y estoy tratando de aplicar algún sistema de seguridad, ya sea con tokens o algo similar, me puedes ayudar?<|im_end|>
46<|im_start|>assistant
47"""
48
49inputs = tokenizer.encode(txt, return_tensors="pt").to("cuda")
50
51generation_config = GenerationConfig(
52 max_new_tokens=max_new_tokens,
53 temperature=0.7,
54 top_p=0.9,
55 top_k=len_tokens,
56 repetition_penalty=1.11,
57 do_sample=True,
58 # pad_token_id=tokenizer.eos_token_id,
59 # eos_token_id=tokenizer.eos_token_id,
60 # use_cache=True,
61 # stopping_criteria= StoppingCriteriaList([stopping_criteria]),
62 )
63outputs = model.generate(generation_config=generation_config,
64 input_ids=inputs,)
65tokenizer.decode(outputs[0], skip_special_tokens=False) #True