Conversation
|
||
![debug debug](debugging_images/debug_debug.png) | ||
|
||
And then once you hit your breakpoint, you can inspect variables or step through code to your heart's content: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only works the first time. After that, we have created a non-empty serialization_dir
, which prevents the debug process from starting again. The workarounds are
- Switch to CLI and delete
serialization_dir
, - Edit the run configuration and set a "before launch" command.
- Edit the appropriate default configuration and set a "before launch" command.
None is ideal, 3 is the least annoying. However, you should document how to setup the "before launch" command correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, but I can just do that in python
Note: Since there is quite a bit of boilerplate to setup, it would help to have inlined code in the tutorial, not just bitmaps. I can't copy/paste from bitmaps... |
|
||
First, create a wrapper script that puts your command-line args into `sys.argv` and calls `main()`: | ||
|
||
![wrapper script](debugging_images/debug_wrapper_with_rmtree.png) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BE VERY CAREFUL TO NOT DO THIS DURING ACTUAL TRAINING
Note that if you're using Beaker, this is a non-issue. Each Beaker run is isolated from the others and doesn't compete for the same output directory.
Yes, I know you're targeting an audience beyond AI2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you're using beaker, you're necessarily not debugging using pycharm, and so you don't need to use this script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just used a PyCharm-for-debug/Beaker-for-train setup last week. Happy to demonstrate in person.
Are you guys editing comments live? Either I'm having a forgetful moment, or I added a note on how "Attach to Process" has poor ergonomics, which I can't find anymore. |
@@ -0,0 +1,133 @@ | |||
# How to Debug Your AllenNLP Code | |||
|
|||
Recently several people have asked how to debug allennlp code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd change this warning:
Recently some people have asked how to debug AllenNLP code using PyCharm, so we put together this "how to". The first section covers debugging in PyCharm, and the second section covers debugging in VSCode.
It turns out that `allennlp` is just (in essence) an alias for `python -m allennlp.run`, so you could equivalently do | ||
|
||
``` | ||
python -m allennlp.run train experiments/venue_classifier.json -s /tmp/your_output_dir_here --include-package my_library -o '{"trainer": {"cuda_device": -1}}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is your motivation for including this? You might consider explaining why in the proceeding text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the motivation is that (as far as I can tell) the "attach to local process" will only find "python" processes, so if you do allennlp train
you can't attach to it. I'll make that clearer
|
||
![attach to local process](debugging_images/attach_to_process_2.png) | ||
|
||
and get results in the debugger: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a long delay before anything started appearing in the console.
|
||
![breakpoint](debugging_images/breakpoint.png) | ||
|
||
Right-click in the editor and choose "Debug": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm setting the breakpoint outside of my startup.py
script (what I named the above) then I need to go to File -> Debug... -> startup.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, this is unclear, I meant go back to the wrapper script, I'll fix that
|
||
![attach to local process](debugging_images/attach_to_process_3.png) | ||
|
||
## How to Debug in PyCharm, Using "Run > Debug" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This worked great for me.
|
||
![inspect variable](debugging_images/inspect_variable.png) | ||
|
||
# How to Debug in VSCode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never used VSCode--so I didn't test this.
Thanks! Looks really good. You're tempting me to download VSCode :)
One extra nit, the vertical picture of the icons just after
https://github.com/allenai/allennlp/blob/master/tutorials/how_to/using_a_debugger.md#how-to-debug-in-vscode
is a bit large/zoomed in? On aesthetic reasons, you might want to consider
a consistent size of the fonts in the images/text. Maybe we can ask Aaron
to help with that when he's back in August?
…On Thu, May 31, 2018 at 11:36 AM, Joel Grus ***@***.***> wrote:
Merged #1312 <#1312>.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#1312 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAlivm1BIjWd9KLZEmVGpEH3tkksq-VFks5t4DhFgaJpZM4UUO1y>
.
|
VSCode is good, it's what I use |
* add debugging how to * clean up * add line to delete serialization directory * include code as code not as png * add VSCode section * formatting * pr feedback * allow allennlp command
No description provided.