MCPcopy Create free account
hub / github.com/PABannier/bark.cpp / bark_load_model_from_file

Function bark_load_model_from_file

bark.cpp:1091–1175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1089}
1090
1091static bool bark_load_model_from_file(
1092 const std::string& fname,
1093 struct bark_context* bctx,
1094 bark_verbosity_level verbosity) {
1095 if (verbosity == bark_verbosity_level::MEDIUM || verbosity == bark_verbosity_level::HIGH) {
1096 printf("%s: loading model from '%s'\n", __func__, fname.c_str());
1097 }
1098
1099 auto fin = std::ifstream(fname, std::ios::binary);
1100 if (!fin) {
1101 fprintf(stderr, "%s: failed to open '%s'\n", __func__, fname.c_str());
1102 return false;
1103 }
1104
1105 // verify magic
1106 {
1107 uint32_t magic;
1108 fin.read((char*)&magic, sizeof(magic));
1109 if (magic != GGML_FILE_MAGIC) {
1110 fprintf(stderr, "%s: invalid model file '%s' (bad magic)\n", __func__, fname.c_str());
1111 return false;
1112 }
1113 }
1114
1115 // vocab
1116 {
1117 if (verbosity == bark_verbosity_level::MEDIUM || verbosity == bark_verbosity_level::HIGH) {
1118 printf("%s: reading bark vocab\n", __func__);
1119 }
1120
1121 if (!bark_vocab_load(fin, &bctx->text_model.vocab)) {
1122 fprintf(stderr, "%s: failed to load vocab\n", __func__);
1123 return false;
1124 }
1125 }
1126
1127 int n_gpu_layers = bctx->n_gpu_layers;
1128
1129 // text
1130 {
1131 if (verbosity == bark_verbosity_level::MEDIUM || verbosity == bark_verbosity_level::HIGH) {
1132 printf("%s: reading bark text model\n", __func__);
1133 }
1134
1135 if (!bark_model_load(fin, bctx->text_model.semantic_model, n_gpu_layers, verbosity)) {
1136 fprintf(stderr, "%s: invalid model file '%s' (bad text)\n", __func__, fname.c_str());
1137 return false;
1138 }
1139 }
1140
1141 // coarse
1142 {
1143 if (!bark_model_load(fin, bctx->text_model.coarse_model, n_gpu_layers, verbosity)) {
1144 fprintf(stderr, "%s: invalid model file '%s' (bad coarse)\n", __func__, fname.c_str());
1145 return false;
1146 }
1147 }
1148

Callers 1

bark_load_modelFunction · 0.70

Calls 4

readMethod · 0.80
closeMethod · 0.80
bark_vocab_loadFunction · 0.70
bark_model_loadFunction · 0.70

Tested by

no test coverage detected