This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: implemented parallel inference for llama-rs, implemented nai…
…ve sequential async inference for llama-cpp and rwkv-cpp (#52) * feat: support parallel inference for llama-rs, support sequential async for llama-cpp and rwkv-cpp
- Loading branch information
Showing
32 changed files
with
558 additions
and
1,415 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,47 @@ | ||
import { EmbeddingResultType, LLama } from "../index"; | ||
import { LLama } from "../index"; | ||
import path from "path"; | ||
import fs from "fs"; | ||
|
||
const model = path.resolve(process.cwd(), "../../ggml-alpaca-7b-q4.bin"); | ||
|
||
LLama.enableLogger(); | ||
|
||
const llama = LLama.create({ | ||
path: model, | ||
numCtxTokens: 128, | ||
}); | ||
|
||
const getWordEmbeddings = (prompt: string, file: string) => { | ||
llama.getWordEmbeddings( | ||
{ | ||
prompt, | ||
numPredict: 128, | ||
temp: 0.2, | ||
topP: 1, | ||
topK: 40, | ||
repeatPenalty: 1, | ||
repeatLastN: 64, | ||
seed: 0, | ||
}, | ||
(response) => { | ||
switch (response.type) { | ||
case EmbeddingResultType.Data: { | ||
fs.writeFileSync( | ||
path.resolve(process.cwd(), file), | ||
JSON.stringify(response.data) | ||
); | ||
break; | ||
} | ||
case EmbeddingResultType.Error: { | ||
console.log(response); | ||
break; | ||
} | ||
} | ||
} | ||
const getWordEmbeddings = async ( | ||
llama: LLama, | ||
prompt: string, | ||
file: string | ||
) => { | ||
const response = await llama.getWordEmbeddings({ | ||
prompt, | ||
numPredict: 128, | ||
temp: 0.2, | ||
topP: 1, | ||
topK: 40, | ||
repeatPenalty: 1, | ||
repeatLastN: 64, | ||
seed: 0, | ||
}); | ||
|
||
fs.writeFileSync( | ||
path.resolve(process.cwd(), file), | ||
JSON.stringify(response) | ||
); | ||
}; | ||
|
||
const dog1 = `My favourite animal is the dog`; | ||
getWordEmbeddings(dog1, "./example/semantic-compare/dog1.json"); | ||
const run = async () => { | ||
const llama = await LLama.create({ | ||
path: model, | ||
numCtxTokens: 128, | ||
}); | ||
|
||
const dog1 = `My favourite animal is the dog`; | ||
getWordEmbeddings(llama, dog1, "./example/semantic-compare/dog1.json"); | ||
|
||
const dog2 = `I have just adopted a cute dog`; | ||
getWordEmbeddings(dog2, "./example/semantic-compare/dog2.json"); | ||
const dog2 = `I have just adopted a cute dog`; | ||
getWordEmbeddings(llama, dog2, "./example/semantic-compare/dog2.json"); | ||
|
||
const cat1 = `My favourite animal is the cat`; | ||
getWordEmbeddings(llama, cat1, "./example/semantic-compare/cat1.json"); | ||
}; | ||
|
||
const cat1 = `My favourite animal is the cat`; | ||
getWordEmbeddings(cat1, "./example/semantic-compare/cat1.json"); | ||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.