Skip to content

Adds support for MacOS Arm CPU builds #15

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

Merged
merged 3 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ if (GGML_CUBLAS)
add_definitions(-DGGML_USE_CUBLAS)
endif()

if (GGML_METAL)
add_definitions(-DGGML_USE_METAL)
set(GGML_METAL_EMBED_LIBRARY ON CACHE BOOL "Embed Metal library")
endif()

add_subdirectory(ggml)

target_link_libraries(tortoise PUBLIC ggml)
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ git clone --recursive https://github.com/balisujohn/tortoise.cpp.git
# Compiling
For now, CUDA and CPU only. To compile:

## Compile for CPU
## Compile for CPU (works on Linux x86 and Mac ARM)
````
mkdir build
cd build
cmake ..
make
````
This is tested with mac os arm

## Compile for CUDA
````
Expand All @@ -27,6 +28,14 @@ make
````
This is tested with Ubuntu 22.04 and cuda 12.0 and a 1070ti

## Compile for Mac OS with metal (work in-progress)
````
mkdir build
cd build
cmake .. -DGGML_METAL=ON
make
````

# Running

**Only lowercase letters, spaces, and punctuation are supported in the prompt.**
Expand Down
12 changes: 6 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ bool autoregressive_model_load(const std::string &fname,

#ifdef GGML_USE_METAL
fprintf(stderr, "%s: using Metal backend\n", __func__);
ggml_metal_log_set_callback(ggml_log_callback_default, nullptr);
// ggml_metal_log_set_callback(ggml_log_callback_default, nullptr);
model.backend = ggml_backend_metal_init();
if (!model.backend) {
fprintf(stderr, "%s: ggml_backend_metal_init() failed\n", __func__);
Expand Down Expand Up @@ -822,7 +822,7 @@ bool autoregressive_model_load(const std::string &fname,
}

int32_t nelements = 1;
int32_t ne[2] = {1, 1};
int32_t ne[4] = {1, 1, 1, 1};
for (int i = 0; i < n_dims; ++i) {
fin.read(reinterpret_cast<char *>(&ne[i]), sizeof(ne[i]));
nelements *= ne[i];
Expand Down Expand Up @@ -1218,7 +1218,7 @@ bool diffusion_model_load(const std::string &fname, diffusion_model &model) {

#ifdef GGML_USE_METAL
fprintf(stderr, "%s: using Metal backend\n", __func__);
ggml_metal_log_set_callback(ggml_log_callback_default, nullptr);
// ggml_metal_log_set_callback(ggml_log_callback_default, nullptr);
model.backend = ggml_backend_metal_init();
if (!model.backend) {
fprintf(stderr, "%s: ggml_backend_metal_init() failed\n", __func__);
Expand Down Expand Up @@ -1559,7 +1559,7 @@ bool diffusion_model_load(const std::string &fname, diffusion_model &model) {
}

int32_t nelements = 1;
int32_t ne[2] = {1, 1};
int32_t ne[4] = {1, 1, 1, 1};
for (int i = 0; i < n_dims; ++i) {
fin.read(reinterpret_cast<char *>(&ne[i]), sizeof(ne[i]));
nelements *= ne[i];
Expand Down Expand Up @@ -1782,7 +1782,7 @@ bool vocoder_model_load(const std::string &fname, vocoder_model &model) {

#ifdef GGML_USE_METAL
fprintf(stderr, "%s: using Metal backend\n", __func__);
ggml_metal_log_set_callback(ggml_log_callback_default, nullptr);
// ggml_metal_log_set_callback(ggml_log_callback_default, nullptr);
model.backend = ggml_backend_metal_init();
if (!model.backend) {
fprintf(stderr, "%s: ggml_backend_metal_init() failed\n", __func__);
Expand Down Expand Up @@ -1946,7 +1946,7 @@ bool vocoder_model_load(const std::string &fname, vocoder_model &model) {
}

int32_t nelements = 1;
int32_t ne[2] = {1, 1};
int32_t ne[4] = {1, 1, 1, 1};
for (int i = 0; i < n_dims; ++i) {
fin.read(reinterpret_cast<char *>(&ne[i]), sizeof(ne[i]));
nelements *= ne[i];
Expand Down
Loading