Implementation:Ollama Ollama Imagegen Transfer
| Knowledge Sources | |
|---|---|
| Domains | Image Generation, Transfer |
| Last Updated | 2025-02-15 00:00 GMT |
Overview
Provides the core transfer package with types, configuration, and shared utilities for parallel blob download and upload operations.
Description
The transfer.go file defines the foundational types and public API for the transfer package. It declares Blob (content-addressed blob with digest, size, and optional cross-repository mount source), DownloadOptions and UploadOptions with full configuration (concurrency, auth, progress callbacks, stall timeout), and AuthChallenge for registry authentication. The package provides Download and Upload entry points that delegate to internal implementations. Shared utilities include digestToPath for converting digest format (sha256:abc to sha256-abc), parseAuthChallenge for parsing WWW-Authenticate headers, backoff for exponential retry delay, progressTracker for atomic concurrent progress aggregation, and speedTracker for median speed calculation. The design is intentionally simpler than Ollama's main transfer code, optimized for many-small-blob workloads.
Usage
Used as the public API for pulling and pushing tensor-based image generation models to/from OCI registries.
Code Reference
Source Location
- Repository: Ollama
- File: x/imagegen/transfer/transfer.go
- Lines: 1-216
Signature
type Blob struct {
Digest string
Size int64
From string // Cross-repository mount source
}
type DownloadOptions struct {
Blobs []Blob
BaseURL string
DestDir string
Repository string
Concurrency int
Progress func(completed, total int64)
Client *http.Client
Token string
GetToken func(ctx context.Context, challenge AuthChallenge) (string, error)
StallTimeout time.Duration
}
type UploadOptions struct { ... }
func Download(ctx context.Context, opts DownloadOptions) error
func Upload(ctx context.Context, opts UploadOptions) error
Import
import "github.com/ollama/ollama/x/imagegen/transfer"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| ctx | context.Context | Yes | Context for cancellation |
| opts | DownloadOptions/UploadOptions | Yes | Transfer configuration |
Outputs
| Name | Type | Description |
|---|---|---|
| error | error | Error from transfer operations |
Usage Examples
// Download model blobs
err := transfer.Download(ctx, transfer.DownloadOptions{
Blobs: blobs,
BaseURL: "https://registry.ollama.ai",
DestDir: blobDir,
Repository: "library/flux2-klein",
Concurrency: 64,
})
// Upload model blobs
err := transfer.Upload(ctx, transfer.UploadOptions{
Blobs: blobs,
BaseURL: registryURL,
SrcDir: blobDir,
Manifest: manifestJSON,
})