server: validate safetensors architecture before copying blobs#16630
Open
nac7 wants to merge 1 commit into
Open
server: validate safetensors architecture before copying blobs#16630nac7 wants to merge 1 commit into
nac7 wants to merge 1 commit into
Conversation
server: validate safetensors architecture before copying blobs When importing a safetensors model directory with an unsupported architecture, Ollama previously copied all blobs into the staging directory and only then attempted conversion, surfacing the "unsupported architecture" error after potentially gigabytes of I/O (issue ollama#15949). Fix: read config.json from the blob store at the start of convertFromSafetensors and call convert.CheckArchitecture before creating the temp directory or linking any files. If the architecture is positively identified as unsupported the error is returned immediately. Unreadable or unparseable config.json files are silently skipped so that ConvertModel can surface those errors with full context as before. Adds convert.CheckArchitecture and a unit test covering supported architectures, known-unsupported architectures, missing file, empty architectures list, and invalid JSON. Fixes ollama#15949 @
stevei101
approved these changes
Jun 10, 2026
stevei101
left a comment
There was a problem hiding this comment.
Approved by Antigravity AI pair programmer after verifying CI checks pass.
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.
Fixes #15949.
Problem
When importing a safetensors model with an unsupported architecture, Ollama copies all blobs into a staging directory first and only then attempts conversion — surfacing the
unsupported architectureerror after potentially many gigabytes of unnecessary I/O:A user reporting this issue had already copied 77 GB of safetensors files before getting the error.
Fix
convert.CheckArchitecture(configPath string) errorreadsconfig.jsonfrom the given path, parsesModelParameters.Architectures, and returns a descriptive error for any architecture that is not handled byLoadModelMetadata's switch statement.convertFromSafetensorsinserver/create.gocalls this beforeos.MkdirTempand before any blob links are created. If config.json is missing, unreadable, or has no architectures field,CheckArchitecturereturnsnilso thatConvertModelcan surface those errors with full context as before.Tests
TestCheckArchitectureinconvert/convert_test.gocovers:LlamaForCausalLM,Gemma3ForCausalLM) → no errorMistralForCausalLM) → error with architecture name