MCPcopy Create free account
hub / github.com/Tencent/TurboTransformers / Impl

Method Impl

example/cpp/bert_model.cpp:82–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80
81struct BertModel::Impl {
82 explicit Impl(const std::string &filename, DLDeviceType device_type,
83 size_t n_layers, int64_t n_heads)
84 : device_type_(device_type) {
85 auto npz = cnpy::npz_load(filename);
86 NPZMapView root("", &npz);
87
88 // HERE define your network model
89 embedding_ = LoadEmbedding(root.Sub("embeddings"), device_type);
90
91 for (size_t i = 0; i < n_layers; ++i) {
92 auto view = root.Sub("encoder.layer." + std::to_string(i));
93 NPZLoader params(view, device_type);
94 encoders_.emplace_back(std::move(params), n_heads);
95 }
96
97 if (root.IsExist("pooler")) {
98 pooler_ = LoadPooler(root.Sub("pooler"), device_type);
99 }
100 }
101
102 // preprocess helper function
103 template <typename T>

Callers

nothing calls this directly

Calls 4

LoadEmbeddingFunction · 0.85
LoadPoolerFunction · 0.85
SubMethod · 0.80
IsExistMethod · 0.80

Tested by

no test coverage detected