From: Svjatoslav Agejenko Date: Sun, 26 May 2024 05:30:51 +0000 (+0300) Subject: Add selftest command. Use nice cpu priority. X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=b9136b2873a0a1ff17fd91de3ec4ec1fe3bec932;p=alyverkko-cli.git Add selftest command. Use nice cpu priority. --- 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."); + } +}