-
Notifications
You must be signed in to change notification settings - Fork 727
⚡ Bolt: Optimize RequestMetrics to_dict serialization for faster request handling #6981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| # limitations under the License. | ||
| """ | ||
|
|
||
| from dataclasses import dataclass, field | ||
| from dataclasses import asdict, dataclass, field, is_dataclass | ||
| from typing import NamedTuple, Optional | ||
|
|
||
| import paddle | ||
|
|
@@ -164,6 +164,28 @@ class SpeculateMetrics: | |
| """ | ||
| accept_ratio_per_head: list[float] | ||
|
|
||
| def to_dict(self): | ||
| """ | ||
| Convert the SpeculateMetrics object to a dictionary. | ||
| """ | ||
| d = {} | ||
| for f in self.__dataclass_fields__: | ||
| v = getattr(self, f) | ||
| if type(v) in (int, float, str, bool, type(None)): | ||
| d[f] = v | ||
| elif is_dataclass(v): | ||
| if hasattr(v, "to_dict"): | ||
| d[f] = v.to_dict() | ||
| else: | ||
| d[f] = asdict(v) | ||
| elif isinstance(v, list): | ||
| d[f] = list(v) | ||
| elif isinstance(v, dict): | ||
|
Comment on lines
+171
to
+183
|
||
| d[f] = dict(v) | ||
| else: | ||
| d[f] = v | ||
| return d | ||
|
Comment on lines
+167
to
+187
|
||
|
|
||
|
|
||
| @dataclass | ||
| class SamplerOutput: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR 标题目前不符合仓库约定的「[CLASS]Title」格式(例如 [Perf] Optimize RequestMetrics to_dict serialization ...)。建议去掉 emoji/前缀并按该格式重命名,以便后续自动化工具/发布记录识别。