<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Esteban Gómez on Medium]]></title>
        <description><![CDATA[Stories by Esteban Gómez on Medium]]></description>
        <link>https://medium.com/@eagomez2?source=rss-c2af86aadbf1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_ldxZko-uQsWSpom</url>
            <title>Stories by Esteban Gómez on Medium</title>
            <link>https://medium.com/@eagomez2?source=rss-c2af86aadbf1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 08:26:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eagomez2/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Tracking machine learning experiments with NuBoard]]></title>
            <link>https://medium.com/@eagomez2/tracking-machine-learning-experiments-with-nuboard-cebb0daf9088?source=rss-c2af86aadbf1------2</link>
            <guid isPermaLink="false">https://medium.com/p/cebb0daf9088</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[speech-processing]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[pytorch]]></category>
            <dc:creator><![CDATA[Esteban Gómez]]></dc:creator>
            <pubDate>Sat, 31 Oct 2026 23:33:16 GMT</pubDate>
            <atom:updated>2026-11-01T10:51:28.992Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YdY-wIe7MGjfF1K9uGfHsg.png" /><figcaption>NuBoard: A local experiment tracker that stores every run as a folder.</figcaption></figure><p>When I train a model, I usually run many variations of it: a few learning rates, a couple of seeds, an ablation or two. TensorBoard shows the curves of all of them well. What it doesn’t show is the context around each curve: which config a run used, which commit it came from, whether it finished or crashed, and which data it was trained on. I used to keep that information in configs, saved artifacts of different types or Notion pages.</p><p>In this post I introduce <a href="https://eagomez2.github.io/nuboard/">NuBoard</a>, a free and open-source experiment tracker I have been working on to keep that context next to the curves. Like TensorBoard, it runs locally, with no account and no server to maintain. It is available on <a href="https://pypi.org/project/nuboard/">PyPI</a>, the code is on <a href="https://github.com/eagomez2/nuboard">GitHub</a>, and the <a href="https://eagomez2.github.io/nuboard/">documentation</a> covers everything here in more detail.</p><h3>Motivation</h3><p>I work mostly on audio and speech models. For a long time my training code logged to TensorBoard, and it served me well. A few needs kept coming up, though:</p><ul><li><strong>Listening to outputs across training.</strong> In speech work you want to hear the same utterance at different steps, ideally with a waveform and a spectrogram next to the player. I also want to add notes or annotate certain parts of the audio to remember my findings later on.</li><li><strong>Keeping track of many runs.</strong> With many small ablations, knowing which run had which settings becomes a large part of the work.</li><li><strong>Working offline or under restrictions.</strong> Hosted trackers handle this bookkeeping well, but they need an account, a network connection from the training machine and your data on an external server. That is not always possible on a university cluster or under an NDA.</li></ul><p>NuBoard is my attempt to cover these needs while staying as simple to use as TensorBoard.</p><h3>The main idea: a run is a folder</h3><p>NuBoard is built around one rule: <strong>each run is a self-contained folder</strong> that can be opened, copied or deleted like any other folder. There is no database and no server running while you train.</p><p>When a script starts a run, NuBoard writes a run.json with the config, the git commit and uncommitted diff, the installed packages, the GPUs and the command line. During training, scalars go to an append-only log and media to a file next to it. When the run finishes, the log is compacted into Parquet, which pandas, Polars or DuckDB can also read. A run that is killed loses at most about the last second of data, and it is marked as crashed with its traceback.</p><p>In practice, this means runs can be moved with cp or rsync, combined from two machines with nuboard merge, and removed by deleting their folders. The logging side uses only the Python standard library, so it adds no dependencies to a training environment.</p><h3>Getting started</h3><p>NuBoard supports Python 3.10 or newer on Linux, macOS and Windows. A demo with 4 example projects and 31 runs, one of them still training, shows the main features:</p><pre>pip install nuboard<br>nuboard demo demo-runs --up --open</pre><p>The logging API follows the method names of PyTorch’s SummaryWriter, so code written for TensorBoard needs few changes:</p><pre>import nuboard as nb</pre><pre>config = {&quot;lr&quot;: 3e-4, &quot;batch_size&quot;: 64}</pre><pre>with nb.init(&quot;speech-enhancement&quot;, run_name=&quot;baseline&quot;, config=config) as run:<br>    for step in range(10_000):<br>        loss = train_step()<br>        run.add_scalar(&quot;train/loss&quot;, loss, step)</pre><pre>        if step % 1000 == 0:<br>            clean = enhance(noisy_example)<br>            run.add_audio(&quot;eval/enhanced&quot;, clean, step, sample_rate=16_000)</pre><p>The run is written to ./experiments/speech-enhancement/runs/&lt;run id&gt;/, and nuboard up experiments opens the viewer at http://localhost:6070. Other methods include add_image, add_video, add_text, add_figure (Matplotlib, Plotly, Altair/Vega-Lite and Bokeh), add_histogram, add_pr_curve, add_table and add_point_cloud, each documented in the <a href="https://eagomez2.github.io/nuboard/api/">Python API docs</a>. Logged data can also be loaded back as Arrow tables, for example with nb.load(&quot;speech-enhancement&quot;).scalars(&quot;train/loss&quot;, group_by=&quot;config.lr&quot;).</p><h3>The viewer</h3><p>The screenshots below come from the demo.</p><h3>Runs</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mV2IcqFKHoVpHXEZ.png" /></figure><p>The first page lists runs as a table. A <a href="https://eagomez2.github.io/nuboard/reference/query/">query language</a> filters them, for example where status != crashed or where tags has &quot;sweep&quot; group by config.optim.lr. Runs can be tagged, annotated with notes and given custom properties, all stored inside each run&#39;s folder. Selecting several runs shows their settings side by side, optionally only the keys that differ.</p><h3>Charts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9xQXetiGmuy9M924.png" /></figure><p>Runs can be grouped by any config value, and each group can be drawn as a mean with a ± std band across seeds or in individual experiments. The x-axis can be the step, wall time or another scalar, and zooming loads finer data for the selected range. Health alerts below the chart point out NaN or Inf values, spikes and throughput drops, with the run and step where they happened.</p><h3>Audio and media</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uHdTW3G203xWmx6R.png" /></figure><p>Audio was the original reason for the project. Each logged clip has a player with a waveform, a spectrogram and a slider to compare the same clip across steps. nb.WaveformFigure draws signals over the waveform, such as a voice activity probability, with labelled regions underneath. Images, video, tables, PR curves and distributions can be compared across steps or runs in the same way.</p><h3>Sweeps and other pages</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ApyXJoVafjd4Lcik.png" /></figure><p>For hyperparameter sweeps there is a parallel coordinates plot with a scatter plot per parameter. Selecting a range on an axis lists the best runs inside it. Other pages cover Markdown <strong>reports</strong> that embed logged media and charts, versioned <strong>artifacts</strong> such as datasets and checkpoints with their lineage, and a <strong>timeline</strong> of when each run ran.</p><h3>Performance</h3><p>Logging overhead matters during training, so I compared NuBoard with tensorboardX and torch.utils.tensorboard on a 4-core Linux machine (NuBoard 0.20.1, tensorboardX 2.6.5, PyTorch 2.15.0). Absolute numbers will differ on other machines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*oRQQ5WKQyslLcBaiHm0wGA.png" /></figure><p>NuBoard against tensorboardX and torch.utils.tensorboard: time on the training thread, training slowdown, image logging, writing and reading 1M points, and size on disk</p><ul><li>Logging 50 scalars took 1.8 µs on the training thread with NuBoard, against 4.9 ms with torch.utils.tensorboard and 7.0 ms with tensorboardX.</li><li>In a loop with 1 ms steps and 50 scalars per step, throughput dropped by 2.5% with NuBoard and by 83% and 88% with the TensorBoard writers.</li><li>Writing 1M scalar points to disk took 1.5 s, against 90 and 145 s. Reading them back took 0.14 s, against about 18 s.</li></ul><p>Most of the difference comes from where the work happens. TensorBoard writers build a protobuf event per scalar in the calling thread, while NuBoard queues values and writes them in batches from a background thread. NuBoard has its own costs too: finish() compacts the run at about 2 s per million points, and init spends around 0.1 s recording git and package information. The <a href="https://eagomez2.github.io/nuboard/benchmarks/">Benchmarks page</a> lists all values, and a script in the repository reproduces them.</p><h3>Comparison with TensorBoard</h3><p>TensorBoard is mature, widely integrated and has been the default choice for years. The main differences are:</p><ul><li><strong>Storage.</strong> TensorBoard writes protobuf event files. NuBoard writes a folder with JSON, an append-only log and Parquet.</li><li><strong>Seeds and hyperparameters.</strong> TensorBoard draws a line per run and has an HParams plugin. NuBoard groups runs by config values and has a Sweeps page.</li><li><strong>Run metadata.</strong> NuBoard records config, git state, packages, hardware, console output and system usage automatically.</li><li><strong>Integrations.</strong> TensorBoard is built into Keras, PyTorch Lightning, Hugging Face and many other libraries. NuBoard currently needs a few lines added by hand.</li></ul><p>Existing TensorBoard logs can be imported with nuboard import-tensorboard runs/, without TensorFlow or TensorBoard installed (<a href="https://eagomez2.github.io/nuboard/guide/tensorboard/">import guide</a>). Keep in mind that only compatible features will be translated.</p><h3>Limitations</h3><p>NuBoard is not a team platform: there are no user accounts, permissions or hosted dashboards, so larger teams are likely better served by a hosted tracker. The <a href="https://eagomez2.github.io/nuboard/reference/limitations/">known limitations</a> page lists the ones I am aware of.</p><h3>Conclusion</h3><p>NuBoard is a local experiment tracker that stores each run as a folder, keeps logging off the training thread, and adds run metadata, grouping, sweeps and media views. Whether it suits your work depends on your setup, and the demo is the quickest way to find out.</p><p>NuBoard is free and open source under the MIT license. Feedback, bug reports, ideas and pull requests are very welcome.</p><ul><li>Documentation: <a href="https://eagomez2.github.io/nuboard/">eagomez2.github.io/nuboard</a></li><li>Source code and issues: <a href="https://github.com/eagomez2/nuboard">github.com/eagomez2/nuboard</a></li><li>PyPI: <a href="https://pypi.org/project/nuboard/">pypi.org/project/nuboard</a></li></ul><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cebb0daf9088" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inspecting audio file collections with sndls]]></title>
            <link>https://medium.com/@eagomez2/inspecting-audio-file-collections-with-sndls-aace1c4242ed?source=rss-c2af86aadbf1------2</link>
            <guid isPermaLink="false">https://medium.com/p/aace1c4242ed</guid>
            <category><![CDATA[sound]]></category>
            <category><![CDATA[audio]]></category>
            <category><![CDATA[speech]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[music]]></category>
            <dc:creator><![CDATA[Esteban Gómez]]></dc:creator>
            <pubDate>Mon, 21 Apr 2025 11:11:22 GMT</pubDate>
            <atom:updated>2025-04-22T07:37:02.703Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fVsSziAxo6w5eWoQ2wxXDg.jpeg" /></figure><p>Working with large and diverse audio collections is common in sound engineering, audio research, and audio machine learning. Tasks like calculating total duration, checking sample rates, and identifying the number of channels require precise answers, especially when preparing data for processing. Since manually inspecting each file isn’t feasible at scale, having an easy way of filtering out empty, clipped, or corrupted files becomes a necessary step to ensure smooth machine learning workflows.</p><p>While tools like <a href="https://www.audacityteam.org/">Audacity</a> can help, they aren’t usually practical for massive datasets. Scripting becomes essential, but constantly writing new scripts for each project is time-consuming, tedious and inefficient. On top of that, researchers often need to answer spontaneous, experiment-driven questions — like how much usable data remains after filtering out files meeting a certain condition — making flexible, reusable tools even more valuable.</p><p>With these ideas in mind, we developed sndls, an open source command line tool that is flexible enough to help you answering all those questions and preparing your data in a consistent and replicable way. We think of sndls as <em>“An audio-friendly ls , with a little something extra”</em>. This means that you can use it directly as a command line tool. It can either be installed in your python environment with minimal dependencies, or in a completely independent way using the recent <a href="https://github.com/astral-sh/uv">uv package manager.</a></p><h3>Quickstart</h3><p>To install it using pip simply run (see more installation methods <a href="https://github.com/eagomez2/sndls?tab=readme-ov-file#installation">here</a>)</p><pre>pip install sndls</pre><p>If the tool was correctly installed you can run</p><pre>sndls --version</pre><p>And you should see the author’s name and current package version (0.1.9 at the moment of writing this article) printed in your terminal.</p><p>Then, to display the content of a folder in a similar way to ls run</p><pre>sndls /path/to/folder</pre><p>where<strong> </strong>/path/to/folder is the folder you want to inspect or the current folder if no path is provided. By default, only .wav files will be displayed, but you can add formats using the -e/--extension argument. For example, if you want .flac<strong> </strong>and .wav to be displayed, use</p><pre>sndls /path/to/folder --extension .wav .flac</pre><p>sndls currently supports the following extensions: .aif, .aiff,<strong><em> </em></strong>.mp3, .flac, .ogg<strong><em>,</em></strong> .wav, .wave.</p><p>After running the aforementioned command, you will see an output like the following:</p><pre>/path/to/audio/dir/000_audio.wav    120.0K WAV  PCM_16        50000x1@16000hz     -18.5dBrms:0    -5.0dBpeak:0<br>/path/to/audio/dir/001_audio.wav    115.0K WAV  PCM_16        52000x1@16000hz     -19.0dBrms:0    -5.5dBpeak:0<br>/path/to/audio/dir/002_audio.wav     95.0K WAV  PCM_16        48000x1@16000hz     -17.0dBrms:0    -4.5dBpeak:0<br>/path/to/audio/dir/003_audio.wav    130.0K WAV  PCM_16        65000x1@16000hz     -18.0dBrms:0    -3.0dBpeak:0<br><br>Total file(s):        4<br>Mono file(s):         4<br>Stereo file(s):       0<br>Multichannel file(s): 0<br>Sample rate(s):       16000hz<br>Skipped files:        0<br>Clipped files:        0<br>Anomalous files:      0<br>Silent files:         0<br>Total duration:       14.5 second(s)<br>Minimum duration:     3.0 second(s)<br>Maximum duration:     4.0 second(s)<br>Average duration:     3.6 second(s)<br>Total size:           460.0K<br><br>Elapsed time: 5.0 ms</pre><p>The top rows display the details, while a summary is shown at the bottom The first four columns correspond to file name, file size, file format and subtype, respectively, whereas the last item corresponds to {num_samples}x{num_channels}@{sample_rate} , therefore 50000x1@16000Hz means that /path/to/audio/dir/000_audio.wav has <strong>50000 samples</strong>, is a <strong>mono file</strong> and has a <strong>sample rate of 16kHz</strong>.</p><p>If you want to make your search recursive (i.e. search in folders within folders) you can add the -r/--recursive flag</p><pre>sndls /path/to/folder --extension .wav .flac --recursive</pre><p>Additionally, if you want to save these results to a .csv file to share it later on, you can run</p><pre>sndls /path/to/folder --extension .wav .flac --recursive --csv output_file.csv</pre><p>And your research results will be saved to output_file.csv.</p><h3>Tutorial</h3><p>What you’ve seen so far is <strong><em>just the tip of the iceberg</em></strong>. sndls offers <strong><em>many more</em></strong> powerful options, including:</p><ul><li>Detecting clipped, silent, or anomalous files that may impact machine learning pipelines.</li><li>Computing and verifying SHA-256 hashes to detect file modifications or corruption.</li><li>Filtering or selecting files using <strong><em>python expressions</em></strong> to identify those matching specific criteria.</li><li>Performing fast, metadata-based file inspection.</li><li>Executing post-processing actions, such as removing clipped files, copying files that meet certain conditions, and more.</li><li>Include a preloaded .csv to select or filter your search based on the preloaded data.</li></ul><p>For further details about all other sndls features please go to <a href="https://github.com/eagomez2/sndls?tab=readme-ov-file#tutorial">the tutorial section</a> inside sndls repository. Additionally, you can always run</p><pre>sndls --help</pre><p>to see a detail description of each available parameter (there are many!).</p><p><a href="https://github.com/eagomez2/sndls">GitHub - eagomez2/sndls: An audio-friendly ls, with a little something extra.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aace1c4242ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Profiling neural networks with moduleprofiler in python]]></title>
            <link>https://medium.com/@eagomez2/profiling-neural-networks-with-moduleprofiler-in-python-c566fe2cf896?source=rss-c2af86aadbf1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c566fe2cf896</guid>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[benchmarking]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Esteban Gómez]]></dc:creator>
            <pubDate>Sun, 29 Sep 2024 15:59:12 GMT</pubDate>
            <atom:updated>2024-10-01T09:00:17.958Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AjbItkohLf69uX8hNaKmkg.png" /></figure><p>Neural networks are a powerful and ubiquitous tool nowadays across many domains. In the audio field in particular, state-of-the-art solutions for many tasks such as <a href="https://speechprocessingbook.aalto.fi/Enhancement/Noise_attenuation.html">noise suppression</a>, <a href="https://speechprocessingbook.aalto.fi/Recognition/Speech_Recognition.html">automatic speech recognition (ASR)</a> or <a href="https://speechprocessingbook.aalto.fi/Speech_Synthesis.html">text-to-speech synthesis (TTS)</a>, are based on neural networks. However, such solutions tend to be much more computationally expensive and memory consuming than previously proposed methods.</p><p>Whilst good performance is important, other factors must be considered before moving from research to production. Some of these are:</p><ul><li><strong>Memory footprint:</strong> A model with powerful performance but having many parameters is unsuitable for devices with limited memory. <a href="https://arxiv.org/pdf/2106.08295">Quantization techniques</a> can be applied to use smaller data types for your weights, but often come at the cost of performance.</li><li><strong>Complexity:</strong> A model that performs well but is very expensive to compute may be impractical for devices with limited resources, such as mobile phones or edge devices. In some cases, a cloud-based solution can be used, but it may not be viable if the device lacks internet connection or data privacy is a concern.</li><li><strong>Speed (inference time):</strong> In some cases, such as hearing aids, the key constraint is latency rather than performance. A well-performing solution without a guaranteed maximum latency can be entirely impractical in real-world use.</li></ul><p>Only after evaluating all these factors together, it is possible to determine the suitability of our solution for its intended applications, therefore it is convenient to keep them under control from an early research stage. <a href="https://github.com/eagomez2/moduleprofiler"><strong>moduleprofiler</strong></a> is a recently released open-source package designed with this idea in mind. It can be used to quickly profile your model and gather all this information as you iterate on your solution. It is compatible with <a href="https://pytorch.org/">PyTorch</a> and works directly in python.</p><p>In the next sections, I will show you how to use this package to profile the aforementioned aspects as you work on your model. For further details, you can always refer to <a href="https://eagomez2.github.io/moduleprofiler/">the official documentation</a>.</p><h3>Installation</h3><p>To install <a href="https://github.com/eagomez2/moduleprofiler"><strong>moduleprofiler</strong></a> simply run</p><pre>python -m pip install moduleprofiler</pre><p>To check if it was correctly installed run</p><pre>python -m pip show moduleprofiler</pre><p>If everything is working correctly, you should see the information of the package printed in your terminal. The version as the moment of writing this article is <strong>0.0.4</strong>.</p><h3>Memory footprint</h3><p>The memory your model requires depends on the number of parameters and their data types. It may also store intermediate computations during inference, but this depends on the specific runtime environment, which may be unknown in early research stages.</p><p>With <strong>moduleprofiler</strong> you can quickly generate a description of your model parameters. By default it outputs a dict , but you can also generate a pandas.DataFrame or export the results to a .csv file that can be shared with other researchers.</p><pre>import torch<br>from moduleprofiler import ModuleProfiler<br><br># Profiler <br>profiler = ModuleProfiler()<br><br># Network<br>net = torch.nn.Linear(in_features=8, out_features=32)<br><br># Number of parameters with dict output<br>params_dict = profiler.count_params(module=net)<br>&quot;&quot;&quot;<br>{&#39;__root__&#39;:<br>    {<br>        &#39;type&#39;: &#39;Linear&#39;,<br>        &#39;trainable_params&#39;: 288,<br>        &#39;nontrainable_params&#39;: 0,<br>        &#39;trainable_params_dtype&#39;: torch.float32, <br>        &#39;trainable_params_size_bits&#39;: 9216,<br>        &#39;trainable_params_percent&#39;: 1.0,<br>        &#39;nontrainable_params_percent&#39;: 0.0<br>    }<br>}<br>&quot;&quot;&quot;<br><br># Number of parameters with DataFrame output<br>params_df = profiler.count_params_df(module=net)<br>&quot;&quot;&quot;<br>     module    type  trainable_params  nontrainable_params trainable_params_dtype  trainable_params_size_bits  trainable_params_percent  nontrainable_params_percent<br>0  __root__  Linear               288                    0          torch.float32                        9216                       1.0                          0.0<br>&quot;&quot;&quot;</pre><p>Please see <a href="https://eagomez2.github.io/moduleprofiler/documentation/#moduleprofiler.profiler.ModuleProfiler.count_params">the documentation</a> of this method for further details about available parameters and output formats.</p><h3>Complexity</h3><p>Accurately estimating the complexity of a model is a crucial step to decide the right computational budget to allocate to effectively solve a given task. An overestimated model may contain redundant parameters that increase its memory footprint and do not represent a significant contribution to the task at hand. Moreover, this increases power consumption and drains the battery of mobile devices unnecessarily faster. At a larger scale, this results in higher manufacturing costs and shorter battery lifetimes with no benefit.</p><p>Complexity can be expressed in different units such as FLOPS, MACS or WFLOPS.</p><ul><li><strong>FLOPS (Floating-point Operations per Second): </strong>Indicates<strong> </strong>the number of floating-point arithmetic operations (such as addition, subtraction, multiplication, and division) a system can execute in one second.</li><li><strong>MACS (Multiply-accumulate Operations per Second):</strong> It is the number of MAC operations that a system can perform in one second. A MAC operation consists of multiplying two numbers and then adding the result in a single instruction. Even though such an instruction set is commonly found in modern hardware, it may not always be present, specially in some low-power embedded systems.</li><li><strong>WFLOPS (Weighted Floating-point Operations per Second):</strong> It is similar to FLOPS, but with different weighting depending on the operation that is being computed. <a href="https://latkin.org/blog/2014/11/09/a-simple-benchmark-of-various-math-operations/">Not all arithmetic operations require the same number of cycles</a>, therefore assigning specific weightings is a way to account for such differences.</li></ul><p><strong>moduleprofiler</strong> adopts a time-independent and hardware-agnostic approach. The number of operations (ops) is estimated solely based on the mathematical relationships between the inputs and outputs of each layer within a given module. This methodology facilitates consistent comparisons between model architectures, regardless of their deployment environment or specific hardware features that may incorporate additional performance optimizations. The derivation of different estimations is detailed step by step in <a href="https://eagomez2.github.io/moduleprofiler/reference/">the reference section of the documentation</a> to ensure replicability and transparency.</p><p>The code below shows how to obtain the number of operations each layer of your model computes. In this case you need to provide an input tensor because the number of operations will depends on its dimensions.</p><pre>import torch<br>from moduleprofiler import ModuleProfiler<br><br># Profiler <br>profiler = ModuleProfiler()<br><br># Network<br>net = torch.nn.Linear(in_features=8, out_features=32)<br><br># Example tensor (needed to estimate ops)<br>x = torch.rand((1, 8))<br><br># Estimate ops with dict output<br>ops_dict = profiler.estimate_ops(module=net, input=x)<br>&quot;&quot;&quot;<br>{&#39;__root__&#39;: {&#39;type&#39;: &#39;Linear&#39;, &#39;ops&#39;: 512}}<br>&quot;&quot;&quot;<br><br># Estimate ops with DataFrame output<br>ops_df = profiler.estimate_ops_df(module=net, input=x)<br>&quot;&quot;&quot;<br>     module    type  ops<br>0  __root__  Linear  512<br>&quot;&quot;&quot;</pre><h3>Speed (inference time)</h3><p>The inference speed of your model is determined by the time it takes for the forward function to execute. To obtain accurate performance statistics, multiple inferences are typically run, as the initial inferences can be slower than later ones. This slowdown is often caused by factors such as CUDA initialization (setting up the context, compiling kernels) if the GPU is used, or <a href="https://en.wikipedia.org/wiki/Just-in-time_compilation">Just-In-Time (JIT) compilation</a>. As a result, the first few inferences are usually excluded from statistical measurements to avoid skewed results.</p><p>It’s important to note that a faster model doesn’t necessarily mean it’s computationally cheaper. Some layers such as convolutional layers, can be highly parallelized and take advantage of multiple threads to reduce execution time, even if they involve more computations than layers that are harder to parallelize, for instance, recurrent neural networks. Please read <a href="https://pytorch.org/docs/stable/notes/cpu_threading_torchscript_inference.html">CPU threading and TorchScript inference</a> to know more details.</p><p>With <strong>moduleprofiler</strong> you can easily obtain meaningful statistical aggregations to assess the inference time of your model. A code example is shown below.</p><pre>import torch<br>from moduleprofiler import ModuleProfiler<br><br># Profiler <br>profiler = ModuleProfiler()<br><br># Network<br>net = torch.nn.Sequential(<br>    torch.nn.Linear(in_features=8, out_features=32),<br>    torch.nn.ReLU()<br>)<br><br># Example tensor (needed to estimate ops)<br>x = torch.rand((1, 8))<br><br># Estimate ops with DataFrame output<br>inference_time_df = profiler.estimate_inference_time_df(<br>    module=net,<br>    input=x,<br>    num_iters=1000,<br>    drop_first=10,<br>    aggr=True<br>)<br>&quot;&quot;&quot;<br>     module        type  inference_time_mean_ms  inference_time_max_ms  inference_time_min_ms  ...      os  os_release  cpu_count  total_memory          gpu<br>0  __root__  Sequential                0.012963               2.752166               0.009625  ...  Darwin      23.6.0         10      16384 MB  unavailable<br>1         0      Linear                0.003966               0.213875               0.003459  ...  Darwin      23.6.0         10      16384 MB  unavailable<br>2         1        ReLU                0.004320               2.434583               0.001750  ...  Darwin      23.6.0         10      16384 MB  unavailable</pre><p>In this case num_iters controls how many iterations are performed and drop_first controls how many inferences are dropped before computing aggregated statistics. If you want to obtain per inference information and compute aggregations yourself, you can set aggr=False. Please see <a href="https://pytorch.org/docs/stable/generated/torch.set_num_threads.html">torch.set_num_threads</a> and <a href="https://pytorch.org/docs/stable/generated/torch.set_num_interop_threads.html">torch.set_num_interop_threads</a> to control how threads are managed for CPU inference.</p><h3>Conclusions</h3><p>Properly profiling models from the early stages of research is essential for understanding the trade-offs associated with various architectural decisions you may consider. The suitability of a model for a specific task cannot be completely determined solely by performance-oriented metrics. Moreover, in some cases the most stringent requirements may come from a different descriptor such as maximum latency or maximum allowed memory footprint. For this reason, it is important to jointly consider such aspects when comparing different models.</p><p><strong>moduleprofiler</strong> is a newly released open-source python package that implements a simple interface to obtain this information from any PyTorch model. In addition, it includes <a href="https://eagomez2.github.io/moduleprofiler/reference/">a reference documentation </a>that provides a step-by-step explanation of how the complexity of different layers is estimated, thereby enhancing replicability of the results</p><p><a href="https://github.com/eagomez2/moduleprofiler">GitHub - eagomez2/moduleprofiler: Free open-source package to profile PyTorch models.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c566fe2cf896" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>