vagrillo commited on
Commit
d1bcdef
·
verified ·
1 Parent(s): e697d18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -32
app.py CHANGED
@@ -1,32 +1,23 @@
1
- # Code to inference Hermes with HF Transformers
2
- # Requires pytorch, transformers, bitsandbytes, sentencepiece, protobuf, and flash-attn packages
3
-
4
- import torch
5
- from transformers import AutoTokenizer, AutoModelForCausalLM
6
- from transformers import LlamaTokenizer, MixtralForCausalLM
7
- import bitsandbytes, flash_attn
8
-
9
- tokenizer = LlamaTokenizer.from_pretrained('NousResearch/Nous-Hermes-2-Mistral-7B-DPO-GGUF', trust_remote_code=True)
10
- model = MixtralForCausalLM.from_pretrained(
11
- "NousResearch/Nous-Hermes-2-Mistral-7B-DPO-GGUF",
12
- torch_dtype=torch.float16,
13
- device_map="auto",
14
- load_in_8bit=False,
15
- load_in_4bit=True,
16
- use_flash_attention_2=True
17
- )
18
-
19
- prompts = [
20
- """<|im_start|>system
21
- You are a sentient, superintelligent artificial general intelligence, here to teach and assist me.<|im_end|>
22
- <|im_start|>user
23
- Write a short story about Goku discovering kirby has teamed up with Majin Buu to destroy the world.<|im_end|>
24
- <|im_start|>assistant""",
25
- ]
26
-
27
- for chat in prompts:
28
- print(chat)
29
- input_ids = tokenizer(chat, return_tensors="pt").input_ids.to("cuda")
30
- generated_ids = model.generate(input_ids, max_new_tokens=750, temperature=0.8, repetition_penalty=1.1, do_sample=True, eos_token_id=tokenizer.eos_token_id)
31
- response = tokenizer.decode(generated_ids[0][input_ids.shape[-1]:], skip_special_tokens=True, clean_up_tokenization_space=True)
32
- print(f"Response: {response}")
 
1
+ from ctransformers import AutoModelForCausalLM
2
+
3
+
4
+ # Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
5
+ #llm = AutoModelForCausalLM.from_pretrained("TheBloke/Mistral-7B-OpenOrca-GGUF", model_file="mistral-7b-openorca.Q4_K_M.gguf", model_type="mistral", gpu_layers=50)
6
+
7
+
8
+ #llm = AutoModelForCausalLM.from_pretrained("Open-Orca/Mistral-7B-OpenOrca",gpu_layers=0, max_new_tokens = 1000, context_length = 10000)
9
+
10
+ llm = AutoModelForCausalLM.from_pretrained("NousResearch/Nous-Hermes-2-Mistral-7B-DPO.Q4_0.gguf",gpu_layers=0, max_new_tokens = 500, context_length = 2048)
11
+ # llm = AutoModelForCausalLM.from_pretrained("/home/ubuntu/.cache/gpt4all/Nous-Hermes-2-Mistral-7B-DPO.Q4_0.gguf",gpu_layers=0, max_new_tokens = 500, context_length = 6000)
12
+
13
+
14
+
15
+
16
+
17
+ #llm = AutoModelForCausalLM.from_pretrained("TheBloke/zephyr-7B-beta-GGUF",model_file="zephyr-7b-beta.Q5_K_M.gguf", model_type="mistral",gpu_layers=0, max_new_tokens = 1000, context_length = 6000)
18
+
19
+ contenuto="che ore sono?"
20
+ print(contenuto)
21
+
22
+ if __name__ == '__main__':
23
+ print(llm(contenuto,threads=16,temperature=0.7,top_k=40,top_p=0.4,repetition_penalty=1.18))