Repository navigation
Keep evaluation coverage after GPU memory retries #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
73fc07b
Keep evaluation coverage when GPU memory retries shrink batches [skip…
anle2024 056e84d
Simplify evaluation retry configuration and validators
anle2024 fee7bd3
Reuse evaluation retry and model plan test setup
anle2024 962fbb3
Keep refit retry settings and discard partial evaluation outputs
anle2024 c94f135
Merge branch 'main' into codex/preserve-evaluation-row-budgets
anle2024 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. | ||
| # All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from contextlib import nullcontext | ||
| from types import SimpleNamespace | ||
| from unittest.mock import Mock | ||
|
|
||
| import pytest | ||
| import torch | ||
| from kumo_core.automl import auto_trainer | ||
| from kumo_core.automl.auto_trainer import AutoTrainer | ||
| from kumo_core.instrumentation import NoOpTrainingInstrumentation | ||
| from kumo_core.model_plan import ModelPlan | ||
| from kumo_core.train.trainer import handle_gpu_oom | ||
| from kumo_core.types import TaskType | ||
| from kumoapi.model_plan import MissingType, RunMode | ||
| from kumoapi.pquery import QueryType | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('steps,expected', [ | ||
| ((100, 200), (204, 407)), | ||
| ((10_000, 20_000), (20_313, 40_625)), | ||
| ((None, None), (None, None)), | ||
| ((MissingType.VALUE, MissingType.VALUE), | ||
| (MissingType.VALUE, MissingType.VALUE)), | ||
| ]) | ||
| def test_retry_budget_reaches_the_trainer_constructor(tmp_path, monkeypatch, | ||
| steps, expected): | ||
| cfg = ModelPlan.from_default(task_type=TaskType.BINARY_CLASSIFICATION, | ||
| query_type=QueryType.STATIC, | ||
| has_train_table_time_col=False, | ||
| run_mode=RunMode.DEBUG) | ||
| cfg.optimization.batch_size = [65] | ||
| cfg.optimization.max_val_steps, cfg.optimization.max_test_steps = steps | ||
| trainer = SimpleNamespace( | ||
| log_dir=str(tmp_path), random_state_seed=0, num_experiments=1, | ||
| max_tries=3, min_retry_batch_size=16, max_epochs=1, | ||
| min_steps_per_epoch=1, max_steps_per_epoch=1, tune_metric='auroc', | ||
| disable_compilation=True, _raise_fake_trial_error_msg=None, | ||
| checkpoint_path=None, encoders=None, | ||
| diskgraph_task_dataset_bundle_dir='unused', | ||
| instrumentation=NoOpTrainingInstrumentation(), | ||
| task=Mock(task_type=TaskType.BINARY_CLASSIFICATION), | ||
| runtime=SimpleNamespace(trainer_runtime_kwargs=lambda: {})) | ||
| for name in ('_get_encoder', '_get_model', '_get_head', '_get_past_encoder', | ||
| '_get_year_over_year_encoder'): | ||
| setattr(trainer, name, lambda *_: None) | ||
| cfg = AutoTrainer._handle_oom_retry(trainer, cfg, trial=0, try_idx=0) | ||
| constructor = Mock(side_effect=RuntimeError('stop before initialization')) | ||
| monkeypatch.setattr(auto_trainer, 'DiskgraphNestedTrainer', constructor) | ||
| with pytest.raises(RuntimeError, match='stop before initialization'): | ||
| AutoTrainer._train(trainer, cfg, metrics_client_job_name='test') | ||
| received = constructor.call_args.kwargs | ||
| assert (received['loader_kwargs']['batch_size'], received['max_val_steps'], | ||
| received['max_test_steps']) == (32, *expected) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('stage,limit,caps,rebuild', [ | ||
| ('test', 100, [100, 200, 400, 800], False), | ||
| ('test', None, [None, None, None, None], False), | ||
| ('predict', 100, [100, 100, 100, 100], False), | ||
| ('test', 100, [100, 200, 400, 800], True), | ||
| ('test', None, [None, None, None, None], True), | ||
| ]) | ||
| @pytest.mark.parametrize('loader_options', | ||
| [None, {}, {'batch_size': 64, 'num_workers': 2}]) | ||
| @pytest.mark.parametrize('failure', | ||
| [None, torch.cuda.OutOfMemoryError, RuntimeError]) | ||
| def test_evaluation_retry_preserves_budget_and_restores_state( | ||
| stage, limit, caps, rebuild, loader_options, failure, monkeypatch): | ||
| monkeypatch.setattr(torch.cuda, 'empty_cache', lambda: None) | ||
| module = SimpleNamespace(eval_loader_kwargs={'batch_size': 64}, | ||
| max_test_steps=limit) | ||
| trainer = SimpleNamespace( | ||
| datamodule=module, | ||
| eval_loader_kwargs=(None if loader_options is None else | ||
| loader_options.copy()), | ||
| max_test_steps=limit, | ||
| task=SimpleNamespace(task_type=TaskType.BINARY_CLASSIFICATION), | ||
| pl_model=Mock()) | ||
| original_options = trainer.eval_loader_kwargs | ||
| attempted = [] | ||
|
|
||
| def evaluate(self): | ||
| if rebuild: | ||
| self.datamodule = SimpleNamespace( | ||
| eval_loader_kwargs={ | ||
| 'batch_size': (self.eval_loader_kwargs or {}).get( | ||
| 'batch_size', 64)}, max_test_steps=self.max_test_steps) | ||
| module = self.datamodule | ||
| batch = module.eval_loader_kwargs['batch_size'] | ||
| attempted.append((batch, module.max_test_steps)) | ||
| if batch > 16: | ||
| raise torch.cuda.OutOfMemoryError('simulated') | ||
| if failure is not None: | ||
| raise failure('simulated') | ||
| return 'complete' | ||
|
|
||
| evaluate.__name__ = stage | ||
| run = handle_gpu_oom(evaluate) | ||
| with pytest.raises(failure) if failure else nullcontext(): | ||
| assert run(trainer) == 'complete' | ||
| expected = list(zip([64, 32, 16, 8], caps)) | ||
| assert attempted == expected[:4 if failure is | ||
| torch.cuda.OutOfMemoryError else 3] | ||
| if stage == 'test' or failure is None: | ||
| assert trainer.datamodule.eval_loader_kwargs == {'batch_size': 64} | ||
| assert trainer.datamodule.max_test_steps == limit | ||
| assert trainer.eval_loader_kwargs is original_options | ||
| assert trainer.eval_loader_kwargs == loader_options | ||
| assert trainer.max_test_steps == limit |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.