Repository navigation
[Docs] Add conditional search-space example to tune.sample_from docstring (#33483) - #63443
Conversation
…ring (ray-project#33483) The docstring for tune.sample_from did not show how to define a conditional search space, which is its canonical use case. Add a short ``Example`` block under python/ray/tune/search/sample.py that samples one parameter from a range derived from another via ``spec.config``. Closes ray-project#33483 [DOC-984] Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request updates the sample_from function's docstring to include an explanation and example of conditional search spaces. The review feedback points out that the documentation uses a deprecated spec.config pattern and suggests updating it to use the config dictionary directly to prevent deprecation warnings.
|
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. |
…om-example Signed-off-by: Douglas Strodtman <[email protected]> # Conflicts: # python/ray/tune/search/sample.py
sample_from callables receive the trial config dict directly; the spec.config access pattern hits the deprecation fallback in Function._CallSampler.__try_fn and logs a warning at runtime. Also rename the example dict to param_space to avoid shadowing the lambda parameter, and fix a pre-existing typo (An callable -> A callable). Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
…les to config-dict style (#63804) ## Why are these changes needed? `tune.sample_from` callables receive the trial `config` dict directly; the legacy `spec.config` access pattern has been deprecated since the placeholder-resolution mechanism landed in Feb 2023 (befad81). Every Tune doc example still written as `lambda spec: spec.config.x` logs this warning on each trial when users copy it: > sample_from functions that take a spec dict are deprecated. Please update your function to work with the config dict directly. Follow-up to #63443, which fixed the `tune.sample_from` docstring itself. ### What changed Updated to config-dict style (`lambda config: config["x"]`): - `doc/source/tune/tutorials/tune-search-spaces.rst` — examples plus the prose describing the `spec` object and `spec.config` namespace - `doc/source/tune/api/search_space.rst` - `doc/source/tune/doc_code/faq.py` — conditional-spaces and grid-search examples - `doc/source/tune/doc_code/key_concepts.py` - `doc/source/tune/examples/pbt_visualization/pbt_visualization.ipynb` — 3 cells - `python/ray/tune/examples/pbt_tune_cifar10_with_keras.py` - `python/ray/tune/tests/test_trial_scheduler_pbt.py` — runs through `Tuner`, so it exercised the deprecated fallback on every run One of these is a bug fix rather than deprecation cleanup: the `tune-resources.rst` `with_resources` example was broken as written. Resource callables receive the bare config dict via `default_resource_request()` with no spec fallback, so `resources=lambda spec: {"gpu": 1} if spec.config.use_gpu else {"gpu": 0}` raises `AttributeError: 'dict' object has no attribute 'config'`. ### Deliberately left unchanged - `test_sample.py` and `test_var.py` `sample_from` sites — these drive `generate_variants` / `BasicVariantGenerator` directly, the legacy full-spec path where `spec.config` is still the operative contract (config-dict style would break them). - `test_placeholder.py::testFunction` — deliberate coverage that both styles work. - `test_controller_resume_integration.py` — restore-path coverage for legacy-style functions. - `variant_generator.py` docstring — documents the DeveloperAPI legacy contract and the `{"eval": ...}` syntax. ### Verification Ran the updated patterns end-to-end on ray 2.55.1: - Config-dict conditional space (`b` sampled from a range depending on `a`): 4 trials, conditional held, zero deprecation warnings. Control with the old spec style logs one warning per trial. - Fixed `with_resources` callable resolves; control with the old spec style reproduces the `AttributeError`. `ruff==0.8.4` and `black==22.10.0` (the pre-commit pins) pass on the edited Python files. ## Related issue number Internal tracking: DOC-1131. ## 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 pre-commit equivalent lint (ruff + black at pinned versions) on the changed files. - [x] I've included any doc changes needed for https://docs.ray.io/en/master/. - [ ] I've added any new APIs to the API Reference (n/a — no API changes). - [x] I've made sure the tests are passing (changed examples validated against ray 2.55.1; `test_trial_scheduler_pbt.py` change is parameter-name-only under the `Tuner` path). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…les to config-dict style (ray-project#63804) ## Why are these changes needed? `tune.sample_from` callables receive the trial `config` dict directly; the legacy `spec.config` access pattern has been deprecated since the placeholder-resolution mechanism landed in Feb 2023 (befad81). Every Tune doc example still written as `lambda spec: spec.config.x` logs this warning on each trial when users copy it: > sample_from functions that take a spec dict are deprecated. Please update your function to work with the config dict directly. Follow-up to ray-project#63443, which fixed the `tune.sample_from` docstring itself. ### What changed Updated to config-dict style (`lambda config: config["x"]`): - `doc/source/tune/tutorials/tune-search-spaces.rst` — examples plus the prose describing the `spec` object and `spec.config` namespace - `doc/source/tune/api/search_space.rst` - `doc/source/tune/doc_code/faq.py` — conditional-spaces and grid-search examples - `doc/source/tune/doc_code/key_concepts.py` - `doc/source/tune/examples/pbt_visualization/pbt_visualization.ipynb` — 3 cells - `python/ray/tune/examples/pbt_tune_cifar10_with_keras.py` - `python/ray/tune/tests/test_trial_scheduler_pbt.py` — runs through `Tuner`, so it exercised the deprecated fallback on every run One of these is a bug fix rather than deprecation cleanup: the `tune-resources.rst` `with_resources` example was broken as written. Resource callables receive the bare config dict via `default_resource_request()` with no spec fallback, so `resources=lambda spec: {"gpu": 1} if spec.config.use_gpu else {"gpu": 0}` raises `AttributeError: 'dict' object has no attribute 'config'`. ### Deliberately left unchanged - `test_sample.py` and `test_var.py` `sample_from` sites — these drive `generate_variants` / `BasicVariantGenerator` directly, the legacy full-spec path where `spec.config` is still the operative contract (config-dict style would break them). - `test_placeholder.py::testFunction` — deliberate coverage that both styles work. - `test_controller_resume_integration.py` — restore-path coverage for legacy-style functions. - `variant_generator.py` docstring — documents the DeveloperAPI legacy contract and the `{"eval": ...}` syntax. ### Verification Ran the updated patterns end-to-end on ray 2.55.1: - Config-dict conditional space (`b` sampled from a range depending on `a`): 4 trials, conditional held, zero deprecation warnings. Control with the old spec style logs one warning per trial. - Fixed `with_resources` callable resolves; control with the old spec style reproduces the `AttributeError`. `ruff==0.8.4` and `black==22.10.0` (the pre-commit pins) pass on the edited Python files. ## Related issue number Internal tracking: DOC-1131. ## 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 pre-commit equivalent lint (ruff + black at pinned versions) on the changed files. - [x] I've included any doc changes needed for https://docs.ray.io/en/master/. - [ ] I've added any new APIs to the API Reference (n/a — no API changes). - [x] I've made sure the tests are passing (changed examples validated against ray 2.55.1; `test_trial_scheduler_pbt.py` change is parameter-name-only under the `Tuner` path). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
|
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. |
…les to config-dict style (ray-project#63804) ## Why are these changes needed? `tune.sample_from` callables receive the trial `config` dict directly; the legacy `spec.config` access pattern has been deprecated since the placeholder-resolution mechanism landed in Feb 2023 (befad81). Every Tune doc example still written as `lambda spec: spec.config.x` logs this warning on each trial when users copy it: > sample_from functions that take a spec dict are deprecated. Please update your function to work with the config dict directly. Follow-up to ray-project#63443, which fixed the `tune.sample_from` docstring itself. ### What changed Updated to config-dict style (`lambda config: config["x"]`): - `doc/source/tune/tutorials/tune-search-spaces.rst` — examples plus the prose describing the `spec` object and `spec.config` namespace - `doc/source/tune/api/search_space.rst` - `doc/source/tune/doc_code/faq.py` — conditional-spaces and grid-search examples - `doc/source/tune/doc_code/key_concepts.py` - `doc/source/tune/examples/pbt_visualization/pbt_visualization.ipynb` — 3 cells - `python/ray/tune/examples/pbt_tune_cifar10_with_keras.py` - `python/ray/tune/tests/test_trial_scheduler_pbt.py` — runs through `Tuner`, so it exercised the deprecated fallback on every run One of these is a bug fix rather than deprecation cleanup: the `tune-resources.rst` `with_resources` example was broken as written. Resource callables receive the bare config dict via `default_resource_request()` with no spec fallback, so `resources=lambda spec: {"gpu": 1} if spec.config.use_gpu else {"gpu": 0}` raises `AttributeError: 'dict' object has no attribute 'config'`. ### Deliberately left unchanged - `test_sample.py` and `test_var.py` `sample_from` sites — these drive `generate_variants` / `BasicVariantGenerator` directly, the legacy full-spec path where `spec.config` is still the operative contract (config-dict style would break them). - `test_placeholder.py::testFunction` — deliberate coverage that both styles work. - `test_controller_resume_integration.py` — restore-path coverage for legacy-style functions. - `variant_generator.py` docstring — documents the DeveloperAPI legacy contract and the `{"eval": ...}` syntax. ### Verification Ran the updated patterns end-to-end on ray 2.55.1: - Config-dict conditional space (`b` sampled from a range depending on `a`): 4 trials, conditional held, zero deprecation warnings. Control with the old spec style logs one warning per trial. - Fixed `with_resources` callable resolves; control with the old spec style reproduces the `AttributeError`. `ruff==0.8.4` and `black==22.10.0` (the pre-commit pins) pass on the edited Python files. ## Related issue number Internal tracking: DOC-1131. ## 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 pre-commit equivalent lint (ruff + black at pinned versions) on the changed files. - [x] I've included any doc changes needed for https://docs.ray.io/en/master/. - [ ] I've added any new APIs to the API Reference (n/a — no API changes). - [x] I've made sure the tests are passing (changed examples validated against ray 2.55.1; `test_trial_scheduler_pbt.py` change is parameter-name-only under the `Tuner` path). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…ring (#33483) (#63443) ## Description The docstring for `tune.sample_from` did not show how to define a conditional search space, which is its canonical use case. Add a short `Example` block under `python/ray/tune/search/sample.py` that samples one parameter from a range derived from another via `spec.config`. ## Related issues Closes #33483 [DOC-984] ## Additional information Target file: `python/ray/tune/search/sample.py`. The example mirrors the existing conditional-search-space pattern from `doc/source/tune/doc_code/faq.py` (`__conditional_spaces_start__` block), so users land on a consistent canonical form whether they read the API reference or the FAQ. Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: elliot-barn <[email protected]>
…les to config-dict style (ray-project#63804) ## Why are these changes needed? `tune.sample_from` callables receive the trial `config` dict directly; the legacy `spec.config` access pattern has been deprecated since the placeholder-resolution mechanism landed in Feb 2023 (befad81). Every Tune doc example still written as `lambda spec: spec.config.x` logs this warning on each trial when users copy it: > sample_from functions that take a spec dict are deprecated. Please update your function to work with the config dict directly. Follow-up to ray-project#63443, which fixed the `tune.sample_from` docstring itself. ### What changed Updated to config-dict style (`lambda config: config["x"]`): - `doc/source/tune/tutorials/tune-search-spaces.rst` — examples plus the prose describing the `spec` object and `spec.config` namespace - `doc/source/tune/api/search_space.rst` - `doc/source/tune/doc_code/faq.py` — conditional-spaces and grid-search examples - `doc/source/tune/doc_code/key_concepts.py` - `doc/source/tune/examples/pbt_visualization/pbt_visualization.ipynb` — 3 cells - `python/ray/tune/examples/pbt_tune_cifar10_with_keras.py` - `python/ray/tune/tests/test_trial_scheduler_pbt.py` — runs through `Tuner`, so it exercised the deprecated fallback on every run One of these is a bug fix rather than deprecation cleanup: the `tune-resources.rst` `with_resources` example was broken as written. Resource callables receive the bare config dict via `default_resource_request()` with no spec fallback, so `resources=lambda spec: {"gpu": 1} if spec.config.use_gpu else {"gpu": 0}` raises `AttributeError: 'dict' object has no attribute 'config'`. ### Deliberately left unchanged - `test_sample.py` and `test_var.py` `sample_from` sites — these drive `generate_variants` / `BasicVariantGenerator` directly, the legacy full-spec path where `spec.config` is still the operative contract (config-dict style would break them). - `test_placeholder.py::testFunction` — deliberate coverage that both styles work. - `test_controller_resume_integration.py` — restore-path coverage for legacy-style functions. - `variant_generator.py` docstring — documents the DeveloperAPI legacy contract and the `{"eval": ...}` syntax. ### Verification Ran the updated patterns end-to-end on ray 2.55.1: - Config-dict conditional space (`b` sampled from a range depending on `a`): 4 trials, conditional held, zero deprecation warnings. Control with the old spec style logs one warning per trial. - Fixed `with_resources` callable resolves; control with the old spec style reproduces the `AttributeError`. `ruff==0.8.4` and `black==22.10.0` (the pre-commit pins) pass on the edited Python files. ## Related issue number Internal tracking: DOC-1131. ## 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 pre-commit equivalent lint (ruff + black at pinned versions) on the changed files. - [x] I've included any doc changes needed for https://docs.ray.io/en/master/. - [ ] I've added any new APIs to the API Reference (n/a — no API changes). - [x] I've made sure the tests are passing (changed examples validated against ray 2.55.1; `test_trial_scheduler_pbt.py` change is parameter-name-only under the `Tuner` path). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: 400Ping <[email protected]>
…ring (ray-project#33483) (ray-project#63443) ## Description The docstring for `tune.sample_from` did not show how to define a conditional search space, which is its canonical use case. Add a short `Example` block under `python/ray/tune/search/sample.py` that samples one parameter from a range derived from another via `spec.config`. ## Related issues Closes ray-project#33483 [DOC-984] ## Additional information Target file: `python/ray/tune/search/sample.py`. The example mirrors the existing conditional-search-space pattern from `doc/source/tune/doc_code/faq.py` (`__conditional_spaces_start__` block), so users land on a consistent canonical form whether they read the API reference or the FAQ. Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: 400Ping <[email protected]>
Description
The docstring for
tune.sample_fromdid not show how to define a conditional search space, which is its canonical use case. Add a shortExampleblock underpython/ray/tune/search/sample.pythat samples one parameter from a range derived from another viaspec.config.Related issues
Closes #33483
[DOC-984]
Additional information
Target file:
python/ray/tune/search/sample.py. The example mirrors the existing conditional-search-space pattern fromdoc/source/tune/doc_code/faq.py(__conditional_spaces_start__block), so users land on a consistent canonical form whether they read the API reference or the FAQ.Generated with Claude Code