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

[Fix] Implement lock to ensure FCFS of requests to same model #549

Merged
merged 2 commits into from
Aug 19, 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
9 changes: 6 additions & 3 deletions examples/multi-models/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ async function parallelGeneration() {
);

// We can serve the two requests concurrently
let message1 = "";
let message2 = "";

async function getModel1Response() {
let message1 = "";
const asyncChunkGenerator1 = await engine.chat.completions.create(request1);
for await (const chunk of asyncChunkGenerator1) {
// console.log(chunk);
Expand All @@ -110,6 +108,7 @@ async function parallelGeneration() {
}

async function getModel2Response() {
let message2 = "";
const asyncChunkGenerator2 = await engine.chat.completions.create(request2);
for await (const chunk of asyncChunkGenerator2) {
// console.log(chunk);
Expand All @@ -123,6 +122,10 @@ async function parallelGeneration() {
}

await Promise.all([getModel1Response(), getModel2Response()]);
// Note: concurrent requests to the same model are executed sequentially in FCFS,
// unlike to different models like above
// Fore more, see https://github.com/mlc-ai/web-llm/pull/549
// await Promise.all([getModel1Response(), getModel1Response()]);

// without specifying from which model to get message, error will throw due to ambiguity
console.log("Final message 1:\n", await engine.getMessage(selectedModel1));
Expand Down
Loading
Loading