tensorflow: tf.data.experimental.enable_debug_mode() doesn't enable breakpoint
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows10
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: Desktop
- TensorFlow installed from (source or binary): pip
- TensorFlow version (use command below): v1.12.1-53831-ga8b6d5ff93a 2.5.0-rc0
- Python version: Python 3.6.8
- CUDA/cuDNN version: CPU
- GPU model and memory: CPU
Describe the current behavior
import tensorflow as tf
tf.data.experimental.enable_debug_mode()
tf.config.run_functions_eagerly(True)
def func(x):
x = x + 1 # BREAKPOINT HERE
return x
dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3])
dataset = dataset.map(func)
# dataset = dataset.map(lambda x: tf.py_function(func, [x], tf.int32)) # doesn't work either
for item in dataset:
print(item)
The breakpoint is not hit. (using pycharm professional 2020.3 )
Describe the expected behavior
I expect that the breakpoint is hit
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (15 by maintainers)
In PyCharm, one can trigger a breakpoint in a function called by
Dataset.map()
by adding the following line within that function:Example:
Also note that you will not need to install
pydevd
separately, as it is bundled with PyCharm. Simply add that line and run debugging.(found in this StackOverflow answer)
pdb.set_trace()
usessignal
, which as per the error message is not supported in the main thread. Either Python 3.8 removed the use ofsignal
inpdb
or added support forsignal
in background threads.Thank you Jay. I was running the repro with an internal build of TensorFlow that uses Python 3.6, which explains the error.
I was able to find a solution to the problem I was encountering. For the example to work with Python 3.6 or Python 3.7, one has to do
pdb.Pdb(nosigint=True).set_trace()
instead ofpdb.set_trace()
.So to summarize, the following program illustrates how to add breakpoints to tf.data user-defined functions:
@cgebbe please let us know if this addresses your question and if it does, feel free to close the issue. Thanks.
I have tested it with installing tf-nightly and adding break point to the source code in post-mortem debug mode with pdb. And the behavior can be re-produced. If we add break point within the function, it is not enabled, while if we add break point in other places (like add a simple print “hello, world” line), it is enabled.
@jayxiaojieshi could you please help investigate this issue? thank you