Repository navigation
fix(managed_files): send provider file ids when creating a fine-tuning job from managed files - #46552
Conversation
…g job from managed files Fine-tuning job creation with a managed training file sent the gateway's managed id and the provider-prefixed deployment model to OpenAI, which rejected the job. The pre-call hook now builds the file id mapping for training_file and validation_file, the deployment hook swaps both, the SDK strips the provider prefix from the model, and the create response returns the caller's own file ids
|
Automatic reviews are disabled for this repository. |
|
@litereview code-review |
|
bugbot run |
| if fine_tuning_file_ids: | ||
| data["model_file_id_mapping"] = await self.get_model_file_id_mapping( | ||
| fine_tuning_file_ids, user_api_key_dict.parent_otel_span | ||
| ) |
There was a problem hiding this comment.
🟡 Managed validation file fails with raw training
With a raw training file and managed validation file, get_model_file_id_mapping prepares a replacement that the direct provider path never uses. The provider receives the managed validation ID and rejects the job.
Learn more
The fine-tuning endpoint chooses router dispatch based solely on the training file's managed ID. If only the validation file is managed, the request goes directly to litellm.acreate_fine_tuning_job. The pre-call hook adds the validation mapping to data, but replacement occurs only in the deployment hook during router dispatch. The direct call therefore sends the unified validation ID to the provider.
Example: Send training_file="file-native", a managed validation ID, and custom_llm_provider="openai". The validation mapping is fetched, but OpenAI receives the managed ID instead of its file-* ID and rejects creation.
Recommended fix: Route requests with either managed file through a deployment that has the file, or explicitly resolve the managed validation ID against the chosen direct provider before dispatch.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Same 400 on main, the endpoint picks the direct path from the training file alone, so this stays out of scope here
Merging this PR will not alter performance
|
✅ code-review5/5 · Ready for human reviewScope: full · Full PR review. Completed · Some checks not run. No correctness findings. Checks and execution details
View review · Reviewed |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ents holding every file Fine-tuning creates now narrow routing the same way managed batches do, so a deployment added after the upload is never picked. Adds a two-worker chaos integration test and runs tests/unit/fine_tuning in the endpoints shard.
|
@litereview code-review |
|
bugbot run |
…no deployment holds the files A managed file used on a model group it was never uploaded for kept failing with the provider's 400 before the routing filter. The filter turned that into a 429 no-deployments error, so fine-tuning now falls back to the whole group in that case while batch input files keep routing only to deployments that hold them.
…re creates through the proxy
|
@litereview code-review |
|
bugbot run |
|
@litellm-stampbot |
litellm-stampbot: risk highNot approved at Rules (
Cursor Bugbot: Medium Risk at Pushes do not re-run this check. Comment |
…tune_managed_file_id
|
bugbot run |
|
@litereview full |
…ne scratch database
|
|
bugbot run |
|
@litereview full |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit cebdd2b. Configure here.
|
@litellm-stampbot |
TLDR
Problem this solves:
target_model_namesalways failsopenai/<model>also send that prefix to OpenAIHow it solves it:
training_fileandvalidation_fileto the routed deployment's own file idsUser Flow
Before: a developer who uploads training data through the gateway can never start a fine-tuning job with it
purpose=fine-tuneandtarget_model_names=<model>, and get back a long id starting withbGl0ZWxstraining_file(and optionally a second one asvalidation_file)invalid training_file: bGl0ZWxs...from OpenAI, so no job is createdAfter: the same upload starts a real job they can track and cancel
bGl0ZWxs...id backidstarts withbGl0ZWxsand whosetraining_fileandvalidation_fileare the ids they sentstatus: cancelledThe admin sees the same thing on https://litellm-domain/ui/?page=logs. The two fine-tuning creates are boxed in red
Before, both creates are logged as Failure, and opening one shows OpenAI's
invalid training_fileerror with the gateway id in itAfter, the same two creates are logged as Success
Linear ticket
Resolves LIT-7071
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreScreenshots / Proof of Fix
Real OpenAI, real Postgres, a proxy with managed files on. Two deployments serve the same base model, one written the way the Admin UI stores it and one the way the docs show it
$KEYis a virtual key minted for both models. Long ids are cut short below. The Logs page screenshots for both runs are under User FlowBefore (a114356)
Upload the training file
Upload the validation file the same way
Create a job on each deployment
After (a157241)
Upload the training file
Upload the validation file the same way
Create a job on each deployment
Retrieve and cancel each job
Ask OpenAI directly what it received
Integration tests and audit
Each checked-in test runs a real proxy at 2 workers, real Postgres, real Redis and a scripted OpenAI. The head ran twice with the same result
tests/integration/compatibilityfine-tuning filestests/integration/security/test_fine_tuning_managed_ids.pyThe skips are existing
BUG:skips. Main has since dropped the one for another key creating with the owner's managed file, and that test passes at the head. The tests that fail before cover managed creates through a 20-request sync and async burst, each worker alone, a replaced worker, a deployment added after the upload, and the provider prefix on OpenAI and AzureThe same flow against real OpenAI, before and after
openai/<model>or bare deploymentopenai/<model>on the direct path/v1/messages,/v1/responsesand its streamWhat OpenAI received after the fix never carried an
openai/model. The only managed ids it saw were the two rows that still fail the same way before and afterType
🐛 Bug Fix
✅ Test
Caveats (if any)
Low
training_filemodel="openai/<x>"andcustom_llm_provider="openai"now send<x>create_batchandcompletionalready strip the prefixinvalid training_fileaiplatform.tuningJobs.create, and there is no Azure fine-tuning resourceFinal Attestation
REVIEWER MUST KNOW BEFORE APPROVING
training_fileused to be an internal decoded string andvalidation_filewas OpenAI's raw file id. Before this PR that create never succeeded against OpenAI, so no working client read the old valueslitellm.create_fine_tuning_jobnow strips<custom_llm_provider>/frommodelfor openai, azure and vertex_ai, the same waycompletionandcreate_batchalready do. The one caller this changes is someone fine-tuning on an OpenAI-compatible server whose real model id starts withopenai/, who now has to write the prefix twice like they already do for chatinvalid training_fileNote
Medium Risk
Changes enterprise proxy file-id translation, deployment routing, and fine-tuning request/response shaping; incorrect mapping could send wrong files or route to deployments without copies, though scope is limited to managed-file fine-tuning and aligned batch behavior.
Overview
Fixes managed fine-tuning creates so the proxy no longer forwards LiteLLM unified file ids or prefixed model names to OpenAI/Azure/Vertex.
The enterprise managed files hook now builds
model_file_id_mappingforacreate_fine_tuning_job, swapstraining_fileandvalidation_fileto each routed deployment’s provider ids (same pattern as batchinput_file_id), and narrows routing to deployments that hold every managed file in the request. The proxy fine-tuning create path echoes the caller’s managed file ids in the response instead of internal/provider values.litellm.create_fine_tuning_jobstrips thecustom_llm_provider/prefix frommodelbefore provider calls. CI and tests add unit coverage plus integration/chaos cases for concurrent multi-worker creates and deployment filtering.Reviewed by Cursor Bugbot for commit cebdd2b. Bugbot is set up for automated code reviews on this repo. Configure here.