| 1177 | } |
| 1178 | |
| 1179 | void TFullModel::Load(IInputStream* s) { |
| 1180 | ReferenceMainFactoryRegistrators(); |
| 1181 | using namespace flatbuffers; |
| 1182 | using namespace NCatBoostFbs; |
| 1183 | ui32 fileDescriptor; |
| 1184 | ::Load(s, fileDescriptor); |
| 1185 | CB_ENSURE(fileDescriptor == GetModelFormatDescriptor(), "Incorrect model file descriptor"); |
| 1186 | auto coreSize = ::LoadSize(s); |
| 1187 | TArrayHolder<ui8> arrayHolder(new ui8[coreSize]); |
| 1188 | s->LoadOrFail(arrayHolder.Get(), coreSize); |
| 1189 | |
| 1190 | { |
| 1191 | flatbuffers::Verifier verifier(arrayHolder.Get(), coreSize, 64 /* max depth */, 256000000 /* max tables */); |
| 1192 | CB_ENSURE(VerifyTModelCoreBuffer(verifier), "Flatbuffers model verification failed"); |
| 1193 | } |
| 1194 | auto fbModelCore = GetTModelCore(arrayHolder.Get()); |
| 1195 | DefaultFullModelInit(fbModelCore); |
| 1196 | |
| 1197 | if (fbModelCore->ModelTrees()) { |
| 1198 | ModelTrees.GetMutable()->FBDeserializeOwning(fbModelCore->ModelTrees()); |
| 1199 | } |
| 1200 | |
| 1201 | TVector<TString> modelParts; |
| 1202 | if (fbModelCore->ModelPartIds()) { |
| 1203 | for (auto part : *fbModelCore->ModelPartIds()) { |
| 1204 | modelParts.emplace_back(part->str()); |
| 1205 | } |
| 1206 | } |
| 1207 | if (!modelParts.empty()) { |
| 1208 | for (const auto& modelPartId : modelParts) { |
| 1209 | if (modelPartId == TStaticCtrProvider::ModelPartId()) { |
| 1210 | CtrProvider = new TStaticCtrProvider; |
| 1211 | CtrProvider->Load(s); |
| 1212 | } else if (modelPartId == NCB::TTextProcessingCollection::GetStringIdentifier()) { |
| 1213 | TextProcessingCollection = new NCB::TTextProcessingCollection(); |
| 1214 | TextProcessingCollection->Load(s); |
| 1215 | } else if (modelPartId == NCB::TEmbeddingProcessingCollection::GetStringIdentifier()) { |
| 1216 | EmbeddingProcessingCollection = new NCB::TEmbeddingProcessingCollection(); |
| 1217 | EmbeddingProcessingCollection->Load(s); |
| 1218 | } else { |
| 1219 | CB_ENSURE( |
| 1220 | false, |
| 1221 | "Got unknown partId = " << modelPartId << " via deserialization. " |
| 1222 | << "Only static ctr, text or embedding processing collection model parts are supported" |
| 1223 | ); |
| 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | UpdateDynamicData(); |
| 1228 | } |
| 1229 | |
| 1230 | void TFullModel::InitNonOwning(const void* binaryBuffer, size_t binarySize) { |
| 1231 | using namespace flatbuffers; |
no test coverage detected