@realtimex/node-llama-cpp 0.1.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/LICENSE +21 -0
- package/README.md +108 -0
- package/dist/ChatWrapper.d.ts +27 -0
- package/dist/ChatWrapper.js +233 -0
- package/dist/ChatWrapper.js.map +1 -0
- 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 +203 -0
- package/dist/bindings/AddonTypes.js +2 -0
- package/dist/bindings/AddonTypes.js.map +1 -0
- package/dist/bindings/Llama.d.ts +104 -0
- package/dist/bindings/Llama.js +570 -0
- package/dist/bindings/Llama.js.map +1 -0
- 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 +297 -0
- package/dist/bindings/getLlama.js +569 -0
- package/dist/bindings/getLlama.js.map +1 -0
- package/dist/bindings/types.d.ts +72 -0
- package/dist/bindings/types.js +105 -0
- package/dist/bindings/types.js.map +1 -0
- package/dist/bindings/utils/MemoryOrchestrator.d.ts +23 -0
- package/dist/bindings/utils/MemoryOrchestrator.js +50 -0
- package/dist/bindings/utils/MemoryOrchestrator.js.map +1 -0
- package/dist/bindings/utils/NoBinaryFoundError.d.ts +2 -0
- package/dist/bindings/utils/NoBinaryFoundError.js +7 -0
- package/dist/bindings/utils/NoBinaryFoundError.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 +29 -0
- package/dist/bindings/utils/asyncSome.js.map +1 -0
- package/dist/bindings/utils/binariesGithubRelease.d.ts +6 -0
- package/dist/bindings/utils/binariesGithubRelease.js +15 -0
- package/dist/bindings/utils/binariesGithubRelease.js.map +1 -0
- package/dist/bindings/utils/clearAllLocalBuilds.d.ts +1 -0
- package/dist/bindings/utils/clearAllLocalBuilds.js +47 -0
- package/dist/bindings/utils/clearAllLocalBuilds.js.map +1 -0
- package/dist/bindings/utils/cloneLlamaCppRepo.d.ts +11 -0
- package/dist/bindings/utils/cloneLlamaCppRepo.js +166 -0
- package/dist/bindings/utils/cloneLlamaCppRepo.js.map +1 -0
- package/dist/bindings/utils/compileLLamaCpp.d.ts +22 -0
- package/dist/bindings/utils/compileLLamaCpp.js +526 -0
- package/dist/bindings/utils/compileLLamaCpp.js.map +1 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.d.ts +18 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.js +311 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.js.map +1 -0
- package/dist/bindings/utils/detectBuildTools.d.ts +14 -0
- package/dist/bindings/utils/detectBuildTools.js +149 -0
- package/dist/bindings/utils/detectBuildTools.js.map +1 -0
- package/dist/bindings/utils/detectGlibc.d.ts +4 -0
- package/dist/bindings/utils/detectGlibc.js +74 -0
- package/dist/bindings/utils/detectGlibc.js.map +1 -0
- package/dist/bindings/utils/disposeBeforeExit.d.ts +8 -0
- package/dist/bindings/utils/disposeBeforeExit.js +36 -0
- package/dist/bindings/utils/disposeBeforeExit.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.d.ts +6 -0
- package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js +105 -0
- package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js.map +1 -0
- package/dist/bindings/utils/getCanUsePrebuiltBinaries.d.ts +1 -0
- package/dist/bindings/utils/getCanUsePrebuiltBinaries.js +8 -0
- package/dist/bindings/utils/getCanUsePrebuiltBinaries.js.map +1 -0
- package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.d.ts +2 -0
- package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js +21 -0
- package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js.map +1 -0
- 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/getLlamaGpuTypes.d.ts +13 -0
- package/dist/bindings/utils/getLlamaGpuTypes.js +36 -0
- package/dist/bindings/utils/getLlamaGpuTypes.js.map +1 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.d.ts +5 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.js +40 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.js.map +1 -0
- package/dist/bindings/utils/getPlatform.d.ts +2 -0
- package/dist/bindings/utils/getPlatform.js +15 -0
- package/dist/bindings/utils/getPlatform.js.map +1 -0
- 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.d.ts +6 -0
- package/dist/bindings/utils/lastBuildInfo.js +17 -0
- package/dist/bindings/utils/lastBuildInfo.js.map +1 -0
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.d.ts +2 -0
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.js +22 -0
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.js.map +1 -0
- 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/resolveActualBindingBinaryPath.d.ts +1 -0
- package/dist/bindings/utils/resolveActualBindingBinaryPath.js +18 -0
- package/dist/bindings/utils/resolveActualBindingBinaryPath.js.map +1 -0
- package/dist/bindings/utils/resolveCustomCmakeOptions.d.ts +1 -0
- package/dist/bindings/utils/resolveCustomCmakeOptions.js +43 -0
- package/dist/bindings/utils/resolveCustomCmakeOptions.js.map +1 -0
- package/dist/bindings/utils/testBindingBinary.d.ts +2 -0
- package/dist/bindings/utils/testBindingBinary.js +269 -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 +17 -0
- package/dist/chatWrappers/AlpacaChatWrapper.js +33 -0
- package/dist/chatWrappers/AlpacaChatWrapper.js.map +1 -0
- package/dist/chatWrappers/ChatMLChatWrapper.d.ts +6 -0
- package/dist/chatWrappers/ChatMLChatWrapper.js +85 -0
- package/dist/chatWrappers/ChatMLChatWrapper.js.map +1 -0
- package/dist/chatWrappers/DeepSeekChatWrapper.d.ts +37 -0
- package/dist/chatWrappers/DeepSeekChatWrapper.js +294 -0
- package/dist/chatWrappers/DeepSeekChatWrapper.js.map +1 -0
- package/dist/chatWrappers/EmptyChatWrapper.d.ts +4 -0
- package/dist/chatWrappers/EmptyChatWrapper.js +5 -0
- package/dist/chatWrappers/EmptyChatWrapper.js.map +1 -0
- package/dist/chatWrappers/FalconChatWrapper.d.ts +19 -0
- package/dist/chatWrappers/FalconChatWrapper.js +126 -0
- package/dist/chatWrappers/FalconChatWrapper.js.map +1 -0
- package/dist/chatWrappers/FunctionaryChatWrapper.d.ts +17 -0
- package/dist/chatWrappers/FunctionaryChatWrapper.js +622 -0
- package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -0
- 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 +19 -0
- package/dist/chatWrappers/GeneralChatWrapper.js +140 -0
- package/dist/chatWrappers/GeneralChatWrapper.js.map +1 -0
- package/dist/chatWrappers/HarmonyChatWrapper.d.ts +78 -0
- package/dist/chatWrappers/HarmonyChatWrapper.js +539 -0
- package/dist/chatWrappers/HarmonyChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama2ChatWrapper.d.ts +12 -0
- package/dist/chatWrappers/Llama2ChatWrapper.js +95 -0
- 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 +32 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.js +290 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.d.ts +35 -0
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.js +264 -0
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.js.map +1 -0
- package/dist/chatWrappers/MistralChatWrapper.d.ts +16 -0
- package/dist/chatWrappers/MistralChatWrapper.js +180 -0
- package/dist/chatWrappers/MistralChatWrapper.js.map +1 -0
- package/dist/chatWrappers/QwenChatWrapper.d.ts +36 -0
- package/dist/chatWrappers/QwenChatWrapper.js +344 -0
- package/dist/chatWrappers/QwenChatWrapper.js.map +1 -0
- package/dist/chatWrappers/SeedChatWrapper.d.ts +25 -0
- package/dist/chatWrappers/SeedChatWrapper.js +183 -0
- package/dist/chatWrappers/SeedChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.d.ts +138 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js +665 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.d.ts +76 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.js +212 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/utils/UniqueIdGenerator.d.ts +7 -0
- package/dist/chatWrappers/generic/utils/UniqueIdGenerator.js +30 -0
- package/dist/chatWrappers/generic/utils/UniqueIdGenerator.js.map +1 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.d.ts +24 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js +45 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js.map +1 -0
- package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.d.ts +25 -0
- package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.js +690 -0
- package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.js.map +1 -0
- package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.d.ts +2 -0
- package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.js +66 -0
- package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.js.map +1 -0
- package/dist/chatWrappers/generic/utils/getFirstValidResult.d.ts +6 -0
- package/dist/chatWrappers/generic/utils/getFirstValidResult.js +19 -0
- package/dist/chatWrappers/generic/utils/getFirstValidResult.js.map +1 -0
- package/dist/chatWrappers/generic/utils/squashChatHistoryItems.d.ts +2 -0
- package/dist/chatWrappers/generic/utils/squashChatHistoryItems.js +35 -0
- package/dist/chatWrappers/generic/utils/squashChatHistoryItems.js.map +1 -0
- package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.d.ts +22 -0
- package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.js +28 -0
- package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.js.map +1 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.d.ts +76 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js +177 -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/getModelLinageNames.d.ts +2 -0
- package/dist/chatWrappers/utils/getModelLinageNames.js +18 -0
- package/dist/chatWrappers/utils/getModelLinageNames.js.map +1 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.d.ts +4 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js +394 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js.map +1 -0
- package/dist/chatWrappers/utils/isLlama3_2LightweightModel.d.ts +2 -0
- package/dist/chatWrappers/utils/isLlama3_2LightweightModel.js +9 -0
- package/dist/chatWrappers/utils/isLlama3_2LightweightModel.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 +148 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js +325 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js.map +1 -0
- package/dist/cli/cli.d.ts +2 -0
- package/dist/cli/cli.js +45 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/commands/ChatCommand.d.ts +59 -0
- package/dist/cli/commands/ChatCommand.js +856 -0
- package/dist/cli/commands/ChatCommand.js.map +1 -0
- package/dist/cli/commands/CompleteCommand.d.ts +47 -0
- package/dist/cli/commands/CompleteCommand.js +658 -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 +55 -0
- package/dist/cli/commands/DebugCommand.js.map +1 -0
- package/dist/cli/commands/InfillCommand.d.ts +49 -0
- package/dist/cli/commands/InfillCommand.js +693 -0
- package/dist/cli/commands/InfillCommand.js.map +1 -0
- package/dist/cli/commands/InitCommand.d.ts +12 -0
- package/dist/cli/commands/InitCommand.js +230 -0
- package/dist/cli/commands/InitCommand.js.map +1 -0
- package/dist/cli/commands/OnPostInstallCommand.d.ts +4 -0
- package/dist/cli/commands/OnPostInstallCommand.js +62 -0
- package/dist/cli/commands/OnPostInstallCommand.js.map +1 -0
- 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 +17 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js +275 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.d.ts +13 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +230 -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 +296 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.d.ts +26 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js +869 -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/source/commands/ClearCommand.d.ts +7 -0
- package/dist/cli/commands/source/commands/ClearCommand.js +54 -0
- package/dist/cli/commands/source/commands/ClearCommand.js.map +1 -0
- package/dist/cli/commands/source/commands/DownloadCommand.d.ts +16 -0
- package/dist/cli/commands/source/commands/DownloadCommand.js +219 -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 +428 -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 +24 -0
- package/dist/cli/utils/ConsoleTable.js +90 -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 +81 -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 +13 -0
- package/dist/cli/utils/interactivelyAskForModel.js +485 -0
- package/dist/cli/utils/interactivelyAskForModel.js.map +1 -0
- package/dist/cli/utils/isRunningUnderRosetta.d.ts +1 -0
- package/dist/cli/utils/isRunningUnderRosetta.js +20 -0
- package/dist/cli/utils/isRunningUnderRosetta.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/packageJsonConfig.d.ts +6 -0
- package/dist/cli/utils/packageJsonConfig.js +51 -0
- package/dist/cli/utils/packageJsonConfig.js.map +1 -0
- package/dist/cli/utils/packageManager.d.ts +1 -0
- package/dist/cli/utils/packageManager.js +15 -0
- package/dist/cli/utils/packageManager.js.map +1 -0
- package/dist/cli/utils/parseXtcArg.d.ts +5 -0
- package/dist/cli/utils/parseXtcArg.js +16 -0
- package/dist/cli/utils/parseXtcArg.js.map +1 -0
- package/dist/cli/utils/printCommonInfoLines.d.ts +12 -0
- package/dist/cli/utils/printCommonInfoLines.js +163 -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/printModelDestination.d.ts +2 -0
- package/dist/cli/utils/printModelDestination.js +11 -0
- package/dist/cli/utils/printModelDestination.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 +19 -0
- package/dist/cli/utils/resolveCommandGgufPath.js +123 -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 +14 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js +12 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js.map +1 -0
- package/dist/cli/utils/resolveNpmrcConfig.d.ts +18 -0
- package/dist/cli/utils/resolveNpmrcConfig.js +129 -0
- package/dist/cli/utils/resolveNpmrcConfig.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/toBytes.d.ts +1 -0
- package/dist/cli/utils/toBytes.js +5 -0
- package/dist/cli/utils/toBytes.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 +6 -0
- package/dist/commands.js +9 -0
- package/dist/commands.js.map +1 -0
- package/dist/config.d.ts +79 -0
- package/dist/config.js +127 -0
- package/dist/config.js.map +1 -0
- 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 +500 -0
- package/dist/evaluator/LlamaChat/LlamaChat.js +2696 -0
- package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -0
- 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.d.ts +16 -0
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +260 -0
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -0
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +520 -0
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +628 -0
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.d.ts +45 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js +191 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js.map +1 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.d.ts +15 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js +16 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js.map +1 -0
- package/dist/evaluator/LlamaCompletion.d.ts +219 -0
- package/dist/evaluator/LlamaCompletion.js +498 -0
- package/dist/evaluator/LlamaCompletion.js.map +1 -0
- package/dist/evaluator/LlamaContext/LlamaContext.d.ts +336 -0
- package/dist/evaluator/LlamaContext/LlamaContext.js +1919 -0
- package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -0
- package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.d.ts +27 -0
- package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.js +130 -0
- package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.js.map +1 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.d.ts +1 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.js +39 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.js.map +1 -0
- package/dist/evaluator/LlamaContext/TokenPredictor.d.ts +55 -0
- package/dist/evaluator/LlamaContext/TokenPredictor.js +20 -0
- package/dist/evaluator/LlamaContext/TokenPredictor.js.map +1 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.d.ts +56 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.js +266 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.js.map +1 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.d.ts +58 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.js +138 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.js.map +1 -0
- package/dist/evaluator/LlamaContext/types.d.ts +602 -0
- package/dist/evaluator/LlamaContext/types.js +2 -0
- package/dist/evaluator/LlamaContext/types.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.d.ts +5 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js +16 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.d.ts +5 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js +42 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/padSafeContextSize.d.ts +1 -0
- package/dist/evaluator/LlamaContext/utils/padSafeContextSize.js +18 -0
- package/dist/evaluator/LlamaContext/utils/padSafeContextSize.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.d.ts +2 -0
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.js +13 -0
- 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 +52 -0
- package/dist/evaluator/LlamaEmbeddingContext.js +86 -0
- package/dist/evaluator/LlamaEmbeddingContext.js.map +1 -0
- package/dist/evaluator/LlamaGrammar.d.ts +39 -0
- package/dist/evaluator/LlamaGrammar.js +72 -0
- package/dist/evaluator/LlamaGrammar.js.map +1 -0
- package/dist/evaluator/LlamaGrammarEvaluationState.d.ts +19 -0
- package/dist/evaluator/LlamaGrammarEvaluationState.js +29 -0
- package/dist/evaluator/LlamaGrammarEvaluationState.js.map +1 -0
- package/dist/evaluator/LlamaJsonSchemaGrammar.d.ts +17 -0
- package/dist/evaluator/LlamaJsonSchemaGrammar.js +35 -0
- package/dist/evaluator/LlamaJsonSchemaGrammar.js.map +1 -0
- package/dist/evaluator/LlamaModel/LlamaModel.d.ts +344 -0
- package/dist/evaluator/LlamaModel/LlamaModel.js +853 -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/LlamaRankingContext.d.ts +91 -0
- package/dist/evaluator/LlamaRankingContext.js +178 -0
- package/dist/evaluator/LlamaRankingContext.js.map +1 -0
- package/dist/evaluator/TokenBias.d.ts +37 -0
- package/dist/evaluator/TokenBias.js +68 -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/evaluator/utils/chunkDocument.d.ts +86 -0
- package/dist/evaluator/utils/chunkDocument.js +212 -0
- package/dist/evaluator/utils/chunkDocument.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 +106 -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 +28 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js +94 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js.map +1 -0
- package/dist/gguf/insights/GgufInsights.d.ts +78 -0
- package/dist/gguf/insights/GgufInsights.js +854 -0
- package/dist/gguf/insights/GgufInsights.js.map +1 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.d.ts +203 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js +284 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js.map +1 -0
- package/dist/gguf/insights/GgufInsightsTokens.d.ts +5 -0
- package/dist/gguf/insights/GgufInsightsTokens.js +40 -0
- package/dist/gguf/insights/GgufInsightsTokens.js.map +1 -0
- package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.d.ts +5 -0
- package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.js +7 -0
- package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.js.map +1 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.d.ts +33 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js +117 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js.map +1 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.d.ts +20 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js +251 -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 +184 -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 +54 -0
- package/dist/gguf/readGgufFileInfo.js +82 -0
- package/dist/gguf/readGgufFileInfo.js.map +1 -0
- package/dist/gguf/types/GgufFileInfoTypes.d.ts +85 -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 +480 -0
- package/dist/gguf/types/GgufMetadataTypes.js +194 -0
- package/dist/gguf/types/GgufMetadataTypes.js.map +1 -0
- package/dist/gguf/types/GgufTensorInfoTypes.d.ts +63 -0
- package/dist/gguf/types/GgufTensorInfoTypes.js +54 -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/getGgufMetadataKeyValue.d.ts +1 -0
- package/dist/gguf/utils/getGgufMetadataKeyValue.js +27 -0
- package/dist/gguf/utils/getGgufMetadataKeyValue.js.map +1 -0
- package/dist/gguf/utils/ggufQuantNames.d.ts +2 -0
- package/dist/gguf/utils/ggufQuantNames.js +42 -0
- package/dist/gguf/utils/ggufQuantNames.js.map +1 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.d.ts +2 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.js +18 -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 +38 -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 +64 -0
- package/dist/gguf/utils/resolveSplitGgufParts.js.map +1 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/dist/state.d.ts +6 -0
- package/dist/state.js +22 -0
- package/dist/state.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +408 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- 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 +92 -0
- package/dist/utils/LlamaText.js +527 -0
- package/dist/utils/LlamaText.js.map +1 -0
- 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/OpenAIFormat.d.ts +177 -0
- package/dist/utils/OpenAIFormat.js +488 -0
- package/dist/utils/OpenAIFormat.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.d.ts +9 -0
- package/dist/utils/ReplHistory.js +72 -0
- package/dist/utils/ReplHistory.js.map +1 -0
- package/dist/utils/StopGenerationDetector.d.ts +47 -0
- package/dist/utils/StopGenerationDetector.js +291 -0
- package/dist/utils/StopGenerationDetector.js.map +1 -0
- 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 +38 -0
- package/dist/utils/TokenStreamRegulator.js +200 -0
- package/dist/utils/TokenStreamRegulator.js.map +1 -0
- 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 +6 -0
- package/dist/utils/appendUserMessageToChatHistory.js +22 -0
- package/dist/utils/appendUserMessageToChatHistory.js.map +1 -0
- package/dist/utils/clearTempFolder.d.ts +1 -0
- package/dist/utils/clearTempFolder.js +16 -0
- package/dist/utils/clearTempFolder.js.map +1 -0
- package/dist/utils/cmake.d.ts +10 -0
- package/dist/utils/cmake.js +146 -0
- package/dist/utils/cmake.js.map +1 -0
- package/dist/utils/compareTokens.d.ts +2 -0
- package/dist/utils/compareTokens.js +4 -0
- package/dist/utils/compareTokens.js.map +1 -0
- package/dist/utils/createModelDownloader.d.ts +262 -0
- package/dist/utils/createModelDownloader.js +486 -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 +20 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js +85 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js.map +1 -0
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.d.ts +19 -0
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.js +60 -0
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.js.map +1 -0
- package/dist/utils/gbnfJson/GbnfTerminal.d.ts +11 -0
- package/dist/utils/gbnfJson/GbnfTerminal.js +54 -0
- package/dist/utils/gbnfJson/GbnfTerminal.js.map +1 -0
- 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/GbnfAnyJson.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfAnyJson.js +53 -0
- package/dist/utils/gbnfJson/terminals/GbnfAnyJson.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.d.ts +18 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.js +83 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.d.ts +7 -0
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.js +22 -0
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.d.ts +7 -0
- package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.js +17 -0
- package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.d.ts +11 -0
- package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.js +28 -0
- package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfFormatString.d.ts +11 -0
- package/dist/utils/gbnfJson/terminals/GbnfFormatString.js +90 -0
- package/dist/utils/gbnfJson/terminals/GbnfFormatString.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.js +23 -0
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.d.ts +5 -0
- package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.js +24 -0
- package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfNull.d.ts +5 -0
- package/dist/utils/gbnfJson/terminals/GbnfNull.js +11 -0
- package/dist/utils/gbnfJson/terminals/GbnfNull.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumber.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumber.js +22 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumber.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js +21 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.d.ts +28 -0
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js +88 -0
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfOr.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfOr.js +34 -0
- package/dist/utils/gbnfJson/terminals/GbnfOr.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfRef.d.ts +15 -0
- package/dist/utils/gbnfJson/terminals/GbnfRef.js +34 -0
- package/dist/utils/gbnfJson/terminals/GbnfRef.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.d.ts +15 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js +86 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfString.d.ts +12 -0
- package/dist/utils/gbnfJson/terminals/GbnfString.js +43 -0
- package/dist/utils/gbnfJson/terminals/GbnfString.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.d.ts +8 -0
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.js +26 -0
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.d.ts +6 -0
- package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js +21 -0
- package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.d.ts +13 -0
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js +67 -0
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/gbnfConsts.d.ts +30 -0
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js +72 -0
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js.map +1 -0
- package/dist/utils/gbnfJson/types.d.ts +213 -0
- package/dist/utils/gbnfJson/types.js +30 -0
- package/dist/utils/gbnfJson/types.js.map +1 -0
- 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/defsScope.d.ts +7 -0
- package/dist/utils/gbnfJson/utils/defsScope.js +17 -0
- package/dist/utils/gbnfJson/utils/defsScope.js.map +1 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.d.ts +5 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js +143 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js.map +1 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForLiteral.d.ts +5 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForLiteral.js +16 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForLiteral.js.map +1 -0
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.d.ts +8 -0
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js +242 -0
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js.map +1 -0
- package/dist/utils/getBuildDefaults.d.ts +5 -0
- package/dist/utils/getBuildDefaults.js +9 -0
- package/dist/utils/getBuildDefaults.js.map +1 -0
- package/dist/utils/getChatWrapperSegmentDefinition.d.ts +2 -0
- package/dist/utils/getChatWrapperSegmentDefinition.js +9 -0
- package/dist/utils/getChatWrapperSegmentDefinition.js.map +1 -0
- package/dist/utils/getConsoleLogPrefix.d.ts +1 -0
- package/dist/utils/getConsoleLogPrefix.js +10 -0
- package/dist/utils/getConsoleLogPrefix.js.map +1 -0
- package/dist/utils/getFirstWritableDir.d.ts +8 -0
- package/dist/utils/getFirstWritableDir.js +60 -0
- package/dist/utils/getFirstWritableDir.js.map +1 -0
- package/dist/utils/getGrammarsFolder.d.ts +2 -0
- package/dist/utils/getGrammarsFolder.js +19 -0
- package/dist/utils/getGrammarsFolder.js.map +1 -0
- package/dist/utils/getLlamaClasses.d.ts +9 -0
- package/dist/utils/getLlamaClasses.js +14 -0
- package/dist/utils/getLlamaClasses.js.map +1 -0
- package/dist/utils/getModuleVersion.d.ts +1 -0
- package/dist/utils/getModuleVersion.js +13 -0
- package/dist/utils/getModuleVersion.js.map +1 -0
- 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/getTempDir.d.ts +10 -0
- package/dist/utils/getTempDir.js +121 -0
- package/dist/utils/getTempDir.js.map +1 -0
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.d.ts +2 -0
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js +205 -0
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js.map +1 -0
- package/dist/utils/gitReleaseBundles.d.ts +2 -0
- package/dist/utils/gitReleaseBundles.js +132 -0
- package/dist/utils/gitReleaseBundles.js.map +1 -0
- package/dist/utils/hashString.d.ts +1 -0
- package/dist/utils/hashString.js +8 -0
- package/dist/utils/hashString.js.map +1 -0
- package/dist/utils/includesText.d.ts +1 -0
- package/dist/utils/includesText.js +12 -0
- package/dist/utils/includesText.js.map +1 -0
- package/dist/utils/isLockfileActive.d.ts +4 -0
- package/dist/utils/isLockfileActive.js +12 -0
- package/dist/utils/isLockfileActive.js.map +1 -0
- 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/modelDownloadEndpoints.d.ts +13 -0
- package/dist/utils/modelDownloadEndpoints.js +27 -0
- package/dist/utils/modelDownloadEndpoints.js.map +1 -0
- package/dist/utils/modelFileAccessTokens.d.ts +5 -0
- package/dist/utils/modelFileAccessTokens.js +41 -0
- package/dist/utils/modelFileAccessTokens.js.map +1 -0
- package/dist/utils/optionsMatrix.d.ts +58 -0
- package/dist/utils/optionsMatrix.js +97 -0
- package/dist/utils/optionsMatrix.js.map +1 -0
- package/dist/utils/parseModelFileName.d.ts +15 -0
- package/dist/utils/parseModelFileName.js +132 -0
- package/dist/utils/parseModelFileName.js.map +1 -0
- package/dist/utils/parseModelUri.d.ts +40 -0
- package/dist/utils/parseModelUri.js +346 -0
- package/dist/utils/parseModelUri.js.map +1 -0
- 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 -0
- package/dist/utils/prettyPrintObject.js +84 -0
- package/dist/utils/prettyPrintObject.js.map +1 -0
- 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 -0
- package/dist/utils/removeNullFields.js +17 -0
- package/dist/utils/removeNullFields.js.map +1 -0
- package/dist/utils/resolveGithubRelease.d.ts +2 -0
- package/dist/utils/resolveGithubRelease.js +77 -0
- package/dist/utils/resolveGithubRelease.js.map +1 -0
- 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/resolveModelDestination.d.ts +16 -0
- package/dist/utils/resolveModelDestination.js +54 -0
- package/dist/utils/resolveModelDestination.js.map +1 -0
- package/dist/utils/resolveModelFile.d.ts +142 -0
- package/dist/utils/resolveModelFile.js +201 -0
- package/dist/utils/resolveModelFile.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/signalSleep.d.ts +1 -0
- package/dist/utils/signalSleep.js +20 -0
- package/dist/utils/signalSleep.js.map +1 -0
- package/dist/utils/spawnCommand.d.ts +11 -0
- package/dist/utils/spawnCommand.js +89 -0
- package/dist/utils/spawnCommand.js.map +1 -0
- package/dist/utils/tokenizeInput.d.ts +3 -0
- package/dist/utils/tokenizeInput.js +14 -0
- package/dist/utils/tokenizeInput.js.map +1 -0
- package/dist/utils/tokenizerUtils.d.ts +12 -0
- package/dist/utils/tokenizerUtils.js +32 -0
- package/dist/utils/tokenizerUtils.js.map +1 -0
- package/dist/utils/transformPromisable.d.ts +54 -0
- package/dist/utils/transformPromisable.js +95 -0
- package/dist/utils/transformPromisable.js.map +1 -0
- package/dist/utils/truncateTextAndRoundToWords.d.ts +11 -0
- package/dist/utils/truncateTextAndRoundToWords.js +110 -0
- package/dist/utils/truncateTextAndRoundToWords.js.map +1 -0
- package/dist/utils/utilTypes.d.ts +18 -0
- package/dist/utils/utilTypes.js +2 -0
- package/dist/utils/utilTypes.js.map +1 -0
- package/dist/utils/waitForLockfileRelease.d.ts +5 -0
- package/dist/utils/waitForLockfileRelease.js +19 -0
- package/dist/utils/waitForLockfileRelease.js.map +1 -0
- package/dist/utils/withLockfile.d.ts +7 -0
- package/dist/utils/withLockfile.js +44 -0
- package/dist/utils/withLockfile.js.map +1 -0
- package/dist/utils/withOra.d.ts +7 -0
- package/dist/utils/withOra.js +37 -0
- package/dist/utils/withOra.js.map +1 -0
- 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.d.ts +6 -0
- package/dist/utils/withStatusLogs.js +25 -0
- package/dist/utils/withStatusLogs.js.map +1 -0
- package/dist/utils/wrapAbortSignal.d.ts +1 -0
- package/dist/utils/wrapAbortSignal.js +14 -0
- package/dist/utils/wrapAbortSignal.js.map +1 -0
- package/llama/.clang-format +46 -0
- package/llama/CMakeLists.txt +141 -0
- package/llama/addon/AddonContext.cpp +1181 -0
- package/llama/addon/AddonContext.h +85 -0
- package/llama/addon/AddonGrammar.cpp +92 -0
- package/llama/addon/AddonGrammar.h +22 -0
- package/llama/addon/AddonGrammarEvaluationState.cpp +36 -0
- package/llama/addon/AddonGrammarEvaluationState.h +17 -0
- package/llama/addon/AddonModel.cpp +691 -0
- package/llama/addon/AddonModel.h +64 -0
- package/llama/addon/AddonModelData.cpp +25 -0
- package/llama/addon/AddonModelData.h +15 -0
- package/llama/addon/AddonModelLora.cpp +103 -0
- package/llama/addon/AddonModelLora.h +28 -0
- package/llama/addon/AddonSampler.cpp +669 -0
- package/llama/addon/AddonSampler.h +75 -0
- package/llama/addon/RingBuffer.h +109 -0
- package/llama/addon/addon.cpp +330 -0
- package/llama/addon/addonGlobals.cpp +22 -0
- package/llama/addon/addonGlobals.h +12 -0
- package/llama/addon/globals/addonLog.cpp +143 -0
- package/llama/addon/globals/addonLog.h +24 -0
- package/llama/addon/globals/addonProgress.cpp +15 -0
- package/llama/addon/globals/addonProgress.h +15 -0
- package/llama/addon/globals/getGpuInfo.cpp +146 -0
- package/llama/addon/globals/getGpuInfo.h +11 -0
- package/llama/addon/globals/getMemoryInfo.cpp +63 -0
- package/llama/addon/globals/getMemoryInfo.h +4 -0
- package/llama/addon/globals/getSwapInfo.cpp +69 -0
- package/llama/addon/globals/getSwapInfo.h +4 -0
- package/llama/binariesGithubRelease.json +3 -0
- package/llama/cmake/addVariantSuffix.cmake +21 -0
- package/llama/cmake/win32.ensureNinjaPath.cmake +68 -0
- package/llama/cmake/win32.ensureNodeLib.cmake +34 -0
- package/llama/cmake/win32.llvmApplyGnuModeAdaptations.cmake +12 -0
- package/llama/cmake/win32.llvmEnsureCmakeAr.cmake +37 -0
- package/llama/cmake/win32.llvmUseGnuModeCompilers.cmake +87 -0
- package/llama/cmake/win32.programFilesPaths.cmake +35 -0
- package/llama/gpuInfo/vulkan-gpu-info.cpp +207 -0
- package/llama/gpuInfo/vulkan-gpu-info.h +9 -0
- package/llama/package.json +5 -0
- package/llama/profiles/llvm.win32.host-arm64.target-arm64.cmake +14 -0
- package/llama/profiles/llvm.win32.host-x64.target-arm64.cmake +14 -0
- package/llama/profiles/llvm.win32.host-x64.target-x64.cmake +14 -0
- package/llama/toolchains/darwin.host-x64.target-arm64.cmake +8 -0
- package/llama/toolchains/linux.host-arm64.target-x64.cmake +5 -0
- package/llama/toolchains/linux.host-x64.target-arm64.cmake +5 -0
- package/llama/toolchains/linux.host-x64.target-arm71.cmake +5 -0
- package/llama/toolchains/llvm.win32.host-x64.target-x64.cmake +20 -0
- package/llama/toolchains/win32.host-arm64.target-arm64.cmake +21 -0
- package/llama/toolchains/win32.host-x64.target-arm64.cmake +21 -0
- package/llama/xpack/package.json +10 -0
- package/package.json +241 -0
- package/templates/README.md +6 -0
- package/templates/package.json +10 -0
- package/templates/packed/electron-typescript-react.json +1 -0
- package/templates/packed/node-typescript.json +1 -0
|
@@ -0,0 +1,854 @@
|
|
|
1
|
+
import { getLlamaWithoutBackend } from "../../bindings/utils/getLlamaWithoutBackend.js";
|
|
2
|
+
import { getDefaultContextBatchSize, getDefaultContextSequences } from "../../evaluator/LlamaContext/LlamaContext.js";
|
|
3
|
+
import { GgmlType } from "../types/GgufTensorInfoTypes.js";
|
|
4
|
+
import { GgufArchitectureType } from "../types/GgufMetadataTypes.js";
|
|
5
|
+
import { getReadablePath } from "../../cli/utils/getReadablePath.js";
|
|
6
|
+
import { padSafeContextSize } from "../../evaluator/LlamaContext/utils/padSafeContextSize.js";
|
|
7
|
+
import { GgufInsightsConfigurationResolver } from "./GgufInsightsConfigurationResolver.js";
|
|
8
|
+
import { GgufInsightsTokens } from "./GgufInsightsTokens.js";
|
|
9
|
+
export class GgufInsights {
|
|
10
|
+
/** @internal */ _llama;
|
|
11
|
+
/** @internal */ _modelSize;
|
|
12
|
+
/** @internal */ _totalFileLayers = null;
|
|
13
|
+
/** @internal */ _supportsRanking;
|
|
14
|
+
/** @internal */ _dominantTensorType;
|
|
15
|
+
/** @internal */ _ggufFileInfo;
|
|
16
|
+
/** @internal */ _configurationResolver;
|
|
17
|
+
/** @internal */ _tokens;
|
|
18
|
+
constructor(ggufFileInfo, llama) {
|
|
19
|
+
this._llama = llama;
|
|
20
|
+
this._ggufFileInfo = ggufFileInfo;
|
|
21
|
+
this._modelSize = calculateTensorsSize(ggufFileInfo.fullTensorInfo ?? [], llama, true, true);
|
|
22
|
+
this._configurationResolver = GgufInsightsConfigurationResolver._create(this);
|
|
23
|
+
this._tokens = GgufInsightsTokens._create(this);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get warnings about the model file that would affect its usage.
|
|
27
|
+
*
|
|
28
|
+
* Most of these warnings are also generated by `llama.cpp`
|
|
29
|
+
*/
|
|
30
|
+
getWarnings(modelFilePath) {
|
|
31
|
+
const warnings = [];
|
|
32
|
+
const modelFilePathText = (modelFilePath != null && modelFilePath !== "")
|
|
33
|
+
? ` ("${getReadablePath(modelFilePath)}")`
|
|
34
|
+
: "";
|
|
35
|
+
if (this._ggufFileInfo?.metadata?.tokenizer?.ggml?.model === "gpt2" &&
|
|
36
|
+
this._ggufFileInfo?.metadata?.tokenizer?.ggml?.model == null) {
|
|
37
|
+
// equivalent to the warning in `llama.cpp` under `llm_load_vocab`: "missing pre-tokenizer type, using: 'default'"
|
|
38
|
+
warnings.push(`This model file${modelFilePathText} is missing a pre-tokenizer configuration. ` +
|
|
39
|
+
"This may cause incorrect tokenization and thus degrade the generation quality. " +
|
|
40
|
+
"Consider using a newer model or regenerating this GGUF model file");
|
|
41
|
+
}
|
|
42
|
+
return warnings;
|
|
43
|
+
}
|
|
44
|
+
get ggufFileInfo() {
|
|
45
|
+
return this._ggufFileInfo;
|
|
46
|
+
}
|
|
47
|
+
get configurationResolver() {
|
|
48
|
+
return this._configurationResolver;
|
|
49
|
+
}
|
|
50
|
+
get tokens() {
|
|
51
|
+
return this._tokens;
|
|
52
|
+
}
|
|
53
|
+
/** The context size the model was trained on */
|
|
54
|
+
get trainContextSize() {
|
|
55
|
+
return this._ggufFileInfo.architectureMetadata.context_length;
|
|
56
|
+
}
|
|
57
|
+
/** The size of an embedding vector the model can produce */
|
|
58
|
+
get embeddingVectorSize() {
|
|
59
|
+
return this._ggufFileInfo.architectureMetadata.embedding_length;
|
|
60
|
+
}
|
|
61
|
+
get totalLayers() {
|
|
62
|
+
const outputLayers = 1;
|
|
63
|
+
return this._getTotalFileLayers() + outputLayers;
|
|
64
|
+
}
|
|
65
|
+
get modelSize() {
|
|
66
|
+
return this._modelSize;
|
|
67
|
+
}
|
|
68
|
+
get flashAttentionSupported() {
|
|
69
|
+
// source: `llama_new_context_with_model` in `llama.cpp`
|
|
70
|
+
if (this._ggufFileInfo.metadata?.general?.architecture === GgufArchitectureType.grok)
|
|
71
|
+
return false;
|
|
72
|
+
else if (this._ggufFileInfo.metadata?.general?.architecture === GgufArchitectureType.gemma2)
|
|
73
|
+
return false;
|
|
74
|
+
else {
|
|
75
|
+
const nHead = this._ggufFileInfo.architectureMetadata?.attention?.head_count ?? 0;
|
|
76
|
+
const nEmbd = this._ggufFileInfo.architectureMetadata?.embedding_length ?? 0;
|
|
77
|
+
const nEmbdHeadK = this._ggufFileInfo.architectureMetadata?.attention?.key_length ?? ((nHead == 0) ? 0 : (nEmbd / nHead));
|
|
78
|
+
const nEmbdHeadV = this._ggufFileInfo.architectureMetadata?.attention?.value_length ?? ((nHead == 0) ? 0 : nEmbd / nHead);
|
|
79
|
+
if (nEmbdHeadK !== nEmbdHeadV)
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
get hasEncoder() {
|
|
85
|
+
switch (this._ggufFileInfo.metadata?.general?.architecture) {
|
|
86
|
+
case GgufArchitectureType.t5:
|
|
87
|
+
case GgufArchitectureType.t5encoder:
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
get hasDecoder() {
|
|
93
|
+
switch (this._ggufFileInfo.metadata?.general?.architecture) {
|
|
94
|
+
case GgufArchitectureType.t5encoder:
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
get isRecurrent() {
|
|
100
|
+
// source: `llm_arch_is_recurrent` in `llama-arch.cpp`
|
|
101
|
+
switch (this._ggufFileInfo.metadata?.general?.architecture) {
|
|
102
|
+
case GgufArchitectureType.mamba:
|
|
103
|
+
case GgufArchitectureType.mamba2:
|
|
104
|
+
case GgufArchitectureType.rwkv6:
|
|
105
|
+
case GgufArchitectureType.rwkv6qwen2:
|
|
106
|
+
case GgufArchitectureType.rwkv7:
|
|
107
|
+
case GgufArchitectureType.arwkv7:
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
get isHybrid() {
|
|
113
|
+
// source: `llm_arch_is_hybrid` in `llama-arch.cpp`
|
|
114
|
+
switch (this._ggufFileInfo.metadata?.general?.architecture) {
|
|
115
|
+
case GgufArchitectureType.jamba:
|
|
116
|
+
case GgufArchitectureType.falconH1:
|
|
117
|
+
case GgufArchitectureType.plamo2:
|
|
118
|
+
case GgufArchitectureType.granitehybrid:
|
|
119
|
+
case GgufArchitectureType.lfm2:
|
|
120
|
+
case GgufArchitectureType.lfm2moe:
|
|
121
|
+
case GgufArchitectureType.nemotronH:
|
|
122
|
+
case GgufArchitectureType.nemotronHMoe:
|
|
123
|
+
case GgufArchitectureType.qwen3next:
|
|
124
|
+
case GgufArchitectureType.kimiLinear:
|
|
125
|
+
case GgufArchitectureType.qwen35:
|
|
126
|
+
case GgufArchitectureType.qwen35moe:
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get the dominant tensor type used in the model file
|
|
133
|
+
*/
|
|
134
|
+
get dominantTensorType() {
|
|
135
|
+
if (this._dominantTensorType == null)
|
|
136
|
+
this._dominantTensorType = getDominantTensorType(this._ggufFileInfo.fullTensorInfo ?? []);
|
|
137
|
+
return this._dominantTensorType;
|
|
138
|
+
}
|
|
139
|
+
get supportsRanking() {
|
|
140
|
+
if (this._supportsRanking != null)
|
|
141
|
+
return this._supportsRanking;
|
|
142
|
+
const layers = this._ggufFileInfo.fullTensorInfo ?? [];
|
|
143
|
+
for (let i = layers.length - 1; i >= 0; i--) {
|
|
144
|
+
const tensor = layers[i];
|
|
145
|
+
if (tensor == null)
|
|
146
|
+
continue;
|
|
147
|
+
if (tensor.name === "cls.weight" || tensor.name === "cls.output.weight") {
|
|
148
|
+
this._supportsRanking = this.tokens.sepToken != null || this.tokens.eosToken != null ||
|
|
149
|
+
isRankingTemplateValid(parseRankingTemplate(this._ggufFileInfo.metadata?.tokenizer?.["chat_template.rerank"]));
|
|
150
|
+
this._supportsRanking &&= !(this.hasEncoder && this.hasDecoder); // encoder-decoder models are not supported
|
|
151
|
+
return this._supportsRanking;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
this._supportsRanking = false;
|
|
155
|
+
return this._supportsRanking;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The size of the SWA (Sliding Window Attention).
|
|
159
|
+
*
|
|
160
|
+
* When `undefined`, the model does not use sliding window attention.
|
|
161
|
+
*/
|
|
162
|
+
get swaSize() {
|
|
163
|
+
const slidingWindow = this._ggufFileInfo?.architectureMetadata?.attention?.sliding_window;
|
|
164
|
+
if (slidingWindow == null || slidingWindow <= 0)
|
|
165
|
+
return undefined;
|
|
166
|
+
const trainContextSize = this.trainContextSize;
|
|
167
|
+
if (trainContextSize != null && slidingWindow >= trainContextSize)
|
|
168
|
+
return undefined;
|
|
169
|
+
return slidingWindow;
|
|
170
|
+
}
|
|
171
|
+
estimateModelResourceRequirements({ gpuLayers, useMmap = this._llama.supportsMmap, gpuSupportsMmap = this._llama.gpuSupportsMmap }) {
|
|
172
|
+
const { cpu, gpu } = this._getTensorResourceSplit(gpuLayers);
|
|
173
|
+
return {
|
|
174
|
+
cpuRam: calculateTensorsSize(cpu, this._llama, false),
|
|
175
|
+
gpuVram: calculateTensorsSize(gpu, this._llama, useMmap && gpuSupportsMmap)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Estimates the memory required to create a context of the given parameters based on the implementation details of `llama.cpp`.
|
|
180
|
+
* The calculation doesn't include a precise estimation of the graph overhead memory, so it uses a rough estimate for that.
|
|
181
|
+
* The estimation for the graph overhead memory will be improved in the future to be more precise, but it's good enough for now.
|
|
182
|
+
*/
|
|
183
|
+
estimateContextResourceRequirements({ contextSize, modelGpuLayers, batchSize, sequences, isEmbeddingContext = false, includeGraphOverhead = true, flashAttention = false, swaFullCache = false, kvCacheKeyType = GgmlType.F16, kvCacheValueType = GgmlType.F16 }) {
|
|
184
|
+
if (sequences == null)
|
|
185
|
+
sequences = getDefaultContextSequences();
|
|
186
|
+
if (batchSize == null)
|
|
187
|
+
batchSize = getDefaultContextBatchSize({ contextSize, sequences });
|
|
188
|
+
const llmData = this._ggufFileInfo.architectureMetadata;
|
|
189
|
+
const tensorInfo = this._ggufFileInfo.fullTensorInfo ?? [];
|
|
190
|
+
const slidingWindow = this.swaSize ?? 0;
|
|
191
|
+
const kvUnified = false;
|
|
192
|
+
const usingSWA = !swaFullCache && slidingWindow > 0 && slidingWindow < contextSize &&
|
|
193
|
+
(this.trainContextSize == null || slidingWindow < this.trainContextSize);
|
|
194
|
+
const swaPattern = getSwaPatternForArchitecture(this._ggufFileInfo.metadata?.general?.architecture, this._ggufFileInfo.architectureMetadata?.attention?.sliding_window_pattern);
|
|
195
|
+
const nonSwaPercent = swaPattern <= 1
|
|
196
|
+
? 1
|
|
197
|
+
: (1 / (swaPattern + (flashAttention ? -0.5 : -1)));
|
|
198
|
+
// source: `llama_kv_cache_unified::get_padding` in `llama-kv-cache.cpp`
|
|
199
|
+
const kvCachePadding = 1;
|
|
200
|
+
const actualContextSize = kvUnified
|
|
201
|
+
? padSafeContextSize(sequences * contextSize, "up")
|
|
202
|
+
: sequences * padSafeContextSize(contextSize, "up");
|
|
203
|
+
const kvSize = usingSWA
|
|
204
|
+
? ((1 - nonSwaPercent) * Math.min(actualContextSize, ggmlPad(sequences * slidingWindow + batchSize, kvCachePadding)) +
|
|
205
|
+
nonSwaPercent * actualContextSize)
|
|
206
|
+
: actualContextSize;
|
|
207
|
+
const totalFileLayers = this._getTotalFileLayers();
|
|
208
|
+
const totalLayersIncludingOutput = totalFileLayers + 1;
|
|
209
|
+
const finalModelGpuLayers = Math.max(0, Math.min(modelGpuLayers ?? totalLayersIncludingOutput, totalLayersIncludingOutput));
|
|
210
|
+
const finalGpuLayers = Math.max(0, Math.min(modelGpuLayers ?? totalFileLayers, totalFileLayers));
|
|
211
|
+
const finalCpuLayers = totalFileLayers - finalGpuLayers;
|
|
212
|
+
const usingGpu = finalModelGpuLayers !== 0;
|
|
213
|
+
const { gpuKVCacheSize, cpuKVCacheSize, gpuRecurrentStateSize, cpuRecurrentStateSize } = this._estimateContextCacheMemorySplitInBytes({
|
|
214
|
+
kvSize,
|
|
215
|
+
sequences,
|
|
216
|
+
totalFileLayers,
|
|
217
|
+
finalModelGpuLayers,
|
|
218
|
+
usingGpu,
|
|
219
|
+
kvCacheKeyType,
|
|
220
|
+
kvCacheValueType
|
|
221
|
+
});
|
|
222
|
+
const vocabularySize = llmData.vocab_size ?? this._ggufFileInfo.metadata.tokenizer?.ggml?.tokens?.length ?? 0;
|
|
223
|
+
const embeddingSize = llmData.embedding_length ?? 0;
|
|
224
|
+
const floatBytes = 4; // sizeof(float)
|
|
225
|
+
const int32TBytes = 4; // sizeof(int32_t)
|
|
226
|
+
const estimateOutput = (nOutputs) => {
|
|
227
|
+
// source: `llama_context::output_reserve` in `llama-context.cpp`
|
|
228
|
+
const nOutputsMax = Math.max(batchSize, nOutputs);
|
|
229
|
+
const isT5 = this._ggufFileInfo.metadata.general?.architecture === GgufArchitectureType.t5;
|
|
230
|
+
const hasLogits = isT5 || !isEmbeddingContext;
|
|
231
|
+
const hasEmbd = isT5 || isEmbeddingContext;
|
|
232
|
+
const logitsSize = hasLogits
|
|
233
|
+
? (vocabularySize * nOutputsMax)
|
|
234
|
+
: 0;
|
|
235
|
+
const embdSize = hasEmbd
|
|
236
|
+
? (embeddingSize * nOutputsMax)
|
|
237
|
+
: 0;
|
|
238
|
+
const outputBufferSize = (logitsSize + embdSize) * floatBytes;
|
|
239
|
+
const outputIdsArr = int32TBytes * batchSize;
|
|
240
|
+
return outputBufferSize + outputIdsArr;
|
|
241
|
+
};
|
|
242
|
+
const estimateGraphOverheadMemory = () => {
|
|
243
|
+
const s1MB = Math.pow(1024, 2);
|
|
244
|
+
const tensorInfo = this._ggufFileInfo.fullTensorInfo ?? [];
|
|
245
|
+
const expertCount = llmData?.expert_count ?? 0;
|
|
246
|
+
const headCount = llmData?.attention?.head_count ?? 0;
|
|
247
|
+
const embeddingLength = llmData?.embedding_length ?? 0;
|
|
248
|
+
let defaultCalculationAdjustment = 0;
|
|
249
|
+
if (batchSize == null)
|
|
250
|
+
return 0;
|
|
251
|
+
if (this._ggufFileInfo.metadata.general?.architecture === GgufArchitectureType.llama) {
|
|
252
|
+
if (expertCount > 0) {
|
|
253
|
+
const expertsUsedCount = this._ggufFileInfo.architectureMetadata.expert_used_count ?? 2;
|
|
254
|
+
return int32TBytes * batchSize * (((expertsUsedCount + 1) * embeddingLength) + (kvSize * headCount));
|
|
255
|
+
}
|
|
256
|
+
return int32TBytes * batchSize * (embeddingLength + (kvSize * headCount));
|
|
257
|
+
}
|
|
258
|
+
else if (this._ggufFileInfo.metadata.general?.architecture === GgufArchitectureType.qwen2) {
|
|
259
|
+
if (modelGpuLayers === this.totalLayers) {
|
|
260
|
+
defaultCalculationAdjustment -= (s1MB * 340) * (this.trainContextSize == null
|
|
261
|
+
? 1
|
|
262
|
+
: kvSize / this.trainContextSize);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
defaultCalculationAdjustment -= (s1MB * 250) + ((s1MB * 50) * (this.trainContextSize == null
|
|
266
|
+
? 1
|
|
267
|
+
: kvSize / this.trainContextSize));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
else if (this._ggufFileInfo.metadata.general?.architecture === GgufArchitectureType.gemma) {
|
|
271
|
+
// only works properly when all layers are on the GPU, which is why it's commented out:
|
|
272
|
+
// return int32TBytes * batchSize * ((llmData.embedding_length ?? 0));
|
|
273
|
+
if (modelGpuLayers === this.totalLayers) {
|
|
274
|
+
defaultCalculationAdjustment += (s1MB * 40) - ((s1MB * 270) * (this.trainContextSize == null
|
|
275
|
+
? 1
|
|
276
|
+
: kvSize / this.trainContextSize));
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
defaultCalculationAdjustment += -(s1MB * 550) + ((s1MB * 150) * (this.trainContextSize == null
|
|
280
|
+
? 1
|
|
281
|
+
: Math.max(0, (1 - (kvSize / this.trainContextSize)))));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else if (this._ggufFileInfo.metadata.general?.architecture === GgufArchitectureType.stablelm) {
|
|
285
|
+
const headCount = this._ggufFileInfo.architectureMetadata.attention?.head_count ?? 0;
|
|
286
|
+
return (int32TBytes * batchSize * kvSize * headCount) - (50 * s1MB);
|
|
287
|
+
// if (modelGpuLayers === this.totalLayers) {
|
|
288
|
+
// defaultCalculationAdjustment += -(s1MB * 20) + (
|
|
289
|
+
// (s1MB * 250) * (
|
|
290
|
+
// this.trainContextSize == null
|
|
291
|
+
// ? 1
|
|
292
|
+
// : kvSize / this.trainContextSize
|
|
293
|
+
// )
|
|
294
|
+
// );
|
|
295
|
+
// } else {
|
|
296
|
+
// defaultCalculationAdjustment += -(s1MB * 40) + (
|
|
297
|
+
// (s1MB * 300) * (
|
|
298
|
+
// this.trainContextSize == null
|
|
299
|
+
// ? 1
|
|
300
|
+
// : kvSize / this.trainContextSize
|
|
301
|
+
// )
|
|
302
|
+
// );
|
|
303
|
+
// }
|
|
304
|
+
}
|
|
305
|
+
else if (this._ggufFileInfo.metadata.general?.architecture === GgufArchitectureType.qwen3) {
|
|
306
|
+
return int32TBytes * batchSize * (embeddingLength + (kvSize * headCount));
|
|
307
|
+
}
|
|
308
|
+
else if (expertCount > 0) {
|
|
309
|
+
const expertsUsedCount = this._ggufFileInfo.architectureMetadata.expert_used_count ?? 2;
|
|
310
|
+
return int32TBytes * batchSize * (((expertsUsedCount + 1) * embeddingLength) + (kvSize * headCount));
|
|
311
|
+
}
|
|
312
|
+
const totalElements = tensorInfo.length === 0
|
|
313
|
+
? this.totalLayers * (((llmData.embedding_length ?? 0) +
|
|
314
|
+
(llmData.feed_forward_length ?? 0)) / 2)
|
|
315
|
+
: tensorInfo.reduce((res, tensor) => {
|
|
316
|
+
return res + tensor.dimensions.reduce((res, dim) => res + Number(dim), 0);
|
|
317
|
+
}, 0);
|
|
318
|
+
if (this._ggufFileInfo.metadata.general?.architecture === GgufArchitectureType.phi3) {
|
|
319
|
+
// magic numbers for estimation. will be improved in the future
|
|
320
|
+
return (totalElements * 123 * (kvSize / 4096)) + defaultCalculationAdjustment;
|
|
321
|
+
}
|
|
322
|
+
else if (this._ggufFileInfo.metadata.general?.architecture === GgufArchitectureType.cohere2) {
|
|
323
|
+
// magic numbers for estimation. will be improved in the future
|
|
324
|
+
return (totalElements * 148 * (kvSize / 4096)) + defaultCalculationAdjustment;
|
|
325
|
+
}
|
|
326
|
+
// magic numbers for estimation. will be improved in the future
|
|
327
|
+
return (totalElements * 77.655 * (kvSize / 4096)) + defaultCalculationAdjustment;
|
|
328
|
+
};
|
|
329
|
+
// source: `llama_context::graph_max_nodes` in `llama-context.cpp`
|
|
330
|
+
const getMaxNodesMultiplier = (arch, nTokens) => {
|
|
331
|
+
if (arch === GgufArchitectureType.qwen3next)
|
|
332
|
+
return {
|
|
333
|
+
min: nTokens * 40,
|
|
334
|
+
multiplier: 32
|
|
335
|
+
};
|
|
336
|
+
return {
|
|
337
|
+
min: 1024,
|
|
338
|
+
multiplier: 8
|
|
339
|
+
};
|
|
340
|
+
};
|
|
341
|
+
const maxNodesMultiplier = getMaxNodesMultiplier(this._ggufFileInfo.metadata?.general?.architecture, Math.min(actualContextSize, batchSize));
|
|
342
|
+
const maxNodes = Math.max(maxNodesMultiplier.min, maxNodesMultiplier.multiplier * tensorInfo.length);
|
|
343
|
+
const cpuNodes = totalFileLayers === 0
|
|
344
|
+
? 0
|
|
345
|
+
: maxNodesMultiplier.multiplier * (tensorInfo.length * (finalCpuLayers / totalFileLayers));
|
|
346
|
+
const gpuNodes = maxNodes - cpuNodes;
|
|
347
|
+
const gpuComputeBufferSize = (this._llama._consts.ggmlTensorOverhead * gpuNodes) +
|
|
348
|
+
this._llama._bindings.getGgmlGraphOverheadCustom(gpuNodes, false);
|
|
349
|
+
const cpuComputeBufferSize = (this._llama._consts.ggmlTensorOverhead * cpuNodes) +
|
|
350
|
+
this._llama._bindings.getGgmlGraphOverheadCustom(cpuNodes, false);
|
|
351
|
+
const graphOverheadMemory = (flashAttention || !includeGraphOverhead)
|
|
352
|
+
? 0
|
|
353
|
+
: estimateGraphOverheadMemory();
|
|
354
|
+
const graphOverheadGpuSize = (usingGpu && totalFileLayers > 0)
|
|
355
|
+
? Math.round(graphOverheadMemory * (finalGpuLayers / totalFileLayers))
|
|
356
|
+
: 0;
|
|
357
|
+
const graphOverheadCpuSize = graphOverheadMemory - graphOverheadGpuSize;
|
|
358
|
+
const outputBufferSize = estimateOutput(sequences);
|
|
359
|
+
const gpuVram = gpuKVCacheSize + gpuRecurrentStateSize + gpuComputeBufferSize + graphOverheadGpuSize + outputBufferSize;
|
|
360
|
+
const cpuRam = cpuKVCacheSize + cpuRecurrentStateSize + cpuComputeBufferSize + graphOverheadCpuSize + outputBufferSize;
|
|
361
|
+
return {
|
|
362
|
+
cpuRam,
|
|
363
|
+
gpuVram: usingGpu
|
|
364
|
+
? gpuVram
|
|
365
|
+
: 0
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Get the split tensor resources for CPU and GPU based on the number of GPU layers
|
|
370
|
+
* @internal
|
|
371
|
+
*/
|
|
372
|
+
_getTensorResourceSplit(gpuLayers) {
|
|
373
|
+
const tensorInfo = this._ggufFileInfo.fullTensorInfo ?? [];
|
|
374
|
+
const architecture = this._ggufFileInfo.metadata?.general?.architecture;
|
|
375
|
+
if (gpuLayers === 0) {
|
|
376
|
+
return {
|
|
377
|
+
cpu: tensorInfo,
|
|
378
|
+
gpu: []
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
const fileLayers = this._getFileLayers();
|
|
382
|
+
const startGpuLayer = Math.max(0, fileLayers - gpuLayers);
|
|
383
|
+
const gpuTensors = [];
|
|
384
|
+
const cpuTensors = [];
|
|
385
|
+
let tokenEmbedLayer;
|
|
386
|
+
let mainOutputLayer;
|
|
387
|
+
for (const singleTensorInfo of tensorInfo) {
|
|
388
|
+
if (isMainOutputLayer(singleTensorInfo.name))
|
|
389
|
+
mainOutputLayer = singleTensorInfo;
|
|
390
|
+
else if (isTokenEmbedLayer(singleTensorInfo.name))
|
|
391
|
+
tokenEmbedLayer = singleTensorInfo;
|
|
392
|
+
// in the implementation of `llm_load_tensors`, layers with `LLM_TENSOR_LAYER_INPUT` are always
|
|
393
|
+
// loaded with `model.dev_input`, which is always set to the CPU
|
|
394
|
+
if (isInputLayer(singleTensorInfo.name)) {
|
|
395
|
+
cpuTensors.push(singleTensorInfo);
|
|
396
|
+
continue;
|
|
397
|
+
// in the implementation of `llm_load_tensors`, layers with `LLM_TENSOR_LAYER_OUTPUT` are always
|
|
398
|
+
// loaded with `model.dev_output`, which is set to the GPU only if all the layers are on the GPU
|
|
399
|
+
}
|
|
400
|
+
else if (isOutputLayer(singleTensorInfo.name)) {
|
|
401
|
+
if (gpuLayers === this.totalLayers) {
|
|
402
|
+
gpuTensors.push(singleTensorInfo);
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
cpuTensors.push(singleTensorInfo);
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const { layerNumber } = parseTensorName(singleTensorInfo.name);
|
|
411
|
+
if (gpuLayers !== this.totalLayers) {
|
|
412
|
+
if (architecture === GgufArchitectureType.qwen2 || architecture === GgufArchitectureType.gemma) {
|
|
413
|
+
if (layerNumber != null && layerNumber >= startGpuLayer)
|
|
414
|
+
gpuTensors.push(singleTensorInfo);
|
|
415
|
+
else
|
|
416
|
+
cpuTensors.push(singleTensorInfo);
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (layerNumber == null || layerNumber >= startGpuLayer)
|
|
421
|
+
gpuTensors.push(singleTensorInfo);
|
|
422
|
+
else
|
|
423
|
+
cpuTensors.push(singleTensorInfo);
|
|
424
|
+
}
|
|
425
|
+
if (mainOutputLayer == null && tokenEmbedLayer != null && gpuLayers === this.totalLayers && !gpuTensors.includes(tokenEmbedLayer))
|
|
426
|
+
gpuTensors.push(tokenEmbedLayer);
|
|
427
|
+
return {
|
|
428
|
+
cpu: cpuTensors,
|
|
429
|
+
gpu: gpuTensors
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
/** @internal */
|
|
433
|
+
_determineNumberOfLayersFromTensorInfo() {
|
|
434
|
+
const layerNumbers = new Set();
|
|
435
|
+
for (const singleTensorInfo of (this._ggufFileInfo.fullTensorInfo ?? [])) {
|
|
436
|
+
const { layerNumber } = parseTensorName(singleTensorInfo.name);
|
|
437
|
+
if (layerNumber != null)
|
|
438
|
+
layerNumbers.add(layerNumber);
|
|
439
|
+
}
|
|
440
|
+
return layerNumbers.size;
|
|
441
|
+
}
|
|
442
|
+
/** @internal */
|
|
443
|
+
_getFileLayers() {
|
|
444
|
+
return this._ggufFileInfo.architectureMetadata.block_count ?? this._determineNumberOfLayersFromTensorInfo();
|
|
445
|
+
}
|
|
446
|
+
_estimateContextCacheMemorySplitInBytes({ kvSize, sequences, totalFileLayers, finalModelGpuLayers, usingGpu, kvCacheKeyType = GgmlType.F16, kvCacheValueType = GgmlType.F16 }) {
|
|
447
|
+
// source: `llama_kv_cache_init` in `llama.cpp`
|
|
448
|
+
const architecture = this._ggufFileInfo.metadata.general?.architecture;
|
|
449
|
+
const nHead = this._ggufFileInfo.architectureMetadata.attention?.head_count ?? 0;
|
|
450
|
+
const nEmbd = this._ggufFileInfo.architectureMetadata.embedding_length ?? 0;
|
|
451
|
+
const nEmbdHeadK = this._ggufFileInfo.architectureMetadata.attention?.key_length ?? ((nHead == 0) ? 0 : (nEmbd / nHead));
|
|
452
|
+
const nHeadKv = this._ggufFileInfo.architectureMetadata.attention?.head_count_kv ?? nHead;
|
|
453
|
+
const nEmbdHeadV = this._ggufFileInfo.architectureMetadata.attention?.value_length ?? ((nHead == 0) ? 0 : nEmbd / nHead);
|
|
454
|
+
const keyTypeSize = this._llama._bindings.getTypeSizeForGgmlType(kvCacheKeyType) ?? this._llama._consts.ggmlTypeF16Size;
|
|
455
|
+
const valueTypeSize = this._llama._bindings.getTypeSizeForGgmlType(kvCacheValueType) ?? this._llama._consts.ggmlTypeF16Size;
|
|
456
|
+
// source: `llama_model::load_tensors` in `llama-model.cpp`
|
|
457
|
+
// repeating layers are assigned to GPU from `i_gpu_start = n_layer + 1 - n_gpu_layers`
|
|
458
|
+
const gpuRepeatingLayerStart = Math.max(0, (totalFileLayers + 1) - finalModelGpuLayers);
|
|
459
|
+
const recurrentLayersByPattern = this.isRecurrent
|
|
460
|
+
? "all"
|
|
461
|
+
: getRecurrentLayersPattern(architecture, this._ggufFileInfo.architectureMetadata);
|
|
462
|
+
let gpuKvElementsK = 0;
|
|
463
|
+
let gpuKvElementsV = 0;
|
|
464
|
+
let cpuKvElementsK = 0;
|
|
465
|
+
let cpuKvElementsV = 0;
|
|
466
|
+
let gpuRecurrentLayers = 0;
|
|
467
|
+
let cpuRecurrentLayers = 0;
|
|
468
|
+
for (let i = 0; i < totalFileLayers; i++) {
|
|
469
|
+
const isGpuLayer = i >= gpuRepeatingLayerStart;
|
|
470
|
+
const isRecurrentLayer = isLayerRecurrent(recurrentLayersByPattern, i);
|
|
471
|
+
if (isRecurrentLayer) {
|
|
472
|
+
if (isGpuLayer)
|
|
473
|
+
gpuRecurrentLayers++;
|
|
474
|
+
else
|
|
475
|
+
cpuRecurrentLayers++;
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
const nHeadKvLayer = resolveLayerHeadCountKv(nHeadKv, i, nHead);
|
|
479
|
+
const layerElementsK = nEmbdHeadK * nHeadKvLayer * kvSize;
|
|
480
|
+
const layerElementsV = nEmbdHeadV * nHeadKvLayer * kvSize;
|
|
481
|
+
if (isGpuLayer) {
|
|
482
|
+
gpuKvElementsK += layerElementsK;
|
|
483
|
+
gpuKvElementsV += layerElementsV;
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
cpuKvElementsK += layerElementsK;
|
|
487
|
+
cpuKvElementsV += layerElementsV;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
const gpuKVCacheSize = usingGpu
|
|
492
|
+
? ((gpuKvElementsK * keyTypeSize) + (gpuKvElementsV * valueTypeSize))
|
|
493
|
+
: 0;
|
|
494
|
+
const cpuKVCacheSize = (cpuKvElementsK * keyTypeSize) + (cpuKvElementsV * valueTypeSize);
|
|
495
|
+
const recurrentCellSize = Math.max(1, sequences);
|
|
496
|
+
const gpuRecurrentStateSize = usingGpu
|
|
497
|
+
? this._estimateRecurrentStateMemorySizeInBytes(recurrentCellSize, gpuRecurrentLayers)
|
|
498
|
+
: 0;
|
|
499
|
+
const cpuRecurrentStateSize = this._estimateRecurrentStateMemorySizeInBytes(recurrentCellSize, cpuRecurrentLayers);
|
|
500
|
+
return {
|
|
501
|
+
gpuKVCacheSize,
|
|
502
|
+
cpuKVCacheSize,
|
|
503
|
+
gpuRecurrentStateSize,
|
|
504
|
+
cpuRecurrentStateSize
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
_estimateRecurrentStateMemorySizeInBytes(recurrentCellSize, layers) {
|
|
508
|
+
if (layers <= 0 || recurrentCellSize <= 0)
|
|
509
|
+
return 0;
|
|
510
|
+
// source: `llama_memory_recurrent` + `llama_hparams::n_embd_r` / `llama_hparams::n_embd_s` in `llama.cpp`
|
|
511
|
+
const nHead = this._ggufFileInfo.architectureMetadata.attention?.head_count ?? 0;
|
|
512
|
+
const nEmbd = this._ggufFileInfo.architectureMetadata.embedding_length ?? 0;
|
|
513
|
+
const wkvHeadSize = this._ggufFileInfo.architectureMetadata.wkv?.head_size ?? 0;
|
|
514
|
+
const tokenShiftCount = this._ggufFileInfo.architectureMetadata.token_shift_count ?? 0;
|
|
515
|
+
const ssmDConv = this._ggufFileInfo.architectureMetadata.ssm?.conv_kernel ?? 0;
|
|
516
|
+
const ssmDInner = this._ggufFileInfo.architectureMetadata.ssm?.inner_size ?? 0;
|
|
517
|
+
const ssmDState = this._ggufFileInfo.architectureMetadata.ssm?.state_size ?? 0;
|
|
518
|
+
const ssmGroupCount = this._ggufFileInfo.architectureMetadata.ssm?.group_count ?? 0;
|
|
519
|
+
const shortConvLCache = this._ggufFileInfo.architectureMetadata.shortconv?.l_cache ?? 0;
|
|
520
|
+
const kdaHeadDim = this._ggufFileInfo.architectureMetadata.kda?.head_dim ?? 0;
|
|
521
|
+
const shortConvHistoryShift = 1;
|
|
522
|
+
const kdaQkvStateCount = 3;
|
|
523
|
+
const kdaDefaultConvKernel = 3;
|
|
524
|
+
const ssmBcStatePairCount = 2;
|
|
525
|
+
const nEmbdR = wkvHeadSize !== 0
|
|
526
|
+
? tokenShiftCount * nEmbd
|
|
527
|
+
: shortConvLCache !== 0
|
|
528
|
+
? nEmbd * Math.max(0, shortConvLCache - shortConvHistoryShift)
|
|
529
|
+
: kdaHeadDim !== 0
|
|
530
|
+
? (kdaQkvStateCount * (ssmDConv > 0
|
|
531
|
+
? ssmDConv - shortConvHistoryShift
|
|
532
|
+
: kdaDefaultConvKernel) * (nHead * kdaHeadDim))
|
|
533
|
+
: ((ssmDConv > 0
|
|
534
|
+
? (ssmDConv - shortConvHistoryShift)
|
|
535
|
+
: 0) * (ssmDInner + (ssmBcStatePairCount * ssmGroupCount * ssmDState)));
|
|
536
|
+
const nEmbdS = wkvHeadSize !== 0
|
|
537
|
+
? nEmbd * wkvHeadSize
|
|
538
|
+
: kdaHeadDim !== 0
|
|
539
|
+
? kdaHeadDim * kdaHeadDim * nHead
|
|
540
|
+
: ssmDState * ssmDInner;
|
|
541
|
+
if (nEmbdR === 0 && nEmbdS === 0)
|
|
542
|
+
return 0;
|
|
543
|
+
const recurrentTypeSize = this._llama._consts.ggmlTypeF32Size;
|
|
544
|
+
const bytesPerLayer = (nEmbdR + nEmbdS) * recurrentTypeSize;
|
|
545
|
+
return layers * recurrentCellSize * bytesPerLayer;
|
|
546
|
+
}
|
|
547
|
+
/** @internal */
|
|
548
|
+
_getTotalFileLayers() {
|
|
549
|
+
if (this._totalFileLayers != null)
|
|
550
|
+
return this._totalFileLayers;
|
|
551
|
+
this._totalFileLayers = this._getFileLayers();
|
|
552
|
+
return this._totalFileLayers;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* @param ggufFileInfo
|
|
556
|
+
* @param llama - If you already have a `Llama` instance, pass it to reuse it for the `GgufInsights` instance.
|
|
557
|
+
* If you don't pass a `Llama` instance, a basic `Llama` instance is created as a fallback - it's a slim instance that
|
|
558
|
+
* doesn't instantiate a `llama.cpp` backend, so it won't utilize the GPU at all, and be shared with other `GgufInsights` instances
|
|
559
|
+
* that need a fallback `Llama` instance.
|
|
560
|
+
*/
|
|
561
|
+
static async from(ggufFileInfo, llama) {
|
|
562
|
+
let resolvedLlama = llama;
|
|
563
|
+
if (resolvedLlama == null)
|
|
564
|
+
resolvedLlama = await getLlamaWithoutBackend();
|
|
565
|
+
return new GgufInsights(ggufFileInfo, resolvedLlama);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
function parseTensorName(tensorName) {
|
|
569
|
+
if (tensorName == null)
|
|
570
|
+
return { layerNumber: undefined };
|
|
571
|
+
const layerTensorPrefix = "blk.";
|
|
572
|
+
if (!tensorName.startsWith(layerTensorPrefix))
|
|
573
|
+
return { layerNumber: undefined };
|
|
574
|
+
const dotIndex = tensorName.indexOf(".", layerTensorPrefix.length);
|
|
575
|
+
const layerNumberString = tensorName.slice(layerTensorPrefix.length, dotIndex < 0
|
|
576
|
+
? tensorName.length
|
|
577
|
+
: dotIndex);
|
|
578
|
+
const layerNumber = parseInt(layerNumberString);
|
|
579
|
+
if (Number.isFinite(layerNumber))
|
|
580
|
+
return { layerNumber };
|
|
581
|
+
return { layerNumber: undefined };
|
|
582
|
+
}
|
|
583
|
+
function calculateTensorsSize(tensorsInfo, llama, useMmap, startFromTensorDataOffset = false) {
|
|
584
|
+
if (!useMmap) {
|
|
585
|
+
let size = 0;
|
|
586
|
+
for (const tensorInfo of tensorsInfo)
|
|
587
|
+
size += calculateTensorSize(tensorInfo, llama);
|
|
588
|
+
return size;
|
|
589
|
+
}
|
|
590
|
+
const fileStats = new Map();
|
|
591
|
+
for (const tensorInfo of tensorsInfo) {
|
|
592
|
+
let stats = fileStats.get(tensorInfo.filePart);
|
|
593
|
+
if (stats == null) {
|
|
594
|
+
stats = {
|
|
595
|
+
tensorsSize: 0
|
|
596
|
+
};
|
|
597
|
+
fileStats.set(tensorInfo.filePart, stats);
|
|
598
|
+
}
|
|
599
|
+
const tensorSize = calculateTensorSize(tensorInfo, llama);
|
|
600
|
+
stats.tensorsSize += tensorSize;
|
|
601
|
+
const startOffset = tensorInfo.offset;
|
|
602
|
+
const endOffset = typeof startOffset === "number"
|
|
603
|
+
? startOffset + tensorSize
|
|
604
|
+
: startOffset + BigInt(tensorSize);
|
|
605
|
+
if (startFromTensorDataOffset)
|
|
606
|
+
stats.startOffset = Number(BigInt(tensorInfo.fileOffset) - BigInt(tensorInfo.offset));
|
|
607
|
+
else if (stats.startOffset == null || startOffset < stats.startOffset)
|
|
608
|
+
stats.startOffset = startOffset;
|
|
609
|
+
if (stats.endOffset == null || endOffset > stats.endOffset)
|
|
610
|
+
stats.endOffset = endOffset;
|
|
611
|
+
}
|
|
612
|
+
let size = 0;
|
|
613
|
+
for (const [, stats] of fileStats) {
|
|
614
|
+
const offsetSize = (stats.endOffset == null || stats.startOffset == null)
|
|
615
|
+
? 0
|
|
616
|
+
: Number(BigInt(stats.endOffset) - BigInt(stats.startOffset));
|
|
617
|
+
const tensorsSize = stats.tensorsSize;
|
|
618
|
+
size += Math.max(offsetSize, tensorsSize);
|
|
619
|
+
}
|
|
620
|
+
return size;
|
|
621
|
+
}
|
|
622
|
+
function calculateTensorSize(tensor, llama) {
|
|
623
|
+
const typeSize = llama._bindings.getTypeSizeForGgmlType(tensor.ggmlType);
|
|
624
|
+
const blockSize = llama._bindings.getBlockSizeForGgmlType(tensor.ggmlType);
|
|
625
|
+
const ggmlMaxDims = llama._consts.ggmlMaxDims;
|
|
626
|
+
if (typeSize == null || blockSize == null)
|
|
627
|
+
throw new Error("Invalid type or block size");
|
|
628
|
+
const { ne, nb } = getTensorNeAndNb(tensor, { typeSize, blockSize, ggmlMaxDims });
|
|
629
|
+
if (blockSize === 1) {
|
|
630
|
+
let totalBytes = typeSize;
|
|
631
|
+
for (let i = 0; i < ggmlMaxDims; i++) {
|
|
632
|
+
totalBytes += (ne[i] - 1) * nb[i];
|
|
633
|
+
}
|
|
634
|
+
return totalBytes;
|
|
635
|
+
}
|
|
636
|
+
else {
|
|
637
|
+
let totalBytes = Math.floor((ne[0] * nb[0]) / blockSize);
|
|
638
|
+
for (let i = 1; i < ggmlMaxDims; i++) {
|
|
639
|
+
totalBytes += (ne[i] - 1) * nb[i];
|
|
640
|
+
}
|
|
641
|
+
return totalBytes;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
function getTensorNeAndNb(tensor, { typeSize, blockSize, ggmlMaxDims }) {
|
|
645
|
+
// number of elements
|
|
646
|
+
// source: `ggml_new_tensor_impl` in `ggml.c`
|
|
647
|
+
const ne = [
|
|
648
|
+
...tensor.dimensions,
|
|
649
|
+
...(Array(Math.max(0, ggmlMaxDims - tensor.dimensions.length)).fill(1))
|
|
650
|
+
].slice(0, ggmlMaxDims);
|
|
651
|
+
// number of bytes
|
|
652
|
+
// source: `ggml_new_tensor_impl` in `ggml.c`
|
|
653
|
+
const nb = [
|
|
654
|
+
typeSize,
|
|
655
|
+
Math.floor(typeSize * (ne[0] / blockSize)),
|
|
656
|
+
...Array(ggmlMaxDims - 2).fill(0)
|
|
657
|
+
];
|
|
658
|
+
for (let i = 2; i < ggmlMaxDims; i++) {
|
|
659
|
+
nb[i] = nb[i - 1] * ne[i - 1];
|
|
660
|
+
}
|
|
661
|
+
return {
|
|
662
|
+
ne,
|
|
663
|
+
nb
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
function isInputLayer(layerName) {
|
|
667
|
+
const [firstPart] = layerName.split(".");
|
|
668
|
+
if (firstPart == null)
|
|
669
|
+
return false;
|
|
670
|
+
// source: in `llama.cpp`, all tensor names from `LLM_TENSOR_NAMES` where
|
|
671
|
+
// in `llm_tensor_info_mapping` have a mapping to `LLM_TENSOR_LAYER_INPUT`
|
|
672
|
+
switch (firstPart) {
|
|
673
|
+
case "token_embd":
|
|
674
|
+
case "token_embd_norm":
|
|
675
|
+
case "token_types":
|
|
676
|
+
case "position_embd":
|
|
677
|
+
return true;
|
|
678
|
+
}
|
|
679
|
+
return false;
|
|
680
|
+
}
|
|
681
|
+
function isOutputLayer(layerName) {
|
|
682
|
+
const [firstPart, secondPart] = layerName.split(".");
|
|
683
|
+
if (firstPart == null)
|
|
684
|
+
return false;
|
|
685
|
+
// source: in `llama.cpp`, all tensor names from `LLM_TENSOR_NAMES` where
|
|
686
|
+
// in `llm_tensor_info_mapping` have a mapping to `LLM_TENSOR_LAYER_INPUT`
|
|
687
|
+
switch (firstPart) {
|
|
688
|
+
case "output":
|
|
689
|
+
case "output_norm":
|
|
690
|
+
case "cls":
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
if (secondPart == null)
|
|
694
|
+
return false;
|
|
695
|
+
// source: in `llama.cpp`, all tensor names from `LLM_TENSOR_NAMES` where
|
|
696
|
+
// in `llm_tensor_info_mapping` have a mapping to `LLM_TENSOR_LAYER_INPUT`
|
|
697
|
+
switch (firstPart + "." + secondPart) {
|
|
698
|
+
case "cls.output":
|
|
699
|
+
case "dec.output_norm":
|
|
700
|
+
case "enc.output_norm":
|
|
701
|
+
return true;
|
|
702
|
+
}
|
|
703
|
+
return false;
|
|
704
|
+
}
|
|
705
|
+
function isMainOutputLayer(layerName) {
|
|
706
|
+
const [firstPart] = layerName.split(".");
|
|
707
|
+
return firstPart === "output";
|
|
708
|
+
}
|
|
709
|
+
function isTokenEmbedLayer(layerName) {
|
|
710
|
+
const [firstPart] = layerName.split(".");
|
|
711
|
+
return firstPart === "token_embd";
|
|
712
|
+
}
|
|
713
|
+
function ggmlPad(value, padding) {
|
|
714
|
+
return ((value + padding - 1) & ~(padding - 1));
|
|
715
|
+
}
|
|
716
|
+
function getSwaPatternForArchitecture(architecture, slidingWindowPattern) {
|
|
717
|
+
if (typeof slidingWindowPattern === "number")
|
|
718
|
+
return slidingWindowPattern;
|
|
719
|
+
// source: `llama_model::load_hparams` in `llama-model.cpp` - calls to `hparams.set_swa_pattern`
|
|
720
|
+
switch (architecture) {
|
|
721
|
+
case GgufArchitectureType.llama4:
|
|
722
|
+
return 4;
|
|
723
|
+
case GgufArchitectureType.afmoe:
|
|
724
|
+
return 4;
|
|
725
|
+
case GgufArchitectureType.modernBert:
|
|
726
|
+
return 3;
|
|
727
|
+
case GgufArchitectureType.phi3:
|
|
728
|
+
return 1;
|
|
729
|
+
case GgufArchitectureType.plamo3:
|
|
730
|
+
return 8;
|
|
731
|
+
case GgufArchitectureType.gemma2:
|
|
732
|
+
return 2;
|
|
733
|
+
case GgufArchitectureType.gemma3:
|
|
734
|
+
return 6;
|
|
735
|
+
case GgufArchitectureType.gemma3n:
|
|
736
|
+
return 5;
|
|
737
|
+
case GgufArchitectureType.gemmaEmbedding:
|
|
738
|
+
return 6;
|
|
739
|
+
case GgufArchitectureType.cohere2:
|
|
740
|
+
return 4;
|
|
741
|
+
case GgufArchitectureType.olmo2:
|
|
742
|
+
return 4;
|
|
743
|
+
case GgufArchitectureType.exaone4:
|
|
744
|
+
return 4;
|
|
745
|
+
case GgufArchitectureType.exaoneMoe:
|
|
746
|
+
return 4;
|
|
747
|
+
case GgufArchitectureType.gptOss:
|
|
748
|
+
return 2;
|
|
749
|
+
case GgufArchitectureType.smallthinker:
|
|
750
|
+
return 4;
|
|
751
|
+
}
|
|
752
|
+
return 1;
|
|
753
|
+
}
|
|
754
|
+
function resolveLayerHeadCountKv(nHeadKv, layerIndex, nHead) {
|
|
755
|
+
if (typeof nHeadKv === "number")
|
|
756
|
+
return nHeadKv;
|
|
757
|
+
const layerHeadCountKv = nHeadKv[layerIndex];
|
|
758
|
+
if (layerHeadCountKv == null)
|
|
759
|
+
return nHead;
|
|
760
|
+
return layerHeadCountKv;
|
|
761
|
+
}
|
|
762
|
+
function getRecurrentLayersPattern(architecture, architectureMetadata) {
|
|
763
|
+
const nHeadKv = architectureMetadata?.attention?.head_count_kv;
|
|
764
|
+
const feedForwardLength = architectureMetadata?.feed_forward_length;
|
|
765
|
+
const hasRecurrentHeadCountKvEntry = Array.isArray(nHeadKv) && nHeadKv.some((value) => value === 0);
|
|
766
|
+
if (architecture === GgufArchitectureType.falconH1)
|
|
767
|
+
// source: `llama_model::load_hparams` in `llama-model.cpp`:
|
|
768
|
+
// `case LLM_ARCH_FALCON_H1` does `std::fill(..., true)` for `recurrent_layer_arr`
|
|
769
|
+
return "all";
|
|
770
|
+
if (architecture === GgufArchitectureType.nemotronH || architecture === GgufArchitectureType.nemotronHMoe) {
|
|
771
|
+
// source: `llama_model::load_hparams` in `llama-model.cpp`:
|
|
772
|
+
// `case LLM_ARCH_NEMOTRON_H / LLM_ARCH_NEMOTRON_H_MOE`:
|
|
773
|
+
// `recurrent_layer_arr[i] = (n_head_kv(i) == 0 && n_ff(i) == 0)`
|
|
774
|
+
if (Array.isArray(nHeadKv))
|
|
775
|
+
return {
|
|
776
|
+
type: "headCountKvAndFeedForward",
|
|
777
|
+
headCountKvValues: nHeadKv,
|
|
778
|
+
feedForwardLength
|
|
779
|
+
};
|
|
780
|
+
if (nHeadKv === 0) {
|
|
781
|
+
if (typeof feedForwardLength === "number")
|
|
782
|
+
return feedForwardLength === 0
|
|
783
|
+
? "all"
|
|
784
|
+
: "none";
|
|
785
|
+
return "none";
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (typeof architectureMetadata?.full_attention_interval === "number" &&
|
|
789
|
+
Number.isFinite(architectureMetadata?.full_attention_interval) &&
|
|
790
|
+
architectureMetadata?.full_attention_interval > 0 &&
|
|
791
|
+
(
|
|
792
|
+
// source: `llama_model::load_hparams` in `llama-model.cpp`
|
|
793
|
+
// `case LLM_ARCH_QWEN3NEXT / LLM_ARCH_QWEN35 / LLM_ARCH_QWEN35MOE`:
|
|
794
|
+
// `hparams.recurrent_layer_arr[i] = ((i + 1) % full_attn_interval != 0)`
|
|
795
|
+
architecture === GgufArchitectureType.qwen3next ||
|
|
796
|
+
architecture === GgufArchitectureType.qwen35 ||
|
|
797
|
+
architecture === GgufArchitectureType.qwen35moe ||
|
|
798
|
+
hasRecurrentHeadCountKvEntry))
|
|
799
|
+
return {
|
|
800
|
+
type: "fullAttentionInterval",
|
|
801
|
+
interval: Math.max(1, Math.floor(architectureMetadata?.full_attention_interval))
|
|
802
|
+
};
|
|
803
|
+
if (hasRecurrentHeadCountKvEntry)
|
|
804
|
+
return {
|
|
805
|
+
type: "headCountKvArray",
|
|
806
|
+
values: nHeadKv
|
|
807
|
+
};
|
|
808
|
+
return "none";
|
|
809
|
+
}
|
|
810
|
+
function isLayerRecurrent(pattern, layerIndex) {
|
|
811
|
+
if (pattern === "all")
|
|
812
|
+
return true;
|
|
813
|
+
else if (pattern === "none")
|
|
814
|
+
return false;
|
|
815
|
+
else if (pattern.type === "fullAttentionInterval")
|
|
816
|
+
return (layerIndex + 1) % pattern.interval !== 0;
|
|
817
|
+
else if (pattern.type === "headCountKvAndFeedForward")
|
|
818
|
+
return pattern.headCountKvValues[layerIndex] === 0 &&
|
|
819
|
+
resolveLayerFeedForwardLength(pattern.feedForwardLength, layerIndex) === 0;
|
|
820
|
+
return pattern.values[layerIndex] === 0;
|
|
821
|
+
}
|
|
822
|
+
function resolveLayerFeedForwardLength(feedForwardLength, layerIndex) {
|
|
823
|
+
if (typeof feedForwardLength === "number")
|
|
824
|
+
return feedForwardLength;
|
|
825
|
+
else if (Array.isArray(feedForwardLength))
|
|
826
|
+
return feedForwardLength[layerIndex] ?? 0;
|
|
827
|
+
return 0;
|
|
828
|
+
}
|
|
829
|
+
export function parseRankingTemplate(template) {
|
|
830
|
+
if (template == null)
|
|
831
|
+
return undefined;
|
|
832
|
+
return template
|
|
833
|
+
.replaceAll("{query}", "{{query}}")
|
|
834
|
+
.replaceAll("{document}", "{{document}}");
|
|
835
|
+
}
|
|
836
|
+
export function isRankingTemplateValid(template) {
|
|
837
|
+
return template != null && template.includes("{{query}}") && template.includes("{{document}}");
|
|
838
|
+
}
|
|
839
|
+
export function getDominantTensorType(tensorInfo) {
|
|
840
|
+
const tensorTypes = [];
|
|
841
|
+
for (const tensor of tensorInfo)
|
|
842
|
+
tensorTypes[tensor.ggmlType] = ((tensorTypes[tensor.ggmlType] ?? 0) +
|
|
843
|
+
tensor.dimensions.map(((dim) => Number(dim))).reduce((a, b) => a * b, 1));
|
|
844
|
+
let dominantType = undefined;
|
|
845
|
+
let maxCount = 0;
|
|
846
|
+
for (const [type, count] of tensorTypes.entries()) {
|
|
847
|
+
if (count > maxCount) {
|
|
848
|
+
maxCount = count;
|
|
849
|
+
dominantType = type;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
return dominantType;
|
|
853
|
+
}
|
|
854
|
+
//# sourceMappingURL=GgufInsights.js.map
|