| 1228 | } |
| 1229 | |
| 1230 | void TFullModel::InitNonOwning(const void* binaryBuffer, size_t binarySize) { |
| 1231 | using namespace flatbuffers; |
| 1232 | using namespace NCatBoostFbs; |
| 1233 | |
| 1234 | TMemoryInput in(binaryBuffer, binarySize); |
| 1235 | ui32 fileDescriptor; |
| 1236 | ::Load(&in, fileDescriptor); |
| 1237 | CB_ENSURE(fileDescriptor == GetModelFormatDescriptor(), "Incorrect model file descriptor"); |
| 1238 | |
| 1239 | size_t coreSize = ::LoadSize(&in); |
| 1240 | const ui8* fbPtr = reinterpret_cast<const ui8*>(in.Buf()); |
| 1241 | in.Skip(coreSize); |
| 1242 | |
| 1243 | { |
| 1244 | flatbuffers::Verifier verifier(fbPtr, coreSize, 64 /* max depth */, 256000000 /* max tables */); |
| 1245 | CB_ENSURE(VerifyTModelCoreBuffer(verifier), "Flatbuffers model verification failed"); |
| 1246 | } |
| 1247 | |
| 1248 | auto fbModelCore = GetTModelCore(fbPtr); |
| 1249 | DefaultFullModelInit(fbModelCore); |
| 1250 | |
| 1251 | if (fbModelCore->ModelTrees()) { |
| 1252 | ModelTrees.GetMutable()->FBDeserializeNonOwning(fbModelCore->ModelTrees()); |
| 1253 | } |
| 1254 | |
| 1255 | TVector<TString> modelParts; |
| 1256 | if (fbModelCore->ModelPartIds()) { |
| 1257 | for (auto part : *fbModelCore->ModelPartIds()) { |
| 1258 | modelParts.emplace_back(part->str()); |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | if (!modelParts.empty()) { |
| 1263 | for (const auto& modelPartId : modelParts) { |
| 1264 | if (modelPartId == TStaticCtrProvider::ModelPartId()) { |
| 1265 | auto ptr = new TStaticCtrProvider; |
| 1266 | CtrProvider = ptr; |
| 1267 | ptr->LoadNonOwning(&in); |
| 1268 | } else if (modelPartId == NCB::TTextProcessingCollection::GetStringIdentifier()) { |
| 1269 | TextProcessingCollection = new NCB::TTextProcessingCollection(); |
| 1270 | TextProcessingCollection->LoadNonOwning(&in); |
| 1271 | } else if (modelPartId == NCB::TEmbeddingProcessingCollection::GetStringIdentifier()) { |
| 1272 | EmbeddingProcessingCollection = new NCB::TEmbeddingProcessingCollection(); |
| 1273 | EmbeddingProcessingCollection->LoadNonOwning(&in); |
| 1274 | } else { |
| 1275 | CB_ENSURE( |
| 1276 | false, |
| 1277 | "Got unknown partId = " << modelPartId << " via deserialization. " |
| 1278 | << "Only static ctr, text or embedding processing collection model parts are supported" |
| 1279 | ); |
| 1280 | } |
| 1281 | } |
| 1282 | } |
| 1283 | UpdateDynamicData(); |
| 1284 | } |
| 1285 | |
| 1286 | void TFullModel::UpdateDynamicData() { |
| 1287 | ModelTrees.GetMutable()->UpdateRuntimeData(); |
no test coverage detected