-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new patches for make.cpp and Makefile
- Loading branch information
Showing
10 changed files
with
247 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- ../Makefile 2024-07-10 22:17:00.507999852 +0200 | ||
+++ Makefile 2024-07-10 22:40:13.002343655 +0200 | ||
@@ -425,6 +425,31 @@ | ||
MK_CXXFLAGS += -pg | ||
endif | ||
|
||
+# | ||
+# llama-cpp-cffi | ||
+# Set shared library extension and linker flags based on the platform | ||
+# | ||
+ifeq ($(UNAME_S), Linux) | ||
+ LIB_EXT := so | ||
+ LIB_LDFLAGS := -shared | ||
+ LIB_CXXFLAGS := -fPIC -DLLAMA_LIB | ||
+endif | ||
+ | ||
+ifeq ($(UNAME_S), Darwin) | ||
+ LIB_EXT := dylib | ||
+ LIB_LDFLAGS := -dynamiclib | ||
+ LIB_CXXFLAGS := -fPIC -DLLAMA_LIB | ||
+endif | ||
+ | ||
+# For Windows (assuming MinGW) | ||
+ifeq ($(OS), Windows_NT) | ||
+ LIB_EXT := dll | ||
+ LIB_LDFLAGS := -shared | ||
+ LIB_CXXFLAGS := -DLLAMA_LIB | ||
+endif | ||
+ | ||
+LIB_NAME := llama-cli.$(LIB_EXT) | ||
+ | ||
# Architecture specific | ||
# TODO: probably these flags need to be tweaked on some architectures | ||
# feel free to update the Makefile for your architecture and send a pull request or issue | ||
@@ -1132,6 +1157,16 @@ | ||
@echo '==== Run ./llama-cli -h for help. ====' | ||
@echo | ||
|
||
+llama-cli-shared: examples/main/main.cpp \ | ||
+ $(OBJ_ALL) | ||
+ $(CXX) $(CXXFLAGS) $(LIB_CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) | ||
+ $(CXX) $(CXXFLAGS) $(LIB_CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $(LIB_NAME) $(LIB_LDFLAGS) $(LDFLAGS) | ||
+ | ||
+llama-cli-static: examples/main/main.cpp \ | ||
+ $(OBJ_ALL) | ||
+ $(CXX) $(CXXFLAGS) $(LIB_CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) | ||
+ ar rcs llama-cli.a $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) | ||
+ | ||
llama-infill: examples/infill/infill.cpp \ | ||
$(OBJ_ALL) | ||
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,93 @@ | ||
import os | ||
import sys | ||
sys.path.append(os.path.abspath('.')) | ||
|
||
import psutil | ||
from llama.ctypes import llama_generate, LlamaOptions | ||
|
||
|
||
options = LlamaOptions( | ||
no_display_prompt=True, | ||
threads=psutil.cpu_count(logical=False), | ||
ctx_size=8192, | ||
predict=512, | ||
flash_attn=True, | ||
cont_batching=True, | ||
simple_io=True, | ||
# log_disable=True, | ||
hf_repo='bartowski/Phi-3.1-mini-128k-instruct-GGUF', | ||
hf_file='Phi-3.1-mini-128k-instruct-Q4_K_M.gguf', | ||
# hf_file='Phi-3.1-mini-128k-instruct-IQ2_M.gguf', | ||
chat_template='chatml', | ||
# prompt='<|im_start|>user\nEvaluate 1 + 2.<|im_end|>\n<|im_start|>assistant\n', | ||
prompt='<|system|>\nYou are a helpful assistant.<|end|><|user|>\nEvaluate 1 + 2.<|end|>\n<|assistant|>\n', | ||
) | ||
|
||
for chunk in llama_generate(options): | ||
print(chunk, flush=True, end='') | ||
from llama.llama_cli_ctypes import llama_generate, Model, Options | ||
|
||
models = [ | ||
Model( | ||
'microsoft/Phi-3-mini-128k-instruct', | ||
'bartowski/Phi-3.1-mini-128k-instruct-GGUF', | ||
'Phi-3.1-mini-128k-instruct-Q4_K_M.gguf', | ||
), | ||
Model( | ||
'Qwen/Qwen2-1.5B-Instruct', | ||
'Qwen/Qwen2-1.5B-Instruct-GGUF', | ||
'qwen2-1_5b-instruct-q4_k_m.gguf', | ||
), | ||
Model( | ||
'TinyLlama/TinyLlama-1.1B-Chat-v1.0', | ||
'TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF', | ||
'tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf', | ||
), | ||
] | ||
|
||
|
||
def demo1(): | ||
options = Options( | ||
no_display_prompt=True, | ||
threads=psutil.cpu_count(logical=False), | ||
ctx_size=8192, | ||
predict=512, | ||
flash_attn=True, | ||
cont_batching=True, | ||
simple_io=True, | ||
log_disable=True, | ||
hf_repo=models[0].hf_repo, | ||
hf_file=models[0].hf_file, | ||
prompt='<|system|>\nYou are a helpful assistant.<|end|><|user|>\nEvaluate 1 + 2.<|end|>\n<|assistant|>\n', | ||
) | ||
|
||
for chunk in llama_generate(options): | ||
print(chunk, flush=True, end='') | ||
|
||
print() | ||
|
||
|
||
def demo2(): | ||
options = Options( | ||
no_display_prompt=True, | ||
threads=psutil.cpu_count(logical=False), | ||
ctx_size=2048, | ||
predict=-2, | ||
flash_attn=True, | ||
cont_batching=True, | ||
simple_io=True, | ||
log_disable=True, | ||
hf_repo=models[1].hf_repo, | ||
hf_file=models[1].hf_file, | ||
prompt='<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\nEvaluate 1 + 2.<|im_end|>\n<|im_start|>assistant\n', | ||
) | ||
|
||
for chunk in llama_generate(options): | ||
print(chunk, flush=True, end='') | ||
|
||
print() | ||
|
||
|
||
def demo3(): | ||
options = Options( | ||
no_display_prompt=True, | ||
threads=psutil.cpu_count(logical=False), | ||
ctx_size=2048, | ||
predict=-2, | ||
flash_attn=True, | ||
cont_batching=True, | ||
simple_io=True, | ||
log_disable=True, | ||
hf_repo=models[2].hf_repo, | ||
hf_file=models[2].hf_file, | ||
prompt='<|system|>\nYou are a helpful assistant.<|end|><|user|>\nEvaluate 1 + 2.<|end|>\n<|assistant|>\n', | ||
) | ||
|
||
for chunk in llama_generate(options): | ||
print(chunk, flush=True, end='') | ||
|
||
print() | ||
|
||
|
||
if __name__ == '__main__': | ||
demo1() | ||
demo2() | ||
demo3() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .cffi import * | ||
# from .cffi import * | ||
# from .ctypes import * |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
__all__ = ['Model'] | ||
|
||
from attrs import define, field | ||
|
||
|
||
@define | ||
class Model: | ||
creator_hf_repo: str | None | ||
hf_repo: str | ||
hf_file: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.