aashish1904 commited on
Commit
6cd6c38
1 Parent(s): 6d73bfc

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +101 -0
README.md ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+
4
+ library_name: transformers
5
+ datasets:
6
+ - Suraponn/thai_instruction_sft
7
+ language:
8
+ - th
9
+ base_model: meta-llama/Meta-Llama-3.1-8B
10
+
11
+ ---
12
+
13
+ ![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeiuCm7c8lEwEJuRey9kiVZsRn2W-b4pWlu3-X534V3YmVuVc2ZL-NXg2RkzSOOS2JXGHutDuyyNAUtdJI65jGTo8jT9Y99tMi4H4MqL44Uc5QKG77B0d6-JfIkZHFaUA71-RtjyYZWVIhqsNZcx8-OMaA?key=xt3VSDoCbmTY7o-cwwOFwQ)
14
+
15
+ # QuantFactory/llama_3.1_8B_Thai_instruct-GGUF
16
+ This is quantized version of [Suraponn/llama_3.1_8B_Thai_instruct](https://huggingface.co/Suraponn/llama_3.1_8B_Thai_instruct) created using llama.cpp
17
+
18
+ # Original Model Card
19
+
20
+
21
+
22
+ import json
23
+ import torch
24
+ from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig
25
+
26
+ model_id = "Suraponn/llama_3.1_8B_Thai_instruct"
27
+
28
+ tokenizer = AutoTokenizer.from_pretrained(
29
+ model_id,
30
+ )
31
+
32
+ model = AutoModelForCausalLM.from_pretrained(
33
+ model_id,
34
+ device_map="cuda:0",
35
+ torch_dtype=torch.float16,
36
+ )
37
+
38
+ config_setting = AutoConfig.from_pretrained(
39
+ model_id,
40
+ add_special_tokens=True,
41
+ )
42
+
43
+
44
+ if tokenizer.chat_template is None:
45
+ tokenizer.chat_template = tokenizer.default_chat_template
46
+
47
+ if not "system" in tokenizer.chat_template and "system" in tokenizer.default_chat_template:
48
+ tokenizer.chat_template = tokenizer.default_chat_template
49
+
50
+
51
+
52
+ s_split = "เขียนบทความเกี่ยวกับการออกกำลังกายให้ถูกต้อง"
53
+
54
+ chat = [
55
+ {
56
+ "role": "system",
57
+ "content": "You are a helpfull assistant. Please respond in Thai."
58
+ },
59
+ {
60
+ "role": "user",
61
+ "content": s_split,
62
+ },
63
+ ]
64
+
65
+ tokenizer.use_default_system_prompt = False
66
+ extract_input = tokenizer.apply_chat_template(chat, tokenize=False , add_generation_prompt=True)
67
+
68
+ #extract_input = extract_input.split(s_split)[0]
69
+ print("------------\n" + extract_input + "\n------------")
70
+
71
+
72
+ inputs = tokenizer(
73
+ extract_input,
74
+ return_tensors="pt",
75
+ add_special_tokens = False,
76
+ )
77
+ #print(inputs)
78
+
79
+
80
+ terminators = [
81
+ tokenizer.eos_token_id,
82
+ tokenizer.convert_tokens_to_ids("<|eot_id|>"),
83
+ ]
84
+ #print(terminators)
85
+
86
+
87
+ inputs = inputs.to(model.device)
88
+
89
+ with torch.no_grad():
90
+ tokens = model.generate(
91
+ **inputs,
92
+ max_new_tokens=2048,
93
+ do_sample=True,
94
+ eos_token_id=terminators,
95
+ temperature=0.7,
96
+ #top_p=1,
97
+ )
98
+
99
+
100
+ output = tokenizer.decode(tokens[0])
101
+ print(output)