Optuna vs Code Llama: Are LLMs a New Paradigm for Hyperparameter Tuning?

Roman Kochnev, Arash Torabi Goodarzi, Zofia Antonina Bentyn, Dmitry Ignatov, Radu Timofte

TL;DR

By fine-tuning Code Llama using Low-Rank Adaptation (LoRA), researchers have demonstrated that large language models can perform hyperparameter optimization (HPO) in a "one-shot" inference step. This approach achieves competitive or superior accuracy compared to traditional iterative frameworks like Optuna while drastically reducing the massive computational overhead typically required by trial-and-error search algorithms.

What Problem Does This Paper Address?

Finding the right hyperparameters (like learning rate, batch size, and momentum) can make or break a deep learning model. Traditionally, engineers rely on automated HPO frameworks like Optuna, which use Bayesian Optimization or Evolutionary Strategies to systematically guess, train, evaluate, and repeat.

While effective, this iterative process is incredibly slow and computationally expensive, often requiring dozens or hundreds of full training runs just to find a single optimal configuration. This paper explores whether a fine-tuned Large Language Model (LLM) can bypass this tedious loop entirely by predicting optimal hyperparameters in a single, one-shot inference step based on the model's architecture code and target accuracy.

Methods

The authors leverage Code Llama-Python as their base model and apply parameter-efficient fine-tuning via Low-Rank Adaptation (LoRA) with a rank of 32, alpha of 16, and a dropout rate of 0.05.

Instead of relying on the LLM's zero-shot capabilities, they implement a structured, two-cycle feedback loop:

  1. Initial HPO Generation: They use Optuna’s Tree-structured Parzen Estimator (TPE) to generate baseline hyperparameter-accuracy pairs.
  2. Prompt Engineering: They format the data into prompts containing a system instruction, the model's implementation code, the desired target accuracy, and the corresponding optimal hyperparameters.
  3. Fine-Tuning & Verification: Code Llama is fine-tuned on these prompts. The model's predictions are then validated by running actual training cycles, and the successful configurations are fed back into the dataset to further refine the model in a second cycle.

The complete generation and evaluation pipeline is outlined below:

Figure 1. Generation of training hyperparameters for our neural network dataset with Optuna and Code Llama.

Datasets

  • LEMUR Neural Network Dataset: A newly introduced open-source benchmark dataset created by the authors for HPO research. It initially contained 3,700 entries of hyperparameter-accuracy pairs and expanded to 7,107 entries after the second fine-tuning cycle.
  • Training Models: 14 computer vision architectures (including ResNet, MobileNetV2/V3, SwinTransformer, SqueezeNet, VGG, ConvNeXt, GoogLeNet, AlexNet, DenseNet, MNASNet, ShuffleNet, and RegNet) trained on the CIFAR-10 dataset, alongside text generation models (RNN, LSTM, Llama 3) trained on Salesforce/WikiText.
  • Test Models (Unseen Architectures): To evaluate zero-shot generalization to completely unfamiliar codebases, the authors tested the model on InceptionV3, VisionTransformer (ViT), and MaxViT.

Key Insights and Ideas

  • Vanilla LLMs are terrible at HPO: Out of the box, pre-trained Code Llama yielded a measly 33.77% relevance rate, frequently suggesting physically impossible configurations like a batch size of 0 or failing to provide numerical values entirely. Fine-tuning is mandatory.
  • Shifting from Search to Inference: Once fine-tuned, the LLM successfully internalizes the relationship between network architecture code and training dynamics, turning a massive search problem into a near-instantaneous inference task.
  • True Architectural Generalization: Remarkably, the fine-tuned LLM didn't just memorize configurations; it successfully generalized to complex, completely unseen architectures in the test set (like VisionTransformer), significantly outperforming Optuna's average baselines.

Key Results

  • Lower Error Rates: The fine-tuned Code Llama consistently achieved lower Root Mean Square Error (RMSE) values than Optuna across most architectures. Code Llama achieved a best overall RMSE of 0.404, outperforming Optuna's best baseline of 0.416.
  • Strong One-Shot Performance: Even in pure one-shot mode (predicting instantly without any iterative refinement loops), Code Llama hit an RMSE of 0.533, offering an excellent shortcut to high-performing configurations.
  • Stability Gains: As shown in the performance distribution across the 14 vision models, the confidence intervals for Code Llama narrowed significantly by the second fine-tuning cycle, indicating highly stable and reproducible hyperparameter recommendations.
Figure 2. RMSE values for 14 computer vision models, comparing results of Optuna (in green) and obtained after fine-tuning Code Llama (fine-tuned cycle 1 in blue and fine-tuned cycle 2 in red). The shaded area around the line indicates 95% confidence interval, reflecting the uncertainty of the RMSE estimates. This visualization aids in assessing the performance of the models across different datasets and epochs.

Limitations and Future Work

Despite the strong results, the authors noted that performance varies depending on architectural similarity. For instance, the model struggled with InceptionV3, where its predictions actually led to a decline in accuracy compared to Optuna. This indicates that if a target architecture deviates too drastically from what the LLM saw during fine-tuning, its recommendations degrade.

Additionally, the study was constrained by local hardware resource limitations. Future work will focus on refining prompt design, exploring alternative parameter initializations, and extending fine-tuning schedules to better accommodate highly complex or unique neural network architectures.

Summary updated

Abstract

Optimal hyperparameter selection is critical for maximizing the performance of neural networks in computer vision, particularly as architectures become more complex. This work explores the use of large language models (LLMs) for hyperparameter optimization by fine-tuning a parameter-efficient version of Code Llama using LoRA. The resulting model produces accurate and computationally efficient hyperparameter recommendations across a wide range of vision architectures. Unlike traditional methods such as Optuna, which rely on resource-intensive trial-and-error procedures, our approach achieves competitive or superior Root Mean Square Error (RMSE) while substantially reducing computational overhead. Importantly, the models evaluated span image-centric tasks such as classification, detection, and segmentation, fundamental components in many image manipulation pipelines including enhancement, restoration, and style transfer. Our results demonstrate that LLM-based optimization not only rivals established Bayesian methods like Tree-structured Parzen Estimators (TPE), but also accelerates tuning for real-world applications requiring perceptual quality and low-latency processing. All generated configurations are publicly available in the LEMUR Neural Network Dataset (https://github.com/ABrain-One/nn-dataset), which serves as an open source benchmark for hyperparameter optimization research and provides a practical resource to improve training efficiency in image manipulation systems.
BibTeX
@misc{kochnev2025optuna,
  author = {Roman Kochnev and Arash Torabi Goodarzi and Zofia Antonina Bentyn and Dmitry Ignatov and Radu Timofte},
  title = {{Optuna vs Code Llama: Are LLMs a New Paradigm for Hyperparameter Tuning?}},
  year = {2025},
  eprint = {2504.06006},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.06006},
}
Figure