@@ -67,12 +67,12 @@ class ModelSettings(BaseSettings):
67
67
n_threads : int = Field (
68
68
default = max (multiprocessing .cpu_count () // 2 , 1 ),
69
69
ge = 1 ,
70
- description = "The number of threads to use." ,
70
+ description = "The number of threads to use. Use -1 for max cpu threads " ,
71
71
)
72
72
n_threads_batch : int = Field (
73
73
default = max (multiprocessing .cpu_count () // 2 , 1 ),
74
74
ge = 0 ,
75
- description = "The number of threads to use when batch processing." ,
75
+ description = "The number of threads to use when batch processing. Use -1 for max cpu threads " ,
76
76
)
77
77
rope_scaling_type : int = Field (
78
78
default = llama_cpp .LLAMA_ROPE_SCALING_TYPE_UNSPECIFIED
@@ -163,6 +163,15 @@ class ModelSettings(BaseSettings):
163
163
verbose : bool = Field (
164
164
default = True , description = "Whether to print debug information."
165
165
)
166
+ @root_validator (pre = True ) # pre=True to ensure this runs before any other validation
167
+ def set_dynamic_defaults (cls , values ):
168
+ # If n_threads or n_threads_batch is -1, set it to multiprocessing.cpu_count()
169
+ cpu_count = multiprocessing .cpu_count ()
170
+ if values .get ('n_threads' , 0 ) == - 1 :
171
+ values ['n_threads' ] = cpu_count
172
+ if values .get ('n_threads_batch' , 0 ) == - 1 :
173
+ values ['n_threads_batch' ] = cpu_count
174
+ return values
166
175
167
176
168
177
class ServerSettings (BaseSettings ):
0 commit comments