Skip to content

[train] Add missing docstrings, Args, and Returns across core Train and AIR - #67621

Merged
pseudo-rnd-thoughts merged 1 commit into
masterfrom
doc-1921-train-core-docstrings
Oct 30, 2026
Merged

pseudo-rnd-thoughts merged 1 commit into
masterfrom
doc-1921-train-core-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 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

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

…nd AIR

Backfill 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.

The Returns sections on the ray.train._internal.session accessors also
document ray.train.context.TrainContext and ray.tune.context.TuneContext,
which copy those docstrings through _copy_doc.

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
pseudo-rnd-thoughts merged commit 5b74588 into master Oct 30, 2026
6 checks passed
@pseudo-rnd-thoughts
pseudo-rnd-thoughts deleted the doc-1921-train-core-docstrings branch October 30, 2026 23:01
pseudo-rnd-thoughts pushed a commit that referenced this pull request Nov 2, 2026
…tegrations (#67620)

## 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](https://claude.com/claude-code)

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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]>
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