Views
No views yet

[INST] <<SYS>>\nأنت مساعد مفيد ومحترم وصادق. أجب دائما بأكبر قدر ممكن من المساعدة بينما تكون آمنا. يجب ألا تتضمن إجاباتك أي محتوى ضار أو غير أخلاقي أو عنصري أو جنسي أو سام أو خطير أو غير قانوني. يرجى التأكد من أن ردودك غير متحيزة اجتماعيا وإيجابية بطبيعتها.\n\nإذا كان السؤال لا معنى له أو لم يكن متماسكا من الناحية الواقعية، اشرح السبب بدلا من الإجابة على شيء غير صحيح. إذا كنت لا تعرف إجابة سؤال ما، فيرجى عدم مشاركة معلومات خاطئة.\n<</SYS>>\n\n
[INST] {prompt} [/INST]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 = "MohamedRashad/AceGPT-13B-chat-AWQ"
4
5tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, padding_side="right")
6model = AutoModelForCausalLM.from_pretrained(
7 model_name_or_path,
8 use_flash_attention_2=True, # disable if you have problems with flash attention 2
9 torch_dtype=torch.float16,
10 low_cpu_mem_usage=True,
11 device_map="auto"
12)
13
14# Using the text streamer to stream output one token at a time
15streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
16
17prompt = "ما أجمل بيت شعر فى اللغة العربية ؟"
18prompt_template=f'''[INST] <<SYS>>\nأنت مساعد مفيد ومحترم وصادق. أجب دائما بأكبر قدر ممكن من المساعدة بينما تكون آمنا. يجب ألا تتضمن إجاباتك أي محتوى ضار أو غير أخلاقي أو عنصري أو جنسي أو سام أو خطير أو غير قانوني. يرجى التأكد من أن ردودك غير متحيزة اجتماعيا وإيجابية بطبيعتها.\n\nإذا كان السؤال لا معنى له أو لم يكن متماسكا من الناحية الواقعية، اشرح السبب بدلا من الإجابة على شيء غير صحيح. إذا كنت لا تعرف إجابة سؤال ما، فيرجى عدم مشاركة معلومات خاطئة.\n<</SYS>>\n\n
19[INST] {prompt} [/INST]
20'''
21
22# Convert prompt to tokens
23tokens = tokenizer(
24 prompt_template,
25 return_tensors='pt'
26).input_ids.cuda()
27
28generation_params = {
29 "do_sample": True,
30 "temperature": 0.7,
31 "top_p": 0.95,
32 "top_k": 40,
33 "max_new_tokens": 512,
34 "repetition_penalty": 1.1
35}
36
37# Generate streamed output, visible one token at a time
38generation_output = model.generate(
39 tokens,
40 streamer=streamer,
41 **generation_params
42)
43
44# Generation without a streamer, which will include the prompt in the output
45generation_output = model.generate(
46 tokens,
47 **generation_params
48)
49
50# Get the tokens from the output, decode them, print them
51token_output = generation_output[0]
52text_output = tokenizer.decode(token_output)
53print("model.generate output: ", text_output)
54
55# Inference is also possible via Transformers' pipeline
56from transformers import pipeline
57
58pipe = pipeline(
59 "text-generation",
60 model=model,
61 tokenizer=tokenizer,
62 **generation_params
63)
64
65pipe_output = pipe(prompt_template)[0]['generated_text']
66print("pipeline output: ", pipe_output)
671from awq import AutoAWQForCausalLM
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_path = "FreedomIntelligence/AceGPT-13B-chat"
5quant_path = "AceGPT-13B-chat-AWQ"
6quant_config = {"zero_point": True, "q_group_size": 128, "w_bit": 4, "version": "GEMM"}
7load_config = {
8 "low_cpu_mem_usage": True,
9 "device_map": "auto",
10 "trust_remote_code": True,
11}
12# Load model
13model = AutoAWQForCausalLM.from_pretrained(model_path, **load_config)
14tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
15
16# Quantize
17model.quantize(tokenizer, quant_config=quant_config)
18
19# Save quantized model
20model.save_quantized(quant_path)
21tokenizer.save_pretrained(quant_path)
22
23# Load quantized model
24model = AutoModelForCausalLM.from_pretrained(quant_path)
25tokenizer = AutoTokenizer.from_pretrained(quant_path)
26
27# Push to hub
28model.push_to_hub(quant_path)
29tokenizer.push_to_hub(quant_path)