Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 18 additions & 2 deletions fastdeploy/engine/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import json
import time
import traceback
from dataclasses import asdict, dataclass, fields
from dataclasses import asdict, dataclass, fields, is_dataclass
from enum import Enum
from typing import Any, Dict, Generic, Optional
from typing import TypeVar as TypingTypeVar
Expand Down Expand Up @@ -896,7 +896,23 @@ def to_dict(self):
"""
Convert the RequestMetrics object to a dictionary.
"""
return {k: v for k, v in asdict(self).items()}
res = {}
for k in self.__dataclass_fields__:
v = getattr(self, k)
Comment on lines +899 to +901
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR 标题目前未按仓库 PR 模板要求包含至少一个标签(形如 [Optimization]...)。建议将标题改为例如 [Optimization] Optimize RequestMetrics.to_dict() serialization(可按需要叠加 [Engine] 等标签),以满足模板检查项并便于后续检索。

Copilot uses AI. Check for mistakes.
if type(v) in (int, float, str, bool, type(None)):
res[k] = v
elif type(v) is list:
res[k] = list(v)
elif type(v) is dict:
res[k] = dict(v)
elif is_dataclass(v):
if hasattr(v, "to_dict"):
res[k] = v.to_dict()
else:
res[k] = asdict(v)
else:
res[k] = v
return res
Comment on lines +899 to +915
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RequestMetrics.to_dict() 的序列化逻辑与 fastdeploy/worker/output.py::SpeculateMetrics.to_dict() 基本重复;建议抽一个共享的轻量 helper(例如放到 metrics/utils 模块)或复用同一实现,避免未来一处修改导致两处行为不一致。

Copilot uses AI. Check for mistakes.

def record_recv_first_token(self):
cur_time = time.time()
Expand Down
14 changes: 14 additions & 0 deletions fastdeploy/worker/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ class SpeculateMetrics:
"""
accept_ratio_per_head: list[float]

def to_dict(self):
res = {}
for k in self.__dataclass_fields__:
v = getattr(self, k)
if type(v) in (int, float, str, bool, type(None)):
res[k] = v
elif type(v) is list:
res[k] = list(v)
elif type(v) is dict:
res[k] = dict(v)
else:
res[k] = v
return res
Comment on lines +167 to +179
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SpeculateMetrics.to_dict()fastdeploy/engine/request.py::RequestMetrics.to_dict() 存在重复的“快速 dataclass 序列化”逻辑;建议抽取共享 helper 或基类复用,减少重复代码并避免后续序列化规则分叉。

Copilot uses AI. Check for mistakes.


@dataclass
class SamplerOutput:
Expand Down
Loading