Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/source/usage/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ logging.getLogger("torchrunx.node1").setLevel(logging.INFO)
logging.getLogger("torchrunx.node1.1").setLevel(logging.INFO) # worker 1 (local rank) on node 1
```

Also, logs from all agents and workers are written to a directory (by the current timestamp) in `$TORCHRUNX_LOG_DIR` (default: `./torchrunx_logs`). These can be controlled using `$TORCHRUNX_LOG_LEVEL` (default: `INFO`).
Also, logs from all agents and workers are written to a directory (by the current timestamp) in `$TORCHRUNX_LOG_DIR` (default: `./torchrunx_logs`). These can be controlled using `$TORCHRUNX_LOG_LEVEL` (default: `INFO`). File logging can be disabled by setting `$TORCHRUNX_LOG_FILE` to `""`.

## Customization

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
requires = ["uv_build"]
build-backend = "uv_build"

[project]
name = "torchrunx"
version = "0.3.3"
version = "0.3.4"
authors = [
{ name = "Apoorv Khandelwal", email = "mail@apoorvkh.com" },
{ name = "Peter Curtin", email = "peter_curtin@brown.edu" },
Expand Down
54 changes: 30 additions & 24 deletions src/torchrunx/utils/log_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,36 @@ def default_handlers(hostnames: list[str], workers_per_host: list[int]) -> list[

Logs for the rank 0 agent and rank 0 worker are redirected to loggers in the launcher process.
Logs for all hosts/workers are written to files in ``$TORCHRUNX_LOG_DIR`` (named by timestamp,
hostname, local_rank).
hostname, local_rank). If ``$TORCHRUNX_LOG_DIR = ""`` logs will not be written to files.
"""
log_dir = Path(os.environ.get("TORCHRUNX_LOG_DIR", "torchrunx_logs"))

file_log_level = os.environ.get("TORCHRUNX_LOG_LEVEL", "INFO")
if file_log_level.isdigit():
file_log_level = int(file_log_level)
elif file_log_level in logging._nameToLevel: # noqa: SLF001
file_log_level = logging._nameToLevel[file_log_level] # noqa: SLF001
else:
msg = (
f"Invalid value for $TORCHRUNX_LOG_LEVEL: {file_log_level}. "
f"Should be a positive integer or any of: {', '.join(logging._nameToLevel.keys())}." # noqa: SLF001
)
raise ValueError(msg)

redirect_agent_0_handler = RedirectHandler()
redirect_agent_0_handler.addFilter(get_handler_filter(hostnames[0], None))
handlers = []

redirect_worker_0_handler = RedirectHandler()
redirect_worker_0_handler.addFilter(get_handler_filter(hostnames[0], 0))
# Agent 0 handler
handlers.append(RedirectHandler())
handlers[-1].addFilter(get_handler_filter(hostnames[0], None))

# Worker 0 handler
handlers.append(RedirectHandler())
handlers[-1].addFilter(get_handler_filter(hostnames[0], 0))

# Log to directory

log_dir = os.environ.get("TORCHRUNX_LOG_DIR", "torchrunx_logs")
if log_dir != "":
file_log_level = os.environ.get("TORCHRUNX_LOG_LEVEL", "INFO")
if file_log_level.isdigit():
file_log_level = int(file_log_level)
elif file_log_level in logging._nameToLevel: # noqa: SLF001
file_log_level = logging._nameToLevel[file_log_level] # noqa: SLF001
else:
msg = (
f"Invalid value for $TORCHRUNX_LOG_LEVEL: {file_log_level}. "
f"Should be a positive integer or any of: {', '.join(logging._nameToLevel.keys())}." # noqa: SLF001
)
raise ValueError(msg)

handlers += file_handlers(
hostnames, workers_per_host, log_dir=Path(log_dir), log_level=file_log_level
)

return [
redirect_agent_0_handler,
redirect_worker_0_handler,
*file_handlers(hostnames, workers_per_host, log_dir=log_dir, log_level=file_log_level),
]
return handlers
4 changes: 3 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.