vmoens
banner
vmoens.bsky.social
vmoens
@vmoens.bsky.social
Member of technical staff @periodiclabs
Open-source/open science advocate
Maintainer of torchrl / tensordict / leanrl

Former MD - Neuroscience PhD

https://github.com/vmoens
Congrats Eugene!
October 2, 2025 at 5:29 PM
Follow me for more CS cuisine!
March 19, 2025 at 2:57 PM
MLGym makes it super easy to set up complex tasks to be solved by LLMs. Honestly one of the most intuivite APIs I have ever seen in that space!
February 21, 2025 at 4:44 PM
After that, your LLM reads these instructions, and outputs prompts with some thoughts. The commands are executed in the docker's bash, and the result is returned to the agent.
February 21, 2025 at 4:44 PM
Good old cProfile with snakeviz is pretty cool too jiffyclub.github.io/snakeviz/
Again, not for cuda ops, and not as fine-grained as line-profiler but quite useful for macro-tracking of compute time
SnakeViz
SnakeViz is a browser based graphical viewer for the output of Python's cProfile module.
jiffyclub.github.io
February 19, 2025 at 5:13 PM
torch.utils.benchmark.Timer is amazing to assess the runtime of a whole isolated piece of code, but be mindful that the way it plays with global variables isn't always obvious and may differ from time.time() on occasions
February 19, 2025 at 5:13 PM
I use line_profiler to check the code line-by-line (careful: cuda ops re async, do not trust it for these!) - very useful to check cpu-overhead pypi.org/project/line...
line-profiler
Line-by-line profiler
pypi.org
February 19, 2025 at 5:13 PM
The profilers I use: PyTorch profiler to view the time spend doing the various ops of my code. It can reliably show you what's going on for a single iteration of your function. pytorch.org/tutorials/re...
PyTorch Profiler — PyTorch Tutorials 2.6.0+cu124 documentation
pytorch.org
February 19, 2025 at 5:13 PM
In general, in-place operations are not preferable to regular ones (you won't gain much mem improvement or speed-ups). Don't load your code with ReLU(inplace=True), mul_, add_ if not absolutely necessary.
February 19, 2025 at 5:13 PM
Using hydra or similar fancy config objects: Avoid calling cfg.attribute often in the code. Instead, cache the args values in your script as global workspace variables.
February 19, 2025 at 5:13 PM
If you have a tiny model (robotics, RL) cpu-overhead bound, avoid frequent calls to eval() or train() in eager mode, or model.parameters() or anything that goes through your model. Prefer cached versions of these calls.
February 19, 2025 at 5:13 PM
Avoid calling tensor.item() in between cuda operations. This triggers a cuda synchronization and blocks your code. Do the logging after all code (forward / backward / optim) has completed. See how to find sync points here)
February 19, 2025 at 5:13 PM
Avoid pinning memory in your code unless you thoroughly tested that it accelerates runtime (see this tutorial for more info). As an aside, pin_memory is also less safe! pytorch.org/tutorials/in...
A guide on good usage of non_blocking and pin_memory() in PyTorch — PyTorch Tutorials 2.6.0+cu124 documentation
pytorch.org
February 19, 2025 at 5:13 PM
Don't send tensors to device using to(device) if you can instantiate them directly there. For instance, prefer randn((), device=device) to randn(()).to(device)
February 19, 2025 at 5:13 PM
I guess my point was that a proper name + definition is necessary to write good code. When I see “policy”, “critic”, “replay buffer”, “env” I know exactly what does and doesn’t belong to them. With agent is systematically a “hm yeah why not” - then you end up with ill-defined monster classes
February 11, 2025 at 9:14 AM
If your agent is a policy call it policy, if it's a trainer call it trainer! If it's just a big undefined collection of methods, consider refactoring it...
February 11, 2025 at 8:52 AM
Every time I meet with people and someone talks about agent, there's at least one person who asks "what do you mean by agent?" or "you should not call that an agent".
February 11, 2025 at 8:52 AM