Skip to content
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

有流的返回方式吗? #34

Open
tianlichunhong opened this issue Jul 28, 2023 · 2 comments
Open

有流的返回方式吗? #34

tianlichunhong opened this issue Jul 28, 2023 · 2 comments

Comments

@tianlichunhong
Copy link

这个代码 model.generate(tokenizer(prompt, return_tensors='pt').input_ids.cuda(), max_new_tokens=4096, streamer=streamer) 确实可以显示答复的内容,但是能否提供一个流返回的代码样例?类似下面的代码:
for respond in model.generate(tokenizer(prompt, return_tensors='pt').input_ids.cuda(), max_new_tokens=4096, streamer=streamer) :
print(respond,end="", flush=True)
上面代码是运行不正确的。请各位老大给一个正确的食用方式。谢谢!

@shiyemin
Copy link
Contributor

steamer本身就是流返回,这部分可以看一眼transformers库的用法

@tianlichunhong
Copy link
Author

steamer本身就是流返回,这部分可以看一眼transformers库的用法

我知道,它只是model.generate执行后,结果直接流打印在屏幕中,为什么不是直接model.generate的返回值,而是打印在屏幕?如果获得流的返回?因为我想将流发送到其他程序处理。我利用多线程的方式读取streamer,但是这个有点复杂。还有其他方法吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants