Repository navigation
[train] Add missing docstrings, Args, and Returns to the framework integrations - #67620
Merged
Merged
Conversation
…tegrations Backfill docstrings, Args entries, and Returns sections on public Ray Train symbols in the Lightning, Torch, TensorFlow, Horovod, Hugging Face, LightGBM, and XGBoost integrations. Each describes existing behavior. BackendConfig.backend_cls, train_func_context, framework, and to_dict are documented on the base class so the framework configs that override them inherit the entries. Docstring-only: no code changes. @rtd-build Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
This was referenced Oct 30, 2026
Merged
pseudo-rnd-thoughts
pushed a commit
that referenced
this pull request
Oct 30, 2026
…nd AIR (#67621) ## Summary Adds the missing docstrings, `Args:` entries, and `Returns:` sections on public Ray Train and AIR symbols in `ray.train.v2`, `ray.train.context`, `ray.train._internal`, `ray.train._checkpoint`, `ray.train.health`, and `ray.air.config`. Each describes existing behavior, written from the code. #67620 covers the framework integrations. ## Before Across these modules, 13 public symbols had no docstring, 4 parameters had no `Args:` entry, and 31 callables that annotate a return type had no `Returns:` section. ## After - The `ray.train._internal.session` accessors (`get_metadata`, `get_experiment_name`, `get_trial_name`, `get_trial_id`, `get_run_id`, `get_trial_resources`, `get_trial_dir`, `get_world_size`, `get_world_rank`, `get_local_rank`) have `Returns:` sections, including the default each returns outside a Train or Tune function. - `ray.train.v2` `TrainContext` methods, both `get_context` functions, `JaxConfig`, `ValidationFn.__call__`, `CheckpointUploadMode.default_delete_local_checkpoint_after_upload`, and `RunConfig.storage_context` are documented. - `Checkpoint.get_metadata`, `set_metadata`, and `update_metadata`, `DataConfig.default_ingest_options`, both `ScalingConfig` placement-group methods, and `Probe.probe_name` are documented. `ray.train.context.TrainContext` and `ray.tune.context.TuneContext` copy their accessor docstrings from `ray.train._internal.session` through `@_copy_doc`, so the session `Returns:` sections document those methods too. A docstring written on the context methods would be overwritten. Behavior is unchanged. The diff touches only docstrings, which the guard below confirms. ## Not in this PR - `JaxConfig.backend_cls`, `framework`, and `to_dict` inherit their docstrings from `BackendConfig`, which #67620 documents. - `WandbLoggerCallback.on_experiment_end`: its `**info` parameter has no type hint, so an `Args:` section raises pydoclint DOC107 under `--arg-type-hints-in-signature`. #67622 adds the type hint and documents it. ## For reviewers These are worth a close read: - The session accessors are `@PublicAPI` but have no public import path. They're documented here because the public `TrainContext` and `TuneContext` render their docstrings. Whether they stay public is a separate question. - `ScalingConfig.as_placement_group_factory` describes the bundle layout: an empty head bundle, a bundle combining the trainer with the first worker, and one bundle per other worker. - `JaxConfig` documents that Ray Train skips JAX distributed setup when neither `use_tpu` nor `use_gpu` is set. ## Duplicate check No open PR documents these symbols. #67521 changes Ray Train health probes but touches only `ray.train.v2._internal`, not `health/probe.py`. ## Testing - `python ci/ray_ci/doc/check_docstring_only.py --base "$(git merge-base upstream/master HEAD)"`: `docstring-only guard: 12 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` over the changed modules and `ray.air.integrations`: 11 undocumented parameters on `master`, 8 on this branch. The rest are on `WandbLoggerCallback`, outside this PR's scope or blocked as 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]>
pseudo-rnd-thoughts
approved these changes
Nov 2, 2026
dstrodtman
added a commit
that referenced
this pull request
Nov 2, 2026
… can be documented (#67622) ## Summary Adds type hints to four public Ray Train callback methods so their parameters can be documented, and documents them: the Lightning `RayTrainReportCallback` constructor and `on_train_epoch_end`, the Transformers `RayTrainReportCallback.on_save`, and `WandbLoggerCallback.on_experiment_end`. Stacked on #67620, which writes the docstrings these `Args:` sections extend. It retargets to `master` once #67620 merges. ## Why this isn't in the docstring-only PRs Ray's pydoclint hook runs with `--arg-type-hints-in-signature`, so it rejects an `Args:` section on a signature without type hints (DOC106, DOC107). These methods had none, or had an unannotated `**info`, so documenting their 9 parameters needs a signature change. A signature change isn't docstring-only, so it's in its own PR without the `docstring-only` label, and premerge runs Train's tests on it. ## Changes - Lightning `RayTrainReportCallback.__init__`: `checkpoint_upload_mode: Optional["CheckpointUploadMode"]` and `validation: Union[bool, "ValidationTaskConfig"]`, matching what the callback passes to `ray.train.report`. The class docstring's prose list of arguments becomes an `Args:` section, plus a `Raises:` section for the existing `TypeError` and `ValueError` checks. - Lightning `RayTrainReportCallback.on_train_epoch_end(self, trainer: pl.Trainer, pl_module: pl.LightningModule) -> None`, with `Args:`. - Transformers `RayTrainReportCallback.on_save(self, args: "TrainingArguments", state: "TrainerState", control: "TrainerControl", **kwargs: Any) -> None`, with `Args:`. - `WandbLoggerCallback.on_experiment_end(self, trials: List["Trial"], **info: Any)`, with `Args:`. The type hints don't change behavior. `ValidationTaskConfig` and the three Transformers types are imported under `TYPE_CHECKING` only, so the runtime imports of both modules are unchanged. `CheckpointUploadMode` is a string annotation on the module's existing conditional import. ## Duplicate check No open PR changes these signatures. Searches for `RayTrainReportCallback`, `WandbLoggerCallback`, and the changed paths returned nothing overlapping. #67621, the sibling docstring PR for core Train and AIR, doesn't touch these files. ## Testing - 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` over the Lightning and Transformers integrations and `wandb.py`: 16 undocumented parameters on the base branch, 7 on this one. The remaining 7 are on `WandbLoggerCallback`'s `log_trial_*` methods, which this PR leaves alone. - Train's unit tests run in premerge on this PR. Lightning, Transformers, and W&B aren't installed in my local environment, so I couldn't import-test the changed modules locally. 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]>
5 of 7 tasks
pseudo-rnd-thoughts
pushed a commit
that referenced
this pull request
Nov 16, 2026
…n legacy LightGBM/XGBoost trainers (#68145) ## Why are these changes needed? In `_get_legacy_train_fn_per_worker` for both `LightGBMTrainer` (`python/ray/train/lightgbm/lightgbm_trainer.py`) and `XGBoostTrainer` (`python/ray/train/xgboost/xgboost_trainer.py`): 1. `num_boost_round = num_boost_round or DEFAULT_NUM_BOOST_ROUND` used truthiness instead of an explicit `is None` check. When a caller explicitly passed `num_boost_round=0` (for example in dry-run initialization or checkpoint evaluation without additional boosting rounds), `0 or 10` silently evaluated to `10`. 2. `callbacks = trainer_kwargs.get("callbacks", [])` retrieved the caller's list reference directly and appended `default_callback_cls()` in-place (`callbacks.append(...)`). Reusing the same configuration dictionary across multiple `Trainer` instantiations mutated the caller's `callbacks` list on each run, and passing `callbacks=None` or a tuple raised an `AttributeError`. This PR: - Checks `if num_boost_round is None: num_boost_round = DEFAULT_NUM_BOOST_ROUND` so explicit `0` is preserved. - Copies `callbacks = list(trainer_kwargs.get("callbacks") or [])` before appending the default `RayTrainReportCallback`. ## Related issue number N/A ## Checks - [x] I've signed off every commit(by using the -s flag, i.e., `git commit -s`) in this PR. - [x] I've run `scripts/format.sh` to lint the changes in this PR. - [x] I've included any doc changes needed for https://docs.ray.io/en/master/. - [x] I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/ - Testing Strategy - [x] Unit tests (`python/ray/train/tests/test_lightgbm_trainer.py` and `python/ray/train/tests/test_xgboost_trainer.py`) - [ ] Release tests - [ ] This PR is not tested :( ## Acknowledgements Thanks to @dstrodtman (#67821, #67786, #67620), @pseudo-rnd-thoughts (#63988, #63427, #63365), and @justinvyu (#57256, #50042) for their work maintaining `LightGBMTrainer` and `XGBoostTrainer`. --------- Signed-off-by: Parth Vadera <[email protected]> Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the missing docstrings,
Args:entries, andReturns:sections on public Ray Train symbols in the framework integrations: Lightning, Torch, TensorFlow, Horovod, Hugging Face Transformers, LightGBM, and XGBoost. Each describes existing behavior, written from the code. #67621 covers core Train and AIR.Before
Across these integrations, 23 public symbols had no docstring, 14 parameters had no
Args:entry, and 13 callables that annotate a return type had noReturns:section.TensorflowConfighad no class docstring.After
root_deviceanddistributed_sampler_kwargs, everyRayLightningEnvironmentmethod, andRayTrainReportCallback.on_train_epoch_endhave docstrings.prepare_trainerfunctions documenttrainerand what they return.get_modelmethods on the LightGBM and XGBoost checkpoints and trainers document their arguments and return value.BackendConfig.backend_cls,train_func_context,framework, andto_dictare documented on the base class rather than on each override, soTorchConfig,TorchXLAConfig,TensorflowConfig,HorovodConfig, andJaxConfiginherit them.Behavior is unchanged. The diff touches only docstrings, which the guard below confirms.
Not in this PR
8 parameters on three methods with untyped signatures: the Lightning
RayTrainReportCallback.__init__(checkpoint_upload_mode,validation,checkpoint_frequency) andon_train_epoch_end(trainer,pl_module), and the TransformersRayTrainReportCallback.on_save(args,state,control). pydoclint runs with--arg-type-hints-in-signature, so anArgs:section on these raises DOC106 and DOC107. Documenting them needs a signature change, which doesn't belong in a docstring-only PR. #67622, stacked on this PR, adds the type hints and documents them.For reviewers
These are worth a close read:
RayFSDPStrategy.lightning_module_state_dict: theReturns:section describes the Lightning 2.0.x full-state-dict path and the fallback to the parent strategy.HorovodConfig.start_timeout: the docstring says Horovod reads it when the config serves as its settings object, since_HorovodBackendpasses the config to Horovod'sCoordinator.RayLightningEnvironment.teardowndoes nothing; the docstring says so rather than inventing a reason.Duplicate check
No open PR documents these symbols. Searches for
docstring train,RayTrainReportCallback,TorchConfig,prepare_trainer, and the changed paths returned nothing overlapping.Testing
python ci/ray_ci/doc/check_docstring_only.py --base "$(git merge-base upstream/master HEAD)":docstring-only guard: 9 file(s), docstrings only.ci/ray_ci/doc/api_param_coverage.pyover the changed integrations: 14 undocumented parameters onmaster, 8 on this branch, all on the untyped signatures listed above.@rtd-buildline, so the Read the Docs preview renders the changed docstrings.AI assistance (Claude Code) was used to prepare this PR.
🤖 Generated with Claude Code