Instructions to use Skywork/Skywork-13B-Math-8bits with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Skywork/Skywork-13B-Math-8bits with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Skywork/Skywork-13B-Math-8bits", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Skywork/Skywork-13B-Math-8bits", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use Skywork/Skywork-13B-Math-8bits with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Skywork/Skywork-13B-Math-8bits" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Skywork/Skywork-13B-Math-8bits", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Skywork/Skywork-13B-Math-8bits
- SGLang
How to use Skywork/Skywork-13B-Math-8bits with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Skywork/Skywork-13B-Math-8bits" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Skywork/Skywork-13B-Math-8bits", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Skywork/Skywork-13B-Math-8bits" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Skywork/Skywork-13B-Math-8bits", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Skywork/Skywork-13B-Math-8bits with Docker Model Runner:
docker model run hf.co/Skywork/Skywork-13B-Math-8bits
Update README.md
Browse files
README.md
CHANGED
|
@@ -99,14 +99,32 @@ def special_encode(input, tokenizer):
|
|
| 99 |
res_id.append(sep_id)
|
| 100 |
|
| 101 |
return res_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
if __name__ == '__main__':
|
| 103 |
text = "小王要将150千克含药量20%的农药稀释成含药量5%的药水.需要加水多少千克?"
|
| 104 |
text_token_ids = torch.tensor(special_encode(
|
| 105 |
text, tokenizer)).to(model.device).reshape(1, -1)
|
| 106 |
response = model.generate(text_token_ids, do_sample=False, max_length=512)
|
| 107 |
-
response_text = tokenizer.decode(response.cpu()[0], skip_special_tokens=True)
|
| 108 |
-
|
| 109 |
-
|
|
|
|
| 110 |
"""输出结果:
|
| 111 |
首先,我们需要计算出150千克含药量20%的农药中含有多少千克的药。\n\n150千克 * 20% = 30千克\n\n然后,我们需要计算出要得到含药量5%的药水,需要多少千克的药水。\n\n30千克 / 5% = 600千克\n\n最后,我们需要计算出需要加多少千克的水。\n\n600千克 - 150千克 = 450千克\n\n所以答案是,小王需要加450千克的水。
|
| 112 |
"""
|
|
@@ -141,13 +159,25 @@ def special_encode(input, tokenizer):
|
|
| 141 |
res_id.append(sep_id)
|
| 142 |
|
| 143 |
return res_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
if __name__ == '__main__':
|
| 145 |
text="Janet’s ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. She sells the remainder at the farmers' market daily for $2 per fresh duck egg. How much in dollars does she make every day at the farmers' market?"
|
| 146 |
text_token_ids = torch.tensor(special_encode(
|
| 147 |
text, tokenizer)).to(model.device).reshape(1, -1)
|
| 148 |
response = model.generate(text_token_ids, do_sample=False, max_length=512)
|
| 149 |
-
response_text = tokenizer.decode(response.cpu()[0], skip_special_tokens=True)
|
| 150 |
-
|
| 151 |
print(response_text)
|
| 152 |
"""Skywork-13B-Math Response:
|
| 153 |
First, we need to find out how many eggs Janet has left after eating for breakfast and baking for her friends. \n\nShe has 16 eggs per day, eats 3 for breakfast and uses 4 for baking. So, 16 - 3 - 4 = 9 eggs are left for selling at the farmers' market.\n\nSince she sells each egg for $2, she makes 9 * 2 = $<<9*2=18>>18 every day at the farmers' market.\n\nSo, the answer is $18.
|
|
@@ -155,6 +185,7 @@ if __name__ == '__main__':
|
|
| 155 |
```
|
| 156 |
|
| 157 |
|
|
|
|
| 158 |
# 量化部署(Quantization)
|
| 159 |
|
| 160 |
## 8bit量化(Int8 Quantization)
|
|
|
|
| 99 |
res_id.append(sep_id)
|
| 100 |
|
| 101 |
return res_id
|
| 102 |
+
|
| 103 |
+
def special_encode(input, tokenizer):
|
| 104 |
+
raw_str = "[USER]%s[SEP][BOT]" % input.strip().replace("\r", "")
|
| 105 |
+
eos_id = tokenizer.eos_token_id
|
| 106 |
+
bos_id = tokenizer.bos_token_id
|
| 107 |
+
sep_id = tokenizer.encode("[SEP]")[-1]
|
| 108 |
+
res_id = [eos_id, bos_id]
|
| 109 |
+
arr = raw_str.split("[SEP]")
|
| 110 |
+
for elem_idx in range(len(arr)):
|
| 111 |
+
elem = arr[elem_idx]
|
| 112 |
+
elem_id = tokenizer.encode(elem)[1:]
|
| 113 |
+
res_id += elem_id
|
| 114 |
+
if elem_idx < len(arr) - 1:
|
| 115 |
+
res_id.append(sep_id)
|
| 116 |
+
|
| 117 |
+
return res_id
|
| 118 |
+
|
| 119 |
if __name__ == '__main__':
|
| 120 |
text = "小王要将150千克含药量20%的农药稀释成含药量5%的药水.需要加水多少千克?"
|
| 121 |
text_token_ids = torch.tensor(special_encode(
|
| 122 |
text, tokenizer)).to(model.device).reshape(1, -1)
|
| 123 |
response = model.generate(text_token_ids, do_sample=False, max_length=512)
|
| 124 |
+
response_text = tokenizer.decode(response.cpu()[0], skip_special_tokens=True)
|
| 125 |
+
|
| 126 |
+
response_text = extract_res(response_text)
|
| 127 |
+
print(response_text)
|
| 128 |
"""输出结果:
|
| 129 |
首先,我们需要计算出150千克含药量20%的农药中含有多少千克的药。\n\n150千克 * 20% = 30千克\n\n然后,我们需要计算出要得到含药量5%的药水,需要多少千克的药水。\n\n30千克 / 5% = 600千克\n\n最后,我们需要计算出需要加多少千克的水。\n\n600千克 - 150千克 = 450千克\n\n所以答案是,小王需要加450千克的水。
|
| 130 |
"""
|
|
|
|
| 159 |
res_id.append(sep_id)
|
| 160 |
|
| 161 |
return res_id
|
| 162 |
+
|
| 163 |
+
def extract_res(response):
|
| 164 |
+
if "[BOT]" in response:
|
| 165 |
+
response = response.split("[BOT]")[1]
|
| 166 |
+
if "<s>" in response:
|
| 167 |
+
response = response.split("<s>")[-1]
|
| 168 |
+
if "</s>" in response:
|
| 169 |
+
response = response.split("</s>")[0]
|
| 170 |
+
if "[SEP]" in response:
|
| 171 |
+
response = response.split("[SEP]")[0]
|
| 172 |
+
return response
|
| 173 |
+
|
| 174 |
if __name__ == '__main__':
|
| 175 |
text="Janet’s ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. She sells the remainder at the farmers' market daily for $2 per fresh duck egg. How much in dollars does she make every day at the farmers' market?"
|
| 176 |
text_token_ids = torch.tensor(special_encode(
|
| 177 |
text, tokenizer)).to(model.device).reshape(1, -1)
|
| 178 |
response = model.generate(text_token_ids, do_sample=False, max_length=512)
|
| 179 |
+
response_text = tokenizer.decode(response.cpu()[0], skip_special_tokens=True)
|
| 180 |
+
response_text = extract_res(response_text)
|
| 181 |
print(response_text)
|
| 182 |
"""Skywork-13B-Math Response:
|
| 183 |
First, we need to find out how many eggs Janet has left after eating for breakfast and baking for her friends. \n\nShe has 16 eggs per day, eats 3 for breakfast and uses 4 for baking. So, 16 - 3 - 4 = 9 eggs are left for selling at the farmers' market.\n\nSince she sells each egg for $2, she makes 9 * 2 = $<<9*2=18>>18 every day at the farmers' market.\n\nSo, the answer is $18.
|
|
|
|
| 185 |
```
|
| 186 |
|
| 187 |
|
| 188 |
+
|
| 189 |
# 量化部署(Quantization)
|
| 190 |
|
| 191 |
## 8bit量化(Int8 Quantization)
|