LLMs as Bandits in Disguise: Why Logging the Road Not Taken Matters

2 min read

I'm not convinced by the recent trend of using LLM routers to optimize AI performance. The current implementation of LLM routers only logs successful outcomes, which can make it hard to see what's going wrong with our models. This lack of transparency is a major concern for me, and it's something that I think we need to address.

The concept of LLM routers as bandits in disguise comes from a recent study that showed how these routers can lead to a lack of accountability in model selection. By only logging successful outcomes, we're not seeing the entire picture. We're not seeing the times when a model failed, or when a different model performed poorly.

python
import logging
import random

# Define a simple LLM router
def llm_router(models, task):
    # Select a random model from the list
    model = random.choice(models)
    # Log the selected model
    logging.info(f"Selected model: {model}")
    # Return the result of the task
    return model(task)

# Define a task
def task(model):
    # Simulate a task with a 50% chance of success
    if random.random() < 0.5:
        return True
    else:
        return False

# Create a logger
logger = logging.getLogger()
logger.setLevel(logging.INFO)

# Define a handler for the logger
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)

# Create a formatter for the handler
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)

# Add the handler to the logger
logger.addHandler(handler)

# Test the LLM router
models = [model1, model2, model3]
result = llm_router(models, task)
logging.info(f"Result: {result}")

This code snippet demonstrates how an LLM router can be implemented using a simple random selection algorithm. However, as the study points out, this approach can lead to a lack of transparency and accountability.

LLM Router Success Rates
Model 180%Model 270%Model 390%
Data from the sources listed below.

In this chart, we can see that Model 1 has the highest success rate, but we're not seeing the entire picture. What about the times when Model 1 failed? Are we learning from those failures, or are we simply ignoring them?

Logging the road not taken is crucial because it allows us to identify and learn from failed attempts, which can lead to significant improvements in model performance. By logging the failures and the paths that didn't lead to the best outcome, we can gain valuable insights into the strengths and weaknesses of our models.

Try this

  1. Install the logging library by running pip install logging in your terminal.
  2. Create a logger by calling logging.getLogger().
  3. Set the level of the logger to INFO using logger.setLevel(logging.INFO).
  4. Define a handler for the logger by creating a StreamHandler and setting its level to INFO.

Sources