Skip to content

Commit 5eb5c42

Browse files
committed
[ml service] Add Flare as a new nnfw type
- Implemented support for 'flare' nnfw type in ML service API - Included test cases to validate flare functionality Signed-off-by: hyunil park <hyunil46.park@samsung.com>
1 parent 40e1488 commit 5eb5c42

File tree

5 files changed

+70
-19
lines changed

5 files changed

+70
-19
lines changed

c/include/nnstreamer-tizen-internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
extern "C" {
2020
#endif /* __cplusplus */
2121

22+
#define ML_NNFW_TYPE_FLARE 23 /**< FLARE framework */
23+
2224
/**
2325
* @brief Constructs the pipeline (GStreamer + NNStreamer).
2426
* @details This function is to construct the pipeline without checking the permission in platform internally. See ml_pipeline_construct() for the details.

c/src/ml-api-inference-single.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static const char *ml_nnfw_subplugin_name[] = {
114114
[ML_NNFW_TYPE_QNN] = "qnn",
115115
[ML_NNFW_TYPE_LLAMACPP] = "llamacpp",
116116
[ML_NNFW_TYPE_TIZEN_HAL] = "tizen-hal",
117+
[ML_NNFW_TYPE_FLARE] = "flare",
117118
NULL
118119
};
119120

@@ -979,16 +980,25 @@ ml_single_open_custom (ml_single_h * single, ml_single_preset * info)
979980
for (i = 0; i < num_models; i++)
980981
g_strstrip (list_models[i]);
981982

982-
status = _ml_validate_model_file ((const char **) list_models, num_models,
983-
&nnfw);
984-
if (status != ML_ERROR_NONE) {
985-
_ml_error_report_continue
986-
("Cannot validate the model (1st model: %s. # models: %d). Error code: %d",
987-
list_models[0], num_models, status);
988-
g_strfreev (list_models);
989-
return status;
983+
/**
984+
* Note : OpenVINO and flare use the bin extension.
985+
* _ml_validate_model_file() infers nnfw based on the file extension.
986+
* The .bin extension is recognized as OpenVINO (ML_NNFW_TYPE_OPENVINO) by default
987+
* If "flare" is specified, it forces ML_NNFW_TYPE_FLARE.
988+
*/
989+
if (info->fw_name && strcasecmp (info->fw_name, "flare") == 0) {
990+
nnfw = ML_NNFW_TYPE_FLARE;
991+
} else {
992+
status = _ml_validate_model_file ((const char **) list_models, num_models,
993+
&nnfw);
994+
if (status != ML_ERROR_NONE) {
995+
_ml_error_report_continue
996+
("Cannot validate the model (1st model: %s. # models: %d). Error code: %d",
997+
list_models[0], num_models, status);
998+
g_strfreev (list_models);
999+
return status;
1000+
}
9901001
}
991-
9921002
g_strfreev (list_models);
9931003

9941004
/**

tests/capi/unittest_capi_service_extension.cc

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <gtest/gtest.h>
1111
#include <glib.h>
12-
12+
#include <iostream>
1313
#include <ml-api-service-private.h>
1414
#include <ml-api-service.h>
1515
#include "ml-api-service-extension.h"
@@ -394,8 +394,7 @@ _extension_test_imgclf (ml_service_h handle, gboolean is_pipeline)
394394
* @brief Callback function for scenario test.
395395
*/
396396
static void
397-
_extension_test_llamacpp_cb (
398-
ml_service_event_e event, ml_information_h event_data, void *user_data)
397+
_extension_test_llm_cb (ml_service_event_e event, ml_information_h event_data, void *user_data)
399398
{
400399
extension_test_data_s *tdata = (extension_test_data_s *) user_data;
401400
ml_tensors_data_h data = NULL;
@@ -413,7 +412,8 @@ _extension_test_llamacpp_cb (
413412
status = ml_tensors_data_get_tensor_data (data, 0U, &_raw, &_size);
414413
EXPECT_EQ (status, ML_ERROR_NONE);
415414

416-
g_print ("%s", (char *) _raw);
415+
std::cout.write (static_cast<const char *> (_raw), _size); /* korean output */
416+
std::cout.flush ();
417417

418418
if (tdata)
419419
tdata->received++;
@@ -427,7 +427,7 @@ _extension_test_llamacpp_cb (
427427
* @brief Internal function to run test with ml-service extension handle.
428428
*/
429429
static inline void
430-
_extension_test_llamacpp (ml_service_h handle, gboolean is_pipeline)
430+
_extension_test_llm (ml_service_h handle, gboolean is_pipeline, gchar *file_name, guint sleep_us)
431431
{
432432
extension_test_data_s *tdata;
433433
ml_tensors_info_h info;
@@ -436,14 +436,14 @@ _extension_test_llamacpp (ml_service_h handle, gboolean is_pipeline)
436436
gsize len = 0;
437437
gchar *contents = NULL;
438438

439-
g_autofree gchar *data_file = _get_data_path ("input.txt");
439+
g_autofree gchar *data_file = _get_data_path (file_name);
440440
ASSERT_TRUE (g_file_test (data_file, G_FILE_TEST_EXISTS));
441441
ASSERT_TRUE (g_file_get_contents (data_file, &contents, &len, NULL));
442442

443443
tdata = _create_test_data (is_pipeline);
444444
ASSERT_TRUE (tdata != NULL);
445445

446-
status = ml_service_set_event_cb (handle, _extension_test_llamacpp_cb, tdata);
446+
status = ml_service_set_event_cb (handle, _extension_test_llm_cb, tdata);
447447
EXPECT_EQ (status, ML_ERROR_NONE);
448448

449449
/* Create and push input data. */
@@ -457,7 +457,7 @@ _extension_test_llamacpp (ml_service_h handle, gboolean is_pipeline)
457457
status = ml_service_request (handle, NULL, input);
458458
EXPECT_EQ (status, ML_ERROR_NONE);
459459

460-
g_usleep (5000000U);
460+
g_usleep (sleep_us);
461461
EXPECT_GT (tdata->received, 0);
462462

463463
/* Clear callback before releasing tdata. */
@@ -477,8 +477,9 @@ TEST (MLServiceExtension, scenarioConfigLlamacpp)
477477
{
478478
ml_service_h handle;
479479
int status;
480-
480+
g_autofree gchar *input_file = g_strdup ("input.txt");
481481
g_autofree gchar *model_file = _get_model_path ("llama-2-7b-chat.Q2_K.gguf");
482+
482483
if (!g_file_test (model_file, G_FILE_TEST_EXISTS)) {
483484
g_critical ("Skipping scenarioConfigLlamacpp test due to missing model file. "
484485
"Please download model file from https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF");
@@ -490,7 +491,33 @@ TEST (MLServiceExtension, scenarioConfigLlamacpp)
490491
status = ml_service_new (config, &handle);
491492
ASSERT_EQ (status, ML_ERROR_NONE);
492493

493-
_extension_test_llamacpp (handle, FALSE);
494+
_extension_test_llm (handle, FALSE, input_file, 5000000U);
495+
496+
status = ml_service_destroy (handle);
497+
EXPECT_EQ (status, ML_ERROR_NONE);
498+
}
499+
500+
/**
501+
* @brief Usage of ml-service extension API.
502+
*/
503+
TEST (MLServiceExtension, scenarioConfigFlare)
504+
{
505+
ml_service_h handle;
506+
int status;
507+
g_autofree gchar *input_file = g_strdup ("flare_input.txt");
508+
g_autofree gchar *model_file = _get_model_path ("sflare_if_4bit_3b.bin");
509+
510+
if (!g_file_test (model_file, G_FILE_TEST_EXISTS)) {
511+
g_critical ("Skipping scenarioConfigFlare test due to missing model file.Please download model file");
512+
return;
513+
}
514+
515+
g_autofree gchar *config = get_config_path ("config_single_flare.conf");
516+
517+
status = ml_service_new (config, &handle);
518+
ASSERT_EQ (status, ML_ERROR_NONE);
519+
520+
_extension_test_llm (handle, FALSE, input_file, 40000000U);
494521

495522
status = ml_service_destroy (handle);
496523
EXPECT_EQ (status, ML_ERROR_NONE);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"single" :
3+
{
4+
"framework" : "flare",
5+
"model" : ["../tests/test_models/models/sflare_if_4bit_3b.bin"],
6+
"adapter" : ["../tests/test_models/models/history_lora.bin"],
7+
"custom" : "tokenizer_path:../tests/test_models/data/tokenizer.json,backend:CPU,output_size:1024,model_type:3B,data_type:W4A32",
8+
"invoke_dynamic" : "true",
9+
"invoke_async" : "false"
10+
}
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<|begin_of_text|><|turn_start|>System\n<|turn_end|>\n<|turn_start|>User\nYou are a summarization expert.Please read the provided <Text> carefully and summarize it in 3 sentences in English. The summary should comprehensively cover the entire content of the original text and be written with the same meaning as the source material.<|begin_of_text|><|turn_start|>System<|turn_end|>국제 연구 컨소시엄이 차세대 재생 에너지 기술 개발에 박차를 가하고 있습니다. 스탠포드 대학을 주도로 MIT, KAIST 등 12개 기관이 참여한 이 프로젝트는 기존 실리콘 기반 태양광 패널의 한계를 극복하기 위해 페로브스카이트-실리콘 탠덤 구조를 적용했습니다. 실험 결과, 이 신소재는 31.2%의 광변환 효율을 달성하며 상용화 가능성을 입증했는데, 이는 기존 단일 접합 태양전지의 최대 효율(26%)을 크게 상회하는 수치입니다. 연구팀은 나노스케일 광포획 구조와 양자점 기술을 접목해 적층형 셀의 내구성을 향상시키는 데 성공했으며, 2025년 상용화를 목표로 대량 생산 공정 개발에 착수했습니다. 현재 캘리포니아의 모하비 사막과 독일 바이에른 지역에 설치된 시범 플랜트에서 실외 테스트가 진행 중이며, 초기 데이터는 일사량 변동 환경에서도 안정적인 성능을 보여주고 있습니다. 산업계 전문가들은 이 기술이 2030년까지 전 세계 태양광 시장의 35%를 점유할 것으로 예상하며, 화석 연료 의존도를 12% 감소시킬 수 있을 것으로 내다보고 있습니다. 특히 개발도상국을 위한 저비용 버전 개발도 병행 중인데, 필리핀과 케냐에서 2024년 말 시범 설치될 예정입니다. 한편 유럽 에너지 위원회는 이 기술이 RE100 목표 달성 시기를 5년 앞당길 수 있을 것으로 평가하며 추가 지원 방안을 검토 중입니다.\n<|turn_end|>\n<|turn_start|>Assistant\n"

0 commit comments

Comments
 (0)