59a0a3844c
PR Test AMD / cancel-on-close (push) Has been skipped
PR Test NVIDIA ARM / scan (push) Has been skipped
PR Test NVIDIA / cancel-on-close (push) Has been skipped
PR Test AMD / scan (push) Has been skipped
PR Test NVIDIA ARM / cancel-on-close (push) Has been skipped
PR Test NVIDIA / scan (push) Has been skipped
Release Docker Images / build (cu129-torch-2.11.0) (push) Has been skipped
Release Docker Images / build (cu130-torch-2.11.0) (push) Has been skipped
Release PyPI / publish (push) Has been skipped
Scheduler Python Test / test (push) Successful in 27m19s
Docs / build (push) Successful in 28m8s
Scheduler C++ Test / test (push) Successful in 28m19s
Scheduler C++ Test / test-flat (push) Successful in 28m18s
Docs / deploy (push) Has been cancelled
PR Test AMD / finish (push) Has been cancelled
PR Test NVIDIA / finish (push) Has been cancelled
PR Test NVIDIA ARM / finish (push) Has been cancelled
PR Test NVIDIA ARM / ${{ matrix.name }} (${{ matrix.runner }}) (push) Has been cancelled
PR Test AMD / ${{ matrix.name }} (${{ matrix.runner }}) (push) Has been cancelled
PR Test NVIDIA / ${{ matrix.name }} (${{ matrix.runner }}) (push) Has been cancelled
91 lines
3.6 KiB
Python
Executable File
91 lines
3.6 KiB
Python
Executable File
# SPDX-License-Identifier: MIT AND Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright (c) 2026 LightSeek Foundation
|
|
# SPDX-FileCopyrightText: Copyright contributors to the FluentLLM project
|
|
# SPDX-FileCopyrightText: Copyright 2023-2024 SGLang Team
|
|
#
|
|
# Copyright (c) 2026 LightSeek Foundation
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
# in the Software without restriction, including without limitation the rights
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
# furnished to do so, subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in
|
|
# all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
# SOFTWARE.
|
|
|
|
"""Abstract engine interface for runtime entrypoints."""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from collections.abc import Iterator
|
|
|
|
import torch
|
|
|
|
|
|
class EngineBase(ABC):
|
|
"""Abstract base class for engine interfaces.
|
|
|
|
This interface covers generation, weight updates, and memory control for
|
|
both HTTP-based adapters and in-process engines.
|
|
"""
|
|
|
|
@abstractmethod
|
|
def generate(
|
|
self,
|
|
prompt: list[str] | str | None = None,
|
|
sampling_params: list[dict] | dict | None = None,
|
|
input_ids: list[list[int]] | list[int] | None = None,
|
|
return_logprob: list[bool] | bool | None = None,
|
|
logprob_start_len: list[int] | int | None = None,
|
|
top_logprobs_num: list[int] | int | None = None,
|
|
token_ids_logprob: list[list[int]] | list[int] | None = None,
|
|
return_text_in_logprobs: bool = False,
|
|
logprob_format: list[str | None] | str | None = None,
|
|
custom_logit_processor: list[str] | str | None = None,
|
|
return_hidden_states: bool | None = None,
|
|
stream: bool | None = None,
|
|
bootstrap_host: list[str] | str | None = None,
|
|
bootstrap_port: list[int] | int | None = None,
|
|
bootstrap_room: list[int] | int | None = None,
|
|
data_parallel_rank: int | None = None,
|
|
) -> dict | Iterator[dict]:
|
|
"""Generate outputs based on given inputs."""
|
|
|
|
@abstractmethod
|
|
def flush_cache(self) -> None:
|
|
"""Flush the cache of the engine."""
|
|
|
|
@abstractmethod
|
|
def update_weights_from_tensor(
|
|
self,
|
|
named_tensors: list[tuple[str, torch.Tensor]],
|
|
load_format: str | None = None,
|
|
flush_cache: bool = True,
|
|
) -> None:
|
|
"""Update model weights with in-memory tensor data."""
|
|
|
|
@abstractmethod
|
|
def release_memory_occupation(self, tags: list[str] | None = None) -> None:
|
|
"""Release GPU memory occupation temporarily (optionally by tag)."""
|
|
|
|
@abstractmethod
|
|
def resume_memory_occupation(self, tags: list[str] | None = None) -> None:
|
|
"""Resume GPU memory occupation previously released (optionally by tag)."""
|
|
|
|
@abstractmethod
|
|
def is_sleeping(self) -> bool:
|
|
"""Return whether any GPU memory is currently released."""
|
|
|
|
@abstractmethod
|
|
def shutdown(self) -> None:
|
|
"""Shutdown the engine and clean up resources."""
|