{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# This file is part of nannos\n# License: GPLv3\n%matplotlib notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Benchmark Modal\n\nNumerical backends performace comparison, with GPU acceleration, as run on Modal (https://modal.com)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nbackends = [\"numpy\", \"scipy\", \"autograd\", \"jax\", \"torch\"]\ninputs = [(b, \"cpu\") for b in backends]\ninputs += [(b, \"gpu\") for b in [\"jax\", \"torch\"]]\n\n\nt = []\n\nplt.figure()\n\nfor i in inputs:\n backend, device = i\n fname = f\"modal/benchmark_{backend}_{device}.npz\"\n arch = np.load(fname)\n times = arch[\"times\"]\n times_all = arch[\"times_all\"]\n real_nh = arch[\"real_nh\"]\n nh = arch[\"nh\"]\n\n t.append(times_all)\n\n plt.plot(real_nh, times_all, \"-o\", label=f\"{backend} {device}\")\nplt.legend()\nplt.xlabel(\"number of harmonics\")\nplt.ylabel(\"time [s]\")\nplt.xscale(\"log\")\nplt.yscale(\"log\")\n\n\nplt.figure()\nfor j, i in enumerate(inputs):\n backend, device = i\n plt.plot(real_nh, t[0] / t[j], \"-o\", label=f\"{backend} {device}\")\nplt.legend()\nplt.xlabel(\"number of harmonics\")\nplt.ylabel(\"speedup vs numpy\")\nplt.xscale(\"log\")\n# plt.yscale(\"log\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import nannos.utils.jupyter\n%nannos_version_table" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.5" } }, "nbformat": 4, "nbformat_minor": 0 }