From b508909609ce2311ff2c9c540aa7cd205fff3f62 Mon Sep 17 00:00:00 2001 From: Vulcan <93451215+trholding@users.noreply.github.com> Date: Sat, 26 Aug 2023 03:24:04 +0530 Subject: [PATCH] Unikernel fixes Makefile and run.c fixes. --- .gitignore | 6 +++++- Makefile | 7 ++++++- run.c | 25 ++++++++++++++++++++----- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 27a300af..88f7be56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *~ -out/model.bin +out/ run run.com.dbg run.com @@ -7,3 +7,7 @@ a.out strlit tokenizer.h model.h +.config.old +.config +UNIK/ +build/ diff --git a/Makefile b/Makefile index f6f9a6cf..5ca22faa 100644 --- a/Makefile +++ b/Makefile @@ -174,6 +174,9 @@ run_clang_static_strlit: run.c # Unikraft Unikernel build .PHONY: run_unik_qemu_x86_64 run_unik_qemu_x86_64: run.c + [ ! -d "UNIK" ] && echo "Cloning unikraft and musl sources..." + [ ! -d "UNIK/unikraft" ] && git clone https://github.com/unikraft/unikraft UNIK/unikraft + [ ! -d "UNIK/libs/musl" ] && git clone https://github.com/unikraft/lib-musl UNIK/libs/musl make -f Makefile.unikernel # run all tests @@ -194,4 +197,6 @@ clean: .PHONY: distclean distclean: rm -f run run.com model.h tokenizer.h strlit run.com.dbg *~ - make -f Makefile.unikernel distclean + make -f Makefile.unikernel distclean + rm -rf UNIK + diff --git a/run.c b/run.c index 98633a3c..e1700198 100644 --- a/run.c +++ b/run.c @@ -1,5 +1,18 @@ /* Inference for Llama-2 Transformer model in pure C The Llama 2 Everywhere @trholding (Vulcan) fork */ + + +// ---------------------------------------------------------------------------- +// Unikraft Unikernel Support Directives +// + +#define LSTATUS 0 + +#ifdef UNIK +#define STRLIT +#define LLOOP +#define LSTATUS 1 +#endif // ---------------------------------------------------------------------------- // INCBIN Embedding Support Directives @@ -887,6 +900,9 @@ int main(int argc, char *argv[]) { #if defined(COSMO_ZIP) || defined(INC_BIN) || defined(STRLIT) // special case for embedded models // we read the embedded checkpoint from within the executable // 'checkpoint' is necessary arg + #ifdef UNIK + printf("\n*** GURU UNMEDITATION :: BOOT > LLAMA HAS AWAKENED ***\n\n"); + #endif #if defined(COSMO_ZIP) checkpoint_path = "/zip/out/model.bin"; tokenizer_path = "/zip/tokenizer.bin"; @@ -894,14 +910,13 @@ int main(int argc, char *argv[]) { checkpoint_path = emb_Model_data; tokenizer_path = emb_Tokenizer_data; #endif - buffertokens=16; - char promptbuffer[1024]; // Buffer for prompt + buffertokens=8; #ifdef LLOOP - stats = 0; + stats = LSTATUS; while(1) { // start of loop #endif prompt=(char*)malloc(1024); - printf("L2E $ "); + printf("\nL2E $ "); fflush(stdout); inprompt(prompt); // read prompt #else @@ -1005,7 +1020,7 @@ int main(int argc, char *argv[]) { free_sampler(&sampler); free_tokenizer(&tokenizer); free_transformer(&transformer); - #if defined(COSMO_ZIP) || defined(INC_BIN) || defined(STRLIT) + #if defined(COSMO_ZIP) || defined(INC_BIN) || defined(STRLIT) #ifdef LLOOP printf("\n"); } // end of loop