mirror of
https://github.com/ollama/ollama.git
synced 2025-05-11 18:36:41 +02:00
ml: Empty tensor constructor for tensors
In cases where we allocate a tensor and then fully overwrite it with copied data, it is wasteful to first zero out the memory.
This commit is contained in:
parent
55e5776c44
commit
ee141cc821
4 changed files with 29 additions and 14 deletions
|
@ -82,6 +82,7 @@ func NewBackend(f *os.File, params BackendParams) (Backend, error) {
|
|||
}
|
||||
|
||||
type Context interface {
|
||||
Empty(dtype DType, shape ...int) Tensor
|
||||
Zeros(dtype DType, shape ...int) Tensor
|
||||
FromFloatSlice(s []float32, shape ...int) (Tensor, error)
|
||||
FromIntSlice(s []int32, shape ...int) (Tensor, error)
|
||||
|
@ -195,7 +196,7 @@ func Dump(ctx Context, t Tensor, opts ...DumpOptions) string {
|
|||
return strconv.FormatFloat(float64(f), 'f', opts[0].Precision, 32)
|
||||
})
|
||||
case DTypeF16:
|
||||
f32 := ctx.Zeros(DTypeF32, t.Shape()...)
|
||||
f32 := ctx.Empty(DTypeF32, t.Shape()...)
|
||||
f32 = t.Copy(ctx, f32)
|
||||
return dump[[]float32](ctx, f32, opts[0].Items, func(f float32) string {
|
||||
return strconv.FormatFloat(float64(f), 'f', opts[0].Precision, 32)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue