Repository navigation
Conversation
…uted to PyTorch native DDP - Replace deprecated smdistributed imports with torch.distributed and torch.nn.parallel.DistributedDataParallel in train_dp.py - Fix init_process_group to use env:// init_method with nccl/gloo backend - Read LOCAL_RANK from env var (set by torchrun) instead of smdistributed API - Fix batch_size scaling: divide by world_size (not world_size // 8) - Properly set CUDA device before wrapping model in DDP with device_ids - Add train_sampler.set_epoch(epoch) for correct shuffling across epochs - Add dist.barrier() after rank-0 logging to prevent desync - Add dist.destroy_process_group() at shutdown - Fix pin_memory to only be True when CUDA is available - Remove unused nn.Parameter attributes (w1, w2, rot) from DressedQNN that caused DDP gradient-reduction errors (parameters not in forward()) - Update notebook markdown to reference PyTorch DDP instead of smdistributed - Update notebook sed line references to match updated train_dp.py
|
Notebooks changed:
Review visual diffs and comment on any notebook cell. All comments sync back to this PR. Powered by ReviewNB |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue #907
Description of changes:
The
Parallelize_training_for_QMLexample usessmdistributed.dataparallelwhich is no longer present in the currentamazon-braket-pytorch-jobs:latestcontainer, causing all jobs submitted withdistribution="data_parallel"to fail withModuleNotFoundError: No module named 'smdistributed'.This PR migrates the data-parallel training script to use PyTorch's built-in
torch.distributedandDistributedDataParallel(which is available in all modern PyTorch DLC images), and fixes several related bugs found during the migration.Changes in
qml_script/train_dp.py:smdistributedimports withtorch.distributed as distandtorch.nn.parallel.DistributedDataParallel as DDPdist.init_process_group(backend="nccl"/"gloo", init_method="env://")(populated bytorchrunat job launch)local_rankfromint(os.environ.get("LOCAL_RANK", "0"))instead of the removeddist.get_local_rank()batch_size //= world_size(the old// world_size // 8causedZeroDivisionErroron instances with < 8 GPUs, e.g.ml.g6.12xlargewith 4 GPUs)torch.cuda.set_device(local_rank)thenDDP(model, device_ids=[local_rank]); fall back to CPU-onlyDDP(model)for non-GPU devicespin_memory=torch.cuda.is_available()(avoid pinning on CPU-only runs)train_sampler.set_epoch(epoch)for correct per-epoch shufflingdist.barrier()after rank-0 logging to prevent rank desync between epochsdist.destroy_process_group()at shutdownChanges in
qml_script/model.py:self.w1,self.w2,self.rotnn.Parameterattributes fromDressedQNN; these were never used inforward()(weights are owned byTorchLayer), causing PyTorch native DDP to raise gradient-reduction errors for unused parametersChanges in
Parallelize_training_for_QML.ipynb:DistributedDataParallelinstead ofsmdistributed>[!WARNING]deprecation notice (the fix removes the deprecated dependency)!sed -n ...p qml_script/train_dp.pycell line ranges to match the updated scriptTesting done:
Verified locally with
torchrun --nproc_per_node=2usinggloobackend (CPU),local:pennylane/lightning.qubitsimulator, and Braket env vars set to match the container environment:Job results saved:
{"last loss": 0.2806}✅Merge Checklist
General
docs/ENTRIES.jsonand rundocs/build_readme.shTests
pytest test/(see TESTING.md) — all 8 repo tests passBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.