-
Notifications
You must be signed in to change notification settings - Fork 168
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
ExtractAdapters
: Extract lora adapters and use them as model inputs or external initializers
#1064
Conversation
quant works too, name updated
- isolated env system update - external initializers test
22bf0b2
to
84a7874
Compare
the external_initializers_name description need to be updated. |
LGTM, I will let other guys put comments. |
@classmethod | ||
def _default_config(cls, accelerator_spec: AcceleratorSpec) -> Dict[str, PassConfigParam]: | ||
return { | ||
"make_inputs": PassConfigParam( |
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.
Do we need to extend it with external data config?
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.
Seems the external related config would be enabled always, right?
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.
Yes, it will always be saved with external data as it is right now so we don't provide the user config options.
# raw_data is required for set_external_data | ||
if not new_initializer.HasField("raw_data"): | ||
new_initializer.raw_data = b"" | ||
set_external_data(new_initializer, location="dummy-location.bin") |
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.
Will this external data be stored under the path user running olive?
Seems it is dummy
stuff? Where will we remove it?
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.
Let us assume the pass flows as
- model M -> Finetuning A -> conversion -> extract external lora weights A1
- model M -> Finetuning B -> conversion -> extract external lora weights B1
Will the dummy-location.bin be overwrote?
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 actually just a place holder. Since the raw_data field is cleared, during model save, it doesn't save anything at this location. https://github.com/onnx/onnx/blob/main/onnx/external_data_helper.py#L304
This is why the description of this PR says the onnx model produced by extract as initializers is invalid because it points to non-existent file.
This is okay since we only intend to use this model using ort inference session with the missing initializers already added to session options.
python -m olive.scripts.export_adapters --adapter_path Mikael110/llama-2-7b-guanaco-qlora --dtype float16 --pack_weights --output_path models/guanaco_fp16_packed.npz | ||
``` | ||
|
||
Snippet below shows an example runs of the generated fine-tuned model using two different adapters. |
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.
As a follow up PR, we want to move this snippet into a working Jypter notebook.
@@ -0,0 +1,100 @@ | |||
import argparse |
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.
We need to cover this script in Olive docs.
Describe your changes
ExtractAdapters
which extracts the lora adapters (float or static quantized) weights and saves them in a separate file. The model graph is also modified in one of the following ways:add_initializer
oradd_external_initializers
.ExtractAdapters
pass.OnnxDAG
utils added to perform onnx graph manipulations. The methods are generic and can be used in other new passes.ONNXModelHandler
has two corresponding new attributes that must be names of files in themodel_path
directory:external_initializers_file_name
constant_inputs_file_name
olive.common.ort_inference.get_ort_inference_session
andOrtInferenceSession
can handle the external initializers and constant inputs.Checklist before requesting a review
lintrunner -a
(Optional) Issue link