Repository navigation
[train] Type-annotate four Train callback methods so their parameters can be documented - #67622
Merged
Merged
Conversation
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
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
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]>
Base automatically changed from
doc-1921-train-framework-docstrings
to
master
November 2, 2026 11:09
… can be documented Add type hints to the Lightning RayTrainReportCallback constructor and on_train_epoch_end, the Transformers RayTrainReportCallback.on_save, and WandbLoggerCallback.on_experiment_end, and document their parameters. pydoclint runs with --arg-type-hints-in-signature, so it rejects an Args section on a signature without type hints. The Lightning callback's prose argument list becomes an Args section. The new annotations that name optional or v2-only types are imported under TYPE_CHECKING, so runtime imports are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
dstrodtman
force-pushed
the
doc-1921-train-callback-type-hints
branch
from
November 2, 2026 13:19
894f425 to
f17e53e
Compare
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 type hints to four public Ray Train callback methods so their parameters can be documented, and documents them: the Lightning
RayTrainReportCallbackconstructor andon_train_epoch_end, the TransformersRayTrainReportCallback.on_save, andWandbLoggerCallback.on_experiment_end.Stacked on #67620, which writes the docstrings these
Args:sections extend. It retargets tomasteronce #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 anArgs: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 thedocstring-onlylabel, and premerge runs Train's tests on it.Changes
RayTrainReportCallback.__init__:checkpoint_upload_mode: Optional["CheckpointUploadMode"]andvalidation: Union[bool, "ValidationTaskConfig"], matching what the callback passes toray.train.report. The class docstring's prose list of arguments becomes anArgs:section, plus aRaises:section for the existingTypeErrorandValueErrorchecks.RayTrainReportCallback.on_train_epoch_end(self, trainer: pl.Trainer, pl_module: pl.LightningModule) -> None, withArgs:.RayTrainReportCallback.on_save(self, args: "TrainingArguments", state: "TrainerState", control: "TrainerControl", **kwargs: Any) -> None, withArgs:.WandbLoggerCallback.on_experiment_end(self, trials: List["Trial"], **info: Any), withArgs:.The type hints don't change behavior.
ValidationTaskConfigand the three Transformers types are imported underTYPE_CHECKINGonly, so the runtime imports of both modules are unchanged.CheckpointUploadModeis 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
ci/ray_ci/doc/api_param_coverage.pyover the Lightning and Transformers integrations andwandb.py: 16 undocumented parameters on the base branch, 7 on this one. The remaining 7 are onWandbLoggerCallback'slog_trial_*methods, which this PR leaves alone.AI assistance (Claude Code) was used to prepare this PR.
🤖 Generated with Claude Code