-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[User] Interactive mode immediately exits on Windows with Zig #1010
Comments
Maybe @iacore can help (as the author of the |
Disclaimer: I don't know much about Windows. The information is not enough. How the program exited is important. This is likely due to UBSan being on by default in Zig build, and the program hitting undefined behavior. On linux, this is always SIGILL. Otherwise, it's a Zig bug. |
It builds in
|
That's weird. I would recommend not using Zig to build this on Windows then. |
I am on Mac M1 with rosetta based kernel. I also getting similar output, however I can inference the model fine.
|
Sounds like a different issue, that's all just diagnostic information apart from the warning, which is unrelated to this. |
I took a stab at debugging this, and I think I know the reason why it exits. The immediate problem is that More precisely, I think this is what happens:
A small self-contained example to illustrate the problem would be this: #include <iostream>
#include <fcntl.h>
#include <io.h>
int main() {
_setmode(_fileno(stdin), _O_WTEXT);
std::wstring buf;
if (!std::getline(std::wcin, buf)) {
std::cout << "ERROR" << std::endl;
}
} If you compile this program with I have absolutely no idea how to fix it, though. |
Trying each of these gives slightly different parsing errors while attempting to build
And a plain
I'm not sure if there's some way to set up a Zig-specific directive to block out an alternative implementation that doesn't use |
Using The issue described in #840 was that some UTF-8 characters were interpreted as zeroes, which shouldn't happen since the UTF-8 codepage does not have zero bytes in it and is compatible with char/ASCII streams, only the representation being different. UTF-16 does have zero bytes though, and this where the problem most likely stems. I'd suggest reverting the #840 commit as the UTF16 -> UTF8 translation shouldn't be needed, and then looking again. From this comment the actual culprit seems to be that the implementation of std::getline is broken and doesn't properly support UTF-8, unfortunately I cannot read Chinese though. In any case the better starting point for investigating what's the actual root cause (why zero bytes are being input to a UTF-8 stream in the first place) would be to use a starting point without #840 The best long term solution would probably be to use fgetc() / fread() and regular file streams instead of the std family of getline and ifstream to remove the problems from library-specific implementations. |
I think
Judging from this issue, I'd say that building C++ binaries for the MSVC ABI is generally not supported yet (although the build errors there are very different from your linking error).
This should theoretically be possible, but I don't believe replacing This Although I absolutely agree that introducing additional UTF-16->UTF-8 translation in #840 makes no sense, even though it fixes the immediate problem with the input. It does look like |
On the latest MSVC build llama-master-6667401-bin-win-avx2-x64 as part of the CRT startup, after setting the application mode to console with I can remember from past troubleshootings that changing the I/O mode on a console stream after it's already allocated and used shouldn't be done and can lead to various bugs and weird interactions. I do not have any certain proof at hand to validate this though. The general wisdom that has worked well for me is to choose either char (ascii/utf-8/mbcs) or wchar (unicode/utf-16) for the whole program at the very beginning and to stick with it, and to never mix them up unless it's absolutely necessary. Also making sure that whatever the CRT library you had to import which generates invisible code on compilation understands the choice you made. Dealing with character encodings can be painful in general. However UTF-8 is an okay solution, while UTF-16 should be avoided at all costs. Explicitly #undef 'ing
Another problem with the current solution is that using TL;DR; Don't mix and match character encodings unless absolutely necessary. |
Whoa, I think I found the root cause. It's this issue. The problem is in As I understand the explanation: the console host represents the text in UTF-16 internally and has to convert it to an OEM encoding (UTF-8 in our case) before returning it to the I think this has been fixed only in February this year. So unfortunately we can't use UTF-8 input here. |
Yep, I just built and ran Windows Terminal from the commit fixing the issue and the previous one. As expected, the former allows me to properly enter non-ASCII symbols with #840 reverted, the latter doesn't. Of course, we can't rely on everyone having a recent version of Windows Terminal, so I guess that |
Perhaps a possible solution. |
Tangentially related: even if this was fixed, building with Zig on Windows is currently even more broken due to ziglang/zig#15958 unless you pass |
This issue was closed because it has been inactive for 14 days since being marked as stale. |
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Expected Behavior
When building with Zig, running the example command for Alpaca results in an interactive prompt that I can type in.
Current Behavior
When building with Zig, running the example command for Alpaca results in an interactive prompt that exits immediately, without producing an error message. Non-interactive mode works fine.
When using Command Prompt specifically, the process exits and leaves the console text green - that doesn't happen in PowerShell or Git Bash, which reset the console color. I think that means that it isn't reaching this line.
The commands, for reference:
I also tried using LLaMA in interactive mode, which resulted in the same behavior.
Building with MSVC via CMake produces a binary that works perfectly fine (besides also leaving the Command Prompt console text green when exiting with Ctrl+C).
Environment and Context
Please provide detailed information about your computer setup. This is important in case the issue is not reproducible except for under certain specific conditions.
Device name DESKTOP-HP640DM
Processor 11th Gen Intel(R) Core(TM) i9-11900K @ 3.50GHz 3.50 GHz
Installed RAM 24.0 GB (23.8 GB usable)
System type 64-bit operating system, x64-based processor
Pen and touch Pen support
Edition Windows 10 Home
Version 22H2
Installed on 3/17/2021
OS build 19045.2728
Experience Windows Feature Experience Pack 120.2212.4190.0
Failure Information (for bugs)
Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.
Steps to Reproduce
Please provide detailed steps for reproducing the issue. We are not sitting in front of your screen, so the more detail the better.
zig build -Drelease-fast
.\zig-out\bin\main.exe -m .\models\ggml-alpaca-7b-q4.bin --color -f .\prompts\alpaca.txt --ctx_size 2048 -n -1 -ins -b 256 --top_k 10000 --temp 0.2 --repeat_penalty 1 -t 7
Failure Logs
Running the Zig build:
Running the MSVC/CMake build:
The text was updated successfully, but these errors were encountered: