Xorbits Inference (Xinference) Documentation

repository·main·Indexed 27 days ago

https://github.com/xorbitsai/inference

A versatile model serving library for language, speech, and multimodal models designed for simplified deployment across distributed and heterogeneous hardware. Includes guides for benchmarking latency and throughput, local development of the Next.js frontend, and comprehensive cluster monitoring using Prometheus, Grafana dashboards, and Filebeat log collection.

Tokens
164.9K
Snippets
664
Records
1.2K
Agent score
94%

What's inside Xinference

  1. Overview of Xorbits Inference (Xinference)

    main

    Xorbits Inference (Xinference) is a powerful and comprehensive distributed inference framework designed for deploying various models, including Large Language Models (LLM), speech recognition models, and multi-modal models. It allows users to deploy their own models or use built-in open-source models with a single command.

    Key capabilities include:

    • Simplified Deployment: One-command deployment for LLMs, speech, and multi-modal models.
    • Heterogeneous Hardware Support: Utilizes engines like ggml to leverage both GPU and CPU for inference, reducing latency and increasing throughput.
    • Flexible Interfaces: Supports OpenAI-compatible RESTful APIs (including Function Calling), RPC, Command Line, and a Web UI.
    • Distributed Computing: Supports distributed deployment with a built-in resource scheduler to manage models across a cluster of machines.
    • Open Ecosystem: Seamless integration with popular libraries such as LangChain, LlamaIndex, Dify, and Chatbox.
  2. Overview of Xinference features and capabilities

    main

    Xorbits Inference (Xinference) is a library for deploying language models, speech recognition, and multimodal models.

    Key Capabilities:

    • Simplified Deployment: Deploy LLMs and multimodal models with a single command.
    • Heterogeneous Hardware: Efficiently uses both GPU and CPU (e.g., via ggml).
    • Flexible Interfaces: Provides OpenAI-compatible RESTful APIs (including Function Calling), RPC, CLI, and a Web UI.
    • Distributed Inference: Supports running models across multiple workers and machines.
    • Third-party Integrations: Works with LangChain, LlamaIndex, Dify, and Chatbox.

    Comparison with other frameworks: Unlike FastChat or OpenLLM, Xinference supports multi-node cluster deployment, diverse inference engines (GGML, TensorRT), and a wide range of model types including image (Text-to-Image), text embeddings, multimodal, and voice models.

  3. Overview of Xinference Core Components

    main

    Xinference is structured into several key modules that handle different aspects of model serving:

    • API: Manages the RESTful interface and authentication (via oauth2).
    • Client: Provides interfaces for interaction, including the oscar Actor Client for cluster interaction and a restful client for service interaction.
    • Core: The engine of the system, containing:
      • worker.py & supervisor.py: Logic for worker actors (computation) and supervisor actors (lifecycle management and scheduling).
      • model.py: Defines the Model Actor, which handles inference requests and data streams.
      • status_guard.py: Monitors model statuses (creating, updating, terminating) via UIDs.
      • cache_tracker.py: Manages model version cache locations and information.
      • metrics.py & resource.py: Collects throughput, latency, CPU/GPU, and memory usage.
      • event.py: Gathers runtime events like warnings and errors.
    • Deploy: Provides the Command Line Interface (CLI).
    • Model: Handles model descriptions, creation, and caching.
    • Frontend: The Next.js-based Web UI.
  4. Overview of Xinference features

    main

    Xinference (Xorbits Inference) is a library for deploying large language models (LLMs), speech recognition models, and multimodal models.

    Key capabilities include:

    • Simplified Deployment: Deploy models for experimentation or production with a single command.
    • Hardware Support: Efficiently utilizes both CPU and GPU (e.g., via GGML).
    • Flexible Interfaces: Provides OpenAI-compatible RESTful APIs (including Function Calling), RPC, CLI, and a Web UI.
    • Distributed Inference: Supports running inference across multiple devices and machines.
    • Third-party Integrations: Compatible with LangChain, LlamaIndex, Dify, and Chatbox.
  5. Understand the Xinference Actor model

    main

    Xinference is built on the Xoscar actor framework. Each actor is a basic unit for model inference and can utilize specific CPU cores or GPU devices. Actors are hosted in asynchronous, non-blocking actor pools.

    Key concepts for developers extending the system:

    • Actor Actions: Define behaviors like launch_model, list_models, or terminate_model within a class inheriting from xoscar.Actor.
    • Lifecycle Methods: Use __post_create__ for initialization after an actor is created and __pre_destroy__ for cleanup before destruction.
    • Asynchronous Invocation: When calling methods via an actor reference (e.g., worker_ref.launch_model()), even synchronous methods are treated as asynchronous.
    import xoscar as xo
    
    class WorkerActor(xo.Actor):
        def __init__(self, *args, **kwargs):
            ...
        async def launch_model(self, model_id, n_gpu, ...):
            # launch an inference engine, use specific model class to load model checkpoints
            ...
        async def list_models(self):
            # list models on this actor
            ...
        async def terminate_model(self, model_id):
            # terminate the model
            ...
        async def __post_create__(self):
            # called after the actor instance is created
            ...
        async def __pre_destroy__(self):
            # called before the actor instance is destroyed
            ...
  6. Configure Xinference monitoring systems

    main

    Xinference provides two parallel monitoring systems for observability. You can use them independently or simultaneously depending on your infrastructure requirements:

    1. Prometheus (Pull Model):

      • Implementation: aioprometheus.
      • Mechanism: Exposes an HTTP /metrics endpoint for scraping.
      • Default Status: Enabled.
      • Disabling: Set the environment variable XINFERENCE_DISABLE_METRICS=1.
    2. OpenTelemetry (Push Model):

      • Implementation: opentelemetry-python.
      • Mechanism: Pushes data via OTLP (HTTP/gRPC) to an external collector.
      • Default Status: Disabled.
      • Enabling: Set the environment variable XINFERENCE_ENABLE_OTEL=true.