-
Notifications
You must be signed in to change notification settings - Fork 654
feat: add weights build and push commands #2683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
36064a1 to
26be175
Compare
…istry Implements WeightsArtifactBuilder for creating OCI artifacts containing model weights. The builder: - Creates OCI-format manifests (application/vnd.oci.image.manifest.v1+json) - Sets artifactType to application/vnd.cog.weights.v1 - Adds layers with custom media types and annotations for weight files - Uses mutate.Addendum to properly attach layer annotations Layer annotations include: - vnd.cog.weights.name: original filename - vnd.cog.weights.dest: container path - vnd.cog.weights.source: origin URL (optional) - vnd.cog.weights.digest.original: uncompressed digest - vnd.cog.weights.size.uncompressed: uncompressed size Test coverage: 93.8%
Add helper functions to detect and handle OCI indexes: - isOCIIndex: checks if ManifestResult is an OCI Image Index - findWeightsManifest: finds weights manifest by annotation - findImageManifest: finds model image manifest with platform filtering Also: - Add Annotations field to PlatformManifest struct - Populate annotations when reading OCI index manifests - Add PushImage/PushIndex to registry Client interface for OCI index push support
- Move WeightsArtifactBuilder, IndexBuilder, IndexFactory from pkg/ociartifact to pkg/model/index_factory.go - Delete pkg/ociartifact/ package (code duplication eliminated) - Add OCI index push flow in pkg/cli/push.go (COG_OCI_INDEX=1 env var) - Add index detection helpers in resolver for loading OCI indexes - Simplify BuildOptions: remove WeightsLockPath (hardcoded to weights.lock) - Add Platform.Variant field to pkg/model/image.go - Add push_test.go placeholder for registry push tests
…ht resolution - Remove Source field from WeightFile - lockfile maps name→blob, not source - Change Name semantics to identifier/handle (e.g., 'model-v1') not filename - Add filePaths map[string]string parameter to AddLayersFromLock for file location - Add context cancellation support to AddLayersFromLock for long operations - Add AnnotationValueWeights constant for 'weights' annotation value - Improve registry push error messages to include reference - Remove binary test files (~109MB) that were accidentally committed - Update all tests to use new API and identifier-style names
Change 'cog weights push' to push weight files as individual blobs using WriteLayer instead of building and pushing an OCI artifact. Layers are pushed concurrently for better performance. - Add WriteLayer method to registry.Client interface - Implement concurrent blob uploads with progress reporting - Update mock clients to implement WriteLayer
…d weights pushing and progress Signed-off-by: Mark Phelps <mphelps@cloudflare.com>
Signed-off-by: Mark Phelps <mphelps@cloudflare.com>
Signed-off-by: Mark Phelps <mphelps@cloudflare.com>
Signed-off-by: Mark Phelps <mphelps@cloudflare.com>
7c8476f to
76f110a
Compare
Use typed errors (io.EOF, syscall.EPIPE, etc.) instead of string matching for more robust error detection tests.
michaeldwan
approved these changes
Feb 4, 2026
Member
michaeldwan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome
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.
Summary
This PR adds (hidden) CLI commands for building and pushing model weights as OCI blobs, building on the OCI bundle infrastructure in
md/oci-bundle.New Commands
cog weights build- Generates aweights.lockfile from weight sources defined incog.yamlcog weights push- Pushes weight files as OCI blobs to a registry with progress trackingKey Changes
Configuration (
pkg/config/)WeightSourcetype withsourceand optionaltargetfieldsWeightsfield toConfigstructcog.yamlvalidationCLI (
pkg/cli/weights.go)cog weights build: Reads weights section from cog.yaml, computes SHA256 digests, generatesweights.lockcog weights push: Pushes weight blobs concurrently with real-time progress bars (TTY) or summary (non-TTY)progressTrackerfor multi-file concurrent uploadsModel Layer (
pkg/model/)WeightsLockGenerator: Processes weight sources (files or directories), computes digests by streamingWeightsPusher: Concurrent blob push with progress callbacksfileBackedLayer: Implementsv1.Layerinterface for memory-efficient streaming from diskindex_factory.goto use uncompressed layers (weights don't compress well)Registry (
pkg/registry/)WriteLayerandWriteLayerWithProgressmethods toClientinterfaceRegistryClientusing go-containerregistryDesign Decisions
No compression: Model weights (safetensors, GGUF, etc.) are already highly optimized binary data that doesn't compress well. Skipping gzip saves CPU time and simplifies the code.
Streaming: Files are never loaded entirely into memory. The
fileBackedLayerstreams directly from disk, andhashFile()computes digests viaio.Copy.Concurrent uploads: Weight files are pushed in parallel with progress tracking per file.
Lock file:
weights.lockpins exact digests and sizes, similar to package manager lock files.Example Usage
Testing
WeightsLockGenerator,WeightsPusher,IndexFactoryweights_build.txtarExample w/ Weights Gen Tool (renamed)
TODO