Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.9%) to scientific vocabulary
Last synced: 10 months ago · JSON representation ·

Repository

Basic Info
  • Host: GitHub
  • Owner: Solvidia
  • License: apache-2.0
  • Language: JavaScript
  • Default Branch: main
  • Size: 3.97 MB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 2 years ago · Last pushed about 2 years ago
Metadata Files
Readme License Code of conduct Citation

README.md

image

solvidia-mem-prof: a Python CPU+GPU+memory profiler with AI-powered optimization proposals

by Emery Berger, Sam Stern, and Juan Altmayer Pizzorno.

About solvidia-mem-prof

solvidia-mem-prof is a high-performance CPU, GPU and memory profiler for Python that does a number of things that other Python profilers do not and cannot do. It runs orders of magnitude faster than many other profilers while delivering far more detailed information. It is also the first profiler ever to incorporate AI-powered proposed optimizations.

AI-powered optimization suggestions

Note

To enable AI-powered optimization suggestions, you need to enter an OpenAI key in the box under "Advanced options". Your account will need to have a positive balance for this to work (check your balance at https://platform.openai.com/account/usage).

Once you've entered your OpenAI key (see above), click on the lightning bolt (⚡) beside any line or the explosion (💥) for an entire region of code to generate a proposed optimization. Click on a proposed optimization to copy it to the clipboard.

You can click as many times as you like on the lightning bolt or explosion, and it will generate different suggested optimizations. Your mileage may vary, but in some cases, the suggestions are quite impressive (e.g., order-of-magnitude improvements).

Quick Start

Installing solvidia-mem-prof:

console python3 -m pip install -U solvidia-mem-prof

or

console conda install -c conda-forge solvidia-mem-prof

Using solvidia-mem-prof:

After installing solvidia-mem-prof, you can use solvidia-mem-prof at the command line, or as a Visual Studio Code extension.

Using the solvidia-mem-prof VS Code Extension: First, install the solvidia-mem-prof extension from the VS Code Marketplace or by searching for it within VS Code by typing Command-Shift-X (Mac) or Ctrl-Shift-X (Windows). Once that's installed, click Command-Shift-P or Ctrl-Shift-P to open the Command Palette. Then select "solvidia-mem-prof: AI-powered profiling..." (you can start typing solvidia-mem-prof and it will pop up if it's installed). Run that and, assuming your code runs for at least a second, a solvidia-mem-prof profile will appear in a webview. Screenshot 2023-09-20 at 7 09 06 PM
Commonly used command-line options: ```console solvidia-mem-prof your_prog.py # full profile (outputs to web interface) python3 -m solvidia-mem-prof your_prog.py # equivalent alternative solvidia-mem-prof --cli your_prog.py # use the command-line only (no web interface) solvidia-mem-prof --cpu your_prog.py # only profile CPU solvidia-mem-prof --cpu --gpu your_prog.py # only profile CPU and GPU solvidia-mem-prof --cpu --gpu --memory your_prog.py # profile everything (same as no options) solvidia-mem-prof --reduced-profile your_prog.py # only profile lines with significant usage solvidia-mem-prof --profile-interval 5.0 your_prog.py # output a new profile every five seconds solvidia-mem-prof (solvidia-mem-prof options) --- your_prog.py (...) # use --- to tell solvidia-mem-prof to ignore options after that point solvidia-mem-prof --help # lists all options ```
Using solvidia-mem-prof programmatically in your code: Invoke using `solvidia-mem-prof` as above and then: ```Python from solvidia-mem-prof import solvidia-mem-prof_profiler # Turn profiling on solvidia-mem-prof_profiler.start() # Turn profiling off solvidia-mem-prof_profiler.stop() ```
Using solvidia-mem-prof to profile only specific functions via @profile: Just preface any functions you want to profile with the `@profile` decorator and run it with solvidia-mem-prof: ```Python # do not import profile! @profile def slow_function(): import time time.sleep(3) ```

Web-based GUI

solvidia-mem-prof has both a CLI and a web-based GUI (demo here).

By default, once solvidia-mem-prof has profiled your program, it will open a tab in a web browser with an interactive user interface (all processing is done locally). Hover over bars to see breakdowns of CPU and memory consumption, and click on underlined column headers to sort the columns. The generated file profile.html is self-contained and can be saved for later use.

solvidia-mem-prof web GUI

solvidia-mem-prof Overview

solvidia-mem-prof talk (PyCon US 2021)

This talk presented at PyCon 2021 walks through solvidia-mem-prof's advantages and how to use it to debug the performance of an application (and provides some technical details on its internals). We highly recommend watching this video!

solvidia-mem-prof presentation at PyCon 2021

Fast and Accurate

  • solvidia-mem-prof is fast. It uses sampling instead of instrumentation or relying on Python's tracing facilities. Its overhead is typically no more than 10-20% (and often less).

  • solvidia-mem-prof is accurate. We tested CPU profiler accuracy and found that solvidia-mem-prof is among the most accurate profilers, correctly measuring time taken.

  • solvidia-mem-prof performs profiling at the line level and per function, pointing to the functions and the specific lines of code responsible for the execution time in your program.

CPU profiling

  • solvidia-mem-prof separates out time spent in Python from time in native code (including libraries). Most Python programmers aren't going to optimize the performance of native code (which is usually either in the Python implementation or external libraries), so this helps developers focus their optimization efforts on the code they can actually improve.
  • solvidia-mem-prof highlights hotspots (code accounting for significant percentages of CPU time or memory allocation) in red, making them even easier to spot.
  • solvidia-mem-prof also separates out system time, making it easy to find I/O bottlenecks.

GPU profiling

  • solvidia-mem-prof reports GPU time (currently limited to NVIDIA-based systems).

Memory profiling

  • solvidia-mem-prof profiles memory usage. In addition to tracking CPU usage, solvidia-mem-prof also points to the specific lines of code responsible for memory growth. It accomplishes this via an included specialized memory allocator.
  • solvidia-mem-prof separates out the percentage of memory consumed by Python code vs. native code.
  • solvidia-mem-prof produces per-line memory profiles.
  • solvidia-mem-prof identifies lines with likely memory leaks.
  • solvidia-mem-prof profiles copying volume, making it easy to spot inadvertent copying, especially due to crossing Python/library boundaries (e.g., accidentally converting numpy arrays into Python arrays, and vice versa).

Other features

  • solvidia-mem-prof can produce reduced profiles (via --reduced-profile) that only report lines that consume more than 1% of CPU or perform at least 100 allocations.
  • solvidia-mem-prof supports @profile decorators to profile only specific functions.
  • When solvidia-mem-prof is profiling a program launched in the background (via &), you can suspend and resume profiling.

Comparison to Other Profilers

Performance and Features

Below is a table comparing the performance and features of various profilers to solvidia-mem-prof.

Performance and feature comparison

  • Slowdown: the slowdown when running a benchmark from the Pyperformance suite. Green means less than 2x overhead. solvidia-mem-prof's overhead is just a 35% slowdown.

solvidia-mem-prof has all of the following features, many of which only solvidia-mem-prof supports:

  • Lines or functions: does the profiler report information only for entire functions, or for every line -- solvidia-mem-prof does both.
  • Unmodified Code: works on unmodified code.
  • Threads: supports Python threads.
  • Multiprocessing: supports use of the multiprocessing library -- solvidia-mem-prof only
  • Python vs. C time: breaks out time spent in Python vs. native code (e.g., libraries) -- solvidia-mem-prof only
  • System time: breaks out system time (e.g., sleeping or performing I/O) -- solvidia-mem-prof only
  • Profiles memory: reports memory consumption per line / function
  • GPU: reports time spent on an NVIDIA GPU (if present) -- solvidia-mem-prof only
  • Memory trends: reports memory use over time per line / function -- solvidia-mem-prof only
  • Copy volume: reports megabytes being copied per second -- solvidia-mem-prof only
  • Detects leaks: automatically pinpoints lines responsible for likely memory leaks -- solvidia-mem-prof only

Output

If you include the --cli option, solvidia-mem-prof prints annotated source code for the program being profiled (as text, JSON (--json), or HTML (--html)) and any modules it uses in the same directory or subdirectories (you can optionally have it --profile-all and only include files with at least a --cpu-percent-threshold of time). Here is a snippet from pystone.py.

Example profile

  • Memory usage at the top: Visualized by "sparklines", memory consumption over the runtime of the profiled code.
  • "Time Python": How much time was spent in Python code.
  • "native": How much time was spent in non-Python code (e.g., libraries written in C/C++).
  • "system": How much time was spent in the system (e.g., I/O).
  • "GPU": (not shown here) How much time spent on the GPU, if your system has an NVIDIA GPU installed.
  • "Memory Python": How much of the memory allocation happened on the Python side of the code, as opposed to in non-Python code (e.g., libraries written in C/C++).
  • "net": Positive net memory numbers indicate total memory allocation in megabytes; negative net memory numbers indicate memory reclamation.
  • "timeline / %": Visualized by "sparklines", memory consumption generated by this line over the program runtime, and the percentages of total memory activity this line represents.
  • "Copy (MB/s)": The amount of megabytes being copied per second (see "About solvidia-mem-prof").

solvidia-mem-prof

The following command runs solvidia-mem-prof on a provided example program.

console solvidia-mem-prof test/testme.py

Click to see all solvidia-mem-prof's options (available by running with --help) ```console % solvidia-mem-prof --help usage: solvidia-mem-prof [-h] [--outfile OUTFILE] [--html] [--reduced-profile] [--profile-interval PROFILE_INTERVAL] [--cpu-only] [--profile-all] [--profile-only PROFILE_ONLY] [--use-virtual-time] [--cpu-percent-threshold CPU_PERCENT_THRESHOLD] [--cpu-sampling-rate CPU_SAMPLING_RATE] [--malloc-threshold MALLOC_THRESHOLD] solvidia-mem-prof: a high-precision CPU and memory profiler. https://github.com/plasma-umass/solvidia-mem-prof command-line: % solvidia-mem-prof [options] yourprogram.py or % python3 -m solvidia-mem-prof [options] yourprogram.py in Jupyter, line mode: %scrun [options] statement in Jupyter, cell mode: %%solvidia-mem-prof [options] code... code... optional arguments: -h, --help show this help message and exit --outfile OUTFILE file to hold profiler output (default: stdout) --html output as HTML (default: text) --reduced-profile generate a reduced profile, with non-zero lines only (default: False) --profile-interval PROFILE_INTERVAL output profiles every so many seconds (default: inf) --cpu-only only profile CPU time (default: profile CPU, memory, and copying) --profile-all profile all executed code, not just the target program (default: only the target program) --profile-only PROFILE_ONLY profile only code in filenames that contain the given strings, separated by commas (default: no restrictions) --use-virtual-time measure only CPU time, not time spent in I/O or blocking (default: False) --cpu-percent-threshold CPU_PERCENT_THRESHOLD only report profiles with at least this percent of CPU time (default: 1%) --cpu-sampling-rate CPU_SAMPLING_RATE CPU sampling rate (default: every 0.01s) --malloc-threshold MALLOC_THRESHOLD only report profiles with at least this many allocations (default: 100) When running solvidia-mem-prof in the background, you can suspend/resume profiling for the process ID that solvidia-mem-prof reports. For example: % python3 -m solvidia-mem-prof [options] yourprogram.py & solvidia-mem-prof now profiling process 12345 to suspend profiling: python3 -m solvidia-mem-prof.profile --off --pid 12345 to resume profiling: python3 -m solvidia-mem-prof.profile --on --pid 12345 ```

solvidia-mem-prof with Jupyter

Instructions for installing and using solvidia-mem-prof with Jupyter notebooks [This notebook](https://nbviewer.jupyter.org/github/plasma-umass/solvidia-mem-prof/blob/master/docs/solvidia-mem-prof-demo.ipynb) illustrates the use of solvidia-mem-prof in Jupyter. Installation: ```console !pip install solvidia-mem-prof %load_ext solvidia-mem-prof ``` Line mode: ```console %scrun [options] statement ``` Cell mode: ```console %%solvidia-mem-prof [options] code... code... ```

Installation

Using pip (Mac OS X, Linux, Windows, and WSL2) solvidia-mem-prof is distributed as a `pip` package and works on Mac OS X, Linux (including Ubuntu in [Windows WSL2](https://docs.microsoft.com/en-us/windows/wsl/wsl2-index)) and (with limitations) Windows platforms. > **Note** > > The Windows version currently only supports CPU and GPU profiling, but not memory or copy profiling. > You can install it as follows: ```console % pip install -U solvidia-mem-prof ``` or ```console % python3 -m pip install -U solvidia-mem-prof ``` You may need to install some packages first. See https://stackoverflow.com/a/19344978/4954434 for full instructions for all Linux flavors. For Ubuntu/Debian: ```console % sudo apt install git python3-all-dev ```
Using conda (Mac OS X, Linux, Windows, and WSL2) ```console % conda install -c conda-forge solvidia-mem-prof ``` solvidia-mem-prof is distributed as a `conda` package and works on Mac OS X, Linux (including Ubuntu in [Windows WSL2](https://docs.microsoft.com/en-us/windows/wsl/wsl2-index)) and (with limitations) Windows platforms. > **Note** > > The Windows version currently only supports CPU and GPU profiling, but not memory or copy profiling. >
On ArchLinux You can install solvidia-mem-prof on Arch Linux via the [AUR package](https://aur.archlinux.org/packages/python-solvidia-mem-prof-git/). Use your favorite AUR helper, or manually download the `PKGBUILD` and run `makepkg -cirs` to build. Note that this will place `libsolvidia-mem-prof.so` in `/usr/lib`; modify the below usage instructions accordingly.

Frequently Asked Questions

Can I use solvidia-mem-prof with PyTest? **A:** Yes! You can run it as follows (for example): `python3 -m solvidia-mem-prof --- -m pytest your_test.py`
Is there any way to get shorter profiles or do more targeted profiling? **A:** Yes! There are several options: 1. Use `--reduced-profile` to include only lines and files with memory/CPU/GPU activity. 2. Use `--profile-only` to include only filenames containing specific strings (as in, `--profile-only foo,bar,baz`). 3. Decorate functions of interest with `@profile` to have solvidia-mem-prof report _only_ those functions. 4. Turn profiling on and off programmatically by importing solvidia-mem-prof (`import solvidia-mem-prof`) and then turning profiling on and off via `solvidia-mem-prof_profiler.start()` and `solvidia-mem-prof_profiler.stop()`. By default, solvidia-mem-prof runs with profiling on, so to delay profiling until desired, use the `--off` command-line option (`python3 -m solvidia-mem-prof --off yourprogram.py`).
How do I run solvidia-mem-prof in PyCharm? **A:** In PyCharm, you can run solvidia-mem-prof at the command line by opening the terminal at the bottom of the IDE and running a solvidia-mem-prof command (e.g., `python -m solvidia-mem-prof `). Use the options `--cli`, `--html`, and `--outfile ` to generate an HTML file that you can then view in the IDE.
How do I use solvidia-mem-prof with Django? **A:** Pass in the `--noreload` option (see https://github.com/plasma-umass/solvidia-mem-prof/issues/178).
Does solvidia-mem-prof work with gevent/Greenlets? **A:** Yes! Put the following code in the beginning of your program, or modify the call to `monkey.patch_all` as below: ```python from gevent import monkey monkey.patch_all(thread=False) ```
How do I use solvidia-mem-prof with PyTorch on the Mac? **A:** solvidia-mem-prof works with PyTorch version 1.5.1 on Mac OS X. There's a bug in newer versions of PyTorch (https://github.com/pytorch/pytorch/issues/57185) that interferes with solvidia-mem-prof (discussion here: https://github.com/plasma-umass/solvidia-mem-prof/issues/110), but only on Macs.

Technical Information

For details about how solvidia-mem-prof works, please see the following paper, which won the Jay Lepreau Best Paper Award at OSDI 2023: Triangulating Python Performance Issues with solvidia-mem-prof. (Note that this paper does not include information about the AI-driven proposed optimizations.)

To cite solvidia-mem-prof in an academic paper, please use the following: ```latex @inproceedings{288540, author = {Emery D. Berger and Sam Stern and Juan Altmayer Pizzorno}, title = {Triangulating Python Performance Issues with {S}calene}, booktitle = {{17th USENIX Symposium on Operating Systems Design and Implementation (OSDI 23)}}, year = {2023}, isbn = {978-1-939133-34-2}, address = {Boston, MA}, pages = {51--64}, url = {https://www.usenix.org/conference/osdi23/presentation/berger}, publisher = {USENIX Association}, month = jul } ```

Success Stories

If you use solvidia-mem-prof to successfully debug a performance problem, please add a comment to this issue!

Acknowledgements

Logo created by Sophia Berger.

This material is based upon work supported by the National Science Foundation under Grant No. 1955610. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.

Owner

  • Name: Solvidia
  • Login: Solvidia
  • Kind: user
  • Location: Santa. Clara, CA
  • Company: Solvidia

Invest in the GPU revolution $SLVDIA

Citation (CITATION.cff)

cff-version: 1.0.0
message: "If you use or refer to Scalene, please cite it as below."
authors:
- family-names: "Berger"
  given-names: "Emery D."
  orcid: "https://orcid.org/0000-0002-3222-3271"
- family-names: "Altmayer Pizzorno"
  given-names: "Juan"
  orcid: "https://orcid.org/0000-0002-1891-2919"
- family-names: "Stern"
  given-names: "Sam"
title: "Scalene: a high-performance, high-precision CPU, GPU, and memory profiler for Python"
version: 1.5.9
date-released: 2022-07-24
url: "https://github.com/plasma-umass/scalene"
preferred-citation:
  type: conference-paper
  authors:
  - family-names: "Berger"
    given-names: "Emery D."
    orcid: "https://orcid.org/0000-0002-3222-3271"
  - family-names: "Stern"
    given-names: "Sam"
  - family-names: "Altmayer Pizzorno"
    given-names: "Juan"
    orcid: "https://orcid.org/0000-0002-1891-2919"
  journal: "17th USENIX Symposium on Operating Systems Design and Implementation (OSDI 2023)"
  month: 7
  start: 51 # First page number
  end: 64 # Last page number
  title: "Triangulating Python Performance Issues with Scalene"
  year: 2023

GitHub Events

Total
Last Year

Dependencies

Pipfile pypi
  • numpy * develop
  • pyperf * develop
  • pytest * develop
  • wheel * develop
  • cloudpickle *
  • nvidia-ml-py *
  • rich *
  • wheel *
Pipfile.lock pypi
  • iniconfig ==2.0.0 develop
  • numpy ==1.25.2 develop
  • packaging ==23.1 develop
  • pluggy ==1.2.0 develop
  • psutil ==5.9.5 develop
  • pyperf ==2.6.1 develop
  • pytest ==7.4.0 develop
  • wheel ==0.41.1 develop
  • cloudpickle ==2.2.1
  • markdown-it-py ==3.0.0
  • mdurl ==0.1.2
  • nvidia-ml-py ==12.535.77
  • pygments ==2.16.1
  • rich ==13.5.2
  • wheel ==0.41.1
requirements.txt pypi
  • Cython >=0.29.28
  • Jinja2 ==3.0.3
  • astunparse >=1.6.3
  • cloudpickle ==2.2.1
  • crdp *
  • ipython >=8.10
  • lxml ==5.1.0
  • packaging ==20.9
  • psutil >=5.9.2
  • pynvml >=11.0,<=11.5
  • pyperf ==2.0.0
  • rich >=10.7.0
  • setuptools >=65.5.1
  • wheel *
setup.py pypi