Chapter 6. Improve model accuracy with inference-time scaling


Inference-time scaling (ITS) improves the quality of model responses by allocating additional compute at inference time. Instead of generating a single response to a prompt, the model generates multiple candidate outputs and uses a selection strategy to return the best one. This approach produces better results without modifying model weights, at the cost of increased compute per query.

The ITS Hub library provides scaling algorithms that you can use with any model accessible through an OpenAI-compatible API, including models served with vLLM on Red Hat OpenShift AI.

6.1. Generate complete responses

The following procedure walks you through using ITS Hub to get better results from a language model without modifying the model itself. You run the following inference-time scaling algorithm against a model served through an OpenAI-compatible API:

  • Self-Consistency: Generates multiple responses and picks the most common answer.
  • Best-of-N: Generates multiple responses, scores each one, and picks the highest-scoring response.

These two algorithms work with any OpenAI-compatible endpoints and require no additional infrastructure.

Prerequisites

  • Python 3.11 or later.
  • Access to one of the following OpenAI-compatible model endpoints:

    • A model served with vLLM on Red Hat OpenShift AI.
    • Any other OpenAI-compatible API (for example, OpenAI, Azure OpenAI, or a local vLLM instance).
  • The model endpoint URL, API key, and model name.

Procedure

  1. Install ITS Hub

    pip install its-hub[lm]
  2. Verify the installation:

    python -c "from its_hub import OpenAICompatibleLanguageModel, SelfConsistency, BestOfN, LLMJudge; print('OK')"
  3. Connect to your model by creating a language model instance that points to your endpoint.

    In the following example, replace the endpoint, api_key, and model_name placeholder values with your actual endpoint details. If your endpoint does not require authentication, as is common with a local vLLM, set api_key="NO_API_KEY".

    from its_hub import OpenAICompatibleLanguageModel
    
    lm = OpenAICompatibleLanguageModel(
        endpoint="https://<your-endpoint>/v1",
        api_key="<your-api-key>",
        model_name="<your-model-name>",
    )
  4. Use the Self-Consistency algorithm to generate multiple responses to the same prompt and select the most common answer. It is similar to asking the same question several times and going with the majority answer.

    • Basic usage

      In the following example, the budget parameter controls how many responses are generated. A budget of 5 means the model generates 5 responses and votes on the answer.

      from its_hub import SelfConsistency
      
      sc = SelfConsistency()
      result = sc.infer(lm, "What is the capital of France?", budget=5)
      print(result)
    • Extract a specific part of the response for voting

      By default, Self-Consistency compares the entire response text. Optionally, you can use a projection function to extract a specific part of the response, such as the final answer, as shown in the following example:

      def extract_last_line(response):
          return response.strip().split("\n")[-1]
      
      sc = SelfConsistency(consistency_space_projection_func=extract_last_line)
      result = sc.infer(lm, "What is 2 + 2?", budget=5)
      print(result)
    • Get the full result

      By default, infer() returns only the winning response as a dictionary. To see all responses and vote counts, set return\_response\_only=False:

      result = sc.infer(lm, "What is the capital of France?", budget=5, return_response_only=False)
      
      print(f"Selected response index: {result.selected_index}")
      print(f"Vote counts: {result.response_counts}")
      print(f"Total responses: {len(result.responses)}")
      print(f"Winning response: {result.the_one}")
  5. Use the Best-of-N algorithm to generate multiple candidate responses, score each one, and return the highest-scoring response. ITS Hub includes an inline implementation of an outcome reward model (LLMJudge).

    • Basic usage. In the following example, a budget of 4 means that the model generates 4 candidate responses. The LLM judge scores each one and returns the best.

      from its_hub import BestOfN, LLMJudge
      
      judge = LLMJudge(lm=lm)
      bon = BestOfN(orm=judge)
      
      result = bon.infer(
          lm,
          "Explain how a CPU works to someone with no technical background",
          budget=4,
      )
      print(result)
    • Get the full result:

      result = bon.infer(
          lm,
          "Explain how a CPU works to someone with no technical background",
          budget=4,
          return_response_only=False,
      )
      
      print(f"Scores: {result.scores}")
      print(f"Selected index: {result.selected_index}")
      print(f"Best response: {result.the_one}")
  6. Clean up resources:

    • To release HTTP connections, run the following command to close the language model instance:

      import asyncio
      asyncio.run(lm.close())
    • To handle cleanup automatically, use an async context manager:

      async with OpenAICompatibleLanguageModel(
          endpoint="https://<your-endpoint>/v1",
          api_key="<your-api-key>",
          model_name="<your-model-name>",
      ) as lm:
          result = await sc.ainfer(lm, "What is the capital of France?", budget=5)

6.2. Step-by-step reasoning

ITS Hub includes algorithms that go beyond generating complete responses. These algorithms build solutions one step at a time, using a process reward model (PRM) to evaluate each reasoning step and steer the generation toward better paths.

  • Beam Search: Explores multiple reasoning paths in parallel, keeping only the most promising ones at each step.
  • Particle Filtering: Maintains a diverse set of candidate solutions and uses probabilistic resampling to focus on promising directions.
  • Entropic Particle Filtering: An advanced variant that prevents the algorithm from converging too early, which is useful for problems that require many reasoning steps.

These algorithms require a process-reward model with additional infrastructure setup and the experimental installation (pip install its-hub[experimental]). They are particularly effective for mathematical reasoning and multi-step problem solving.

For setup instructions and usage examples, see the following resources on ITS Hub docs: https://github.com/Red-Hat-AI-Innovation-Team/its\_hub/tree/v1/docs

  • For advanced configuration and all available algorithms, see the algorithm reference.
  • To manage concurrency when handling multiple requests, see the orchestration guide.
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top