Skip to content
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
4 changes: 2 additions & 2 deletions cmd/cog/cog.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
func main() {
cmd, err := cli.NewRootCommand()
if err != nil {
console.Fatal("%f", err)
console.Fatalf("%f", err)
}

if err = cmd.Execute(); err != nil {
console.Fatal("%s", err)
console.Fatalf("%s", err)
}
}
12 changes: 6 additions & 6 deletions cmd/generate_compatibility_matrices/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ func main() {

if *tfOutputPath != "" {
if err := writeTFCompatibilityMatrix(*tfOutputPath); err != nil {
console.Fatal("Failed to write Tensorflow compatibility matrix: %s", err)
console.Fatalf("Failed to write Tensorflow compatibility matrix: %s", err)
}
}
if *torchOutputPath != "" {
if err := writeTorchCompatibilityMatrix(*torchOutputPath); err != nil {
console.Fatal("Failed to write PyTorch compatibility matrix: %s", err)
console.Fatalf("Failed to write PyTorch compatibility matrix: %s", err)
}
}
if *cudaImagesOutputPath != "" {
if err := writeCUDABaseImageTags(*cudaImagesOutputPath); err != nil {
console.Fatal("Failed to write CUDA base images: %s", err)
console.Fatalf("Failed to write CUDA base images: %s", err)
}
}
}

func writeTFCompatibilityMatrix(outputPath string) error {
console.Info("Writing Tensorflow compatibility matrix to %s...", outputPath)
console.Infof("Writing Tensorflow compatibility matrix to %s...", outputPath)

url := "https://www.tensorflow.org/install/source"
resp, err := soup.Get(url)
Expand Down Expand Up @@ -94,7 +94,7 @@ func writeTFCompatibilityMatrix(outputPath string) error {
}

func writeTorchCompatibilityMatrix(outputPath string) error {
console.Info("Writing PyTorch compatibility matrix to %s...", outputPath)
console.Infof("Writing PyTorch compatibility matrix to %s...", outputPath)

compats := []model.TorchCompatibility{}
var err error
Expand Down Expand Up @@ -123,7 +123,7 @@ func writeTorchCompatibilityMatrix(outputPath string) error {
}

func writeCUDABaseImageTags(outputPath string) error {
console.Info("Writing CUDA base images to %s...", outputPath)
console.Infof("Writing CUDA base images to %s...", outputPath)
url := "https://hub.docker.com/v2/repositories/nvidia/cuda/tags/?page_size=1000&name=devel-ubuntu&ordering=last_updated"
resp, err := soup.Get(url)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions pkg/cli/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

var benchmarkSetups int
var benchmarkRuns int
var benchmarkTarget string

type BenchmarkResults struct {
SetupTimes []float64
Expand All @@ -35,6 +36,7 @@ func newBenchmarkCommand() *cobra.Command {

cmd.Flags().IntVarP(&benchmarkSetups, "setup-iterations", "s", 3, "Number of setup iterations")
cmd.Flags().IntVarP(&benchmarkRuns, "run-iterations", "r", 3, "Number of run iterations per setup iteration")
cmd.Flags().StringVarP(&benchmarkTarget, "target", "t", "docker-cpu", "Target to benchmark (e.g. docker-cpu, docker-gpu)")

return cmd
}
Expand All @@ -47,7 +49,7 @@ func benchmarkModel(cmd *cobra.Command, args []string) error {
id := args[0]

cli := client.NewClient()
console.Info("Starting benchmark of %s:%s", repo, id)
console.Infof("Starting benchmark of %s:%s", repo, id)

mod, err := cli.GetModel(repo, id)
if err != nil {
Expand All @@ -67,7 +69,7 @@ func benchmarkModel(cmd *cobra.Command, args []string) error {
}
results := new(BenchmarkResults)
for i := 0; i < benchmarkSetups; i++ {
console.Info("Running setup iteration %d", i+1)
console.Infof("Running setup iteration %d", i+1)
if err := runBenchmarkInference(mod, modelDir, results, benchmarkRuns); err != nil {
return err
}
Expand Down Expand Up @@ -100,13 +102,13 @@ func runBenchmarkInference(mod *model.Model, modelDir string, results *Benchmark

logWriter := logger.NewConsoleLogger()
bootStart := time.Now()
deployment, err := servingPlatform.Deploy(mod, model.TargetDockerCPU, logWriter)
deployment, err := servingPlatform.Deploy(mod, benchmarkTarget, logWriter)
if err != nil {
return err
}
defer func() {
if err := deployment.Undeploy(); err != nil {
console.Warn("Failed to kill Docker container: %s", err)
console.Warnf("Failed to kill Docker container: %s", err)
}
}()
bootTime := time.Since(bootStart).Seconds()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func buildModel(cmd *cobra.Command, args []string) error {
return fmt.Errorf("%s does not exist in %s. Are you in the right directory?", global.ConfigFilename, projectDir)
}

console.Info("Uploading %s to %s", projectDir, repo)
console.Infof("Uploading %s to %s", projectDir, repo)

cli := client.NewClient()
mod, err := cli.UploadModel(repo, projectDir)
Expand Down
10 changes: 9 additions & 1 deletion pkg/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func newDebugCommand() *cobra.Command {
Short: "Generate a Dockerfile from " + global.ConfigFilename,
Hidden: true,
}
cmd.Flags().StringP("arch", "a", "cpu", "Architecture (cpu/gpu)")

cmd.AddCommand(debug)

Expand Down Expand Up @@ -57,8 +58,15 @@ func cmdDockerfile(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if err := config.ValidateAndCompleteConfig(); err != nil {
return err
}

generator := &docker.DockerfileGenerator{Config: config, Arch: "cpu"}
arch, err := cmd.Flags().GetString("arch")
if err != nil {
return err
}
generator := &docker.DockerfileGenerator{Config: config, Arch: arch}
out, err := generator.Generate()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/infer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func cmdInfer(cmd *cobra.Command, args []string) error {
}
defer func() {
if err := deployment.Undeploy(); err != nil {
console.Warn("Failed to kill Docker container: %s", err)
console.Warnf("Failed to kill Docker container: %s", err)
}
}()

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func setRepo(cmd *cobra.Command, args []string) error {
}
exists, err := files.FileExists(filepath.Join(cwd, global.ConfigFilename))
if !exists {
console.Warn("%s does not exist in %s. Are you in the right directory?", global.ConfigFilename, cwd)
console.Warnf("%s does not exist in %s. Are you in the right directory?", global.ConfigFilename, cwd)
}

cli := client.NewClient()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func startServer(cmd *cobra.Command, args []string) error {
}
}

console.Debug("Preparing to start server on port %d", port)
console.Debugf("Preparing to start server on port %d", port)

// TODO(andreas): make this configurable
dataDir := ".cog"
Expand Down
6 changes: 6 additions & 0 deletions pkg/cli/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func showModel(cmd *cobra.Command, args []string) error {
if arg.Help != nil {
help = *arg.Help
}
if arg.Min != nil {
typeStr += ", min: " + *arg.Min
}
if arg.Max != nil {
typeStr += ", max: " + *arg.Max
}
if arg.Default != nil {
typeStr += ", default: " + *arg.Default
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (c *Client) UploadModel(repo *model.Repo, projectDir string) (*model.Model,
msg := new(logger.Message)
if err := json.Unmarshal(line, msg); err != nil {
console.Debug(string(line))
console.Warn("Failed to parse console message: %s", err)
console.Warnf("Failed to parse console message: %s", err)
continue
}
switch msg.Type {
Expand Down
52 changes: 39 additions & 13 deletions pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,54 @@ type Console struct {
}

// Debug level message
func (c *Console) Debug(msg string, v ...interface{}) {
c.log(DebugLevel, msg, v...)
func (c *Console) Debug(msg string) {
c.log(DebugLevel, msg)
}

// Info level message
func (c *Console) Info(msg string, v ...interface{}) {
c.log(InfoLevel, msg, v...)
func (c *Console) Info(msg string) {
c.log(InfoLevel, msg)
}

// Warn level message
func (c *Console) Warn(msg string, v ...interface{}) {
c.log(WarnLevel, msg, v...)
func (c *Console) Warn(msg string) {
c.log(WarnLevel, msg)
}

// Error level message
func (c *Console) Error(msg string, v ...interface{}) {
c.log(ErrorLevel, msg, v...)
func (c *Console) Error(msg string) {
c.log(ErrorLevel, msg)
}

// Fatal level message, followed by exit
func (c *Console) Fatal(msg string, v ...interface{}) {
c.log(FatalLevel, msg, v...)
func (c *Console) Fatal(msg string) {
c.log(FatalLevel, msg)
os.Exit(1)
}

// Debug level message
func (c *Console) Debugf(msg string, v ...interface{}) {
c.log(DebugLevel, fmt.Sprintf(msg, v...))
}

// Info level message
func (c *Console) Infof(msg string, v ...interface{}) {
c.log(InfoLevel, fmt.Sprintf(msg, v...))
}

// Warn level message
func (c *Console) Warnf(msg string, v ...interface{}) {
c.log(WarnLevel, fmt.Sprintf(msg, v...))
}

// Error level message
func (c *Console) Errorf(msg string, v ...interface{}) {
c.log(ErrorLevel, fmt.Sprintf(msg, v...))
}

// Fatal level message, followed by exit
func (c *Console) Fatalf(msg string, v ...interface{}) {
c.log(FatalLevel, fmt.Sprintf(msg, v...))
os.Exit(1)
}

Expand Down Expand Up @@ -75,20 +101,20 @@ func (c *Console) DebugOutput(line string) {
fmt.Fprintln(os.Stderr, line)
}

func (c *Console) log(level Level, msg string, v ...interface{}) {
func (c *Console) log(level Level, msg string) {
if level < c.Level {
return
}

prompt := "═══╡ "
continuationPrompt := " │ "

formattedMsg := fmt.Sprintf(msg, v...)
formattedMsg := msg

// Word wrap
width, err := GetWidth()
if err != nil {
Debug("error getting width of terminal: %s", err)
Debugf("error getting width of terminal: %s", err)
} else if width > 30 {
// Only do word wrapping for terminals 30 chars or wider. Anything smaller and the terminal
// is probably resized really small for some reason, and when the user resizes it to be big
Expand Down
45 changes: 35 additions & 10 deletions pkg/console/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,53 @@ func SetColor(color bool) {
}

// Debug level message.
func Debug(msg string, v ...interface{}) {
ConsoleInstance.Debug(msg, v...)
func Debug(msg string) {
ConsoleInstance.Debug(msg)
}

// Info level message.
func Info(msg string, v ...interface{}) {
ConsoleInstance.Info(msg, v...)
func Info(msg string) {
ConsoleInstance.Info(msg)
}

// Warn level message.
func Warn(msg string, v ...interface{}) {
ConsoleInstance.Warn(msg, v...)
func Warn(msg string) {
ConsoleInstance.Warn(msg)
}

// Error level message.
func Error(msg string, v ...interface{}) {
ConsoleInstance.Error(msg, v...)
func Error(msg string) {
ConsoleInstance.Error(msg)
}

// Fatal level message.
func Fatal(msg string, v ...interface{}) {
ConsoleInstance.Fatal(msg, v...)
func Fatal(msg string) {
ConsoleInstance.Fatal(msg)
}

// Debug level message.
func Debugf(msg string, v ...interface{}) {
ConsoleInstance.Debugf(msg, v...)
}

// Info level message.
func Infof(msg string, v ...interface{}) {
ConsoleInstance.Infof(msg, v...)
}

// Warn level message.
func Warnf(msg string, v ...interface{}) {
ConsoleInstance.Warnf(msg, v...)
}

// Error level message.
func Errorf(msg string, v ...interface{}) {
ConsoleInstance.Errorf(msg, v...)
}

// Fatal level message.
func Fatalf(msg string, v ...interface{}) {
ConsoleInstance.Fatalf(msg, v...)
}

// Output a line to stdout. Useful for printing primary output of a command, or the output of a subcommand.
Expand Down
2 changes: 1 addition & 1 deletion pkg/console/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (i Interactive) Read() (string, error) {

if i.Options != nil {
if !slices.ContainsString(i.Options, text) {
Warn("%s is not a valid option", text)
Warnf("%s is not a valid option", text)
continue
}
}
Expand Down
Loading