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

[Enhanced] method of memory loading model #2029

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dhzgit
Copy link

@dhzgit dhzgit commented Apr 26, 2023

Motivation

There is no way to load the model from memory, so it cannot be loaded from memory when the model is encrypted

Modification

Add methods to load models from memory

@CLAassistant
Copy link

CLAassistant commented Apr 26, 2023

CLA assistant check
All committers have signed the CLA.

@irexyc
Copy link
Collaborator

irexyc commented Apr 26, 2023

Thanks for you contribution.

While, the current apis already have the ability to load a model from memory like this:

  mmdeploy_model_t model;
  std::ifstream ifs(model_path, std::ios::binary); // /path/to/zipmodel
  ifs.seekg(0, std::ios::end);
  auto size = ifs.tellg();
  ifs.seekg(0, std::ios::beg);
  std::string str(size, '\0');
  ifs.read(str.data(), size);
  mmdeploy_model_create(str.data(), size, &model);

  int status{};
  mmdeploy_classifier_t classifier{};
  status = mmdeploy_classifier_create(model, device_name, 0, &classifier);
  // or use mmdeploy_classifier_create_v2

I'm not sure if it's necessary to add these api. What is your option about this pr? @lvhan028

@irexyc irexyc requested a review from lvhan028 April 26, 2023 03:30
@dhzgit
Copy link
Author

dhzgit commented Apr 26, 2023

The current code already has the usage of "mmdeploy_classifier_create_by_path", and adding the corresponding "mmdeploy_classifier_create_by_buffer" can effectively reduce misunderstandings about the API during use and corresponding usage costs. After all, even if our staff are proficient in both Python/C++and various AI model usage scenarios, it took a long time to find "mmdeploy_model_create" in the code and master the usage of this API.

@@ -32,7 +32,7 @@ option(MMDEPLOY_BUILD_SDK_CSHARP_API "build SDK C# API support" OFF)
option(MMDEPLOY_BUILD_SDK_JAVA_API "build SDK JAVA API" OFF)
option(MMDEPLOY_BUILD_EXAMPLES "build examples" OFF)
option(MMDEPLOY_SPDLOG_EXTERNAL "use external spdlog" OFF)
option(MMDEPLOY_ZIP_MODEL "support SDK model in zip format" OFF)
option(MMDEPLOY_ZIP_MODEL "support SDK model in zip format" ON)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is recommended to keep MMDEPLOY_ZIP_MODEL OFF as the default value because not all of the users need it

@@ -40,6 +40,18 @@ int mmdeploy_classifier_create_by_path(const char* model_path, const char* devic
return ec;
}

int mmdeploy_classifier_create_by_buffer(const void* buffer, int size, const char* device_name,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't suggest creating another API. It's kinda redundant because mmdeploy_model_create and mmdeploy_classifier_create are enough to make up for it

@lvhan028
Copy link
Collaborator

Hi,

The current code already has the usage of "mmdeploy_classifier_create_by_path", and adding the corresponding "mmdeploy_classifier_create_by_buffer" can effectively reduce misunderstandings about the API during use and corresponding usage costs. After all, even if our staff are proficient in both Python/C++and various AI model usage scenarios, it took a long time to find "mmdeploy_model_create" in the code and master the usage of this API.

I understand your concern.
But mmdeploy_classifier_create already suggests reading a model from buffer, doesn't it?
And its comments say,

* @param[in] model an instance of mmclassification sdk model created by
 * \ref mmdeploy_model_create_by_path or \ref mmdeploy_model_create in \ref model.h

So, from the perspective of maintenance, I think it's not necessary to change the API. Instead, we can describe a procedure in the user guide about creating predictors from the buffer

@OpenMMLab-Assistant-004
Copy link

Hi @dhzgit,

We'd like to express our appreciation for your valuable contributions to the mmdeploy. Your efforts have significantly aided in enhancing the project's quality.
It is our pleasure to invite you to join our community thorugh Discord_Special Interest Group (SIG) channel. This is a great place to share your experiences, discuss ideas, and connect with other like-minded people. To become a part of the SIG channel, send a message to the moderator, OpenMMLab, briefly introduce yourself and mention your open-source contributions in the #introductions channel. Our team will gladly facilitate your entry. We eagerly await your presence. Please follow this link to join us: ​https://discord.gg/UjgXkPWNqA.

If you're on WeChat, we'd also love for you to join our community there. Just add our assistant using the WeChat ID: openmmlabwx. When sending the friend request, remember to include the remark "mmsig + Github ID".

Thanks again for your awesome contribution, and we're excited to have you as part of our community!

@RunningLeon RunningLeon requested a review from irexyc May 16, 2023 10:31
@RunningLeon RunningLeon added the enhancement New feature or request label May 16, 2023
@codecov
Copy link

codecov bot commented May 16, 2023

Codecov Report

Patch coverage has no change and project coverage change: +0.21 🎉

Comparison is base (2c7e91b) 49.44% compared to head (0c93abe) 49.65%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2029      +/-   ##
==========================================
+ Coverage   49.44%   49.65%   +0.21%     
==========================================
  Files         338      339       +1     
  Lines       12920    12985      +65     
  Branches     1897     1901       +4     
==========================================
+ Hits         6388     6448      +60     
- Misses       6088     6091       +3     
- Partials      444      446       +2     
Flag Coverage Δ
unittests 49.65% <ø> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 6 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@lvhan028
Copy link
Collaborator

@irexyc could you please add a tutorial about loading mmdeploy SDK model from a buffer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants