-
Notifications
You must be signed in to change notification settings - Fork 612
Airfrans datapipe not broken #1475
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
coreyjadams
wants to merge
9
commits into
NVIDIA:main
Choose a base branch
from
coreyjadams:airfrans-datapipe-not-broken
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
155ad94
unbreak git
coreyjadams 8b44d35
Merge branch 'NVIDIA:main' into airfrans-datapipe-not-broken
coreyjadams 8b8ade4
Add pipeline reader updates
coreyjadams 85936c6
physicsnemo datapipes work
coreyjadams 3f45e20
Add physicsnemo datapipes to airfrans
coreyjadams cbdc44e
Fix linter
coreyjadams f596ef6
Consolidate yaml configs to reduce file count bloat
coreyjadams 4ec797d
Fix license issues
coreyjadams 1e899ac
Merge branch 'main' into airfrans-datapipe-not-broken
coreyjadams 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
183 changes: 183 additions & 0 deletions
183
examples/cfd/external_aerodynamics/globe/airfrans/benchmark_datapipe.py
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,183 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2023 - 2026 NVIDIA CORPORATION & AFFILIATES. | ||
| # SPDX-FileCopyrightText: All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """ | ||
| Benchmark the AirFRANS datapipe throughput via the physicsnemo DataLoader. | ||
|
|
||
| Instantiates the full pipeline from the Hydra config, wraps it in | ||
| physicsnemo.datapipes.DataLoader with the same collate as training, and | ||
| measures wall-clock time per batch over N iterations. | ||
|
|
||
| Usage | ||
| ----- | ||
| # Arrow reader (default; dataset_path from conf/config.yaml) | ||
| python benchmark_datapipe.py | ||
|
|
||
| # Override config from CLI | ||
| python benchmark_datapipe.py dataset_path=/path/to/arrow +n_samples=50 | ||
|
|
||
| # VTK reader | ||
| python benchmark_datapipe.py reader=vtk data_dir=/path/to/vtk | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import statistics | ||
| import time | ||
| from typing import Any, Sequence | ||
|
|
||
| import hydra | ||
| import torch | ||
| from omegaconf import DictConfig, OmegaConf | ||
| from torch.utils.data import SequentialSampler | ||
|
|
||
| from physicsnemo.datapipes import DataLoader as PhysicsnemoDataLoader | ||
| from physicsnemo.datapipes import Dataset as PhysicsnemoDataset | ||
| from tensordict import TensorDict | ||
|
|
||
| from physicsnemo_dataset import _structured_tensordict_to_airfrans_sample | ||
|
|
||
| logging.basicConfig(level=logging.INFO) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
| _CUDA_AVAILABLE = torch.cuda.is_available() | ||
| _BYTES_PER_MB = 2**20 | ||
|
|
||
|
|
||
| def collate_single( | ||
| samples: Sequence[tuple[TensorDict, dict[str, Any]]], | ||
| ): | ||
| """Collate for batch_size=1: convert structured TensorDict to AirFRANSSample.""" | ||
| data, _ = samples[0] | ||
| return _structured_tensordict_to_airfrans_sample(data) | ||
|
|
||
|
|
||
| def _gpu_memory_mb() -> dict[str, float] | None: | ||
| """Return current GPU memory stats in MB, or None if CUDA not available.""" | ||
| if not _CUDA_AVAILABLE: | ||
| return None | ||
| torch.cuda.synchronize() | ||
| return { | ||
| "allocated_mb": torch.cuda.memory_allocated() / _BYTES_PER_MB, | ||
| "reserved_mb": torch.cuda.memory_reserved() / _BYTES_PER_MB, | ||
| "max_allocated_mb": torch.cuda.max_memory_allocated() / _BYTES_PER_MB, | ||
| "max_reserved_mb": torch.cuda.max_memory_reserved() / _BYTES_PER_MB, | ||
| } | ||
|
|
||
|
|
||
| def benchmark( | ||
| dataloader: PhysicsnemoDataLoader, | ||
| n_samples: int, | ||
| ) -> tuple[list[float], dict[str, float] | None]: | ||
| dataset = dataloader.dataset | ||
| actual_n = min(n_samples, len(dataset)) | ||
| if actual_n == 0: | ||
| logger.warning("Dataset is empty — nothing to benchmark.") | ||
| return [], _gpu_memory_mb() if _CUDA_AVAILABLE else None | ||
|
|
||
| logger.info("Warming up (1 batch)...") | ||
| _ = next(iter(dataloader)) | ||
|
|
||
| if _CUDA_AVAILABLE: | ||
| torch.cuda.reset_peak_memory_stats() | ||
| torch.cuda.synchronize() | ||
|
|
||
| logger.info("Timing %d batches...", actual_n) | ||
| times: list[float] = [] | ||
| it = iter(dataloader) | ||
| for _ in range(actual_n): | ||
| t0 = time.perf_counter() | ||
| _ = next(it) | ||
| times.append(time.perf_counter() - t0) | ||
|
|
||
| gpu_stats = _gpu_memory_mb() | ||
| return times, gpu_stats | ||
|
|
||
|
|
||
| def print_results( | ||
| times: list[float], | ||
| gpu_stats: dict[str, float] | None = None, | ||
| ) -> None: | ||
| n = len(times) | ||
| if n == 0: | ||
| return | ||
| total = sum(times) | ||
| mean = statistics.mean(times) | ||
| std = statistics.stdev(times) if n > 1 else 0.0 | ||
| median = statistics.median(times) | ||
| throughput = n / total if total > 0 else 0.0 | ||
|
|
||
| header = ( | ||
| f"{'Samples':>8s} {'Total (s)':>10s} {'Mean (s)':>10s} " | ||
| f"{'Median (s)':>11s} {'Std (s)':>10s} {'Throughput':>12s}" | ||
| ) | ||
| sep = "-" * len(header) | ||
| print() | ||
| print(sep) | ||
| print(header) | ||
| print(sep) | ||
| print( | ||
| f"{n:>8d} {total:>10.3f} {mean:>10.4f} " | ||
| f"{median:>11.4f} {std:>10.4f} {throughput:>10.2f}/s" | ||
| ) | ||
| print(sep) | ||
|
|
||
| if gpu_stats is not None: | ||
| print() | ||
| print("GPU memory (peak during benchmark):") | ||
| print( | ||
| f" max allocated: {gpu_stats['max_allocated_mb']:.2f} MB " | ||
| f"max reserved: {gpu_stats['max_reserved_mb']:.2f} MB" | ||
| ) | ||
| print( | ||
| f" current allocated: {gpu_stats['allocated_mb']:.2f} MB " | ||
| f"current reserved: {gpu_stats['reserved_mb']:.2f} MB" | ||
| ) | ||
| print() | ||
|
|
||
|
|
||
| @hydra.main( | ||
| version_base=None, | ||
| config_path="./conf", | ||
| config_name="config", | ||
| ) | ||
| def main(cfg: DictConfig) -> None: | ||
| n_samples: int = cfg.get("n_samples", 100) | ||
|
|
||
| print("=== AirFRANS Datapipe Benchmark ===") | ||
| print() | ||
| print(OmegaConf.to_yaml(cfg, resolve=True)) | ||
|
|
||
| logger.info("Building physicsnemo dataloader...") | ||
| dataset: PhysicsnemoDataset = hydra.utils.instantiate(cfg.dataset) | ||
| sampler = SequentialSampler(dataset) | ||
| dataloader = PhysicsnemoDataLoader( | ||
| dataset, | ||
| batch_size=1, | ||
| sampler=sampler, | ||
| collate_fn=collate_single, | ||
| ) | ||
| logger.info("Dataset size: %d samples", len(dataset)) | ||
|
|
||
| times, gpu_stats = benchmark(dataloader, n_samples) | ||
| print_results(times, gpu_stats) | ||
|
|
||
| dataset.close() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
46 changes: 46 additions & 0 deletions
46
examples/cfd/external_aerodynamics/globe/airfrans/conf/config.yaml
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,46 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2023 - 2026 NVIDIA CORPORATION & AFFILIATES. | ||
| # SPDX-FileCopyrightText: All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| defaults: | ||
| - reader@reader: arrow | ||
| - transforms: transforms | ||
| - _self_ | ||
|
|
||
| # Data paths (set via CLI overrides or environment) | ||
| dataset_path: /lustre/fsw/portfolios/coreai/projects/coreai_modulus_cae/datasets/airfrans/huggingface/ # used by reader=arrow | ||
| # dataset_path: /lustre/fsw/portfolios/coreai/projects/coreai_modulus_cae/datasets/airfrans/Dataset/ # used by reader=vtk | ||
|
|
||
| # Dataset parameters | ||
| task: full | ||
| split: train | ||
| device: auto | ||
|
|
||
| # Reader (populated from defaults) | ||
| reader: {} | ||
|
|
||
| # Dataset wrapping the reader + transforms | ||
| dataset: | ||
| _target_: physicsnemo.datapipes.Dataset | ||
| device: ${device} | ||
| reader: ${reader} | ||
| transforms: | ||
| - ${transforms.gradients} | ||
| - ${transforms.normals} | ||
| - ${transforms.freestream} | ||
| - ${transforms.nondimensionalize} | ||
| - ${transforms.forces} | ||
| - ${transforms.patch} | ||
| - ${transforms.to_airfrans_sample} | ||
22 changes: 22 additions & 0 deletions
22
examples/cfd/external_aerodynamics/globe/airfrans/conf/reader/arrow.yaml
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,22 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2023 - 2026 NVIDIA CORPORATION & AFFILIATES. | ||
| # SPDX-FileCopyrightText: All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| _target_: pipeline.arrow_reader.AirFRANSArrowReader | ||
| dataset_path: ${dataset_path} | ||
| task: ${task} | ||
| split: ${split} | ||
| pin_memory: true | ||
| include_index_in_metadata: true |
22 changes: 22 additions & 0 deletions
22
examples/cfd/external_aerodynamics/globe/airfrans/conf/reader/vtk.yaml
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,22 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2023 - 2026 NVIDIA CORPORATION & AFFILIATES. | ||
| # SPDX-FileCopyrightText: All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| _target_: pipeline.vtk_reader.AirFRANSVTKReader | ||
| dataset_path: ${dataset_path} | ||
| task: ${task} | ||
| split: ${split} | ||
| pin_memory: true | ||
| include_index_in_metadata: true |
38 changes: 38 additions & 0 deletions
38
examples/cfd/external_aerodynamics/globe/airfrans/conf/transforms/transforms.yaml
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,38 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2023 - 2026 NVIDIA CORPORATION & AFFILIATES. | ||
| # SPDX-FileCopyrightText: All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| gradients: | ||
| _target_: pipeline.transforms.ComputeGradients | ||
|
|
||
| normals: | ||
| _target_: pipeline.transforms.ComputeAirfoilNormals | ||
|
|
||
| freestream: | ||
| _target_: pipeline.transforms.ComputeFreestreamQuantities | ||
|
|
||
| nondimensionalize: | ||
| _target_: pipeline.transforms.NondimensionalizeFields | ||
|
|
||
| forces: | ||
| _target_: pipeline.transforms.ComputeForceCoefficients | ||
|
|
||
| patch: | ||
| _target_: pipeline.transforms.PatchNonPhysicalValues | ||
| threshold: 1.02 | ||
| warn_fraction: 0.0001 | ||
|
|
||
| to_airfrans_sample: | ||
| _target_: pipeline.transforms.ToAirFRANSSampleStructure |
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.
Hardcoded internal NVIDIA cluster path in public config
The
dataset_pathdefault is set to a NVIDIA-internal Lustre path (/lustre/fsw/portfolios/coreai/...). This path will not resolve for anyone outside the internal cluster and should be replaced with a placeholder, requiring users to provide their own path via CLI override.