Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions python/sglang/srt/sampling/penaltylib/orchestrator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import abc
from typing import TYPE_CHECKING, Set, Type
import weakref
from typing import TYPE_CHECKING, Optional, Set, Type

import torch

Expand All @@ -17,7 +18,7 @@ def __init__(
penalizers: Set[Type["_BatchedPenalizer"]],
):
self.vocab_size = vocab_size
self.batch = batch
self._batch_ref = weakref.ref(batch)
self.device = batch.device
self.penalizers = {Penalizer: Penalizer(self) for Penalizer in penalizers}

Expand All @@ -27,6 +28,17 @@ def __init__(
is_required |= pen_is_required
self.is_required = is_required

@property
def batch(self) -> ScheduleBatch | None:
return self._batch_ref()

@batch.setter
def batch(self, value: Optional[ScheduleBatch]):
if value is None:
self._batch_ref = lambda: None
else:
self._batch_ref = weakref.ref(value)

def reqs(self):
return self.batch.reqs

Expand Down
Loading