COSMOS: Predictable and Cost-Effective Adaptation of LLMs