Skip to content

[train] Add missing docstrings, Args, and Returns to the framework integrations - #67620

Merged
pseudo-rnd-thoughts merged 1 commit into
masterfrom
doc-1921-train-framework-docstrings
Nov 2, 2026
Merged

pseudo-rnd-thoughts merged 1 commit into
masterfrom
doc-1921-train-framework-docstrings

Conversation

@dstrodtman

@dstrodtman dstrodtman commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the missing docstrings, Args: entries, and Returns: 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 no Returns: section. TensorflowConfig had no class docstring.

After

  • The Lightning strategies' root_device and distributed_sampler_kwargs, every RayLightningEnvironment method, and RayTrainReportCallback.on_train_epoch_end have docstrings.
  • Both prepare_trainer functions document trainer and what they return.
  • The get_model methods on the LightGBM and XGBoost checkpoints and trainers document their arguments and return value.
  • BackendConfig.backend_cls, train_func_context, framework, and to_dict are documented on the base class rather than on each override, so TorchConfig, TorchXLAConfig, TensorflowConfig, HorovodConfig, and JaxConfig inherit 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) and on_train_epoch_end (trainer, pl_module), and the Transformers RayTrainReportCallback.on_save (args, state, control). pydoclint runs with --arg-type-hints-in-signature, so an Args: 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: the Returns: 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 _HorovodBackend passes the config to Horovod's Coordinator.
  • RayLightningEnvironment.teardown does 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.
  • 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 integrations: 14 undocumented parameters on master, 8 on this branch, all on the untyped signatures 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

…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]>
@dstrodtman dstrodtman added train Ray Train Related Issue go add ONLY when ready to merge, run all tests docstring-only Skip heavy library tests for Ray API docstring edits. labels Oct 30, 2026
@dstrodtman
dstrodtman requested a review from a team as a code owner October 30, 2026 17:09
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

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
pseudo-rnd-thoughts merged commit 991e976 into master Nov 2, 2026
6 checks passed
@pseudo-rnd-thoughts
pseudo-rnd-thoughts deleted the doc-1921-train-framework-docstrings branch November 2, 2026 11:09
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]>
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docstring-only Skip heavy library tests for Ray API docstring edits. go add ONLY when ready to merge, run all tests train Ray Train Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants