close temporary context

This commit is contained in:
Michael Yang 2025-04-03 09:59:03 -07:00
parent efa75659c3
commit 2fce80288f

View File

@ -112,8 +112,10 @@ func (m *TextModel) Forward(ctx ml.Context, inputs, positions, outputs ml.Tensor
row := image.Multimodal.(*imageRow)
row.parent.dataOnce.Do(func() {
// use a new, throwaway context so the image tensor is not added to the graph
m.Backend().NewContext().Forward(row.parent.tensor).Compute(row.parent.tensor)
temp := m.Backend().NewContext()
temp.Forward(row.parent.tensor).Compute(row.parent.tensor)
row.parent.data = row.parent.tensor.Floats()
temp.Close()
})
imageFeature, err := ctx.Input().FromFloatSlice(row.data(), row.shape...)