Skip to content

Commit 5f8f774

Browse files
sayanshaw24Sayan Shaw
andauthored
Fix Compiler Warnings C4333 and C5038 (#986)
* fix warnings * pin safetensors version --------- Co-authored-by: Sayan Shaw <[email protected]>
1 parent af289f5 commit 5f8f774

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

operators/tokenizer/trietree.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TrieTree {
1818
static constexpr int kMaxTokenLength_ = 128;
1919
static constexpr ValueT kInvalidId_ = static_cast<ValueT>(invalid_id);
2020

21-
TrieTree(CharT ch = 0) : ch_(ch), value_(std::nullopt) {}
21+
TrieTree(CharT ch = 0) : value_(std::nullopt), ch_(ch) {}
2222

2323
void Add(const std::basic_string<CharT>& key, int idx = 0,
2424
const std::optional<ValueT>& value = std::nullopt) noexcept {

operators/tokenizer/ugm_kernels.hpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -796,21 +796,26 @@ class SpmUgmDecoder {
796796
// Helper: Encode a wchar_t as UTF-8
797797
std::string EncodeUTF8(wchar_t wc) const {
798798
std::string out;
799-
if (wc < 0x80) {
800-
out += static_cast<char>(wc);
801-
} else if (wc < 0x800) {
802-
out += static_cast<char>((wc >> 6) | 0xC0);
803-
out += static_cast<char>((wc & 0x3F) | 0x80);
804-
} else if (wc < 0x10000) {
805-
out += static_cast<char>((wc >> 12) | 0xE0);
806-
out += static_cast<char>(((wc >> 6) & 0x3F) | 0x80);
807-
out += static_cast<char>((wc & 0x3F) | 0x80);
799+
800+
// Promote wchar_t to uint32_t to avoid data loss from shift operations and silence warning C4333
801+
uint32_t u = static_cast<uint32_t>(wc);
802+
803+
if (u < 0x80) {
804+
out += static_cast<char>(u);
805+
} else if (u < 0x800) {
806+
out += static_cast<char>((u >> 6) | 0xC0);
807+
out += static_cast<char>((u & 0x3F) | 0x80);
808+
} else if (u < 0x10000) {
809+
out += static_cast<char>((u >> 12) | 0xE0);
810+
out += static_cast<char>(((u >> 6) & 0x3F) | 0x80);
811+
out += static_cast<char>((u & 0x3F) | 0x80);
808812
} else {
809-
out += static_cast<char>((wc >> 18) | 0xF0);
810-
out += static_cast<char>(((wc >> 12) & 0x3F) | 0x80);
811-
out += static_cast<char>(((wc >> 6) & 0x3F) | 0x80);
812-
out += static_cast<char>((wc & 0x3F) | 0x80);
813+
out += static_cast<char>((u >> 18) | 0xF0);
814+
out += static_cast<char>(((u >> 12) & 0x3F) | 0x80);
815+
out += static_cast<char>(((u >> 6) & 0x3F) | 0x80);
816+
out += static_cast<char>((u & 0x3F) | 0x80);
813817
}
818+
814819
return out;
815820
}
816821

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ onnx >=1.9.0
55
protobuf < 4.0.0
66
# multiple versions of onnxruntime are supported, but only one can be installed at a time
77
onnxruntime >=1.12.0
8+
safetensors < 0.4.3
89
transformers < 4.50.0
910
tensorflow_text >=2.5.0;python_version < '3.11'
1011
requests >=2.26.0

0 commit comments

Comments
 (0)