-
Notifications
You must be signed in to change notification settings - Fork 654
OCI bundle format for model weights #2676
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
Conversation
a8a88f6 to
0fe2ec4
Compare
markphelps
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.
one minor nit but lgtm!
markphelps
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.
constantly approve
…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
Replace the --files flag with random file generation: - Add --count (-n) flag for number of files (default: 3) - Add --min-size and --max-size flags (default: 25mb-50mb) - Add --output-dir to optionally keep generated files - Files are named weights-001.bin, weights-002.bin, etc. - Generate random data in 1MB chunks for memory efficiency This simplifies testing the OCI bundle format without needing real weight files.
- Add ModelImageFormat enum (FormatStandalone, FormatBundle) in format.go - Update Model struct: replace Format with ImageFormat field - Update BuildOptions: replace OCIIndex bool with ImageFormat - Create Pusher interface with ImagePusher and BundlePusher implementations - Add Resolver.Push() that delegates to appropriate pusher based on format - Add BuildWeightsArtifactFromManifest to IndexFactory - Simplify pkg/cli/push.go to use resolver.Push() for bundles - Move ImageFormatFromEnv() to model package The push logic is now cleanly separated: - ImagePusher: Simple docker push for standalone images - BundlePusher: Full OCI Index workflow (push image, build weights artifact, build index, push index) Closes cog-cz1
- Add inline mock weights generator to avoid pkg/wheels init panic - Add StartTestRegistryWithCleanup for harness (no *testing.T required) - Add registry-start, registry-inspect, docker-push, mock-weights commands - Add oci_bundle_build.txtar and oci_bundle_push.txtar integration tests - Update push_test.go to use testcontainers instead of TEST_REGISTRY env
…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
- Add PlatformUnknown constant for non-platform-specific artifacts - Use AnnotationValueWeights constant instead of "weights" string literal - Update all usages in index_factory.go, resolver.go, and tests
36064a1 to
26be175
Compare
markphelps
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.
i will not approve again
Summary
Adds OCI bundle format support for separating model weights from container images. This enables weight deduplication across model versions and faster cold starts by allowing weights to be cached and shared.
What's Changed
New Types & Formats
ModelFormat(pkg/model/format.go) - Enum for image formats:FormatStandalone(traditional) andFormatBundle(OCI index with weights)WeightsManifest/WeightFile(pkg/model/weights.go) - Types for weight file metadata (digests, sizes, destinations)WeightsLock(pkg/model/weights_lock.go) - Lockfile format mapping weight identifiers to deployment blob metadataIndex/IndexManifest(pkg/model/index.go) - OCI Image Index types with manifest type detectionOCI Index Building
IndexFactory(pkg/model/index_factory.go) - Builds OCI Image Indexes containing:vnd.cog.reference.type: weightsannotation)WeightsArtifactBuilder- Creates OCI artifacts from weight files with proper media types and annotationsIndexBuilder- Combines model image + weights artifact into an OCI indexPush Flow
Pusherinterface (pkg/model/pusher.go) - Strategy pattern for push operationsImagePusher- Standard docker push for standalone imagesBundlePusher- OCI index push with weights artifactResolver.Push()- Selects appropriate pusher based onModel.ImageFormatBuild Integration
BuildOptions.ImageFormat- Specify bundle vs standalone formatBuildOptions.WeightsLockPath- Custom path for weights.lock fileweights.lockand attachesWeightsManifestto built modelsTesting
weights-lock-gen(tools/weights-lock-gen/) - CLI tool to generate random weight files for testingintegration-tests/harness/) - Commands for testing OCI bundle push/inspect:registry-start/registry-stop- Ephemeral Docker registryregistry-inspect- Inspect pushed manifestsmock-weights- Generate test weight files and lockfileCleanup
pkg/docker/fast_push.go,pkg/monobeam/, etc.)Sourcefield fromWeightFile(lockfile maps name→blob, source comes from cog.yaml)Design Notes
"llama-3.1-8b"not"model.safetensors")filePaths map[string]stringparameterunknown/unknownused for non-platform-specific artifacts (weights)vnd.cog.reference.type: weightsidentifies weights manifests in indexesTesting
Next Steps
cog build --oci-indexflag to use bundle format