Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from auto_round import AutoRoundConfig ##must import for autoround format
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
quantized_model_dir = "OPEA/DeepSeek-V3-int4-sym-gptq-inc"
|
| 6 |
+
quantization_config = AutoRoundConfig(
|
| 7 |
+
backend="cpu"
|
| 8 |
+
)
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
+
quantized_model_dir,
|
| 11 |
+
torch_dtype=torch.bfloat16,
|
| 12 |
+
trust_remote_code=True,
|
| 13 |
+
device_map="cpu",
|
| 14 |
+
revision="8fe0735",##use autoround format, the only difference is config.json
|
| 15 |
+
quantization_config = quantization_config, ##cpu only machine don't need to set this value
|
| 16 |
+
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir,trust_remote_code=True)
|
| 20 |
+
prompt = "There is a girl who likes adventure,"
|
| 21 |
+
messages = [
|
| 22 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
| 23 |
+
{"role": "user", "content": prompt}
|
| 24 |
+
]
|
| 25 |
+
text = tokenizer.apply_chat_template(
|
| 26 |
+
messages,
|
| 27 |
+
tokenize=False,
|
| 28 |
+
add_generation_prompt=True
|
| 29 |
+
)
|
| 30 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 31 |
+
|
| 32 |
+
generated_ids = model.generate(
|
| 33 |
+
model_inputs.input_ids,
|
| 34 |
+
max_new_tokens=200, ##change this to align with the official usage
|
| 35 |
+
do_sample=False ##change this to align with the official usage
|
| 36 |
+
)
|
| 37 |
+
generated_ids = [
|
| 38 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 42 |
+
print(response)
|
| 43 |
+
|
| 44 |
+
prompt = "9.11和9.8哪个数字大"
|
| 45 |
+
|
| 46 |
+
##INT4
|
| 47 |
+
"""要比较 **9.11** 和 **9.8** 的大小,可以按照以下步骤进行:
|
| 48 |
+
|
| 49 |
+
1. **比较整数部分**:
|
| 50 |
+
- 两个数的整数部分都是 **9**,所以整数部分相同。
|
| 51 |
+
|
| 52 |
+
2. **比较小数部分**:
|
| 53 |
+
- **9.11** 的小数部分是 **0.11**
|
| 54 |
+
- **9.8** 的小数部分是 **0.8**(即 **0.80**)
|
| 55 |
+
|
| 56 |
+
3. **分析小数部分**:
|
| 57 |
+
- **0.80** 大于 **0.11**
|
| 58 |
+
|
| 59 |
+
因此,**9.8** 大于 **9.11**。
|
| 60 |
+
|
| 61 |
+
最终答案:\boxed{9.8}
|
| 62 |
+
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
prompt = "strawberry中有几个r?"
|
| 66 |
+
##INT4
|
| 67 |
+
"""
|
| 68 |
+
### 第一步:理解问题
|
| 69 |
+
|
| 70 |
+
首先,我需要明确问题的含义。问题是:“strawberry中有几个r?”。这里的“strawberry”是一个英文单词,意思是“草莓”。问题问的是这个单 词中有多少个字母“r”。
|
| 71 |
+
|
| 72 |
+
### 第二步:分解单词
|
| 73 |
+
|
| 74 |
+
为了找出“strawberry”中有多少个“r”,我需要将这个单词分解成单个字母。让我们逐个字母来看:
|
| 75 |
+
|
| 76 |
+
- s
|
| 77 |
+
- t
|
| 78 |
+
- r
|
| 79 |
+
- a
|
| 80 |
+
- w
|
| 81 |
+
- b
|
| 82 |
+
- e
|
| 83 |
+
- r
|
| 84 |
+
- r
|
| 85 |
+
- y
|
| 86 |
+
|
| 87 |
+
### 第三步:识别字母“r”
|
| 88 |
+
|
| 89 |
+
现在,我需要找出这些字母中哪些是“r”。让我们逐一检查:
|
| 90 |
+
|
| 91 |
+
1. s - 不是r
|
| 92 |
+
2. t - 不是r
|
| 93 |
+
3. r - 是r
|
| 94 |
+
4. a - 不是r
|
| 95 |
+
5. w - 不是r
|
| 96 |
+
6. b - 不是r
|
| 97 |
+
7. e - 不是r
|
| 98 |
+
8. r - 是r
|
| 99 |
+
"""
|
| 100 |
+
|
| 101 |
+
prompt = "How many r in strawberry."
|
| 102 |
+
##INT4
|
| 103 |
+
"""The word "strawberry" contains **3 "r"s.
|
| 104 |
+
"""
|
| 105 |
+
|
| 106 |
+
prompt = "There is a girl who likes adventure,"
|
| 107 |
+
##INT4:
|
| 108 |
+
"""That's wonderful! A girl who loves adventure is likely curious, brave, and eager to explore the world around her. Here are some ideas to fuel her adventurous spirit:
|
| 109 |
+
|
| 110 |
+
### **Outdoor Adventures**
|
| 111 |
+
|
| 112 |
+
- **Hiking:** Explore local trails, national parks, or mountains.
|
| 113 |
+
- **Camping:** Spend a night under the stars and connect with nature.
|
| 114 |
+
- **Rock Climbing:** Challenge herself with bouldering or climbing walls.
|
| 115 |
+
- **Kayaking/Canoeing:** Paddle through rivers, lakes, or even the ocean.
|
| 116 |
+
- **Zip-lining:** Soar through the treetops for an adrenaline rush.
|
| 117 |
+
|
| 118 |
+
### **Travel Adventures**
|
| 119 |
+
|
| 120 |
+
- **Road Trips:** Plan a journey to new cities or scenic destinations.
|
| 121 |
+
- **Backpacking:** Travel light and explore different cultures and landscapes.
|
| 122 |
+
- **Volunteer Abroad:** Combine adventure with helping others in a new country.
|
| 123 |
+
|
| 124 |
+
### **Creative Adventures**
|
| 125 |
+
|
| 126 |
+
- **Photography:** Capture the beauty
|
| 127 |
+
"""
|
| 128 |
+
|
| 129 |
+
prompt = "Please give a brief introduction of DeepSeek company."
|
| 130 |
+
##INT4:
|
| 131 |
+
"""DeepSeek Artificial Intelligence Co., Ltd. (referred to as "DeepSeek" or "深度求索") , founded in 2023, is a Chinese company dedicated to making AGI a reality"""
|