Skip to content

Fix _print_stream crash when the stream is empty - #794

Open
rootkiller6788 wants to merge 1 commit into
google-deepmind:mainfrom
rootkiller6788:fix-print-stream-empty-iterator
Open

Fix _print_stream crash when the stream is empty#794
rootkiller6788 wants to merge 1 commit into
google-deepmind:mainfrom
rootkiller6788:fix-print-stream-empty-iterator

Conversation

@rootkiller6788

Copy link
Copy Markdown

ChatSampler 开 print_stream 时,如果模型一个 token 都没生成(max_new_tokens=0,或者 cache_length 太小一上来就满了),_print_stream 会在循环结束后去用没绑定的循环变量 state,直接抛 UnboundLocalError,用户根本看不出是哪的问题。

改成在循环里记下最后一个 state,流是空的话抛一条明确的 ValueError,提示大概率是 max_new_tokens=0 或 cache 满了(建议加大 cache_length)。非空流的行为完全不变。

顺带把之前压着这个问题的 # pylint: disable=undefined-variable,undefined-loop-variable 去掉了,因为现在这个 bug 真正被处理了。

The streaming loop referenced the loop variable `state` after the loop, so
an empty iterator (e.g. max_new_tokens=0 or a cache that is already full)
raised UnboundLocalError instead of a useful error. Track the last state
and raise a clear ValueError when nothing was generated.
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

Successfully merging this pull request may close these issues.

1 participant