Skip to content
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

Quick fix for Apple Silicon M1 support in run #1704

Merged
merged 2 commits into from
May 31, 2024
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
6 changes: 6 additions & 0 deletions pkg/cli/run.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"runtime"
"strconv"
"strings"

Expand All @@ -9,6 +10,7 @@ import (
"github.com/replicate/cog/pkg/config"
"github.com/replicate/cog/pkg/docker"
"github.com/replicate/cog/pkg/image"
"github.com/replicate/cog/pkg/util"
"github.com/replicate/cog/pkg/util/console"
)

Expand Down Expand Up @@ -73,6 +75,10 @@ func run(cmd *cobra.Command, args []string) error {
Workdir: "/src",
}

if util.IsAppleSiliconMac(runtime.GOOS, runtime.GOARCH) {
runOptions.Platform = "linux/amd64"
}

for _, portString := range runPorts {
port, err := strconv.Atoi(portString)
if err != nil {
Expand Down
18 changes: 11 additions & 7 deletions pkg/docker/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ type Volume struct {
}

type RunOptions struct {
Args []string
Env []string
GPUs string
Image string
Ports []Port
Volumes []Volume
Workdir string
Args []string
Env []string
GPUs string
Image string
Ports []Port
Volumes []Volume
Workdir string
Platform string
}

// used for generating arguments, with a few options not exposed by public API
Expand Down Expand Up @@ -84,6 +85,9 @@ func generateDockerArgs(options internalRunOptions) []string {
if options.Workdir != "" {
dockerArgs = append(dockerArgs, "--workdir", options.Workdir)
}
if options.Platform != "" {
dockerArgs = append(dockerArgs, "--platform", options.Platform)
}
dockerArgs = append(dockerArgs, options.Image)
dockerArgs = append(dockerArgs, options.Args...)
return dockerArgs
Expand Down