[wip] prototype python model builder using buildkit llb #2396
Draft
michaeldwan wants to merge 2 commits intomainfrom
Draft
[wip] prototype python model builder using buildkit llb #2396michaeldwan wants to merge 2 commits intomainfrom
michaeldwan wants to merge 2 commits intomainfrom
Conversation
- a model package and Model type to represent a cog model and all related metadata and configuration - a factory abstraction for building models with 2 backends, the existing just calls out to image.Build or image.BuildBase, and a new very much wip buildkit backend - lots of scaffolding and hacky prototypes to test out building python models with buildkit llb apis
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
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.
Nothing to see here... Just a PR so I can run tests in CI.
This is a lot of junk code that'll get cleaned up or thrown away. The intention is to test out iteratively building models using buildkit's LLB (low-level build) api. Early tests are promising. But as it says on the box, this is a low level api and we need a decent amount of scaffolding and ergonomic helpers to replace the existing Dockerfile-based builds.
How does it work?
Currently images are built from dynamically generated Dockerfiles based on a cog.yaml and build flags. The only opportunity we have to influence the build is when the dockerfile is generated; after that control is yielded to docker, which uses a dockerfile buildkit frontend to translate our instructions into buildkit LLB. This drastically limits how much control we have over the resulting images.
This PR skips the indirect dockerfile-to-llb-to-image process in favor of the Go buildkit frontend that lets us define exactly what buildkit will do by mutating state in code. Like interactive multi-stage Dockerfiles... we can fork and merge state ensuring no bloat, and even inspect files or command output before deciding how to proceed. For example, instead of being limited by python versions in our base images, we can check if there's a base image or external layer for a package the build needs, use it if available, otherwise install/compile on demand.
You can get a (very rough) idea what this looks like by checking out the python builder in this PR.
You can try it out on CPU-only models by running predict/build/run/push with the
COG_BUILDKIT_FACTORY=1env variable. You'll also need to enable the new dockerfile client withCOG_DOCKER_SDK_CLIENT=1.This PR contains roughly: