OpenAI Compatible Frontend (#116)

This commit is contained in:
Zhuohan Li
2023-05-23 21:39:50 -07:00
committed by GitHub
parent e86717833d
commit 057daef778
20 changed files with 644 additions and 169 deletions

View File

@ -1,5 +1,5 @@
"""A layer that samples the next tokens from the model's outputs."""
from typing import Dict, List, Tuple
from typing import Dict, List, Tuple, Optional
import numpy as np
import torch
@ -258,9 +258,9 @@ def _apply_top_p_top_k(
def _get_topk_logprobs(
logprobs: torch.Tensor,
num_logprobs: int,
num_logprobs: Optional[int],
) -> Dict[int, float]:
if num_logprobs == 0:
if num_logprobs is None or num_logprobs == 0:
return {}
topk_logprobs, topk_ids = torch.topk(logprobs, num_logprobs)