Skip to content

Commit e28cb3a

Browse files
RJKeevilriccardopinosio
authored andcommitted
Fix compilation issues with XLA disabled
1 parent 1c3728d commit e28cb3a

4 files changed

Lines changed: 28 additions & 11 deletions

File tree

datasets/dataset_xla_disabled.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ package datasets
44

55
import "github.com/knights-analytics/hugot/pipelineBackends"
66

7-
type Dataset interface{}
7+
type Dataset interface {
8+
SetVerbose(bool)
9+
}
810

911
type SemanticSimilarityDataset struct{}
1012

1113
func (s *SemanticSimilarityDataset) SetTokenizationPipeline(_ pipelineBackends.Pipeline) error {
1214
return nil
1315
}
16+
17+
func (s *SemanticSimilarityDataset) SetVerbose(_ bool) {}

hugot_training.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,17 @@ func (s *TrainingSession) Train() error {
9797
func (s *TrainingSession) Save(path string) error {
9898
model := s.pipeline.GetModel()
9999
if model != nil {
100-
xlaModel := model.XLAModel
101-
if xlaModel != nil {
102-
if err := xlaModel.OnnxModel.ContextToONNX(xlaModel.Ctx); err != nil {
103-
return err
100+
if s.runtime == "XLA" {
101+
xlaModel := model.XLAModel
102+
if xlaModel != nil {
103+
return xlaModel.Save(path)
104+
} else {
105+
return fmt.Errorf("xla model is nil")
104106
}
105-
if err := xlaModel.OnnxModel.SaveToFile(path); err != nil {
106-
return err
107-
}
108-
return nil
109107
} else {
110-
return fmt.Errorf("xla model is nil")
108+
return fmt.Errorf("XLA runtime is required for saving a training model")
111109
}
110+
112111
} else {
113112
return fmt.Errorf("pipeline model is nil")
114113
}

pipelineBackends/model_xla.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,13 @@ func nextPowerOf2(n int) int {
227227
}
228228
return pow
229229
}
230+
231+
func (xlaModel *XLAModel) Save(path string) error {
232+
if err := xlaModel.OnnxModel.ContextToONNX(xlaModel.Ctx); err != nil {
233+
return err
234+
}
235+
if err := xlaModel.OnnxModel.SaveToFile(path); err != nil {
236+
return err
237+
}
238+
return nil
239+
}

pipelineBackends/model_xla_disabled.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ func createXLAModelBackend(_ *Model, _ *options.Options) error {
1414
return nil
1515
}
1616

17-
func createInputTensorsXLA(_ *PipelineBatch, _ []InputOutputInfo) error {
17+
func createInputTensorsXLA(_ *PipelineBatch, _ []InputOutputInfo, _ bool) error {
1818
return nil
1919
}
2020

2121
func runXLASessionOnBatch(_ *PipelineBatch, _ *BasePipeline) error {
2222
return nil
2323
}
24+
25+
func (xlaModel *XLAModel) Save(_ string) error {
26+
return nil
27+
}

0 commit comments

Comments
 (0)