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

RuntimeError: stack expects a non-empty TensorList #4

Open
hjx999222 opened this issue Jan 7, 2025 · 1 comment
Open

RuntimeError: stack expects a non-empty TensorList #4

hjx999222 opened this issue Jan 7, 2025 · 1 comment

Comments

@hjx999222
Copy link

hjx999222 commented Jan 7, 2025

When running your code, I encounter some issues, and sometimes it results in the following bug. Could you please help me resolve it? Thank you!

Traceback (most recent call last):
File "DRAGIN_simplified/src/main.py", line 90, in
main()
File "DRAGIN_simplified/src/main.py", line 76, in main
pred = model.inference(entry["question"], entry["demo"], entry["case"])
File "DRAGIN_simplified/src/generate.py", line 433, in inference
outputs = self.generator.generate(
File "DRAGIN_simplified/src/generate.py", line 240, in generate
atten = torch.stack([atten[l:r, :].mean(dim=-2) for l, r in range_], dim=-2) # 同组的注意者(token),对同一被注意者(word)的attention取平均
RuntimeError: stack expects a non-empty TensorList

@Bocchi7
Copy link
Owner

Bocchi7 commented Jan 8, 2025

It seems that the list range_ is empty, which means the new generated tokens are empty (after deleting the last eos_token). Check if the program enters the branch in line 214 and the list tokens become empty.

        if ended:
            tokens = tokens[:-1]
            # 注:如果tokens中有"</s>"("<s>"也一样),转换成字符串后仍然会保留。因此在这里删掉。

When the situation occurs, you may return the GeneratorOutput instance immediately (see the format as line 267). Remember to set ended as True.

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