Wednesday, August 14, 2019

Show a range of data for the histograms/distributions in TensorBoard

Sometimes we want to look at the detail of histograms/distributions for a particular range of steps. However, TensorBoard does not provide zoom-in function for histograms/distributions. In order to do so, you have to change the TensorBoard code. The relevant python code is PYTHON_DIR/site-packages/tensorboard/plugins/histogram/histograms_plugin.py. In funciton histotrams_impl(), you can filter out the steps constraining e.step you needed before the return. In order to show every steps, you also need to set the flag "--samples_per_plugin hisgograms=0" when starting tensorboard.

Wednesday, January 30, 2019

Incorrect handling of CTRL-C in pdb

I usually start a python program I want to debug by running:
    python3 -m pdb -c continue MY_PROGRAM
I can use CTRL-C to break the program, adding break points, and I can CTRL-C multiple times.
However, recently, for some unknown reason, pdb is no longer able to continue to run the program after the second CTRL-C. Looking into pdb.py, I found the following piece of code for handling CTRL-C.

    def sigint_handler(self, signum, frame):
        if self.allow_kbdint:
            raise KeyboardInterrupt
        self.message("\nProgram interrupted. (Use 'cont' to resume).")
        self.set_step()
        self.set_trace(frame)
        # restore previous signal handler
        signal.signal(signal.SIGINT, self._previous_sigint_handler)

Inspecting the value of self._previous_sigint_handler, it points to the default sigint handler, which will break the program. It turns out that the last two lines were removed in python3.5.3 in this commit.

So you can solve this problem by upgrading to a newer version of python3. Or if it's not easy to upgrade (like me, using Ubuntu 16.04, python 3.6.3 or newer is not available), commenting out the last line seems to work.