This example shows how to run Nano GPT from Spring Boot microservice using JEP technology.
To run this application you can use bootRun task, or start manually GptServiceExampleApplication from IDE.
Before run you need to perform build task to install jep-distro module from Maven Central and Nano GPT sources from github master branch
Then open local Swagger frontend http://localhost:8080/swagger-ui/index.html
You can use 2 endpoints:
- /gpt/train
- /gpt/poem
Here you need train nural network first, and then generate a poem based on your first phrase.
You can debug it using python remote debugger.
- Install python plugin
- To enable debugging you need to setup DEBUG_PYTHON_EGG environment variable with path to pydevd-pycharm.egg.
This is pydevd-pycharm code, so you don't need to install it via pip. It is always matched with python plugin version.
Usually it is located in IntelliJ IDEA python plugin directory,
for example on Windows:
DEBUG_PYTHON_EGG=%APPDATA%\JetBrains\IntelliJIdea2022.3\plugins\python\debugger-eggs-output\pydevd-pycharm.egg
You can also set the host and port viaDEBUG_PYTHON_HOSTandDEBUG_PYTHON_PORT, respectively. Otherwise, those will default tolocalhostand52225. - Now, add a "Run/Debug Configuration" in Intellij and choose the "Python Debug Server". Configure the host name and port according to the values set above.
You should also set a proper "Path mapping" according to your local configuration. For example:
Local path :D:/Workspace/joker/gpt-service-example/build/python/nanoGPT-master
Remote path:D:/Workspace/joker/gpt-service-example/build/python/nanoGPT-master
Local path :D:/Workspace/joker/gpt-service-example/src/main/resources
Remote path:D:/Workspace/joker/gpt-service-example/build/resources/main - Start the Python Debug Server (run configuration prepared above).
- Set breakpoint in some python code you want to inspect
- Run your code
GptServiceExampleApplication. - Start training or generate poem through swagger. It will connect to remote debugger and stop on break point where you can inspect the state.
You can switch on python profiling by setting environment variable:
PROFILER_STAT_FILE - file name of debug output for example profiler_stats.gprof
and set the following system property:
-Dpython.interpreters.number=1 - to make processing in one thread for debug output dump to be happened.
This initializes profile decorator which uses embedded Python cProfiler
You can use @profile annotation to place on any function you need to profile.
After finishing, profiling statistics will be dumped into PROFILER_STAT_FILE.
You can use https://sourceforge.net/projects/qcachegrindwin/ to analyse this output.
To open it in qcachegrind/kcachegrind you need to convert it to callgrind format
pip install pyprof2calltree
pyprof2calltree -i profiler_stats.gprof -o profiler_stats.kgrind
also you can convert from gprof to dot
pip install gprof2dot
gprof2dot -f pstats profile_results.prof | dot -Tpng -o profile_results.png