modctl is a command-line tool for managing machine learning model artifacts as OCI-compliant packages. It enables packaging, distributing, and retrieving models with their associated code, documentation, and configuration using container registry infrastructure. This page provides a high-level introduction to the tool's architecture, key components, and design principles.
For detailed information on specific subsystems, see:
Sources: go.mod1-30 pkg/backend/backend.go1-87
modctl is a model artifact management tool that treats ML models as first-class distributable artifacts. It packages model weights, training code, documentation, and metadata into standardized OCI-compliant images that can be stored in container registries and distributed using P2P networks. The tool follows the ModelPack specification to ensure interoperability across the ML ecosystem.
The tool provides a Docker-like experience for ML practitioners:
| Operation | Description | Backend Method |
|---|---|---|
modctl build | Package model files into an artifact | Build() |
modctl push | Upload artifact to a registry | Push() |
modctl pull | Download artifact from a registry | Pull() |
modctl extract | Unpack artifact contents locally | Extract() |
modctl inspect | View artifact metadata and layers | Inspect() |
modctl ls | List locally stored artifacts | List() |
Sources: pkg/backend/backend.go27-69 test/mocks/backend/backend.go30-761
modctl uses the OCI image specification for model artifacts, enabling:
Sources: go.mod18-19
Artifacts are defined using a Modelfile that specifies:
NAME, ARCH, FAMILY: Model metadataCONFIG: Configuration filesMODEL: Model weights and checkpointsCODE: Training/inference codeDOC: Documentation and notebooksThe modctl modelfile generate command can automatically create a Modelfile by scanning a directory.
Sources: Referenced in diagrams and table of contents
errgroupretry-go/v4mpb progress barssha256-simdSources: go.mod8 go.mod16 go.mod24
modctl build [--output-local] [--output-remote ghcr.io/org/model:v1]
Sources: pkg/backend/backend.go40-41
Figure 1: Core Architecture Mapping to Code Entities
The architecture follows a layered design with clear separation of concerns:
cmd/): Cobra-based command structure with Viper configuration managementpkg/backend/): Unified interface abstracting all 14 operationspkg/storage/): OCI distribution library wrapper for manifest and blob operationsSources: pkg/backend/backend.go27-69 pkg/backend/backend.go72-86
Figure 2: Backend Interface Method Categories
The Backend interface defines 14 operations grouped by functionality:
| Category | Methods | Purpose |
|---|---|---|
| Authentication | Login(), Logout() | Registry credential management |
| Creation | Build(), Attach(), Upload() | Artifact construction and augmentation |
| Distribution | Pull(), Push(), Fetch() | Registry transfer operations |
| Introspection | List(), Inspect() | Query local artifacts |
| Maintenance | Remove(), Prune(), Tag(), Extract() | Storage management |
Sources: pkg/backend/backend.go27-69 test/mocks/backend/backend.go43-747
pkg/backend/)The backend struct pkg/backend/backend.go72-74 implements the Backend interface and serves as the orchestration layer. It holds a storage.Storage instance and delegates storage operations while coordinating higher-level workflows like building artifacts, managing transfers, and handling progress reporting.
The New() function pkg/backend/backend.go77-86 instantiates the backend with a storage directory path.
Sources: pkg/backend/backend.go72-86
The storage layer abstracts OCI registry operations through the storage.Storage interface, which wraps the distribution/distribution/v3 library. This abstraction enables:
Sources: go.mod9 pkg/backend/backend.go23
The CLI layer uses the Cobra framework go.mod21 for command parsing and Viper go.mod22 for configuration management. Commands create a Backend instance and invoke the appropriate interface method with operation-specific configuration structs from pkg/config/.
Sources: go.mod21-22
| Library | Purpose | Version |
|---|---|---|
oras.land/oras-go/v2 | OCI artifact transfer | v2.6.0 |
distribution/distribution/v3 | OCI registry storage | v3.0.0 |
opencontainers/image-spec | OCI specification types | v1.1.1 |
modelpack/model-spec | ModelPack specification | v0.0.7 |
d7y.io/api/v2 | Dragonfly P2P API | v2.1.94 |
Sources: go.mod5-30
| Library | Purpose | Version |
|---|---|---|
spf13/cobra | CLI framework | v1.10.2 |
spf13/viper | Configuration management | v1.21.0 |
vbauerster/mpb/v8 | Progress bars | v8.11.2 |
avast/retry-go/v4 | Retry logic with backoff | v4.7.0 |
minio/sha256-simd | Hardware-accelerated hashing | v1.0.1 |
klauspost/compress | Fast compression | v1.18.0 |
Sources: go.mod5-30
Two Git libraries provide repository metadata extraction:
go-git/go-git/v5 (v5.16.4): Pure Go implementationlibgit2/git2go/v34 (v34.0.0): CGo bindings to libgit2Sources: go.mod14-15
modctl adheres to the OCI image specification for:
Sources: go.mod18-19
Model artifacts follow the ModelPack spec (github.com/modelpack/model-spec v0.0.7), which extends OCI with:
Sources: go.mod17
Figure 3: End-to-End Artifact Lifecycle
--output-remote)Sources: pkg/backend/backend.go40-50
~/.modctl/ (configurable via --storage-dir)The New() function pkg/backend/backend.go77-86 accepts a storageDir parameter to override the default location.
Sources: pkg/backend/backend.go77-86
All major subsystems are defined as interfaces (Backend, Storage, Builder, OutputStrategy) with concrete implementations. This enables:
mockery)The mock in test/mocks/backend/backend.go30-761 demonstrates the full interface contract used for testing.
Sources: pkg/backend/backend.go26-69 test/mocks/backend/backend.go30-761
All artifacts are identified by cryptographic digests (SHA256). This ensures:
Sources: go.mod18
Transfer operations use errgroup.WithContext with configurable concurrency limits to parallelize layer operations while preventing resource exhaustion. Individual layer operations include retry logic via avast/retry-go/v4.
modctl provides a comprehensive toolkit for ML model lifecycle management by:
The tool's architecture emphasizes modularity, testability, and extensibility through interface-driven design and clear separation of concerns across its layered subsystem structure.
Sources: go.mod1-30 pkg/backend/backend.go1-87 test/mocks/backend/backend.go1-761
Refresh this wiki
This wiki was recently refreshed. Please wait 4 days to refresh again.