返回模型
说明文档
启用键值缓存的 BigCode StarCoder ONNX fp16 格式模型
- 模型创建者:BigCode
- 原始模型:BigCode StarCoder
<!-- description start -->
描述
本仓库包含由 Esperanto Technologies 转换的 BigCode StarCoder ONNX 文件。 该模型采用 fp16 格式,并已启用 KVC(键值缓存)功能。
<!-- description end -->
如何下载 ONNX 模型和权重文件
获取模型最简单的方法是克隆整个仓库。
或者,您也可以使用 huggingface-hub Python 库下载文件。
pip3 install huggingface-hub>=0.17.1
然后,您可以使用如下命令高速下载任意单个模型文件到当前目录:
huggingface-cli download Esperanto/starcoder-kvc-fp16-onnx --local-dir starcoder-kvc-fp16-onnx --local-dir-use-symlinks False
更多关于使用 huggingface-cli 下载的文档,请参阅:HF -> Hub Python Library -> Download files -> Download from the CLI。
如何使用 ONNXRuntime 从 Python 代码运行
此模型可以轻松在 CPU 上使用 ONNXRuntime 运行。
首先安装依赖包
pip3 install onnx==1.16.1
pip3 install onnxruntime==1.17.1
示例代码:使用此模型生成文本
我们定义一个使用贪婪解码的循环:
import numpy as np
import onnxruntime
import onnx
from transformers import AutoTokenizer
def generate_text(model_path, prompt, tokenizer, max_gen_tokens, total_sequence, window, context):
model = onnx.load(model_path)
#我们为第一次迭代创建输入
input_tensor = tokenizer(prompt, return_tensors=\"pt\")
prompt_size = len(input_tensor['input_ids'][0])
actual_input = input_tensor['input_ids']
if prompt_size < window:
actual_input = np.concatenate((tokenizer.bos_token_id*np.ones([1, window - prompt_size], dtype = 'int64'),
actual_input), axis=1)
if prompt_size + max_gen_tokens > total_sequence:
print(\"错误:需要更长的总序列长度!\")
return
first_attention = np.concatenate((np.zeros([1, total_sequence - window], dtype = 'int64'),
np.ones((1, window), dtype = 'int64')), axis=1)
max_gen_tokens += prompt_size #我们需要在解析提示词的基础上进行生成
inputs_names =[node.name for node in model.graph.input]
output_names =[node.name for node in model.graph.output]
inputs_dict = {}
inputs_dict['input_ids'] = actual_input[:, :window].reshape(1, window).numpy()
inputs_dict['attention_mask'] = first_attention
for name in inputs_names:
if name == 'input_ids' or name == 'attention_mask': continue
inputs_dict[name] = np.zeros([1, context-window, 256], dtype=\"float16\")
index = 0
new_token = np.array([10])
next_index = window
old_j = 0
total_input = actual_input.numpy()
rt_session = onnxruntime.InferenceSession(model_path)
## 运行推理
while next_index < max_gen_tokens:
if new_token.any() == tokenizer.eos_token_id:
break
#推理
output = rt_session.run(output_names, inputs_dict)
outs_dictionary = {name: content for (name, content) in zip (output_names, output)}
#我们为下一次推理准备输入
for name in inputs_names:
if name == 'input_ids':
old_j = next_index
if next_index < prompt_size:
if prompt_size - next_index >= window: next_index += window
else: next_index = prompt_size
j = next_index - window
else:
next_index +=1
j = next_index - window
new_token = outs_dictionary['logits'].argmax(-1).reshape(1, window)
total_input = np.concatenate((total_input, new_token[: , -1:]), axis = 1)
inputs_dict['input_ids']= total_input[:, j:next_index].reshape(1, window)
elif name == 'attention_mask':
inputs_dict['attention_mask'] = np.concatenate((np.zeros((1, total_sequence-next_index), dtype = 'int64'), np.ones((1, next_index), dtype = 'int64')), axis=1)
else:
old_name = name.replace(\"past_key_values\", \"present\")
inputs_dict[name] = outs_dictionary[old_name][:, next_index-old_j:context-window+(next_index - old_j), :]
answer = tokenizer.decode(total_input[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
return answer
现在我们运行推理:
tokenizer = AutoTokenizer.from_pretrained(\"Esperanto/starcoder-kvc-fp16-onnx\")
model_path = \"starcoder-kvc-fp16-onnx/model.onnx\"
max_gen_tokens = 20 #我们想要生成的token数量
total_sequence = 128 #总序列长度
context = 1024 #扩展KVC的上下文长度
window = 16 #每次想要解析的token数量
messages = [
{\"role\": \"system\", \"content\": \"You are a pirate chatbot who always responds in pirate speak!\"},
{\"role\": \"user\", \"content\": \"Who are you?\"},
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
generated = generate_text(model_path, prompt, tokenizer, max_gen_tokens, total_sequence, window, context)
print(generated)
Esperanto/starcoder-kvc-fp16-onnx
作者 Esperanto
↓ 1
♥ 0
创建时间: 2024-08-02 11:48:47+00:00
更新时间: 2024-10-17 09:59:20+00:00
在 Hugging Face 上查看文件 (496)
.gitattributes
README.md
added_tokens.json
config.json
merges.txt
model.onnx
ONNX
onnx__MatMul_4784
onnx__MatMul_4789
onnx__MatMul_4790
onnx__MatMul_4791
onnx__MatMul_4792
onnx__MatMul_4797
onnx__MatMul_4798
onnx__MatMul_4799
onnx__MatMul_4800
onnx__MatMul_4805
onnx__MatMul_4806
onnx__MatMul_4807
onnx__MatMul_4808
onnx__MatMul_4813
onnx__MatMul_4814
onnx__MatMul_4815
onnx__MatMul_4816
onnx__MatMul_4821
onnx__MatMul_4822
onnx__MatMul_4823
onnx__MatMul_4824
onnx__MatMul_4829
onnx__MatMul_4830
onnx__MatMul_4831
onnx__MatMul_4832
onnx__MatMul_4837
onnx__MatMul_4838
onnx__MatMul_4839
onnx__MatMul_4840
onnx__MatMul_4845
onnx__MatMul_4846
onnx__MatMul_4847
onnx__MatMul_4848
onnx__MatMul_4853
onnx__MatMul_4854
onnx__MatMul_4855
onnx__MatMul_4856
onnx__MatMul_4861
onnx__MatMul_4862
onnx__MatMul_4863
onnx__MatMul_4864
onnx__MatMul_4869
onnx__MatMul_4870
onnx__MatMul_4871
onnx__MatMul_4872
onnx__MatMul_4877
onnx__MatMul_4878
onnx__MatMul_4879
onnx__MatMul_4880
onnx__MatMul_4885
onnx__MatMul_4886
onnx__MatMul_4887
onnx__MatMul_4888
onnx__MatMul_4893
onnx__MatMul_4894
onnx__MatMul_4895
onnx__MatMul_4896
onnx__MatMul_4901
onnx__MatMul_4902
onnx__MatMul_4903
onnx__MatMul_4904
onnx__MatMul_4909
onnx__MatMul_4910
onnx__MatMul_4911
onnx__MatMul_4912
onnx__MatMul_4917
onnx__MatMul_4918
onnx__MatMul_4919
onnx__MatMul_4920
onnx__MatMul_4925
onnx__MatMul_4926
onnx__MatMul_4927
onnx__MatMul_4928
onnx__MatMul_4933
onnx__MatMul_4934
onnx__MatMul_4935
onnx__MatMul_4936
onnx__MatMul_4941
onnx__MatMul_4942
onnx__MatMul_4943
onnx__MatMul_4944
onnx__MatMul_4949
onnx__MatMul_4950
onnx__MatMul_4951
onnx__MatMul_4952
onnx__MatMul_4957
onnx__MatMul_4958
onnx__MatMul_4959
onnx__MatMul_4960
onnx__MatMul_4965
onnx__MatMul_4966
onnx__MatMul_4967
onnx__MatMul_4968
onnx__MatMul_4973
onnx__MatMul_4974
onnx__MatMul_4975
onnx__MatMul_4976
onnx__MatMul_4981
onnx__MatMul_4982
onnx__MatMul_4983
onnx__MatMul_4984
onnx__MatMul_4989
onnx__MatMul_4990
onnx__MatMul_4991
onnx__MatMul_4992
onnx__MatMul_4997
onnx__MatMul_4998
onnx__MatMul_4999
onnx__MatMul_5000
onnx__MatMul_5005
onnx__MatMul_5006
onnx__MatMul_5007
onnx__MatMul_5008
onnx__MatMul_5013
onnx__MatMul_5014
onnx__MatMul_5015
onnx__MatMul_5016
onnx__MatMul_5021
onnx__MatMul_5022
onnx__MatMul_5023
onnx__MatMul_5024
onnx__MatMul_5029
onnx__MatMul_5030
onnx__MatMul_5031
onnx__MatMul_5032
onnx__MatMul_5037
onnx__MatMul_5038
onnx__MatMul_5039
onnx__MatMul_5040
onnx__MatMul_5045
onnx__MatMul_5046
onnx__MatMul_5047
onnx__MatMul_5048
onnx__MatMul_5053
onnx__MatMul_5054
onnx__MatMul_5055
onnx__MatMul_5056
onnx__MatMul_5061
onnx__MatMul_5062
onnx__MatMul_5063
onnx__MatMul_5064
onnx__MatMul_5069
onnx__MatMul_5070
onnx__MatMul_5071
onnx__MatMul_5072
onnx__MatMul_5077
onnx__MatMul_5078
onnx__MatMul_5079
onnx__MatMul_5080
onnx__MatMul_5085
onnx__MatMul_5086
onnx__MatMul_5087
onnx__MatMul_5088
onnx__MatMul_5093
onnx__MatMul_5094
onnx__MatMul_5095
onnx__MatMul_5096
onnx__MatMul_5101
onnx__MatMul_5102
onnx__MatMul_5103
onnx__MatMul_5104
special_tokens_map.json
token_id_to_str.json
tokenizer.json
tokenizer_config.json
transformer.h.0.attn.c_attn.bias
transformer.h.0.attn.c_proj.bias
transformer.h.0.ln_1.bias
transformer.h.0.ln_1.weight
transformer.h.0.ln_2.bias
transformer.h.0.ln_2.weight
transformer.h.0.mlp.c_fc.bias
transformer.h.0.mlp.c_proj.bias
transformer.h.1.attn.c_attn.bias
transformer.h.1.attn.c_proj.bias
transformer.h.1.ln_1.bias
transformer.h.1.ln_1.weight
transformer.h.1.ln_2.bias
transformer.h.1.ln_2.weight
transformer.h.1.mlp.c_fc.bias
transformer.h.1.mlp.c_proj.bias
transformer.h.10.attn.c_attn.bias
transformer.h.10.attn.c_proj.bias
transformer.h.10.ln_1.bias
transformer.h.10.ln_1.weight
transformer.h.10.ln_2.bias
transformer.h.10.ln_2.weight
transformer.h.10.mlp.c_fc.bias
transformer.h.10.mlp.c_proj.bias
transformer.h.11.attn.c_attn.bias
transformer.h.11.attn.c_proj.bias
transformer.h.11.ln_1.bias
transformer.h.11.ln_1.weight
transformer.h.11.ln_2.bias
transformer.h.11.ln_2.weight
transformer.h.11.mlp.c_fc.bias
transformer.h.11.mlp.c_proj.bias
transformer.h.12.attn.c_attn.bias
transformer.h.12.attn.c_proj.bias
transformer.h.12.ln_1.bias
transformer.h.12.ln_1.weight
transformer.h.12.ln_2.bias
transformer.h.12.ln_2.weight
transformer.h.12.mlp.c_fc.bias
transformer.h.12.mlp.c_proj.bias
transformer.h.13.attn.c_attn.bias
transformer.h.13.attn.c_proj.bias
transformer.h.13.ln_1.bias
transformer.h.13.ln_1.weight
transformer.h.13.ln_2.bias
transformer.h.13.ln_2.weight
transformer.h.13.mlp.c_fc.bias
transformer.h.13.mlp.c_proj.bias
transformer.h.14.attn.c_attn.bias
transformer.h.14.attn.c_proj.bias
transformer.h.14.ln_1.bias
transformer.h.14.ln_1.weight
transformer.h.14.ln_2.bias
transformer.h.14.ln_2.weight
transformer.h.14.mlp.c_fc.bias
transformer.h.14.mlp.c_proj.bias
transformer.h.15.attn.c_attn.bias
transformer.h.15.attn.c_proj.bias
transformer.h.15.ln_1.bias
transformer.h.15.ln_1.weight
transformer.h.15.ln_2.bias
transformer.h.15.ln_2.weight
transformer.h.15.mlp.c_fc.bias
transformer.h.15.mlp.c_proj.bias
transformer.h.16.attn.c_attn.bias
transformer.h.16.attn.c_proj.bias
transformer.h.16.ln_1.bias
transformer.h.16.ln_1.weight
transformer.h.16.ln_2.bias
transformer.h.16.ln_2.weight
transformer.h.16.mlp.c_fc.bias
transformer.h.16.mlp.c_proj.bias
transformer.h.17.attn.c_attn.bias
transformer.h.17.attn.c_proj.bias
transformer.h.17.ln_1.bias
transformer.h.17.ln_1.weight
transformer.h.17.ln_2.bias
transformer.h.17.ln_2.weight
transformer.h.17.mlp.c_fc.bias
transformer.h.17.mlp.c_proj.bias
transformer.h.18.attn.c_attn.bias
transformer.h.18.attn.c_proj.bias
transformer.h.18.ln_1.bias
transformer.h.18.ln_1.weight
transformer.h.18.ln_2.bias
transformer.h.18.ln_2.weight
transformer.h.18.mlp.c_fc.bias
transformer.h.18.mlp.c_proj.bias
transformer.h.19.attn.c_attn.bias
transformer.h.19.attn.c_proj.bias
transformer.h.19.ln_1.bias
transformer.h.19.ln_1.weight
transformer.h.19.ln_2.bias
transformer.h.19.ln_2.weight
transformer.h.19.mlp.c_fc.bias
transformer.h.19.mlp.c_proj.bias
transformer.h.2.attn.c_attn.bias
transformer.h.2.attn.c_proj.bias
transformer.h.2.ln_1.bias
transformer.h.2.ln_1.weight
transformer.h.2.ln_2.bias
transformer.h.2.ln_2.weight
transformer.h.2.mlp.c_fc.bias
transformer.h.2.mlp.c_proj.bias
transformer.h.20.attn.c_attn.bias
transformer.h.20.attn.c_proj.bias
transformer.h.20.ln_1.bias
transformer.h.20.ln_1.weight
transformer.h.20.ln_2.bias
transformer.h.20.ln_2.weight
transformer.h.20.mlp.c_fc.bias
transformer.h.20.mlp.c_proj.bias
transformer.h.21.attn.c_attn.bias
transformer.h.21.attn.c_proj.bias
transformer.h.21.ln_1.bias
transformer.h.21.ln_1.weight
transformer.h.21.ln_2.bias
transformer.h.21.ln_2.weight
transformer.h.21.mlp.c_fc.bias
transformer.h.21.mlp.c_proj.bias
transformer.h.22.attn.c_attn.bias
transformer.h.22.attn.c_proj.bias
transformer.h.22.ln_1.bias
transformer.h.22.ln_1.weight
transformer.h.22.ln_2.bias
transformer.h.22.ln_2.weight
transformer.h.22.mlp.c_fc.bias
transformer.h.22.mlp.c_proj.bias
transformer.h.23.attn.c_attn.bias
transformer.h.23.attn.c_proj.bias
transformer.h.23.ln_1.bias
transformer.h.23.ln_1.weight
transformer.h.23.ln_2.bias
transformer.h.23.ln_2.weight
transformer.h.23.mlp.c_fc.bias
transformer.h.23.mlp.c_proj.bias
transformer.h.24.attn.c_attn.bias
transformer.h.24.attn.c_proj.bias
transformer.h.24.ln_1.bias
transformer.h.24.ln_1.weight
transformer.h.24.ln_2.bias
transformer.h.24.ln_2.weight
transformer.h.24.mlp.c_fc.bias
transformer.h.24.mlp.c_proj.bias
transformer.h.25.attn.c_attn.bias
transformer.h.25.attn.c_proj.bias
transformer.h.25.ln_1.bias
transformer.h.25.ln_1.weight
transformer.h.25.ln_2.bias
transformer.h.25.ln_2.weight
transformer.h.25.mlp.c_fc.bias
transformer.h.25.mlp.c_proj.bias
transformer.h.26.attn.c_attn.bias
transformer.h.26.attn.c_proj.bias
transformer.h.26.ln_1.bias
transformer.h.26.ln_1.weight
transformer.h.26.ln_2.bias
transformer.h.26.ln_2.weight
transformer.h.26.mlp.c_fc.bias
transformer.h.26.mlp.c_proj.bias
transformer.h.27.attn.c_attn.bias
transformer.h.27.attn.c_proj.bias
transformer.h.27.ln_1.bias
transformer.h.27.ln_1.weight
transformer.h.27.ln_2.bias
transformer.h.27.ln_2.weight
transformer.h.27.mlp.c_fc.bias
transformer.h.27.mlp.c_proj.bias
transformer.h.28.attn.c_attn.bias
transformer.h.28.attn.c_proj.bias
transformer.h.28.ln_1.bias
transformer.h.28.ln_1.weight
transformer.h.28.ln_2.bias
transformer.h.28.ln_2.weight
transformer.h.28.mlp.c_fc.bias
transformer.h.28.mlp.c_proj.bias
transformer.h.29.attn.c_attn.bias
transformer.h.29.attn.c_proj.bias
transformer.h.29.ln_1.bias
transformer.h.29.ln_1.weight
transformer.h.29.ln_2.bias
transformer.h.29.ln_2.weight
transformer.h.29.mlp.c_fc.bias
transformer.h.29.mlp.c_proj.bias
transformer.h.3.attn.c_attn.bias
transformer.h.3.attn.c_proj.bias
transformer.h.3.ln_1.bias
transformer.h.3.ln_1.weight
transformer.h.3.ln_2.bias
transformer.h.3.ln_2.weight
transformer.h.3.mlp.c_fc.bias
transformer.h.3.mlp.c_proj.bias
transformer.h.30.attn.c_attn.bias
transformer.h.30.attn.c_proj.bias
transformer.h.30.ln_1.bias
transformer.h.30.ln_1.weight
transformer.h.30.ln_2.bias
transformer.h.30.ln_2.weight
transformer.h.30.mlp.c_fc.bias
transformer.h.30.mlp.c_proj.bias
transformer.h.31.attn.c_attn.bias
transformer.h.31.attn.c_proj.bias
transformer.h.31.ln_1.bias
transformer.h.31.ln_1.weight
transformer.h.31.ln_2.bias
transformer.h.31.ln_2.weight
transformer.h.31.mlp.c_fc.bias
transformer.h.31.mlp.c_proj.bias
transformer.h.32.attn.c_attn.bias
transformer.h.32.attn.c_proj.bias
transformer.h.32.ln_1.bias
transformer.h.32.ln_1.weight
transformer.h.32.ln_2.bias
transformer.h.32.ln_2.weight
transformer.h.32.mlp.c_fc.bias
transformer.h.32.mlp.c_proj.bias
transformer.h.33.attn.c_attn.bias
transformer.h.33.attn.c_proj.bias
transformer.h.33.ln_1.bias
transformer.h.33.ln_1.weight
transformer.h.33.ln_2.bias
transformer.h.33.ln_2.weight
transformer.h.33.mlp.c_fc.bias
transformer.h.33.mlp.c_proj.bias
transformer.h.34.attn.c_attn.bias
transformer.h.34.attn.c_proj.bias
transformer.h.34.ln_1.bias
transformer.h.34.ln_1.weight
transformer.h.34.ln_2.bias
transformer.h.34.ln_2.weight
transformer.h.34.mlp.c_fc.bias
transformer.h.34.mlp.c_proj.bias
transformer.h.35.attn.c_attn.bias
transformer.h.35.attn.c_proj.bias
transformer.h.35.ln_1.bias
transformer.h.35.ln_1.weight
transformer.h.35.ln_2.bias
transformer.h.35.ln_2.weight
transformer.h.35.mlp.c_fc.bias
transformer.h.35.mlp.c_proj.bias
transformer.h.36.attn.c_attn.bias
transformer.h.36.attn.c_proj.bias
transformer.h.36.ln_1.bias
transformer.h.36.ln_1.weight
transformer.h.36.ln_2.bias
transformer.h.36.ln_2.weight
transformer.h.36.mlp.c_fc.bias
transformer.h.36.mlp.c_proj.bias
transformer.h.37.attn.c_attn.bias
transformer.h.37.attn.c_proj.bias
transformer.h.37.ln_1.bias
transformer.h.37.ln_1.weight
transformer.h.37.ln_2.bias
transformer.h.37.ln_2.weight
transformer.h.37.mlp.c_fc.bias
transformer.h.37.mlp.c_proj.bias
transformer.h.38.attn.c_attn.bias
transformer.h.38.attn.c_proj.bias
transformer.h.38.ln_1.bias
transformer.h.38.ln_1.weight
transformer.h.38.ln_2.bias
transformer.h.38.ln_2.weight
transformer.h.38.mlp.c_fc.bias
transformer.h.38.mlp.c_proj.bias
transformer.h.39.attn.c_attn.bias
transformer.h.39.attn.c_proj.bias
transformer.h.39.ln_1.bias
transformer.h.39.ln_1.weight
transformer.h.39.ln_2.bias
transformer.h.39.ln_2.weight
transformer.h.39.mlp.c_fc.bias
transformer.h.39.mlp.c_proj.bias
transformer.h.4.attn.c_attn.bias
transformer.h.4.attn.c_proj.bias
transformer.h.4.ln_1.bias
transformer.h.4.ln_1.weight
transformer.h.4.ln_2.bias
transformer.h.4.ln_2.weight
transformer.h.4.mlp.c_fc.bias
transformer.h.4.mlp.c_proj.bias
transformer.h.5.attn.c_attn.bias
transformer.h.5.attn.c_proj.bias
transformer.h.5.ln_1.bias
transformer.h.5.ln_1.weight
transformer.h.5.ln_2.bias
transformer.h.5.ln_2.weight
transformer.h.5.mlp.c_fc.bias
transformer.h.5.mlp.c_proj.bias
transformer.h.6.attn.c_attn.bias
transformer.h.6.attn.c_proj.bias
transformer.h.6.ln_1.bias
transformer.h.6.ln_1.weight
transformer.h.6.ln_2.bias
transformer.h.6.ln_2.weight
transformer.h.6.mlp.c_fc.bias
transformer.h.6.mlp.c_proj.bias
transformer.h.7.attn.c_attn.bias
transformer.h.7.attn.c_proj.bias
transformer.h.7.ln_1.bias
transformer.h.7.ln_1.weight
transformer.h.7.ln_2.bias
transformer.h.7.ln_2.weight
transformer.h.7.mlp.c_fc.bias
transformer.h.7.mlp.c_proj.bias
transformer.h.8.attn.c_attn.bias
transformer.h.8.attn.c_proj.bias
transformer.h.8.ln_1.bias
transformer.h.8.ln_1.weight
transformer.h.8.ln_2.bias
transformer.h.8.ln_2.weight
transformer.h.8.mlp.c_fc.bias
transformer.h.8.mlp.c_proj.bias
transformer.h.9.attn.c_attn.bias
transformer.h.9.attn.c_proj.bias
transformer.h.9.ln_1.bias
transformer.h.9.ln_1.weight
transformer.h.9.ln_2.bias
transformer.h.9.ln_2.weight
transformer.h.9.mlp.c_fc.bias
transformer.h.9.mlp.c_proj.bias
transformer.ln_f.bias
transformer.ln_f.weight
transformer.wpe.weight
transformer.wte.weight
vocab.json