Repository navigation
Studio: MCP agents upload datasets, load what they trained, and download models ahead of time - #14107
Merged
danielhanchen merged 202 commits intoOct 19, 2026
Conversation
…_datasets Adds the MCP output classes this PR uses (DatasetUpload, ImageDatasetUpload, DownloadRef, JobStatus.download, TrainingStarted.config, LocalDataset.ref). The upload route returns the raw stored path to API-key callers, so the tool mints the ref itself and never echoes the path.
…rainable TTS validate_only now runs the trainer's audio-type detection, refuses GGUF, audio.cpp and native text-to-speech ids, sets is_dataset_audio for codec TTS (Orpheus/SNAC, CSM, Spark/BiCodec, OuteTTS/DAC), and echoes the validated config with every path and secret dropped. The start_training docstring names the trainable TTS bases, their columns and the one-GPU order.
…aset Sends captioned images to the diffusion dataset route with fresh file stems, so a later upload never replaces an earlier image, and returns the dataset name start_training kind "diffusion" takes as data_dir, never its path.
Adds exactly /api/hub/download to the MCP allowlist (download, download-status, download-progress and download/cancel; nothing else under /api/hub) and a model_downloads module that stages GGUF, safetensors and diffusion downloads, follows and stops them by one id, and waits for a managed download before a load (K16 guard 2). The tools wire it up once the parent PR's load changes merge.
… load unloads
- get_job takes wait_s (0-240 s): it re-reads the job every 2 s, reports
progress, and returns when the job finishes, its status or phase changes,
or the wait runs out, with poll_after_s for a job still running. New kinds:
training and diffusion_training (run folder and checkpoint names once
completed) and load.
- load_model takes wait_s (unset: 240 s). The load runs as a job in a new
studio_mcp/job_store.py, so a client that stops waiting never stops it; an
early return gives status "loading" and a job_id for get_job(kind="load"),
and a repeat call follows the load in flight.
- Loads report evicted_slots ({kind, model}) from the load answer's
evicted_slots, else its evicted ids placed by a resident snapshot, else a
before/after diff of the chat, image and video slots. unload_model echoes
the kind asked for.
- export_jobs.py is a thin wrapper over the job store.
…-use-ace31b0b542c
…ad, and queue videos - load_model: image/video memory knobs (memory_mode, speed_mode, transformer_quant, text_encoder_quant, h3_task) and llm/tts/audio placement (device, alongside, kv_cache_type, gpu_layers); placement echoed on LoadResult and the image/video slots. - plan_load previews variants, download bytes, residents and what a load would unload. - A GGUF variant only partly on disk, and not downloading under Unsloth Studio, is refused. - unload_model(kind="all") frees every chat, speech, image, video and STT model. - generate_video queues a clip Unsloth Studio is too busy for and submits it in order.
download_model stages a model in Unsloth Studio's download manager without loading it; get_job(kind="download") follows it and cancel(kind="model_download") stops it by the id it returns. load_model takes a training checkpoint or an export by name, loads it by a minted ref: handle, and reports the name back, never a path or the handle. is_lora follows the run's PEFT type (the load route detects LoRA itself), and checkpoint/export are refused for image, video and stt.
… arbiter that tracks residents Stores the mode in the owner's database with a bool-first migration, extends /api/settings/multi-model, and gives acquire_for a policy, an eviction report and per-owner residents. Adds the response fields, the MCP mode read, the padded-error headers and the structured out_of_memory check.
… failed read, and keep media evictions - A chat load started elsewhere is followed only when no variant is asked for (the status names only the repo), and a repeat call follows a load only with the same variant and settings. - Following a load skips a failed status read instead of failing. - A route's chat-only evicted list no longer hides an image or video model the load also unloaded; evicted is built from evicted_slots. - Progress keeps its last fraction through a step that reports none.
…o-use-ace31b0b542c # Conflicts: # studio/backend/studio_mcp/tools/cancel.py # studio/backend/studio_mcp/tools/jobs.py # studio/backend/studio_mcp/tools/models.py # studio/backend/tests/test_mcp_no_host_paths.py
…on a change says to look again at once
…eckpoints as LoRA K16 guard 2: before M7's partial-variant refusal, load_model waits up to 240 s on an Unsloth Studio download of the same model or variant, then reports it with the id get_job(kind="download") follows; a managed download is waited on, never refused. Checkpoint and export loads skip both guards and pass is_lora from the run's PEFT type. The LLM load poll no longer asks the Hub about a ref: handle. Adds the download_model row to MCP.md.
- plan_load treats another variant of a resident GGUF repo as a new load. - plan_load reports 0 bytes when nothing is left to download. - unload_model(kind="all") also unloads models held behind the active one. - A media GGUF that an image or video load is already downloading is not refused. - The video queue keeps a clip queued through a network error and ignores stale clip times.
…o-use-ace31b0b542c # Conflicts: # studio/backend/studio_mcp/tools/jobs.py # studio/backend/studio_mcp/tools/models.py
…load-placement # Conflicts: # studio/backend/studio_mcp/loading.py
…heckpoints Now that get_job waits on training and loads, start_training points agents at get_job(kind="training", wait_s=50) instead of studio_status. A checkpoint or export load names any evicted_slots entry back from its ref: handle, the download wait skips ref: handles, get_job(kind="download") has a poll_after_s, and the K16 tests cover attach before the download wait before the partial refusal.
…o-use-ace31b0b542c # Conflicts: # studio/backend/studio_mcp/loading.py
…d report every model a load unloads Always is enforced in the arbiter for chat and media, at the primary-replace guard (same repo allowed), in the kept-slot retry loop and before the H3 image unload. The refusal answers 409 with X-Unsloth-Refusal everywhere, the OpenAI envelope on /v1 and auto-switch, and the existing 503 on /p. Chat, image and video loads list what they unloaded in evicted_slots, and callers that assumed one GPU owner now ask holds().
…l/unsloth into Etherll/mcp-long-work-evictions
… the Always refusal on every surface
…l/unsloth into Etherll/mcp-long-work-evictions
…i#14088) into Etherll/mcp-load-placement
…ining, not loads)
…xport Unsloth Studio serves a checkpoint under its ref: handle, so chat(model=<name>) answers from the active model with a mismatch note. The checkpoint and export fields now say to chat with model unset; the GPU run hit this.
…o-use-ace31b0b542c
…ll/unsloth into r14107 # Conflicts: # studio/backend/studio_mcp/loading.py [skip ci]
# Conflicts: # studio/backend/core/inference/gpu_arbiter.py
# Conflicts: # studio/backend/routes/inference.py
# Conflicts: # studio/MCP.md # studio/backend/studio_mcp/loading.py # studio/backend/studio_mcp/tools/jobs.py # studio/backend/studio_mcp/tools/models.py
# Conflicts: # studio/backend/tests/test_mcp_tools_loading.py
# Conflicts: # studio/MCP.md # studio/backend/studio_mcp/outputs.py # studio/backend/studio_mcp/tools/jobs.py # studio/backend/studio_mcp/tools/models.py # studio/backend/studio_mcp/tools/video.py # studio/backend/tests/test_mcp_server.py # studio/backend/tests/test_mcp_tools_status.py
# Conflicts: # studio/MCP.md # studio/backend/studio_mcp/tools/cancel.py # studio/backend/studio_mcp/tools/models.py # studio/backend/tests/test_mcp_no_host_paths.py # studio/backend/tests/test_mcp_tools_cancel.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Includes #14088, #14089 and #14090; review the last 24 commits (7cbecec..HEAD:
git log --no-merges 06a089d2d1..HEAD), leaving out the merges of #14090's branch.Summary
Over MCP, an agent could start training in Unsloth Studio, but it could not upload its own data, load the model it had trained, or download the next model ahead of time. This PR adds dataset uploads, loading a checkpoint or export by name, a resolved
validate_onlyecho, TTS fine-tuning guidance, and adownload_modeltool backed by Unsloth Studio's download manager.Changes
Datasets
datasets(action="upload", filename, data_base64 | rows)sends a file to/api/hub/datasets/upload. It returns aref:handle forconfig.local_datasets, never the stored path the route returns.datasets(action="upload_images", name, images, captions)sends captioned images to the diffusion dataset route. Every image gets a fresh file stem, so a later upload never replaces an earlier one. Images past Unsloth Studio's upload limit are refused before anything is sent, with a note to split them across calls. It returns the dataset name thatstart_training(kind="diffusion")takes asdata_dir.Loading what you trained
load_model(checkpoint="<run>" | "<run>/checkpoint-N")resolves the name throughcheckpoints.resolve.load_model(export="<name>")resolves it under the exports folder, andvariantpicks a GGUF export's quantization.ref:handle and report the name back, never a path or the handle.evicted_slotsentries get their names back the same way, and so does theget_job(kind="load")result of a load that outlastedwait_s.unload_model(model=<that name>)finds it.is_lorafollows the run's PEFT type, passed through Studio: MCP agents choose how and where a model loads, preview the load, and queue videos #14090'sis_lorakwarg. The load route detects LoRA itself, so a full fine-tune is not forced to load as LoRA.variantpassed, sodevice="cpu"places it as GGUF. An export whose file name has no quantization needsvariantbefore it can be placed. A checkpoint is refused fordevice="cpu".checkpointandexportare refused forkindimage, video and stt.ref:handle, so the field text says to chat with it by leavingchat'smodelunset.start_trainingvalidate_onlynow returns the resolved config, with every path and secret dropped.ref:handle resolves to.is_dataset_audiofor codec TTS: Orpheus/SNAC, CSM, Spark/BiCodec and OuteTTS/DAC. A real start runs the same check, so it refuses the same models and sendsis_dataset_audiofor codec TTS.unsloth/orpheus-3b-0.1-ft,sesame/csm-1b,unsloth/Spark-TTS-0.5Bandunsloth/Llama-OuteTTS-1.0-1B. It covers:custom_format_mappingroles;load_model(checkpoint/export)→generate_audio.get_job(kind="training", wait_s=50)instead ofstudio_status.Prefetch
ALLOWED_PREFIXESgains exactly/api/hub/download. That covers/download,/download-status,/download-progressand/download/cancel, and nothing else under/api/hub.download_model(model, kind, variant?)starts a download without loading anything. GGUF repos sendgguf_variant, image and video send their download-plan entries withscope_id="diffusion", a native TTS or audio model sends its audio download-plan entries (companion codec repos included) withscope_id="audio", and STT reusesdownload_stt. Image and video downloads take the same optionsload_modeltakes (memory_mode,speed_mode,transformer_quant,text_encoder_quant,h3_task), so the plan stages the files the load will read.generation, socancel(kind="model_download", id)(through/download/cancel) stops only the rundownload_modelstarted.get_job(kind="download", id)reads/download-statusand works withwait_s.repo:variantshorthand downloads and waits on that variant. A native speech prefetch underkind="tts"or"audio"serves a load of either kind.load_modelwaits for a running Unsloth Studio download of the same model or variant before Studio: MCP agents choose how and where a model loads, preview the load, and queue videos #14090's partial-variant refusal. The wait runs inside the load job (Studio: MCP agents choose how and where a model loads, preview the load, and queue videos #14090 now runs every pre-load read there), so it outliveswait_s: the call returnsloadingwith a job id,get_job(kind="load")names the download id while it waits, and the load starts once the download ends. The wait is capped at an hour, after which the load fails and names the download id. A managed download is waited on, never refused. An attach to an in-flight load (guard 1) still comes first, and an unmanaged partial variant is still refused.JobStatus.downloadandDownloadRef.studio/MCP.mdgets thedownload_modelrow and updateddatasetsandstart_trainingrows.Testing
New tests:
test_mcp_tools_datasets_upload.py,test_mcp_tools_datasets_images.py,test_mcp_tools_training_validate.py,test_mcp_tools_download.py,test_mcp_train_to_use.pyandtest_mcp_k16_guard_order.py.test_mcp_server.py,test_mcp_forward.py,test_mcp_no_host_paths.py,test_mcp_tool_contract.pyand the cancel, jobs, placement, training and video tests were updated. #14090's allowlist test now expects the whole download manager to be forwarded. In #14090'stest_mcp_tools_plan_load.py, the fakedownload-statusnow reports only the partial Q8_0 as running: with guard 2, aload_modelwaits on any running managed download, so a world where every download is running made those loads wait outwait_s.Result on this head: 1,840 passed, 3 skipped.
GPU run on the head before the last two own commits (one device, real Unsloth Studio on its own port, 91 MCP calls):
datasets(upload)with 40 rows returned aref:, andvalidate_onlyechoed the config with no paths.unsloth/Qwen3-0.6Btrained for 10 steps (~57 s), followed withget_job(kind="training", wait_s).load_model(checkpoint=<run>)loaded it in 26 s, reported the name only, andchatanswered.checkpoint-5also loaded.export_model(format="lora"), thenget_job(kind="export"), thenload_model(export="<run>/lora")andchatworked.unload_model(kind="all")returned GPU memory to baseline.validate_onlysetis_dataset_audio.download_modelworked for Qwen3-4B-GGUF UD-Q4_K_XL, Z-Image-Turbo and Wan2.2-TI2V-5B GGUF (already on disk, so they came back completed), and audio.cpp TTS.cancel(kind="model_download").load_modelduring a running download returnedloadingwith a job id and later finished.No UI change.
Not in this PR
studio_statusandunload_model(kind="all")show itsref:handle (opaque, not a path) instead of its name. That code is owned elsewhere; follow-up.gguf-download-progressis left off the allowlist on purpose.save_directoryhas only one level is not found by name. Use"<run>/<name>".Follow-ups
download_model(no variant listed, so it is refused). This is the same name-based rule Studio: MCP agents choose how and where a model loads, preview the load, and queue videos #14090'sis_ggufuses for loads, so prefetch and load agree. Moving both to the listing signal is a follow-up.get_job(kind="load")read in the same event-loop turn a trained load finishes can still show itsref:handle, and a cancelled trained load names the handle. The fix belongs in the shared load job runner.