Repository navigation
Conversation
Signed-off-by: Daraan <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request improves the stack information for warn_if_slow by adding stacklevel=2 to the logger.warning call. This is a great enhancement for debuggability, as it will now correctly point to the location where warn_if_slow is used, rather than the utility function itself. The accompanying formatting fixes also improve code style. The changes are correct and well-implemented. I've added one suggestion to consider adding a test to verify the new logging behavior.
| logger.warning( | ||
| self.message.format(name=self.name, duration=duration), stacklevel=2 | ||
| ) |
There was a problem hiding this comment.
This change to add stacklevel=2 is a great improvement for debuggability. To ensure this behavior is maintained and to prevent future regressions, it would be beneficial to add a unit test. A test could use caplog to capture the warning and assert that the LogRecord's pathname and lineno correctly point to the call site of with warn_if_slow(...).
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
|
Anti Stale comment |
|
@matthewdeng : This looks quite beneficial, would you take a look, please? |
…67610) ## Summary Adds the missing docstrings, `Args:` entries, and `Returns:` sections on public Ray Tune symbols in `search`, `stopper`, `trainable`, `context`, `utils`, `execution`, and `logger`. Each describes existing behavior, written from the code. It follows #67608, which covers `ray.tune.schedulers`. Stacked on #67608: this PR targets that branch so the correctness PR above it can build on both, and retargets to `master` once #67608 merges. The two PRs share no files. ## Before Across these subpackages, 23 public symbols had no docstring, 43 parameters had no `Args:` entry, and 14 callables that annotate a return type had no `Returns:` section. The sampling functions such as `tune.uniform`, `tune.quniform`, and `tune.randint` described their bounds in prose but had no `Args:` block. ## After 19 of the 23 docstrings, 35 of the 43 parameters, and 10 of the 14 `Returns:` sections are documented. Where a base class lacked the docstring its overrides inherit, this PR documents the base instead of each override: `Searcher.get_state`, `Searcher.set_state`, `Stopper.__call__`, and `Stopper.stop_all`. That covers both `ConcurrencyLimiter` classes and `Repeater`, and `CombinedStopper`. Behavior is unchanged. The diff touches only docstrings, which the guard below confirms. ## Not in this PR - **Four methods with untyped signatures:** `BasicVariantGenerator.set_state` and `save_to_dir`, `FunctionStopper.is_valid_function`, and `Trainable.reset`. pydoclint, run with `--arg-type-hints-in-signature`, rejects an `Args:` section on a signature without type hints, so documenting these 6 parameters needs a signature change. That signature change is in #67612, since this PR is docstring-only. `BasicVariantGenerator.set_state` and `FunctionStopper.is_valid_function` get a docstring here, without sections. - **`TuneContext.get_trial_name`, `get_trial_id`, `get_trial_resources`, and `get_trial_dir`:** these take their docstrings at runtime from `ray.train._internal.session` through `@_copy_doc`, so they render documented already. A docstring written on the method would be overwritten. Their `Returns:` sections belong on the `session` functions, which Ray Train owns. - **`Repeater.on_trial_complete`:** #67013 changes this method and edits the same docstring, so its `Args:` entries are left to land after that PR. ## For reviewers These docstrings are worth a close read: - `Verbosity` documents the four levels as the `verbose` argument of `tune.run` describes the legacy output, and notes that the default output treats levels 2 and 3 the same (`get_air_verbosity` in `tune/experimental/output.py`). - `PlacementGroupFactory.__call__` is deprecated. Its new docstring says so and points to `to_placement_group()`. - `BasicVariantGenerator.get_state` documents that it returns `False` instead of a state when any variants are generated lazily. ## Duplicate check No open PR documents these symbols. Open PRs #66923 (`stopper.py`), #66699 (`logger/json.py`), and #58359 (`utils/util.py`) change code in files this PR touches, and all three apply cleanly on top of this branch. #67013 (`repeater.py`) also applies cleanly, because this PR leaves the method it changes alone. ## Testing - `python ci/ray_ci/doc/check_docstring_only.py --base "$(git merge-base upstream/master HEAD)"`: `docstring-only guard: 15 file(s), docstrings only.` - The full pre-commit suite on the changed files, including ruff, black, pydoclint, and the docstyle hook: passed. - `ci/ray_ci/doc/api_param_coverage.py`, run over `python/ray/tune/` outside `schedulers/`: 43 undocumented parameters on `master`, 8 on this branch: 6 on the four untyped signatures and 2 on `Repeater.on_trial_complete`, all listed above. - The commit carries an `@rtd-build` line, so the Read the Docs preview renders the changed docstrings. AI assistance (Claude Code) was used to prepare this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Currently warn_if_slow does now show us where in the code the slow function is executed.
The logger message will just point us to:
ray/tune/utils/util.py.This PR adds a stacklevel of 2 to the logging_warning which helps to better trace where in tune the function was actually used.
pre-commit wanted some formatting as well