Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
81549361 committed Oct 29, 2024
1 parent ae99f83 commit 5e5f521
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions python/sglang/srt/sampling/penaltylib/penalizers/dry_penalty.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,27 @@ def _apply(self, logits: torch.Tensor) -> torch.Tensor:
max_back_length = 50 # Limit the backward match to 50 to prevent overflow
for i in range(1):
if self.input_ids is None:
# Initialize self.input_ids as needed, for example:
self.input_ids = []

if self.output_ids is not None:
# Convert lists to tensors if necessary
if isinstance(self.output_ids, list):
self.output_ids = torch.tensor(self.output_ids)

if i < len(self.input_ids):
if isinstance(self.input_ids[i], list):
self.input_ids[i] = torch.tensor(self.input_ids[i])

self.input_ids[i] = torch.cat(
[self.input_ids[i], self.output_ids], dim=0
)
else:
self.input_ids.append(
torch.cat([self.input_ids, self.output_ids], dim=0)
)
if isinstance(self.input_ids, list):
self.input_ids = torch.tensor(self.input_ids)

new_tensor = torch.cat([self.input_ids, self.output_ids], dim=0)
self.input_ids.append(new_tensor)

input_ids = self.input_ids[i]
else:
if i < len(self.input_ids) and self.input_ids[i] is not None:
Expand Down

0 comments on commit 5e5f521

Please sign in to comment.