LLM Selection for STEM Workloads: An Evaluation Framework and Engineering Practice

    Selecting a large language model for scientific, engineering, and technical workloads cannot rely on word-of-mouth reviews. This article presents a structured, reproducible evaluation framework that breaks down model capability into five independently measurable dimensions, outlines how to build a custom benchmark set, and covers cost, latency, and stability assessment—along with practical engineering considerations for integrating a model into production systems.

    Why Public Opinion Is Not a Reliable Basis for Model Selection

    Model reviews found in forums and online communities are typically based on a handful of personal conversations. This kind of feedback has three inherent limitations. First, the domain, style, and language of the questions vary widely—a model that excels at mathematical proofs may be inconsistent at code completion or literature summarization. Second, model services are updated frequently; versions, inference parameters, and pricing structures all change, which means conclusions drawn just six months ago can quickly become outdated. Third, conspicuous errors (such as fabricated citations or invented formulas) are easy to remember, while the large volume of correct answers goes unnoticed—so public perception tends to skew toward the extreme.

    STEM users need reproducible judgments. The rational approach is to define tasks first, compare candidate models on a unified test set, and then make a decision based on cost and stability.

    Breaking Down Core Capability Dimensions for STEM Scenarios

    Before evaluation begins, “capability” should be decomposed into dimensions that can be measured independently. The following five are commonly relevant:

    1. Mathematics and symbolic reasoning. This covers multi-step algebraic manipulation, probability calculation, unit conversion, and logical completeness of proofs. These tasks usually have definite answers, making them suitable for automated scoring.
    2. Code generation and scientific computing. This includes writing numerical computation code from a specification, explaining error messages, and modifying existing functions. Evaluation should be based on whether the code passes unit tests, not on whether the code merely looks plausible.
    3. Literature comprehension and long-document processing. This involves extracting methods from long papers, comparing experimental setups, and summarizing research limitations. When testing, input length should be controlled so that recall can be observed separately for key information placed at the beginning, middle, and end of the document.
    4. Factual accuracy and citation reliability. It is not uncommon for models to fabricate paper titles, author names, DOIs, or data sources in their responses. This dimension should be scored separately and never mixed with reasoning ability.
    5. Structured output and instruction following. For example, returning JSON according to a fixed schema, or strictly adhering to specified units and decimal places. Downstream programs depend on these formats—a single formatting error can interrupt the entire pipeline.

    Building a Custom Benchmark Set

    A well-designed benchmark set is the most valuable asset in the model selection process. The following principles should guide its construction:

    • Source questions from real tasks. Prioritize collecting actual problems the team has encountered in its work, rather than copying from public question banks. Publicly available questions tend to appear in training data, which can inflate scores.
    • Every question must have a verifiable ground truth. Numerical problems should have exact answers, code problems should come with test cases, and literature problems should reference sources that can be checked item by item.
    • Stratify by difficulty. Each dimension should include at least three difficulty levels—basic, intermediate, and hard—to avoid the scenario where all models achieve full marks on easy questions and no meaningful differentiation is possible.
    • Include edge-case samples. For example, questions with insufficient information or incorrect premises. A capable model should point out the problem rather than follow the user’s assumption and produce an answer anyway. Such samples test whether a model tends to blindly accommodate the user.

    The evaluation workflow can be expressed in pseudocode as follows:

    1. function evaluate(candidate_models, question_set):
    2. results = []
    3. for model in candidate_models:
    4. for question in question_set:
    5. start = start_timer()
    6. answer = call_model_api(model, question.prompt, temperature=0)
    7. elapsed = end_timer() - start
    8. score = grade(answer, question.gold_answer, question.type)
    9. record(results, model=model, category=question.category, score=score, latency=elapsed)
    10. return summarize(results, by_category=average, by_model=group)

    Grading methods should also differ by question type:

    1. function grade(answer, gold_answer, type):
    2. if type == "numeric":
    3. extracted = extract_numeric_value_from_end(answer)
    4. return 1 if abs(extracted - gold_answer) <= tolerance else 0
    5. if type == "code":
    6. write_function_to_sandbox(answer) # no network, no credentials
    7. run_unit_tests()
    8. return passed_tests / total_tests
    9. if type == "citation":
    10. return 1 if every citation can be verified against a credible source else 0
    11. if type == "open_ended":
    12. scored by two or more reviewers using a rubric
    13. inter-rater consistency sampled and checked
    14. return average_score

    Two additional cautions are worth noting. Setting the temperature to 0 does not guarantee identical outputs on every run. Each question should be run multiple times, and the mean and variance should be reported so that one lucky result is not mistaken for consistent capability. Additionally, code generated by the model must be executed in an isolated sandbox environment to prevent it from accessing local files or external networks.

    Cost, Latency, and Stability

    LLM services are typically billed per token for both input and output, with output prices usually higher than input prices. Cost estimation can be performed using the following formula:

    1. function estimate_monthly_cost(avg_input_tokens, avg_output_tokens, input_price, output_price, daily_invocations):
    2. single_call = avg_input_tokens / 1000 * input_price + avg_output_tokens / 1000 * output_price
    3. return single_call * daily_invocations * 30

    Prices should be taken from the service provider’s current published rates—do not rely on outdated secondhand information.

    Latency should be measured using two distinct metrics. Time-to-first-token determines the perceived responsiveness in interactive scenarios, while total completion time affects the overall duration of batch processing tasks. Stability should be tracked along three dimensions: timeout rate, rate of malformed output formats, and the consistency of results across multiple invocations of the same question.

    Which of these four factors matters most depends on the use case. Research-assisted writing is sensitive to accuracy, batch data processing is sensitive to format and cost, and interactive Q&A is more sensitive to latency.

    It is advisable to wrap model invocations in a dedicated abstraction layer so that business code only depends on a unified interface. This way, switching models only requires changing configuration—no business logic changes are needed.

    1. config = read_env_vars(provider_endpoint, api_key, model_name)
    2. client = create_client(endpoint=config.endpoint, api_key=config.api_key)
    3. function request(prompt, params):
    4. for attempt in range(3):
    5. try:
    6. return client.send(model=config.model_name, messages=prompt, temperature=params.temperature, timeout=params.timeout)
    7. except TimeoutError or RateLimitError:
    8. wait(2 ** attempt) # exponential backoff in seconds
    9. raise RequestFailedError

    A few practical notes:

    • API keys should be stored in environment variables or a dedicated secrets management service. They must never be hardcoded into source code or written to logs.
    • Retry logic should only handle recoverable errors such as timeouts and rate limiting. For paid API calls, care must be taken to avoid duplicate billing caused by repeated submissions from the application layer.