Skip to content

Commit

Permalink
feat: Update example model and remove relayout option
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-cj committed Aug 23, 2020
1 parent fd7f814 commit a4b25ad
Show file tree
Hide file tree
Showing 17 changed files with 0 additions and 65 deletions.
65 changes: 0 additions & 65 deletions cmd/ormb-storage-initializer/cmd/pull-and-export.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"

"github.com/kleveross/ormb/pkg/consts"
"github.com/kleveross/ormb/pkg/model"
"github.com/kleveross/ormb/pkg/oras"
"github.com/kleveross/ormb/pkg/ormb"
)
Expand Down Expand Up @@ -86,73 +81,13 @@ var pullExportCmd = &cobra.Command{
return err
}

// For model registry, can not move any exported data, but for model
// serving, it must relayout model file so that it will work.
if !reLayoutOpt {
return nil
}

if err := relayoutModel(dstDir); err != nil {
return err
}

return nil
},
}

func relayoutModel(modelDir string) error {
// Move the files in model directory to the upper directory.
// e.g. Move /mnt/models/model to /mnt/models (dstDir).
// but for tensorflow serving, MUST move /mnt/models/model to /mnt/models/1 (dstDir).
// Seldon core will run `--model_base_path=dstDir` directly.
originalDir, err := filepath.Abs(
filepath.Join(modelDir, consts.ORMBModelDirectory))
if err != nil {
return err
}
destinationDir, err := filepath.Abs(modelDir)
if err != nil {
return err
}

// For TensorFlow serving, MUST move /mnt/models/model to /mnt/models/1 (dstDir).
ormbfileBytes, err := ioutil.ReadFile(path.Join(modelDir, "ormbfile.yaml"))
if err != nil {
return err
}
var metadata model.Metadata
err = yaml.Unmarshal(ormbfileBytes, &metadata)
if err != nil {
return err
}
if metadata.Format == string(model.FormatSavedModel) {
if err := os.Rename(originalDir, path.Join(modelDir, "1")); err != nil {
return err
}

return nil
}

// For other format model.
files, err := ioutil.ReadDir(originalDir)
if err != nil {
return err
}
for _, f := range files {
oldPath := filepath.Join(originalDir, f.Name())
newPath := filepath.Join(destinationDir, f.Name())
fmt.Printf("Moving %s to %s\n", oldPath, newPath)
if err := os.Rename(oldPath, newPath); err != nil {
return err
}
}
return nil
}

func init() {
rootCmd.AddCommand(pullExportCmd)

pullExportCmd.Flags().BoolVarP(&reLayoutOpt, "relayout", "", true, "relayout data for model serving")
pullExportCmd.Flags().BoolVarP(&plainHTTPOpt, "plain-http", "", true, "use plain http and not https")
pullExportCmd.Flags().BoolVarP(&insecureOpt, "insecure", "", true, "allow connections to TLS registry without certs")
}
Loading

0 comments on commit a4b25ad

Please sign in to comment.