-
Notifications
You must be signed in to change notification settings - Fork 12.2k
add alias for lora adaptors #8636
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the correct usage of lora adapter in llama.cpp
The adapter is loaded independently from inference context (
llama_context
). To control which adapter is enabled or not, usellama_lora_adapter_set
andllama_lora_adapter_remove
See: #8332
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for replying.
If the adaptors are expected to set/remove outside of the library. It should not be loaded while initialized the model.
IMO, the adaptors can be handled outsize the library, but the exist adaptors are unknown and invisiable. Need explicity way to clean current adaptors. It would be better to have
llama_lora_adaptors_clean
to clean exist adaptors.In real scenarios, apply multiple adaptors on the foundation model is not common(let me know if there are cases). Apply one adaptor on foundation model is a common partten. And when setting a adaptor, usually we need clean exist adaptors outside of the library, but the exist adaptors are invisiable.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's small misconception here. llama.cpp comes with 2 main interfaces:
llama_context
andllama_model
. When you load the model, tensors are stored inllama_model
as read-only. If you want to use these tensors for inference, you need to pass the model tollama_context
. This makes it possible to re-use onellama_model
in multiplellama_context
The same idea applies to
llama_lora_adapter
. When adapter is loaded, you can reuse it in multiple differentllama_context
. Imagine one context can use adapter for task A and the other can use adapter for task B.The list of active adapters is held by each
llama_context
(with the corresponding scales)When you want to remove adapter from llama_context, use
llama_lora_adapter_remove
. To free an adapter (i.e. remove it completely from memory), usellama_lora_adapter_free
. The adapters are also free ifllama_model
is freed, because adapter is linked to specific model.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After lctx, model loaded outside of the library:
std::tie(model, ctx) = llama_init_from_gpt_params(params);
The ctx handles the adaptors and invisible outside library scope. The inference context allocate the memory for computation graph calculation. The efficient way is reused the same context.
Or the adaptors have to be handled outside the library and prevent load any adaptors within the library scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that common use case is one adapter per context, and
llama_lora_adaptors_clean
maybe useful to detach all adapters from a given context. But IMO llama.cpp should only provides most low-level API and user can build their own wrapper logic on top of it. Much like how operating systems only provide most basic syscalls, and libraries like glibc build on top of these syscalls.In your case, user can simply write a
llama_lora_adapter_switch(llama_lora_adapter * ptr)
that automatically detach old adapter usingllama_lora_adapter_remove
, then attach the new one withllama_lora_adapter_set
. It could be implement as a utility (seecommon
folder).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree adding a
llama_lora_adaptors_clear
to clean exist adaptors. If this cleaning functionality is visible outside of the library’s scope, users can manipulate the adaptors outside of the library to customize them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look on #8653
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
llama_init_from_gpt_params
is not part of the library, it's only part of the examples. 3rd party applications should not rely on it.