onrdmr commited on
Commit
85f7286
1 Parent(s): 38e2441

Update app.py

Browse files

fine tuned halini gpu'ya kurdum.quantized çalışmadı ama cpu'da çalıştığından çökmüş de olabilir bakılacak.

Files changed (1) hide show
  1. app.py +65 -54
app.py CHANGED
@@ -1,6 +1,19 @@
1
  import gradio as gr
 
2
  from huggingface_hub import InferenceClient
3
- from llama_cpp import Llama
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  """
6
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
@@ -8,55 +21,53 @@ For more information on `huggingface_hub` Inference API support, please check th
8
  # client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
 
10
 
11
- # Define the inference parameters
12
- inference_params = {
13
- "n_threads": 4,
14
- "n_predict": -1,
15
- "top_k": 40,
16
- "min_p": 0.05,
17
- "top_p": 0.95,
18
- "temp": 0.8,
19
- "repeat_penalty": 1.1,
20
- "input_prefix": "<|start_header_id|>user<|end_header_id|>\\n\\n",
21
- "input_suffix": "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\\n\\n",
22
- "antiprompt": [],
23
- "pre_prompt": "Sen bir yapay zeka asistanısın. Kullanıcı sana bir görev verecek. Amacın görevi olabildiğince sadık bir şekilde tamamlamak.",
24
- "pre_prompt_suffix": "<|eot_id|>",
25
- "pre_prompt_prefix": "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\\n\\n",
26
- "seed": -1,
27
- "tfs_z": 1,
28
- "typical_p": 1,
29
- "repeat_last_n": 64,
30
- "frequency_penalty": 0,
31
- "presence_penalty": 0,
32
- "n_keep": 0,
33
- "logit_bias": {},
34
- "mirostat": 0,
35
- "mirostat_tau": 5,
36
- "mirostat_eta": 0.1,
37
- "memory_f16": True,
38
- "multiline_input": False,
39
- "penalize_nl": True
40
- }
41
-
42
-
43
- llama = Llama.from_pretrained(
44
- repo_id="ytu-ce-cosmos/Turkish-Llama-8b-Instruct-v0.1-GGUF",
45
- filename="*Q4_K.gguf",
46
- verbose=False
47
- )
48
-
49
  def respond(
50
  message,
51
  history: list[tuple[str, str]],
52
  system_message,
 
 
 
53
  ):
54
- # Construct the prompt
55
- prompt = f"{inference_params['pre_prompt_prefix']}{inference_params['pre_prompt']}\n\n{inference_params['input_prefix']}{message}{inference_params['input_suffix']}"
 
 
 
 
 
 
56
 
57
- # Generate the response
58
- response = llama(prompt)
59
- yield response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  """
62
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
@@ -64,16 +75,16 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
64
  demo = gr.ChatInterface(
65
  respond,
66
  additional_inputs=[
67
- gr.Textbox(value="You are a friendly Chatbot.", label="System message")#,
68
- #gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
69
- #gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
70
- #gr.Slider(
71
- # minimum=0.1,
72
- # maximum=1.0,
73
- # value=0.95,
74
- # step=0.05,
75
- # label="Top-p (nucleus sampling)",
76
- #), # inference parametreleri eklenecek
77
  ],
78
  )
79
 
 
1
  import gradio as gr
2
+ import spaces
3
  from huggingface_hub import InferenceClient
4
+ #from llama_cpp import Llama
5
+ from transformers import AutoTokenizer, AutoModelForCausalLM
6
+ import torch
7
+
8
+ model_id = "ytu-ce-cosmos/Turkish-Llama-8b-Instruct-v0.1"
9
+
10
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
11
+ model = AutoModelForCausalLM.from_pretrained(
12
+ model_id,
13
+ torch_dtype=torch.bfloat16,
14
+ device_map="auto",
15
+ )
16
+
17
 
18
  """
19
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
 
21
  # client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
22
 
23
 
24
+ @spaces.GPU
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  def respond(
26
  message,
27
  history: list[tuple[str, str]],
28
  system_message,
29
+ max_tokens,
30
+ temperature,
31
+ top_p,
32
  ):
33
+
34
+ print("response girildi")
35
+
36
+ messages = [
37
+ {"role": "system", "content": "Sen bir yapay zeka asistanısın. Kullanıcı sana bir görev verecek. Amacın görevi olabildiğince sadık bir şekilde tamamlamak. Görevi yerine getirirken adım adım düşün ve adımlarını gerekçelendir."},
38
+ {"role": "user", "content": message},
39
+ ]
40
+
41
 
42
+ input_ids = tokenizer.apply_chat_template(
43
+ messages,
44
+ add_generation_prompt=True,
45
+ return_tensors="pt"
46
+ ).to(model.device)
47
+
48
+ terminators = [
49
+ tokenizer.eos_token_id,
50
+ tokenizer.convert_tokens_to_ids("<|eot_id|>")
51
+ ]
52
+
53
+ print("cevaba girildi")
54
+
55
+
56
+
57
+ outputs = model.generate(
58
+ input_ids,
59
+ max_new_tokens=256,
60
+ eos_token_id=terminators,
61
+ do_sample=True,
62
+ temperature=0.6,
63
+ top_p=0.9,
64
+ )
65
+ response = outputs[0][input_ids.shape[-1]:]
66
+ print("cevap döndü")
67
+
68
+
69
+ yield tokenizer.decode(response, skip_special_tokens=True)
70
+
71
 
72
  """
73
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
 
75
  demo = gr.ChatInterface(
76
  respond,
77
  additional_inputs=[
78
+ gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
79
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
80
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
81
+ gr.Slider(
82
+ minimum=0.1,
83
+ maximum=1.0,
84
+ value=0.95,
85
+ step=0.05,
86
+ label="Top-p (nucleus sampling)",
87
+ ), # inference parametreleri eklenecek
88
  ],
89
  )
90