File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change
1
+ import os
1
2
from dataclasses import dataclass
2
3
from threading import Condition , Event
3
4
from typing import Any , Literal , Optional , overload
@@ -295,7 +296,7 @@ def sample(
295
296
draws : int ,
296
297
tune : int ,
297
298
chains : int ,
298
- cores : int ,
299
+ cores : Optional [ int ] ,
299
300
seed : Optional [int ],
300
301
save_warmup : bool ,
301
302
progress_bar : bool ,
@@ -313,7 +314,7 @@ def sample(
313
314
draws : int ,
314
315
tune : int ,
315
316
chains : int ,
316
- cores : int ,
317
+ cores : Optional [ int ] ,
317
318
seed : Optional [int ],
318
319
save_warmup : bool ,
319
320
progress_bar : bool ,
@@ -330,7 +331,7 @@ def sample(
330
331
draws : int = 1000 ,
331
332
tune : int = 300 ,
332
333
chains : int = 6 ,
333
- cores : int = 6 ,
334
+ cores : Optional [ int ] = None ,
334
335
seed : Optional [int ] = None ,
335
336
save_warmup : bool = True ,
336
337
progress_bar : bool = True ,
@@ -408,6 +409,14 @@ def sample(
408
409
for name , val in kwargs .items ():
409
410
setattr (settings , name , val )
410
411
412
+ if cores is None :
413
+ try :
414
+ # Only available in python>=3.13
415
+ available = os .process_cpu_count ()
416
+ except AttributeError :
417
+ available = os .cpu_count ()
418
+ cores = min (chains , available )
419
+
411
420
if init_mean is None :
412
421
init_mean = np .zeros (compiled_model .n_dim )
413
422
You can’t perform that action at this time.
0 commit comments