Skip to content

Commit 08cef1a

Browse files
authored
Restore cog_runtime support with pinned coglet version (#2522)
* use pinned coglet if `cog_runtime: true` in cog.yaml, remove prompts and warning * Pin coglet version for monobase models
1 parent 02102a9 commit 08cef1a

File tree

4 files changed

+18
-113
lines changed

4 files changed

+18
-113
lines changed

pkg/dockerfile/env.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ package dockerfile
22

33
import (
44
"maps"
5-
"os"
65
"slices"
76

87
"github.com/replicate/cog/pkg/config"
98
)
109

11-
const CogletVersionEnvVarName = "R8_COGLET_VERSION"
12-
1310
func envLineFromConfig(c *config.Config) (string, error) {
1411
vars := c.ParsedEnvironment()
1512
if len(vars) == 0 {
@@ -24,11 +21,3 @@ func envLineFromConfig(c *config.Config) (string, error) {
2421

2522
return out, nil
2623
}
27-
28-
func CogletVersionFromEnvironment() string {
29-
host := os.Getenv(CogletVersionEnvVarName)
30-
if host == "" {
31-
host = "coglet"
32-
}
33-
return host
34-
}

pkg/dockerfile/env_test.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

pkg/dockerfile/fast_generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (g *FastGenerator) generateMonobase(lines []string, tmpDir string) ([]strin
230230
var envs []string
231231

232232
envs = append(envs, []string{
233-
"ENV R8_COG_VERSION=" + CogletVersionFromEnvironment(),
233+
"ENV R8_COG_VERSION=" + PinnedCogletURL,
234234
}...)
235235

236236
torchVersion, ok := g.Config.TorchVersion()

pkg/dockerfile/standard_generator.go

Lines changed: 17 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ const StripDebugSymbolsCommand = "find / -type f -name \"*python*.so\" -not -nam
4646
const CFlags = "ENV CFLAGS=\"-O3 -funroll-loops -fno-strict-aliasing -flto -S\""
4747
const PrecompilePythonCommand = "RUN find / -type f -name \"*.py[co]\" -delete && find / -type f -name \"*.py\" -exec touch -t 197001010000 {} \\; && find / -type f -name \"*.py\" -printf \"%h\\n\" | sort -u | /usr/bin/python3 -m compileall --invalidation-mode timestamp -o 2 -j 0"
4848
const STANDARD_GENERATOR_NAME = "STANDARD_GENERATOR"
49-
50-
const AskAboutCogRuntime = false
49+
const PinnedCogletURL = "https://github.com/replicate/cog-runtime/releases/download/v0.1.0-beta10/coglet-0.1.0b10-py3-none-any.whl" // Pinned coglet URL to avoid API dependency
5150

5251
type StandardGenerator struct {
5352
Config *config.Config
@@ -449,7 +448,7 @@ RUN rm -rf /usr/bin/python3 && ln -s ` + "`realpath \\`pyenv which python\\`` /u
449448
}
450449

451450
func (g *StandardGenerator) installCog() (string, error) {
452-
// FIXME: remove once pipelines use cog_runtime: true
451+
// Skip installing normal cog if coglet is already in requirements
453452
if g.Config.ContainsCoglet() {
454453
return "", nil
455454
}
@@ -459,18 +458,9 @@ func (g *StandardGenerator) installCog() (string, error) {
459458
return "", nil
460459
}
461460

462-
// completely disable cog-runtime since it's not compatible with non-procedure models!
463-
// TODO[md]: remove this once we sort out a path forward for cog-runtime
464-
// if g.Config.Build.CogRuntime != nil && *g.Config.Build.CogRuntime {
465-
// return g.installCogRuntime()
466-
// }
467-
// accepted, err := g.askAboutCogRuntime()
468-
// if err != nil {
469-
// return "", err
470-
// }
471-
// if accepted {
472-
// return g.installCogRuntime()
473-
// }
461+
if g.Config.Build.CogRuntime != nil && *g.Config.Build.CogRuntime {
462+
return g.installCogRuntime()
463+
}
474464

475465
data, filename, err := ReadWheelFile()
476466
if err != nil {
@@ -490,79 +480,18 @@ func (g *StandardGenerator) installCog() (string, error) {
490480
return strings.Join(lines, "\n"), nil
491481
}
492482

493-
// func (g *StandardGenerator) installCogRuntime() (string, error) {
494-
// // We need fast-* compliant Python version to reconstruct coglet venv PYTHONPATH
495-
// if !CheckMajorMinorOnly(g.Config.Build.PythonVersion) {
496-
// return "", fmt.Errorf("Python version must be <major>.<minor>")
497-
// }
498-
// m, err := NewMonobaseMatrix(http.DefaultClient)
499-
// if err != nil {
500-
// return "", err
501-
// }
502-
// cmds := []string{
503-
// "ENV R8_COG_VERSION=coglet",
504-
// "ENV R8_PYTHON_VERSION=" + g.Config.Build.PythonVersion,
505-
// "RUN pip install " + m.LatestCoglet.URL,
506-
// }
507-
// return strings.Join(cmds, "\n"), nil
508-
// }
509-
510-
// func (g *StandardGenerator) askAboutCogRuntime() (bool, error) {
511-
// // Training is not supported
512-
// if g.Config.Train != "" {
513-
// return false, nil
514-
// }
515-
// // Only warn if cog_runtime is not explicitly set
516-
// if g.Config.Build.CogRuntime != nil {
517-
// return false, nil
518-
// }
519-
520-
// console.Warnf("Major Cog runtime upgrade available. Opt in now by setting build.cog_runtime: true in cog.yaml.")
521-
// console.Warnf("More: https://replicate.com/changelog/2025-07-21-cog-runtime")
522-
523-
// // Do not ask until we're ready
524-
// if !AskAboutCogRuntime {
525-
// return false, nil
526-
// }
527-
528-
// // Skip question if not in an interactive shell
529-
// if !term.IsTerminal(int(os.Stdin.Fd())) || !term.IsTerminal(int(os.Stdout.Fd())) || !term.IsTerminal(int(os.Stderr.Fd())) {
530-
// return false, nil
531-
// }
532-
533-
// interactive := &console.InteractiveBool{
534-
// Prompt: "Do you want to switch to the new Cog runtime?",
535-
// Default: true,
536-
// // NonDefaultFlag is not applicable here
537-
// }
538-
// cogRuntime, err := interactive.Read()
539-
// if err != nil {
540-
// return false, fmt.Errorf("failed to read from stdin: %v", err)
541-
// }
542-
// // Only add cog_runtime: true to cog.yaml if answer is yes
543-
// // Otherwise leave it absent so we keep nagging
544-
// if !cogRuntime {
545-
// console.Warnf("Not switching. Add build.cog_runtime: false to disable this reminder.")
546-
// return false, nil
547-
// }
548-
// g.Config.Build.CogRuntime = &cogRuntime
549-
550-
// console.Infof("Adding build.cog_runtime: true to %s", g.Config.Filename())
551-
// newYaml, err := yaml.Marshal(g.Config)
552-
// if err != nil {
553-
// return false, err
554-
// }
555-
// path := filepath.Join(g.Dir, g.Config.Filename())
556-
// oldYaml, err := os.ReadFile(path)
557-
// if err != nil {
558-
// return false, err
559-
// }
560-
// merged, err := util.OverwriteYAML(newYaml, oldYaml)
561-
// if err != nil {
562-
// return false, err
563-
// }
564-
// return true, os.WriteFile(path, merged, 0o644)
565-
// }
483+
func (g *StandardGenerator) installCogRuntime() (string, error) {
484+
// We need fast-* compliant Python version to reconstruct coglet venv PYTHONPATH
485+
if !CheckMajorMinorOnly(g.Config.Build.PythonVersion) {
486+
return "", fmt.Errorf("Python version must be <major>.<minor>")
487+
}
488+
cmds := []string{
489+
"ENV R8_COG_VERSION=coglet",
490+
"ENV R8_PYTHON_VERSION=" + g.Config.Build.PythonVersion,
491+
"RUN pip install " + PinnedCogletURL,
492+
}
493+
return strings.Join(cmds, "\n"), nil
494+
}
566495

567496
func (g *StandardGenerator) pipInstalls() (string, error) {
568497
var err error

0 commit comments

Comments
 (0)