mlxrunner

package
v0.32.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 51 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(args []string) error

Types

type Client added in v0.16.0

type Client struct {
	// contains filtered or unexported fields
}

Client wraps an MLX runner subprocess to implement llm.LlamaServer for LLM models.

func NewClient added in v0.16.2

func NewClient(modelName string, softContextLength int) (*Client, error)

NewClient prepares a new MLX runner client for LLM models. The subprocess is not started until Load() is called.

func (*Client) ApplyChatTemplate added in v0.30.0

func (c *Client) ApplyChatTemplate(ctx context.Context, req llm.ChatRequest) (string, error)

func (*Client) Chat added in v0.30.0

func (c *Client) Chat(ctx context.Context, req llm.ChatRequest, fn func(llm.ChatResponse)) error

func (*Client) Close added in v0.16.0

func (c *Client) Close() error

Close terminates the subprocess.

func (*Client) Completion added in v0.16.0

func (c *Client) Completion(ctx context.Context, req llm.CompletionRequest, fn func(llm.CompletionResponse)) error

Completion implements llm.LlamaServer.

func (*Client) ContextLength added in v0.16.0

func (c *Client) ContextLength() int

func (*Client) Detokenize added in v0.16.0

func (c *Client) Detokenize(ctx context.Context, tokens []int) (string, error)

Detokenize implements llm.LlamaServer.

func (*Client) Embedding added in v0.16.0

func (c *Client) Embedding(ctx context.Context, input string) ([]float32, int, error)

Embedding implements llm.LlamaServer.

func (*Client) GetDeviceInfos added in v0.16.0

func (c *Client) GetDeviceInfos(ctx context.Context) []ml.DeviceInfo

GetDeviceInfos implements llm.LlamaServer.

func (*Client) GetPort added in v0.16.0

func (c *Client) GetPort() int

GetPort implements llm.LlamaServer.

func (*Client) HasExited added in v0.16.0

func (c *Client) HasExited() bool

HasExited implements llm.LlamaServer.

func (*Client) Load added in v0.16.0

func (c *Client) Load(ctx context.Context, _ ml.SystemInfo, gpus []ml.DeviceInfo, requireFull bool) ([]ml.DeviceID, error)

Load checks whether the model fits in GPU memory and starts the subprocess.

func (*Client) MemorySize added in v0.17.5

func (c *Client) MemorySize() (total, vram uint64)

MemorySize implements llm.LlamaServer.

func (*Client) ModelPath added in v0.16.0

func (c *Client) ModelPath() string

ModelPath implements llm.LlamaServer.

func (*Client) Pid added in v0.16.0

func (c *Client) Pid() int

Pid implements llm.LlamaServer.

func (*Client) Ping added in v0.16.0

func (c *Client) Ping(ctx context.Context) error

Ping implements llm.LlamaServer.

func (*Client) Tokenize added in v0.16.0

func (c *Client) Tokenize(ctx context.Context, content string) ([]int, error)

Tokenize implements llm.LlamaServer.

func (*Client) VRAMByGPU added in v0.16.0

func (c *Client) VRAMByGPU(id ml.DeviceID) uint64

VRAMByGPU implements llm.LlamaServer.

func (*Client) WaitUntilRunning added in v0.16.0

func (c *Client) WaitUntilRunning(ctx context.Context) error

WaitUntilRunning waits for the subprocess to be ready.

type CompletionRequest added in v0.21.1

type CompletionRequest struct {
	Prompt      string
	Options     api.Options
	Logprobs    bool
	TopLogprobs int
}

type CompletionResponse added in v0.17.5

type CompletionResponse struct {
	Content    string
	Done       bool
	DoneReason int

	PromptEvalCount    int
	PromptEvalDuration time.Duration
	EvalCount          int
	EvalDuration       time.Duration

	Logprobs []llm.Logprob

	Error *api.StatusError
}

type Request

type Request struct {
	CompletionRequest
	Responses chan CompletionResponse
	Pipeline  func(context.Context, Request) error

	Ctx         context.Context //nolint:containedctx // Queued requests carry caller cancellation to the runner.
	Tokens      []int32
	SamplerOpts sample.Options
}

Request is a short-lived struct that carries a completion request through a channel from the HTTP handler to the runner goroutine. The ctx field must travel with the request so that cancellation propagates across the channel boundary.

type Runner added in v0.18.0

type Runner struct {
	Model     base.Model
	Tokenizer *tokenizer.Tokenizer
	Requests  chan Request
	Sampler   *sample.Sampler
	// contains filtered or unexported fields
}

func (*Runner) Load added in v0.18.0

func (r *Runner) Load(modelName string) error

func (*Runner) Prepare added in v0.21.1

func (r *Runner) Prepare(request *Request) error

Prepare tokenizes the prompt and validates it against the model's context length. It is safe to call from any goroutine. On success it populates request.Tokens and adjusts request.Options.NumPredict.

func (*Runner) Run added in v0.18.0

func (r *Runner) Run(host, port string, mux http.Handler) error

func (*Runner) TextGenerationPipeline added in v0.18.0

func (r *Runner) TextGenerationPipeline(ctx context.Context, request Request) error

Directories

Path Synopsis
mlx
generator command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL