Skip to content

Commit 6ce0b2e

Browse files
authored
Merge branch 'main' into lkomali/replace_gap_with_aiperf_remaining
2 parents af6f7fc + 7b0fad3 commit 6ce0b2e

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

components/src/dynamo/common/config_dump/config_dumper.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,27 @@ def dump_config(dump_config_to: Optional[str], config: Any) -> None:
9898
Raises:
9999
Logs errors but does not raise exceptions to ensure graceful degradation.
100100
"""
101-
config_dump_payload = get_config_dump(config)
102101

103102
if dump_config_to:
103+
config_dump_payload = get_config_dump(config)
104104
try:
105105
dump_path = pathlib.Path(dump_config_to)
106106
dump_path.parent.mkdir(parents=True, exist_ok=True)
107107
with open(dump_path.resolve(), "w", encoding="utf-8") as f:
108108
f.write(config_dump_payload)
109109
logger.info(f"Dumped config to {dump_path.resolve()}")
110110
except (OSError, IOError):
111-
logger.exception(f"Failed to dump config to {dump_config_to}")
111+
logger.exception(
112+
f"Failed to dump config to {dump_config_to}, dropping to stdout"
113+
)
112114
logger.info(f"CONFIG_DUMP: {config_dump_payload}")
113115
except Exception:
114-
logger.exception("Unexpected error dumping config")
116+
logger.exception("Unexpected error dumping config, dropping to stdout")
115117
logger.info(f"CONFIG_DUMP: {config_dump_payload}")
116-
else:
117-
logger.info(f"CONFIG_DUMP: {config_dump_payload}")
118+
elif logger.getEffectiveLevel() <= logging.DEBUG:
119+
# only collect/dump config if the logger is at DEBUG level or lower
120+
config_dump_payload = get_config_dump(config)
121+
logger.debug(f"CONFIG_DUMP: {config_dump_payload}")
118122

119123

120124
def get_config_dump(config: Any, extra_info: Optional[Dict[str, Any]] = None) -> str:
@@ -183,6 +187,21 @@ def add_config_dump_args(parser: argparse.ArgumentParser):
183187
)
184188

185189

190+
try:
191+
# trtllm uses pydantic, but it's not a hard dependency
192+
import pydantic
193+
194+
def try_process_pydantic(obj: Any) -> Optional[dict]:
195+
if isinstance(obj, pydantic.BaseModel):
196+
return obj.model_dump()
197+
return None
198+
199+
except ImportError:
200+
201+
def try_process_pydantic(obj: Any) -> Optional[dict]:
202+
return None
203+
204+
186205
@functools.singledispatch
187206
def _preprocess_for_encode(obj: object) -> object:
188207
"""
@@ -193,6 +212,10 @@ def _preprocess_for_encode(obj: object) -> object:
193212
"""
194213
if dataclasses.is_dataclass(obj) and not isinstance(obj, type):
195214
return dataclasses.asdict(obj)
215+
216+
if (result := try_process_pydantic(obj)) is not None:
217+
return result
218+
196219
logger.warning(f"Unknown type {type(obj)}, using __dict__ or str(obj)")
197220
if hasattr(obj, "__dict__"):
198221
return obj.__dict__

components/src/dynamo/trtllm/utils/trtllm_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from tensorrt_llm.llmapi import BuildConfig
99

1010
from dynamo._core import get_reasoning_parser_names, get_tool_parser_names
11-
from dynamo.common.config_dump import add_config_dump_args
11+
from dynamo.common.config_dump import add_config_dump_args, register_encoder
1212
from dynamo.trtllm import __version__
1313
from dynamo.trtllm.request_handlers.handler_base import (
1414
DisaggregationMode,
@@ -98,6 +98,13 @@ def __str__(self) -> str:
9898
)
9999

100100

101+
@register_encoder(Config)
102+
def _preprocess_for_encode_config(
103+
obj: Config,
104+
) -> dict: # pyright: ignore[reportUnusedFunction]
105+
return obj.__dict__
106+
107+
101108
def is_first_worker(config):
102109
"""
103110
Check if the current worker is the first worker in the disaggregation chain.

0 commit comments

Comments
 (0)