TracerWarning in assert statement


#1

I am running the following piece of code and I am not sure what the warning implies how to correct it

/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:116: 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!

/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:119: 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!

/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:122: 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!


#2

The warning is probably caused by your assertions. The PyTorch JIT converts tensor shapes to tensors, and your assert statements convert tensors to a boolean. There’s nothing to correct, unless you want to remove your assertions.