8000 Add support for fast build images in cog run by 8W9aG · Pull Request #2408 · replicate/cog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for fast build images in cog run #2408

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 2 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions pkg/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,44 @@ func run(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
client := registry.NewRegistryClient()

cfg, projectDir, err := config.GetConfig(configFilename)
if err != nil {
return err
}
client := registry.NewRegistryClient()
imageName, err := image.BuildBase(ctx, dockerClient, cfg, projectDir, buildUseCudaBaseImage, DetermineUseCogBaseImage(cmd), buildProgressOutput, client)
if err != nil {
return err

var imageName string
if cfg.Build.Fast || buildFast {
imageName = config.DockerImageName(projectDir)
err = image.Build(
ctx,
cfg,
projectDir,
imageName,
buildSecrets,
buildNoCache,
buildSeparateWeights,
buildUseCudaBaseImage,
buildProgressOutput,
buildSchemaFile,
buildDockerfileFile,
DetermineUseCogBaseImage(cmd),
buildStrip,
buildPrecompile,
cfg.Build.Fast || buildFast,
nil,
buildLocalImage,
dockerClient,
client)
if err != nil {
return err
}
} else {
imageName, err = image.BuildBase(ctx, dockerClient, cfg, projectDir, buildUseCudaBaseImage, DetermineUseCogBaseImage(cmd), buildProgressOutput, client)
if err != nil {
return err
}
}

gpus := ""
Expand Down Expand Up @@ -102,10 +131,6 @@ func run(cmd *cobra.Command, args []string) error {
console.Info("")
console.Infof("Running '%s' in Docker with the current directory mounted as a volume...", strings.Join(args, " "))

if buildFast {
console.Info("Fast run enabled.")
}

err = docker.Run(ctx, dockerClient, runOptions)
// Only retry if we're using a GPU but but the user didn't explicitly select a GPU with --gpus
// If the user specified the wrong GPU, they are explicitly selecting a GPU and they'll want to hear about it
Expand Down
14 changes: 14 additions & 0 deletions test-integration/test_integration/test_run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import subprocess
from pathlib import Path


def test_run(tmpdir_factory, cog_binary):
Expand Down Expand Up @@ -46,3 +47,16 @@ def test_run_with_secret(tmpdir_factory, cog_binary):
)
assert b"RUN echo hello world" in result.stdout
assert b"RUN --mount=type=secret,id=foo,target=secret.txt echo shh" in result.stdout


def test_run_fast_build(cog_binary):
project_dir = Path(__file__).parent / "fixtures/fast-build"
result = subprocess.run(
[cog_binary, "run", "echo", "hello world"],
cwd=project_dir,
check=True,
capture_output=True,
text=True,
)
assert result.returncode == 0
assert result.stdout == "hello world\n"
0