Let me enthusiastically welcome you all back to week three of our LLM engineering journey.
If you enjoyed last week when we got deep into building user interfaces using the fabulous Gradio framework,
then you're going to love this week even more, because now it's time to get into open source and start
using the wonderful world of Huggingface.
But first, a quick recap as always on what you can already do.
You can describe Transformers and you are fluent in the key terminology.
You can talk about context windows until the cows come home and all of that.
You can confidently code whether it's with Gemini or Claude or with OpenAI.
You know the APIs.
You know how to stream, you know about markdown, you know about JSON responses.
And you can also build an AI assistant, a chatbot.
You can make it use tools.
You can make it use different agents, and you can make it multimodal.
And we've built one ourselves.
And hopefully you've extended it to.
too.
So what's happening today?
Today we're going to get into hugging face.
And to start with, you're just going to be able to describe what it is and the scope and scale of hugging
face.
One of the most remarkable things about hugging face is its breadth.
All the different things that it offers to the open source data science community, and you'll have
a good appreciation for that shortly.
Uh, we're going to look at models, data sets and spaces in hugging face, and you'll also have a good
understanding of Google Colab.
You may already have an understanding of Google Colab, in which case it'll be a quick revision point.
But for those that don't, we're going to go into it.
You're going to see how you can run code on a box with a good GPU, and you'll have a sense of the different
offerings out there and which ones we'll be using for the class.
So we'll get you set up.
So prepare for some open source stuff.
But first, as always, a quick recap on what's been going on, where we are and what's left to do.
We started on the left with uh, at the beginning, no LM engineering knowledge, we will end up on
the right as proficient LM engineers.
In week one, we got immersed in all things frontier.
In week two.
Last week we built UIs.
We used all of the APIs for the top three and we experimented with tools.
Agent ization Multi-modality this week, all about open source, all about hugging face.
Next week we talk about selecting the right LM for the problem and generating code.
After that is Rag week.
Then we fine tune a frontier model, then we fine tune an open source model, and then in the finale
we bring it all home.
So without further ado, let's talk hugging face.
So as I say, it's ubiquitous.
It's it's used across the community.
It is a fabulous resource.
And amongst many things, it offers us three the hugging face platform, the the what you get to if
you go to Hugging Face Co and you've signed up with an account.
You have access to three categories of things.
First of all, you have models over 800,000 open source models that can do a bunch of different types
of tasks, many of which we will experiment with in this week's lectures.
And in future weeks, there are data sets.
It is a treasure trove, over 200,000 data sets covering almost any problem that you can think of.
You can try searching and see what you find.
We're going to be using one particularly amazing data set later in this course.
But but you will find lots of data to to solve your problems.
Um, it's similar to to the platform Kaggle which is much more focused on the data side of things.
But you have such a huge resource of that data within hugging face.
And then hugging face also has something called spaces, which is where you can write an app and expose
that app.
Have it running on hugging face cloud hardware and and available for other people to use.
As long as you're you're happy for your code to be open source, because that is the the you know,
that's what Hugging Face is all about.
Uh, so spaces are many of the spaces apps are written built in Gradio.
So they are gradio apps.
Um, there are things that are not gradio apps.
There's something called Streamlit, which is another way to build apps that is also quite magical.
Different to Gradio, quite magical.
Um, and there are some other ways that you can publish apps as well.
Uh, but I'd say Gradio is probably the most common that's there.
And there's in particular things called leaderboards, which are gradio apps whose job it is to evaluate
different llms and rank them and show them in a kind of scorecard.
We're going to be using leaderboards a lot when we look at comparing different llms and, but we'll
be seeing some of them today as well as we look at huggingface spaces.
So that's the Huggingface platform, which is what you get to if you go to Huggingface Co and log in
and start looking at what's out there.
Hugging face also offers libraries code, which forms the basis of many of our open source projects.
And the libraries give us this amazing head start in what we want to do.
It brings time to market much lower, because you can just be off and running very quickly with very
little boilerplate code.
It's the very well crafted libraries to reduce the barrier to entry and make people productive quickly.
The one of the first libraries you'll experience is the Hugging Face Hub, which is a library that allows
you to log in to hugging face and, uh, both download and upload things like data sets and models from
the hub, which is what hugging face calls the platform we just talked about.
Um, data sets is a library that gives us access, immediate access to, uh, the, the the data repositories
in hugging Huggingface and Transformers.
This is a central library, which is the wrapper code around Llms that follow the transformer architecture,
and under the covers it's got either PyTorch or TensorFlow code that actually runs these neural networks.
But when you create a transformer, you have the actual deep neural network code at your fingertips.
When we make calls to functions, to methods in transformer code, we're no longer calling out to an
API running on a cloud somewhere else under OpenAI's umbrella.
We are executing the code ourselves to to execute to either inference or training against our deep neural
network.
So there are three other libraries that I wanted to mention that we're going to come to later in the
course that are more advanced libraries.
Um, the first of them, Peft, stands for parameter efficient fine tuning.
And this is, uh, utilities which allow us to train llms without needing to work with all of the billions
of parameters in the Llms.
So it's parameter efficient.
And the technique in particular that we'll be using is called Laura or Laura is a variation of Laura,
and there'll be plenty of time to explain that later on.
But but bear in mind that's what we'll be using.
And it's part of the Peft library parameter efficient fine tuning.
Then there's a library called Treal, which stands for Transformer Reinforcement Learning.
And it includes a few things.
It's the ability to do things like something called reward modeling.
Mm.
And it's also something called proximal policy optimization PPO.
And you may see mm and PPO mentioned from time to time.
And this is related to uh, the both this thing called WRF that I mentioned a while ago, and it's the
successors better ways of doing it, which is how we are able to train LMS so that they are really effective
at chat.
And it was the key innovation that resulted in ChatGPT in late 2022.
So a lot of that code is within TRL.
Also within TRL is something called supervised fine tuning and SFT, and that is something we will directly
use ourselves later in the course.
That is the specific library we will be using to fine tune an open source model, so that it's even
more effective in our particular domain with a particular problem.
We will set it so SFT supervised fine tuning part of the TRL library.
All these acronyms.
SFT part of TRL uh and the it's a it's an essential framework.
But this is some of the more advanced stuff we'll get back to.
So you don't have to remember all that right now, and certainly don't have to remember all these acronyms,
but just let me plant that seed in you so that when you see it later, it's something that you've heard
of before.
The other one is one that is more of a behind the scenes, but you'll often see us importing it and
making some use of it.
It's called accelerate, and it's some, uh, advanced huggingface code that allows, uh, that allows
our transformers to run across any distributed configuration.
So it allows both training and inference to run at scale in an efficient, adaptable way, potentially
across multiple GPUs.
Although in all the experiments we'll be doing, we'll only be using a maximum of one GPU.
So those are some of the key libraries that sit behind hugging face.
At this point.
I think it's time that we get to look at hugging face.
So let's go in and take some some browsing around, starting with the hugging face platform.