FM Selection Criteria
Complete the full lesson to earn 25 points
Work through each section, then tap “Mark as Complete” on the last one.
Foundation Model Selection: A Practical Guide for Engineering Teams
Introduction: Why Model Selection Matters
In the current landscape of artificial intelligence, we have moved past the phase where simply having access to a Large Language Model (LLM) was the primary goal. Today, the challenge lies in selecting the right tool for a specific job. Foundation Model (FM) selection is the process of evaluating, testing, and choosing a base model that balances performance, cost, latency, and operational complexity for your unique application requirements.
Choosing the wrong model can be a costly mistake. If you pick a model that is too large, you might face prohibitive inference costs and unacceptable latency, making your application feel sluggish to end-users. Conversely, choosing a model that is too small or lacks the necessary reasoning capabilities might lead to poor output quality, requiring constant manual correction or complex prompt engineering workarounds that could have been avoided with a more capable base model.
This lesson is designed to help you navigate the crowded market of foundation models. We will move beyond marketing claims and focus on the technical metrics, operational realities, and integration strategies that matter when building production-grade software. By the end of this module, you will have a structured framework to evaluate models based on your data, your budget, and your business goals.
1. The Core Dimensions of Model Evaluation
When you approach model selection, you should think of it as a multi-dimensional optimization problem. You are rarely looking for the "best" model in an abstract sense; you are looking for the model that provides the best return on investment for your specific use case.
Performance and Capability
Performance is often the first metric engineers look at, but it is frequently misunderstood. It is not just about a model's score on a public benchmark like MMLU (Massive Multitask Language Understanding). Instead, performance should be measured through your own domain-specific evaluation sets. Does the model follow your specific formatting requirements? Can it handle your unique industry jargon? Does it respect the context window constraints of your documents?
Inference Cost
Cost is a major driver of architectural decisions. Proprietary models (like those behind paid APIs) usually charge per token, which can scale linearly with your traffic. Open-weights models, which you host yourself, have fixed infrastructure costs (GPU time) and variable costs (scaling your instances). You must calculate the "break-even" point where self-hosting becomes cheaper than API usage, taking into account the engineering time required to maintain the infrastructure.
Latency and Throughput
For real-time applications, such as a customer support chatbot or an autocomplete feature in an IDE, latency is critical. A model that takes five seconds to generate a response is useless for an interactive interface, even if its reasoning is perfect. You must consider the "Time to First Token" (TTFT) and the total generation speed, which are heavily influenced by the model's parameter size and the hardware it runs on.
Callout: Performance vs. Cost Trade-offs When choosing between a massive model (e.g., GPT-4o or Claude 3.5 Sonnet) and a smaller, specialized model (e.g., Llama 3 8B or Mistral 7B), consider the "law of diminishing returns." For many classification or extraction tasks, a smaller model, when fine-tuned on your specific data, will often outperform a general-purpose giant while costing a fraction of the price. Always start with the smallest model that meets your quality threshold.
2. Categorizing Foundation Models
To make an informed decision, you need to understand the different classes of models available today. We generally group them into three buckets:
Proprietary API-Based Models
These are models provided by companies like OpenAI, Anthropic, and Google. They are accessed via an HTTP request and require no infrastructure management on your part.
- Pros: High reasoning capability, no hardware maintenance, frequent updates.
- Cons: Data privacy concerns, dependency on third-party uptime, opaque model updates (which can lead to "model drift" where your prompts suddenly stop working).
Open-Weights Models
These models (e.g., Llama, Mistral, Qwen) allow you to download the model files and run them on your own infrastructure or a private cloud provider.
- Pros: Total control over data privacy, no vendor lock-in, stable environment (the model won't change unless you update it), potentially lower cost at scale.
- Cons: High operational overhead (need to manage GPU clusters, quantization, and serving software), high initial setup time.
Domain-Specific Models
These are models pre-trained or fine-tuned on specific data types, such as medical records, legal contracts, or code repositories.
- Pros: Significantly higher accuracy for niche tasks.
- Cons: Highly specialized; often cannot perform general tasks outside their training domain.
3. Practical Steps for Selection
Selection is not a guessing game; it is an iterative experiment. Follow these steps to ensure you make a data-backed decision.
Step 1: Define Your Evaluation Dataset
Before you touch a model, create a "Golden Dataset." This should be a set of 50 to 100 representative inputs and their corresponding "ideal" outputs. This serves as your ground truth. If you do not have this, you are effectively flying blind.
Step 2: Establish a Baseline
Run your evaluation set through a high-end model (like GPT-4o). This establishes the "ceiling" of what is possible with current technology. If the best model on the market cannot solve your problem, you may need to rethink your approach (e.g., using RAG or agentic workflows) rather than just swapping models.
Step 3: Run Pilot Tests with Smaller Models
Take a selection of smaller, open-weights models and run them against your baseline. Use a library like promptfoo or a custom Python script to automate the comparison.
# Example: Evaluating models using a simple scoring script
import openai
def evaluate_model(model_name, prompt):
# This is a conceptual snippet for tracking responses
response = client.chat.completions.create(
model=model_name,
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.content
# Your Golden Dataset
tasks = [
{"prompt": "Summarize this legal clause: [text]", "expected": "[summary]"},
# ... more tasks
]
# Iterate through models
models = ["gpt-4o", "llama-3-8b-instruct", "mistral-7b-v0.3"]
for model in models:
for task in tasks:
output = evaluate_model(model, task['prompt'])
# Compare output against task['expected']
Step 4: Cost-Benefit Analysis
Once you have your results, map the accuracy against the cost. You might find that a $0.50 per million token model is 95% as effective as a $15.00 per million token model. In most business cases, the 5% drop in accuracy is a trade-off worth making.
4. Technical Considerations: Quantization and Serving
If you decide to go the open-weights route, you will quickly encounter the need for quantization. Quantization is the process of reducing the precision of the model's weights (e.g., from 16-bit float to 4-bit integer).
Note: Quantization is not just about saving space; it is about performance. A 4-bit quantized model often fits into a smaller GPU, which allows for higher batch sizes and faster inference, with a surprisingly minimal impact on model intelligence.
When serving your models, you should look into production-ready inference servers such as:
- vLLM: Excellent for high-throughput serving and paged attention.
- TGI (Text Generation Inference): Optimized for performance and stability.
- Ollama: Great for local development, though not typically recommended for high-load production environments.
5. Avoiding Common Pitfalls
Even experienced teams fall into common traps during the model selection process. Being aware of these will save you weeks of development time.
Pitfall 1: The "Shiny Object" Syndrome
Teams often feel pressured to use the newest, largest model released by a major lab. However, the latest model is not always the best. Larger models are slower and more expensive. If your task is simple extraction, a massive model is overkill and will only introduce unnecessary latency into your pipeline.
Pitfall 2: Ignoring Data Privacy and Compliance
If you are working with PII (Personally Identifiable Information) or sensitive corporate data, sending that data to a third-party API might be a violation of your compliance policy. Always verify where your data is processed and whether the provider uses your data for training. If you cannot guarantee privacy with an API, you must choose an open-weights model and host it in your own VPC (Virtual Private Cloud).
Pitfall 3: Not Planning for Model Updates
If you rely on an API, the provider will eventually deprecate the model you are using. You must build your infrastructure to be "model-agnostic." Use an abstraction layer (like an internal gateway or a library like LiteLLM) so that swapping a model requires changing a configuration file rather than rewriting your entire codebase.
Pitfall 4: Over-optimization
Some engineers spend months trying to squeeze 1% more accuracy out of a model by fine-tuning it, when that same 1% could be achieved much faster by improving the quality of the data in your RAG (Retrieval-Augmented Generation) system. Remember that the model is only one part of the stack; the data you feed it is often more important.
6. Comparison Table: Model Selection Criteria
| Criterion | Proprietary API Models | Open-Weights Models |
|---|---|---|
| Setup Effort | Low (Plug and play) | High (Infrastructure management) |
| Data Privacy | Depends on Terms of Service | Total control (Local hosting) |
| Cost Predictability | Variable (Per token) | Fixed (Compute resources) |
| Customization | Limited (Prompting/Few-shot) | High (Full fine-tuning) |
| Maintenance | Minimal | High (Updates, security, scaling) |
7. Best Practices for Long-Term Success
To build a sustainable system, follow these industry-standard practices:
- Use an Abstraction Layer: Never hardcode API calls throughout your app. Create a service that handles model interaction so you can swap out providers (e.g., switching from GPT-4 to Claude 3) without touching your business logic.
- Monitor Your Inputs and Outputs: Use tools like LangSmith, Arize, or open-source equivalents to log what users are sending and what the model is returning. This data is essential for debugging and future fine-tuning.
- Implement Fallback Strategies: If you are using a third-party API, have a secondary provider ready to go. If the primary API goes down, your system should be able to route traffic to a backup model automatically.
- Iterate on Prompts, Not Just Models: Often, a "smarter" model is just a "better-prompted" model. Before deciding a model is not good enough, spend time refining your system prompt, adding examples (few-shot prompting), and using structured output formats like JSON mode or Pydantic.
- Focus on Data Quality: The "Garbage In, Garbage Out" rule is more relevant here than in any other field of software engineering. Clean your retrieval data, remove duplicates, and ensure your RAG context is relevant to the prompt.
Callout: The Role of Fine-Tuning Many teams assume fine-tuning is the first step. It should actually be the last. Always start with effective prompt engineering and RAG. Only move to fine-tuning if you have a massive dataset of high-quality examples and you have reached a plateau where prompting can no longer improve the model's performance on your specific task.
8. Step-by-Step Selection Workflow
If you are currently evaluating a new project, follow this step-by-step process:
- Discovery: List the top 3 requirements for your application (e.g., "Must handle JSON output," "Must be under 500ms latency," "Must be HIPAA compliant").
- Filtering: Eliminate models that do not meet these requirements. For example, if you need HIPAA compliance, eliminate any API provider that does not offer a HIPAA-compliant tier.
- Benchmarking: Pick 3 candidate models:
- The current industry leader (for your baseline).
- A mid-sized, cost-effective model.
- A small, fast model.
- Execution: Run your "Golden Dataset" against all three models. Measure accuracy, latency, and cost per 1,000 requests.
- Decision: Choose the model that satisfies the requirements while minimizing cost.
- Refinement: Once the model is integrated, set up monitoring to track performance drift. If the model starts failing, you have the data ready to evaluate a replacement.
9. Addressing Common Questions
How often should I re-evaluate my model choice?
You should perform a "check-in" every 3 to 6 months. The field moves rapidly; a model that was the best choice six months ago may now be significantly more expensive or less capable than a newer, smaller model.
Is it possible to use multiple models in one application?
Yes, this is an excellent practice. You can use a "Router" pattern: use a cheap, fast model for simple queries (like classification or summarizing short text) and route complex queries (like multi-step reasoning) to a more powerful, expensive model. This optimizes both cost and user experience.
What if my model is "hallucinating"?
Hallucination is rarely the fault of the model alone. It is usually a result of poor context or vague instructions. Before switching models, check if your retrieved context contains the necessary information and ensure your system prompt explicitly tells the model to "say 'I don't know' if the answer is not in the provided text."
How do I handle large context requirements?
If you are dealing with massive documents, you are limited by the model's "context window." When evaluating models, check their maximum token limit. If a model supports 128k tokens but slows down significantly after 32k, it might not be suitable for your use case despite the marketing claim.
10. Key Takeaways
As we conclude this lesson, remember that foundation model selection is a strategic engineering decision, not a one-time choice. Here are the core principles to carry forward:
- Start Small: Always test with the smallest, most efficient model first. You can always upgrade to a larger model, but downgrading later often requires re-engineering your prompts and workflows.
- Build an Evaluation Framework: Never choose a model based on "vibes" or benchmark scores provided by the vendor. Build your own Golden Dataset and evaluate models against your specific, real-world data.
- Prioritize Abstraction: Decouple your application code from the specific model provider. Use gateways and configuration-based loading to allow for seamless model swapping as the market evolves.
- Quantify the Trade-offs: Every model choice involves a trade-off between cost, latency, and intelligence. Be explicit about which of these is your highest priority for your specific project.
- Focus on Data over Models: A medium-sized model with high-quality, curated RAG data will almost always outperform a massive model with poor, noisy, or irrelevant context.
- Monitor and Re-evaluate: The model you choose today will be obsolete eventually. Build your system with the assumption that you will need to replace the model component periodically.
- Compliance is Non-Negotiable: Ensure your model selection aligns with your organization's legal and security requirements before you begin the technical integration.
By following these guidelines, you move from being a passive consumer of AI services to an active architect of intelligent systems. You are now equipped to make decisions that not only satisfy the immediate needs of your project but also ensure the long-term stability and cost-effectiveness of your software.
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles your daily points limit so you progress twice as fast, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× daily points limit
- ✓ Distraction-free lessons