From b9136b2873a0a1ff17fd91de3ec4ec1fe3bec932 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 26 May 2024 08:30:51 +0300 Subject: [PATCH] Add selftest command. Use nice cpu priority. --- doc/index.org | 3 -- .../eu/svjatoslav/alyverkko_cli/AiTask.java | 3 ++ .../eu/svjatoslav/alyverkko_cli/Main.java | 4 +- .../commands/SelftestCommand.java | 47 +++++++++++++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 src/main/java/eu/svjatoslav/alyverkko_cli/commands/SelftestCommand.java diff --git a/doc/index.org b/doc/index.org index 290c028..03c7da6 100644 --- a/doc/index.org +++ b/doc/index.org @@ -531,9 +531,6 @@ Ideas to be possibly implemented in the future: ** System operation -- Implement CPU nice priority for inference processes to minimize the - impact on system responsiveness during heavy computations. - - Enable model selection per individual inference task, allowing for dynamic adjustment based on task requirements. diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/AiTask.java b/src/main/java/eu/svjatoslav/alyverkko_cli/AiTask.java index 2a7ca34..64baed0 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/AiTask.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/AiTask.java @@ -142,7 +142,10 @@ public class AiTask { */ private String getCliCommand() { + int niceValue = 10; // Set the desired niceness level (10 is a common value for background tasks) + return join(" ", + "nice", "-n", Integer.toString(niceValue), configuration.getLlamaCppExecutablePath().getAbsolutePath(), "--model " + model.filesystemPath, "--threads " + configuration.getThreadCount(), diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/Main.java b/src/main/java/eu/svjatoslav/alyverkko_cli/Main.java index 258a751..049f966 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/Main.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/Main.java @@ -2,6 +2,7 @@ package eu.svjatoslav.alyverkko_cli; import eu.svjatoslav.alyverkko_cli.commands.JoinFilesCommand; import eu.svjatoslav.alyverkko_cli.commands.ListModelsCommand; +import eu.svjatoslav.alyverkko_cli.commands.SelftestCommand; import eu.svjatoslav.alyverkko_cli.configuration.Configuration; import eu.svjatoslav.alyverkko_cli.commands.MailCorrespondentCommand; @@ -15,7 +16,8 @@ public class Main { private final java.util.List commands = java.util.Arrays.asList( new ListModelsCommand(), new MailCorrespondentCommand(), - new JoinFilesCommand() + new JoinFilesCommand(), + new SelftestCommand() ); public static void main(final String[] args) throws IOException, InterruptedException { diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/SelftestCommand.java b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/SelftestCommand.java new file mode 100644 index 0000000..52843f1 --- /dev/null +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/SelftestCommand.java @@ -0,0 +1,47 @@ +package eu.svjatoslav.alyverkko_cli.commands; + +import eu.svjatoslav.alyverkko_cli.Command; +import eu.svjatoslav.alyverkko_cli.Main; + +import java.io.IOException; + +import static eu.svjatoslav.alyverkko_cli.Main.configuration; +import static eu.svjatoslav.alyverkko_cli.configuration.Configuration.loadConfiguration; + +public class SelftestCommand implements Command { + + @Override + public String getName() { + return "selftest"; + } + + @Override + public void execute(String[] cliArguments) throws IOException { + // Perform selftest checks here + System.out.println("Starting selftest..."); + + configuration = loadConfiguration(); + + // Check if the configuration is loaded + if (Main.configuration == null) { + System.err.println("Configuration not found or invalid."); + return; + } + + // Validate models directory + if (!Main.configuration.getModelsDirectory().exists() || !Main.configuration.getModelsDirectory().isDirectory()) { + System.err.println("Models directory does not exist or is not a directory: " + Main.configuration.getModelsDirectory()); + return; + } + + // Validate llama.cpp executable path + if (!Main.configuration.getLlamaCppExecutablePath().exists() || !Main.configuration.getLlamaCppExecutablePath().isFile()) { + System.err.println("llama.cpp executable not found at: " + Main.configuration.getLlamaCppExecutablePath()); + return; + } + + // Additional checks like model file existence, etc., can be added here + + System.out.println("Selftest completed successfully."); + } +} -- 2.20.1