-
Notifications
You must be signed in to change notification settings - Fork 5
Many bug/performance fixes #88
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
ndryden
wants to merge
28
commits into
main
Choose a base branch
from
review-fixes
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.
+9,428
−644
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
3debef9
Add test infrastructure: pytest config, shared fixtures, MPI/torchrun…
ndryden 10915fa
Fix reporting and visualization bugs
ndryden cb037cb
Fix U-Net construction validation and activation checkpointing
ndryden 7a9ba6f
Generate restart scripts from the run's actual environment and launch…
ndryden 6fbc8e0
Fix IFS point-generation kernel bugs
ndryden 7e93cf5
Make dataset id ordering deterministic and v1 label mapping split-con…
ndryden 3c99abe
Harden checkpointing: atomic writes, corruption fallback, race-free b…
ndryden 7a95c57
Compute validation Dice on hard predictions and sample-weighted val loss
ndryden ebeabd2
Make datagen RNG deterministic and category-search resume safe
ndryden be2b110
Validate generated instances, write them atomically, and fix rasteriz…
ndryden ec5a1e9
Validate config keys, wire --config overrides, implement benchmark sw…
ndryden 9983add
Make distributed datagen failure paths collective-safe
ndryden 9590601
Fix DDP device pinning, launcher detection, and worker teardown order
ndryden 5469a21
Reduce training/validation metrics globally across data-parallel repl…
ndryden a93fe5f
Fix resume flag handling, stats-file headers, and step-counter persis…
ndryden 0802d96
Handle a missing parallel strategy and CPU-only devices in training
ndryden 2d4eb0e
Only treat .csv files as fractal categories when indexing instances
ndryden 245d98f
Clean up unused imports in test_reporting
ndryden 3846534
Apply ruff formatting to checkpointing
ndryden 2a0254d
Rasterize by scattering point indices and store point clouds as float32
ndryden 0eaafab
Resolve mask paths once and size category search rounds adaptively
ndryden 2c99f6f
Skip the upsample pad when no padding is needed
ndryden 7ce9a5c
Trim per-step overhead in the training and validation compute path
ndryden 03a3530
Cut redundant dataset I/O per sample and per startup scan
ndryden ed1edd3
Load the resume checkpoint on rank 0 and broadcast it
ndryden cca7e3a
Adapt tests and helpers to the always-distributed design
ndryden 07c2393
Persist the cumulative optimizer-step total across resumes
ndryden 9d8b787
Gather the dataset id digest on the backend's device
ndryden 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,80 @@ | |
| from ScaFFold.utils.utils import setup_mpi_logger | ||
|
|
||
|
|
||
| def _make_fresh_run_dir(base_run_dir, timestamp): | ||
| """Create a fresh timestamped run directory without clobbering an existing one. | ||
|
|
||
| The bare timestamped name is attempted first. If it already exists -- two | ||
| jobs launched under the same base directory within the same wall-clock | ||
| second name their directories identically -- a numeric suffix is appended | ||
| and incremented until an unused name is found. ``mkdir(exist_ok=False)`` is | ||
| atomic, so each name is claimed by exactly one creator and neither job | ||
| overwrites the other's config or stats. | ||
|
|
||
| Returns the created directory as a ``Path``. | ||
| """ | ||
| candidate = base_run_dir / timestamp | ||
| suffix = 0 | ||
| while True: | ||
| try: | ||
| candidate.mkdir(parents=True, exist_ok=False) | ||
| return candidate | ||
| except FileExistsError: | ||
| suffix += 1 | ||
| candidate = base_run_dir / f"{timestamp}-{suffix}" | ||
|
|
||
|
|
||
| def resolve_run_dir(args_dict, combined_config): | ||
| """Decide the benchmark run directory and whether this launch resumes a run. | ||
|
|
||
| The semantics are fixed and unambiguous: | ||
|
|
||
| * ``--run-dir DIR`` (with or without ``--restart``): resume in that exact | ||
| directory. ``train_from_scratch`` is forced off and ``restart`` on so the | ||
| downstream benchmark driver takes its restart path. | ||
| * ``--restart`` without ``--run-dir``: rejected with a clear error. The run | ||
| directory to resume must be named explicitly; the most recent directory | ||
| is never guessed. | ||
| * neither flag: create a fresh timestamped directory under ``base_run_dir``, | ||
| retrying with a numeric suffix on a same-second name collision. | ||
|
|
||
| ``combined_config['benchmark_run_dir']`` is set in every path so the driver | ||
| can always read it. Returns ``(benchmark_run_dir: Path, restarting: bool)``. | ||
| """ | ||
| restart_flag = bool(args_dict.get("restart")) | ||
| run_dir_arg = args_dict.get("run_dir") | ||
|
|
||
| if run_dir_arg is not None: | ||
| benchmark_run_dir = Path(run_dir_arg) | ||
| # An explicit run dir is expected to already exist; tolerate a missing | ||
| # one but never treat a pre-existing dir as an error here. | ||
| benchmark_run_dir.mkdir(parents=True, exist_ok=True) | ||
| restarting = True | ||
| elif restart_flag: | ||
| raise ValueError( | ||
| "--restart requires --run-dir: pass the directory of the run to " | ||
| "resume (e.g. '--restart --run-dir <path>'). The most recent run " | ||
| "directory is not resolved automatically." | ||
| ) | ||
| else: | ||
| base_run_dir = Path(combined_config["base_run_dir"]) | ||
| timestamp = datetime.now().strftime( | ||
| f"{combined_config.get('job_name')}_%Y%m%d-%H%M%S" | ||
| ) | ||
| benchmark_run_dir = _make_fresh_run_dir(base_run_dir, timestamp) | ||
| log = setup_mpi_logger(__file__, args_dict.get("verbose", 0)) | ||
| log.info( | ||
| "benchmark_run_dir created at path %s", Path.resolve(benchmark_run_dir) | ||
| ) | ||
| restarting = False | ||
|
|
||
| combined_config["benchmark_run_dir"] = str(benchmark_run_dir) | ||
| if restarting: | ||
| combined_config["train_from_scratch"] = False | ||
| combined_config["restart"] = True | ||
| return benchmark_run_dir, restarting | ||
|
|
||
|
|
||
| def main(): | ||
| """ | ||
| Command line interface for ScaFFold. | ||
|
|
@@ -101,13 +175,19 @@ def main(): | |
| "Requires path to config file." | ||
| ), | ||
| ) | ||
| # Specify config file | ||
| # Specify config file(s): the first is the complete base config, any | ||
| # additional -c/--config files are partial overrides applied in order. | ||
| benchmark_parser.add_argument( | ||
| "-c", | ||
| "--config", | ||
| type=str, | ||
| action="append", | ||
| default=None, | ||
| help="Path to config file for running benchmark", | ||
| help=( | ||
| "Path to config file for running benchmark. May be given more " | ||
| "than once: the first file is the base config and later files " | ||
| "are partial overrides." | ||
| ), | ||
|
Comment on lines
+178
to
+190
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When would we need to support multiple configs overriding each other? This seems unnecessary. |
||
| required=True, | ||
| ) | ||
|
|
||
|
|
@@ -224,14 +304,36 @@ def main(): | |
| log = setup_mpi_logger(__file__, args.verbose) | ||
| combined_config = None | ||
|
|
||
| # Reject an incoherent resume request on every rank, before the rank-0 | ||
| # config work and its collective barrier, so the job fails fast and | ||
| # uniformly instead of leaving the non-zero ranks blocked in a barrier | ||
| # while rank 0 aborts. | ||
| if ( | ||
| args.command == "benchmark" | ||
| and getattr(args, "restart", False) | ||
| and getattr(args, "run_dir", None) is None | ||
| ): | ||
| parser.error( | ||
| "--restart requires --run-dir: pass the directory of the run to " | ||
| "resume (e.g. '--restart --run-dir <path>')." | ||
| ) | ||
|
|
||
| if rank == 0: | ||
| log.debug("args = %s", args) | ||
|
|
||
| bench_config = config_utils.load_config(Path(args.config), "sweep") | ||
| bench_config_dict = ( | ||
| vars(bench_config) if not isinstance(bench_config, dict) else bench_config | ||
| ) | ||
| # --config may be a single path (generate_fractals) or a list of | ||
| # paths (benchmark, action="append"): base config plus overrides. | ||
| config_paths = args.config if isinstance(args.config, list) else [args.config] | ||
| merged_dict = config_utils.load_config_files(config_paths) | ||
| # Validate the merged result and derive dependent settings | ||
| # (list-valued sweep params are allowed here; the benchmark driver | ||
| # expands them per run). | ||
| bench_config = config_utils.Config(merged_dict, allow_sweeps=True) | ||
| bench_config_dict = vars(bench_config) | ||
| cli_args = vars(args) | ||
| # Downstream consumers expect a single config path (e.g. to copy it | ||
| # into the run dir); keep the base config there. | ||
| cli_args["config"] = config_paths[0] | ||
|
|
||
| # Combine configs: CLI args override config file values | ||
| combined_config = bench_config_dict.copy() | ||
|
|
@@ -276,31 +378,12 @@ def main(): | |
| combined_config["vol_size"] = pow(2, combined_config["problem_scale"]) | ||
| combined_config["point_num"] = int(combined_config["vol_size"] ** 3 / 256) | ||
|
|
||
| # Handle Restart / Resume logic | ||
| if hasattr(args, "restart") and args.restart: | ||
| log.info("Restart flag detected: forcing train_from_scratch = False") | ||
| combined_config["train_from_scratch"] = False | ||
| combined_config["restart"] = True | ||
|
|
||
| # If user manually supplied --run-dir (via restart script), use it. | ||
| if hasattr(args, "run_dir") and args.run_dir is not None: | ||
| log.info("Resuming in existing directory: %s", args.run_dir) | ||
| benchmark_run_dir = Path(args.run_dir) | ||
| # Ensure we don't accidentally wipe checkpoints even if --restart wasn't explicitly passed | ||
| combined_config["train_from_scratch"] = False | ||
| else: | ||
| base_run_dir = Path(combined_config["base_run_dir"]) | ||
| timestamp = datetime.now().strftime( | ||
| f"{combined_config.get('job_name')}_%Y%m%d-%H%M%S" | ||
| ) | ||
| benchmark_run_dir = base_run_dir / timestamp | ||
| log.info( | ||
| "benchmark_run_dir created at path %s", | ||
| Path.resolve(benchmark_run_dir), | ||
| ) | ||
|
|
||
| combined_config["benchmark_run_dir"] = str(benchmark_run_dir) | ||
| benchmark_run_dir.mkdir(parents=True, exist_ok=True) | ||
| # Resolve the run directory and whether this launch resumes a run. | ||
| # This sets combined_config["benchmark_run_dir"] on every path and, | ||
| # when resuming, forces train_from_scratch off / restart on. | ||
| benchmark_run_dir, restarting = resolve_run_dir(vars(args), combined_config) | ||
| if restarting: | ||
| log.info("Resuming in existing directory: %s", benchmark_run_dir) | ||
|
|
||
| # Add scheduler metadata and machine name to config.yaml | ||
| combined_config["scheduler_metadata"] = collect_scheduler_metadata() | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PatrickRMiles Do you utilize the sweep feature of the configs? I do not, I run one config for each program execution. I think we could deprecate this entirely. We should sweep using CLI parameters and bash scripts IMO, so we are not supporting this code.