Skip to content

Commit 9faf1b5

Browse files
Merge branch 'PaddlePaddle:develop' into develop
2 parents 5275365 + c521c6a commit 9faf1b5

File tree

20 files changed

+415
-117
lines changed

20 files changed

+415
-117
lines changed

README_CN.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,11 @@
5757

5858
- FastDeploy系列[**直播课程回放**](https://aistudio.baidu.com/aistudio/education/group/info/27800)
5959

60-
- **2023.01.17** 发布 [**YOLOv8**](./examples/vision/detection/paddledetection/) 在FastDeploy系列硬件的部署支持。 其中包括 [**Paddle YOLOv8**](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov8) 以及 [**社区 ultralytics YOLOv8**](https://github.com/ultralytics/ultralytics)
61-
- [**Paddle YOLOv8**](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov8) 可以部署的硬件:[**Intel CPU**](./examples/vision/detection/paddledetection/python/infer_yolov8.py)[**NVIDIA GPU**](./examples/vision/detection/paddledetection/python/infer_yolov8.py)[**Jetson**](./examples/vision/detection/paddledetection/python/infer_yolov8.py)[**飞腾**](./examples/vision/detection/paddledetection/python/infer_yolov8.py)[**昆仑芯**](./examples/vision/detection/paddledetection/python/infer_yolov8.py)[**昇腾**](./examples/vision/detection/paddledetection/python/infer_yolov8.py)[**ARM CPU**](./examples/vision/detection/paddledetection/cpp/infer_yolov8.cc)[**RK3588**](./examples/vision/detection/paddledetection/rknpu2)[**Sophgo TPU**](./examples/vision/detection/paddledetection/sophgo), 部分硬件包含 **Python** 部署和 **C++** 部署;
62-
- [**社区 ultralytics YOLOv8**](https://github.com/ultralytics/ultralytics) 可以部署的硬件:[**Intel CPU**](./examples/vision/detection/yolov8)[**NVIDIA GPU**](./examples/vision/detection/yolov8)[**Jetson**](./examples/vision/detection/yolov8),均包含 **Python** 部署和 **C++** 部署;
63-
- FastDeploy 一行模型API切换,可以实现**YOLOv8****PP-YOLOE+****YOLOv5** 等模型性能对比。
64-
- 服务化部署结合VisualDL新增支持可视化部署。在FastDeploy容器中启动VDL服务后,即可在VDL界面修改模型配置、启动/管理模型服务、查看性能数据、发送请求等,详细操作可参考相关文档
60+
- 服务化部署结合VisualDL新增支持可视化部署。在FastDeploy容器中启动VDL服务后,即可在VDL界面修改模型配置、启动/管理模型服务、查看性能数据、发送请求等,详细操作可参考相关文档
6561
- [Serving可视化部署](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/vdl_management.md)
6662
- [Serving可视化请求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/client.md#%E4%BD%BF%E7%94%A8fastdeploy-client%E8%BF%9B%E8%A1%8C%E5%8F%AF%E8%A7%86%E5%8C%96%E8%AF%B7%E6%B1%82)
6763

6864

69-
7065
- **✨👥✨ 社区交流**
7166

7267
- **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1o50e4voz-zbiIneCNRf_eH99eS2NVLg) and chat with other community members about ideas

examples/vision/ocr/PP-OCR/cpu-gpu/cpp/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/dict/l
6262
# 运行部署示例
6363
# 在CPU上使用Paddle Inference推理
6464
./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 0
65-
# 在CPU上使用OenVINO推理
65+
# 在CPU上使用OpenVINO推理
6666
./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 1
6767
# 在CPU上使用ONNX Runtime推理
6868
./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 2
@@ -110,7 +110,7 @@ wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/dict/l
110110
|数字选项|含义|
111111
|:---:|:---:|
112112
|0| 在CPU上使用Paddle Inference推理 |
113-
|1| 在CPU上使用OenVINO推理 |
113+
|1| 在CPU上使用OpenVINO推理 |
114114
|2| 在CPU上使用ONNX Runtime推理 |
115115
|3| 在CPU上使用Paddle Lite推理 |
116116
|4| 在GPU上使用Paddle Inference推理 |

fastdeploy/fastdeploy_model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FASTDEPLOY_DECL FastDeployModel {
4747
std::vector<Backend> valid_timvx_backends = {};
4848
/** Model's valid directml backends. This member defined all the onnxruntime directml backends have successfully tested for the model
4949
*/
50-
std::vector<Backend> valid_directml_backends = {};
50+
std::vector<Backend> valid_directml_backends = {Backend::ORT};
5151
/** Model's valid ascend backends. This member defined all the cann backends have successfully tested for the model
5252
*/
5353
std::vector<Backend> valid_ascend_backends = {};

fastdeploy/runtime/backends/ort/ort_backend.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ bool OrtBackend::BuildOption(const OrtBackendOption& option) {
9898
"DML", ORT_API_VERSION, reinterpret_cast<const void**>(&ortDmlApi));
9999
OrtStatus* onnx_dml_status =
100100
ortDmlApi->SessionOptionsAppendExecutionProvider_DML(session_options_,
101-
0);
101+
option_.device_id);
102102
if (onnx_dml_status != nullptr) {
103103
FDERROR
104104
<< "DirectML is not support in your machine, the program will exit."
@@ -260,8 +260,13 @@ bool OrtBackend::InitFromOnnx(const std::string& model_file,
260260
}
261261
char* model_content_ptr;
262262
int model_content_size = 0;
263+
#ifdef ENABLE_PADDLE2ONNX
263264
paddle2onnx::ConvertFP32ToFP16(model_file.c_str(), model_file.size(),
264265
&model_content_ptr, &model_content_size);
266+
#else
267+
FDERROR << "Didn't compile with ENABLE_PADDLE2ONNX, FP16 is not supported" << std::endl;
268+
return false;
269+
#endif
265270
std::string onnx_model_proto(model_content_ptr,
266271
model_content_ptr + model_content_size);
267272
delete[] model_content_ptr;

fastdeploy/runtime/enum_variables.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "fastdeploy/runtime/enum_variables.h"
16+
#include "fastdeploy/core/config.h"
1617

1718
namespace fastdeploy {
1819
std::ostream& operator<<(std::ostream& out, const Backend& backend) {

fastdeploy/runtime/runtime_option.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ void RuntimeOption::UseAscend() {
141141
paddle_lite_option.device = device;
142142
}
143143

144-
void RuntimeOption::UseDirectML() { device = Device::DIRECTML; }
144+
void RuntimeOption::UseDirectML(int adapter_id) {
145+
device = Device::DIRECTML;
146+
device_id = adapter_id;
147+
}
145148

146149
void RuntimeOption::UseSophgo() {
147150
device = Device::SOPHGOTPUD;

fastdeploy/runtime/runtime_option.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct FASTDEPLOY_DECL RuntimeOption {
8282
void UseAscend();
8383

8484
/// Use onnxruntime DirectML to inference
85-
void UseDirectML();
85+
void UseDirectML(int adapter_id = 0);
8686

8787
/// Use Sophgo to inference
8888
void UseSophgo();

fastdeploy/utils/utils.cc

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
#include "fastdeploy/utils/utils.h"
1616

1717
#include <sstream>
18+
#include <fstream>
19+
#include <string_view>
20+
21+
#ifdef _WIN32
22+
#include <Windows.h>
23+
#endif
1824

1925
namespace fastdeploy {
2026

@@ -48,18 +54,53 @@ FDLogger& FDLogger::operator<<(std::ostream& (*os)(std::ostream&)) {
4854
return *this;
4955
}
5056

51-
bool ReadBinaryFromFile(const std::string& file, std::string* contents) {
52-
std::ifstream fin(file, std::ios::in | std::ios::binary);
53-
if (!fin.is_open()) {
54-
FDERROR << "Failed to open file: " << file << " to read." << std::endl;
57+
// using os_string = std::filesystem::path::string_type;
58+
#ifdef _WIN32
59+
using os_string = std::wstring;
60+
#else
61+
using os_string = std::string;
62+
#endif
63+
64+
os_string to_osstring(std::string_view utf8_str)
65+
{
66+
#ifdef _WIN32
67+
int len = MultiByteToWideChar(CP_UTF8, 0, utf8_str.data(), (int)utf8_str.size(), nullptr, 0);
68+
os_string result(len, 0);
69+
MultiByteToWideChar(CP_UTF8, 0, utf8_str.data(), (int)utf8_str.size(), result.data(), len);
70+
return result;
71+
#else
72+
return std::string(utf8_str);
73+
#endif
74+
}
75+
76+
bool ReadBinaryFromFile(const std::string& path, std::string* contents)
77+
{
78+
if (!contents) {
79+
return false;
80+
}
81+
auto& result = *contents;
82+
result.clear();
83+
84+
std::ifstream file(to_osstring(path), std::ios::binary | std::ios::ate);
85+
if (!file.is_open()) {
5586
return false;
5687
}
57-
fin.seekg(0, std::ios::end);
58-
contents->clear();
59-
contents->resize(fin.tellg());
60-
fin.seekg(0, std::ios::beg);
61-
fin.read(&(contents->at(0)), contents->size());
62-
fin.close();
88+
89+
auto fileSize = file.tellg();
90+
if (fileSize != -1) {
91+
result.resize(fileSize);
92+
file.seekg(0, std::ios::beg);
93+
file.read(const_cast<char*>(result.data()), fileSize);
94+
}
95+
else {
96+
// no size available, read to EOF
97+
constexpr auto chunksize = 4096;
98+
std::string chunk(chunksize, 0);
99+
while (!file.fail()) {
100+
file.read(const_cast<char*>(chunk.data()), chunksize);
101+
result.insert(result.end(), chunk.data(), chunk.data() + file.gcount());
102+
}
103+
}
63104
return true;
64105
}
65106

fastdeploy/vision/ocr/ppocr/rec_postprocessor.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@
1515
#include "fastdeploy/vision/ocr/ppocr/rec_postprocessor.h"
1616
#include "fastdeploy/utils/perf.h"
1717
#include "fastdeploy/vision/ocr/ppocr/utils/ocr_utils.h"
18+
#include "fastdeploy/utils/utils.h"
1819

1920
namespace fastdeploy {
2021
namespace vision {
2122
namespace ocr {
2223

2324
std::vector<std::string> ReadDict(const std::string& path) {
24-
std::ifstream in(path);
25+
std::string content;
26+
ReadBinaryFromFile(path, &content);
27+
std::stringstream in(std::move(content));
2528
FDASSERT(in, "Cannot open file %s to read.", path.c_str());
2629
std::string line;
2730
std::vector<std::string> m_vec;
2831
while (getline(in, line)) {
32+
if (!line.empty() && *line.rbegin() == '\r') line.pop_back();
2933
m_vec.push_back(line);
3034
}
3135
m_vec.insert(m_vec.begin(), "#"); // blank char for ctc

llm/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
# 挂载模型文件
1616
export MODEL_PATH=${PWD}/Llama-3-8B-A8W8C8
1717
18-
docker run --gpus all --shm-size 5G --network=host \
18+
docker run --gpus all --shm-size 5G --network=host --privileged --cap-add=SYS_PTRACE \
1919
-v ${MODEL_PATH}:/models/ \
20-
-dit registry.baidubce.com/paddlepaddle/fastdeploy:llm-serving-cuda123-cudnn9-v1.0 \
20+
-dit registry.baidubce.com/paddlepaddle/fastdeploy:llm-serving-cuda123-cudnn9-v1.2 \
2121
bash -c 'export USE_CACHE_KV_INT8=1 && cd /opt/output/Serving && bash start_server.sh; exec bash'
2222
```
2323

0 commit comments

Comments
 (0)