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
32 changes: 27 additions & 5 deletions components/src/dynamo/common/config_dump/config_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,27 @@ def dump_config(dump_config_to: Optional[str], config: Any) -> None:
Raises:
Logs errors but does not raise exceptions to ensure graceful degradation.
"""
config_dump_payload = get_config_dump(config)

if dump_config_to:
config_dump_payload = get_config_dump(config)
try:
dump_path = pathlib.Path(dump_config_to)
dump_path.parent.mkdir(parents=True, exist_ok=True)
with open(dump_path.resolve(), "w", encoding="utf-8") as f:
f.write(config_dump_payload)
logger.info(f"Dumped config to {dump_path.resolve()}")
except (OSError, IOError):
logger.exception(f"Failed to dump config to {dump_config_to}")
logger.exception(
f"Failed to dump config to {dump_config_to}, dropping to stdout"
)
logger.info(f"CONFIG_DUMP: {config_dump_payload}")
except Exception:
logger.exception("Unexpected error dumping config")
logger.exception("Unexpected error dumping config, dropping to stdout")
logger.info(f"CONFIG_DUMP: {config_dump_payload}")
else:
logger.info(f"CONFIG_DUMP: {config_dump_payload}")
elif logger.getEffectiveLevel() <= logging.DEBUG:
# only collect/dump config if the logger is at DEBUG level or lower
config_dump_payload = get_config_dump(config)
logger.debug(f"CONFIG_DUMP: {config_dump_payload}")


def get_config_dump(config: Any, extra_info: Optional[Dict[str, Any]] = None) -> str:
Expand Down Expand Up @@ -183,6 +187,20 @@ def add_config_dump_args(parser: argparse.ArgumentParser):
)


try:
# trtllm uses pydantic, but it's not a hard dependency
import pydantic

def try_process_pydantic(obj: Any) -> Optional[dict]:
if isinstance(obj, pydantic.BaseModel):
return obj.model_dump()

except ImportError:

def try_process_pydantic(obj: Any) -> Optional[dict]:
return None


@functools.singledispatch
def _preprocess_for_encode(obj: object) -> object:
"""
Expand All @@ -193,6 +211,10 @@ def _preprocess_for_encode(obj: object) -> object:
"""
if dataclasses.is_dataclass(obj) and not isinstance(obj, type):
return dataclasses.asdict(obj)

if (result := try_process_pydantic(obj)) is not None:
return result

logger.warning(f"Unknown type {type(obj)}, using __dict__ or str(obj)")
if hasattr(obj, "__dict__"):
return obj.__dict__
Expand Down
9 changes: 8 additions & 1 deletion components/src/dynamo/trtllm/utils/trtllm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tensorrt_llm.llmapi import BuildConfig

from dynamo._core import get_reasoning_parser_names, get_tool_parser_names
from dynamo.common.config_dump import add_config_dump_args
from dynamo.common.config_dump import add_config_dump_args, register_encoder
from dynamo.trtllm import __version__
from dynamo.trtllm.request_handlers.handler_base import (
DisaggregationMode,
Expand Down Expand Up @@ -98,6 +98,13 @@ def __str__(self) -> str:
)


@register_encoder(Config)
def _preprocess_for_encode_config(
obj: Config,
) -> dict: # pyright: ignore[reportUnusedFunction]
return obj.__dict__


def is_first_worker(config):
"""
Check if the current worker is the first worker in the disaggregation chain.
Expand Down
Loading