MCPcopy Create free account
hub / github.com/alibaba/MNN / main

Function main

tools/cpp/generateIO.cpp:39–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39int main(int argc, char* argv[]) {
40 if (argc < 4) {
41 MNN_PRINT("Usage: ./generateLlmIO model inputJson outputDir externalFilePath\n");
42 return 1;
43 }
44
45 std::string ExternalFilePath;
46 std::string modelPath = std::string(argv[1]);
47 std::string inputJson = argv[2];
48 std::string outputDir = argv[3];
49 if (argc >= 5) {
50 ExternalFilePath = argv[4];
51 }
52
53 rapidjson::Document document;
54 std::ifstream fileNames(inputJson.c_str());
55 std::ostringstream output;
56 output << fileNames.rdbuf();
57 auto outputStr = output.str();
58 document.Parse(outputStr.c_str());
59 if (document.HasParseError()) {
60 MNN_ERROR("Invalid json\n");
61 return 0;
62 }
63 int shapeIndex = 0;
64 std::shared_ptr<MNN::Express::Module> net;
65
66 if (document.HasMember("configs")) {
67 if (!(MNNCreateDir(outputDir.c_str()))) {
68 MNN_PRINT("Failed to create dir %s.\n", outputDir.c_str());
69 }
70 auto configsArray = document["configs"].GetArray();
71 for (auto& configObj : configsArray) {
72 std::map<std::string, float> inputInfo;
73 std::map<std::string, std::string> inputType;
74 std::vector<std::string> inputNames;
75 std::vector<std::string> outputNames;
76 std::map<std::string, std::vector<int>> inputShape;
77 std::vector<MNN::Express::VARP> inputs;
78 std::vector<MNN::Express::VARP> outputs;
79 if (configObj.HasMember("inputs")) {
80 auto inputsInfo = configObj["inputs"].GetArray();
81 for (auto iter = inputsInfo.begin(); iter != inputsInfo.end(); iter++) {
82 auto obj = iter->GetObject();
83 std::string type = "float";
84 std::string name = obj["name"].GetString();
85 inputNames.emplace_back(name);
86 if (obj.HasMember("type")) {
87 type = obj["type"].GetString();
88 inputType.insert(std::make_pair(name, type));
89 }
90 if (obj.HasMember("value")) {
91 float value;
92 if (type == "int") {
93 value = (float)obj["value"].GetInt();
94 } else {
95 value = obj["value"].GetFloat();
96 }

Callers

nothing calls this directly

Calls 15

MNNCreateDirFunction · 0.85
_InputFunction · 0.85
MNNFilePathConcatFunction · 0.85
HasMemberMethod · 0.80
saveInputOutputsFunction · 0.70
stringFunction · 0.50
loadFunction · 0.50
to_stringFunction · 0.50
c_strMethod · 0.45
strMethod · 0.45
ParseMethod · 0.45
HasParseErrorMethod · 0.45

Tested by

no test coverage detected