#+title: Modernizing a CUDA library from 2015 #+description: Using an AI agent to modernize a 2015 CUDA library into a modern PyTorch package #+date: 2026-01-10 #+status: abandoned #+ailvl: 0 #+keywords: optimization agent In 2022, we released (led by [[https://tommoral.github.io][Thomas Moreau]]) [[https://github.com/benchopt/benchopt][benchopt]], a benchmarking suite tailored for machine learning workflows. Among the initial benchmarks, there was one dedicated to [[https://github.com/benchopt/benchmark_tv_2d][2D Total Variation]]. Total Variation is a regularization introduced in 1992 by Leonid Rudin, Stanley Osher and Emad Fatemi that was (is) quite popular in inverse problems for imaging, before the use of deep priors. I opened [[https://github.com/benchopt/benchmark_tv_2d/issues/6][an issue]] to add one of my solvers, that I implemented in 2015. It was a CUDA library that I developed when I was a postdoc with [[https://www.ceremade.dauphine.fr/~chambolle/][Antonin Chambolle]] in 2014-2015. It was designed to be a fast implementation of a [[https://en.wikipedia.org/wiki/Total_variation_denoising][Total Variation solver]] based on [[https://link.springer.com/article/10.1007/s10851-017-0724-6][our joint paper]] with [[https://sites.google.com/view/paulinetan][Pauline Tan]] and Antonin. But I never took the time to make it easily pip/conda/uv-friendly, and the idea kinda died due to the usual (pretext of) lack of time. Fast-forward to 2026, agents are quite powerful to manipulate existing codebases, especially simple ones like =ftvp=. I tried today [[https://ampcode.com][amp]] using Claude Opus 4.5 with the following prompt. #+begin_quote My goal is to modernize this repository. =ftvp= is a CUDA library dedicated to the computation of the proximal operator of the isotropic Total Variation in 2D and 3D on Nvidia GPU. I want to drop the C-first aspect, the goal is to package a Python algorithm. It should use modern CUDA as of 2026. Do not change the algorithm, but feel free to change everything. The use is described in README.md. A reference implementation in C is in TV4colorCPTV.c. The other files are the CUDA implementation. Ultimately I want a PyTorch-aware function proxtv(img, lambda) that works on BW and color images where img is the torch array and lamba the regularization parameter of TV. #+end_quote Following this prompt, Amp used $1.20 to generate this [[https://github.com/svaiter/ftvp/pull/2/commits/abfdf9ebc8c5cfc7d75b3cd01fbfe4a972c3522a][commit]]. It forgot to add ninja as a requirement, and the examples were only trying the prox on a black square. So I asked, #+begin_quote 1. You need to add ninja to the requirements to be able to JIT. 2. Write me an additional examples that perform the denoising on a real image #+end_quote The generated script was correct, but again it missed two dependencies required to run the examples. #+begin_quote Add numpy and pillow as dependency for running this example. #+end_quote Finally, I generated the PR request as follow > Generate a summary of the changes so that I can copy it in the PR interface of githb. Be explicit on the fact that is was driven by a AI agent. Overall, the total cost was $2.15 (of free credits) for something that I am convinced I would never have done otherwise. The full thread is [[https://ampcode.com/threads/T-019ba740-5029-745f-8915-0d21d531d394][here]]. I /still/ have to check that this is correct to merge it, and then submit a pull request on [[https://github.com/benchopt/benchmark_tv_2d][benchopt/benchmark_tv_2d]]. I will update this feedback note when this is done.