Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Improve llama.cpp snippet #778

Merged
merged 8 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/tasks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export { snippets };
export { SKUS, DEFAULT_MEMORY_OPTIONS } from "./hardware";
export type { HardwareSpec, SkuType } from "./hardware";
export { LOCAL_APPS } from "./local-apps";
export type { LocalApp, LocalAppKey } from "./local-apps";
export type { LocalApp, LocalAppKey, LocalAppSnippet } from "./local-apps";

export { DATASET_LIBRARIES_UI_ELEMENTS } from "./dataset-libraries";
export type { DatasetLibraryUiElement, DatasetLibraryKey } from "./dataset-libraries";
71 changes: 49 additions & 22 deletions packages/tasks/src/local-apps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import type { ModelData } from "./model-data";
import type { PipelineType } from "./pipelines";

export interface LocalAppSnippet {
/**
* Title of the snippet
*/
title: string;
/**
* Optional setup guide
*/
setup?: string;
/**
* Content (or command) to be run
*/
content: string;
}

/**
* Elements configurable by a local app.
*/
Expand Down Expand Up @@ -39,36 +54,48 @@ export type LocalApp = {
* And if not (mostly llama.cpp), snippet to copy/paste in your terminal
* Support the placeholder {{GGUF_FILE}} that will be replaced by the gguf file path or the list of available files.
*/
snippet: (model: ModelData, filepath?: string) => string | string[];
snippet: (model: ModelData, filepath?: string) => string | string[] | LocalAppSnippet | LocalAppSnippet[];
}
);

function isGgufModel(model: ModelData) {
return model.tags.includes("gguf");
}

const snippetLlamacpp = (model: ModelData, filepath?: string): string[] => {
const snippetLlamacpp = (model: ModelData, filepath?: string): LocalAppSnippet[] => {
const command = (binary: string) =>
[
"# Load and run the model:",
`${binary} \\`,
` --hf-repo "${model.id}" \\`,
` --hf-file ${filepath ?? "{{GGUF_FILE}}"} \\`,
' -p "You are a helpful assistant" \\',
" --conversation",
Vaibhavs10 marked this conversation as resolved.
Show resolved Hide resolved
].join("\n");
return [
`# Option 1: use llama.cpp with brew
brew install llama.cpp

# Load and run the model
llama \\
--hf-repo "${model.id}" \\
--hf-file ${filepath ?? "{{GGUF_FILE}}"} \\
-p "I believe the meaning of life is" \\
-n 128`,
`# Option 2: build llama.cpp from source with curl support
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
LLAMA_CURL=1 make

# Load and run the model
./main \\
--hf-repo "${model.id}" \\
-m ${filepath ?? "{{GGUF_FILE}}"} \\
-p "I believe the meaning of life is" \\
-n 128`,
{
title: "Install from brew",
setup: "brew install llama.cpp",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw unrelated but wondering is llama.cpp is on winget? cc @mfuntowicz too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked here: https://winget.run and didn't find any. To think of it, it'd be a pretty cool idea to add that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it would be nice to have, knowing that llama.cpp already have pre-built binary via CI. Unfortunately I'm not very familiar with windows stuff, so I'll create an issue on llama.cpp to see if someone can help.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created the issue: ggerganov/llama.cpp#8188

content: command("llama-cli"),
},
{
title: "Use pre-built binary",
setup: [
// prettier-ignore
"# Download pre-built binary from:",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptually LGTM. Just wondering if this doesn't bloat the overall UI for snippets for a user i.e. we present too many options to the end-user.

(just food for thought)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I switched my mind to "UX/UI designer" when I drafted this proposal ;-)

The current UI has a problem that these multiple snippets but no title for them (visually hard to distinct between the 2 snippets):

image

My first iteration would be to have a title for each snippet, then only "expand" one section at a time (while other options are "collapsed")

image

But then I think we can also split between the "setup" and "run" step, since ideally the user will setup just once but run multiple times.

Feel free to give other suggestions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea I quite like the second image. Let's ask @gary149/ @julien-c for thoughts here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @gary149 wdyt

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bumping this as I think it'll be good to merge this soon! cc: @gary149 (sorry for creating an extra notification)

Copy link
Collaborator

@gary149 gary149 Jul 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay on the UI, but let's see if it's not busted on the Hub side. (sorry for the late reply)

"# https://github.com/ggerganov/llama.cpp/releases",
].join("\n"),
content: command("./llama-cli"),
},
{
title: "Build from source code",
setup: [
"git clone https://github.com/ggerganov/llama.cpp.git",
"cd llama.cpp",
"LLAMA_CURL=1 make llama-cli",
].join("\n"),
content: command("./llama-cli"),
},
];
};

Expand Down
Loading