Local Tool Calling with llamacpp
Summary
TLDRローカルモデルの使用と機能呼び出しの重要性について説明するビデオです。ローカルモデルを使って高精度を保ちながら推論速度を上げる方法や、LLMに外部ツールをバインドして特定のタスクを実行させる仕組みについて紹介しています。Hermes 2 Pro llama 38bモデルを使った具体例を示し、ローカル環境でツールコールを実行するプロセスを詳細に解説。特に、ツールコールがエージェントにとって重要な機能であることを強調し、ローカルエージェントのセットアップの将来の可能性について触れています。
Takeaways
- 🌐 LanceがL chainからローカルモデルのハイレベルな興味を報告しています。ローカルモデルとは、ノートPCやデバイス上でLLMを実行できる機能です。
- 🛠️ LLMの重みを量子化または精度を32ビットから8ビットなどに下げることで、モデルサイズを小さくして推論速度を上げ、精度を最小限に損なわないようにします。
- 📈 LLMのローカル実行はAppleデバイスなどでもサポートされ、プライバシーを保護しながらモデルを実行できます。
- 🔧 ツール呼び出しや関数呼び出しは、LLMの機能を拡張する重要な要素で、外部のツールをLLMにバインドして使用します。
- 🔄 LLMはツールを実行する能力はなく、入力に基づいてツールを実行するためのペイロードを返すことができます。
- 🔗 Lanceはllama.cppという新しい統合を紹介しており、これはツール呼び出しを有効にします。
- 📚 Lanceはローカルで実行するための適切なモデルを選択する重要性を強調しており、Hermes 2 Pro llama 38bはツール呼び出しにチューニングされています。
- 💻 ローカルでの実行には、大きなパラメータモデルは推奨されず、8億パラメータモデルがローカルPCで実行できるサイズだと述べています。
- 🔧 Lanceはローカル環境の設定方法や、Apple MetalなどのGPUの活用方法についてガイドを提供しています。
- 📝 ローカルでの実行例として、LanceはノートPCでモデルを初期化し、ツール呼び出しを実演しています。
- 🤖 ツール呼び出しは構造化された出力を生成する場合にも使用でき、ジョークの例として実際に動作を確認しています。
- 🚀 LanceはローカルLLMの進化と、将来的にはローカルエージェントの設定にツール呼び出しを使用する可能性について触れています。
Q & A
ローカルモデルとは何ですか?
-ローカルモデルとは、例えばノートパソコンやデバイス上で直接実行可能な言語モデル(LM)のことを指します。これにより、モデルのサイズを小さくしたり、推論の速度を上げたりすることができます。
モデルのウェイトを量子化することとは何を意味しますか?
-モデルのウェイトを量子化とは、例えば32ビットの浮動小数点数から8ビットなどに精度を下げることで、モデルのサイズを小さくし、推論速度を上げることができます。
ツール呼び出しとは何を意味していますか?
-ツール呼び出しは、言語モデル(LM)の外部で定義されたツールを呼び出すことです。LMはそのツールを実行する機能を持たないが、入力に基づいてツールを実行するためのペイロードを返すことができます。
llama CDPとの統合とは何を意味しますか?
-llama CDPとの統合は、ツール呼び出しを可能にする機能を提供する、llama CDPと言語モデルを連携させることを意味します。これにより、ローカルでモデルを実行し、ツール呼び出しを活用することが可能になります。
Hermes 2モデルとは何ですか?
-Hermes 2モデルは、ツール呼び出しに特化してチューニングされた8億パラメーターの言語モデルです。このモデルは、ツール呼び出しの評価で90%のスコアを獲得しており、ローカルでの実行に適しています。
ローカルで言語モデルを実行するためにはどのような環境設定が必要ですか?
-ローカルで言語モデルを実行するためには、AppleのデバイスであればMetalを利用し、環境によってはGPUの利用も検討する必要があります。また、モデルの実行に必要なパッケージをインストールすることも重要です。
モデルの初期化とは何を意味していますか?
-モデルの初期化とは、言語モデルを実行するための準備を整えることを意味します。これには、モデルのウェイトをロードし、必要なライブラリを初期化する作業が含まれます。
ツールのバインドとは何を意味していますか?
-ツールのバインドとは、言語モデルにツールを関連付けることを意味します。これにより、LMは入力に応じてツールを実行するためのペイロードを返すことができます。
ローカルで実行されたモデルのパフォーマンスはどのように評価されますか?
-ローカルで実行されたモデルのパフォーマンスは、ツール呼び出しの正確性や構造化された出力を評価する指標に基づいて評価されます。たとえば、Hermes 2モデルは、ツール呼び出しの評価で90%のスコアを獲得しています。
ローカルで実行される言語モデルの将来性についてどう考えていますか?
-ローカルで実行される言語モデルは、より良いチューニングやデータに基づいて徐々に性能が向上していくと予想されます。将来的には、より大きなモデルもローカル環境で実行できるようになり、より高度な機能を提供するでしょう。
Outlines
🤖 ローカルモデルでのツール使用と機能呼び出しの紹介
Lanceは、ローカルマシン上でLLM(大規模言語モデル)を実行する能力に高い関心があることを指摘。特に、デバイス上でモデルの重みを量子化または精度を下げることで、モデルサイズを小さくして推論速度を上げ、精度を最小限に損なわないようにすることができる。このプロセスには、Appleのデバイスを含む多くのプラットフォームが対応しており、特にHermes 2 Pro llama 38bモデルはツール呼び出しに適しています。このモデルはFireworks AIと提携し、関数呼び出しの評価で90%、構造化出力の評価で84%の精度を達成している。しかし、8億パラメーターモデルはこの用途には少し小さすぎるため、より大きなラップトップで70億パラメーターモデルを実行することを提案している。
🔧 ローカル環境でのツール呼び出しの実践
Lanceは、ローカル環境でツール呼び出しを実行する方法を説明し、新しいchat llama CPPの統合を紹介。ツール呼び出しは、外部のツールに入力を渡し、モデルがその入力に基づいて必要なペイロードを返すことができる機能である。このプロセスは、モデルが文字列を文字列に変換するのではなく、入力と生の関数から抽出されたスキーマに基づいて関数を実行するペイロードを返すことに重点を置いている。Lanceは、Hermes 2 Pro llama 3モデルを使用して、ローカルで実行し、関数呼び出しの正確性と信頼性をテストした。また、ローカルで実行する際には、Appleのメタルを使用するなど、環境の設定に関するガイドも提供している。
Mindmap
Keywords
💡LLM(Large Language Model)
💡量子化(Quantization)
💡推論(Inference)
💡ツール呼び出し(Tool Calling)
💡Llama CPP
💡Hermes 2 Pro
💡ローカル環境(Local Environment)
💡モデルのファインチューニング(Fine-tuning)
💡構造化出力(Structured Output)
💡Lang Smith
Highlights
ローカルモデルの高い関心:ローカルデバイスでLLMを実行する能力が高い関心を集めている。
モデルの量子化:LLMのウェイトを量子化し、精度を低下させることなくモデルサイズを縮小し、推論速度を向上させる。
ツール使用の重要性:エージェントのためのツールコーリングの重要性について議論。
Llama CPPとの統合:Llama CPPとの新しい統合がツール使用を可能にする。
Hermes 2 Pro llama 38Bモデル:ツールコーリングに最適化された8億パラメータモデル。
ツールバインディング:LLMにツールをバインドするプロセスの詳細。
基本機能のデモ:ローカルでLLMを実行し、英語からフランス語への翻訳が成功。
ツールコーリングの実例:場所と単位を入力として天気情報を取得するツールをバインド。
LangSmithとの連携:ツールコーリングの結果がLangSmithに表示される。
構造化出力のサポート:LLMが構造化出力を生成するための方法。
鳥に関するジョーク:LLMが鳥に関するジョークを生成する例。
ツールコーリングの信頼性:ツールコーリングの信頼性とパフォーマンスの改善方法。
大容量モデルの可能性:大容量モデル(70Bなど)を使用することでパフォーマンスが向上。
ローカルエージェントの設定:ツールコーリングを使用したローカルエージェントの設定についての言及。
未来の展望:より優れたローカルLLMが登場することで、ツールコーリングの能力がさらに向上する期待。
Transcripts
hey this is Lance from L chain we' seen
very high interest in local models so
that's the ability to run llms locally
for example on your laptop or maybe on
your device um and we've done quite a
bit of work on this we have a few videos
focusing on ways you can incorporate
local models and advanc workflows like
rag but there's been one thing that's
kind of been missing and that is this
idea of tool use or function calling
which can be kind of used
interchangeably and I'm going to talk
about that today because we just
released an integration with llama CDP
that enables this so first of all local
M the big idea here is simply this you
can take an lm's weights and you can
basically quantize them or reduce their
Precision for example from like say
32bit floating Point down to say 8 bit
or lower to reduce the model size and
speed up inference with minimal loss and
accuracy this allows you to run it even
on your device so many many Apple
devices now will support running uh
running llms uh directly locally free
private so this is like obviously really
cool AMA is one of the great options for
doing this cppp is the other one so kind
of these are two of the more popular
ways to do and there there are of course
some others so I don't want to exclude
anyone now here's the rub tool calling
is really important for lots of things
in particular agents and really what's
going on with tool calling is this
you're defining some tool so external to
the LM so let's say in this particular
case we have this tool called Magic
function you take an input add two to it
what we really want to do is bind it to
the llm okay so we bind this tool and
when the the input is relevant to that
particular tool the llm knows to return
a payload necessary to run the tool now
this is kind of an often misconception
the LM doesn't have the ability to like
somehow magically run this function
right it's string to string typed but
what's happening is it can return the
payload necessary to run the function
based upon the input and the schema that
is extracted from the raw function
itself that's really what's going on so
what you're getting out from a tool call
is basically like the tool arguments and
the tool name for the input so that's
really what's going on it's a kind of
central capability and kind of a high
general interest now I want to walk you
through the process of doing this
locally on my laptop uh using our new
chat llama CPP integration so I'm go
over to the notebook here now here's
what's very important you have to pick
the right model that ideally supports
tool calling so for this I hunted around
local llama and this Hermes 2 model
Hermes 2 Pro llama 38b has been fine-
tuned for Tool calling you I'll share of
course this link you can go through it
uh but it's pretty neat so in particular
scoring 90% on our function calling
evaluation build partnership with
fireworks AI um and on our and 84% on
structured output evaluation so here's
kind of the catch this is a very good
this is a very good model to test I'm
going to caveat that it's an 8 billion
parameter model most providers I talked
to fireworks for example that kind of
don't recommend tool calling with 8
billion parameter models same with Gro
so 8 billion is definitely small but
it's what we can runow locally on a
laptop unless you have a larger laptop
you can try 70 billion of course but so
we're going to try this out um so we're
going to be using this Hermes 2 Pro
llama 3 Model that's been fine-tuned for
Tool calling 8 billion parameter model
so all I've done is when I go over to
hugging face here I go to the files and
versions I just download one of these
models I already did this so I don't
want to waste your time with that um in
my notebook now I'm just in PIP
installing a few a few packages here
lent Community lb P python this is based
of python wrapper from llama CBP allows
you to to basically use llama CBP
functionality so here's what I'm doing I
specify the path to my model boom right
here and I go ahead and and uh initi
instantiate it so boom there we go and
so you'll see all this spam out don't
worry too much about it this kind of
always is the case it'll give you a
whole bunch of logging about the model
you can kind of dig through it if you're
interested um so and I will make a quick
note I'll showare this of course check
out our guide and running LMS locally
there are some things you want to do
with your environment before you try
this for example Mac um basically that
you're utilizing Apple metal or or the
Apple GPU but that's kind of a separate
Point uh and um I'll I'll point you to
our guide to kind of go through that
anyway so we initialized our model uh
now try an invocation so we go ahead and
run this you can see it's running
locally so it takes a little bit of time
uh and I can even go to Lang Smith
because I should be just kind of logging
these um to my default project let's see
I'm in my personal user I go to rlm and
and there it is so you can see llama
cppp is running uh and it is still going
okay it looks like it's done so it
translated uh uh I love programming from
English to French and this should be
yeah there it is it comes through so
okay cool so we have basic functionality
working um let's see we can try basic
chain to a prompt llm we can go back to
Lang Smith we can kind of look at what's
going on so we can look at what the
input is input language output language
German input I love programming uh this
is still running and cool that's done
and this should show up in Lang now
there it is okay so those are
fundamentals now here are things get
kind of interesting tool calling like
what we talked about here so what we're
doing here is I'm going to go ahead and
Define some Tool uh so for example in
this particular case I'm defining the
the input to the input schema to Tool
explicitly this weather input location
uh and uh the location and the unit
specifi those as strings um I add those
to the argument schema for my tool so
this tool decorator indicates that this
function is going to be a tool and then
I'm going to bind that to my llm so all
I need to do is llm which we defined up
here right that's this guy all the way
up that's our llm right that's just our
model llm dot bind tools I passed the
Tool uh function name and this is the
catch here this is actually very
important to get this to run reli Le at
least in my experience and I've tested
this only only a bit you I found that
using us enforced invocation of the
function certainly improves reliability
and performance quite a bit we need to
do evals on this to kind of confirm it
but that's been my experience today so
let's go ahead and try this out so I'm
going to run this and again this might
take a little bit of time because we're
all running locally um it'll kind of
spam out okay and that's that ran that's
pretty cool so here's what's neat if I
go to the AI message tool calls and look
at this this is pretty nice remember
look back at here what is really coming
with a tool call all you're getting is
like payload need to run the tool and
the tool name look at this tool name get
weather arguments location unit and it's
parsing that just from natural language
it even does the conversion from HCMC to
hoi Min City pretty cool right um so
this is actually working this is working
locally on my laptop I can go over
to uh y I can go over to here and yeah
look at this this is neat right so I'm
in lsmith here uh this is showing you
that this particular tool is bound to my
llm um it's cool
this flag tells you it's called really
cool you get here's the tool name that
was invoked here's the payload so great
this this is now working that's really
nice um yeah this is showing another
example of my little magic function um
same idea what is Magic function of
three and let's see yeah so you get the
tool name magic function and then the
arguments is Magic function three so
that's really neat now what's another
cool thing about this tool calling is
kind of a very general case and it can
be used to do kind of structured outputs
as well uh and so we actually have a
very nice kind of helper uh kind of
method for that called with structured
output again you just pass your uh your
your output schema uh to okay in this
particular case you actually convert it
to a dictionary so you convert to open
ey tool and then you pass that in to
what structured output let's try this
joke tell me let's try this out tell me
a joke about birds and that is running
and hopefully this works and maybe it's
a funny joke okay this time it's a
little bit flaky it doesn't give me a
setup it only gives me a punch line
let's try that again so you can see the
reliability is a little bit variable
you'd have to tune this a little bit
maybe it's an issue of um yeah okay so
in this case it didn't quite work quite
as well uh but I have seen this work in
other particular cases so uh it may
depend a little bit on the formulation
of the joke okay so in this particular
case you get the setup you get the punch
line so again uh I think it's absolutely
worth playing with this it's really
interesting the fact that you can run
tool CL locally opens up a lot of cool
things um of course if you have a larger
laptop you actually run higher capacity
models like 70b I think those would
really work well I'm using 8 billion
parameter model a little bit small for
this particular kind of use case but it
does appear to be working new
integration I would definitely encourage
playing with this and I mean here's the
thing that I really think is important
to note look these mods are only going
to get better so as better L you know as
better local LM come out better fine
tunes find tun on more data like the
capacities will get more and more and
more or or kind of greater and greater
and greater and so um maybe in some
future videos we'll talk a little bit
about setting up local agents using tool
calling we've done a lot of local agents
using Lang graph without tool calling
but with the the ability to kind of call
tools through LL CVP currently um we may
be able to kind of take a stab at
setting up some tool calling agents and
uh we'll follow up on that in the in the
near future thanks
Weitere verwandte Videos ansehen
![](https://i.ytimg.com/vi/K2lkAl9_zy8/hq720.jpg)
How to Use Stable Diffusion AI (Locally) with AI Agents using AutoGen!
![](https://i.ytimg.com/vi/9q6h5EreGxY/hq720.jpg?v=658005c1)
GPTs解説#3 外部APIを利用できる「Actions」機能の仕組みと使い方 【ChatGPT】
![](https://i.ytimg.com/vi/CdQd6rfIv5M/hq720.jpg)
Dify AI: Create LLM Apps In SECONDS with NO Code FOR FREE! Flowise 2.0?
![](https://i.ytimg.com/vi/DtZhJkDSKiI/hq720.jpg?v=655c0b26)
GPTs解説の詐欺動画ばっかだから本当の解説します#0 【ChatGPT】
![](https://i.ytimg.com/vi/G6nmspkp6eo/hq720.jpg)
Llama 3 tool calling agents with Firefunction-v2
![](https://i.ytimg.com/vi/pvlT056DAHs/hq720.jpg)
Agent Trajectory | LangSmith Evaluation - Part 26
5.0 / 5 (0 votes)