Skip to content

Commit 3bc64a6

Browse files
committed
Merge remote-tracking branch 'origin/master' into pizza
2 parents 02025a7 + aaf3b23 commit 3bc64a6

File tree

14 files changed

+447
-20
lines changed

14 files changed

+447
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ models/*
1919

2020
/main
2121
/quantize
22+
/quantize-stats
2223
/result
2324
/perplexity
2425
/embedding

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ if (LLAMA_OPENBLAS)
115115

116116
add_compile_definitions(GGML_USE_OPENBLAS)
117117
add_link_options(${BLAS_LIBRARIES})
118+
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} openblas)
118119
else()
119120
message(WARNING "OpenBLAS not found")
120121
endif()

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ common.o: examples/common.cpp examples/common.h
149149
$(CXX) $(CXXFLAGS) -c examples/common.cpp -o common.o
150150

151151
clean:
152-
rm -vf *.o main quantize perplexity embedding
152+
rm -vf *.o main quantize quantize-stats perplexity embedding
153153

154154
main: examples/main/main.cpp ggml.o llama.o common.o
155155
$(CXX) $(CXXFLAGS) examples/main/main.cpp ggml.o llama.o common.o -o main $(LDFLAGS)
@@ -160,6 +160,9 @@ main: examples/main/main.cpp ggml.o llama.o common.o
160160
quantize: examples/quantize/quantize.cpp ggml.o llama.o
161161
$(CXX) $(CXXFLAGS) examples/quantize/quantize.cpp ggml.o llama.o -o quantize $(LDFLAGS)
162162

163+
quantize-stats: examples/quantize-stats/quantize-stats.cpp ggml.o llama.o
164+
$(CXX) $(CXXFLAGS) examples/quantize-stats/quantize-stats.cpp ggml.o llama.o -o quantize-stats $(LDFLAGS)
165+
163166
perplexity: examples/perplexity/perplexity.cpp ggml.o llama.o common.o
164167
$(CXX) $(CXXFLAGS) examples/perplexity/perplexity.cpp ggml.o llama.o common.o -o perplexity $(LDFLAGS)
165168

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ if (EMSCRIPTEN)
3131
else()
3232
add_subdirectory(main)
3333
add_subdirectory(quantize)
34+
add_subdirectory(quantize-stats)
3435
add_subdirectory(perplexity)
3536
add_subdirectory(embedding)
3637
endif()

examples/common.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414
#endif
1515

1616
#if defined (_WIN32)
17+
#include <fcntl.h>
18+
#include <io.h>
1719
#pragma comment(lib,"kernel32.lib")
1820
extern "C" __declspec(dllimport) void* __stdcall GetStdHandle(unsigned long nStdHandle);
1921
extern "C" __declspec(dllimport) int __stdcall GetConsoleMode(void* hConsoleHandle, unsigned long* lpMode);
2022
extern "C" __declspec(dllimport) int __stdcall SetConsoleMode(void* hConsoleHandle, unsigned long dwMode);
2123
extern "C" __declspec(dllimport) int __stdcall SetConsoleCP(unsigned int wCodePageID);
2224
extern "C" __declspec(dllimport) int __stdcall SetConsoleOutputCP(unsigned int wCodePageID);
25+
extern "C" __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int CodePage, unsigned long dwFlags,
26+
const wchar_t * lpWideCharStr, int cchWideChar,
27+
char * lpMultiByteStr, int cbMultiByte,
28+
const char * lpDefaultChar, bool * lpUsedDefaultChar);
29+
#define CP_UTF8 65001
2330
#endif
2431

2532
bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
@@ -310,12 +317,20 @@ void win32_console_init(bool enable_color) {
310317
SetConsoleMode(hConOut, dwMode | 0x4); // ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x4)
311318
}
312319
// Set console output codepage to UTF8
313-
SetConsoleOutputCP(65001); // CP_UTF8
320+
SetConsoleOutputCP(CP_UTF8);
314321
}
315322
void* hConIn = GetStdHandle((unsigned long)-10); // STD_INPUT_HANDLE (-10)
316323
if (hConIn && hConIn != (void*)-1 && GetConsoleMode(hConIn, &dwMode)) {
317-
// Set console input codepage to UTF8
318-
SetConsoleCP(65001); // CP_UTF8
324+
// Set console input codepage to UTF16
325+
_setmode(_fileno(stdin), _O_WTEXT);
319326
}
320327
}
328+
329+
// Convert a wide Unicode string to an UTF8 string
330+
void win32_utf8_encode(const std::wstring & wstr, std::string & str) {
331+
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
332+
std::string strTo(size_needed, 0);
333+
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
334+
str = strTo;
335+
}
321336
#endif

examples/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,5 @@ void set_console_color(console_state & con_st, console_color_t color);
9393

9494
#if defined (_WIN32)
9595
void win32_console_init(bool enable_color);
96+
void win32_utf8_encode(const std::wstring & wstr, std::string & str);
9697
#endif

examples/main/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,19 @@ int main(int argc, char ** argv) {
387387
std::string line;
388388
bool another_line = true;
389389
do {
390+
#if defined(_WIN32)
391+
std::wstring wline;
392+
if (!std::getline(std::wcin, wline)) {
393+
// input stream is bad or EOF received
394+
return 0;
395+
}
396+
win32_utf8_encode(wline, line);
397+
#else
390398
if (!std::getline(std::cin, line)) {
391399
// input stream is bad or EOF received
392400
return 0;
393401
}
402+
#endif
394403
if (line.empty() || line.back() != '\\') {
395404
another_line = false;
396405
} else {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(TARGET quantize-stats)
2+
add_executable(${TARGET} quantize-stats.cpp)
3+
target_link_libraries(${TARGET} PRIVATE llama ${CMAKE_THREAD_LIBS_INIT})
4+
target_compile_features(${TARGET} PRIVATE cxx_std_11)

0 commit comments

Comments
 (0)