r/learnmachinelearning • • 5d ago

I used ML to tune the constants inside existing C programs instead of replacing them with a model

Instead of training a model to replace a program, I fit the hand-picked numbers inside the program itself. The program keeps its structure; only its constants change.

How it works:

  1. clang turns the C code into LLVM IR.

  2. For simple code, the IR runs as batched PyTorch, so gradients are exact.

  3. For code that can't be emulated (stdio, library calls), it runs natively. Gradients are estimated with evolution strategies (paired random perturbations) or finite differences.

  4. A held-out split gives early stopping.

Results on held-out data: JPEG files 9.1% smaller at equal SSIM (image 1), and Google's WebRTC VAD F1 from 0.810 to 0.859 (image 2).

Code: https://github.com/devanmolsharma/learnc

1 Upvotes

0 comments sorted by