PaddlePaddle / FastDeploy

⚡️An Easy-to-use and Fast Deep Learning Model Deployment Toolkit for ☁️Cloud 📱Mobile and 📹Edge. Including Image, Video, Text and Audio 20+ main stream scenarios and 150+ SOTA models with end-to-end optimization, multi-platform and multi-framework support.
https://www.paddlepaddle.org.cn/fastdeploy
Apache License 2.0
2.9k stars 453 forks source link

怎么主动释放已经加载的模型 #2393

Open ThinkWD opened 6 months ago

ThinkWD commented 6 months ago

问一个小白问题, 为什么所有模型都只有加载的接口, 没有释放的接口.

如果有释放的接口的话请说一下在哪里, 谢谢

ThinkWD commented 6 months ago

我尝试使用智能指针, 但是类析构了, 占用的内存/显存没有释放 (jetson, trt 后端)

// load
auto det_model = std::make_unique<detection::PPYOLOE>(model, params, config, option);
if (!det_model->Initialized())
    std::exit();

// free
det_model.reset();

大佬们帮忙看看 @jiangjiajun @rainyfly

ThinkWD commented 6 months ago

今天也是等待回复的一天...

ThinkWD commented 5 months ago

今天也是等待回复的一天...

rainyfly commented 5 months ago

https://github.com/PaddlePaddle/FastDeploy/blob/develop/fastdeploy/runtime/backends/tensorrt/trt_backend.cc 把这个里面context、engine destroy()掉试试

ThinkWD commented 5 months ago

https://github.com/PaddlePaddle/FastDeploy/blob/develop/fastdeploy/runtime/backends/tensorrt/trt_backend.cc 把这个里面context、engine destroy()掉试试

fastdeploy/runtime/backends/tensorrt/trt_backend.h 添加

~TrtBackend() {
    if (parser_) {
      parser_.reset();
    }
    if (context_) {
      context_.reset();
      engine_.reset();
      builder_.reset();
      network_.reset();
    }
  }

fastdeploy/runtime/runtime.h 添加

  ~Runtime() {
    if (backend_)
      backend_.reset();
  }

fastdeploy/fastdeploy_model.h 添加

  virtual void Release() {
    if (runtime_)
      runtime_.reset();
  }

实测均无法释放显存

是不是我的修改不正确? 还有其它可能有用的建议吗? @rainyfly

ThinkWD commented 5 months ago

等待回复...

ThinkWD commented 5 months ago

......

Algabeno commented 1 week ago

你好 你是否已经有更好的解决方法 我遇到了和你一样的问题

ThinkWD commented 1 week ago

你好 你是否已经有更好的解决方法 我遇到了和你一样的问题

没什么好方法,飞浆这些库没有人维护的,换成别的库了