-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f164cb
commit 584aa03
Showing
8 changed files
with
49 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import functools | ||
from typing import Callable, Any | ||
|
||
from ... import config, logger | ||
|
||
def generation_logger(func: Callable) -> Callable: | ||
@functools.wraps(func) # 保留 func 的元信息 | ||
def wrapper(self, *args, **kwargs) -> Any: | ||
result = func(self, *args, **kwargs) | ||
if config.log_model_io: | ||
logger.info("【model_io】"+self.backend+":"+self.model_name+".generate()") | ||
logger.info("- input_text: "+result["input_text"]) | ||
logger.info("- output_text: "+result["output_text"]) | ||
return result | ||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import math | ||
|
||
def convert_openai_logprobs(logprobs): | ||
logprobs = logprobs.model_dump() | ||
logits_list = [] | ||
for token_info in logprobs["content"]: | ||
logits = { | ||
"token": token_info["token"], | ||
"pred_token": [], | ||
# "logits": [], | ||
"probs": [], | ||
"logprobs": [] | ||
} | ||
for predict_info in token_info["top_logprobs"]: | ||
logits["pred_token"].append(predict_info["token"]) | ||
logits["logprobs"].append(round(predict_info["logprob"],4)) | ||
logits["probs"].append(round(math.exp(predict_info["logprob"]),4)) | ||
logits_list.append(logits) | ||
return logits_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters