-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #331 from fluxlinkage/master
增加基本的GLM模型(例如glm-large-chinese)支持
- Loading branch information
Showing
8 changed files
with
691 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// Created by huangyuyang on 5/11/23. | ||
// | ||
|
||
#ifndef FASTLLM_GLM_H | ||
#define FASTLLM_GLM_H | ||
|
||
#include "basellm.h" | ||
#include "cmath" | ||
|
||
#include <iostream> | ||
|
||
namespace fastllm { | ||
class GLMModel: public basellm { | ||
public: | ||
GLMModel (); // 构造函数 | ||
|
||
// 推理 | ||
virtual int Forward( | ||
const Data &inputIds, | ||
const Data &attentionMask, | ||
const Data &positionIds, | ||
std::vector <std::pair <Data, Data> > &pastKeyValues, | ||
const GenerationConfig &generationConfig = GenerationConfig(), | ||
const LastTokensManager &lastTokens = LastTokensManager(), | ||
std::vector <float> *logits = nullptr); | ||
|
||
std::vector <int> ForwardBatch( | ||
int batch, | ||
const Data &inputIds, | ||
const Data &attentionMask, | ||
const Data &positionIds, | ||
std::vector <std::pair <Data, Data> > &pastKeyValues, | ||
const GenerationConfig &generationConfig = GenerationConfig(), | ||
const LastTokensManager &lastTokens = LastTokensManager(), | ||
std::vector <std::vector <float>*> *retLogits = nullptr); | ||
|
||
// 根据输入的tokens生成LLM推理的输入 | ||
virtual void FillLLMInputs(std::vector <std::vector <float> > &inputTokens, | ||
const std::map <std::string, int> ¶ms, | ||
Data &inputIds, Data &attentionMask, Data &positionIds); | ||
|
||
virtual void InitParams(); | ||
virtual void WarmUp(); // 预热 | ||
|
||
virtual std::string MakeInput(const std::string &history, int round, const std::string &input); // 根据历史信息和当前输入生成prompt | ||
|
||
virtual std::string MakeHistory(const std::string &history, int round, const std::string &input, const std::string &output); // 根据当前回复更新history | ||
|
||
private: | ||
|
||
float scale_attn_1; | ||
|
||
static constexpr int eot_token_id = 50000;//<|endoftext|> | ||
static constexpr int cls_token_id = 50002;//[CLS] | ||
static constexpr int mask_token_id = 50003;//[MASK] | ||
static constexpr int smask_token_id = 50008;//[sMASK] | ||
static constexpr int gmask_token_id = 50009;//[gMASK] | ||
}; | ||
} | ||
|
||
#endif //FASTLLM_GLM_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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -777,4 +777,4 @@ printf("tot = %d\n", tot); | |
void basellm::DisableAdapter() { | ||
adapterName = ""; | ||
} | ||
} | ||
} |
Oops, something went wrong.