Launch MLflow UI or Tensorboard on a remote server with port forwarding

MLflow tracking or Tensorboard are great to visualize the results of experiments running on a remote server. Actually they’re great to keep track of any sort of computation involving repeated runs with changing parameters, not just machine learning runs. To open the UI in the browser of a local machine, you can use SSH port forwarding. If you already have a VS Code window open, the embedded terminal automates port forwarding after you type the command....

February 1, 2022

Ray cheatsheet

This cheatsheet lists some things I need with Ray and that are a bit hard to find in the documentation. How to restart fail runs in Ray Tune From the docs: # Rerun ONLY failed trials after an experiment is finished. tune.run(my_trainable, config=space, local_dir=<path/to/dir>, resume="ERRORED_ONLY") How to resume an experiment with no name with Ray Tune You can resume checkpointed experiments with ray.tune(name=name, resume=True, ...). If you didn’t specify a name for the experiment you want to resume, Ray assigned a name based on the date and time you launched the experiment, such as run_2021-08-18_02-39....

August 21, 2021

How to enlarge images in TensorBoard

Images can be quite small on Tensorboard when the dataset has small dimensions. Instead of awkwardly zooming the whole board with ctrl +, you can actually pass the maximum number of images per row to the grid constructor on PyTorch: images, _ = batch grid = torchvision.utils.make_grid(images, nrow=2) writer.add_image("images", grid, 0) The default setting puts 8 images per row (on the left in the picture). If the zoomed images (on the right) are now too large, you can still collapse the grid to a miniature by clicking on it....

August 12, 2021

How to get all the hooks of a tensor in PyTorch

Hooks are useful to debug and tinker with your PyTorch models. But how do you debug the hooks themselves? Suppose you have a tensor with some hooks, for instance: t = torch.tensor(1.0, requires_grad=True) def hook_1(grad): return grad * 2 def hook_2(grad): return grad + 1 t.register_hook(hook_1) t.register_hook(hook_2) What if you are adding this kind of hook at different places in your code? The order matters, so you might want to print all the hooks for your tensor to check in which order they are called....

June 22, 2021

How to download Imagenet

The official Imagenet website is a pain to navigate. If you want to download the most common version of Imagenet (with about 150 gigabytes of images), you can get it from Kaggle: https://www.kaggle.com/c/imagenet-object-localization-challenge/data?select=imagenet_object_localization_patched2019.tar.gz. But if you prefer to download from the command line without logging-in through Kaggle, or if you are looking for the full version of Imagenet (with 1.5 terabytes of images), you can use AcademicTorrents. AcademicTorrents is a great way to get datasets and can be faster than a direct download!...

June 5, 2021

How to run a command with multiple arguments in GNU Parallel

GNU Parallel is incredibly useful to run the same command multiple times in parallel. However, I spent an unreasonable amount of time trying to find how to use it for commands that take an arbitrary number of arguments. The manual and online discussions explain how to pipe the output of a command into another while splitting it into chunks. If you just want to read multiple lines and feed them as space-separated arguments to a command, you can simply use the -N argument....

May 6, 2021

Stop asking for the SSH key passphrase (Git in VS Code terminal)

I am using Git from the VS Code terminal on Ubuntu. For some reason, it started to ask me to unlock my SSH key every time I wanted to push/pull. Here are a few things to try first: This is usually fixed by configuring the SSH agent, for instance as explained here in the VS Code documentation. If you are using Zsh, you can also configure the SSH agent with a plugin, such as this one for Oh My Zsh or this one for Zim....

May 2, 2021

LaTeX: left arrow to sample an element uniformly at random

Here is a command to draw a left arrow with a dollar sign. It is commonly used to denote a variable assignment uniformly at random from a given set. LaTeX notation to sample a random elementLaTeX notation to sample a random element $\alpha \overset{{\scriptscriptstyle\$}}{\leftarrow} \mathbb{G}$ Some people use the letter R instead of the dollar sign $. Here are a few variants: LaTeX notation to sample a random element (variants)LaTeX notation to sample a random element (variants)...

April 14, 2021

Conda commands for Python environments

This cheatsheet contains all the commands that I use to manage my Python virtual environments with Conda. I also included some Pip commands at the bottom of the page. Install Conda wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && bash Miniconda3-latest-Linux-x86_64.sh Create a new environment conda create -n myenv python=3.8 Clone an environment conda create -n myclone --clone myenv List all the Conda environments conda env list Delete an environment conda deactivate myenv conda remove -n myenv --all Save and load an environment with Conda Save the environment: conda list --export > requirements....

October 11, 2020

Using a dual-screen wallpaper on Ubuntu

You don’t need any fancy tool to span a wallpaper across multiple monitors on Ubuntu. Indeed, this is natively supported by Gnome Tweaks, the go-to application for Gnome desktop personalization. If you don’t have Gnome Tweaks already, you can install it with sudo apt install gnome-tweaks. Then, you can just select your wallpaper in the Appearance tab of Gnome Tweaks and choose the “Wallpaper” option. Dual wallpaper on UbuntuDual-screen wallpaper on Ubuntu with Gnome Tweaks....

October 4, 2020