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: do not upload the seed token when publishing a dataset (#11230)
Nilay7c5ce3419c1f
diff --git a/studio/backend/core/data_recipe/huggingface.py b/studio/backend/core/data_recipe/huggingface.pyindex 624b92a48bb..1be9b4f00d7 100644--- a/studio/backend/core/data_recipe/huggingface.py+++ b/studio/backend/core/data_recipe/huggingface.py@@ -6,6 +6,7 @@ from __future__ import annotationsfrom core.training.account_jobs import account_hf_tokenimport jsonfrom pathlib import Path+import tempfilefrom utils.paths import recipe_datasets_root, resolve_dataset_path@@ -48,6 +49,12 @@ def _resolve_recipe_artifact_path(artifact_path: str) -> Path:return resolved+def _drop_seed_token(builder_config: dict) -> None:+ # The hf and github_repo seed sources save their token in plain text.+ seed_config = builder_config.get("data_designer", {}).get("seed_config") or {}+ seed_config.get("source", {}).pop("token", None)++def publish_recipe_dataset(*,artifact_path: str,@@ -95,6 +102,7 @@ def publish_recipe_dataset(if builder_config_path.exists():with builder_config_path.open(encoding = "utf-8") as fh:builder_config = json.load(fh)+ _drop_seed_token(builder_config)card = DataDesignerDatasetCard.from_metadata(metadata = metadata,@@ -119,11 +127,16 @@ def publish_recipe_dataset(repo_id = repo_id,processors_folder = dataset_path / PROCESSORS_OUTPUTS_FOLDER_NAME,)- client._upload_config_files(- repo_id = repo_id,- metadata_path = metadata_path,- builder_config_path = builder_config_path,- )+ with tempfile.TemporaryDirectory() as scrubbed_dir:+ scrubbed_config_path = Path(scrubbed_dir) / SDG_CONFIG_FILENAME+ if builder_config is not None:+ with scrubbed_config_path.open("w", encoding = "utf-8") as fh:+ json.dump(builder_config, fh, indent = 2, ensure_ascii = False)+ client._upload_config_files(+ repo_id = repo_id,+ metadata_path = metadata_path,+ builder_config_path = scrubbed_config_path,+ )from utils.hf_endpoint import get_hf_endpointdiff --git a/studio/backend/tests/test_data_recipe_publish_seed_token.py b/studio/backend/tests/test_data_recipe_publish_seed_token.pynew file mode 100644index 00000000000..70b2f3aeabc--- /dev/null+++ b/studio/backend/tests/test_data_recipe_publish_seed_token.py@@ -0,0 +1,122 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import json+import sys+from types import ModuleType, SimpleNamespace++import pytest++from core.data_recipe import huggingface as recipe_hf++_SOURCES = [+ {+ "seed_type": "hf",+ "path": "datasets/org/name/data/*.parquet",+ "token": "hf_FAKEFAKEFAKE",+ "endpoint": "https://huggingface.co",+ },+ {"seed_type": "github_repo", "repos": ["org/name"], "token": "ghp_FAKEFAKEFAKE"},+]+++def _stub_data_designer(monkeypatch, seen):+ class _UploadError(Exception):+ pass++ class _Client:+ def __init__(self, token):+ pass++ def __getattr__(self, name):+ return lambda **kwargs: None++ def _upload_config_files(self, *, repo_id, metadata_path, builder_config_path):+ # The real client gates each of the two files on .exists() on its own.+ if metadata_path.exists():+ seen["uploaded_metadata"] = metadata_path.name+ if builder_config_path.exists():+ seen["uploaded"] = builder_config_path.read_text(encoding = "utf-8")+ seen["uploaded_name"] = builder_config_path.name++ class _Card:+ @classmethod+ def from_metadata(cls, *, builder_config, **kwargs):+ seen["card"] = json.dumps(builder_config)+ return SimpleNamespace(text = "", push_to_hub = lambda *args, **kwargs: None)++ modules = {+ "data_designer.engine.storage.artifact_storage": {+ "FINAL_DATASET_FOLDER_NAME": "parquet-files",+ "METADATA_FILENAME": "metadata.json",+ "PROCESSORS_OUTPUTS_FOLDER_NAME": "processors-files",+ "SDG_CONFIG_FILENAME": "builder_config.json",+ },+ "data_designer.integrations.huggingface.client": {+ "HuggingFaceHubClient": _Client,+ "HuggingFaceHubClientUploadError": _UploadError,+ },+ "data_designer.integrations.huggingface.dataset_card": {+ "DataDesignerDatasetCard": _Card,+ },+ }+ for name, attrs in modules.items():+ module = ModuleType(name)+ for key, value in attrs.items():+ setattr(module, key, value)+ monkeypatch.setitem(sys.modules, name, module)+++def _publish(monkeypatch, tmp_path, builder_config):+ seen: dict = {}+ _stub_data_designer(monkeypatch, seen)+ monkeypatch.setattr(recipe_hf, "_resolve_recipe_artifact_path", lambda _: tmp_path)+ (tmp_path / "metadata.json").write_text("{}", encoding = "utf-8")+ if builder_config is not None:+ (tmp_path / "builder_config.json").write_text(json.dumps(builder_config), encoding = "utf-8")+ recipe_hf.publish_recipe_dataset(+ artifact_path = str(tmp_path),+ repo_id = "org/dataset",+ description = "d",+ hf_token = "hf_publish",+ )+ return seen++[email protected]("source", _SOURCES)+def test_publish_keeps_the_seed_token_out_of_the_hub(monkeypatch, tmp_path, source):+ recipe = {+ "columns": [{"name": "c", "column_type": "expression", "token": "kept"}],+ "seed_config": {"source": source, "sampling_strategy": "ordered"},+ }+ builder_config = {"data_designer": recipe, "library_version": "0.5.4"}+ seen = _publish(monkeypatch, tmp_path, builder_config)++ assert seen["uploaded_name"] == "builder_config.json"+ assert "FAKEFAKEFAKE" not in seen["uploaded"]+ assert "FAKEFAKEFAKE" not in seen["card"]++ expected_source = {k: v for k, v in source.items() if k != "token"}+ assert json.loads(seen["uploaded"]) == {+ "data_designer": {+ **recipe,+ "seed_config": {"source": expected_source, "sampling_strategy": "ordered"},+ },+ "library_version": "0.5.4",+ }++ on_disk = json.loads((tmp_path / "builder_config.json").read_text(encoding = "utf-8"))+ assert on_disk == builder_config+++def test_publish_without_a_seed_uploads_the_config_unchanged(monkeypatch, tmp_path):+ builder_config = {"data_designer": {"columns": [], "seed_config": None}}+ seen = _publish(monkeypatch, tmp_path, builder_config)+ assert json.loads(seen["uploaded"]) == builder_config+++def test_publish_without_a_builder_config_uploads_none(monkeypatch, tmp_path):+ seen = _publish(monkeypatch, tmp_path, None)+ assert seen["uploaded_metadata"] == "metadata.json"+ assert "uploaded" not in seen+ assert seen["card"] == "null"