-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
黄宇扬
committed
Apr 25, 2024
1 parent
a232bea
commit 4736535
Showing
10 changed files
with
403 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
#ifndef FASTLLM_BERT_H | ||
#define FASTLLM_BERT_H | ||
|
||
#include "basellm.h" | ||
#include "fastllm.h" | ||
|
||
namespace fastllm { | ||
class BertModel { | ||
public: | ||
BertModel() {}; | ||
|
||
~BertModel() { | ||
this->weight.ReleaseWeight(); | ||
}; | ||
|
||
void InitParams(); // 初始化参数信息 | ||
|
||
// 推理 | ||
std::vector <std::vector <float> > Forward( | ||
const Data &inputIds, | ||
const Data &attentionMask, | ||
const Data &tokenTypeIds, | ||
const Data &positionIds); | ||
|
||
std::vector <float> EmbeddingSentence(const std::string &context); | ||
|
||
std::vector <std::vector <float> > EmbeddingSentenceBatch(const std::vector <std::string> &contexts); | ||
|
||
void LoadFromFile(const std::string &fileName); // 从文件读取 | ||
|
||
void SaveLowBitModel(const std::string &fileName, int bit); // 存储成量化模型 | ||
|
||
void SaveModel(const std::string &fileName); // 直接导出 | ||
|
||
void WarmUp() {}; // 预热 | ||
|
||
std::string model_type; | ||
|
||
float layer_norm_eps = 1e-12; | ||
|
||
int embed_dim = 512; | ||
int num_attention_heads = 64; | ||
int head_dim = embed_dim / num_attention_heads; | ||
int max_positions = 32768; | ||
int block_cnt = 12; | ||
|
||
WeightMap weight; // 权重 | ||
std::map <std::string, int> deviceMap; | ||
}; | ||
} | ||
|
||
#endif //FASTLLM_BERT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.