Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

fix: cap dataset.map() num_proc to 8 to prevent CUDA fork deadlocks

Roland Tannous3d0d1c702014
diff --git a/studio/backend/utils/datasets/chat_templates.py b/studio/backend/utils/datasets/chat_templates.py
index e3b1bef3159..3f6d73377ea 100644
--- a/studio/backend/utils/datasets/chat_templates.py
+++ b/studio/backend/utils/datasets/chat_templates.py
@@ -285,7 +285,7 @@ def apply_chat_template_to_dataset(
if not isinstance(dataset, IterableDataset):
from multiprocessing import cpu_count
if num_proc is None or type(num_proc) is not int:
- num_proc = cpu_count()
+ num_proc = min(cpu_count(), 8)
dataset_map_kwargs['num_proc'] = num_proc
dataset_map_kwargs['desc'] = "Applying template to Alpaca format"
@@ -349,7 +349,7 @@ def apply_chat_template_to_dataset(
if not isinstance(dataset, IterableDataset):
from multiprocessing import cpu_count
if num_proc is None or type(num_proc) is not int:
- num_proc = cpu_count()
+ num_proc = min(cpu_count(), 8)
dataset_map_kwargs['num_proc'] = num_proc
dataset_map_kwargs['desc'] = f"Applying chat template to {final_format}"
diff --git a/studio/backend/utils/datasets/format_conversion.py b/studio/backend/utils/datasets/format_conversion.py
index 9367741e8e2..df2ff95fc86 100644
--- a/studio/backend/utils/datasets/format_conversion.py
+++ b/studio/backend/utils/datasets/format_conversion.py
@@ -110,7 +110,7 @@ def standardize_chat_format(
from multiprocessing import cpu_count
if num_proc is None or type(num_proc) is not int:
- num_proc = cpu_count()
+ num_proc = min(cpu_count(), 8)
dataset_map_kwargs['num_proc'] = num_proc
dataset_map_kwargs['desc'] = "Standardizing chat format"
@@ -176,7 +176,7 @@ def convert_chatml_to_alpaca(dataset, batch_size=1000, num_proc=None):
from multiprocessing import cpu_count
if num_proc is None or type(num_proc) is not int:
- num_proc = cpu_count()
+ num_proc = min(cpu_count(), 8)
dataset_map_kwargs['num_proc'] = num_proc
dataset_map_kwargs['desc'] = "Converting ChatML to Alpaca format"
@@ -224,7 +224,7 @@ def convert_alpaca_to_chatml(dataset, batch_size=1000, num_proc=None):
from multiprocessing import cpu_count
if num_proc is None or type(num_proc) is not int:
- num_proc = cpu_count()
+ num_proc = min(cpu_count(), 8)
dataset_map_kwargs['num_proc'] = num_proc
dataset_map_kwargs['desc'] = "Converting Alpaca to ChatML format"