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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: refuse a Train Split Start past the last row instead of training on one row (#17303)
Vineeth Sai Varikuntla0b4860e4dc55
diff --git a/studio/backend/core/training/dataset_bounds.py b/studio/backend/core/training/dataset_bounds.pyindex 286a36b6393..7f5a29fdb82 100644--- a/studio/backend/core/training/dataset_bounds.py+++ b/studio/backend/core/training/dataset_bounds.py@@ -240,3 +240,15 @@ def bound_dataset_rows(if on_bound is not None:on_bound(max_train_rows, total_rows)return bounded+++def slice_dataset_rows(dataset, start: Optional[int], end: Optional[int]):+ """Rows [start, end] inclusive, end clamped to the last row; returns (rows, start, end)."""+ total = len(dataset)+ start = max(0, start or 0)+ if start >= total:+ raise ValueError(+ f"Train Split Start {start} is past the last row of this dataset ({total} rows)."+ )+ end = max(start, min(total - 1 if end is None else end, total - 1))+ return dataset.select(range(start, end + 1)), start, enddiff --git a/studio/backend/core/training/trainer.py b/studio/backend/core/training/trainer.pyindex 233d9006117..7b2fa34e799 100644--- a/studio/backend/core/training/trainer.py+++ b/studio/backend/core/training/trainer.py@@ -116,7 +116,12 @@ from .training import (should_use_mlx_training_backend,)-from .dataset_bounds import bound_dataset_rows, world_size_env_report, world_size_from_env+from .dataset_bounds import (+ bound_dataset_rows,+ slice_dataset_rows,+ world_size_env_report,+ world_size_from_env,+)logger = get_logger(__name__)@@ -3635,11 +3640,9 @@ class UnslothTrainer:dataset_slice_start is not None or dataset_slice_end is not None):total_rows = len(dataset)- start = dataset_slice_start if dataset_slice_start is not None else 0- end = dataset_slice_end if dataset_slice_end is not None else total_rows - 1- start = max(0, min(start, total_rows - 1))- end = max(start, min(end, total_rows - 1))- dataset = dataset.select(range(start, end + 1))+ dataset, start, end = slice_dataset_rows(+ dataset, dataset_slice_start, dataset_slice_end+ )logger.info(f"Sliced dataset to rows [{start}, {end}]: {len(dataset)} of {total_rows} rows\n")diff --git a/studio/backend/core/training/worker.py b/studio/backend/core/training/worker.pyindex 74d22444cd6..f6728399d1c 100644--- a/studio/backend/core/training/worker.py+++ b/studio/backend/core/training/worker.py@@ -59,6 +59,7 @@ from core.training.dataset_bounds import (max_train_rows_for_config,record_row_bound,row_bound_for_resume,+ slice_dataset_rows,world_size_from_env,)from core.training.resume import _checkpoint_state, session_eta_seconds@@ -3509,12 +3510,8 @@ def _run_mlx_training(event_queue, stop_queue, config):if dataset_streaming:return _slice_streaming_dataset(ds, slice_start, slice_end)if slice_start is not None or slice_end is not None:- start = slice_start if slice_start is not None else 0- end = slice_end if slice_end is not None else len(ds) - 1- if end < start:- return ds.select([])# The user named these rows; the bound below defers to that.- return ds.select(range(start, min(end + 1, len(ds))))+ return slice_dataset_rows(ds, slice_start, slice_end)[0]if mlx_split_names_rows:return dsreturn bound_dataset_rows(@@ -6201,9 +6198,7 @@ def _run_embedding_training(event_queue: Any, stop_queue: Any, config: dict) ->slice_start = config.get("dataset_slice_start")slice_end = config.get("dataset_slice_end")if slice_start is not None or slice_end is not None:- start = slice_start if slice_start is not None else 0- end = slice_end if slice_end is not None else len(dataset)- dataset = dataset.select(range(start, min(end + 1, len(dataset))))+ dataset = slice_dataset_rows(dataset, slice_start, slice_end)[0]if csv_text_columns:kept = dataset.filter(diff --git a/studio/backend/tests/test_embedding_csv_cells_as_written.py b/studio/backend/tests/test_embedding_csv_cells_as_written.pyindex 377942f102e..e5d11f6881b 100644--- a/studio/backend/tests/test_embedding_csv_cells_as_written.py+++ b/studio/backend/tests/test_embedding_csv_cells_as_written.py@@ -188,6 +188,15 @@ def test_embedding_csv_slice_counts_rows_of_the_file(run_embedding):assert warnings == ["Dropped 1 of 3 rows because a text cell was empty."]+def test_embedding_slice_start_past_the_last_row_is_refused(run_embedding):+ run_embedding(+ "q,a\nq0,a0\nq1,a1\n",+ error = "Failed to load dataset: Train Split Start 5 is past the last row of this "+ "dataset (2 rows).",+ dataset_slice_start = 5,+ )++def test_embedding_csv_score_na_marker_outside_the_slice_still_trains(run_embedding):dataset, _ = run_embedding("s1,s2,score\naa,bb,0.5\ncc,dd,NA\n",diff --git a/studio/backend/tests/test_mlx_training_worker_config.py b/studio/backend/tests/test_mlx_training_worker_config.pyindex 6d7c9b03f5a..348d5e97814 100644--- a/studio/backend/tests/test_mlx_training_worker_config.py+++ b/studio/backend/tests/test_mlx_training_worker_config.py@@ -842,6 +842,29 @@ def test_mlx_slice_reads_a_stream_lazily():assert calls == [("skip", 2), ("take", 3)][email protected]("slice_start, slice_end", [(2, 4), (50, None)])+def test_mlx_slice_clamps_the_end_and_refuses_a_start_past_the_last_row(slice_start, slice_end):+ from datasets import Dataset++ body = ast.parse(textwrap.dedent(inspect.getsource(_worker._run_mlx_training))).body[0].body+ nodes = [n for n in body if isinstance(n, ast.FunctionDef) and n.name == "_slice"]+ namespace = {+ **vars(_worker),+ "dataset_streaming": False,+ "slice_start": slice_start,+ "slice_end": slice_end,+ "mlx_split_names_rows": False,+ }+ exec(compile(ast.Module(body = nodes, type_ignores = []), "<slice>", "exec"), namespace)+ rows = Dataset.from_list([{"i": i} for i in range(4)])++ if slice_start >= 4:+ with pytest.raises(ValueError, match = "Train Split Start 50 is past the last row"):+ namespace["_slice"](rows)+ else:+ assert namespace["_slice"](rows)["i"] == [2, 3]++def _run_mlx_assignment(target, **names):body = ast.parse(textwrap.dedent(inspect.getsource(_worker._run_mlx_training))).body[0].bodynodes = [n for n in body if isinstance(n, ast.Assign) and ast.unparse(n.targets[0]) == target]diff --git a/studio/backend/tests/test_training_preflight.py b/studio/backend/tests/test_training_preflight.pyindex 260d3864567..e0ff95f8b59 100644--- a/studio/backend/tests/test_training_preflight.py+++ b/studio/backend/tests/test_training_preflight.py@@ -579,6 +579,56 @@ def test_max_steps_bound_defers_to_an_explicit_slice(monkeypatch):assert sliced.shuffle_seeds == [][email protected]("slice_start, slice_end", [(50, 60), (50, None), (10, None)])+def test_explicit_slice_start_past_the_last_row_is_refused(monkeypatch, slice_start, slice_end):+ from hub.utils import dataset_cache++ trainer = _cached_only_loader(monkeypatch, _SizedDataset(10))+ monkeypatch.setattr(+ dataset_cache,+ "load_cached_hf_dataset",+ lambda *args, **kwargs: _SizedDataset(10),+ )+ updates = []+ trainer._update_progress = lambda **kwargs: updates.append(kwargs)++ result = trainer.load_and_format_dataset(+ "org/dataset",+ dataset_local_files_only = True,+ dataset_local_path = "/cache/snapshot",+ dataset_slice_start = slice_start,+ dataset_slice_end = slice_end,+ )++ assert result is None+ errors = [u["error"] for u in updates if "error" in u]+ assert errors == [+ f"Train Split Start {slice_start} is past the last row of this dataset (10 rows)."+ ]+++def test_explicit_slice_end_past_the_last_row_still_clamps(monkeypatch):+ from hub.utils import dataset_cache++ trainer = _cached_only_loader(monkeypatch, _SizedDataset(10))+ monkeypatch.setattr(+ dataset_cache,+ "load_cached_hf_dataset",+ lambda *args, **kwargs: _SizedDataset(10),+ )++ result = trainer.load_and_format_dataset(+ "org/dataset",+ dataset_local_files_only = True,+ dataset_local_path = "/cache/snapshot",+ dataset_slice_start = 6,+ dataset_slice_end = 60,+ )++ assert result is not None+ assert len(result[0]["dataset"]) == 4++def test_max_steps_bound_defers_to_a_split_instruction(monkeypatch):train = _SizedDataset(500_000)trainer = _cached_only_loader(monkeypatch, train)