| 80 | |
| 81 | struct 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> |
nothing calls this directly
no test coverage detected