-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logits的获取 #1933
Comments
主要是想知道log probs是怎么获取结果的,需要取模型每次解码的logits分数,有什么办法获取每次解码过程中所有词表对应的logits输出吗? |
仔细看了代码,不知道你们是否有支持输出greddy search配合输出logits的计划,现在虽然可以通过设置top p和top k实现greedy search,但是输出的logprobs只有一个token,无法查看不同token之间的概率分布。另外一点,虽然可以通过设置topk的数量看到指定数量token的token概率,但是这样输出的结果变成随机了,不利于确定性任务的部署(比如分类任务,毕竟从topk里面随机采样待来的随机性不能接受) |
@AIFFFENG hi, you can refer to this example: https://lmdeploy.readthedocs.io/en/latest/inference/vl_pipeline.html#calculate-logits |
这个只是得到了输入的logits吧? |
You can set Line 52 in f613814
|
是的,我确实可以通过设置logprobs得到概率,但是这样需要同时设置topk才能得到topk的概率,我想要的是能够支持输出原始的logits信息(词表大小,同时greddy search) |
在这篇文档中,介绍了获取 logits 的方式。 from transformers import AutoTokenizer
from lmdeploy import pipeline
model_repoid_or_path='internlm/internlm2_5-7b-chat'
pipe = pipeline(model_repoid_or_path)
tokenizer = AutoTokenizer.from_pretrained(model_repoid_or_path, trust_remote_code=True)
# logits
messages = [
{"role": "user", "content": "Hello, how are you?"},
]
input_ids = tokenizer.apply_chat_template(messages)
logits = pipe.get_logits(input_ids) |
我做过这个的实验,但是这个获取的logits应该是输入的logits吧?我看模型并没有输出其他的token |
如果是要所有output_token的logits,确实没有这个功能。可以看看其他框架,或者用transformers吧 |
其他框架支持的不是很好。我有个疑问,按理说解码过程应该是会输出词表中每个token的概率吧,然后这时候根据topk和topp去选取对应的token,最后再通过log softmax得到ogprob,既然可以得到logprob,按理说只要将解码过程中每个token的概率保存并且返回即可吧?(我在c++源码里面有发现is_return_logits等变量(我猜是这个),在python的generate 传入该变量,模型报错了),总结来说还是想很好奇框架不支持返回logits的原因,理论上应该保存即可实现。 |
我个人的看法是:
|
感谢回复,前两点确实解决了我对于输出logits的困惑,我解释一下第三点的原因。 |
Checklist
Describe the bug
模型为Qwenvl
Reproduction
image_list =[image_path]*100
prompts = [(instruct_question, load_image(img_url)) for img_url in image_list]
response = pipe(prompts,gen_config=gen_config)
批量推理
Environment
Error traceback
No response
The text was updated successfully, but these errors were encountered: