-
Notifications
You must be signed in to change notification settings - Fork 27
[ml service] Support flexible tensors for compatibility with filters like llama.cpp #635
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,9 +139,9 @@ typedef struct | |
| gboolean invoking; /**< invoke running flag */ | ||
| ml_tensors_data_h in_tensors; /**< input tensor wrapper for processing */ | ||
| ml_tensors_data_h out_tensors; /**< output tensor wrapper for processing */ | ||
| gboolean is_flexible; /**< true if tensor filter handles flexible input/output */ | ||
|
|
||
| GList *destroy_data_list; /**< data to be freed by filter */ | ||
| tensor_format format; /**< current format */ | ||
| } ml_single; | ||
|
|
||
| /** | ||
|
|
@@ -781,11 +781,10 @@ ml_single_set_info_in_handle (ml_single_h single, gboolean is_input, | |
| ml_tensors_info_h info = NULL; | ||
|
|
||
| ml_single_get_gst_info (single_h, is_input, &gst_info); | ||
| if (single_h->is_flexible) { | ||
| gst_info.format = _NNS_TENSOR_FORMAT_FLEXIBLE; | ||
| gst_info.num_tensors = 1U; /* TODO: Consider multiple input tensors filter */ | ||
| if (single_h->format == _NNS_TENSOR_FORMAT_FLEXIBLE) { | ||
| gst_info.format = single_h->format; | ||
| gst_info.num_tensors = 1U; /* TODO: Consider multiple input tensors filter */ | ||
| } | ||
|
|
||
| _ml_tensors_info_create_from_gst (&info, &gst_info); | ||
|
|
||
| gst_tensors_info_free (&gst_info); | ||
|
|
@@ -854,7 +853,6 @@ ml_single_create_handle (ml_nnfw_type_e nnfw) | |
| single_h->output = NULL; | ||
| single_h->destroy_data_list = NULL; | ||
| single_h->invoking = FALSE; | ||
| single_h->is_flexible = FALSE; | ||
|
|
||
| gst_tensors_info_init (&single_h->in_info); | ||
| gst_tensors_info_init (&single_h->out_info); | ||
|
|
@@ -955,7 +953,6 @@ ml_single_open_custom (ml_single_h * single, ml_single_preset * info) | |
| gchar **list_models; | ||
| guint i, num_models; | ||
| char *hw_name; | ||
| gboolean invoke_dynamic = FALSE; | ||
|
|
||
| check_feature_state (ML_FEATURE_INFERENCE); | ||
|
|
||
|
|
@@ -1078,10 +1075,14 @@ ml_single_open_custom (ml_single_h * single, ml_single_preset * info) | |
| fw_name = _ml_get_nnfw_subplugin_name (nnfw); /* retry for "auto" */ | ||
| } | ||
| hw_name = _ml_nnfw_to_str_prop (hw); | ||
|
|
||
| g_object_set (filter_obj, "framework", fw_name, "accelerator", hw_name, | ||
| "model", converted_models, NULL); | ||
| "model", converted_models, "invoke-dynamic", info->invoke_dynamic, NULL); | ||
| g_free (hw_name); | ||
|
|
||
| if (info->invoke_dynamic) | ||
| single_h->format = _NNS_TENSOR_FORMAT_FLEXIBLE; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, should we keep current format here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently updating within the sub-plugin. We need to fix all sub-plugins. Is it a necessary discussion? |
||
|
|
||
| if (info->custom_option) { | ||
| g_object_set (filter_obj, "custom", info->custom_option, NULL); | ||
| } | ||
|
|
@@ -1105,11 +1106,6 @@ ml_single_open_custom (ml_single_h * single, ml_single_preset * info) | |
| * | ||
| */ | ||
|
|
||
| if (invoke_dynamic) { | ||
| single_h->is_flexible = TRUE; | ||
| g_object_set (filter_obj, "invoke-dynamic", TRUE, NULL); | ||
| } | ||
|
|
||
| if (nnfw == ML_NNFW_TYPE_NNTR_INF) { | ||
| if (!in_tensors_info || !out_tensors_info) { | ||
| if (!in_tensors_info) { | ||
|
|
@@ -1230,6 +1226,14 @@ ml_single_open_with_option (ml_single_h * single, const ml_option_h option) | |
| if (ML_ERROR_NONE == ml_option_get (option, "framework_name", &value) || | ||
| ML_ERROR_NONE == ml_option_get (option, "framework", &value)) | ||
| info.fw_name = (gchar *) value; | ||
| if (ML_ERROR_NONE == ml_option_get (option, "invoke_dynamic", &value)) { | ||
| if (strcasecmp ((gchar *) value, "TRUE") == 0) | ||
| info.invoke_dynamic = TRUE; | ||
| } | ||
| if (ML_ERROR_NONE == ml_option_get (option, "invoke_async", &value)) { | ||
| if (strcasecmp ((gchar *) value, "TRUE") == 0) | ||
| info.invoke_async = TRUE; | ||
| } | ||
|
|
||
| return ml_single_open_custom (single, &info); | ||
| } | ||
|
|
@@ -1345,10 +1349,8 @@ _ml_single_invoke_validate_data (ml_single_h single, | |
| "The %d-th input tensor is not valid. There is no valid dimension metadata for this tensor.", | ||
| i); | ||
|
|
||
| if (single_h->is_flexible) { | ||
| /* Skip data size check for flexible */ | ||
| if (single_h->format == _NNS_TENSOR_FORMAT_FLEXIBLE) | ||
| continue; | ||
| } | ||
|
|
||
| raw_size = _model->tensors[i].size; | ||
| if (G_UNLIKELY (_data->tensors[i].size != raw_size)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "single" : | ||
| { | ||
| "framework" : "llamacpp", | ||
| "model" : ["../tests/test_models/models/llama-2-7b-chat.Q2_K.gguf"], | ||
| "custom" : "num_predict:32", | ||
| "invoke_dynamic" : "true", | ||
| "invoke_async" : "false" | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.