Skip to main content
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=None uses the cache. Files land in ~/.cache/blobhub/revisions/<revision id>/, or in the same layout under $XDG_CACHE_HOME/blobhub when that variable holds an absolute path.
  • dest is 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 to dest is 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 NotFound with error artifact_not_found and status None, 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, through initiate_download, each part written at its offset.
The SDK never unpacks an archive. 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.
That needs a credential that can write to the blob, so hub here comes from blobhub.connect(), not connect(anonymous=True). What upload() does:
  1. Checks the file. It must exist (FileNotFoundError), end in .onnx and not be empty (ValueError).
  2. Packs it. It writes model.tar.gz in a temporary folder, holding exactly one regular file named model.onnx. The platform’s processing refuses an archive holding anything else.
  3. 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, then complete_upload. If anything fails after initiate_upload, the SDK sends cancel_upload before raising.
  4. Waits on the upload’s operation until it is completed. If processing fails, because the file does not parse as ONNX, it raises OperationFailed with error upload_failed. After timeout seconds it raises WaitTimeout, and the processing carries on.
The platform’s own checks surface as errors: 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