Commit 01aa7887 authored by Jesse Gross's avatar Jesse Gross Committed by Jesse Gross
Browse files

ml: Remove Output from Context interface

Model implementations should use Input for all of their tensors
supplied to the model. This includes tensors that relate to the
outputs, which is confusing since there is also an Output funciton.

Since Output is only used internally in GGML and not used by any
model implementations, we can remove it from the interface to
reduce confusion.
parent ead27aa9
...@@ -362,7 +362,6 @@ func (c *testContext) FromIntSlice(s []int32, shape ...int) (ml.Tensor, error) { ...@@ -362,7 +362,6 @@ func (c *testContext) FromIntSlice(s []int32, shape ...int) (ml.Tensor, error) {
} }
func (c *testContext) Input() ml.Context { return c } func (c *testContext) Input() ml.Context { return c }
func (c *testContext) Output() ml.Context { return c }
func (c *testContext) Layer(int) ml.Context { return c } func (c *testContext) Layer(int) ml.Context { return c }
func (c *testContext) Forward(...ml.Tensor) ml.Context { return c } func (c *testContext) Forward(...ml.Tensor) ml.Context { return c }
......
...@@ -110,12 +110,10 @@ type Context interface { ...@@ -110,12 +110,10 @@ type Context interface {
MaxGraphNodes() int MaxGraphNodes() int
Close() Close()
// Input returns a context appropriate for creating input tensors // Input returns a context appropriate for creating tensors that are
// inputs to the model (which includes things like output locations)
Input() Context Input() Context
// Output returns a context appropriate for creating output tensors
Output() Context
// Layer returns a context appropriate for creating intermediate tensors // Layer returns a context appropriate for creating intermediate tensors
Layer(int) Context Layer(int) Context
} }
......
...@@ -48,9 +48,6 @@ type Backend struct { ...@@ -48,9 +48,6 @@ type Backend struct {
// input is the backend used for inputs // input is the backend used for inputs
input *C.struct_ggml_backend_buffer_type input *C.struct_ggml_backend_buffer_type
// output is the backend used for outputs
output *C.struct_ggml_backend_buffer_type
// layers is the backend used for repeating layers // layers is the backend used for repeating layers
layers map[int]*C.struct_ggml_backend_buffer_type layers map[int]*C.struct_ggml_backend_buffer_type
...@@ -400,8 +397,7 @@ func New(ctx context.Context, r *os.File, params ml.BackendParams) (ml.Backend, ...@@ -400,8 +397,7 @@ func New(ctx context.Context, r *os.File, params ml.BackendParams) (ml.Backend,
C.size_t(maxGraphNodes), C.size_t(maxGraphNodes),
C._Bool(len(gpus) > 1 && slices.Contains(gpus, output.d)), C._Bool(len(gpus) > 1 && slices.Contains(gpus, output.d)),
), ),
input: deviceBufferTypes[input.d], input: deviceBufferTypes[input.d],
output: deviceBufferTypes[output.d],
layers: func() map[int]*C.struct_ggml_backend_buffer_type { layers: func() map[int]*C.struct_ggml_backend_buffer_type {
m := make(map[int]*C.struct_ggml_backend_buffer_type) m := make(map[int]*C.struct_ggml_backend_buffer_type)
for i, layer := range layers { for i, layer := range layers {
...@@ -482,19 +478,6 @@ func (c Context) Input() ml.Context { ...@@ -482,19 +478,6 @@ func (c Context) Input() ml.Context {
return &c return &c
} }
func (c Context) Output() ml.Context {
if c.b.output != nil {
return &Context{
b: c.b,
ctx: c.ctx,
buft: c.b.output,
maxGraphNodes: c.maxGraphNodes,
}
}
return &c
}
func (c Context) Layer(i int) ml.Context { func (c Context) Layer(i int) ml.Context {
if buft, ok := c.b.layers[i]; ok { if buft, ok := c.b.layers[i]; ok {
return &Context{ return &Context{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment