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

feat: load multiple models #495

Closed
wants to merge 3 commits into from
Closed

Conversation

vansangpfiev
Copy link
Contributor

@vansangpfiev vansangpfiev commented Apr 10, 2024

Issue link: #467

  • use std::unordered_map to store all llama_server_context (lsc)
  • refactor: move background thread to lsc, each lsc has its own background thread
  • TODO: update documentation

We use mode_id as a key to find the model, so they have to be unique. That requires some changes in request parameter:
For completions:
Have to set value the model_alias for inferences/llamaCPP/loadmodel and inferences/llamaCPP/unloadmodel , this has to be the same as model parameter in inferences/llamaCPP/chat_completion
loadmodel/unloadmodel:

{
...
 "llama_model_path": "file_to_location"
  "model_alias": "model1"
...
}

chat_completion:

{
...
  "model": "model1"  
...
}

For embeddings:
The same for loadmodel/unloadmodel, for embedding request, we need to add model parameter
loadmodel/unloadmodel

{
...
    "llama_model_path": "e:/workspace/model/nomic-embed-text-v1.5.f16.gguf",
    "model_alias": "model1",
    "model_type": "embedding"
...
}

embedding

{
...  
  "input": "how are you",
  "model": "model1"
...
}

@vansangpfiev vansangpfiev self-assigned this Apr 10, 2024
@vansangpfiev vansangpfiev force-pushed the feat-load-multiple-models branch 2 times, most recently from 99ef8e5 to fc8cabd Compare April 12, 2024 03:01
@vansangpfiev vansangpfiev marked this pull request as ready for review April 12, 2024 03:26
@vansangpfiev vansangpfiev force-pushed the feat-load-multiple-models branch from fc8cabd to 4dc2ccf Compare April 16, 2024 01:25
task_queue_thread_num = std::max(task_queue_thread_num, params.n_parallel);
LOG_INFO << "Start inference task queue, num threads: "
<< task_queue_thread_num;
inference_task_queue = std::make_unique<trantor::ConcurrentTaskQueue>(
Copy link
Contributor

Choose a reason for hiding this comment

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

The inference task queue is constructed with the model's parameters. It is shared among the model's operations, which is incorrect, right? Let's say it would be renewed every time a new model request with a larger n_parallel number comes in:

  1. How will pending tasks be processed since it is renewed?
  2. Will later requests change thread_num, causing side effects for previously loaded models?"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One solution (though it is not optimal) is that we can use a task queue for each model. Will change the code to make it works correctly first.

auto s = input.asString();
std::replace(s.begin(), s.end(), '\\', '/');
auto const pos = s.find_last_of('/');
// We only if file name has gguf extension or nothing
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing some words

Copy link
Contributor

@louis-menlo louis-menlo left a comment

Choose a reason for hiding this comment

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

LGTM

@vansangpfiev
Copy link
Contributor Author

Moved PR to janhq/cortex.llamacpp#14

@vansangpfiev vansangpfiev deleted the feat-load-multiple-models branch July 8, 2024 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants