Manuscript Offprint

arXiv:2610.05902

On Hyperparameter Tuning on the Test Set

Matteo Fregonara, Tom Viering, Jan van Gemert

ABSTRACT

"Don't tune hyperparameters on the test set" is often stated in machine learning textbooks. Violating it is considered a cardinal sin that produces misleadingly optimistic results, corrupts benchmark integrity, and thus can even be interpreted as scientific fraud. Yet evidence suggests that test set hyperparameter tuning does occur in practice, making it all the more important to understand its actual consequences. So how bad is it, really? In this work we question this dogma and put it to an empirical test. We systematically study the magnitude of the performance inflation caused by tuning the hyperparameters on the test set for MNIST-1D, CIFAR-10, and three tasks from the GLUE benchmark. Our experiments show that while the effect is real and significant, it is frequently small relative to other sources of noise. In many cases, we find that tuning on the test set recovers exactly the same model as when tuning on the validation set. Most importantly, we find that the rankings of models remain essentially preserved after tuning on the test set and therefore that consistent test-set tuning may not invalidate benchmarks or model selection. Our results call for a more nuanced view of tuning hyperparameters on the test set, stimulating researchers to openly report test tuning.

1 INTRODUCTION

Overfitting is an inflated generalization estimate, possibly distorting model selection rankings, which may lead to deploying the wrong model. We investigate overfitting of hyperparameters: configurations that determine model training behavior. Specifically, we investigate overfitting by tuning hyperparameters on the test set, i.e., the same data set used for reporting generalization performance.

Machine learning textbooks prohibit hyperparameter tuning on the test set. From a theoretical perspective, a hyperparameter is no different than any other model parameter that is set at training time. Thus, an extreme view can see tuning hyperparameters on the test set as academic fraud in the current benchmarking paradigm (Hardt, 2026). For example, tuning model parameter initialization on the test set (Picard, 2021) will give excellent accuracy; independent of other claims for empirical gain in machine learning scholarship (Lipton & Steinhardt, 2019; Sculley et al., 2018).

In practice, however, several implementations already tune hyperparameters on the test set, both in computer vision (PyTorch Contributors, 2024; Wightman, 2019; Touvron et al., 2021a; Bao et al., 2022b; He et al., 2022a) and in natural language processing (Devlin et al., 2019; Google Research, 2018; Liu et al., 2019; Facebook AI Research, 2019). Accordingly, it can be argued that a hyperparameter is not like an individual model parameter, because hyperparameters are usually regularized by their global effect on a model, where e.g., the learning rate is typically shared over all model parameters. Moreover, in practice, not an infinite number of hyperparameter configurations are evaluated, but only a handful (Hastie et al., 2009). Thus, there is tension between theory and practice, and here we investigate how bad hyperparameter overfitting really is.

In this paper, we give the first systematic empirical evaluation of overfitting by tuning hyperparameters on the test set. We carefully construct a controlled evaluation benchmark of repeated hyperparameter tuning on a validation set, compared to tuning on the test set. We evaluate on the controlled MNIST-1D (Greydanus & Kobak, 2024), image classification on CIFAR-10 (Krizhevsky, 2009) and three natural language understanding tasks from the GLUE benchmark (Wang et al., 2019) (RTE, MRPC and CoLA). We test multiple model families, and train 36,000 model variants. We investigate how easily models overfit, how severe the overfitting is, and if the overfitting leads to differences in model selection.

Our results show that overfitting by tuning on the test set is significant on every benchmark we evaluate. Yet, the same hyperparameter configuration is often best on both the validation set as on the test set and the accuracy gain by overfitting is mild when compared to other sources of randomness such as data splits. Model selection rankings barely change when all models are tuned on test data, and we did not observe that the best model is not selected.

Our results call for a nuanced view on tuning hyperparameters on the test set. Overfitting is real, and comparing validation-tuned models vs test-tuned models benefits test-tuned models. However, model rankings rarely change when all models under comparison are tuned on the same data, making the effect of test-tuning relatively benign. Our paper gives empirical evidence to normalize hyperparameter tuning on the test set, and we encourage authors not to hide or be reluctant to admit test-tuning, but openly report it.

References (66)