blobhub.types.onnx.Onnx is the typed module for blobhub.model.onnx blobs. Each revision of such a blob holds one
model, which you upload as a .onnx file and the platform processes into three artifacts.
Onnx(revision) raises TypeMismatch when the revision’s blob is not an ONNX blob.
Artifacts
model.artifacts() sends describe and returns a list of Artifact(path, size). A
processed upload yields three:
The list is empty until an upload has been processed.
Download
model.download(path="model.onnx", *, dest=None) downloads one artifact and returns its local Path.
dest=Noneuses the cache. Files land in~/.cache/blobhub/revisions/<revision id>/, or in the same layout under$XDG_CACHE_HOME/blobhubwhen that variable holds an absolute path.destis a folder or a file. An existing folder, or a string ending in/, receives the artifact under its own name; anything else is the file path to write. A file written todestis never cached.- The file appears complete or not at all. The bytes go to a temporary file next to the target, which replaces the target only once its size matches the artifact’s.
- An artifact the revision does not hold raises
NotFoundwitherrorartifact_not_foundandstatusNone, before any download is attempted. That is what a draft whose upload is still being processed gives you. - Up to 4 MiB, the artifact comes in one request through
download. Above that it comes in ranged parts over presigned URLs, throughinitiate_download, each part written at its offset.
download() fetches the model.onnx the platform already extracted.
The cache
A cached copy is reused only for a committed revision, whose content can no longer change. Before reusing it,download() reads the revision again and checks that it is still committed and that the copy was taken from that
exact state: a revision that was reopened, changed and committed again is downloaded afresh. A draft’s artifacts
are downloaded every time.
The cache is never pruned. Delete ~/.cache/blobhub whenever you like.
Topology
model.topology() downloads model.json (cached like any artifact) and returns it parsed as a dict: the model’s
graph without its weights. It is how you look at a large model without fetching the model itself.
Upload
model.upload(file, *, timeout=600.0) uploads a local .onnx file to the revision, waits until the platform has
processed it, and returns the completed Operation.
hub here comes from blobhub.connect(), not
connect(anonymous=True).
What upload() does:
- Checks the file. It must exist (
FileNotFoundError), end in.onnxand not be empty (ValueError). - Packs it. It writes
model.tar.gzin a temporary folder, holding exactly one regular file namedmodel.onnx. The platform’s processing refuses an archive holding anything else. - Uploads it. An archive of up to 4 MiB goes in one request,
upload. A larger one goes in 10 MiB parts over presigned URLs:initiate_upload, the part uploads, thencomplete_upload. If anything fails afterinitiate_upload, the SDK sendscancel_uploadbefore raising. - Waits on the upload’s operation until it is
completed. If processing fails, because the file does not parse as ONNX, it raisesOperationFailedwitherrorupload_failed. Aftertimeoutseconds it raisesWaitTimeout, and the processing carries on.
Uploads are writes, so they are not retried after a failure that may have reached the platform; see
Errors and retries. A part’s own
PUT to storage is retried, because repeating it is
harmless.
See also
- Notebooks — three notebooks download public models; the fourth uploads one.
- Upload Model, Multipart Upload, Describe Model, Download Model and Multipart Download — the REST commands underneath.
- Get Operation — what
upload()waits on.

