Skip to content

[wip] prototype python model builder using buildkit llb #2396

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

michaeldwan
Copy link
Member

@michaeldwan michaeldwan commented Jun 6, 2025

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=1 env variable. You'll also need to enable the new dockerfile client with COG_DOCKER_SDK_CLIENT=1.

This PR contains roughly:

  • 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. I don't love yet another abstraction, but this lets me swap out the build backend without hacking up the rest of the codebase.
  • lots of scaffolding and hacky prototypes to test out building python models with buildkit llb apis

- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant