-
Notifications
You must be signed in to change notification settings - Fork 258
[WIP]: Improve predict_tile memory use and windowed raster inference #1304
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
Open
henrykironde
wants to merge
7
commits into
weecology:main
Choose a base branch
from
henrykironde:fix-gpus
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e38d70b
Improve predict_tile memory use and windowed raster inference
henrykironde 863951f
Add GPU tests and CUDA fallback warning
henrykironde cbdce34
Fix in-place crop normalization corrupts overlapping windows
henrykironde e552a5a
Add TiledRaster close on failure and pickle for multiprocessing
henrykironde 65a42a3
fix: avoid in-place mutation of caller array in _ensure_rgb_chw_float32
henrykironde 525ef03
Avoid ZeroDivisionError edge case
henrykironde d847701
fix: normalize full image in SingleImage.prepare_items for consistent…
henrykironde 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/usr/bin/env python | ||
| """HPC-only multi-GPU training smoke test (DDP). | ||
|
|
||
| Run with: | ||
| torchrun --nproc_per_node=2 tests/hpc_multi_gpu_train.py | ||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| import torch | ||
|
|
||
| from deepforest import get_data | ||
| from deepforest.main import deepforest | ||
|
|
||
|
|
||
| def _require_hpc() -> None: | ||
| if os.environ.get("GITHUB_ACTIONS") or os.environ.get("CI"): | ||
| raise SystemExit("CI environment detected; skip HPC-only test.") | ||
| if not os.environ.get("HIPERGATOR") and not os.environ.get("SLURM_JOB_ID"): | ||
| raise SystemExit( | ||
| "This script is intended for HPC use only. " | ||
| "Set HIPERGATOR=1 or run under SLURM." | ||
| ) | ||
|
|
||
|
|
||
| def _require_ddp() -> None: | ||
| if "LOCAL_RANK" not in os.environ and "RANK" not in os.environ: | ||
| raise SystemExit( | ||
| "DDP environment not detected. Run with:\n" | ||
| " torchrun --nproc_per_node=2 tests/hpc_multi_gpu_train.py" | ||
| ) | ||
|
|
||
|
|
||
| def main() -> int: | ||
| _require_hpc() | ||
| _require_ddp() | ||
|
|
||
| if torch.cuda.device_count() < 2: | ||
| raise SystemExit("Need at least 2 GPUs for this test.") | ||
|
|
||
| m = deepforest() | ||
| m.config.workers = 0 | ||
| m.config.batch_size = 1 | ||
| m.config.num_classes = 1 | ||
| m.config.label_dict = {"Tree": 0} | ||
| train_csv = get_data("example.csv") | ||
| m.config.train.csv_file = train_csv | ||
| m.config.train.root_dir = os.path.dirname(train_csv) | ||
| m.config.validation.csv_file = train_csv | ||
| m.config.validation.root_dir = os.path.dirname(train_csv) | ||
| m.create_model(initialize_model=True) | ||
|
|
||
| # Keep this fast but avoid fast_dev_run's zero-length warning in DDP. | ||
| m.create_trainer( | ||
| accelerator="gpu", | ||
| devices=2, | ||
| strategy="ddp", | ||
| fast_dev_run=False, | ||
| max_epochs=1, | ||
| limit_train_batches=2, | ||
| limit_val_batches=2, | ||
| log_every_n_steps=1, | ||
| ) | ||
| m.trainer.fit(m) | ||
|
|
||
| # Multi-GPU evaluation pass (uses same example.csv) | ||
| m.trainer.validate(m) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) |
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.