How to debug programs efficiently?
Hello, thank you for your outstanding work.
My local program runs well, but when I try to modify the program, I find that it cannot be debugged like traditional Python code. The program does not stop at the breakpoints set in PyCharm. By checking the output in the command line window, I found that the main program works by calling scripts and passing arguments.:
Therefore, my current debugging method is to copy these commands:
--batch_size 1 --caption_extension .txt --caption_separator , --debug --frequency_tags --max_data_loader_n_workers 2 --onnx --remove_underscore --repo_id SmilingWolf/wd-convnext-tagger-v3 "D:\Code\Python\paper code\2
and paste them into the Run/Debug Configurations window in PyCharm for debugging:
Generally, there is no problem, but sometimes it may cause some issues that should not occur due to different paths of the main function. For example, when I directly input the command to call tag_images_by_wd14_tagger.py to tag images, I found that this method cannot find the wd14_tagger_model folder downloaded when running the kohya GUI normally. Instead, it creates a new wd14_tagger_model folder and re-downloads the model with tag_images_by_wd14_tagger.py as the root directory, as shown in the following image:
This leads to inconsistent behavior of the kohya GUI.
Additionally, this method of debugging by passing arguments through scripts is quite cumbersome because the multi-line commands with line breaks printed during the normal operation of the kohya GUI cannot be directly pasted into PyCharm's Run/Debug Configurations, as the Run/Debug Configurations requires the arguments to be on a single line. This forces me to carefully remove the extra symbols.
So, I would like to ask how you debug efficiently on your side?
Short answer... I don't really use a python debug mode... I just run the command through the GUI and look at any tracefiles... If you run them outside the GUI the internal environment variables and path that are set will not properly apply and result in what you are observing...
Wow, that's impressive! You managed to write such a large project without using an IDE for debugging!
I have the following two questions for you:
1.Could you please clarify what you mean by tracefiles? Are they the log information generated by the terminal?
2.When you mention GUI, are you referring to pages in the browser or to the command-line terminal generated by double-clicking gui.bat?
Hi,
I should have said traceback output when something crash while running the python code. This is usually what I go by to track the source of the issue. I do use an IDE (VSCode) but I have never used the debug python feature while troubleshooting... Perhaps I need to read more about it and see if I could get more productive using that.
When I mention GUI I mean the actual web interface used to enter the training parameters and the resulting script call used to run the sd-scripts from kohya_ss. Double-clicking the gui.bat will start the GUI.
Thank you very much for your explanation. I understand it roughly, which makes me think you are really awesome!
The reason I use the debug feature of IDEs (such as VS Code) is that it allows me to clearly see the value of any variable, whether it's local or global, at any line of code during the current execution state: