@@ -77,28 +77,49 @@ def _gpu_offload_fields(
77
77
offload_settings : DictObject ,
78
78
) -> Sequence [KvConfigFieldDict ]:
79
79
fields : list [KvConfigFieldDict ] = []
80
- gpu_keys = (
81
- ("ratio" , f"{ endpoint } .load.llama.acceleration.offloadRatio" ),
82
- ("mainGpu" , "llama.load.mainGpu" ),
83
- ("splitStrategy" , "llama.load.splitStrategy" ),
84
- )
85
- for key , mapped_key in gpu_keys :
80
+ remaining_keys = set (offload_settings .keys ())
81
+ simple_gpu_keys = (("ratio" , f"{ endpoint } .load.llama.acceleration.offloadRatio" ),)
82
+ for key , mapped_key in simple_gpu_keys :
86
83
if key in offload_settings :
84
+ remaining_keys .remove (key )
87
85
fields .append ({"key" : mapped_key , "value" : offload_settings [key ]})
86
+ split_config_keys = ("mainGpu" , "splitStrategy" , "disabledGpus" )
87
+ split_config_settings : dict [str , Any ] = {}
88
+ for key in split_config_keys :
89
+ if key in offload_settings :
90
+ remaining_keys .remove (key )
91
+ split_config_settings [key ] = offload_settings [key ]
92
+ if split_config_settings :
93
+ fields .append ({"key" : "load.gpuSplitConfig" , "value" : split_config_settings })
94
+ if remaining_keys :
95
+ raise LMStudioValueError (
96
+ f"Unknown GPU offload settings: { sorted (remaining_keys )} "
97
+ )
88
98
return fields
89
99
90
100
91
101
# Some fields have different names in the client and server configs
102
+ # (this map has also been used to avoid adding new key categories for new setting scopes)
92
103
_CLIENT_TO_SERVER_KEYMAP = {
93
104
"maxTokens" : "maxPredictedTokens" ,
94
105
"rawTools" : "tools" ,
106
+ # "reasoning" scope
107
+ "reasoningParsing" : "reasoning.parsing" ,
108
+ # "speculativeDecoding" scope
109
+ "draftModel" : "speculativeDecoding.draftModel" ,
110
+ "speculativeDecodingNumDraftTokensExact" : "speculativeDecoding.numDraftTokensExact" ,
111
+ "speculativeDecodingMinDraftLengthToConsider" : "speculativeDecoding.minDraftLengthToConsider" ,
112
+ "speculativeDecodingMinContinueDraftingProbability" : "speculativeDecoding.minContinueDraftingProbability" ,
95
113
}
96
114
97
115
98
116
def _to_server_key (key : str ) -> str :
99
117
return _CLIENT_TO_SERVER_KEYMAP .get (key , key )
100
118
101
119
120
+ _NOT_YET_SUPPORTED_KEYS : set [str ] = set ()
121
+
122
+
102
123
def _to_kv_config_stack_base (
103
124
config : DictObject ,
104
125
namespace : str ,
@@ -114,9 +135,12 @@ def _to_kv_config_stack_base(
114
135
# TODO: Define a JSON or TOML data file for mapping prediction config
115
136
# fields to config stack entries (preferably JSON exported by
116
137
# lmstudio-js rather than something maintained in the Python SDK)
138
+ # https://github.com/lmstudio-ai/lmstudio-js/issues/253
139
+ remaining_keys = set (config .keys () - _NOT_YET_SUPPORTED_KEYS )
117
140
118
141
for client_key in checkbox_keys :
119
142
if client_key in config :
143
+ remaining_keys .remove (client_key )
120
144
server_key = _to_server_key (client_key )
121
145
fields .append (
122
146
_to_checkbox_kv (
@@ -125,12 +149,14 @@ def _to_kv_config_stack_base(
125
149
)
126
150
for client_key in simple_keys :
127
151
if client_key in config :
152
+ remaining_keys .remove (client_key )
128
153
server_key = _to_server_key (client_key )
129
154
fields .append (
130
155
_to_simple_kv (f"{ namespace } .{ request } " , server_key , config [client_key ])
131
156
)
132
157
for client_key in llama_keys :
133
158
if client_key in config :
159
+ remaining_keys .remove (client_key )
134
160
server_key = _to_server_key (client_key )
135
161
fields .append (
136
162
_to_simple_kv (
@@ -139,6 +165,7 @@ def _to_kv_config_stack_base(
139
165
)
140
166
for client_key in llama_checkbox_keys :
141
167
if client_key in config :
168
+ remaining_keys .remove (client_key )
142
169
server_key = _to_server_key (client_key )
143
170
fields .append (
144
171
_to_checkbox_kv (
@@ -149,8 +176,12 @@ def _to_kv_config_stack_base(
149
176
)
150
177
for gpu_offload_key in gpu_offload_keys :
151
178
if gpu_offload_key in config :
179
+ remaining_keys .remove (gpu_offload_key )
152
180
fields .extend (_gpu_offload_fields (namespace , config [gpu_offload_key ]))
153
181
182
+ if remaining_keys :
183
+ raise LMStudioValueError (f"Unknown config settings: { sorted (remaining_keys )} " )
184
+
154
185
return fields
155
186
156
187
@@ -180,6 +211,7 @@ def _to_kv_config_stack_base(
180
211
],
181
212
}
182
213
214
+
183
215
_EMBEDDING_LOAD_CONFIG_KEYS = {
184
216
"checkbox_keys" : [],
185
217
"simple_keys" : [
@@ -253,6 +285,11 @@ def load_config_to_kv_config_stack(
253
285
"topKSampling" ,
254
286
"toolCallStopStrings" ,
255
287
"rawTools" ,
288
+ "reasoningParsing" ,
289
+ "draftModel" ,
290
+ "speculativeDecodingNumDraftTokensExact" ,
291
+ "speculativeDecodingMinDraftLengthToConsider" ,
292
+ "speculativeDecodingMinContinueDraftingProbability" ,
256
293
],
257
294
"llama_keys" : [
258
295
"cpuThreads" ,
0 commit comments