Implement multi-dimensional DistConv sharding#27
Open
PatrickRMiles wants to merge 21 commits intoLBANN:mainfrom
Open
Implement multi-dimensional DistConv sharding#27PatrickRMiles wants to merge 21 commits intoLBANN:mainfrom
PatrickRMiles wants to merge 21 commits intoLBANN:mainfrom
Conversation
added 17 commits
March 10, 2026 14:40
…to deal with 1D inputs
…t pass them as-is to the ParallelStrategy call
Comment on lines
+7
to
+13
| problem_scale: 8 # Determines dataset resolution and number of unet layers. Default is 6. | ||
| unet_bottleneck_dim: 3 # Power of 2 of the unet bottleneck layer dimension. Default of 3 -> bottleneck layer of size 8. | ||
| seed: 42 # Random seed. | ||
| batch_size: 1 # Batch sizes for each vol size. | ||
| optimizer: "ADAM" # "ADAM" is preferred option, otherwise training defautls to RMSProp. | ||
| num_shards: 2 # DistConv param: number of shards to divide the tensor into. It's best to choose the fewest ranks needed to fit one sample in GPU memory, since that keeps communication at a minimum | ||
| shard_dim: 2 # DistConv param: dimension on which to shard | ||
| dc_num_shards: [1, 1, 2] # DistConv param: number of shards to divide the tensor into. It's best to choose the fewest ranks needed to fit one sample in GPU memory, since that keeps communication at a minimum | ||
| dc_shard_dims: [2, 3, 4] # DistConv param: dimension on which to shard |
Collaborator
There was a problem hiding this comment.
What should default scale be? Maybe we need scale-specific configs
problem_scale: 7
dc_num_shards: [1,1,1]
problem_scale: 8
dc_num_shards: [1,1,2]
problem_scale: 9
dc_num_shards: [2,2,4]
unet_bottleneck_dim: 4
Comment on lines
+118
to
+136
| def _ensure_tuple(val): | ||
| """ | ||
| Ensures the input value is converted to a tuple of integers. | ||
| Handles: int, list, tuple, and string representations like "[2,2]" or "2,2". | ||
| """ | ||
| if val is None: | ||
| return (1,) # Default safety | ||
| if isinstance(val, (list, tuple)): | ||
| return tuple(int(i) for i in val) | ||
| if isinstance(val, str): | ||
| # Handle cases where user might type literal "(2, 2, 2)" in YAML or "2,2" in CLI | ||
| val = val.strip("()[]").split(",") | ||
| return tuple(int(i.strip()) for i in val if i.strip()) | ||
| # Fallback for single integer | ||
| return ( | ||
| 1, | ||
| 1, | ||
| int(val), | ||
| ) |
Collaborator
There was a problem hiding this comment.
I get this is for the way the current cli arg is set for --num-shards, but I think we should just change that and remove this. As it is not clear the single value set will become the third dimension in the tuple
Collaborator
There was a problem hiding this comment.
heres a patch for the changes
diff --git a/ScaFFold/cli.py b/ScaFFold/cli.py
index 840a7e6..3c73f40 100644
--- a/ScaFFold/cli.py
+++ b/ScaFFold/cli.py
@@ -157,8 +157,9 @@ def main():
help="Resume execution in this specific directory. Overrides --base-run-dir.",
)
benchmark_parser.add_argument(
- "--num-shards",
+ "--dc-num-shards",
type=int,
+ nargs=3,
help="DistConv param: number of shards to divide the tensor into. It's best to choose the fewest ranks needed to fit one sample in GPU memory, since that keeps communication at a minimum",
)
benchmark_parser.add_argument(
diff --git a/ScaFFold/utils/config_utils.py b/ScaFFold/utils/config_utils.py
index b6d77d2..378dc51 100644
--- a/ScaFFold/utils/config_utils.py
+++ b/ScaFFold/utils/config_utils.py
@@ -73,8 +73,8 @@ class Config:
self.target_dice = config_dict["target_dice"]
self.checkpoint_interval = config_dict["checkpoint_interval"]
- self.dc_num_shards = _ensure_tuple(config_dict.get("dc_num_shards", (1, 1, 1)))
- self.dc_shard_dims = _ensure_tuple(config_dict.get("dc_shard_dims", (2, 3, 4)))
+ self.dc_num_shards = config_dict["dc_num_shards"]
+ self.dc_shard_dims = config_dict["dc_shard_dims"]
self.dc_total_shards = math.prod(self.dc_num_shards)
# Safety Check: Length mismatch
if len(self.dc_num_shards) != len(self.dc_shard_dims):
@@ -113,24 +113,3 @@ def load_config(file_path: str, config_type: str):
raise ValueError(
f"Invalid config type specified: {type}. Must be either 'sweep' or 'run'"
)
-
-
-def _ensure_tuple(val):
- """
- Ensures the input value is converted to a tuple of integers.
- Handles: int, list, tuple, and string representations like "[2,2]" or "2,2".
- """
- if val is None:
- return (1,) # Default safety
- if isinstance(val, (list, tuple)):
- return tuple(int(i) for i in val)
- if isinstance(val, str):
- # Handle cases where user might type literal "(2, 2, 2)" in YAML or "2,2" in CLI
- val = val.strip("()[]").split(",")
- return tuple(int(i.strip()) for i in val if i.strip())
- # Fallback for single integer
- return (
- 1,
- 1,
- int(val),
- )
diff --git a/ScaFFold/utils/evaluate.py b/ScaFFold/utils/evaluate.py
index 6f8da8a..5c907c4 100644
--- a/ScaFFold/utils/evaluate.py
+++ b/ScaFFold/utils/evaluate.py
@@ -17,6 +17,7 @@ import torch.nn.functional as F
from distconv import DCTensor
from torch.distributed.tensor import DTensor, Replicate, Shard, distribute_tensor
from tqdm import tqdm
+import numpy as np
from ScaFFold.utils.dice_score import (
SpatialAllReduce,
Collaborator
|
|
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.
No description provided.