bakch92 commited on
Commit
a196cf1
·
verified ·
1 Parent(s): 0c2ba39

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +57 -0
README.md CHANGED
@@ -36,6 +36,63 @@ This is the model card of a 🤗 transformers model that has been pushed on the
36
  - **Demo [optional]:** [More Information Needed]
37
 
38
  ## Uses
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
41
 
 
36
  - **Demo [optional]:** [More Information Needed]
37
 
38
  ## Uses
39
+ ```
40
+ import os
41
+ import torch
42
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
43
+ from peft import PeftModel
44
+
45
+ model_id = 'model_result'
46
+
47
+ bnb_config = BitsAndBytesConfig(
48
+ load_in_4bit=True,
49
+ bnb_4bit_quant_type="nf4",
50
+ bnb_4bit_compute_dtype=torch.bfloat16,
51
+ bnb_4bit_use_double_quant=True,
52
+ )
53
+
54
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
55
+ tokenizer.pad_token = tokenizer.eos_token
56
+
57
+ model = AutoModelForCausalLM.from_pretrained(
58
+ model_id,
59
+ #torch_dtype=torch.bfloat16,
60
+ quantization_config=bnb_config, # 4-bit quantization (4비트 양자화)
61
+ device_map="auto",
62
+ )
63
+
64
+ model.eval()
65
+
66
+ from transformers import TextStreamer
67
+
68
+ def inference(input: str):
69
+ streamer = TextStreamer(tokenizer=tokenizer, skip_prompt=True, skip_special_tokens=True)
70
+
71
+ messages = [
72
+ {"role": "system", "content": "You are an information security AI assistant. Information security questions must be answered accurately."},
73
+ {"role": "user", "content": f"Please provide concise, non-repetitive answers to the following questions:\n {input}"}
74
+ # {"role": "user", "content": f"{input}"}
75
+ ]
76
+
77
+ input_ids = tokenizer.apply_chat_template(
78
+ messages,
79
+ tokenize=True,
80
+ add_generation_prompt=True,
81
+ return_tensors="pt",
82
+ ).to(model.device)
83
+
84
+ outputs = model.generate(
85
+ input_ids,
86
+ streamer=streamer,
87
+ max_new_tokens=8192,
88
+ num_beams=1,
89
+ do_sample=True,
90
+ temperature=0.1,
91
+ top_p=0.95,
92
+ top_k=10
93
+ )
94
+
95
+ ```
96
 
97
  <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
98