Skip to content
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

feat: support build tabby on windows #948

Merged
merged 4 commits into from
Dec 11, 2023

Conversation

darknight
Copy link
Contributor

For #909

The trial is partially successful, raise PR for further discussion.

See comments inline.

@darknight darknight marked this pull request as draft December 6, 2023 02:46
@darknight
Copy link
Contributor Author

darknight commented Dec 6, 2023

My test env:

OS:
Windows 11

rustup default:
1.73.0-x86_64-pc-windows-msvc (default)

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\bin\Hostx64\x64> .\cl.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.35.32217.1 for x64

Local test:
Both cargo build and cargo build --release were done successfully, but the generated tabby.exe by cargo build seemed corrupted, it can not be run at all. The release build is working as expected.

I was suspecting probably because of unclean local development environment, so I setup a window runner on GitHub, see test-rust-windows.yml for more info.

CI test:
Can take a look at latest build: https://github.com/darknight/tabby/actions/runs/7109544886/job/19354636544

It's same result as my local testing, tabby.exe in release mode is able to execute and print ********enter main then exit********, while debug more produce an error:

error: process didn't exit successfully: `target\debug\tabby.exe` (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)

With some expriments and googling, I didn't have much luck, so raise a PR for public discussion. But I do suspect this corruption is due to incorrect build on llama-cpp-bindings (either llama.cpp or the binding itself)

WSL test:

For the change, I also tested in Ubuntu 22.04 via wsl, it's working fine. This is expected and proved those changes have no impact on already supported platforms (I don't have Mac but I think should be working as well).

cc: @wsxiaoys

@wsxiaoys
Copy link
Member

wsxiaoys commented Dec 6, 2023

For the change, I also tested in Ubuntu 22.04 via wsl, it's working fine. This is expected and proved those changes have no impact on already supported platforms (I don't have Mac but I think should be working as well).

I haven’t go through all details - but one thing might worth to try is you could build chat example on windows with llama.cpp instructions. As long as it works, we should have a way to make it behave properly in tabby as well

@ichDaheim
Copy link
Contributor

First of all: I'm really looking forward to the possibility of using tabby under Windows. This would be fantastic and a great help to me. And i if have to admit that i have no insight to the code here - and do not know Rust at all. So please forgive me if my suggestion is nonsense. But from my understanding your main problem is to get llama.cpp build on different OS ?

If my assumption is correct: you may want to consider this repo from mozilla: https://github.com/Mozilla-Ocho/llamafile - for future builds?

If not: sorry for not keeping my mouth shut. ;-)

@darknight
Copy link
Contributor Author

darknight commented Dec 7, 2023

First of all: I'm really looking forward to the possibility of using tabby under Windows. This would be fantastic and a great help to me. And i if have to admit that i have no insight to the code here - and do not know Rust at all. So please forgive me if my suggestion is nonsense. But from my understanding your main problem is to get llama.cpp build on different OS ?

Your understanding is correct. The main problem I faced currently is if I build llama.cpp in Release mode, everything is fine, but if build in Debug mode, the generated llama libraries seems not working. Currently I'm investigating the root cause.

If my assumption is correct: you may want to consider this repo from mozilla: https://github.com/Mozilla-Ocho/llamafile - for future builds?

I took a quick look at this repo, seems its target is to generate one single-file executable to run everywhere. Well, what we need here are the libraries built from llama.cpp (more specificially, llama.lib & ggml_static.lib). Those libs will be used in tabby.

If not: sorry for not keeping my mouth shut. ;-)

Don't say that man, any idea/discussion/suggestion is welcome. @ichDaheim

@wsxiaoys
Copy link
Member

wsxiaoys commented Dec 7, 2023

Your understanding is correct. The main problem I faced currently is if I build llama.cpp in Release mode, everything is fine, but if build in Debug mode, the generated llama libraries seems not working. Currently I'm investigating the root cause.

One workaround I would like to take is to build llama.cpp in release mode regardless of rust build, I think this is also the current behavior in linux / mac.

@darknight darknight force-pushed the build-on-windows branch 2 times, most recently from fd1e5f7 to b3f4816 Compare December 7, 2023 14:25
@darknight darknight changed the title Try build tabby on windows feat: support build tabby on windows Dec 7, 2023
@darknight
Copy link
Contributor Author

Your understanding is correct. The main problem I faced currently is if I build llama.cpp in Release mode, everything is fine, but if build in Debug mode, the generated llama libraries seems not working. Currently I'm investigating the root cause.

One workaround I would like to take is to build llama.cpp in release mode regardless of rust build, I think this is also the current behavior in linux / mac.

If this is acceptable, I think the PR is ready for review.

Essentially, I just added conditional compilation settings for windows, so the changes are supposed to be completely back-compatible on *nx platforms.

Both build:

cargo build --package llama-cpp-bindings
-OR-
cargo build --package llama-cpp-bindings --release

succeed on my local laptop.

Be aware that this is the first step to enable tabby to build on windows.

cargo build still failed due to tabby crate depends on tabby-download crate, which has platform specific dependence.

I plan to raise 2 more PRs separately:

  1. find aim alternative to replace it in tabby-download
  2. update build.rs again to enable feature cuda & rocm, currently both features assume lib path in *nix style, need to change accordingly.

@darknight darknight marked this pull request as ready for review December 7, 2023 15:14
@wsxiaoys
Copy link
Member

wsxiaoys commented Dec 7, 2023

aim itself is opensource and it looks like its implementation is straight forward to port out from it

@wsxiaoys
Copy link
Member

wsxiaoys commented Dec 10, 2023

Please add windows build to release.yml: https://github.com/TabbyML/tabby/blob/main/.github/workflows/release.yml (with cuda on)

@darknight
Copy link
Contributor Author

Please add windows build to release.yml: https://github.com/TabbyML/tabby/blob/main/.github/workflows/release.yml (with cuda on)

cuda settings need to be updated to reflect cuda lib path on windows, and I'm working on that.

Is it ok that I raise a separate PR to include cuda change + workflow update?

@wsxiaoys
Copy link
Member

please rebase against main

println!(r"cargo:rustc-link-search=native={}\lib\x64", cuda_path);
} else {
println!("cargo:rustc-link-search=native=/usr/local/cuda/lib64");
}
println!("cargo:rustc-link-lib=cudart");
println!("cargo:rustc-link-lib=culibos");
Copy link
Contributor Author

@darknight darknight Dec 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some search work, and compared the cuda doc carefully and found:

Until 12.0.0, there indeed exists culibos regardless of os type, it is a thread abstraction layer, as mentioned here: https://docs.nvidia.com/cuda/archive/12.0.0/cusparse/index.html#static-library-support

Since 12.0.1, in the similar page, there's no such keyword found: https://docs.nvidia.com/cuda/archive/12.0.1/cusparse/index.html#static-library-support

I do suspect this lib has been removed from 12.0.1 and afterwards, that's why I failed to compile on my laptop cause I installed latest cuda tookit (12.3.1).

We're using 11.7 during the release build, so I think this line should continue to work, even on the new windows settings (although I didn't test locally)

As for local development, we can raise a separate PR to fix it for both windows & *nix platforms. What do you think? @wsxiaoys

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as long as the ci build pass - we're good

Whether to fix the build for cuda12 can be discussed separately

@@ -0,0 +1,3 @@
Echo "install protocol buffer compiler..."
choco install protoc
choco install cuda --version=11.7.1.51694
Copy link
Contributor Author

@darknight darknight Dec 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more note, I installed cuda by downloading complete .exe file (3.05GB) in my laptop, and it installed to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3, set CUDA_PATH by default.

Here I just use choco and assume it has similar behaviour, but be aware it may cause issue here.

@wsxiaoys
Copy link
Member

debugging in #1009

@wsxiaoys
Copy link
Member

fixed, please rebase

@wsxiaoys
Copy link
Member

Otherwise LGTM!

@wsxiaoys
Copy link
Member

Thanks for the effort!

@wsxiaoys wsxiaoys merged commit e0d0133 into TabbyML:main Dec 11, 2023
8 checks passed
wsxiaoys pushed a commit that referenced this pull request Dec 11, 2023
* feat: update config to support build on windows

* resolve comment

* update release.yml

* resolve comment
@darknight darknight deleted the build-on-windows branch December 11, 2023 04:51
@ichDaheim
Copy link
Contributor

Hi @darknight @wsxiaoys
the windows version does not start on my machine. under powershell cmd the command ".\tabby_x86_64-pc-windows-msvc.exe serve --model TabbyML/CodeLlama-7B --chat-model TabbyML/Mistral-7B" does not do anything at all.
Double clicking the .exe gives me the error message that "cublas64_11.dll" and "cudart64.dll" are not found. (do not have a nvidia gpu). Guess this means the current version is only for users with a nvidia graphics card ?

@wsxiaoys
Copy link
Member

Yes - the distributed binary requires cuda runtime (thus nvidia gpu card). If you're interested in CPU only binary distribution, feel free to file an issue, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants