@@ -83,19 +83,19 @@ type tokenizedInput struct {
8383// PipelineBatch represents a batch of inputs that runs through the pipeline.
8484type PipelineBatch struct {
8585 Input []tokenizedInput
86- InputTensors []* ort.Tensor [int64 ]
8786 MaxSequenceLength int
88- OutputTensors []* ort.Tensor [float32 ]
87+ InputValues []ort.Value
88+ OutputValues []ort.Value
8989}
9090
9191func (b * PipelineBatch ) Destroy () error {
92- destroyErrors := make ([]error , 0 , len (b .InputTensors )+ len (b .OutputTensors ))
92+ destroyErrors := make ([]error , 0 , len (b .InputValues )+ len (b .OutputValues ))
9393
94- for _ , tensor := range b .InputTensors {
94+ for _ , tensor := range b .InputValues {
9595 destroyErrors = append (destroyErrors , tensor .Destroy ())
9696 }
9797
98- for _ , tensor := range b .OutputTensors {
98+ for _ , tensor := range b .OutputValues {
9999 destroyErrors = append (destroyErrors , tensor .Destroy ())
100100 }
101101 return errors .Join (destroyErrors ... )
@@ -231,7 +231,7 @@ func createInputTensors(batch *PipelineBatch, inputsMeta []ort.InputOutputInfo)
231231 tensorSize := len (batch .Input ) * (batch .MaxSequenceLength )
232232 batchSize := int64 (len (batch .Input ))
233233
234- inputTensors := make ([]* ort.Tensor [ int64 ] , len (inputsMeta ))
234+ inputTensors := make ([]ort.Value , len (inputsMeta ))
235235 var tensorCreationErr error
236236
237237 for i , inputMeta := range inputsMeta {
@@ -263,7 +263,7 @@ func createInputTensors(batch *PipelineBatch, inputsMeta []ort.InputOutputInfo)
263263 return tensorCreationErr
264264 }
265265 }
266- batch .InputTensors = inputTensors
266+ batch .InputValues = inputTensors
267267 return nil
268268}
269269
@@ -297,8 +297,7 @@ func runSessionOnBatch(batch *PipelineBatch, session *ort.DynamicAdvancedSession
297297 maxSequenceLength := int64 (batch .MaxSequenceLength )
298298
299299 // allocate vectors with right dimensions for the output
300- outputTensors := make ([]* ort.Tensor [float32 ], len (outputs ))
301- arbitraryOutputTensors := make ([]ort.ArbitraryTensor , len (outputs ))
300+ outputTensors := make ([]ort.Value , len (outputs ))
302301 var outputCreationErr error
303302
304303 for outputIndex , meta := range outputs {
@@ -326,22 +325,15 @@ func runSessionOnBatch(batch *PipelineBatch, session *ort.DynamicAdvancedSession
326325 if outputCreationErr != nil {
327326 return outputCreationErr
328327 }
329- arbitraryOutputTensors [outputIndex ] = ort .ArbitraryTensor (outputTensors [outputIndex ])
330328 }
331329
332- // Run Onnx model
333- arbitraryInputTensors := make ([]ort.ArbitraryTensor , len (batch .InputTensors ))
334- for i , t := range batch .InputTensors {
335- arbitraryInputTensors [i ] = ort .ArbitraryTensor (t )
336- }
337-
338- errOnnx := session .Run (arbitraryInputTensors , arbitraryOutputTensors )
330+ errOnnx := session .Run (batch .InputValues , outputTensors )
339331 if errOnnx != nil {
340332 return errOnnx
341333 }
342334
343335 // store resulting tensors
344- batch .OutputTensors = outputTensors
336+ batch .OutputValues = outputTensors
345337 return nil
346338}
347339
0 commit comments