Large Language Models

CSC-430

Phillip Wright

Large Language Models

As you are aware, large language models have had a huge impact on the industry and will continue to do so.

Let’s talk about why this class is still important.

At least for now!

Large Language Models II

First, what we’re not focusing much on:

What are the best practices for using LLMs?

Large Language Models III

…because anyone telling you that they know how LLMs will be used a year (or even a few months) from now is, at best, a bit clueless and overconfident, and, at worst, a charlatan trying to sell you something!

How Do They Work?

This is not a course on LLMs, so we will just consider their implementation at a very high level:

An LLM is a neural network trained on a massive corpus of real-world and synthetic data.

They are, more or less, simple text completion models.

Text Completion

Surprisingly, it turns out that a very accurate text completion model is sufficient for a large chunk of knowledge work that previously required human brains.

Text Completion II

To make these models more useful, they are usually packaged into chat-like tools. But they are still only doing text completion.

Chat

The way a “chat” works is that it stores the entire conversation that you are having (along with additional prompts, data, etc.) and sends it to the LLM for every request.

Chat II

For instance, if you start a chat with “Hello!”, then the input sent to the LLM may be:

system prompt: you are a kind, helpful chatbot

context:

prompt: Hello!

To which the LLM may respond: “Hello! How can I help you?”

Chat III

When you respond with “What was my first message?”, the LLM could not possibly answer correctly, unless we include the previous context:

system prompt: you are a kind, helpful chatbot

context:

  user: Hello!

  agent: Hello! How can I help you?

prompt: What was my first message?

Memory

This is necessary because an LLM has no memory. The chat tool you are using may have supplemental support for “memory”, but this is not in the LLM.

Every interaction with the LLM is a fresh turn with absolutely no history, unless the history is manually added to the request.

Memory II

The “memory” that you see is simply a data store provided by the tool which adds content to the context to mimic memory.

For example, if the LLM recalls facts about you from a month ago, it’s because the tool has told that fact to the LLM as part of the context.

Tool Calls

One of the biggest advances for using LLMs has been the support for tool calls. The idea is to provide tools (e.g., for searching files) and expose their specifications to the LLM so that it can call the tools.

The tool output then becomes text in the context of the chat for the next turn.

Tool Calls II

The calls themselves are simply text completion! For example, if you ask where the type SimpleBlob is used, the LLM may receive:

tools:
  grep: allows for using grep in a given directory.
    arguments: directory, regex

prompt: Where is the type `SimpleBlob` used?

Tool Calls III

The LLM will then respond, perhaps, with:

tool_call:{
  tool: grep,
  arguments:{
    directory: ~/some/project,
    regex: SimpleBlob
  }
}

The agent will recognize this (as it follows a standard, agreed-upon format) and make the call on behalf of the LLM.

Tool Calls IV

The agent will then take the output and make another call to the LLM. This call will include the previous tool request, tool call, tool output, and the original prompt.

The LLM will then hopefully respond with a useful answer.

Tool Calls V

Again, though, tool calls are nothing more than a convenient, efficient way to gather data into the context of the chat.

This is better than dumping all files into the context, but it is still nothing more than text completion on context data.

Context Is Limited

The reason why we want to focus on this is that the amount of context an LLM can use is limited.

Once you fill up the context, you must “forget” old parts of the context, move them to memory, compact the context, or something else.

In all cases, though, knowledge is lost.

Human Context

This should sound somewhat familiar to you as a human, as humans also have a limited context of information that we can keep in our heads at once.

It is actually a thesis of this course that we must use tools, processes, best practices, etc. in order to allow us to tackle complex problems with the limited contexts we can store in our brains.

Human Context II

Best practices like keeping classes small and tightly focused on single, separate abstractions, which can then be used without knowledge of their implementations, for example, allow us to focus on just those abstract concepts and the small amount of code using them, instead of requiring us to be familiar with all of the related code.

Context Is Limited II

Since LLMs are also limited in the amount of context they can use, we can’t simply dump millions of lines of code into the context and then expect them to do meaningful work.

LLMs, accordingly, benefit from code that is written in a context-friendly manner, using context-friendly processes, etc.

Context Is Limited III

Unfortunately, LLMs seem to have difficulty generating such high-quality, context-friendly code.

Accordingly, it is still a valuable skill to understand how to craft such code so that you can guide the LLM.

Otherwise, you will end up with such sprawling, unorganized code that even an LLM will not have enough context to understand its own work properly.

Job Security

From a job security perspective, it is fortunate for us that the context limits seem to be a particularly difficult hurdle based on fundamental hardware limits. If we want bigger contexts, we must do one of the following:

  • Use smaller (i.e., dumber) models
  • Accept significantly slower response times

Job Security II

If someone figures out a way to significantly increase context sizes without reducing the effectiveness of the frontier models, then that will be the point where humans as developers are no longer needed.

Learning

Another way that we could get around the context limitations would be to make the training of models significantly faster and cheaper.

Learning II

You could roughly think of an LLM that could actually be refined as it is being used (i.e., a model that could learn) as a model with more or less infinite context, as the context would no longer be needed.

The context would simply be “learned” by the LLM and stored in the model weights.

Job Security III

So, if efficient “learning” is achieved, we would also become obsolete as developers.

This, too, seems to be a fairly fundamental limitation at the moment.

The Future

This all implies that, for the short term, it will be important to develop the ability to guide LLMs towards high-quality code and to start transitioning your focus to “large-context” concerns like system design and product planning, which humans still excel at.