node-llama-cpp 3.0.0-beta.9 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -27
- package/bins/_linux-arm64.moved.txt +1 -0
- package/bins/_linux-armv7l.moved.txt +1 -0
- package/bins/_linux-x64-cuda.moved.txt +1 -0
- package/bins/_linux-x64-vulkan.moved.txt +1 -0
- package/bins/_linux-x64.moved.txt +1 -0
- package/bins/_mac-arm64-metal.moved.txt +1 -0
- package/bins/_mac-x64.moved.txt +1 -0
- package/bins/_win-arm64.moved.txt +1 -0
- package/bins/_win-x64-cuda.moved.txt +1 -0
- package/bins/_win-x64-vulkan.moved.txt +1 -0
- package/bins/_win-x64.moved.txt +1 -0
- package/dist/ChatWrapper.d.ts +19 -39
- package/dist/ChatWrapper.js +129 -72
- package/dist/ChatWrapper.js.map +1 -1
- package/dist/apiDocsIndex.d.ts +1 -0
- package/dist/apiDocsIndex.js +7 -0
- package/dist/apiDocsIndex.js.map +1 -0
- package/dist/bindings/AddonTypes.d.ts +88 -20
- package/dist/bindings/Llama.d.ts +43 -3
- package/dist/bindings/Llama.js +193 -23
- package/dist/bindings/Llama.js.map +1 -1
- package/dist/bindings/consts.d.ts +2 -0
- package/dist/bindings/consts.js +13 -0
- package/dist/bindings/consts.js.map +1 -0
- package/dist/bindings/getLlama.d.ts +123 -18
- package/dist/bindings/getLlama.js +264 -75
- package/dist/bindings/getLlama.js.map +1 -1
- package/dist/bindings/types.d.ts +29 -5
- package/dist/bindings/types.js +51 -2
- package/dist/bindings/types.js.map +1 -1
- package/dist/bindings/utils/MemoryOrchestrator.d.ts +21 -0
- package/dist/bindings/utils/MemoryOrchestrator.js +49 -0
- package/dist/bindings/utils/MemoryOrchestrator.js.map +1 -0
- package/dist/bindings/utils/asyncEvery.d.ts +5 -0
- package/dist/bindings/utils/asyncEvery.js +15 -0
- package/dist/bindings/utils/asyncEvery.js.map +1 -0
- package/dist/bindings/utils/asyncSome.d.ts +5 -0
- package/dist/bindings/utils/asyncSome.js +27 -0
- package/dist/bindings/utils/asyncSome.js.map +1 -0
- package/dist/bindings/utils/clearAllLocalBuilds.js.map +1 -1
- package/dist/bindings/utils/cloneLlamaCppRepo.d.ts +1 -1
- package/dist/bindings/utils/cloneLlamaCppRepo.js +39 -28
- package/dist/bindings/utils/cloneLlamaCppRepo.js.map +1 -1
- package/dist/bindings/utils/compileLLamaCpp.d.ts +11 -3
- package/dist/bindings/utils/compileLLamaCpp.js +250 -81
- package/dist/bindings/utils/compileLLamaCpp.js.map +1 -1
- package/dist/bindings/utils/detectAvailableComputeLayers.d.ts +14 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.js +305 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.js.map +1 -0
- package/dist/bindings/utils/detectGlibc.d.ts +4 -0
- package/dist/bindings/utils/detectGlibc.js +46 -0
- package/dist/bindings/utils/detectGlibc.js.map +1 -0
- package/dist/bindings/utils/getBestComputeLayersAvailable.d.ts +9 -0
- package/dist/bindings/utils/getBestComputeLayersAvailable.js +29 -0
- package/dist/bindings/utils/getBestComputeLayersAvailable.js.map +1 -0
- package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js +14 -6
- package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js.map +1 -1
- package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js.map +1 -1
- package/dist/bindings/utils/getGpuTypesToUseForOption.d.ts +12 -0
- package/dist/bindings/utils/getGpuTypesToUseForOption.js +39 -0
- package/dist/bindings/utils/getGpuTypesToUseForOption.js.map +1 -0
- package/dist/bindings/utils/getLinuxDistroInfo.d.ts +9 -0
- package/dist/bindings/utils/getLinuxDistroInfo.js +46 -0
- package/dist/bindings/utils/getLinuxDistroInfo.js.map +1 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.d.ts +5 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.js +27 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.js.map +1 -0
- package/dist/bindings/utils/getPlatform.js.map +1 -1
- package/dist/bindings/utils/getPlatformInfo.d.ts +5 -0
- package/dist/bindings/utils/getPlatformInfo.js +28 -0
- package/dist/bindings/utils/getPlatformInfo.js.map +1 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.d.ts +3 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js +27 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js.map +1 -0
- package/dist/bindings/utils/hasFileInPath.d.ts +2 -0
- package/dist/bindings/utils/hasFileInPath.js +34 -0
- package/dist/bindings/utils/hasFileInPath.js.map +1 -0
- package/dist/bindings/utils/lastBuildInfo.js.map +1 -1
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.d.ts +1 -1
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.js +3 -9
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.js.map +1 -1
- package/dist/bindings/utils/logDistroInstallInstruction.d.ts +14 -0
- package/dist/bindings/utils/logDistroInstallInstruction.js +48 -0
- package/dist/bindings/utils/logDistroInstallInstruction.js.map +1 -0
- package/dist/bindings/utils/resolveCustomCmakeOptions.js +26 -26
- package/dist/bindings/utils/resolveCustomCmakeOptions.js.map +1 -1
- package/dist/bindings/utils/testBindingBinary.d.ts +1 -0
- package/dist/bindings/utils/testBindingBinary.js +100 -0
- package/dist/bindings/utils/testBindingBinary.js.map +1 -0
- package/dist/bindings/utils/testCmakeBinary.d.ts +5 -0
- package/dist/bindings/utils/testCmakeBinary.js +32 -0
- package/dist/bindings/utils/testCmakeBinary.js.map +1 -0
- package/dist/chatWrappers/AlpacaChatWrapper.d.ts +2 -1
- package/dist/chatWrappers/AlpacaChatWrapper.js +10 -2
- package/dist/chatWrappers/AlpacaChatWrapper.js.map +1 -1
- package/dist/chatWrappers/ChatMLChatWrapper.d.ts +2 -14
- package/dist/chatWrappers/ChatMLChatWrapper.js +23 -21
- package/dist/chatWrappers/ChatMLChatWrapper.js.map +1 -1
- package/dist/chatWrappers/FalconChatWrapper.d.ts +4 -10
- package/dist/chatWrappers/FalconChatWrapper.js +39 -21
- package/dist/chatWrappers/FalconChatWrapper.js.map +1 -1
- package/dist/chatWrappers/FunctionaryChatWrapper.d.ts +8 -32
- package/dist/chatWrappers/FunctionaryChatWrapper.js +514 -118
- package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -1
- package/dist/chatWrappers/GemmaChatWrapper.d.ts +7 -0
- package/dist/chatWrappers/GemmaChatWrapper.js +96 -0
- package/dist/chatWrappers/GemmaChatWrapper.js.map +1 -0
- package/dist/chatWrappers/GeneralChatWrapper.d.ts +4 -10
- package/dist/chatWrappers/GeneralChatWrapper.js +46 -22
- package/dist/chatWrappers/GeneralChatWrapper.js.map +1 -1
- package/dist/chatWrappers/Llama2ChatWrapper.d.ts +12 -0
- package/dist/chatWrappers/{LlamaChatWrapper.js → Llama2ChatWrapper.js} +37 -20
- package/dist/chatWrappers/Llama2ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama3ChatWrapper.d.ts +16 -0
- package/dist/chatWrappers/Llama3ChatWrapper.js +173 -0
- package/dist/chatWrappers/Llama3ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.d.ts +35 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.js +277 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/MistralChatWrapper.d.ts +15 -0
- package/dist/chatWrappers/MistralChatWrapper.js +169 -0
- package/dist/chatWrappers/MistralChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.d.ts +100 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js +409 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.d.ts +60 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.js +204 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.d.ts +23 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js +45 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js.map +1 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.d.ts +57 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js +119 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js.map +1 -0
- package/dist/chatWrappers/utils/chunkChatItems.d.ts +10 -0
- package/dist/chatWrappers/utils/chunkChatItems.js +44 -0
- package/dist/chatWrappers/utils/chunkChatItems.js.map +1 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.d.ts +4 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js +221 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js.map +1 -0
- package/dist/chatWrappers/utils/jsonDumps.d.ts +7 -0
- package/dist/chatWrappers/utils/jsonDumps.js +18 -0
- package/dist/chatWrappers/utils/jsonDumps.js.map +1 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.d.ts +95 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js +335 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js.map +1 -0
- package/dist/cli/cli.js +19 -11
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/commands/ChatCommand.d.ts +16 -7
- package/dist/cli/commands/ChatCommand.js +321 -190
- package/dist/cli/commands/ChatCommand.js.map +1 -1
- package/dist/cli/commands/CompleteCommand.d.ts +31 -0
- package/dist/cli/commands/CompleteCommand.js +402 -0
- package/dist/cli/commands/CompleteCommand.js.map +1 -0
- package/dist/cli/commands/DebugCommand.d.ts +7 -0
- package/dist/cli/commands/DebugCommand.js +54 -0
- package/dist/cli/commands/DebugCommand.js.map +1 -0
- package/dist/cli/commands/InfillCommand.d.ts +33 -0
- package/dist/cli/commands/InfillCommand.js +438 -0
- package/dist/cli/commands/InfillCommand.js.map +1 -0
- package/dist/cli/commands/InitCommand.d.ts +11 -0
- package/dist/cli/commands/InitCommand.js +195 -0
- package/dist/cli/commands/InitCommand.js.map +1 -0
- package/dist/cli/commands/OnPostInstallCommand.js +6 -2
- package/dist/cli/commands/OnPostInstallCommand.js.map +1 -1
- package/dist/cli/commands/PullCommand.d.ts +13 -0
- package/dist/cli/commands/PullCommand.js +158 -0
- package/dist/cli/commands/PullCommand.js.map +1 -0
- package/dist/cli/commands/inspect/InspectCommand.d.ts +4 -0
- package/dist/cli/commands/inspect/InspectCommand.js +21 -0
- package/dist/cli/commands/inspect/InspectCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.d.ts +12 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js +225 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.d.ts +12 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +149 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.d.ts +4 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.js +202 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.d.ts +18 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js +629 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js.map +1 -0
- package/dist/cli/commands/source/SourceCommand.d.ts +4 -0
- package/dist/cli/commands/source/SourceCommand.js +19 -0
- package/dist/cli/commands/source/SourceCommand.js.map +1 -0
- package/dist/cli/commands/source/commands/BuildCommand.d.ts +16 -0
- package/dist/cli/commands/source/commands/BuildCommand.js +148 -0
- package/dist/cli/commands/source/commands/BuildCommand.js.map +1 -0
- package/dist/cli/commands/{ClearCommand.d.ts → source/commands/ClearCommand.d.ts} +1 -1
- package/dist/cli/commands/{ClearCommand.js → source/commands/ClearCommand.js} +11 -10
- package/dist/cli/commands/source/commands/ClearCommand.js.map +1 -0
- package/dist/cli/commands/{DownloadCommand.d.ts → source/commands/DownloadCommand.d.ts} +5 -4
- package/dist/cli/commands/source/commands/DownloadCommand.js +217 -0
- package/dist/cli/commands/source/commands/DownloadCommand.js.map +1 -0
- package/dist/cli/projectTemplates.d.ts +7 -0
- package/dist/cli/projectTemplates.js +10 -0
- package/dist/cli/projectTemplates.js.map +1 -0
- package/dist/cli/recommendedModels.d.ts +2 -0
- package/dist/cli/recommendedModels.js +585 -0
- package/dist/cli/recommendedModels.js.map +1 -0
- package/dist/cli/startCreateCli.d.ts +2 -0
- package/dist/cli/startCreateCli.js +26 -0
- package/dist/cli/startCreateCli.js.map +1 -0
- package/dist/cli/utils/ConsoleInteraction.d.ts +22 -0
- package/dist/cli/utils/ConsoleInteraction.js +122 -0
- package/dist/cli/utils/ConsoleInteraction.js.map +1 -0
- package/dist/cli/utils/ConsoleTable.d.ts +23 -0
- package/dist/cli/utils/ConsoleTable.js +86 -0
- package/dist/cli/utils/ConsoleTable.js.map +1 -0
- package/dist/cli/utils/basicChooseFromListConsoleInteraction.d.ts +13 -0
- package/dist/cli/utils/basicChooseFromListConsoleInteraction.js +111 -0
- package/dist/cli/utils/basicChooseFromListConsoleInteraction.js.map +1 -0
- package/dist/cli/utils/consolePromptQuestion.d.ts +6 -0
- package/dist/cli/utils/consolePromptQuestion.js +82 -0
- package/dist/cli/utils/consolePromptQuestion.js.map +1 -0
- package/dist/cli/utils/getReadablePath.d.ts +1 -0
- package/dist/cli/utils/getReadablePath.js +14 -0
- package/dist/cli/utils/getReadablePath.js.map +1 -0
- package/dist/cli/utils/interactivelyAskForModel.d.ts +8 -0
- package/dist/cli/utils/interactivelyAskForModel.js +450 -0
- package/dist/cli/utils/interactivelyAskForModel.js.map +1 -0
- package/dist/cli/utils/logUsedGpuTypeOption.d.ts +2 -0
- package/dist/cli/utils/logUsedGpuTypeOption.js +9 -0
- package/dist/cli/utils/logUsedGpuTypeOption.js.map +1 -0
- package/dist/cli/utils/printCommonInfoLines.d.ts +9 -0
- package/dist/cli/utils/printCommonInfoLines.js +82 -0
- package/dist/cli/utils/printCommonInfoLines.js.map +1 -0
- package/dist/cli/utils/printInfoLine.d.ts +12 -0
- package/dist/cli/utils/printInfoLine.js +54 -0
- package/dist/cli/utils/printInfoLine.js.map +1 -0
- package/dist/cli/utils/projectTemplates.d.ts +19 -0
- package/dist/cli/utils/projectTemplates.js +47 -0
- package/dist/cli/utils/projectTemplates.js.map +1 -0
- package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.d.ts +6 -0
- package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.js +14 -0
- package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.js.map +1 -0
- package/dist/cli/utils/resolveCommandGgufPath.d.ts +5 -0
- package/dist/cli/utils/resolveCommandGgufPath.js +72 -0
- package/dist/cli/utils/resolveCommandGgufPath.js.map +1 -0
- package/dist/cli/utils/resolveHeaderFlag.d.ts +1 -0
- package/dist/cli/utils/resolveHeaderFlag.js +21 -0
- package/dist/cli/utils/resolveHeaderFlag.js.map +1 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.d.ts +19 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js +7 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js.map +1 -0
- package/dist/cli/utils/splitAnsiToLines.d.ts +1 -0
- package/dist/cli/utils/splitAnsiToLines.js +32 -0
- package/dist/cli/utils/splitAnsiToLines.js.map +1 -0
- package/dist/cli/utils/withCliCommandDescriptionDocsUrl.d.ts +2 -0
- package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js +23 -0
- package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js.map +1 -0
- package/dist/commands.d.ts +4 -3
- package/dist/commands.js +6 -3
- package/dist/commands.js.map +1 -1
- package/dist/config.d.ts +35 -4
- package/dist/config.js +58 -17
- package/dist/config.js.map +1 -1
- package/dist/consts.d.ts +4 -0
- package/dist/consts.js +11 -0
- package/dist/consts.js.map +1 -0
- package/dist/evaluator/LlamaChat/LlamaChat.d.ts +151 -41
- package/dist/evaluator/LlamaChat/LlamaChat.js +1289 -437
- package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -1
- package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.d.ts +11 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js +55 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js.map +1 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.d.ts +16 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js +45 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js.map +1 -0
- package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.d.ts +8 -0
- package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js +12 -0
- package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js.map +1 -0
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +27 -17
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -1
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +187 -13
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +280 -53
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -1
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.d.ts +40 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js +186 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js.map +1 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.d.ts +10 -2
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js +8 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js.map +1 -1
- package/dist/evaluator/LlamaCompletion.d.ts +168 -0
- package/dist/evaluator/LlamaCompletion.js +470 -0
- package/dist/evaluator/LlamaCompletion.js.map +1 -0
- package/dist/evaluator/LlamaContext/LlamaContext.d.ts +62 -21
- package/dist/evaluator/LlamaContext/LlamaContext.js +501 -120
- package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -1
- package/dist/evaluator/LlamaContext/LlamaSampler.d.ts +1 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.js +31 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.js.map +1 -0
- package/dist/evaluator/LlamaContext/types.d.ts +177 -16
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.d.ts +2 -0
- package/dist/evaluator/LlamaContext/utils/{resolveBatchItemsPrioritizingStrategy.js → resolveBatchItemsPrioritizationStrategy.js} +5 -5
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.js.map +1 -0
- package/dist/evaluator/LlamaEmbedding.d.ts +21 -0
- package/dist/evaluator/LlamaEmbedding.js +53 -0
- package/dist/evaluator/LlamaEmbedding.js.map +1 -0
- package/dist/evaluator/LlamaEmbeddingContext.d.ts +29 -19
- package/dist/evaluator/LlamaEmbeddingContext.js +36 -43
- package/dist/evaluator/LlamaEmbeddingContext.js.map +1 -1
- package/dist/evaluator/LlamaGrammar.d.ts +16 -13
- package/dist/evaluator/LlamaGrammar.js +17 -10
- package/dist/evaluator/LlamaGrammar.js.map +1 -1
- package/dist/evaluator/LlamaGrammarEvaluationState.d.ts +7 -3
- package/dist/evaluator/LlamaGrammarEvaluationState.js +8 -4
- package/dist/evaluator/LlamaGrammarEvaluationState.js.map +1 -1
- package/dist/evaluator/LlamaJsonSchemaGrammar.d.ts +3 -0
- package/dist/evaluator/LlamaJsonSchemaGrammar.js +5 -3
- package/dist/evaluator/LlamaJsonSchemaGrammar.js.map +1 -1
- package/dist/evaluator/LlamaModel/LlamaModel.d.ts +255 -0
- package/dist/evaluator/LlamaModel/LlamaModel.js +780 -0
- package/dist/evaluator/LlamaModel/LlamaModel.js.map +1 -0
- package/dist/evaluator/LlamaModel/utils/TokenAttributes.d.ts +29 -0
- package/dist/evaluator/LlamaModel/utils/TokenAttributes.js +65 -0
- package/dist/evaluator/LlamaModel/utils/TokenAttributes.js.map +1 -0
- package/dist/evaluator/TokenBias.d.ts +34 -0
- package/dist/evaluator/TokenBias.js +65 -0
- package/dist/evaluator/TokenBias.js.map +1 -0
- package/dist/evaluator/TokenMeter.d.ts +45 -0
- package/dist/evaluator/TokenMeter.js +74 -0
- package/dist/evaluator/TokenMeter.js.map +1 -0
- package/dist/gguf/consts.d.ts +4 -0
- package/dist/gguf/consts.js +12 -0
- package/dist/gguf/consts.js.map +1 -0
- package/dist/gguf/errors/InvalidGgufMagicError.d.ts +3 -0
- package/dist/gguf/errors/InvalidGgufMagicError.js +6 -0
- package/dist/gguf/errors/InvalidGgufMagicError.js.map +1 -0
- package/dist/gguf/errors/UnsupportedGgufValueTypeError.d.ts +4 -0
- package/dist/gguf/errors/UnsupportedGgufValueTypeError.js +9 -0
- package/dist/gguf/errors/UnsupportedGgufValueTypeError.js.map +1 -0
- package/dist/gguf/fileReaders/GgufFileReader.d.ts +36 -0
- package/dist/gguf/fileReaders/GgufFileReader.js +109 -0
- package/dist/gguf/fileReaders/GgufFileReader.js.map +1 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.d.ts +16 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.js +62 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.js.map +1 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.d.ts +25 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js +92 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js.map +1 -0
- package/dist/gguf/insights/GgufInsights.d.ts +50 -0
- package/dist/gguf/insights/GgufInsights.js +401 -0
- package/dist/gguf/insights/GgufInsights.js.map +1 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.d.ts +146 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js +226 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js.map +1 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.d.ts +19 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js +78 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js.map +1 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.d.ts +15 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js +183 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js.map +1 -0
- package/dist/gguf/insights/utils/scoreLevels.d.ts +5 -0
- package/dist/gguf/insights/utils/scoreLevels.js +16 -0
- package/dist/gguf/insights/utils/scoreLevels.js.map +1 -0
- package/dist/gguf/parser/GgufV2Parser.d.ts +20 -0
- package/dist/gguf/parser/GgufV2Parser.js +156 -0
- package/dist/gguf/parser/GgufV2Parser.js.map +1 -0
- package/dist/gguf/parser/GgufV3Parser.d.ts +3 -0
- package/dist/gguf/parser/GgufV3Parser.js +4 -0
- package/dist/gguf/parser/GgufV3Parser.js.map +1 -0
- package/dist/gguf/parser/parseGguf.d.ts +8 -0
- package/dist/gguf/parser/parseGguf.js +61 -0
- package/dist/gguf/parser/parseGguf.js.map +1 -0
- package/dist/gguf/readGgufFileInfo.d.ts +45 -0
- package/dist/gguf/readGgufFileInfo.js +71 -0
- package/dist/gguf/readGgufFileInfo.js.map +1 -0
- package/dist/gguf/types/GgufFileInfoTypes.d.ts +84 -0
- package/dist/gguf/types/GgufFileInfoTypes.js +18 -0
- package/dist/gguf/types/GgufFileInfoTypes.js.map +1 -0
- package/dist/gguf/types/GgufMetadataTypes.d.ts +372 -0
- package/dist/gguf/types/GgufMetadataTypes.js +114 -0
- package/dist/gguf/types/GgufMetadataTypes.js.map +1 -0
- package/dist/gguf/types/GgufTensorInfoTypes.d.ts +37 -0
- package/dist/gguf/types/GgufTensorInfoTypes.js +33 -0
- package/dist/gguf/types/GgufTensorInfoTypes.js.map +1 -0
- package/dist/gguf/utils/GgufReadOffset.d.ts +6 -0
- package/dist/gguf/utils/GgufReadOffset.js +18 -0
- package/dist/gguf/utils/GgufReadOffset.js.map +1 -0
- package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.d.ts +6 -0
- package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js +76 -0
- package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js.map +1 -0
- package/dist/gguf/utils/getGgufFileTypeName.d.ts +4 -0
- package/dist/gguf/utils/getGgufFileTypeName.js +13 -0
- package/dist/gguf/utils/getGgufFileTypeName.js.map +1 -0
- package/dist/gguf/utils/getGgufMetadataArchitectureData.d.ts +3 -0
- package/dist/gguf/utils/getGgufMetadataArchitectureData.js +4 -0
- package/dist/gguf/utils/getGgufMetadataArchitectureData.js.map +1 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.d.ts +1 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.js +16 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.js.map +1 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.d.ts +2 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js +39 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js.map +1 -0
- package/dist/gguf/utils/resolveSplitGgufParts.d.ts +7 -0
- package/dist/gguf/utils/resolveSplitGgufParts.js +55 -0
- package/dist/gguf/utils/resolveSplitGgufParts.js.map +1 -0
- package/dist/index.d.ts +39 -14
- package/dist/index.js +29 -8
- package/dist/index.js.map +1 -1
- package/dist/state.d.ts +2 -0
- package/dist/state.js +7 -0
- package/dist/state.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +131 -5
- package/dist/types.js.map +1 -1
- package/dist/utils/DisposeGuard.d.ts +13 -0
- package/dist/utils/DisposeGuard.js +120 -0
- package/dist/utils/DisposeGuard.js.map +1 -0
- package/dist/utils/InsufficientMemoryError.d.ts +3 -0
- package/dist/utils/InsufficientMemoryError.js +6 -0
- package/dist/utils/InsufficientMemoryError.js.map +1 -0
- package/dist/utils/LlamaText.d.ts +73 -26
- package/dist/utils/LlamaText.js +475 -157
- package/dist/utils/LlamaText.js.map +1 -1
- package/dist/utils/LruCache.d.ts +12 -0
- package/dist/utils/LruCache.js +44 -0
- package/dist/utils/LruCache.js.map +1 -0
- package/dist/utils/OverridesObject.d.ts +7 -0
- package/dist/utils/OverridesObject.js +2 -0
- package/dist/utils/OverridesObject.js.map +1 -0
- package/dist/utils/ReplHistory.js +5 -1
- package/dist/utils/ReplHistory.js.map +1 -1
- package/dist/utils/StopGenerationDetector.d.ts +27 -8
- package/dist/utils/StopGenerationDetector.js +108 -22
- package/dist/utils/StopGenerationDetector.js.map +1 -1
- package/dist/utils/ThreadsSplitter.d.ts +32 -0
- package/dist/utils/ThreadsSplitter.js +177 -0
- package/dist/utils/ThreadsSplitter.js.map +1 -0
- package/dist/utils/TokenStreamRegulator.d.ts +10 -4
- package/dist/utils/TokenStreamRegulator.js +102 -10
- package/dist/utils/TokenStreamRegulator.js.map +1 -1
- package/dist/utils/UnsupportedError.d.ts +2 -0
- package/dist/utils/UnsupportedError.js +7 -0
- package/dist/utils/UnsupportedError.js.map +1 -0
- package/dist/utils/appendUserMessageToChatHistory.d.ts +4 -0
- package/dist/utils/appendUserMessageToChatHistory.js +4 -0
- package/dist/utils/appendUserMessageToChatHistory.js.map +1 -1
- package/dist/utils/clearTempFolder.js.map +1 -1
- package/dist/utils/cmake.js +23 -10
- package/dist/utils/cmake.js.map +1 -1
- package/dist/utils/compareTokens.d.ts +1 -1
- package/dist/utils/compareTokens.js.map +1 -1
- package/dist/utils/createModelDownloader.d.ts +199 -0
- package/dist/utils/createModelDownloader.js +405 -0
- package/dist/utils/createModelDownloader.js.map +1 -0
- package/dist/utils/findBestOption.d.ts +4 -0
- package/dist/utils/findBestOption.js +15 -0
- package/dist/utils/findBestOption.js.map +1 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.d.ts +1 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js +23 -12
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js.map +1 -1
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.js.map +1 -1
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.d.ts +5 -0
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js +11 -0
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.d.ts +3 -1
- package/dist/utils/gbnfJson/terminals/GbnfArray.js +10 -5
- package/dist/utils/gbnfJson/terminals/GbnfArray.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.d.ts +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNull.d.ts +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNull.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNumber.d.ts +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNumber.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.d.ts +3 -1
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js +9 -4
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfOr.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js +37 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfString.d.ts +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfString.js +23 -5
- package/dist/utils/gbnfJson/terminals/GbnfString.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.d.ts +7 -4
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js +37 -9
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/gbnfConsts.d.ts +5 -4
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js +14 -3
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js.map +1 -1
- package/dist/utils/gbnfJson/types.d.ts +3 -0
- package/dist/utils/gbnfJson/types.js.map +1 -1
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.d.ts +10 -0
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js +15 -0
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js.map +1 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.d.ts +2 -1
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js +6 -5
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js.map +1 -1
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js +3 -3
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js.map +1 -1
- package/dist/utils/getBuildDefaults.d.ts +1 -2
- package/dist/utils/getBuildDefaults.js +2 -3
- package/dist/utils/getBuildDefaults.js.map +1 -1
- package/dist/utils/getConsoleLogPrefix.d.ts +1 -1
- package/dist/utils/getConsoleLogPrefix.js +5 -4
- package/dist/utils/getConsoleLogPrefix.js.map +1 -1
- package/dist/utils/getGrammarsFolder.js +1 -1
- package/dist/utils/getGrammarsFolder.js.map +1 -1
- package/dist/utils/getQueuedTokensBeforeStopTrigger.d.ts +6 -0
- package/dist/utils/getQueuedTokensBeforeStopTrigger.js +22 -0
- package/dist/utils/getQueuedTokensBeforeStopTrigger.js.map +1 -0
- package/dist/utils/getReadableContextSize.d.ts +1 -0
- package/dist/utils/getReadableContextSize.js +7 -0
- package/dist/utils/getReadableContextSize.js.map +1 -0
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js +15 -11
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js.map +1 -1
- package/dist/utils/gitReleaseBundles.js +68 -1
- package/dist/utils/gitReleaseBundles.js.map +1 -1
- package/dist/utils/isToken.d.ts +2 -0
- package/dist/utils/isToken.js +4 -0
- package/dist/utils/isToken.js.map +1 -0
- package/dist/utils/isUrl.d.ts +1 -0
- package/dist/utils/isUrl.js +15 -0
- package/dist/utils/isUrl.js.map +1 -0
- package/dist/utils/mergeUnionTypes.d.ts +10 -0
- package/dist/utils/mergeUnionTypes.js +2 -0
- package/dist/utils/mergeUnionTypes.js.map +1 -0
- package/dist/utils/modelFileAccesTokens.d.ts +4 -0
- package/dist/utils/modelFileAccesTokens.js +40 -0
- package/dist/utils/modelFileAccesTokens.js.map +1 -0
- package/dist/utils/parseModelFileName.d.ts +1 -0
- package/dist/utils/parseModelFileName.js +6 -1
- package/dist/utils/parseModelFileName.js.map +1 -1
- package/dist/utils/parseTextTemplate.d.ts +66 -0
- package/dist/utils/parseTextTemplate.js +116 -0
- package/dist/utils/parseTextTemplate.js.map +1 -0
- package/dist/utils/prettyPrintObject.d.ts +10 -1
- package/dist/utils/prettyPrintObject.js +61 -15
- package/dist/utils/prettyPrintObject.js.map +1 -1
- package/dist/utils/pushAll.d.ts +6 -0
- package/dist/utils/pushAll.js +11 -0
- package/dist/utils/pushAll.js.map +1 -0
- package/dist/utils/removeNullFields.d.ts +2 -2
- package/dist/utils/removeNullFields.js.map +1 -1
- package/dist/utils/resolveGithubRelease.d.ts +2 -2
- package/dist/utils/resolveGithubRelease.js.map +1 -1
- package/dist/utils/resolveLastTokens.d.ts +2 -0
- package/dist/utils/resolveLastTokens.js +12 -0
- package/dist/utils/resolveLastTokens.js.map +1 -0
- package/dist/utils/runtime.d.ts +4 -0
- package/dist/utils/runtime.js +8 -0
- package/dist/utils/runtime.js.map +1 -0
- package/dist/utils/safeEventCallback.d.ts +6 -0
- package/dist/utils/safeEventCallback.js +29 -0
- package/dist/utils/safeEventCallback.js.map +1 -0
- package/dist/utils/spawnCommand.d.ts +11 -2
- package/dist/utils/spawnCommand.js +55 -7
- package/dist/utils/spawnCommand.js.map +1 -1
- package/dist/utils/tokenizeInput.d.ts +1 -1
- package/dist/utils/tokenizeInput.js +6 -3
- package/dist/utils/tokenizeInput.js.map +1 -1
- package/dist/utils/transformPromisable.d.ts +40 -0
- package/dist/utils/transformPromisable.js +64 -0
- package/dist/utils/transformPromisable.js.map +1 -0
- package/dist/utils/truncateTextAndRoundToWords.d.ts +2 -0
- package/dist/utils/truncateTextAndRoundToWords.js +32 -0
- package/dist/utils/truncateTextAndRoundToWords.js.map +1 -1
- package/dist/utils/utilTypes.d.ts +3 -0
- package/dist/utils/utilTypes.js +2 -0
- package/dist/utils/utilTypes.js.map +1 -0
- package/dist/utils/waitForLockfileRelease.js.map +1 -1
- package/dist/utils/withLockfile.js.map +1 -1
- package/dist/utils/withOra.d.ts +2 -0
- package/dist/utils/withOra.js +16 -6
- package/dist/utils/withOra.js.map +1 -1
- package/dist/utils/withProgressLog.d.ts +22 -0
- package/dist/utils/withProgressLog.js +211 -0
- package/dist/utils/withProgressLog.js.map +1 -0
- package/dist/utils/withStatusLogs.js +1 -1
- package/dist/utils/withStatusLogs.js.map +1 -1
- package/dist/utils/wrapAbortSignal.d.ts +1 -0
- package/dist/utils/wrapAbortSignal.js +9 -0
- package/dist/utils/wrapAbortSignal.js.map +1 -0
- package/llama/CMakeLists.txt +134 -5
- package/llama/addon/AddonContext.cpp +629 -0
- package/llama/addon/AddonContext.h +52 -0
- package/llama/addon/AddonGrammar.cpp +39 -0
- package/llama/addon/AddonGrammar.h +19 -0
- package/llama/addon/AddonGrammarEvaluationState.cpp +25 -0
- package/llama/addon/AddonGrammarEvaluationState.h +17 -0
- package/llama/addon/AddonModel.cpp +672 -0
- package/llama/addon/AddonModel.h +61 -0
- package/llama/addon/AddonModelData.cpp +25 -0
- package/llama/addon/AddonModelData.h +15 -0
- package/llama/addon/AddonModelLora.cpp +105 -0
- package/llama/addon/AddonModelLora.h +28 -0
- package/llama/addon/AddonSampler.cpp +513 -0
- package/llama/addon/AddonSampler.h +65 -0
- package/llama/addon/RingBuffer.h +109 -0
- package/llama/addon/addon.cpp +223 -0
- package/llama/addon/addonGlobals.cpp +22 -0
- package/llama/addon/addonGlobals.h +12 -0
- package/llama/addon/globals/addonLog.cpp +136 -0
- package/llama/addon/globals/addonLog.h +21 -0
- package/llama/addon/globals/addonProgress.cpp +15 -0
- package/llama/addon/globals/addonProgress.h +15 -0
- package/llama/addon/globals/getGpuInfo.cpp +108 -0
- package/llama/addon/globals/getGpuInfo.h +6 -0
- package/llama/binariesGithubRelease.json +1 -1
- package/llama/gitRelease.bundle +0 -0
- package/llama/gpuInfo/cuda-gpu-info.cu +120 -0
- package/llama/gpuInfo/cuda-gpu-info.h +10 -0
- package/llama/gpuInfo/metal-gpu-info.h +8 -0
- package/llama/gpuInfo/metal-gpu-info.mm +30 -0
- package/llama/gpuInfo/vulkan-gpu-info.cpp +83 -0
- package/llama/gpuInfo/vulkan-gpu-info.h +9 -0
- package/llama/grammars/README.md +297 -6
- package/llama/grammars/json.gbnf +4 -4
- package/llama/grammars/json_arr.gbnf +4 -4
- package/llama/llama.cpp.info.json +1 -1
- package/llama/toolchains/win32.host-x64.target-arm64.cmake +41 -0
- package/package.json +109 -59
- package/templates/packed/electron-typescript-react.json +1 -0
- package/templates/packed/node-typescript.json +1 -0
- package/dist/AbortError.d.ts +0 -2
- package/dist/AbortError.js +0 -7
- package/dist/AbortError.js.map +0 -1
- package/dist/chatWrappers/LlamaChatWrapper.d.ts +0 -13
- package/dist/chatWrappers/LlamaChatWrapper.js.map +0 -1
- package/dist/chatWrappers/resolveChatWrapperBasedOnModel.d.ts +0 -13
- package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js +0 -57
- package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js.map +0 -1
- package/dist/cli/commands/BuildCommand.d.ts +0 -11
- package/dist/cli/commands/BuildCommand.js +0 -106
- package/dist/cli/commands/BuildCommand.js.map +0 -1
- package/dist/cli/commands/ClearCommand.js.map +0 -1
- package/dist/cli/commands/DownloadCommand.js +0 -169
- package/dist/cli/commands/DownloadCommand.js.map +0 -1
- package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.d.ts +0 -22
- package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js +0 -121
- package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js.map +0 -1
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/firstInFirstOutStrategy.js.map +0 -1
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/maximumParallelismStrategy.js.map +0 -1
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.d.ts +0 -2
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.js.map +0 -1
- package/dist/evaluator/LlamaModel.d.ts +0 -120
- package/dist/evaluator/LlamaModel.js +0 -320
- package/dist/evaluator/LlamaModel.js.map +0 -1
- package/dist/utils/getGbnfGrammarForGbnfJsonSchema.d.ts +0 -2
- package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js +0 -9
- package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js.map +0 -1
- package/dist/utils/parseModelTypeDescription.d.ts +0 -6
- package/dist/utils/parseModelTypeDescription.js +0 -9
- package/dist/utils/parseModelTypeDescription.js.map +0 -1
- package/dist/utils/resolveChatWrapper.d.ts +0 -4
- package/dist/utils/resolveChatWrapper.js +0 -16
- package/dist/utils/resolveChatWrapper.js.map +0 -1
- package/llama/addon.cpp +0 -950
- package/llamaBins/linux-arm64/.buildMetadata.json +0 -1
- package/llamaBins/linux-arm64/llama-addon.node +0 -0
- package/llamaBins/linux-armv7l/.buildMetadata.json +0 -1
- package/llamaBins/linux-armv7l/llama-addon.node +0 -0
- package/llamaBins/linux-x64/.buildMetadata.json +0 -1
- package/llamaBins/linux-x64/llama-addon.node +0 -0
- package/llamaBins/linux-x64-cuda/.buildMetadata.json +0 -1
- package/llamaBins/linux-x64-cuda/llama-addon.node +0 -0
- package/llamaBins/mac-arm64-metal/.buildMetadata.json +0 -1
- package/llamaBins/mac-arm64-metal/ggml-metal.metal +0 -6119
- package/llamaBins/mac-arm64-metal/llama-addon.node +0 -0
- package/llamaBins/mac-x64/.buildMetadata.json +0 -1
- package/llamaBins/mac-x64/llama-addon.node +0 -0
- package/llamaBins/win-x64/.buildMetadata.json +0 -1
- package/llamaBins/win-x64/llama-addon.exp +0 -0
- package/llamaBins/win-x64/llama-addon.lib +0 -0
- package/llamaBins/win-x64/llama-addon.node +0 -0
- package/llamaBins/win-x64-cuda/.buildMetadata.json +0 -1
- package/llamaBins/win-x64-cuda/llama-addon.exp +0 -0
- package/llamaBins/win-x64-cuda/llama-addon.lib +0 -0
- package/llamaBins/win-x64-cuda/llama-addon.node +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/firstInFirstOutStrategy.d.ts +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/firstInFirstOutStrategy.js +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/maximumParallelismStrategy.d.ts +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/maximumParallelismStrategy.js +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CommandModule } from "yargs";
|
|
2
|
+
import { BuildGpu } from "../../../../bindings/types.js";
|
|
3
|
+
type InspectMeasureCommand = {
|
|
4
|
+
modelPath?: string;
|
|
5
|
+
header?: string[];
|
|
6
|
+
gpu?: BuildGpu | "auto";
|
|
7
|
+
minLayers: number;
|
|
8
|
+
maxLayers?: number;
|
|
9
|
+
minContextSize: number;
|
|
10
|
+
maxContextSize?: number;
|
|
11
|
+
flashAttention?: boolean;
|
|
12
|
+
measures: number;
|
|
13
|
+
printHeaderBeforeEachLayer?: boolean;
|
|
14
|
+
evaluateText?: string;
|
|
15
|
+
repeatEvaluateText?: number;
|
|
16
|
+
};
|
|
17
|
+
export declare const InspectMeasureCommand: CommandModule<object, InspectMeasureCommand>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import process from "process";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import { fork } from "node:child_process";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import bytes from "bytes";
|
|
7
|
+
import stripAnsi from "strip-ansi";
|
|
8
|
+
import { readGgufFileInfo } from "../../../../gguf/readGgufFileInfo.js";
|
|
9
|
+
import { resolveCommandGgufPath } from "../../../utils/resolveCommandGgufPath.js";
|
|
10
|
+
import { getLlama } from "../../../../bindings/getLlama.js";
|
|
11
|
+
import { LlamaLogLevel, nodeLlamaCppGpuOptions, parseNodeLlamaCppGpuOption } from "../../../../bindings/types.js";
|
|
12
|
+
import { getConsoleLogPrefix } from "../../../../utils/getConsoleLogPrefix.js";
|
|
13
|
+
import { ConsoleTable } from "../../../utils/ConsoleTable.js";
|
|
14
|
+
import { GgufInsights } from "../../../../gguf/insights/GgufInsights.js";
|
|
15
|
+
import { resolveHeaderFlag } from "../../../utils/resolveHeaderFlag.js";
|
|
16
|
+
import { getPrettyBuildGpuName } from "../../../../bindings/consts.js";
|
|
17
|
+
import { getReadablePath } from "../../../utils/getReadablePath.js";
|
|
18
|
+
import { withCliCommandDescriptionDocsUrl } from "../../../utils/withCliCommandDescriptionDocsUrl.js";
|
|
19
|
+
import { documentationPageUrls } from "../../../../config.js";
|
|
20
|
+
export const InspectMeasureCommand = {
|
|
21
|
+
command: "measure [modelPath]",
|
|
22
|
+
describe: withCliCommandDescriptionDocsUrl("Measure VRAM consumption of a GGUF model file with all possible combinations of gpu layers and context sizes", documentationPageUrls.CLI.Inspect.Measure),
|
|
23
|
+
builder(yargs) {
|
|
24
|
+
return yargs
|
|
25
|
+
.option("modelPath", {
|
|
26
|
+
alias: ["m", "model", "path", "url"],
|
|
27
|
+
type: "string",
|
|
28
|
+
description: "Model file to use for the chat. Can be a path to a local file or a URL of a model file to download. Leave empty to choose from a list of recommended models"
|
|
29
|
+
})
|
|
30
|
+
.option("header", {
|
|
31
|
+
alias: ["H"],
|
|
32
|
+
type: "string",
|
|
33
|
+
array: true,
|
|
34
|
+
description: "Headers to use when downloading a model from a URL, in the format `key: value`. You can pass this option multiple times to add multiple headers."
|
|
35
|
+
})
|
|
36
|
+
.option("gpu", {
|
|
37
|
+
type: "string",
|
|
38
|
+
// yargs types don't support passing `false` as a choice, although it is supported by yargs
|
|
39
|
+
choices: nodeLlamaCppGpuOptions,
|
|
40
|
+
coerce: (value) => {
|
|
41
|
+
if (value == null || value == "")
|
|
42
|
+
return undefined;
|
|
43
|
+
return parseNodeLlamaCppGpuOption(value);
|
|
44
|
+
},
|
|
45
|
+
defaultDescription: "Uses the latest local build, and fallbacks to \"auto\"",
|
|
46
|
+
description: "Compute layer implementation type to use for llama.cpp. If omitted, uses the latest local build, and fallbacks to \"auto\""
|
|
47
|
+
})
|
|
48
|
+
.option("minLayers", {
|
|
49
|
+
alias: "mnl",
|
|
50
|
+
type: "number",
|
|
51
|
+
default: 1,
|
|
52
|
+
description: "Minimum number of layers to offload to the GPU"
|
|
53
|
+
})
|
|
54
|
+
.option("maxLayers", {
|
|
55
|
+
alias: "mxl",
|
|
56
|
+
type: "number",
|
|
57
|
+
default: -1,
|
|
58
|
+
defaultDescription: "All layers",
|
|
59
|
+
description: "Maximum number of layers to offload to the GPU"
|
|
60
|
+
})
|
|
61
|
+
.option("minContextSize", {
|
|
62
|
+
alias: "mncs",
|
|
63
|
+
type: "number",
|
|
64
|
+
default: 512,
|
|
65
|
+
description: "Minimum context size"
|
|
66
|
+
})
|
|
67
|
+
.option("maxContextSize", {
|
|
68
|
+
alias: "mxcs",
|
|
69
|
+
type: "number",
|
|
70
|
+
default: -1,
|
|
71
|
+
defaultDescription: "Train context size",
|
|
72
|
+
description: "Maximum context size"
|
|
73
|
+
})
|
|
74
|
+
.option("flashAttention", {
|
|
75
|
+
alias: "fa",
|
|
76
|
+
type: "boolean",
|
|
77
|
+
default: false,
|
|
78
|
+
description: "Enable flash attention for the context"
|
|
79
|
+
})
|
|
80
|
+
.option("measures", {
|
|
81
|
+
alias: "n",
|
|
82
|
+
type: "number",
|
|
83
|
+
default: 10,
|
|
84
|
+
description: "Number of context size measures to take for each gpu layers count"
|
|
85
|
+
})
|
|
86
|
+
.option("printHeaderBeforeEachLayer", {
|
|
87
|
+
alias: "ph",
|
|
88
|
+
type: "boolean",
|
|
89
|
+
default: true,
|
|
90
|
+
description: "Print header before each layer's measures"
|
|
91
|
+
})
|
|
92
|
+
.option("evaluateText", {
|
|
93
|
+
alias: ["evaluate", "et"],
|
|
94
|
+
type: "string",
|
|
95
|
+
description: "Text to evaluate with the model"
|
|
96
|
+
})
|
|
97
|
+
.option("repeatEvaluateText", {
|
|
98
|
+
alias: ["repeatEvaluate", "ret"],
|
|
99
|
+
type: "number",
|
|
100
|
+
default: 1,
|
|
101
|
+
description: "Number of times to repeat the evaluation text before sending it for evaluation, in order to make it longer"
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
async handler({ modelPath: ggufPath, header: headerArg, gpu, minLayers, maxLayers, minContextSize, maxContextSize, flashAttention, measures = 10, printHeaderBeforeEachLayer = true, evaluateText, repeatEvaluateText }) {
|
|
105
|
+
if (maxLayers === -1)
|
|
106
|
+
maxLayers = undefined;
|
|
107
|
+
if (maxContextSize === -1)
|
|
108
|
+
maxContextSize = undefined;
|
|
109
|
+
if (minLayers < 1)
|
|
110
|
+
minLayers = 1;
|
|
111
|
+
const headers = resolveHeaderFlag(headerArg);
|
|
112
|
+
// ensure a llama build is available
|
|
113
|
+
const llama = gpu == null
|
|
114
|
+
? await getLlama("lastBuild", {
|
|
115
|
+
logLevel: LlamaLogLevel.error
|
|
116
|
+
})
|
|
117
|
+
: await getLlama({
|
|
118
|
+
gpu,
|
|
119
|
+
logLevel: LlamaLogLevel.error
|
|
120
|
+
});
|
|
121
|
+
const resolvedGgufPath = await resolveCommandGgufPath(ggufPath, llama, headers);
|
|
122
|
+
console.info(`${chalk.yellow("File:")} ${getReadablePath(resolvedGgufPath)}`);
|
|
123
|
+
console.info(`${chalk.yellow("GPU:")} ${getPrettyBuildGpuName(llama.gpu)}${gpu == null ? chalk.gray(" (last build)") : ""}`);
|
|
124
|
+
console.info();
|
|
125
|
+
const ggufMetadata = await readGgufFileInfo(resolvedGgufPath, {
|
|
126
|
+
sourceType: "filesystem"
|
|
127
|
+
});
|
|
128
|
+
const ggufInsights = await GgufInsights.from(ggufMetadata, llama);
|
|
129
|
+
const totalVram = (await llama.getVramState()).total;
|
|
130
|
+
let lastGpuLayers = maxLayers ?? ggufInsights.totalLayers;
|
|
131
|
+
let previousContextSizeCheck = undefined;
|
|
132
|
+
measureTable.logHeader({ drawRowSeparator: !printHeaderBeforeEachLayer });
|
|
133
|
+
while (lastGpuLayers >= (minLayers ?? 0)) {
|
|
134
|
+
let printedAlreadyWithThisProcess = false;
|
|
135
|
+
let hadSuccessInThisProcess = false;
|
|
136
|
+
const getNewProccessValue = () => {
|
|
137
|
+
if (printedAlreadyWithThisProcess)
|
|
138
|
+
return undefined;
|
|
139
|
+
printedAlreadyWithThisProcess = true;
|
|
140
|
+
return chalk.green("*");
|
|
141
|
+
};
|
|
142
|
+
const done = await measureModel({
|
|
143
|
+
modelPath: resolvedGgufPath,
|
|
144
|
+
gpu: gpu == null
|
|
145
|
+
? undefined
|
|
146
|
+
: llama.gpu,
|
|
147
|
+
maxGpuLayers: lastGpuLayers,
|
|
148
|
+
minGpuLayers: minLayers,
|
|
149
|
+
initialMaxContextSize: previousContextSizeCheck,
|
|
150
|
+
maxContextSize,
|
|
151
|
+
minContextSize,
|
|
152
|
+
flashAttention,
|
|
153
|
+
tests: measures,
|
|
154
|
+
evaluateText: evaluateText == null
|
|
155
|
+
? undefined
|
|
156
|
+
: evaluateText.repeat(repeatEvaluateText ?? 1),
|
|
157
|
+
onInfo({ gpuLayers, result }) {
|
|
158
|
+
if (lastGpuLayers !== gpuLayers) {
|
|
159
|
+
lastGpuLayers = gpuLayers;
|
|
160
|
+
previousContextSizeCheck = undefined;
|
|
161
|
+
measureTable.logLine({});
|
|
162
|
+
if (printHeaderBeforeEachLayer)
|
|
163
|
+
measureTable.logHeader({ drawRowSeparator: false });
|
|
164
|
+
}
|
|
165
|
+
if (result.type === "crash") {
|
|
166
|
+
if (!hadSuccessInThisProcess) {
|
|
167
|
+
measureTable.logLine({
|
|
168
|
+
newProcess: getNewProccessValue(),
|
|
169
|
+
type: chalk.redBright("Crash"),
|
|
170
|
+
gpuLayers: String(lastGpuLayers),
|
|
171
|
+
contextSize: previousContextSizeCheck != null
|
|
172
|
+
? String(previousContextSizeCheck)
|
|
173
|
+
: chalk.red(result.result),
|
|
174
|
+
estimatedModelVram: previousContextSizeCheck == null
|
|
175
|
+
? undefined
|
|
176
|
+
: chalk.red(result.result)
|
|
177
|
+
});
|
|
178
|
+
lastGpuLayers--;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else if (result.type === "error") {
|
|
182
|
+
previousContextSizeCheck = result.contextSize;
|
|
183
|
+
hadSuccessInThisProcess = true;
|
|
184
|
+
measureTable.logLine({
|
|
185
|
+
newProcess: getNewProccessValue(),
|
|
186
|
+
type: chalk.red("Error"),
|
|
187
|
+
gpuLayers: String(lastGpuLayers),
|
|
188
|
+
contextSize: previousContextSizeCheck != null
|
|
189
|
+
? String(previousContextSizeCheck)
|
|
190
|
+
: chalk.red(result.error),
|
|
191
|
+
estimatedModelVram: previousContextSizeCheck == null
|
|
192
|
+
? undefined
|
|
193
|
+
: chalk.red(result.error)
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
else if (result.type === "success") {
|
|
197
|
+
previousContextSizeCheck = result.contextSize;
|
|
198
|
+
hadSuccessInThisProcess = true;
|
|
199
|
+
const modelVramEstimation = ggufInsights.estimateModelResourceRequirements({ gpuLayers: lastGpuLayers }).gpuVram;
|
|
200
|
+
const modelVramEstimationDiffBytes = (modelVramEstimation < result.modelVramUsage ? "-" : "") +
|
|
201
|
+
bytes(Math.abs(result.modelVramUsage - modelVramEstimation));
|
|
202
|
+
const modelVramEstimationDiffText = modelVramEstimationDiffBytes.padEnd(9, " ") + " " +
|
|
203
|
+
padStartAnsi("(" + renderDiffPercentageWithColors(((modelVramEstimation / result.modelVramUsage) - 1) * 100) + ")", 9);
|
|
204
|
+
const contextVramEstimation = previousContextSizeCheck == null
|
|
205
|
+
? undefined
|
|
206
|
+
: ggufInsights.estimateContextResourceRequirements({
|
|
207
|
+
contextSize: previousContextSizeCheck,
|
|
208
|
+
modelGpuLayers: lastGpuLayers,
|
|
209
|
+
flashAttention
|
|
210
|
+
}).gpuVram;
|
|
211
|
+
const contextVramEstimationDiffBytes = (result.contextVramUsage == null || contextVramEstimation == null)
|
|
212
|
+
? undefined
|
|
213
|
+
: ((contextVramEstimation < result.contextVramUsage ? "-" : "") +
|
|
214
|
+
bytes(Math.abs(result.contextVramUsage - contextVramEstimation)));
|
|
215
|
+
const contextVramEstimationDiffText = (contextVramEstimation == null || contextVramEstimationDiffBytes == null || result.contextVramUsage == null)
|
|
216
|
+
? undefined
|
|
217
|
+
: (contextVramEstimationDiffBytes.padEnd(9, " ") + " " +
|
|
218
|
+
padStartAnsi("(" + renderDiffPercentageWithColors(((contextVramEstimation / result.contextVramUsage) - 1) * 100) + ")", 9));
|
|
219
|
+
measureTable.logLine({
|
|
220
|
+
newProcess: getNewProccessValue(),
|
|
221
|
+
type: previousContextSizeCheck == null
|
|
222
|
+
? "Model"
|
|
223
|
+
: "Context",
|
|
224
|
+
gpuLayers: String(lastGpuLayers),
|
|
225
|
+
contextSize: previousContextSizeCheck != null
|
|
226
|
+
? String(previousContextSizeCheck)
|
|
227
|
+
: undefined,
|
|
228
|
+
estimatedModelVram: bytes(modelVramEstimation),
|
|
229
|
+
actualModelVram: bytes(result.modelVramUsage),
|
|
230
|
+
modelEstimationDiff: modelVramEstimationDiffText,
|
|
231
|
+
estimatedContextVram: contextVramEstimation == null
|
|
232
|
+
? undefined
|
|
233
|
+
: bytes(contextVramEstimation),
|
|
234
|
+
actualContextVram: result.contextVramUsage == null
|
|
235
|
+
? undefined
|
|
236
|
+
: bytes(result.contextVramUsage),
|
|
237
|
+
contextEstimationDiff: contextVramEstimationDiffText,
|
|
238
|
+
totalVramUsage: ((result.totalVramUsage / totalVram) * 100).toFixed(2).padStart(5, "0") + "% " +
|
|
239
|
+
chalk.gray("(" + bytes(result.totalVramUsage) + "/" + bytes(totalVram) + ")")
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
if (done)
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
const measureTable = new ConsoleTable([{
|
|
250
|
+
key: "newProcess",
|
|
251
|
+
title: " ",
|
|
252
|
+
width: 1
|
|
253
|
+
}, {
|
|
254
|
+
key: "type",
|
|
255
|
+
title: "Type",
|
|
256
|
+
width: Math.max("Type".length, "Model".length, "Context".length),
|
|
257
|
+
canSpanOverEmptyColumns: true
|
|
258
|
+
}, {
|
|
259
|
+
key: "gpuLayers",
|
|
260
|
+
title: "Layers",
|
|
261
|
+
width: "Layers".length,
|
|
262
|
+
canSpanOverEmptyColumns: true
|
|
263
|
+
}, {
|
|
264
|
+
key: "contextSize",
|
|
265
|
+
title: "Context size",
|
|
266
|
+
width: "Context size".length,
|
|
267
|
+
canSpanOverEmptyColumns: true
|
|
268
|
+
}, {
|
|
269
|
+
key: "estimatedModelVram",
|
|
270
|
+
title: "Estimated model VRAM",
|
|
271
|
+
width: "Estimated model VRAM".length,
|
|
272
|
+
canSpanOverEmptyColumns: true
|
|
273
|
+
}, {
|
|
274
|
+
key: "actualModelVram",
|
|
275
|
+
title: "Model VRAM",
|
|
276
|
+
width: "Model VRAM".length
|
|
277
|
+
}, {
|
|
278
|
+
key: "modelEstimationDiff",
|
|
279
|
+
title: "Diff",
|
|
280
|
+
width: Math.max("Diff".length, 9 + 1 + 9)
|
|
281
|
+
}, {
|
|
282
|
+
key: "estimatedContextVram",
|
|
283
|
+
title: "Estimated context VRAM",
|
|
284
|
+
width: "Estimated context VRAM".length
|
|
285
|
+
}, {
|
|
286
|
+
key: "actualContextVram",
|
|
287
|
+
title: "Context VRAM",
|
|
288
|
+
width: "Context VRAM".length
|
|
289
|
+
}, {
|
|
290
|
+
key: "contextEstimationDiff",
|
|
291
|
+
title: "Diff",
|
|
292
|
+
width: Math.max("Diff".length, 9 + 1 + 9)
|
|
293
|
+
}, {
|
|
294
|
+
key: "totalVramUsage",
|
|
295
|
+
title: "VRAM usage",
|
|
296
|
+
width: Math.max("VRAM usage".length, 8 + 1 + 8 + 1 + 8)
|
|
297
|
+
}]);
|
|
298
|
+
function renderDiffPercentageWithColors(percentage, { greenBright = 2, green = 6, yellow = 10, yellowBright = 14 } = {}) {
|
|
299
|
+
const percentageText = percentage.toFixed(2).padStart(5, "0") + "%";
|
|
300
|
+
const absPercentage = Math.abs(percentage);
|
|
301
|
+
if (absPercentage < greenBright)
|
|
302
|
+
return chalk.greenBright(percentageText);
|
|
303
|
+
else if (absPercentage < green)
|
|
304
|
+
return chalk.green(percentageText);
|
|
305
|
+
else if (absPercentage < yellow)
|
|
306
|
+
return chalk.yellow(percentageText);
|
|
307
|
+
else if (absPercentage < yellowBright)
|
|
308
|
+
return chalk.yellowBright(percentageText);
|
|
309
|
+
return chalk.red(percentageText);
|
|
310
|
+
}
|
|
311
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
312
|
+
const detectedFileName = path.basename(__filename);
|
|
313
|
+
const expectedFileName = "InspectMeasureCommand";
|
|
314
|
+
async function measureModel({ modelPath, gpu, tests, initialMaxContextSize, maxContextSize, minContextSize, maxGpuLayers, minGpuLayers, flashAttention, evaluateText, onInfo }) {
|
|
315
|
+
if (!detectedFileName.startsWith(expectedFileName)) {
|
|
316
|
+
console.warn(getConsoleLogPrefix() +
|
|
317
|
+
`"${expectedFileName}.js" file is not independent, so running sub-process tests cannot be done with it\n` +
|
|
318
|
+
getConsoleLogPrefix() +
|
|
319
|
+
'To resolve this issue, make sure that "node-llama-cpp" is not bundled together with other code.');
|
|
320
|
+
throw new Error("Sub-process tests cannot be done with the current file");
|
|
321
|
+
}
|
|
322
|
+
const subProcess = fork(__filename, [], {
|
|
323
|
+
detached: false,
|
|
324
|
+
stdio: [null, null, null, "ipc"],
|
|
325
|
+
env: {
|
|
326
|
+
...process.env,
|
|
327
|
+
MEASURE_MODEL_CP: "true",
|
|
328
|
+
MEASURE_MODEL_CP_GPU: gpu == null
|
|
329
|
+
? undefined
|
|
330
|
+
: JSON.stringify(gpu)
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
let isPlannedExit = false;
|
|
334
|
+
let forkSucceeded = false;
|
|
335
|
+
let timeoutHandle = null;
|
|
336
|
+
const processCreationTimeout = 1000 * 60 * 5;
|
|
337
|
+
const stdTexts = [];
|
|
338
|
+
let lastGpuLayers = maxGpuLayers;
|
|
339
|
+
function cleanup() {
|
|
340
|
+
if (subProcess.exitCode == null)
|
|
341
|
+
subProcess.kill("SIGKILL");
|
|
342
|
+
if (timeoutHandle != null)
|
|
343
|
+
clearTimeout(timeoutHandle);
|
|
344
|
+
process.off("exit", cleanup);
|
|
345
|
+
}
|
|
346
|
+
process.on("exit", cleanup);
|
|
347
|
+
subProcess.stdout?.on("data", (data) => {
|
|
348
|
+
stdTexts.push(data.toString());
|
|
349
|
+
});
|
|
350
|
+
subProcess.stderr?.on("data", (data) => {
|
|
351
|
+
stdTexts.push(data.toString());
|
|
352
|
+
});
|
|
353
|
+
return Promise.race([
|
|
354
|
+
new Promise((_, reject) => {
|
|
355
|
+
timeoutHandle = setTimeout(() => {
|
|
356
|
+
if (!forkSucceeded) {
|
|
357
|
+
reject(new Error("Measuring using a sub-process timed out"));
|
|
358
|
+
cleanup();
|
|
359
|
+
}
|
|
360
|
+
}, processCreationTimeout);
|
|
361
|
+
}),
|
|
362
|
+
new Promise((resolve, reject) => {
|
|
363
|
+
function done() {
|
|
364
|
+
if (!forkSucceeded)
|
|
365
|
+
reject(new Error(`Measuring a model failed to run a sub-process via file "${__filename}"`));
|
|
366
|
+
else
|
|
367
|
+
resolve(isPlannedExit);
|
|
368
|
+
cleanup();
|
|
369
|
+
}
|
|
370
|
+
subProcess.on("message", (message) => {
|
|
371
|
+
if (message.type === "ready") {
|
|
372
|
+
forkSucceeded = true;
|
|
373
|
+
subProcess.send({
|
|
374
|
+
type: "start",
|
|
375
|
+
modelPath,
|
|
376
|
+
tests,
|
|
377
|
+
initialMaxContextSize,
|
|
378
|
+
maxContextSize,
|
|
379
|
+
minContextSize,
|
|
380
|
+
maxGpuLayers,
|
|
381
|
+
minGpuLayers,
|
|
382
|
+
flashAttention,
|
|
383
|
+
evaluateText
|
|
384
|
+
});
|
|
385
|
+
if (timeoutHandle != null) {
|
|
386
|
+
clearTimeout(timeoutHandle);
|
|
387
|
+
timeoutHandle = null;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
else if (message.type === "done") {
|
|
391
|
+
isPlannedExit = true;
|
|
392
|
+
subProcess.send({ type: "exit" });
|
|
393
|
+
}
|
|
394
|
+
else if (message.type === "error") {
|
|
395
|
+
lastGpuLayers = message.gpuLayers;
|
|
396
|
+
onInfo({
|
|
397
|
+
gpuLayers: lastGpuLayers,
|
|
398
|
+
result: {
|
|
399
|
+
type: "error",
|
|
400
|
+
error: message.error,
|
|
401
|
+
contextSize: message.contextSize
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
else if (message.type === "stats") {
|
|
406
|
+
lastGpuLayers = message.gpuLayers;
|
|
407
|
+
onInfo({
|
|
408
|
+
gpuLayers: message.gpuLayers,
|
|
409
|
+
result: {
|
|
410
|
+
type: "success",
|
|
411
|
+
modelVramUsage: message.modelVramUsage,
|
|
412
|
+
contextSize: message.contextSize,
|
|
413
|
+
contextVramUsage: message.contextVramUsage,
|
|
414
|
+
contextStateSize: message.contextStateSize,
|
|
415
|
+
totalVramUsage: message.totalVramUsage
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
subProcess.on("exit", (code) => {
|
|
421
|
+
if (code !== 0 || !isPlannedExit)
|
|
422
|
+
onInfo({
|
|
423
|
+
gpuLayers: lastGpuLayers,
|
|
424
|
+
result: {
|
|
425
|
+
type: "crash",
|
|
426
|
+
result: stdTexts.join("")
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
done();
|
|
430
|
+
});
|
|
431
|
+
if (subProcess.killed || subProcess.exitCode != null) {
|
|
432
|
+
if (subProcess.exitCode !== 0 || !isPlannedExit)
|
|
433
|
+
onInfo({
|
|
434
|
+
gpuLayers: lastGpuLayers,
|
|
435
|
+
result: {
|
|
436
|
+
type: "crash",
|
|
437
|
+
result: stdTexts.join("")
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
done();
|
|
441
|
+
}
|
|
442
|
+
})
|
|
443
|
+
]);
|
|
444
|
+
}
|
|
445
|
+
if (process.env.MEASURE_MODEL_CP === "true" && process.send != null) {
|
|
446
|
+
void runTestWorkerLogic();
|
|
447
|
+
}
|
|
448
|
+
async function runTestWorkerLogic() {
|
|
449
|
+
const gpuEnvVar = process.env.MEASURE_MODEL_CP_GPU;
|
|
450
|
+
const llama = (gpuEnvVar == null || gpuEnvVar === "")
|
|
451
|
+
? await getLlama("lastBuild", {
|
|
452
|
+
logLevel: LlamaLogLevel.error
|
|
453
|
+
})
|
|
454
|
+
: await getLlama({
|
|
455
|
+
gpu: JSON.parse(gpuEnvVar),
|
|
456
|
+
logLevel: LlamaLogLevel.error
|
|
457
|
+
});
|
|
458
|
+
if (process.send == null)
|
|
459
|
+
throw new Error("No IPC channel to parent process");
|
|
460
|
+
function sendInfoBack(info) {
|
|
461
|
+
if (process.send == null)
|
|
462
|
+
process.exit(1);
|
|
463
|
+
process.send(info);
|
|
464
|
+
}
|
|
465
|
+
async function testContextSizes({ model, modelVramUsage, startContextSize, maxContextSize, minContextSize, tests, flashAttention, evaluateText }) {
|
|
466
|
+
const contextSizeCheckPlan = getContextSizesCheckPlan(maxContextSize != null
|
|
467
|
+
? Math.min(model.trainContextSize, maxContextSize)
|
|
468
|
+
: model.trainContextSize, tests, minContextSize);
|
|
469
|
+
let currentContextSizeCheck = startContextSize == null
|
|
470
|
+
? -1
|
|
471
|
+
: getNextItemInCheckContextSizesPlan(contextSizeCheckPlan, startContextSize);
|
|
472
|
+
while (currentContextSizeCheck != null) {
|
|
473
|
+
if (currentContextSizeCheck === -1)
|
|
474
|
+
currentContextSizeCheck = null;
|
|
475
|
+
try {
|
|
476
|
+
const preContextVramUsage = (await llama.getVramState()).used;
|
|
477
|
+
const context = await model.createContext({
|
|
478
|
+
contextSize: currentContextSizeCheck ?? (maxContextSize != null
|
|
479
|
+
? { max: maxContextSize }
|
|
480
|
+
: undefined),
|
|
481
|
+
ignoreMemorySafetyChecks: currentContextSizeCheck != null,
|
|
482
|
+
flashAttention,
|
|
483
|
+
failedCreationRemedy: false
|
|
484
|
+
});
|
|
485
|
+
if (evaluateText != null && evaluateText != "") {
|
|
486
|
+
const sequence = context.getSequence();
|
|
487
|
+
await sequence.evaluateWithoutGeneratingNewTokens(model.tokenize(evaluateText));
|
|
488
|
+
}
|
|
489
|
+
const postContextVramUsage = (await llama.getVramState()).used;
|
|
490
|
+
sendInfoBack({
|
|
491
|
+
type: "stats",
|
|
492
|
+
gpuLayers: model.gpuLayers,
|
|
493
|
+
modelVramUsage,
|
|
494
|
+
contextSize: context.contextSize,
|
|
495
|
+
contextVramUsage: postContextVramUsage - preContextVramUsage,
|
|
496
|
+
contextStateSize: context.stateSize,
|
|
497
|
+
totalVramUsage: postContextVramUsage
|
|
498
|
+
});
|
|
499
|
+
currentContextSizeCheck = context.contextSize;
|
|
500
|
+
await context.dispose();
|
|
501
|
+
}
|
|
502
|
+
catch (err) {
|
|
503
|
+
sendInfoBack({
|
|
504
|
+
type: "error",
|
|
505
|
+
error: String(err),
|
|
506
|
+
gpuLayers: model.gpuLayers,
|
|
507
|
+
contextSize: currentContextSizeCheck == null
|
|
508
|
+
? undefined
|
|
509
|
+
: currentContextSizeCheck
|
|
510
|
+
});
|
|
511
|
+
if (currentContextSizeCheck == null) {
|
|
512
|
+
currentContextSizeCheck = contextSizeCheckPlan[0];
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
currentContextSizeCheck = getNextItemInCheckContextSizesPlan(contextSizeCheckPlan, currentContextSizeCheck);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
async function testWithGpuLayers({ modelPath, gpuLayers, tests, startContextSize, maxContextSize, minContextSize, flashAttention, evaluateText }) {
|
|
520
|
+
try {
|
|
521
|
+
const preModelVramUsage = (await llama.getVramState()).used;
|
|
522
|
+
const model = await llama.loadModel({
|
|
523
|
+
modelPath,
|
|
524
|
+
gpuLayers,
|
|
525
|
+
defaultContextFlashAttention: flashAttention,
|
|
526
|
+
ignoreMemorySafetyChecks: true
|
|
527
|
+
});
|
|
528
|
+
const postModelVramUsage = (await llama.getVramState()).used;
|
|
529
|
+
sendInfoBack({
|
|
530
|
+
type: "stats",
|
|
531
|
+
gpuLayers: model.gpuLayers,
|
|
532
|
+
modelVramUsage: postModelVramUsage - preModelVramUsage,
|
|
533
|
+
totalVramUsage: postModelVramUsage
|
|
534
|
+
});
|
|
535
|
+
await testContextSizes({
|
|
536
|
+
model,
|
|
537
|
+
modelVramUsage: postModelVramUsage - preModelVramUsage,
|
|
538
|
+
startContextSize,
|
|
539
|
+
maxContextSize,
|
|
540
|
+
minContextSize,
|
|
541
|
+
flashAttention,
|
|
542
|
+
tests,
|
|
543
|
+
evaluateText
|
|
544
|
+
});
|
|
545
|
+
await model.dispose();
|
|
546
|
+
}
|
|
547
|
+
catch (err) {
|
|
548
|
+
sendInfoBack({
|
|
549
|
+
type: "error",
|
|
550
|
+
error: String(err),
|
|
551
|
+
gpuLayers: gpuLayers
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
process.on("message", async (message) => {
|
|
556
|
+
if (message.type === "start") {
|
|
557
|
+
for (let gpuLayers = message.maxGpuLayers; gpuLayers >= (message.minGpuLayers ?? 0); gpuLayers--) {
|
|
558
|
+
await testWithGpuLayers({
|
|
559
|
+
modelPath: message.modelPath,
|
|
560
|
+
gpuLayers,
|
|
561
|
+
tests: message.tests,
|
|
562
|
+
startContextSize: gpuLayers == message.maxGpuLayers
|
|
563
|
+
? message.initialMaxContextSize
|
|
564
|
+
: undefined,
|
|
565
|
+
maxContextSize: message.maxContextSize,
|
|
566
|
+
minContextSize: message.minContextSize,
|
|
567
|
+
flashAttention: message.flashAttention,
|
|
568
|
+
evaluateText: message.evaluateText
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
sendInfoBack({ type: "done" });
|
|
572
|
+
}
|
|
573
|
+
else if (message.type === "exit") {
|
|
574
|
+
await llama.dispose();
|
|
575
|
+
process.exit(0);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
process.send({ type: "ready" });
|
|
579
|
+
}
|
|
580
|
+
function getContextSizesCheckPlan(trainContextSize, tests = 10, minContextSize) {
|
|
581
|
+
const res = [];
|
|
582
|
+
let shouldStop = false;
|
|
583
|
+
const attemptToCoverSizes = [256, 512, 1024, 2048, 4096];
|
|
584
|
+
function addSize(size) {
|
|
585
|
+
if (size > trainContextSize) {
|
|
586
|
+
size = trainContextSize;
|
|
587
|
+
shouldStop = true;
|
|
588
|
+
}
|
|
589
|
+
if (size < 2)
|
|
590
|
+
size = 2;
|
|
591
|
+
if (res[res.length - 1] === size) {
|
|
592
|
+
shouldStop = true;
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
res.push(size);
|
|
596
|
+
}
|
|
597
|
+
while (!shouldStop && res.length < tests) {
|
|
598
|
+
const lastSize = res[res.length - 1];
|
|
599
|
+
if (lastSize == null) {
|
|
600
|
+
addSize(Math.max(minContextSize ?? 0, Math.min(attemptToCoverSizes[0], trainContextSize / tests)));
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
const stepSizesLeft = Math.floor((trainContextSize - Math.min(lastSize, attemptToCoverSizes[attemptToCoverSizes.length - 1])) / (tests - res.length));
|
|
604
|
+
let stopAddingAttemptedSizes = false;
|
|
605
|
+
for (const size of attemptToCoverSizes) {
|
|
606
|
+
if (stepSizesLeft > lastSize && lastSize < size && size <= trainContextSize) {
|
|
607
|
+
addSize(size);
|
|
608
|
+
stopAddingAttemptedSizes = true;
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
if (stopAddingAttemptedSizes)
|
|
613
|
+
continue;
|
|
614
|
+
addSize(lastSize + stepSizesLeft);
|
|
615
|
+
}
|
|
616
|
+
return res.reverse();
|
|
617
|
+
}
|
|
618
|
+
function getNextItemInCheckContextSizesPlan(plan, currentSize) {
|
|
619
|
+
for (const size of plan) {
|
|
620
|
+
if (size < currentSize)
|
|
621
|
+
return size;
|
|
622
|
+
}
|
|
623
|
+
return null;
|
|
624
|
+
}
|
|
625
|
+
function padStartAnsi(text, length, padChar = " ") {
|
|
626
|
+
const textWithoutAnsi = stripAnsi(text);
|
|
627
|
+
return padChar.repeat(Math.max(0, length - textWithoutAnsi.length)) + text;
|
|
628
|
+
}
|
|
629
|
+
//# sourceMappingURL=InspectMeasureCommand.js.map
|