From 31a9fada9c7ab1f04ae74eeaf483489a1d71d0af Mon Sep 17 00:00:00 2001 From: X0RSH1FT Date: Sat, 17 Jun 2023 17:44:37 -0400 Subject: [PATCH] Added window's powershell and BAT scripts for building and testing llama executable. Includes environment configuration powershell script as well that can be used to adjust build and test parameters. --- bin/build.bat | 4 ++ bin/env.config.ps1 | 28 ++++++++++ bin/help.bat | 4 ++ bin/llama.ps1 | 129 +++++++++++++++++++++++++++++++++++++++++++++ bin/test.bat | 4 ++ 5 files changed, 169 insertions(+) create mode 100644 bin/build.bat create mode 100644 bin/env.config.ps1 create mode 100644 bin/help.bat create mode 100644 bin/llama.ps1 create mode 100644 bin/test.bat diff --git a/bin/build.bat b/bin/build.bat new file mode 100644 index 000000000..19b0d5a29 --- /dev/null +++ b/bin/build.bat @@ -0,0 +1,4 @@ +@echo off +@title LLAMA.CPP - BUILD +PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\llama.ps1'" "-build" +pause diff --git a/bin/env.config.ps1 b/bin/env.config.ps1 new file mode 100644 index 000000000..74a25ad9d --- /dev/null +++ b/bin/env.config.ps1 @@ -0,0 +1,28 @@ +Set-StrictMode -Version 3.0 + +#region Directories + +# Project directory +$PROJ_DIR = Resolve-Path "$PSScriptRoot\.." + +# Build directory +$BUILD_DIR = "$PROJ_DIR\build" + +#endregion + +#region Files + +# LLAMA.CPP executable +$LLAMA_EXE = "$BUILD_DIR\bin\Release\main.exe" + +#endregion + +#region Test data + +# Test model +$TEST_MODEL_PATH = "F:\Models\Wizard-Vicuna-13B-Uncensored-GGML\Wizard-Vicuna-13B-Uncensored.ggmlv3.q4_0.bin" + +# Test prompt +$TEST_PROMPT = "The life of a cyberpunk is" + +#endregion \ No newline at end of file diff --git a/bin/help.bat b/bin/help.bat new file mode 100644 index 000000000..363d499c1 --- /dev/null +++ b/bin/help.bat @@ -0,0 +1,4 @@ +@echo off +@title LLAMA.CPP - HELP +PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\llama.ps1'" "-help" +pause diff --git a/bin/llama.ps1 b/bin/llama.ps1 new file mode 100644 index 000000000..4c931524a --- /dev/null +++ b/bin/llama.ps1 @@ -0,0 +1,129 @@ +param( + [switch] $clear, # Clear console prior to execution + [switch] $debug, # Enable debug output + [switch] $verbose, # Enable verbose output + [switch] $build, # Build the executable + [switch] $test, # Test the executable + [switch] $help # Display help output from executable +) + +#region Env. config + +Set-StrictMode -Version 3.0 + +if ($clear) { Clear-Host } +if ($debug) { $DebugPreference = "Continue" } +if ($verbose) { $VerbosePreference = "Continue" } + +# Import environment configuration +. "$PSScriptRoot\env.config.ps1" + +#endregion + +#region Operations + +function ExecuteCommand +{ + param( + [string] $command, + [string] $cwd = $PROJ_DIR + ) + Write-Verbose "Executing command: $command" + Write-Verbose "Working directory: $cwd" + + $cur_dir = Get-Location + Set-Location $cwd + + Invoke-Expression $command + + Set-Location $cur_dir +} + +function Build +{ + param( + [string] $build_path = $BUILD_DIR + ) + + $cur_dir = Get-Location + + try + { + # Test if the build directory exists and create it if needed + if (!(Test-Path -Path $build_path -PathType Container)) { New-Item -Path $build_path -ItemType Directory | Out-Null } + + # Set the location to the build directory + Set-Location "$build_path" + + # Run the build commands + cmake .. + cmake --build . --config Release + } + catch { Write-Error "An error occurred during the build process: $_" } + finally { Set-Location $cur_dir } +} + +function Validate +{ + # Check that llama.exe exists + if (!(Test-Path "$LLAMA_EXE")) { throw "Could not find llama.exe at path - '$LLAMA_EXE'"} +} + +function GenerateTextFromPrompt +{ + param( + [string] $model_path, + [string] $prompt, + [int] $context_size = 2048, + [int] $thread_cnt = 4 + ) + Validate + $arguments = "-m '$model_path' -p '$prompt' -c '$context_size' -t '$thread_cnt' --color" + ExecuteCommand "$LLAMA_EXE $arguments" +} + +function GenerateTextFromFile +{ + param( + [string] $model_path, + [string] $file, + [int] $context_size = 2048, + [int] $thread_cnt = 4 + ) + Validate + $arguments = "-m '$model_path' -f '$file' -c '$context_size' -t '$thread_cnt' --color" + ExecuteCommand "$LLAMA_EXE $arguments" +} + +function GenerateInteractiveText +{ + param( + [string] $model_path, + [int] $context_size = 2048, + [int] $thread_cnt = 4 + ) + Validate + $arguments = "-m '$model_path' --interactive-first -c '$context_size' -t '$thread_cnt' --color" + ExecuteCommand "$LLAMA_EXE $arguments" # Wait for input before starting +} + +function Help +{ + Validate + ExecuteCommand "$LLAMA_EXE --help" +} + +function Test +{ + GenerateTextFromPrompt "$TEST_MODEL_PATH" "$TEST_PROMPT" +} + +#endregion + +#region Execution + +if ($build) { Build } +if ($test) { Test } +if ($help) { Help } + +#endregion \ No newline at end of file diff --git a/bin/test.bat b/bin/test.bat new file mode 100644 index 000000000..bbf9d9c33 --- /dev/null +++ b/bin/test.bat @@ -0,0 +1,4 @@ +@echo off +@title LLAMA.CPP - TEST +PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\llama.ps1'" "-test" +pause