mirror of
https://github.com/ollama/ollama.git
synced 2026-02-20 08:16:07 -05:00
This change adds a new MLX based runner which includes: * Method-based MLX bindings * Subprocess-based MLX runner (x/mlxrunner) * KV cache with tree management * A basic sampler The GLM4-MoE-Lite model has been ported to use the new bindings. --------- Co-authored-by: Michael Yang <git@mxy.ng>
46 lines
853 B
Go
46 lines
853 B
Go
//go:build mlx
|
|
|
|
package mlx
|
|
|
|
// #include "generated.h"
|
|
import "C"
|
|
|
|
import (
|
|
"log/slog"
|
|
"sync"
|
|
)
|
|
|
|
type Device struct {
|
|
ctx C.mlx_device
|
|
}
|
|
|
|
func (d Device) LogValue() slog.Value {
|
|
str := C.mlx_string_new()
|
|
defer C.mlx_string_free(str)
|
|
C.mlx_device_tostring(&str, d.ctx)
|
|
return slog.StringValue(C.GoString(C.mlx_string_data(str)))
|
|
}
|
|
|
|
var DefaultDevice = sync.OnceValue(func() Device {
|
|
d := C.mlx_device_new()
|
|
C.mlx_get_default_device(&d)
|
|
return Device{d}
|
|
})
|
|
|
|
type Stream struct {
|
|
ctx C.mlx_stream
|
|
}
|
|
|
|
func (s Stream) LogValue() slog.Value {
|
|
str := C.mlx_string_new()
|
|
defer C.mlx_string_free(str)
|
|
C.mlx_stream_tostring(&str, s.ctx)
|
|
return slog.StringValue(C.GoString(C.mlx_string_data(str)))
|
|
}
|
|
|
|
var DefaultStream = sync.OnceValue(func() Stream {
|
|
s := C.mlx_stream_new()
|
|
C.mlx_get_default_stream(&s, DefaultDevice().ctx)
|
|
return Stream{s}
|
|
})
|