-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a391fbf
commit 36e9141
Showing
21 changed files
with
445 additions
and
713 deletions.
There are no files selected for viewing
This file contains 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains 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,86 @@ | ||
import sys | ||
import os | ||
|
||
from loguru import logger | ||
import torch | ||
import torch.distributed as dist | ||
from torch.nn.parallel import DistributedDataParallel as DDP | ||
from torch.utils.data.distributed import DistributedSampler | ||
|
||
|
||
def setup_logger(rank=-1, world_size=1): | ||
"""Setup logger for distributed training""" | ||
config = { | ||
"handlers": [ | ||
{ | ||
"sink": sys.stdout, | ||
"format": ( | ||
"<green>{time:YYYY-MM-DD HH:mm:ss}</green> | " | ||
"<level>{level: <8}</level> | " | ||
"<cyan>Rank {extra[rank]}/{extra[world_size]}</cyan> | " | ||
"<cyan>{name}</cyan>:<cyan>{line}</cyan> | " | ||
"<level>{message}</level>" | ||
), | ||
"level": "DEBUG", | ||
"colorize": True, | ||
} | ||
] | ||
} | ||
|
||
try: # Remove all existing handlers | ||
logger.configure(**config) | ||
except ValueError: | ||
pass | ||
|
||
# Create a new logger instance with rank information | ||
return logger.bind(rank=rank, world_size=world_size) | ||
|
||
|
||
def setup_distributed(params): | ||
"""Initialize distributed training environment with explicit device mapping""" | ||
if not params.distributed: | ||
return False | ||
|
||
try: | ||
if "RANK" in os.environ and "WORLD_SIZE" in os.environ: | ||
params.rank = int(os.environ["RANK"]) | ||
params.world_size = int(os.environ["WORLD_SIZE"]) | ||
params.local_rank = int(os.environ["LOCAL_RANK"]) | ||
elif "SLURM_PROCID" in os.environ: | ||
params.rank = int(os.environ["SLURM_PROCID"]) | ||
params.local_rank = params.rank % torch.cuda.device_count() | ||
params.world_size = int(os.environ["SLURM_NTASKS"]) | ||
else: | ||
raise ValueError("Not running with distributed environment variables set") | ||
|
||
torch.cuda.set_device(params.local_rank) | ||
init_method = "env://" | ||
backend = params.dist_backend | ||
if backend == "nccl" and not torch.cuda.is_available(): | ||
backend = "gloo" | ||
|
||
if not dist.is_initialized(): | ||
dist.init_process_group( | ||
backend=backend, | ||
init_method=init_method, | ||
world_size=params.world_size, | ||
rank=params.rank, | ||
) | ||
torch.cuda.set_device(params.local_rank) | ||
dist.barrier(device_ids=[params.local_rank]) | ||
|
||
return True | ||
except Exception as e: | ||
print(f"Failed to initialize distributed training: {e}") | ||
return False | ||
|
||
|
||
def cleanup_distributed(): | ||
"""Clean up distributed training resources safely with device mapping""" | ||
if dist.is_initialized(): | ||
try: | ||
local_rank = int(os.environ.get("LOCAL_RANK", 0)) | ||
dist.barrier(device_ids=[local_rank]) | ||
dist.destroy_process_group() | ||
except Exception as e: | ||
print(f"Error during distributed cleanup: {e}") |
File renamed without changes.
This file contains 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,20 @@ | ||
#!/bin/bash | ||
|
||
torchrun --nproc_per_node=2 --master_port=29502 src/train.py \ | ||
--distributed \ | ||
--mode seq_train \ | ||
--dataset dsprites \ | ||
--optim adamw \ | ||
--num_ladders 3 \ | ||
--batch_size 256 \ | ||
--num_epochs 30 \ | ||
--learning_rate 5e-4 \ | ||
--beta 8 \ | ||
--z_dim 2 \ | ||
--coff 0.5 \ | ||
--pre_kl \ | ||
--hidden_dim 64 \ | ||
--fade_in_duration 5000 \ | ||
--output_dir ./output/dsprites/ \ | ||
--data_path ./data/dsprites/ | ||
|
This file contains 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 |
---|---|---|
@@ -1,16 +1,19 @@ | ||
#!/bin/bash | ||
|
||
python train.py \ | ||
torchrun --nproc_per_node=2 --master_port=29501 src/train.py \ | ||
--distributed \ | ||
--mode seq_train \ | ||
--dataset dtd \ | ||
--optim adamw \ | ||
--num_ladders 3 \ | ||
--batch_size 32 \ | ||
--batch_size 128 \ | ||
--num_epochs 30 \ | ||
--learning_rate 5e-4 \ | ||
--beta 3 \ | ||
--beta 8 \ | ||
--z_dim 3 \ | ||
--coff 0.2 \ | ||
--coff 0.5 \ | ||
--pre_kl \ | ||
--hidden_dim 64 \ | ||
--fade_in_duration 5000 \ | ||
--output_dir ./output/dtd/ \ | ||
--optim adamw | ||
--data_path ./data/dtd/ |
13 changes: 9 additions & 4 deletions
13
scripts/run_fashionmnist.sh → src/scripts/run_fashionmnist.sh
This file contains 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 |
---|---|---|
@@ -1,15 +1,20 @@ | ||
#!/bin/bash | ||
|
||
python train.py \ | ||
torchrun --nproc_per_node=2 --master_port=29501 src/train.py \ | ||
--distributed \ | ||
--mode seq_train \ | ||
--dataset fashionmnist \ | ||
--optim adamw \ | ||
--num_ladders 3 \ | ||
--batch_size 16 \ | ||
--batch_size 64 \ | ||
--num_epochs 30 \ | ||
--learning_rate 5e-4 \ | ||
--beta 3 \ | ||
--z_dim 3 \ | ||
--z_dim 2 \ | ||
--coff 0.5 \ | ||
--pre_kl \ | ||
--hidden_dim 32 \ | ||
--fade_in_duration 5000 \ | ||
--output_dir ./output/fashionmnist/ \ | ||
--optim adamw | ||
--data_path ./data/fashionmnist/ | ||
|
This file contains 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,19 @@ | ||
#!/bin/bash | ||
|
||
torchrun --nproc_per_node=2 --master_port=29501 src/train.py \ | ||
--distributed \ | ||
--mode seq_train \ | ||
--dataset flowers102 \ | ||
--optim adamw \ | ||
--num_ladders 3 \ | ||
--batch_size 128 \ | ||
--num_epochs 30 \ | ||
--learning_rate 5e-4 \ | ||
--beta 8 \ | ||
--z_dim 3 \ | ||
--coff 0.5 \ | ||
--pre_kl \ | ||
--hidden_dim 64 \ | ||
--fade_in_duration 5000 \ | ||
--output_dir ./output/flowers102/ \ | ||
--data_path ./data/flowers102/ |
This file contains 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 |
---|---|---|
@@ -1,17 +1,19 @@ | ||
#!/bin/bash | ||
|
||
torchrun --nproc_per_node=2 train_ddp.py \ | ||
--distributed True \ | ||
torchrun --nproc_per_node=2 --master_port=29501 src/train.py \ | ||
--distributed \ | ||
--mode seq_train \ | ||
--dataset ident3d \ | ||
--optim adamw \ | ||
--num_ladders 3 \ | ||
--batch_size 128 \ | ||
--num_epochs 30 \ | ||
--learning_rate 5e-4 \ | ||
--beta 1 \ | ||
--beta 8 \ | ||
--z_dim 3 \ | ||
--coff 0.5 \ | ||
--pre_kl \ | ||
--hidden_dim 64 \ | ||
--fade_in_duration 5000 \ | ||
--output_dir ./output/ident3d/ \ | ||
--optim adamw | ||
--data_path ./data/ident3d/ |
Oops, something went wrong.