elastic / ml-cpp

Machine learning C++ code
Other
149 stars 62 forks source link

[ML] Framework for testing effect of various MKL settings #2714

Open edsavage opened 2 weeks ago

edsavage commented 2 weeks ago

Checkpointing current status for visibility.

Contains the changes to build system required to compile and link code referring to MKL functions, along with various scripts etc. to exercise those functions and gather data on the impact that they may have.

Tools and packages needed for testing MKL setting with pytorch_inference

Compiling the code.

Checkout the code in this PR on a linux x86_64 machine and configure CMake as normal, but ensure that pytorch_inference is linked against libtcmalloc. This can be done with e.g.

cmake -B cmake-build-relwithdebinfo  -DLINK_TCMALLOC
cmake --build cmake-build-relwithdebinfo -j`nproc` -t install

Running pytorch_inference

There are several python scripts in the bin/pytorch_inference directory that are capable of running pytorch_inference on various models. Examples are

python3 main.py elser_model_2_linux-x86_64.pt ../../build/distribution/platform/linux-x86_64/bin/pytorch_inference inference_requests.json --num_threads_per_allocation 8 --cache_size 274756282
python3 evaluate.py bert-base-uncased-fill-mask.pt --memory_benchmark --num_threads_per_allocation=4

These scripts can be tweaked in various ways before running. In the case of evaluate.py edit the script to:

Viewing results

If running pytorch_inference under heapprof there will be a reasonably large number of output files generated, e.g. /tmp/heapprof.0040.heap. These files need to be post processed by a tool called pprof e.g.:

pprof ../../build/distribution/platform/linux-x86_64/bin/pytorch_inference /tmp/heapprof.0040.heap --pdf > pytorch_inference_heapprof_0040.pdf

to generate a pdf file of the heapprof results (other output formats are available).

Heapcheck has its own GUI especially for viewing results - https://github.com/KDE/heaptrack?tab=readme-ov-file#heaptrack_gui but can also display results as plain text.