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

UnboundLocalError: local variable 'label' referenced before assignment #26

Closed
demongolem-biz opened this issue Feb 3, 2022 · 2 comments

Comments

@demongolem-biz
Copy link

If I set the code to run with cpu instead of gpu, I get the above error.

This happens because in train function of FewShotNERFramework in framework.py, label is only defined if torch.cuda.isavailable is true. So then there is an assert statement a few lines later that is outside of that if block which uses label, that is assert logits.shape[0] == label.shape[0], print(logits.shape, label.shape). But further lines also depend upon label being present.

I get a RuntimeError: CUDA error: out of memory should I try to run with the GPU.

The else case for cuda not available should be dealt with better other than this assert statement in my opinon even if running this code with cpu would not be supported.

@demongolem-biz
Copy link
Author

If we brought label = torch.cat(query['label'], 0) before the if block would that be proper?

@yulinchen99
Copy link
Collaborator

If we brought label = torch.cat(query['label'], 0) before the if block would that be proper?

yes, that would be correct.

yulinchen99 added a commit that referenced this issue Feb 5, 2022
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