Skip to content

Commit ab8cbd4

Browse files
committed
switch to sphinx.ext.autodoc
1 parent 76e1d72 commit ab8cbd4

File tree

13 files changed

+47
-72
lines changed

13 files changed

+47
-72
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
docs/source/README.md
2+
docs/source/contributing.md
23
torchrunx_logs/
34
.pixi/
45
.ruff_cache/

docs/conf.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""Configuration file for the Sphinx documentation builder."""
2-
32
from glob import glob
43
import shutil
54

65
shutil.copyfile("../README.md", "source/README.md")
6+
shutil.copyfile("../CONTRIBUTING.md", "source/contributing.md")
77

88
project = "torchrunx"
9+
copyright = 'Apoorv Khandelwal and Peter Curtin'
910
github_username = "apoorvkh"
1011
github_repository = "torchrunx"
1112
html_theme = "furo"
@@ -14,7 +15,7 @@
1415
html_extra_path = list(glob("source/examples/scripts/*.py"))
1516

1617
extensions = [
17-
"autodoc2",
18+
"sphinx.ext.autodoc",
1819
"myst_parser", # support markdown
1920
"sphinx.ext.intersphinx", # link to external docs
2021
"sphinx.ext.napoleon", # for google style docstrings
@@ -23,14 +24,11 @@
2324
"sphinx_toolbox.github",
2425
]
2526

26-
maximum_signature_line_length = 100
27-
autodoc2_render_plugin = "myst"
28-
intersphinx_mapping = {
29-
"python": ("https://docs.python.org/3.9", None),
30-
"fabric": ("https://docs.fabfile.org/en/stable", None),
31-
'torch': ('https://pytorch.org/docs/stable', None),
32-
"numpy": ("https://numpy.org/doc/stable", None),
33-
}
27+
autodoc_member_order = "bysource"
28+
autodoc_typehints = "description"
29+
autodoc_typehints_description_target = "documented"
30+
31+
intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
3432

3533
from docs.linkcode_github import generate_linkcode_resolve_fn
3634
linkcode_resolve = generate_linkcode_resolve_fn(project, github_username, github_repository)

docs/source/api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# API
22

33
```{eval-rst}
4-
.. autofunction:: torchrunx.launch
4+
.. autofunction:: torchrunx.launch(func, args, kwargs, ...)
55
```
66

7-
We provide the {mod}`torchrunx.Launcher` class as an alias to {mod}`torchrunx.launch`.
7+
We provide the {obj}`torchrunx.Launcher` class as an alias to {obj}`torchrunx.launch`.
88

99
```{eval-rst}
1010
.. autoclass:: torchrunx.Launcher
@@ -21,9 +21,9 @@ We provide the {mod}`torchrunx.Launcher` class as an alias to {mod}`torchrunx.la
2121
## Exceptions
2222

2323
```{eval-rst}
24-
.. autoclass:: torchrunx.AgentFailedError
24+
.. autoexception:: torchrunx.AgentFailedError
2525
```
2626

2727
```{eval-rst}
28-
.. autoclass:: torchrunx.WorkerFailedError
28+
.. autoexception:: torchrunx.WorkerFailedError
2929
```

docs/source/contributing.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/source/features/customization.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ We forward all logs (i.e. from {mod}`logging` and {mod}`sys.stdout`/{mod}`sys.st
2323
We provide some utilities to help:
2424

2525
```{eval-rst}
26-
.. autofunction:: torchrunx.file_handler
26+
.. autofunction:: torchrunx.utils.file_handler
2727
```
2828

2929
```{eval-rst}
30-
.. autofunction:: torchrunx.stream_handler
30+
.. autofunction:: torchrunx.utils.stream_handler
3131
```
3232

3333
```{eval-rst}
34-
.. autofunction:: torchrunx.add_filter_to_handler
34+
.. autofunction:: torchrunx.utils.add_filter_to_handler
3535
```

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies = [
2525
[dependency-groups]
2626
dev = ["ruff==0.9.5", "pyright[nodejs]==1.1.393", "pytest==8.3.4"]
2727
test-extras = ["submitit", "transformers"]
28-
docs = ["sphinx==7.4.7", "furo==2024.8.6", "myst-parser==3.0.1", "sphinx-autodoc2==0.5.0", "sphinx-toolbox==3.8.1"]
28+
docs = ["sphinx==7.4.7", "furo==2024.8.6", "myst-parser==3.0.1", "sphinx-toolbox==3.8.2"]
2929

3030

3131
[tool.ruff]

src/torchrunx/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22

33
from .launcher import Launcher, LaunchResult, launch
44
from .utils.errors import AgentFailedError, WorkerFailedError
5-
from .utils.logging_utilities import add_filter_to_handler, file_handler, stream_handler
65

76
__all__ = [
87
"AgentFailedError",
98
"LaunchResult",
109
"Launcher",
1110
"WorkerFailedError",
12-
"add_filter_to_handler",
13-
"file_handler",
1411
"launch",
15-
"stream_handler",
1612
]

src/torchrunx/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
LauncherAgentGroup,
2020
get_open_port,
2121
)
22-
from .utils.logging_utilities import log_records_to_socket, redirect_stdio_to_logger
22+
from .utils.logging import log_records_to_socket, redirect_stdio_to_logger
2323
from .worker import WorkerArgs, worker_entrypoint
2424

2525

src/torchrunx/launcher.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
ExceptionFromWorker,
3535
WorkerFailedError,
3636
)
37-
from .utils.logging_utilities import LoggingServerArgs, start_logging_server
37+
from .utils.logging import LoggingServerArgs, start_logging_server
3838

3939

4040
def launch(
@@ -65,25 +65,33 @@ def launch(
6565
"""Distribute and parallelize a function onto specified nodes and workers.
6666
6767
Arguments:
68-
func: Function to launch on each node and replicate for each worker.
69-
args: Positional arguments for ``func``.
70-
kwargs: Keyword arguments for ``func``.
68+
func: Function to replicate on each node/worker.
69+
args: Positional arguments for ``func``. Default: :py:obj:`None`.
70+
kwargs: Keyword arguments for ``func``. Default: :py:obj:`None`.
7171
hostnames: Nodes on which to launch the function.
72-
Default: infer from localhost or SLURM.
72+
Default: ``"auto"`` (infer from localhost or SLURM).
7373
workers_per_host: Number of processes to run (e.g. # of GPUs) per node.
74-
Default: use number of GPUs on each host.
74+
Default: ``"auto"`` (number of GPUs per host).
7575
ssh_config_file: Path to an SSH configuration file for connecting to nodes.
76-
Default: ``~/.ssh/config`` or ``/etc/ssh/ssh_config``.
76+
Default: ``"~/.ssh/config"`` or ``"/etc/ssh/ssh_config"``.
7777
backend: `Backend <https://pytorch.org/docs/stable/distributed.html#torch.distributed.Backend>`_
78-
for worker process group. Set `None` to disable. Default: NCCL (GPU) or GLOO (CPU).
78+
for worker process group. Set `None` to disable.
79+
Default: ``"auto"`` (NCCL if GPU or GLOO if CPU).
7980
timeout: Worker process group timeout (seconds).
81+
Default: ``600``.
8082
default_env_vars: Environment variables to copy from the launcher process to workers.
8183
Supports bash pattern matching syntax.
84+
Default: ``("PATH", "LD_LIBRARY", "LIBRARY_PATH", "PYTHON*", "CUDA*", "TORCH*",
85+
"PYTORCH*", "NCCL*")``.
8286
extra_env_vars: Additional user-specified environment variables to copy.
87+
Default: ``()``.
8388
env_file: Path to a file (e.g., ``.env``) with additional environment variables to copy.
89+
Default: :py:obj:`None`.
8490
propagate_exceptions: Raise exceptions from worker processes in the launcher.
85-
If false, raises :obj:`WorkerFailedError` instead.
91+
If false, raises :exc:`WorkerFailedError` instead.
92+
Default: :py:obj:`True`.
8693
handler_factory: Function to customize processing of agent and worker logs with handlers.
94+
Default: ``"auto"`` (see `custom logging <https://torchrun.xyz/features/customization.html#logging>`_).
8795
8896
Raises:
8997
RuntimeError: If there are configuration issues.
@@ -115,7 +123,7 @@ def launch(
115123

116124
@dataclass
117125
class Launcher:
118-
"""Useful for sequential invocations or for specifying arguments via CLI."""
126+
"""Alias class for :func:`launch`. Refer to that function for documentation."""
119127

120128
hostnames: list[str] | Literal["auto", "slurm"] = "auto"
121129
workers_per_host: int | list[int] | Literal["auto"] = "auto"
@@ -153,7 +161,7 @@ def run( # noqa: C901, PLR0912
153161
args: tuple | None = None,
154162
kwargs: dict[str, Any] | None = None,
155163
) -> LaunchResult:
156-
"""Run a function using the :mod:`torchrunx.Launcher` configuration."""
164+
"""Launch a function using class configuration."""
157165
if not dist.is_available():
158166
msg = "The torch.distributed package is not available."
159167
raise RuntimeError(msg)

src/torchrunx/utils/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
"""Utility classes and functions."""
2+
3+
from .logging import add_filter_to_handler, file_handler, stream_handler
4+
5+
__all__ = ["add_filter_to_handler", "file_handler", "stream_handler"]

0 commit comments

Comments
 (0)