MCPcopy Create free account
hub / github.com/sql-machine-learning/sqlflow / TFTrainWithLoadAndSave

Function TFTrainWithLoadAndSave

go/codegen/pai/tensorflow.go:52–75  ·  view source on GitHub ↗

TFTrainWithLoadAndSave generates PAI-TF train program. Load pre-trained model if modelPathToLoad != "". Save the trained model to modelPathToSave.

(ir *ir.TrainStmt, session *pb.Session, modelPathToSave, modelPathToLoad string, cc *ClusterConfig)

Source from the content-addressed store, hash-verified

50// Load pre-trained model if modelPathToLoad != "".
51// Save the trained model to modelPathToSave.
52func TFTrainWithLoadAndSave(ir *ir.TrainStmt, session *pb.Session, modelPathToSave, modelPathToLoad string, cc *ClusterConfig) (string, error) {
53 // Distributed training must call train_and_evaluate, which need the user to specify validation.select
54 valSelect, valOK := ir.Attributes["validation.select"]
55 hasVal := true
56 if !valOK || valSelect.(string) == "" {
57 hasVal = false
58 }
59 if cc.Worker.Count > 1 && !hasVal {
60 return "", fmt.Errorf("Distributed training must specify WITH validation.select")
61 }
62
63 loadCode, err := generateLoadOSSModelCode(ir.Estimator, modelPathToLoad)
64 if err != nil {
65 return "", err
66 }
67
68 trainCode, err := tensorflow.Train(ir, session)
69 if err != nil {
70 return "", err
71 }
72
73 fullCode := fmt.Sprintf("%s\n%s", loadCode, trainCode)
74 return fullCode, nil
75}
76
77// TFLoadAndPredict generates PAI-TF prediction program.
78func TFLoadAndPredict(ir *ir.PredictStmt, session *pb.Session, modelPath string) (string, error) {

Callers 1

TrainFunction · 0.85

Calls 3

TrainFunction · 0.92
generateLoadOSSModelCodeFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected