Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ScaFFold/utils/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
# Masks are values 0 <= x <= n_categories
MASK_DTYPE = np.uint16
# Volumes/img are 0 <= x <= 1
VOLUME_DTYPE = np.float32
VOLUME_DTYPE_NAME = "float32"
VOLUME_NP_DTYPE = getattr(np, VOLUME_DTYPE_NAME)
VOLUME_TORCH_DTYPE = getattr(torch, VOLUME_DTYPE_NAME)
VOLUME_DTYPE = VOLUME_NP_DTYPE

# Shared AMP dtype selection for torch.autocast.
AMP_DTYPE = torch.bfloat16
10 changes: 6 additions & 4 deletions ScaFFold/utils/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from ScaFFold.utils.checkpointing import CheckpointManager
from ScaFFold.utils.data_loading import FractalDataset, SpatialShardSpec
from ScaFFold.utils.data_types import AMP_DTYPE, VOLUME_DTYPE
from ScaFFold.utils.data_types import AMP_DTYPE, VOLUME_TORCH_DTYPE
from ScaFFold.utils.dice_score import compute_sharded_dice
from ScaFFold.utils.distributed import get_local_rank, get_world_rank, get_world_size

Expand Down Expand Up @@ -436,7 +436,7 @@ def warmup(self):

images = images.to(
device=self.device,
dtype=VOLUME_DTYPE,
dtype=VOLUME_TORCH_DTYPE,
memory_format=torch.channels_last_3d,
non_blocking=True,
)
Expand Down Expand Up @@ -611,7 +611,7 @@ def train(self):
begin_code_region("image_to_device")
images = images.to(
device=self.device,
dtype=VOLUME_DTYPE,
dtype=VOLUME_TORCH_DTYPE,
memory_format=torch.channels_last_3d, # NDHWC (channels last) vs NCDHW (channels first)
non_blocking=True,
)
Expand Down Expand Up @@ -749,7 +749,9 @@ def train(self):
self.config.n_categories,
self.config._parallel_strategy,
)
dice_info = torch.tensor([dice_sum, numsamples], dtype=VOLUME_DTYPE)
dice_info = torch.tensor(
[dice_sum, numsamples], dtype=VOLUME_TORCH_DTYPE
)
if self.config.dist:
dice_info = dice_info.to(device=self.device)
torch.distributed.all_reduce(
Expand Down
Loading