# xorbitsai/inference architecture

> Architecture diagram of the GitHub repository xorbitsai/inference, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xorbitsai/inference
- Repository: https://github.com/xorbitsai/inference

## Overview

##### Project Type and Purpose
- This project is a comprehensive model serving framework designed for deploying and serving language, speech, and multimodal models.
- As highlighted in the README, Xinference (Xorbits Inference) simplifies model deployment with support for RESTful APIs, distributed inference, and heterogeneous hardware utilization. It is intended for research, rapid experimentation, and enterprise deployment of state-of-the-art AI models.

##### File Structure for Key Components
- The top-level “xinference” package contains multiple subdirectories that reveal the layered architecture:
- “xinference/api” – contains OAuth2 authentication, RESTful API endpoints that expose inference functionalities.
- “xinference/client” – provides client modules to interface with the API, including RESTful client calls.
- “xinference/core” – this contains essential modules such as scheduling, metrics, resource management, progress tracking, and worker management.
- “xinference/model” – subdivided into folders like “audio”, “embedding”, “image”, “llm”, “rerank”, “video”; these modules serve as the core model handlers and specifications.
- “xinference/deploy” – includes scripts and Docker/Kubernetes (K8s) deployment configurations to launch the service in diverse settings.
- “xinference/thirdparty” – integrates a wealth of external libraries and tools (e.g., for language models, speech processing, onnx export, and other specialized functionalities).
- “xinference/web” – contains the Web UI (in “xinference/web/ui”) that supports user interaction and administration of deployed models.
- Additional directories like “doc”, “benchmark”, and “examples” contribute to documentation, performance testing, and sample usage.

A. Identify the Main Components:
- Client Layer:
- Web UI (from xinference/web/ui)
- CLI and RESTful client (from xinference/client)
- API Gateway:
- RESTful API endpoints (from xinference/api), including OAuth2 layers for authentication.
- Core Services:
- Scheduler, resource management, progress tracking (from xinference/core)
- Chat, image, and other interfaces for handling requests (e.g., chat_interface, image_interface modules)
- Model Management:
- Model modules for different modalities (audio, embedding, image, llm, etc., under xinference/model)
- Internal model specification and configuration (e.g., JSON spec files in each model subdirectory)
- Deployment & Orchestration:
- Deployment scripts (xinference/deploy) including Dockerfiles, docker-compose, and Kubernetes helm charts.
- Supervisor components and worker management (from deploy/supervisor.py and deploy/worker.py)
- Third-Party Integration Layer:
- Integration with external libraries and tools (contained in xinference/thirdparty) for specialized tasks such as distributed inference or specialized model acceleration.

B. Determine Relationships and Interactions:
- From the API Gateway, show connections to multiple Core Service components responsible for scheduling, resource allocation, and managing actual requests.
- Link the Core Services to the Model Management layer where different model types (LLM, audio, image, etc.) are loaded and executed.
- Integration points to Third-Party modules, showing how external libraries, frameworks (like ggml, vLLM, or Llama.cpp bindings) and additional functionality are leveraged.

C. Highlight Architectural Patterns and Technologies:
- A layered (or microservices-like) architecture where the separation of concerns is apparent:
- The “frontend” (client and Web UI) is decoupled from the business logic (API and core services) and the execution layer (model serving and deployment automation).
- Design principles:
- Modular design: clear separation between API, core scheduling, and model-specific logic.
- Extensibility: Third-party integration enables plugging in new inference engines or functionalities.
- Distributed deployment: Deployment components show support for clusters, Docker, and Kubernetes.
- Mention the use of RESTful API, OAuth2 for authentication, and support for various hardware acceleration technologies.

D. Tailored Guidelines Based on Project Type:
- The frontend (client and web UI) from the backend services.
- API layer and Microservices handling inference requests.
- Backend model management and hardware orchestration.
- Offer visual distinction between synchronous API calls (client to API gateway) and asynchronous processing in core services (scheduling, resource management).
- Integration with external tools that enable distributed and scalable inference operations.

- At the top, show “Client Layer” (Web UI, CLI, SDK).
- To one side, place “Core Services” which includes scheduling, metrics, resource tracking, and the supervisor.
- At the bottom, represent “Model Management” subdivided into distinct model types (LLM, audio, image, etc.), which are executed on hardware (possibly shown in a “Hardware Resource” cluster node).
- Off to the side or in an overlay, include “Deployment & Orchestration” which interfaces with the Core Services to distribute inference across multiple nodes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        UI["Client (Web UI)"] 
        CLI["Client (CLI/RESTful)"]
    end

    %% API Gateway & Authentication
    subgraph "API Gateway & Authentication"
        API["API Gateway & OAuth2 Authentication"]
    end

    %% Core Services
    subgraph "Core Services"
        Core["Core Services (Scheduler, Metrics, Resource & Worker Management)"]
    end

    %% Model Management
    subgraph "Model Management"
        Model["Model Management (Audio, Embedding, Image, LLM, Rerank, Video)"]
    end

    %% Deployment & Orchestration
    subgraph "Deployment & Orchestration"
        Deploy["Deployment & Orchestration"]
    end

    %% Third-Party Integration (shown separately)
    ThirdParty["Third-Party Integration"]

    %% Connections - Vertical Flow
    UI -->|"sendsRequests"| API
    CLI -->|"sendsRequests"| API
    API -->|"forwardsTo"| Core
    Core -->|"manages"| Model
    Model -->|"deployedBy"| Deploy

    %% Integration Lines with Third-Party
    ThirdParty ---|"integratesWith"| Core
    ThirdParty ---|"supports"| Model

    %% Styles for Colors and Shapes
    classDef client fill:#aee1f9,stroke:#333,stroke-width:2px;
    classDef api fill:#c0e7c0,stroke:#333,stroke-width:2px;
    classDef core fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef model fill:#f9c0c0,stroke:#333,stroke-width:2px;
    classDef deploy fill:#d1d1f9,stroke:#333,stroke-width:2px;
    classDef thirdparty fill:#c0d6f9,stroke:#333,stroke-width:2px;

    %% Apply Classes
    class UI,CLI client;
    class API api;
    class Core core;
    class Model model;
    class Deploy deploy;
    class ThirdParty thirdparty;

    %% Click Events
    click UI "https://github.com/xorbitsai/inference/tree/main/xinference/web/ui"
    click CLI "https://github.com/xorbitsai/inference/tree/main/xinference/client"
    click API "https://github.com/xorbitsai/inference/tree/main/xinference/api"
    click Core "https://github.com/xorbitsai/inference/tree/main/xinference/core"
    click Model "https://github.com/xorbitsai/inference/tree/main/xinference/model"
    click Deploy "https://github.com/xorbitsai/inference/tree/main/xinference/deploy"
    click ThirdParty "https://github.com/xorbitsai/inference/tree/main/xinference/thirdparty"
```
