A general framework for large-scale model selection