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: include Schema transform output in recipe dataset downloads (#16039)
Nilaya90de04e159f
diff --git a/studio/backend/core/data_recipe/export.py b/studio/backend/core/data_recipe/export.pyindex 10f07d7ab92..33ae38702a2 100644--- a/studio/backend/core/data_recipe/export.py+++ b/studio/backend/core/data_recipe/export.py@@ -211,6 +211,17 @@ def _artifact_image_files(dataset_path: Path) -> list[Path]:]+def _processor_parquet_dirs(dataset_path: Path) -> list[Path]:+ processors_dir = dataset_path / "processors-files"+ if not processors_dir.is_dir():+ return []+ return [+ path+ for path in drop_appledouble_metadata(sorted(processors_dir.iterdir()))+ if path.is_dir() and _parquet_files(path)+ ]++def download_filename(*, artifact_path: str, export_format: ExportFormat, stem: str) -> str:"""The name the export will have, and the checks ``build_dataset_download`` will make, so arun whose shards are gone is refused while the caller can still be told."""@@ -221,7 +232,9 @@ def download_filename(*, artifact_path: str, export_format: ExportFormat, stem:_parquet_dir(dataset_path)if export_format == "parquet":return f"{stem}.parquet.zip"- return f"{stem}.jsonl.zip" if _artifact_image_files(dataset_path) else f"{stem}.jsonl"+ if _artifact_image_files(dataset_path) or _processor_parquet_dirs(dataset_path):+ return f"{stem}.jsonl.zip"+ return f"{stem}.jsonl"def _add_images_to_archive(archive: zipfile.ZipFile, dataset_path: Path) -> None:@@ -261,6 +274,14 @@ def build_dataset_download(with zipfile.ZipFile(zip_path, "w", compression = zipfile.ZIP_DEFLATED) as archive:for parquet_file in _parquet_files(parquet_dir):archive.write(parquet_file, arcname = parquet_file.name)+ for processor_dir in _processor_parquet_dirs(dataset_path):+ for parquet_file in _parquet_files(processor_dir):+ archive.write(+ parquet_file,+ arcname = str(+ Path("processors") / processor_dir.name / parquet_file.name+ ),+ )_add_images_to_archive(archive, dataset_path)except BaseException:zip_path.unlink(missing_ok = True)@@ -273,15 +294,22 @@ def build_dataset_download(try:_write_jsonl_from_parquet(parquet_dir, jsonl_path)image_files = _artifact_image_files(dataset_path)- if not image_files:+ processor_dirs = _processor_parquet_dirs(dataset_path)+ if not image_files and not processor_dirs:return jsonl_path, "application/x-ndjson", f"{stem}.jsonl"- # Rows reference these by relative path, so a bare JSONL loses every image.+ # Rows reference images by relative path, so a bare JSONL loses every image.zip_tmp = tempfile.NamedTemporaryFile(delete = False, suffix = ".zip")zip_tmp.close()zip_path = Path(zip_tmp.name)try:with zipfile.ZipFile(zip_path, "w", compression = zipfile.ZIP_DEFLATED) as archive:archive.write(jsonl_path, arcname = f"{stem}.jsonl")+ for processor_dir in processor_dirs:+ _write_jsonl_from_parquet(processor_dir, jsonl_path)+ archive.write(+ jsonl_path,+ arcname = str(Path("processors") / f"{processor_dir.name}.jsonl"),+ )_add_images_to_archive(archive, dataset_path)except BaseException:zip_path.unlink(missing_ok = True)diff --git a/studio/backend/tests/test_data_recipe_dataset_download.py b/studio/backend/tests/test_data_recipe_dataset_download.pyindex 76266e6fa8a..faf35608f63 100644--- a/studio/backend/tests/test_data_recipe_dataset_download.py+++ b/studio/backend/tests/test_data_recipe_dataset_download.py@@ -750,6 +750,146 @@ def test_jsonl_export_stays_a_plain_file_without_images(tmp_path: Path, monkeypafile_path.unlink(missing_ok = True)+def _schema_transform_artifact(tmp_path: Path, monkeypatch) -> Path:+ dataset_path = tmp_path / "recipe-datasets" / "job-schema-transform"+ _write_parquet_rows(dataset_path / "parquet-files", [{"question": "Q1", "answer": "A1"}])+ _write_parquet_rows(+ dataset_path / "processors-files" / "chat_format",+ [+ {+ "messages": [+ {"role": "user", "content": "Q1"},+ {"role": "assistant", "content": "A1"},+ ]+ }+ ],+ )+ monkeypatch.setattr(+ "core.data_recipe.export._resolve_recipe_artifact_path",+ lambda artifact_path: dataset_path,+ )+ return dataset_path+++def test_jsonl_export_includes_schema_transform_output(tmp_path: Path, monkeypatch):+ dataset_path = _schema_transform_artifact(tmp_path, monkeypatch)++ from core.data_recipe.export import download_filename++ assert (+ download_filename(artifact_path = str(dataset_path), export_format = "jsonl", stem = "run")+ == "run.jsonl.zip"+ )+ file_path, media_type, download_name = build_dataset_download(+ artifact_path = str(dataset_path),+ export_format = "jsonl",+ filename_stem = "run",+ )+ try:+ assert (media_type, download_name) == ("application/zip", "run.jsonl.zip")+ with zipfile.ZipFile(file_path) as archive:+ names = sorted(archive.namelist())+ rows = archive.read("run.jsonl").decode("utf-8")+ transformed = archive.read("processors/chat_format.jsonl").decode("utf-8")+ finally:+ file_path.unlink(missing_ok = True)+ assert names == ["processors/chat_format.jsonl", "run.jsonl"]+ assert json.loads(rows.strip()) == {"question": "Q1", "answer": "A1"}+ assert json.loads(transformed.strip()) == {+ "messages": [+ {"role": "user", "content": "Q1"},+ {"role": "assistant", "content": "A1"},+ ]+ }+++def test_parquet_export_includes_schema_transform_output(tmp_path: Path, monkeypatch):+ dataset_path = _schema_transform_artifact(tmp_path, monkeypatch)++ file_path, _, _ = build_dataset_download(+ artifact_path = str(dataset_path),+ export_format = "parquet",+ filename_stem = "run",+ )+ try:+ with zipfile.ZipFile(file_path) as archive:+ names = sorted(archive.namelist())+ finally:+ file_path.unlink(missing_ok = True)+ assert names == ["batch_00000.parquet", "processors/chat_format/batch_00000.parquet"]+++ ("export_format", "expected"),+ [+ (+ "jsonl",+ [+ "images/a.png",+ "processors/alpaca.jsonl",+ "processors/chat_format.jsonl",+ "run.jsonl",+ ],+ ),+ (+ "parquet",+ [+ "batch_00000.parquet",+ "images/a.png",+ "processors/alpaca/batch_00000.parquet",+ "processors/chat_format/batch_00000.parquet",+ ],+ ),+ ],+)+def test_export_includes_every_schema_transform_beside_images(+ tmp_path: Path, monkeypatch, export_format: str, expected: list[str]+):+ dataset_path = _schema_transform_artifact(tmp_path, monkeypatch)+ _write_parquet_rows(dataset_path / "processors-files" / "alpaca", [{"instruction": "Q1"}])+ (dataset_path / "images").mkdir()+ (dataset_path / "images" / "a.png").write_bytes(b"png")++ file_path, _, _ = build_dataset_download(+ artifact_path = str(dataset_path),+ export_format = export_format,+ filename_stem = "run",+ )+ try:+ with zipfile.ZipFile(file_path) as archive:+ assert sorted(archive.namelist()) == expected+ if export_format == "jsonl":+ alpaca = archive.read("processors/alpaca.jsonl").decode("utf-8")+ assert json.loads(alpaca.strip()) == {"instruction": "Q1"}+ finally:+ file_path.unlink(missing_ok = True)+++def test_jsonl_export_stays_plain_when_no_transform_wrote_shards(tmp_path: Path, monkeypatch):+ dataset_path = tmp_path / "recipe-datasets" / "job-empty-transform"+ _write_parquet_rows(dataset_path / "parquet-files", [{"question": "Q1"}])+ (dataset_path / "processors-files" / "empty").mkdir(parents = True)+ (dataset_path / "processors-files" / "preview.parquet").write_bytes(b"not a folder")+ monkeypatch.setattr(+ "core.data_recipe.export._resolve_recipe_artifact_path",+ lambda artifact_path: dataset_path,+ )++ from core.data_recipe.export import download_filename++ assert (+ download_filename(artifact_path = str(dataset_path), export_format = "jsonl", stem = "run")+ == "run.jsonl"+ )+ file_path, media_type, download_name = build_dataset_download(+ artifact_path = str(dataset_path),+ export_format = "jsonl",+ filename_stem = "run",+ )+ file_path.unlink(missing_ok = True)+ assert (media_type, download_name) == ("application/x-ndjson", "run.jsonl")++def test_jsonl_reader_preserves_columns_named_like_old_reader_helpers(tmp_path: Path):from core.data_recipe.export import _write_jsonl_from_parquet