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

Make assertions only if actually chunking forward #13598

Merged
merged 1 commit into from
Sep 24, 2021
Merged

Make assertions only if actually chunking forward #13598

merged 1 commit into from
Sep 24, 2021

Conversation

joshdevins
Copy link
Contributor

This moves the assertion on checking input dimensions into a block that will only be called if the function is actually going to do chunking forward. This is often not the case at inference time and PyTorch tracing a model with this assertion in it leads to a tracing warning.

TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  input_tensor.shape[chunk_dim] == tensor_shape for input_tensor in input_tensors

@joshdevins joshdevins marked this pull request as draft September 16, 2021 10:28
@LysandreJik
Copy link
Member

Asking @patrickvonplaten for review as it's on reformer

@joshdevins
Copy link
Contributor Author

joshdevins commented Sep 20, 2021

@LysandreJik This appears when tracing sentence-transformers/all-MiniLM-L12-v2, which doesn't seem to be a reformer 🤔

@patrickvonplaten
Copy link
Contributor

Hey @joshdevins,

I'm happy with the PR! Can you rebase to current master - it should fix the failing tests I think. Also could you maybe replace the assert statement by if ... raise ValueError? We are trying to move away from assert statements :-)

@joshdevins joshdevins marked this pull request as ready for review September 22, 2021 11:45
This moves the assertion on checking input dimensions into a block that will only be called if the function is actually going to do chunking forward. This is often not the case at inference time and PyTorch tracing a model with this assertion in it leads to a tracing warning.

TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  input_tensor.shape[chunk_dim] == tensor_shape for input_tensor in input_tensors
Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@patrickvonplaten patrickvonplaten merged commit 678bb24 into huggingface:master Sep 24, 2021
@joshdevins joshdevins deleted the tracing-warn-chunking-forward branch September 24, 2021 08:27
stas00 pushed a commit to stas00/transformers that referenced this pull request Oct 12, 2021
This moves the assertion on checking input dimensions into a block that will only be called if the function is actually going to do chunking forward. This is often not the case at inference time and PyTorch tracing a model with this assertion in it leads to a tracing warning.

TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  input_tensor.shape[chunk_dim] == tensor_shape for input_tensor in input_tensors
Albertobegue pushed a commit to Albertobegue/transformers that referenced this pull request Jan 13, 2022
This moves the assertion on checking input dimensions into a block that will only be called if the function is actually going to do chunking forward. This is often not the case at inference time and PyTorch tracing a model with this assertion in it leads to a tracing warning.

TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  input_tensor.shape[chunk_dim] == tensor_shape for input_tensor in input_tensors
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.

None yet

3 participants