INC4AI commited on
Commit
dbbac5e
·
verified ·
1 Parent(s): 111113f

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +109 -0
README.md ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model:
3
+ - tencent/Youtu-LLM-2B
4
+ pipeline_tag: text-generation
5
+ ---
6
+
7
+ ## Model Details
8
+
9
+ This model is an int4 model with group_size 128 and symmetric quantization of [tencent/Youtu-LLM-2B](https://huggingface.co/tencent/Youtu-LLM-2B) generated by [intel/auto-round](https://github.com/intel/auto-round). Please follow the license of the original model.
10
+
11
+ ## How to Use
12
+
13
+ ### HF Usage
14
+
15
+ ```python
16
+ # transformers==4.57.1
17
+ import re
18
+ from transformers import AutoTokenizer, AutoModelForCausalLM
19
+
20
+ # 1. Configure Model
21
+ model_id = "Intel/Youtu-LLM-2B-int4-AutoRound"
22
+
23
+ # 2. Initialize Tokenizer and Model
24
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
25
+ model = AutoModelForCausalLM.from_pretrained(
26
+ model_id,
27
+ device_map="auto",
28
+ trust_remote_code=True
29
+ )
30
+
31
+ # 3. Construct Dialogue Input
32
+ prompt = "Hello"
33
+ messages = [{"role": "user", "content": prompt}]
34
+
35
+ # Use apply_chat_template to construct input; set enable_thinking=True to activate Reasoning Mode
36
+ input_text = tokenizer.apply_chat_template(
37
+ messages,
38
+ tokenize=False,
39
+ add_generation_prompt=True,
40
+ enable_thinking=True
41
+ )
42
+
43
+ model_inputs = tokenizer([input_text], return_tensors="pt").to(model.device)
44
+ print("Input prepared. Starting generation...")
45
+
46
+ # 4. Generate Response
47
+ outputs = model.generate(
48
+ **model_inputs,
49
+ max_new_tokens=512,
50
+ do_sample=True,
51
+ temperature=1.0,
52
+ top_k=20,
53
+ top_p=0.95,
54
+ repetition_penalty=1.05
55
+ )
56
+ print("Generation complete!")
57
+
58
+ # 5. Parse Results
59
+ full_response = tokenizer.decode(outputs[0], skip_special_tokens=True)
60
+
61
+ def parse_reasoning(text):
62
+ """Extract thought process within <think> tags and the subsequent answer content"""
63
+ thought_pattern = r"<think>(.*?)</think>"
64
+ match = re.search(thought_pattern, text, re.DOTALL)
65
+
66
+ if match:
67
+ thought = match.group(1).strip()
68
+ answer = text.split("</think>")[-1].strip()
69
+ else:
70
+ thought = "(No explicit thought process generated)"
71
+ answer = text
72
+ return thought, answer
73
+
74
+ thought, final_answer = parse_reasoning(full_response)
75
+
76
+ print(f"\n{'='*20} Thought Process {'='*20}\n{thought}")
77
+ print(f"\n{'='*20} Final Answer {'='*20}\n{final_answer}")
78
+ ```
79
+
80
+ ## Generate the Model
81
+
82
+ ```bash
83
+ pip install transformers==4.57.1
84
+ auto-round --bits 4 --iters 200 --model_name tencent/Youtu-LLM-2B
85
+ ```
86
+
87
+ ## Ethical Considerations and Limitations
88
+
89
+ The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.
90
+
91
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
92
+
93
+ ## Caveats and Recommendations
94
+
95
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
96
+
97
+ Here are a couple of useful links to learn more about Intel's AI software:
98
+
99
+ - [Intel Neural Compressor](https://github.com/intel/neural-compressor)
100
+
101
+ ## Disclaimer
102
+
103
+ The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.
104
+
105
+ ## Cite
106
+
107
+ @article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }
108
+
109
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)