-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Vulkan build on MacOS #5311
Vulkan build on MacOS #5311
Conversation
Could you edit the flake (see 60ecf09) and see if you can build with Vulkan on x86_64 MacOS? |
Does that imply removing |
Yeah, just remove all vulkan references from broken or badPlatform. To install nix, follow https://github.com/DeterminateSystems/nix-installer. Then |
This should probably have it's own issue, but I've tested this PR on an Apple Silicon M1 and noticed I was getting garbage output to my prompts when
@0cc4m is this something expected with integrated GPUs? Can I help debug this further somehow? |
I can make requested patches today but testing them locally would take me longer, ETA ~week. Is there a way we can get this in sooner? For Intel Mac users this really is a huge improvement. |
I can try doing the nix tests, I think. I'll also add code to check if the extension is available. It would be good if you could test that afterwards, since I don't have a Mac system. Then we should be able to merge. Would that work? |
Sure, happy to test! |
@dokterbob I added the checks. Can you check if it works on Apple? I tried build it with nix locally and it didn't throw an error, but I have no idea how nix works or how to use it. @philiptaron Let me know if it looks correct. The CI should fail if it doesn't work, right? |
I think you also need this change: diff --git a/flake.nix b/flake.nix
index ad2f9b29..dc4e503c 100644
--- a/flake.nix
+++ b/flake.nix
@@ -150,6 +150,7 @@
packages =
{
default = config.legacyPackages.llamaPackages.llama-cpp;
+ vulkan = config.packages.default.override { useVulkan = true; };
}
// lib.optionalAttrs pkgs.stdenv.isLinux {
opencl = config.packages.default.override { useOpenCL = true; };
@@ -157,7 +158,6 @@
mpi-cpu = config.packages.default.override { useMpi = true; };
mpi-cuda = config.packages.default.override { useMpi = true; };
- vulkan = config.packages.default.override { useVulkan = true; };
}
// lib.optionalAttrs (system == "x86_64-linux") {
rocm = config.legacyPackages.llamaPackagesRocm.llama-cpp; |
You can also push commits to this PR. I think it's better if you do that, I have no clue what I'm doing in the nix files. |
It might be significantly delayed then; it's a week of real-life responsibilities for me. 🙂 |
Runs like a charm and pushed @philiptaron's patch. Not get into nix to test it though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I built this on Sonoma, both Intel Mac and M2 Mac. Compiles and runs. If @ggerganov doesn't object, I aim to merge this in 12 hours.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a look at the code; I'd like to see the refactor tractor continue to plow, @0cc4m. 😀
std::vector<const char*> layers; | ||
|
||
if (validation_ext) { | ||
layers.push_back("VK_LAYER_KHRONOS_validation"); | ||
} | ||
std::vector<const char*> extensions; | ||
if (validation_ext) { | ||
extensions.push_back("VK_EXT_validation_features"); | ||
} | ||
if (portability_enumeration_ext) { | ||
extensions.push_back("VK_KHR_portability_enumeration"); | ||
} | ||
vk::InstanceCreateInfo instance_create_info(vk::InstanceCreateFlags{}, &app_info, layers, extensions); | ||
if (portability_enumeration_ext) { | ||
instance_create_info.flags |= vk::InstanceCreateFlagBits::eEnumeratePortabilityKHR; | ||
} | ||
|
||
std::vector<vk::ValidationFeatureEnableEXT> features_enable; | ||
vk::ValidationFeaturesEXT validation_features; | ||
|
||
if (validation_ext) { | ||
features_enable = { vk::ValidationFeatureEnableEXT::eBestPractices }; | ||
validation_features = { | ||
features_enable, | ||
{}, | ||
}; | ||
validation_features.setPNext(nullptr); | ||
instance_create_info.setPNext(&validation_features); | ||
|
||
std::cerr << "ggml_vulkan: Validation layers enabled" << std::endl; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping that these constants would have one home:
"VK_LAYER_KHRONOS_validation"
"VK_EXT_validation_features"
"VK_KHR_portability_enumeration"
Could you accomplish that by making a function that returned or mutated the two variables features_enable
and validation_features
?
That way, this generic code could stay unaware of the sort of features and validation that got added, and the system-specific code below would be able to add (as needed) the right features and validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could, but let's not overextend the scope and duration of this PR. If you wanna do a refactor PR yourself or in collaboration with me, or gather suggestions in an issue, that's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went to try to do that refactoring with a spare hour this morning, and ran into a rebase error (on 8b38eb5) that I could not see how to resolve in a straightforward manner. Could you or @dokterbob rebase this branch on master appropriately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't have any issues merging upstream into the branch, not sure what your problem was.
To deal with the linker error that Vulkan currently has with cmake, you can use this workaround patch:
diff --git a/examples/gguf/CMakeLists.txt b/examples/gguf/CMakeLists.txt
index 6481f087..85950145 100644
--- a/examples/gguf/CMakeLists.txt
+++ b/examples/gguf/CMakeLists.txt
@@ -1,5 +1,5 @@
set(TARGET gguf)
add_executable(${TARGET} gguf.cpp)
install(TARGETS ${TARGET} RUNTIME)
-target_link_libraries(${TARGET} PRIVATE ggml ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(${TARGET} PRIVATE common ggml ${CMAKE_THREAD_LIBS_INIT})
target_compile_features(${TARGET} PRIVATE cxx_std_11)
… clean up ggml_vk_instance_init()
Author: Philip Taron <philip.taron@gmail.com> Date: Tue Feb 13 20:28:02 2024 +0000
d735894
to
b7b44e0
Compare
I intend to merge after CI completes. |
Keep in mind to squash the commits when merging in the future 👍 |
If that's the style preferred in this repo, I'll make sure to do that next time. |
Any chance we should enable it on linux/windows as well? I'm getting similar error with whisper.cpp + Vulkan. |
Significant (~30%) performance boost on Intel Mac.
I'm getting up to ~10 toks/s with 28 layers offloaded to a 4GB AMD Radeon Pro 5500M. Up from ~7 tok/s on just CPU.