/** * This file is divided into 4 sections: * * 1. globalConfigSchematics: The pool for all config keys and their types * 2. Functionality scope definitions: i.e. what config keys are available in what functionality * scope. An example functionality scope is llmPrediction. * 3. Utility types that can be used to work with types of schema. */ import { defaultGPUSplitConfig, type KVConfigFieldDependency, type LLMLoadPromptTemplate, } from "@lmstudio/lms-shared-types"; import { KVConfigSchematicsBuilder, type InferConfigFieldFilter, type InferConfigSchemaKeys, type InferConfigSchemaMap, type InferValueTypeKeys, type InferValueTypeMap, type KVConfigSchematics, type KVFieldValueTypeLibrary, } from "./KVConfig.js"; import { kvValueTypesLibrary } from "./valueTypes.js"; const VIRTUAL_MODEL_CUSTOM_FIELD_EXTENSION_PREFIX = "ext.virtualModel.customField"; const speculativeDecodingDraftModelSelectedDependencies: Array = [ { key: "llm.prediction.speculativeDecoding.draftModel", condition: { type: "notEquals", value: "" }, }, ]; const speculativeDecodingDraftTokenFieldParams = { modelCentric: true, dependencies: speculativeDecodingDraftModelSelectedDependencies, }; export const defaultLlmLoadPromptTemplate: LLMLoadPromptTemplate = { type: "jinja", jinjaPromptTemplate: { template: "{% for message in messages %}" + "{% if message['role'] == 'system' %}{{ 'Instruct: ' + message['content'] + '\\n' }}" + "{% elif message['role'] == 'user' %}{{ 'Human: ' + message['content'] + '\\n' }}" + "{% elif message['role'] == 'assistant' %}{{ 'AI: ' + message['content'] + '\\n' }}" + "{% endif %}" + "{% endfor %}" + "{% if add_generation_prompt %}{{ 'AI: ' }}{% endif %}", }, }; // --------------------------- // 1. globalConfigSchematics // --------------------------- export const globalConfigSchematics = new KVConfigSchematicsBuilder(kvValueTypesLibrary) .extension(VIRTUAL_MODEL_CUSTOM_FIELD_EXTENSION_PREFIX) .field("envVars", "envVars", {}, {}) .scope("llm.prediction", builder => builder .field( "temperature", "numeric", { min: 0, step: 0.01, slider: { min: 0, max: 1, step: 0.01 }, precision: 2, shortHand: "temp", }, 0.8, ) .field("contextOverflowPolicy", "contextOverflowPolicy", {}, "truncateMiddle") .field( "maxPredictedTokens", "checkboxNumeric", { min: 1, int: true }, { checked: false, value: 1000 }, ) .field("stopStrings", "stringArray", {}, []) .field("toolCallStopStrings", "stringArray", {}, []) .field("structured", "llamaStructuredOutput", {}, { type: "none" }) .scope("speculativeDecoding", builder => builder .field( "draftModel", "speculativeDecodingDraftModel", { modelCentric: true, }, "", ) .field( "minDraftLengthToConsider", "numeric", { ...speculativeDecodingDraftTokenFieldParams, min: 0, int: true, slider: { min: 0, max: 10, step: 1 }, }, 0, ) .field( "numReuseTokens", "numeric", { ...speculativeDecodingDraftTokenFieldParams, min: 1, int: true, }, 256, ) .field( "minContinueDraftingProbability", "numeric", { ...speculativeDecodingDraftTokenFieldParams, min: 0, max: 1, step: 0.01, precision: 2, slider: { min: 0, max: 1, step: 0.01 }, }, 0.75, ) .field( "maxTokensToDraft", "numeric", { ...speculativeDecodingDraftTokenFieldParams, min: 1, int: true, slider: { min: 10, max: 30, step: 1 }, }, 16, ) .field( "numDraftTokensExact", "numeric", { ...speculativeDecodingDraftTokenFieldParams, min: 1, int: true, slider: { min: 1, max: 10, step: 1 }, }, 2, ), ) .field("tools", "toolUse", {}, { type: "none" }) .field("toolChoice", "toolChoice", {}, { type: "generic", mode: "auto" }) .field("toolNaming", "toolNaming", {}, "removeSpecial") .field( "promptTemplate", "llmPromptTemplate", { modelCentric: true }, { type: "manual", manualPromptTemplate: { beforeSystem: "Instruct: ", afterSystem: "\n", beforeAssistant: "AI: ", afterAssistant: "\n", beforeUser: "Human: ", afterUser: "\n", }, stopStrings: [], }, ) .field("systemPrompt", "string", { isParagraph: true }, "") .field( "seed", "checkboxNumeric", { int: true, min: -1, uncheckedHint: "config:seedUncheckedHint" }, { checked: false, value: -1 }, ) .field("contextPrefill", "context", {}, []) .field("topKSampling", "numeric", { min: -1, max: 500, int: true }, 40) .field( "repeatPenalty", "checkboxNumeric", { min: -1, step: 0.01 }, { checked: true, value: 1.1 }, ) .field( "minPSampling", "checkboxNumeric", { min: 0, max: 1, step: 0.01, precision: 2, slider: { min: 0, max: 1, step: 0.01 } }, { checked: true, value: 0.05 }, ) .field( "topPSampling", "checkboxNumeric", { min: 0, max: 1, step: 0.01, precision: 2, slider: { min: 0, max: 1, step: 0.01 } }, { checked: true, value: 0.95 }, ) .field( "logProbs", "checkboxNumeric", { min: 0, max: 100, int: true }, { checked: false, value: 0 }, ) .scope("reasoning", builder => builder .field( "enableThinking", "boolean", { displayName: "Enable Thinking", subtitle: "Controls thinking for chat templates that support enable_thinking.", }, true, ) .field( "budgetTokens", "checkboxNumeric", { min: 0, int: true, uncheckedHint: "config:reasoningBudgetUncheckedHint", }, { checked: false, value: 1024 }, ) .field( "parsing", "llmReasoningParsing", {}, { enabled: true, startString: "", endString: "", }, ), ) .scope("vision", builder => builder .field( "userMaxImageDimensionPixels", "checkboxNumeric", { int: true, min: 1 }, { checked: true, value: 1024 }, ) .field("ignoreModelPreferredMaxImageDimension", "boolean", {}, false), ) .scope("llama", builder => builder .field("cpuThreads", "numeric", { min: 1, int: true }, 4) .field( "frequencyPenalty", "checkboxNumeric", { precision: 2 }, { checked: false, value: 0.0 }, ) .field( "xtcProbability", "checkboxNumeric", { min: 0, max: 1, step: 0.01, precision: 2, slider: { min: 0, max: 1, step: 0.01 } }, { checked: false, value: 0.5 }, ) .field( "xtcThreshold", "checkboxNumeric", { min: 0, max: 1, step: 0.01, precision: 2, slider: { min: 0, max: 0.5, step: 0.01 } }, { checked: false, value: 0.1 }, ) .field( "presencePenalty", "checkboxNumeric", { step: 0.01, precision: 2 }, { checked: false, value: 0.0 }, ) .field( "mirostatSampling", "llamaMirostatSampling", {}, { // Disabled by default version: 0, learningRate: 0.1, targetEntropy: 5, }, ) .field( "tailFreeSampling", "checkboxNumeric", { min: 0, max: 1, step: 0.01, precision: 2, slider: { min: 0, max: 1, step: 0.01 } }, { checked: false, value: 0.95 }, ) .field( "locallyTypicalSampling", "checkboxNumeric", { min: 0, max: 1, step: 0.01, precision: 2, slider: { min: 0, max: 1, step: 0.01 } }, { checked: false, value: 0.9 }, ) .field("logitBias", "llamaLogitBias", {}, []), ), ) .scope("llm.load", builder => builder .field( "contextLength", "contextLength", { machineDependent: true, }, 2048, ) .field("autoFitMinContextLength", "numeric", { min: 0, int: true, machineDependent: true }, 0) .field("numExperts", "numeric", { min: 0, int: true }, 0) .field( "seed", "checkboxNumeric", { int: true, min: -1, uncheckedHint: "config:seedUncheckedHint" }, { checked: false, value: -1 }, ) .field( "promptTemplate", "llmLoadPromptTemplate", { modelCentric: true }, defaultLlmLoadPromptTemplate, ) .field( "engineConfigFileContents", "string", { machineDependent: true, nonConfigurable: true, requiresPrivilegedWrite: true }, "", ) .field( "engineCwd", "string", { machineDependent: true, nonConfigurable: true, requiresPrivilegedWrite: true }, "", ) .field("offloadKVCacheToGpu", "boolean", {}, true) .field( "lazyMode", "select", { options: [ { value: "auto", displayName: "Auto" }, { value: "on", displayName: "On" }, { value: "off", displayName: "Off" }, ], machineDependent: true, displayName: "On-Demand Tensor Loading", }, "auto", ) .field( "numCpuExpertLayersRatio", "llamaAccelerationOffloadRatio", { machineDependent: true, isExperimental: true }, "off", ) .field( "moeCacheMiB", "numeric", { min: 0, int: true, machineDependent: true, isExperimental: true, displayName: "MoE Expert Cache (MiB)", hint: "GPU memory reserved to cache MoE expert weights that stay in system RAM. " + "0 disables the cache.", }, 0, ) .field( "moeExpertResidentRatio", "checkboxNumeric", { min: 0.01, max: 1, step: 0.01, precision: 2, machineDependent: true, isExperimental: true, displayName: "Resident MoE Experts", hint: "Fraction of MoE experts kept in memory. Lower values save memory but can slow responses.", }, { checked: false, value: 0.25 }, ) .field( "numParallelSessions", "numeric", { min: 1, max: 1023, int: true, isExperimental: true }, 4, ) .field( "maxMemoryBytes", "checkboxNumeric", { min: 1, max: Number.MAX_SAFE_INTEGER, int: true, machineDependent: true, displayName: "Maximum Memory (bytes)", hint: "Caps Splash's Metal allocations. Leave unchecked to let Splash choose the budget automatically.", }, { checked: false, value: 28 * 1024 ** 3 }, ) .field("useUnifiedKvCache", "boolean", { isExperimental: true }, true) .scope("speculativeDecoding", builder => builder .field( "draftMtp", "boolean", { displayName: "Draft MTP", hint: "Use bundled multi-token prediction heads when loading the model.", }, false, ) .field( "draftDspark", "boolean", { displayName: "Draft DSpark", hint: "Use bundled DSpark heads when loading the model.", }, false, ) .field( "draftSimple", "boolean", { displayName: "Draft Simple", hint: "Use a separate draft model for speculative decoding.", }, false, ) .field( "draftDflashSidecar", "boolean", { displayName: "DFlash Sidecar", hint: "Use a DFlash sidecar drafter model for speculative decoding.", }, false, ) .field( "draftDsparkSidecar", "boolean", { displayName: "DSpark Sidecar", hint: "Use a DSpark sidecar drafter model for speculative decoding.", }, false, ) .field( "draftMtpSidecar", "boolean", { displayName: "MTP Sidecar", hint: "Use an MTP sidecar drafter model for speculative decoding.", }, false, ) .field( "draftModel", "string", { displayName: "Speculative Decoding", hint: "Configure load-time speculative decoding.", }, "", ) .field( "draftMaxTokens", "numeric", { min: 0, int: true, displayName: "Max Draft Tokens", hint: "Maximum number of draft tokens to generate.", }, 3, ) .field( "draftMinTokens", "numeric", { min: 0, int: true, displayName: "Min Draft Tokens", hint: "Minimum draft length to verify with the main model.", }, 0, ) .field( "draftMinContinueProbability", "numeric", { min: 0, max: 1, step: 0.01, precision: 2, displayName: "Drafting Probability Cutoff", hint: "Continue drafting while token probability is at or above this threshold.", }, 0, ), ) .scope("llama", builder => builder .field("autoFit", "boolean", { machineDependent: true }, true) .scope("acceleration", builder => builder.field( "offloadRatio", "llamaAccelerationOffloadRatio", { machineDependent: true }, "max", ), ) .field("cpuThreadPoolSize", "numeric", { min: 1, machineDependent: true }, 4) .field("evalBatchSize", "numeric", { min: 1, int: true }, 2048) .field( "physicalBatchSize", "numeric", { min: 1, int: true, displayName: "Physical Batch Size", }, 512, ) .field("flashAttention", "boolean", {}, false) .field( "contextCheckpoints", "numeric", { min: 0, int: true, displayName: "Context Checkpoints", hint: "Maximum number of context checkpoints to keep per llama-server slot. 0 disables checkpoints.", }, 32, ) .field("reasoningBudgetMessage", "string", {}, "") .field( "ropeFrequencyBase", "checkboxNumeric", { min: 0, uncheckedHint: "config:ropeFrequencyBaseUncheckedHint" }, { checked: false, value: 0 }, ) .field( "ropeFrequencyScale", "checkboxNumeric", { min: 0, uncheckedHint: "config:ropeFrequencyScaleUncheckedHint" }, { checked: false, value: 0 }, ) .field("keepModelInMemory", "boolean", {}, true) .field("useFp16ForKVCache", "boolean", {}, true) .field("tryMmap", "boolean", {}, true) .field("tryDirectIO", "boolean", {}, false) .field( "argumentsOverride", "llamaCppArgumentsOverride", {}, { enabled: false, disabledParameters: [], overrideParameters: [], excludeAllConfig: false, }, ) .field( "kCacheQuantizationType", "llamaCacheQuantizationType", { isExperimental: true }, { checked: false, value: "f16" }, ) .field( "vCacheQuantizationType", "llamaCacheQuantizationType", { isExperimental: true, warning: "config:llamaKvCacheQuantizationWarning" }, { checked: false, value: "f16" }, ), ) .scope("mlx", builder => builder .field("autoFit", "boolean", { machineDependent: true }, true) .field("diskCache", "boolean", { machineDependent: true }, true) .field( "kvCacheQuantization", "mlxKvCacheQuantizationType", { isExperimental: true }, { enabled: false, bits: 8, groupSize: 64, quantizedStart: 5000 }, ), ) .scope("yuzu", builder => builder.field("autoFit", "boolean", { machineDependent: true }, true).field( "neuralEngine", "select", { options: [ { value: "auto", displayName: "Auto" }, { value: "off", displayName: "Off" }, ], displayName: "Neural Engine Prefill", hint: "Auto uses the Neural Engine alongside the GPU to process long prompts when that is faster. Off keeps prompt processing on the GPU.", }, "auto", ), ) .scope("vllm", builder => builder .field( "autoFit", "boolean", { machineDependent: true, displayName: "AutoFit Context", hint: "Automatically choose the largest context that fits in the GPU memory budget.", }, true, ) .field( "gpuMemoryUtilization", "numeric", { min: 0, max: 1, step: 0.01, precision: 2, slider: { min: 0, max: 1, step: 0.01 }, displayName: "GPU Memory Utilization", }, 0.92, ) .field("reasoningParser", "string", { displayName: "Reasoning Parser" }, "") .field("toolCallParser", "string", { displayName: "Tool Call Parser" }, ""), ), ) .scope("load", builder => builder .field("gpuSplitConfig", "gpuSplitConfig", {}, defaultGPUSplitConfig) .field("gpuStrictVramCap", "boolean", {}, false), ) .scope("embedding.load", builder => builder .field("contextLength", "contextLength", { machineDependent: true }, 2048) .field( "seed", "checkboxNumeric", { int: true, min: -1, uncheckedHint: "config:seedUncheckedHint" }, { checked: false, value: -1 }, ) .scope("llama", builder => builder .scope("acceleration", builder => builder.field( "offloadRatio", "llamaAccelerationOffloadRatio", { machineDependent: true }, "max", ), ) .field("evalBatchSize", "numeric", { min: 1, int: true }, 2048) .field( "ropeFrequencyBase", "checkboxNumeric", { min: 0, uncheckedHint: "config:ropeFrequencyBaseUncheckedHint" }, { checked: false, value: 0 }, ) .field( "ropeFrequencyScale", "checkboxNumeric", { min: 0, uncheckedHint: "config:ropeFrequencyScaleUncheckedHint" }, { checked: false, value: 0 }, ) .field("keepModelInMemory", "boolean", {}, true) .field("tryMmap", "boolean", {}, true), ), ) // Use the ordinary context control; retain the server's parallel/unified-KV defaults. .scope("decision.load", builder => builder .field("contextLength", "contextLength", { machineDependent: true }, 2048) .field("autoFitMinContextLength", "numeric", { min: 0, int: true, machineDependent: true }, 0) .field("numParallelSessions", "numeric", { min: 1, max: 1023, int: true }, 4) .field("useUnifiedKvCache", "boolean", {}, true) .field("offloadKVCacheToGpu", "boolean", {}, true) .field( "numCpuExpertLayersRatio", "llamaAccelerationOffloadRatio", { machineDependent: true }, "off", ) .field( "moeCacheMiB", "numeric", { min: 0, int: true, machineDependent: true, displayName: "MoE Expert Cache (MiB)", hint: "GPU memory reserved to cache MoE expert weights that stay in system RAM. " + "0 disables the cache.", }, 0, ) .field("numExperts", "numeric", { min: 0, int: true }, 0) .field( "seed", "checkboxNumeric", { min: -1, int: true, uncheckedHint: "config:seedUncheckedHint" }, { checked: false, value: -1 }, ) .scope("llama", builder => builder .field("autoFit", "boolean", { machineDependent: true }, true) .scope("acceleration", builder => builder.field( "offloadRatio", "llamaAccelerationOffloadRatio", { machineDependent: true }, "max", ), ) .field("cpuThreadPoolSize", "numeric", { min: 1, int: true, machineDependent: true }, 4) .field("evalBatchSize", "numeric", { min: 1, int: true }, 2048) .field( "physicalBatchSize", "numeric", { min: 1, int: true, displayName: "Physical Batch Size" }, 512, ) .field("flashAttention", "boolean", {}, false) .field( "ropeFrequencyBase", "checkboxNumeric", { min: 0, uncheckedHint: "config:ropeFrequencyBaseUncheckedHint" }, { checked: false, value: 0 }, ) .field( "ropeFrequencyScale", "checkboxNumeric", { min: 0, uncheckedHint: "config:ropeFrequencyScaleUncheckedHint" }, { checked: false, value: 0 }, ) .field("keepModelInMemory", "boolean", {}, true) .field("tryMmap", "boolean", {}, true) .field("tryDirectIO", "boolean", {}, false) .field("useFp16ForKVCache", "boolean", {}, true) .field( "kCacheQuantizationType", "llamaCacheQuantizationType", {}, { checked: false, value: "f16" }, ) .field( "vCacheQuantizationType", "llamaCacheQuantizationType", {}, { checked: false, value: "f16" }, ) .field( "argumentsOverride", "llamaCppArgumentsOverride", {}, { enabled: false, disabledParameters: [], overrideParameters: [], excludeAllConfig: false, }, ), ), ) .scope("retrieval", builder => builder .field("databaseFile", "string", { machineDependent: true }, "") .field( "chunkingMethod", "retrievalChunkingMethod", {}, { type: "recursive-v1", chunkSize: 512, chunkOverlap: 100, }, ) .field("limit", "numeric", { min: 1, int: true }, 5) .field("embeddingModel", "modelIdentifier", { domain: ["embedding"] }, ""), ) .build(); // ------------------------------------ // 2. Functionality scope definitions // ------------------------------------ export const llmPredictionConfigSchematics = globalConfigSchematics.scoped("llm.prediction"); export const llmSharedPredictionConfigSchematics = llmPredictionConfigSchematics.sliced( "temperature", "maxPredictedTokens", "promptTemplate", "systemPrompt", "seed", "contextPrefill", "tools", "toolChoice", "toolNaming", "reasoning.*", "vision.*", ); export const llmLlamaPredictionConfigSchematics = llmSharedPredictionConfigSchematics.union( llmPredictionConfigSchematics.sliced( "llama.*", "contextOverflowPolicy", "stopStrings", "toolCallStopStrings", "structured", "topKSampling", "repeatPenalty", "minPSampling", "topPSampling", "logProbs", "speculativeDecoding.draftModel", "speculativeDecoding.minContinueDraftingProbability", "speculativeDecoding.minDraftLengthToConsider", "speculativeDecoding.maxTokensToDraft", "speculativeDecoding.numReuseTokens", ), ); export const llmMlxPredictionConfigSchematics = llmSharedPredictionConfigSchematics.union( llmPredictionConfigSchematics.sliced( "mlx.*", "contextOverflowPolicy", "stopStrings", "toolCallStopStrings", "structured", "repeatPenalty", "minPSampling", "topPSampling", "topKSampling", "logProbs", "speculativeDecoding.draftModel", "speculativeDecoding.numDraftTokensExact", ), ); export const llmOmlxPredictionConfigSchematics = llmPredictionConfigSchematics.sliced( "temperature", "maxPredictedTokens", "stopStrings", "structured", "tools", "toolChoice", "toolNaming", "systemPrompt", "seed", "contextPrefill", "topKSampling", "repeatPenalty", "minPSampling", "topPSampling", "reasoning.enableThinking", "reasoning.budgetTokens", "llama.presencePenalty", "llama.frequencyPenalty", ); export const llmVllmPredictionConfigSchematics = llmPredictionConfigSchematics.sliced( "temperature", "maxPredictedTokens", "stopStrings", "structured", "tools", "toolChoice", "toolNaming", "systemPrompt", "seed", "contextPrefill", "topKSampling", "repeatPenalty", "minPSampling", "topPSampling", "logProbs", "reasoning.enableThinking", "reasoning.budgetTokens", "llama.presencePenalty", "llama.frequencyPenalty", "llama.logitBias", ); // Keep yuzu defaults and limits local to its slice; other engines retain their sampler defaults. export const llmYuzuPredictionConfigSchematics = new KVConfigSchematicsBuilder(kvValueTypesLibrary) .scope("llm.prediction", builder => builder .field( "temperature", "numeric", { min: 0, max: 2, step: 0.01, precision: 2, slider: { min: 0, max: 2, step: 0.01 }, shortHand: "temp", }, 1, ) .field("topKSampling", "numeric", { min: 1, max: 32, int: true }, 20) .field( "topPSampling", "checkboxNumeric", { // Smallest positive float32 accepted by the runtime. Unchecked maps to top_p = 1. min: 2 ** -149, max: 1, step: 0.01, precision: 2, slider: { min: 0.01, max: 1, step: 0.01 }, }, { checked: true, value: 0.95 }, ), ) .build() .scoped("llm.prediction") .union( llmPredictionConfigSchematics.sliced( "maxPredictedTokens", "systemPrompt", "tools", "toolChoice", "toolNaming", "reasoning.enableThinking", "seed", "stopStrings", "structured", ), ); export const llmTransformersPredictionConfigSchematics = llmSharedPredictionConfigSchematics.union( llmPredictionConfigSchematics.sliced("transformers.*"), ); export const llmOnnxPredictionConfigSchematics = llmSharedPredictionConfigSchematics.union( llmPredictionConfigSchematics.sliced("onnx.*", "repeatPenalty", "topPSampling", "topKSampling"), ); export const llmMistralrsPredictionConfigSchematics = llmSharedPredictionConfigSchematics; export const llmLoadSchematics = globalConfigSchematics .scoped("llm.load") .union(globalConfigSchematics.sliced("envVars")) .union(globalConfigSchematics.scoped("load")); export const llmSharedLoadConfigSchematics = llmLoadSchematics.sliced( "contextLength", "autoFitMinContextLength", "seed", "envVars", ); export const llmYuzuLoadConfigSchematics = llmLoadSchematics .sliced( "contextLength", "autoFitMinContextLength", "numParallelSessions", "maxMemoryBytes", "speculativeDecoding.draftModel", "yuzu.*", ) .withTypeParamOverride("numParallelSessions", param => ({ ...param, max: 4 })); const llamaLoadConfigSchematics = globalConfigSchematics.sliced("llama.load.*", "load.*"); export const llmLlamaLoadConfigSchematics = llmSharedLoadConfigSchematics .union( llmLoadSchematics.sliced( "llama.*", "load.*", "promptTemplate", "offloadKVCacheToGpu", "lazyMode", "numParallelSessions", "useUnifiedKvCache", "speculativeDecoding.draftMtp", "speculativeDecoding.draftSimple", "speculativeDecoding.draftDflashSidecar", "speculativeDecoding.draftDsparkSidecar", "speculativeDecoding.draftMtpSidecar", "speculativeDecoding.draftModel", "speculativeDecoding.draftMaxTokens", "speculativeDecoding.draftMinTokens", "speculativeDecoding.draftMinContinueProbability", ), ) .union(llamaLoadConfigSchematics); export const llmMlxLoadConfigSchematics = llmSharedLoadConfigSchematics.union( llmLoadSchematics.sliced("mlx.*", "numParallelSessions"), ); export const llmOmlxLoadConfigSchematics = llmLoadSchematics .sliced( "contextLength", "numParallelSessions", "maxMemoryBytes", "moeExpertResidentRatio", "envVars", "speculativeDecoding.draftMtp", "speculativeDecoding.draftDspark", "speculativeDecoding.draftDflashSidecar", "speculativeDecoding.draftMtpSidecar", "speculativeDecoding.draftModel", "speculativeDecoding.draftMaxTokens", ) .withTypeParamOverride("maxMemoryBytes", param => ({ ...param, hint: "Memory budget for model weights and context. Leave unchecked for automatic sizing.", })) // oMLX grows its KV cache as the conversation grows, so context length is a cap, not a // reservation. .withTypeParamOverride("contextLength", param => ({ ...param, hint: "The maximum number of tokens this engine accepts in one prompt. Memory is allocated as " + "the conversation grows, so the model may run out of memory before reaching this limit.", })); export const llmVllmLoadConfigSchematics = llmSharedLoadConfigSchematics .union( llmLoadSchematics.sliced( "vllm.*", "numParallelSessions", "promptTemplate", "engineConfigFileContents", "engineCwd", "speculativeDecoding.draftMtp", "speculativeDecoding.draftDspark", "speculativeDecoding.draftSimple", "speculativeDecoding.draftDflashSidecar", "speculativeDecoding.draftDsparkSidecar", "speculativeDecoding.draftMtpSidecar", "speculativeDecoding.draftModel", "speculativeDecoding.draftMaxTokens", ), ) .union(globalConfigSchematics.sliced("load.gpuSplitConfig")); export const llmTransformersLoadConfigSchematics = llmSharedLoadConfigSchematics.union( llmLoadSchematics.sliced("transformers.*"), ); export const llmOnnxLoadConfigSchematics = llmSharedLoadConfigSchematics.union( llmLoadSchematics.sliced("onnx.*"), ); const llmLlamaMoeAdditionalLoadConfigSchematics = llmLoadSchematics.sliced( "numExperts", "numCpuExpertLayersRatio", "moeCacheMiB", ); export const llmLlamaMoeLoadConfigSchematics = llmLlamaLoadConfigSchematics.union( llmLlamaMoeAdditionalLoadConfigSchematics, ); export const llmMistralrsLoadConfigSchematics = llmSharedLoadConfigSchematics; export const embeddingLoadSchematics = globalConfigSchematics .scoped("embedding.load") .union(globalConfigSchematics.sliced("load.*")); export const embeddingSharedLoadConfigSchematics = embeddingLoadSchematics.sliced( "contextLength", "seed", ); export const retrievalSchematics = globalConfigSchematics.scoped("retrieval"); export const embeddingLlamaLoadConfigSchematics = embeddingSharedLoadConfigSchematics .union(embeddingLoadSchematics.sliced("llama.*")) .union(llamaLoadConfigSchematics); export const decisionLoadSchematics = globalConfigSchematics .scoped("decision.load") .union(globalConfigSchematics.sliced("envVars")) .union(llamaLoadConfigSchematics); export const decisionSharedLoadConfigSchematics = decisionLoadSchematics.sliced( "contextLength", "autoFitMinContextLength", "numParallelSessions", "useUnifiedKvCache", "envVars", ); export const decisionLlamaLoadConfigSchematics = decisionLoadSchematics; export const emptyConfigSchematics = new KVConfigSchematicsBuilder(kvValueTypesLibrary).build(); export const customFieldConfigSchematics = new KVConfigSchematicsBuilder(kvValueTypesLibrary) .extension(VIRTUAL_MODEL_CUSTOM_FIELD_EXTENSION_PREFIX) .build(); // ------------------ // 3. Utility types // ------------------ /** * LM Studio recognized config schematics. */ export type GlobalConfigSchematics = typeof globalConfigSchematics; type ValueTypeMap = typeof kvValueTypesLibrary extends KVFieldValueTypeLibrary ? RValueTypeMap : never; /** * Any config schematics that uses the value types defined in the type library. */ export type TypedConfigSchematics = KVConfigSchematics; /** * Any field filter that uses the value types defined in the type library. */ export type TypedConfigFieldFilter = InferConfigFieldFilter; export type GlobalKVValueTypeMap = InferValueTypeMap; /** * All the value type keys */ export type GlobalKVValueTypeKeys = InferValueTypeKeys; /** * Given a value type key, look up the typescript type of the value */ export type GlobalKVValueTypeValueTypeForKey = GlobalKVValueTypeMap[TKey]["value"]; /** * Given a value type key, look up the typescript type of the param */ export type GlobalKVValueTypeParamTypeForKey = GlobalKVValueTypeMap[TKey]["param"]; export type GlobalConfigSchemaMap = InferConfigSchemaMap; /** * All the config keys */ export type GlobalConfigSchemaKeys = InferConfigSchemaKeys; /** * Given a config key, look up the typescript type of the value */ export type GlobalConfigSchemaTypeForKey = GlobalConfigSchemaMap[TKey]["type"]; /** * Given a config key, look up the value type key */ export type GlobalConfigSchemaValueTypeKeyForKey = GlobalConfigSchemaMap[TKey]["valueTypeKey"];