-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into chore/convention
- Loading branch information
Showing
27 changed files
with
4,572 additions
and
192 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <sstream> | ||
#include "common/tokenizer.h" | ||
|
||
struct ModelMetadata { | ||
uint32_t version; | ||
uint64_t tensor_count; | ||
uint64_t metadata_kv_count; | ||
std::shared_ptr<Tokenizer> tokenizer; | ||
|
||
std::string ToString() const { | ||
std::ostringstream ss; | ||
ss << "ModelMetadata {\n" | ||
<< "version: " << version << "\n" | ||
<< "tensor_count: " << tensor_count << "\n" | ||
<< "metadata_kv_count: " << metadata_kv_count << "\n" | ||
<< "tokenizer: "; | ||
|
||
if (tokenizer) { | ||
ss << "\n" << tokenizer->ToString(); | ||
} else { | ||
ss << "null"; | ||
} | ||
|
||
ss << "\n}"; | ||
return ss.str(); | ||
} | ||
}; |
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,72 @@ | ||
#pragma once | ||
|
||
#include <sstream> | ||
#include <string> | ||
|
||
struct Tokenizer { | ||
std::string eos_token = ""; | ||
bool add_eos_token = true; | ||
|
||
std::string bos_token = ""; | ||
bool add_bos_token = true; | ||
|
||
std::string unknown_token = ""; | ||
std::string padding_token = ""; | ||
|
||
std::string chat_template = ""; | ||
|
||
bool add_generation_prompt = true; | ||
|
||
// Helper function for common fields | ||
std::string BaseToString() const { | ||
std::ostringstream ss; | ||
ss << "eos_token: \"" << eos_token << "\"\n" | ||
<< "add_eos_token: " << (add_eos_token ? "true" : "false") << "\n" | ||
<< "bos_token: \"" << bos_token << "\"\n" | ||
<< "add_bos_token: " << (add_bos_token ? "true" : "false") << "\n" | ||
<< "unknown_token: \"" << unknown_token << "\"\n" | ||
<< "padding_token: \"" << padding_token << "\"\n" | ||
<< "chat_template: \"" << chat_template << "\"\n" | ||
<< "add_generation_prompt: " | ||
<< (add_generation_prompt ? "true" : "false") << "\""; | ||
return ss.str(); | ||
} | ||
|
||
virtual ~Tokenizer() = default; | ||
|
||
virtual std::string ToString() = 0; | ||
}; | ||
|
||
struct GgufTokenizer : public Tokenizer { | ||
std::string pre = ""; | ||
|
||
~GgufTokenizer() override = default; | ||
|
||
std::string ToString() override { | ||
std::ostringstream ss; | ||
ss << "GgufTokenizer {\n"; | ||
// Add base class members | ||
ss << BaseToString() << "\n"; | ||
// Add derived class members | ||
ss << "pre: \"" << pre << "\"\n"; | ||
ss << "}"; | ||
return ss.str(); | ||
} | ||
}; | ||
|
||
struct SafeTensorTokenizer : public Tokenizer { | ||
bool add_prefix_space = true; | ||
|
||
~SafeTensorTokenizer() = default; | ||
|
||
std::string ToString() override { | ||
std::ostringstream ss; | ||
ss << "SafeTensorTokenizer {\n"; | ||
// Add base class members | ||
ss << BaseToString() << "\n"; | ||
// Add derived class members | ||
ss << "add_prefix_space: " << (add_prefix_space ? "true" : "false") << "\n"; | ||
ss << "}"; | ||
return ss.str(); | ||
} | ||
}; |
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
Oops, something went wrong.