trinity.common.models.sglang_model module#
- class trinity.common.models.sglang_model.SGLangClient(server_url: str, api_key: str | None, logger: Logger)[source]#
Bases:
objectA simple http client to interact with the SGLang API server.
- async init_weights_update_group(master_address: str, master_port: int, rank_offset: int, world_size: int, group_name: str, backend: str = 'nccl', timeout: int = 1200) bool[source]#
- async flush_cache(timeout: float = 30) bool[source]#
Flush KV and Mamba cache to free GPU memory before weight sync.
- async update_weights_from_distributed(state_dict_meta_list: List[Tuple[str, str, Tuple]], group_name: str, flush_cache: bool = True, abort_all_requests: bool = False, weight_version: str | None = None, timeout: float = 300) bool[source]#
- class trinity.common.models.sglang_model.SGLangRolloutModel(config: InferenceModelConfig)[source]#
Bases:
BaseInferenceModelWrapper around the SGLang engine to handle async requests.
- Parameters:
config (Config) β The config.
- __init__(config: InferenceModelConfig) None[source]#
- async init_process_group(master_address: str, master_port: int, rank_offset: int, world_size: int, group_name: str, backend: str = 'nccl', timeout: int = 1200)[source]#
Initialize the process group for model weight synchronization.
- async set_state_dict_meta(state_dict_meta: List[Tuple[str, str, Tuple]])[source]#
Set the state_dict meta for NCCL weight sync.
- async teardown_process_group()[source]#
Destroy the weight update group via the SGLang API.
Only the main node (node_rank=0) issues the API call; other nodes just clear local state.
- async generate(prompt: str, lora_request=None, **kwargs) Sequence[Experience][source]#
Generate a responses from a prompt in async.
- async chat(messages: List[dict], lora_request=None, **kwargs) Sequence[Experience][source]#
Generate experiences from a list of history chat messages in async.
- async logprobs(token_ids: List[int], **kwargs) Tensor[source]#
Generate logprobs for a list of tokens in async.
- async convert_messages_to_experience(messages: List[dict], tools=None, temperature: float | None = None) Experience[source]#
Convert a list of messages into an experience in async.
- Parameters:
messages β List of message dictionaries
tools β Optional list of tools
temperature β Optional temperature for logprobs calculation
- async sync_model_weights(model_version: int, method: SyncMethod, timeout: float = 1200) int[source]#
Sync the model with the latest model_version.